Zebediah Figura : vkd3d-shader: Lower DIV to RCP + MUL for SM1.

Alexandre Julliard julliard at winehq.org
Mon May 31 15:58:28 CDT 2021


Module: vkd3d
Branch: master
Commit: 100c65c967704411b751fee17e9c0b165be9c6d7
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=100c65c967704411b751fee17e9c0b165be9c6d7

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Fri May 21 00:32:24 2021 -0500

vkd3d-shader: Lower DIV to RCP + MUL for SM1.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/hlsl_codegen.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index b4ea839..afa096b 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -388,6 +388,27 @@ static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi
     return true;
 }
 
+/* Lower DIV to RCP + MUL. */
+static bool lower_division(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
+{
+    struct hlsl_ir_expr *expr;
+    struct hlsl_ir_node *rcp;
+
+    if (instr->type != HLSL_IR_EXPR)
+        return false;
+    expr = hlsl_ir_expr(instr);
+    if (expr->op != HLSL_IR_BINOP_DIV)
+        return false;
+
+    if (!(rcp = hlsl_new_unary_expr(ctx, HLSL_IR_UNOP_RCP, expr->operands[1].node, instr->loc)))
+        return false;
+    list_add_before(&expr->node.entry, &rcp->entry);
+    expr->op = HLSL_IR_BINOP_MUL;
+    hlsl_src_remove(&expr->operands[1]);
+    hlsl_src_from_node(&expr->operands[1], rcp);
+    return true;
+}
+
 static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
 {
     switch (instr->type)
@@ -1954,6 +1975,9 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
     while (transform_ir(ctx, split_struct_copies, entry_func->body, NULL));
     while (transform_ir(ctx, fold_constants, entry_func->body, NULL));
 
+    if (ctx->profile->major_version < 4)
+        transform_ir(ctx, lower_division, entry_func->body, NULL);
+
     do
         compute_liveness(ctx, entry_func);
     while (transform_ir(ctx, dce, entry_func->body, NULL));




More information about the wine-cvs mailing list