From 496a3a2093d7455f5774d16190f0ab98c0f08e31 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Sun, 25 Jun 2023 19:10:34 -0500 Subject: [PATCH] vkd3d-shader/hlsl: Use lower_ir() for lower_division(). --- libs/vkd3d-shader/hlsl_codegen.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 6a2a8bc8..23e52a25 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -2268,10 +2268,10 @@ static bool sort_synthetic_separated_samplers_first(struct hlsl_ctx *ctx) } /* Lower DIV to RCP + MUL. */ -static bool lower_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) +static bool lower_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_block *block) { + struct hlsl_ir_node *rcp, *mul; struct hlsl_ir_expr *expr; - struct hlsl_ir_node *rcp; if (instr->type != HLSL_IR_EXPR) return false; @@ -2281,10 +2281,12 @@ static bool lower_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi if (!(rcp = hlsl_new_unary_expr(ctx, HLSL_OP1_RCP, expr->operands[1].node, &instr->loc))) return false; - list_add_before(&expr->node.entry, &rcp->entry); - expr->op = HLSL_OP2_MUL; - hlsl_src_remove(&expr->operands[1]); - hlsl_src_from_node(&expr->operands[1], rcp); + hlsl_block_add_instr(block, rcp); + + if (!(mul = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, expr->operands[0].node, rcp))) + return false; + hlsl_block_add_instr(block, mul); + return true; } @@ -4423,7 +4425,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry lower_ir(ctx, lower_ternary, body); if (profile->major_version < 4) { - hlsl_transform_ir(ctx, lower_division, body, NULL); + lower_ir(ctx, lower_division, body); hlsl_transform_ir(ctx, lower_sqrt, body, NULL); lower_ir(ctx, lower_dot, body); lower_ir(ctx, lower_round, body);