From 16409569fd02212366fe80cac5ed864134d54f23 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 VKD3DSIH_ITOF. --- libs/vkd3d-shader/msl.c | 22 ++++++++++++++++++++++ tests/hlsl/asint.shader_test | 2 +- tests/hlsl/bool-cast.shader_test | 4 ++-- tests/hlsl/default-values.shader_test | 4 ++-- tests/hlsl/lerp.shader_test | 2 +- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d-shader/msl.c b/libs/vkd3d-shader/msl.c index 9c5df5bc..e082e701 100644 --- a/libs/vkd3d-shader/msl.c +++ b/libs/vkd3d-shader/msl.c @@ -425,6 +425,25 @@ static void msl_relop(struct msl_generator *gen, const struct vkd3d_shader_instr msl_dst_cleanup(&dst, &gen->string_buffers); } +static void msl_cast(struct msl_generator *gen, const struct vkd3d_shader_instruction *ins, const char *constructor) +{ + unsigned int component_count; + struct msl_src src; + struct msl_dst dst; + uint32_t mask; + + mask = msl_dst_init(&dst, gen, ins, &ins->dst[0]); + msl_src_init(&src, gen, &ins->src[0], mask); + + if ((component_count = vsir_write_mask_component_count(mask)) > 1) + msl_print_assignment(gen, &dst, "%s%u(%s)", constructor, component_count, src.str->buffer); + else + msl_print_assignment(gen, &dst, "%s(%s)", constructor, src.str->buffer); + + msl_src_cleanup(&src, &gen->string_buffers); + msl_dst_cleanup(&dst, &gen->string_buffers); +} + static void msl_mov(struct msl_generator *gen, const struct vkd3d_shader_instruction *ins) { struct msl_src src; @@ -501,6 +520,9 @@ static void msl_handle_instruction(struct msl_generator *gen, const struct vkd3d case VKD3DSIH_NEU: msl_relop(gen, ins, "!="); break; + case VKD3DSIH_ITOF: + msl_cast(gen, ins, "float"); + break; case VKD3DSIH_MOV: msl_mov(gen, ins); break; diff --git a/tests/hlsl/asint.shader_test b/tests/hlsl/asint.shader_test index e4f9425e..83e84d49 100644 --- a/tests/hlsl/asint.shader_test +++ b/tests/hlsl/asint.shader_test @@ -36,7 +36,7 @@ float4 main() : sv_target uniform 0 int4 11 12 0 0 uniform 4 int4 13 14 0 0 uniform 8 int4 20 21 22 23 -todo(msl) draw quad +draw quad probe (320,240) rgba (13.0, 21.0, 0.0, 0.0) diff --git a/tests/hlsl/bool-cast.shader_test b/tests/hlsl/bool-cast.shader_test index e56722d1..6aeec953 100644 --- a/tests/hlsl/bool-cast.shader_test +++ b/tests/hlsl/bool-cast.shader_test @@ -27,7 +27,7 @@ float4 main() : SV_TARGET uniform 0 float4 0.0 0.0 2.0 4.0 if(sm<4) uniform 4 float4 0 1 0 10 if(sm>=4) uniform 4 int4 0 1 0 10 -todo(msl) draw quad +draw quad probe (0, 0) rgba (0.0, 10.0, 1.0, 11.0) @@ -42,5 +42,5 @@ float4 main() : sv_target [test] if(sm<4) uniform 0 float4 1.0 1.0 1.0 0.0 if(sm>=4) uniform 0 uint4 0x00000001 0x00000002 0x80000000 0x00000000 -todo(msl) draw quad +draw quad probe (0, 0) rgba (2.0, 2.0, 2.0, 0.0) diff --git a/tests/hlsl/default-values.shader_test b/tests/hlsl/default-values.shader_test index 32f09b5f..93936a9e 100644 --- a/tests/hlsl/default-values.shader_test +++ b/tests/hlsl/default-values.shader_test @@ -111,7 +111,7 @@ if(sm<4) uniform 8 float4 70 90 0 0 if(sm<4) uniform 12 float4 80 100 0 0 if(sm>=4) uniform 8 int4 70 90 0 0 if(sm>=4) uniform 12 int4 80 100 0 0 -todo(msl) draw quad +draw quad probe (0, 0) rgba (70, 80, 90, 100) @@ -216,7 +216,7 @@ if(sm<4) uniform 8 float4 70 90 0 0 if(sm<4) uniform 12 float4 80 100 0 0 if(sm>=4) uniform 8 int4 70 90 0 0 if(sm>=4) uniform 12 int4 80 100 0 0 -todo(msl) draw quad +draw quad probe (0, 0) rgba (70, 80, 90, 100) diff --git a/tests/hlsl/lerp.shader_test b/tests/hlsl/lerp.shader_test index 2163f791..dac2e051 100644 --- a/tests/hlsl/lerp.shader_test +++ b/tests/hlsl/lerp.shader_test @@ -33,7 +33,7 @@ if(sm<4) uniform 8 float4 0 1 -1 1000000 if(sm>=4) uniform 0 int4 2 3 4 0 if(sm>=4) uniform 4 int4 0 -10 10 1000000 if(sm>=4) uniform 8 int4 0 1 -1 1000000 -todo(msl) draw quad +draw quad probe (0, 0) rgba (2.0, -10.0, -2.0, 1e12) 4