Zebediah Figura : vkd3d-shader: Allocate constant registers for anonymous constants.

Alexandre Julliard julliard at winehq.org
Tue Apr 13 16:17:34 CDT 2021


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

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Thu Apr  8 23:38:26 2021 -0500

vkd3d-shader: Allocate constant registers for anonymous constants.

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

---

 libs/vkd3d-shader/hlsl.h         |  1 +
 libs/vkd3d-shader/hlsl_codegen.c | 51 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 3f6abdc..923eff5 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -380,6 +380,7 @@ struct hlsl_ir_constant
         double d[4];
         bool b[4];
     } value;
+    struct hlsl_reg reg;
 };
 
 struct hlsl_scope
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index cfa021b..f7e1156 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -798,6 +798,55 @@ static void allocate_temp_registers_recurse(struct list *instrs, struct liveness
     }
 }
 
+static void allocate_const_registers_recurse(struct list *instrs, struct liveness *liveness)
+{
+    struct hlsl_ir_node *instr;
+
+    LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
+    {
+        switch (instr->type)
+        {
+            case HLSL_IR_CONSTANT:
+            {
+                struct hlsl_ir_constant *constant = hlsl_ir_constant(instr);
+
+                if (instr->data_type->reg_size > 1)
+                    constant->reg = allocate_range(liveness, 1, UINT_MAX, instr->data_type->reg_size);
+                else
+                    constant->reg = allocate_register(liveness, 1, UINT_MAX, instr->data_type->dimx);
+                TRACE("Allocated constant @%u to %s.\n", instr->index,
+                        debug_register('c', constant->reg, instr->data_type));
+                break;
+            }
+
+            case HLSL_IR_IF:
+            {
+                struct hlsl_ir_if *iff = hlsl_ir_if(instr);
+                allocate_const_registers_recurse(&iff->then_instrs, liveness);
+                allocate_const_registers_recurse(&iff->else_instrs, liveness);
+                break;
+            }
+
+            case HLSL_IR_LOOP:
+            {
+                struct hlsl_ir_loop *loop = hlsl_ir_loop(instr);
+                allocate_const_registers_recurse(&loop->body, liveness);
+                break;
+            }
+
+            default:
+                break;
+        }
+    }
+}
+
+static void allocate_const_registers(struct hlsl_ir_function_decl *entry_func)
+{
+    struct liveness liveness = {0};
+
+    allocate_const_registers_recurse(entry_func->body, &liveness);
+}
+
 /* Simple greedy temporary register allocation pass that just assigns a unique
  * index to all (simultaneously live) variables or intermediate values. Agnostic
  * as to how many registers are actually available for the current backend, and
@@ -846,6 +895,8 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
         rb_for_each_entry(&ctx->functions, dump_function, NULL);
 
     allocate_temp_registers(entry_func);
+    if (ctx->profile->major_version < 4)
+        allocate_const_registers(entry_func);
 
     if (ctx->failed)
         return VKD3D_ERROR_INVALID_SHADER;




More information about the wine-cvs mailing list