From 4039168bcabe49375109baf7ac4aaf76db983901 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 11 Nov 2025 17:24:38 +0100 Subject: [PATCH] vkd3d-shader/hlsl: Consider scalars to be equivalent to 1-component vectors in hlsl_add_conditional(). --- libs/vkd3d-shader/hlsl_codegen.c | 8 ++++++-- tests/hlsl/conditional.shader_test | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 8334ffdf7..382e0cebc 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -5490,10 +5490,14 @@ static struct hlsl_ir_node *lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *hlsl_add_conditional(struct hlsl_ctx *ctx, struct hlsl_block *instrs, struct hlsl_ir_node *condition, struct hlsl_ir_node *if_true, struct hlsl_ir_node *if_false) { + struct hlsl_type *false_type = if_false->data_type; struct hlsl_type *cond_type = condition->data_type; struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS]; + struct hlsl_type *true_type = if_true->data_type; - VKD3D_ASSERT(hlsl_types_are_equal(if_true->data_type, if_false->data_type)); + VKD3D_ASSERT(hlsl_types_are_equal(true_type, false_type) + || (hlsl_is_vec1(true_type) && hlsl_is_vec1(false_type) + && true_type->e.numeric.type == false_type->e.numeric.type)); if (cond_type->e.numeric.type != HLSL_TYPE_BOOL) { @@ -5505,7 +5509,7 @@ struct hlsl_ir_node *hlsl_add_conditional(struct hlsl_ctx *ctx, struct hlsl_bloc operands[0] = condition; operands[1] = if_true; operands[2] = if_false; - return hlsl_block_add_expr(ctx, instrs, HLSL_OP3_TERNARY, operands, if_true->data_type, &condition->loc); + return hlsl_block_add_expr(ctx, instrs, HLSL_OP3_TERNARY, operands, true_type, &condition->loc); } static struct hlsl_ir_node *lower_int_division_sm4(struct hlsl_ctx *ctx, diff --git a/tests/hlsl/conditional.shader_test b/tests/hlsl/conditional.shader_test index 3e99b91f3..48e63270b 100644 --- a/tests/hlsl/conditional.shader_test +++ b/tests/hlsl/conditional.shader_test @@ -70,10 +70,40 @@ float main() : sv_target return float4(0.9, 0.8, 0.7, 0.6); } +[vertex shader] +void main(float4 p : position, out float t[4] : texcoord, out float4 position : sv_position) +{ + t[0] = (p.x + 1.0) / 2.0; + t[2] = 0.0; + t[1] = (p.y + 1.0) / 2.0; + t[3] = 1.0; + position = p; +} + +[pixel shader] +float4 main(float t[4] : texcoord) : sv_target +{ + if (t[0] > 0.5) + return floor(float4(t) * 128.0 + 0.5) / 128.0; + return float4(0.0, 1.0, 0.0, 1.0); +} + +[test] +todo(msl & sm>=6) draw quad +probe (160, 120) f32(0.00, 1.00, 0.0, 1.0) +probe (480, 120) f32(0.75, 0.75, 0.0, 1.0) +probe (160, 360) f32(0.00, 1.00, 0.0, 1.0) +probe (480, 360) f32(0.75, 0.25, 0.0, 1.0) + % Using older profiles fails to compile with forced control flow instruction [require] shader model >= 3.0 +[vertex shader] +float4 main(float4 p : position) : sv_position +{ + return p; +} [pixel shader] uniform float a;