From d049ea640f8ad199d84b2ecdfba7d51569014479 Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Mon, 20 Jan 2025 22:18:57 -0600 Subject: [PATCH] vkd3d-shader/hlsl: Implement broadcasts in constant folding. Normally lower_broadcasts() takes care of this, but loop unrolling executes before other constant passes. --- libs/vkd3d-shader/hlsl_constant_ops.c | 17 ++++++++--------- tests/hlsl/unroll.shader_test | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index e8dd4d62..8d112fb5 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -148,15 +148,7 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, float f = 0.0f; int32_t i = 0; - if (dst_type->e.numeric.dimx != src->node.data_type->e.numeric.dimx - || dst_type->e.numeric.dimy != src->node.data_type->e.numeric.dimy) - { - FIXME("Cast from %s to %s.\n", debug_hlsl_type(ctx, src->node.data_type), - debug_hlsl_type(ctx, dst_type)); - return false; - } - - for (k = 0; k < dst_type->e.numeric.dimx; ++k) + for (k = 0; k < src->node.data_type->e.numeric.dimx; ++k) { switch (src->node.data_type->e.numeric.type) { @@ -221,6 +213,13 @@ static bool fold_cast(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, break; } } + + if (src->node.data_type->e.numeric.dimx == 1) + { + for (k = 1; k < dst_type->e.numeric.dimx; ++k) + dst->u[k] = dst->u[0]; + } + return true; } diff --git a/tests/hlsl/unroll.shader_test b/tests/hlsl/unroll.shader_test index b9f3d65e..cb21079b 100644 --- a/tests/hlsl/unroll.shader_test +++ b/tests/hlsl/unroll.shader_test @@ -64,7 +64,7 @@ float4 main() : sv_target draw quad probe (0,0) rgba(1337.0, 0, 0, 0) -[pixel shader todo(sm<6)] +[pixel shader] float4 main() : sv_target { float i = 0; @@ -79,5 +79,5 @@ float4 main() : sv_target } [test] -todo(sm<6) draw quad +draw quad probe (0,0) rgba(0, 0, 0, 0)