[PATCH vkd3d v3 5/6] vkd3d-shader: Allocate constant registers for anonymous constants.
Zebediah Figura
zfigura at codeweavers.com
Thu Apr 8 23:38:26 CDT 2021
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
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 3f6abdc7..923eff55 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 cfa021bc..f7e11565 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;
--
2.31.1
More information about the wine-devel
mailing list