From b9ebf87114762fd212ec15891e57c918d99ddb94 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Sat, 8 Mar 2025 16:59:58 +0100 Subject: [PATCH] vkd3d-shader/hlsl: Do not collect expressions across different operations in hlsl_normalize_binary_exprs(). --- libs/vkd3d-shader/hlsl_constant_ops.c | 10 ++++++---- tests/hlsl/arithmetic-uint.shader_test | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index f4715a92..f74ecffc 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -1712,7 +1712,8 @@ bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst progress = true; } - if (!progress && e1 && (tmp = collect_exprs(ctx, &block, instr, op, e1->operands[1].node, arg2))) + if (!progress && e1 && e1->op == op + && (tmp = collect_exprs(ctx, &block, instr, op, e1->operands[1].node, arg2))) { /* (y OPR (x OPL a)) OPR (x OPL b) -> y OPR (x OPL (a OPR b)) */ arg1 = e1->operands[0].node; @@ -1720,7 +1721,7 @@ bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst progress = true; } - if (!progress && is_op_commutative(op) && e1 + if (!progress && is_op_commutative(op) && e1 && e1->op == op && (tmp = collect_exprs(ctx, &block, instr, op, e1->operands[0].node, arg2))) { /* ((x OPL a) OPR y) OPR (x OPL b) -> (x OPL (a OPR b)) OPR y */ @@ -1729,7 +1730,8 @@ bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst progress = true; } - if (!progress && e2 && (tmp = collect_exprs(ctx, &block, instr, op, arg1, e2->operands[0].node))) + if (!progress && e2 && e2->op == op + && (tmp = collect_exprs(ctx, &block, instr, op, arg1, e2->operands[0].node))) { /* (x OPL a) OPR ((x OPL b) OPR y) -> (x OPL (a OPR b)) OPR y */ arg1 = tmp; @@ -1737,7 +1739,7 @@ bool hlsl_normalize_binary_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst progress = true; } - if (!progress && is_op_commutative(op) && e2 + if (!progress && is_op_commutative(op) && e2 && e2->op == op && (tmp = collect_exprs(ctx, &block, instr, op, arg1, e2->operands[1].node))) { /* (x OPL a) OPR (y OPR (x OPL b)) -> (x OPL (a OPR b)) OPR y */ diff --git a/tests/hlsl/arithmetic-uint.shader_test b/tests/hlsl/arithmetic-uint.shader_test index 1081dce6..32578076 100644 --- a/tests/hlsl/arithmetic-uint.shader_test +++ b/tests/hlsl/arithmetic-uint.shader_test @@ -107,7 +107,7 @@ uint4 main() : SV_TARGET [test] uniform 0 uint4 0xccaa5533 7 1 2 todo(glsl | msl) draw quad -todo(sm<6) probe (0, 0) rgbaui(0xff77, 0xf, 0x407f, 0x9) +probe (0, 0) rgbaui(0xff77, 0xf, 0x407f, 0x9) [require] shader model >= 6.2