From 58d02da8928313b466b0c28dce0cb35b2ed54446 Mon Sep 17 00:00:00 2001 From: Shaun Ren Date: Thu, 6 Nov 2025 14:32:51 -0500 Subject: [PATCH] vkd3d-shader/hlsl: Use a bool type for "new_cond" in lower_conditional_block_discard_nz(). This fixes the assertion error "sm4_generate_vsir_instr_expr Failed assertion: dst_type->e.numeric.type == HLSL_TYPE_BOOL" which occurs when compiling the following HLSL shader using the ps_4_0 target profile: uniform float4 x; uniform bool b; float4 main() : SV_Target { if (!b) clip(x.x); else clip(x.y); return x; } --- libs/vkd3d-shader/hlsl_codegen.c | 7 +----- tests/hlsl/clip.shader_test | 42 +++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 924ec8e05..a3337c443 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -4099,7 +4099,6 @@ static bool lower_conditional_block_stores(struct hlsl_ctx *ctx, struct hlsl_ir_ static bool lower_conditional_block_discard_nz(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_ir_node *cond, bool is_then) { - struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {0}; struct hlsl_ir_node *discard_cond, *new_cond = NULL; struct hlsl_ir_jump *jump; struct hlsl_block block; @@ -4122,12 +4121,8 @@ static bool lower_conditional_block_discard_nz(struct hlsl_ctx *ctx, struct hlsl cond = hlsl_block_add_unary_expr(ctx, &block, HLSL_OP1_LOGIC_NOT, cond, &instr->loc); discard_cond = hlsl_block_add_cast(ctx, &block, discard_cond, cond->data_type, &instr->loc); - operands[0] = cond; - operands[1] = discard_cond; - /* discard_nz (cond && discard_cond) */ - new_cond = hlsl_block_add_expr(ctx, &block, HLSL_OP2_LOGIC_AND, operands, - hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), &jump->node.loc); + new_cond = hlsl_block_add_binary_expr(ctx, &block, HLSL_OP2_LOGIC_AND, cond, discard_cond); list_move_before(&jump->node.entry, &block.instrs); hlsl_src_remove(&jump->condition); diff --git a/tests/hlsl/clip.shader_test b/tests/hlsl/clip.shader_test index bb7597cfd..c16165986 100644 --- a/tests/hlsl/clip.shader_test +++ b/tests/hlsl/clip.shader_test @@ -10,19 +10,49 @@ float4 main() : sv_target [test] uniform 0 float4 1 2 3 4 todo(glsl) draw quad -probe (0, 0) rgba (1, 2, 3, 4) +probe (0, 0) f32(1, 2, 3, 4) uniform 0 float4 9 8 7 6 todo(glsl) draw quad -probe (0, 0) rgba (9, 8, 7, 6) +probe (0, 0) f32(9, 8, 7, 6) uniform 0 float4 -1 8 7 6 todo(glsl) draw quad -probe (0, 0) rgba (9, 8, 7, 6) +probe (0, 0) f32(9, 8, 7, 6) uniform 0 float4 9 0 7 6 todo(glsl) draw quad -probe (0, 0) rgba (9, 0, 7, 6) +probe (0, 0) f32(9, 0, 7, 6) uniform 0 float4 3 -8 3 0 todo(glsl) draw quad -probe (0, 0) rgba (9, 0, 7, 6) +probe (0, 0) f32(9, 0, 7, 6) uniform 0 float4 3 3 3 -1 todo(glsl) draw quad -probe (0, 0) rgba (9, 0, 7, 6) +probe (0, 0) f32(9, 0, 7, 6) + +[pixel shader] +uniform float4 x; +uniform bool b; + +float4 main() : SV_Target +{ + if (!b) + clip(x.x); + else + clip(x.y); + + return x; +} + +[test] +uniform 0 float4 1 -2 3 4 +if(sm<4) uniform 4 float 0 +if(sm>=4) uniform 4 uint 0 +todo(glsl) draw quad +probe (0, 0) f32(1, -2, 3, 4) +uniform 0 float4 9 -8 7 6 +if(sm<4) uniform 4 float 1 +if(sm>=4) uniform 4 uint 1 +todo(glsl) draw quad +probe (0, 0) f32(1, -2, 3, 4) +if(sm<4) uniform 4 float 0 +if(sm>=4) uniform 4 uint 0 +todo(glsl) draw quad +probe (0, 0) f32(9, -8, 7, 6)