From 5bb7dcaba311967832c9ae578d9351602b566cae Mon Sep 17 00:00:00 2001 From: Feifan He Date: Fri, 22 Nov 2024 15:45:54 +0800 Subject: [PATCH] vkd3d-shader/msl: Implement support for VKD3DSPR_IMMCONST registers. --- libs/vkd3d-shader/msl.c | 31 +++++++++++++++++++ tests/hlsl/asfloat.shader_test | 2 +- tests/hlsl/loop.shader_test | 4 +-- tests/hlsl/matrix-semantics.shader_test | 6 ++-- tests/hlsl/object-field-offsets.shader_test | 6 ++-- .../register-reservations-numeric.shader_test | 8 ++--- tests/hlsl/storage-qualifiers.shader_test | 4 +-- tests/hlsl/swizzle-matrix.shader_test | 4 +-- tests/hlsl/uniform-parameters.shader_test | 2 +- 9 files changed, 49 insertions(+), 18 deletions(-) diff --git a/libs/vkd3d-shader/msl.c b/libs/vkd3d-shader/msl.c index 321faea5..dbedbbb6 100644 --- a/libs/vkd3d-shader/msl.c +++ b/libs/vkd3d-shader/msl.c @@ -153,6 +153,37 @@ static void msl_print_register_name(struct vkd3d_string_buffer *buffer, msl_print_register_datatype(buffer, gen, reg->data_type); break; + case VKD3DSPR_IMMCONST: + switch (reg->dimension) + { + case VSIR_DIMENSION_SCALAR: + switch (reg->data_type) + { + case VKD3D_DATA_INT: + vkd3d_string_buffer_printf(buffer, "as_type(%#xu)", reg->u.immconst_u32[0]); + break; + case VKD3D_DATA_UINT: + vkd3d_string_buffer_printf(buffer, "%#xu", reg->u.immconst_u32[0]); + break; + case VKD3D_DATA_FLOAT: + vkd3d_string_buffer_printf(buffer, "as_type(%#xu)", reg->u.immconst_u32[0]); + break; + default: + msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_INTERNAL, + "Internal compiler error: Unhandled immconst datatype %#x.", reg->data_type); + vkd3d_string_buffer_printf(buffer, "", reg->data_type); + break; + } + break; + + default: + vkd3d_string_buffer_printf(buffer, "", reg->dimension); + msl_compiler_error(gen, VKD3D_SHADER_ERROR_MSL_INTERNAL, + "Internal compiler error: Unhandled dimension %#x.", reg->dimension); + break; + } + break; + case VKD3DSPR_CONSTBUFFER: if (reg->idx_count != 3) { diff --git a/tests/hlsl/asfloat.shader_test b/tests/hlsl/asfloat.shader_test index 08f6c693..2184c186 100644 --- a/tests/hlsl/asfloat.shader_test +++ b/tests/hlsl/asfloat.shader_test @@ -36,7 +36,7 @@ float4 main() : sv_target uniform 0 float4 11 12 0 0 uniform 4 float4 13 14 0 0 uniform 8 float4 20 21 22 23 -todo(msl) draw quad +draw quad probe (320,240) rgba (13.0, 21.0, 0.0, 0.0) [pixel shader fail] diff --git a/tests/hlsl/loop.shader_test b/tests/hlsl/loop.shader_test index c47528ec..0259d736 100644 --- a/tests/hlsl/loop.shader_test +++ b/tests/hlsl/loop.shader_test @@ -70,7 +70,7 @@ float4 main() : sv_target [test] uniform 0 float 4.0 -todo(msl) draw quad +draw quad probe (0, 0) rgba (409.1, 409.1, 409.1, 409.1) [pixel shader] @@ -100,7 +100,7 @@ float4 main() : sv_target [test] uniform 0 float 4.0 -todo(msl) draw quad +draw quad probe (0, 0) rgba (410.1, 410.1, 410.1, 410.1) % loop attribute by itself diff --git a/tests/hlsl/matrix-semantics.shader_test b/tests/hlsl/matrix-semantics.shader_test index 8f3736c8..d9601e0d 100644 --- a/tests/hlsl/matrix-semantics.shader_test +++ b/tests/hlsl/matrix-semantics.shader_test @@ -44,7 +44,7 @@ row_major float4x1 main() : sv_target } [test] -todo(sm>=6 | msl) draw quad +todo(sm>=6) draw quad probe rtv 0 (0,0) r (1.0) probe rtv 1 (0,0) r (2.0) probe rtv 2 (0,0) r (3.0) @@ -57,7 +57,7 @@ float1x4 main() : sv_target } [test] -todo(sm>=6 | msl) draw quad +todo(sm>=6) draw quad probe rtv 0 (0,0) r (1.0) probe rtv 1 (0,0) r (2.0) probe rtv 2 (0,0) r (3.0) @@ -78,7 +78,7 @@ void main(out float1x2 x : sv_target0, out float1x2 y : sv_target2) } [test] -todo(sm>=6 | msl) draw quad +todo(sm>=6) draw quad probe rtv 0 (0,0) r (1.0) probe rtv 1 (0,0) r (2.0) probe rtv 2 (0,0) r (5.0) diff --git a/tests/hlsl/object-field-offsets.shader_test b/tests/hlsl/object-field-offsets.shader_test index f322d7f9..3909f7ca 100644 --- a/tests/hlsl/object-field-offsets.shader_test +++ b/tests/hlsl/object-field-offsets.shader_test @@ -19,7 +19,7 @@ float4 main() : sv_target [test] uniform 0 float4 1.0 2.0 3.0 4.0 uniform 4 float4 5.0 6.0 7.0 8.0 -todo(msl) draw quad +draw quad probe (0, 0) rgba (1.0, 2.0, 3.0, 0.0) @@ -45,7 +45,7 @@ float4 main() : sv_target [test] uniform 0 float4 1.0 2.0 3.0 4.0 uniform 4 float4 5.0 6.0 7.0 8.0 -todo(msl) draw quad +draw quad probe (0, 0) rgba (1.0, 2.0, 5.0, 0.0) @@ -66,5 +66,5 @@ float4 main() : sv_target [test] uniform 0 float4 1.0 2.0 3.0 4.0 uniform 4 float4 5.0 6.0 7.0 8.0 -todo(msl) draw quad +draw quad probe (0, 0) rgba (1.0, 2.0, 5.0, 0.0) diff --git a/tests/hlsl/register-reservations-numeric.shader_test b/tests/hlsl/register-reservations-numeric.shader_test index 80985233..3fb5d9eb 100644 --- a/tests/hlsl/register-reservations-numeric.shader_test +++ b/tests/hlsl/register-reservations-numeric.shader_test @@ -117,7 +117,7 @@ uniform 0 float4 0.1 0.2 0.3 0.4 uniform 4 float4 1.1 1.2 1.3 1.4 uniform 8 float4 2.1 2.2 2.3 2.4 uniform 12 float4 3.1 3.2 3.3 3.4 -todo(msl) draw quad +draw quad probe (0, 0) rgba (2.1, 2.2, 0.0, 0.0) @@ -188,7 +188,7 @@ uniform 0 float4 0.1 0.2 0.3 0.4 uniform 4 float4 1.1 1.2 1.3 1.4 uniform 8 float4 2.1 2.2 2.3 2.4 uniform 12 float4 3.1 3.2 3.3 3.4 -todo(msl) draw quad +draw quad probe (0, 0) rgba (2.1, 2.2, 2.3, 0.0) @@ -241,7 +241,7 @@ float4 main() : sv_target uniform 0 float 200 uniform 4 float 201 uniform 8 float 202 -todo(msl) draw quad +draw quad probe (0,0) rgba (201.0, 202.0, 0.0, 0.0) [pixel shader] @@ -259,7 +259,7 @@ float4 main() : sv_target uniform 0 float 201 uniform 4 float 202 uniform 8 float 203 -todo(msl) draw quad +draw quad probe (0,0) rgba (203.0, 0.0, 0.0, 0.0) [pixel shader fail(sm<4)] diff --git a/tests/hlsl/storage-qualifiers.shader_test b/tests/hlsl/storage-qualifiers.shader_test index bf5f228d..9defe8e8 100644 --- a/tests/hlsl/storage-qualifiers.shader_test +++ b/tests/hlsl/storage-qualifiers.shader_test @@ -17,7 +17,7 @@ void main(in uniform float4 a, uniform float4 b, out float4 o : sv_target) [test] uniform 0 float4 0.1 0.0 0.0 0.0 uniform 4 float4 0.2 0.0 0.0 0.0 -todo(sm>=6 | msl) draw quad +todo(sm>=6) draw quad probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4) [pixel shader] @@ -42,5 +42,5 @@ void main(out float4 o : sv_target) [test] uniform 0 float4 0.1 0.0 0.0 0.0 uniform 4 float4 0.2 0.0 0.0 0.0 -todo(msl) draw quad +draw quad probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4) diff --git a/tests/hlsl/swizzle-matrix.shader_test b/tests/hlsl/swizzle-matrix.shader_test index afdf940f..cadec865 100644 --- a/tests/hlsl/swizzle-matrix.shader_test +++ b/tests/hlsl/swizzle-matrix.shader_test @@ -169,7 +169,7 @@ float4 main() : sv_target [test] uniform 0 float4 20 30 40 -1 -todo(msl) draw quad +draw quad probe (0,0) rgba (10.0, 20.0, 30.0, 40.0) @@ -187,7 +187,7 @@ float4 main() : sv_target [test] uniform 0 float4 20 30 80 -1 -todo(msl) draw quad +draw quad probe (0,0) rgba (80.0, 30.0, 20.0, 10.0) diff --git a/tests/hlsl/uniform-parameters.shader_test b/tests/hlsl/uniform-parameters.shader_test index f3a63cdd..1951987f 100644 --- a/tests/hlsl/uniform-parameters.shader_test +++ b/tests/hlsl/uniform-parameters.shader_test @@ -31,5 +31,5 @@ float4 main(uniform float2x2 m, uniform float4 v) : sv_target uniform 0 float4 11 12 0 0 uniform 4 float4 13 14 0 0 uniform 8 float4 20 21 22 23 -todo(msl) draw quad +draw quad probe (320,240) rgba (13.0, 21.0, 0.0, 0.0)