Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl_codegen.c | 4 ++++ libs/vkd3d-shader/hlsl_sm4.c | 16 ++++++++++++++++ 3 files changed, 21 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 80cea512..9b579b72 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -469,6 +469,7 @@ struct hlsl_ctx struct hlsl_vec4 *values; size_t count, size; } constant_defs; + uint32_t temp_count; };
enum hlsl_error_level diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index a1d6e8e9..c2aeb7b0 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -685,6 +685,7 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl struct liveness { size_t size; + uint32_t reg_count; struct { /* 0 if not live yet. */ @@ -747,6 +748,7 @@ static struct hlsl_reg allocate_register(struct hlsl_ctx *ctx, struct liveness * ret.id = component_idx / 4; ret.writemask = writemask; ret.allocated = true; + liveness->reg_count = max(liveness->reg_count, ret.id + 1); return ret; }
@@ -782,6 +784,7 @@ static struct hlsl_reg allocate_range(struct hlsl_ctx *ctx, struct liveness *liv liveness->regs[component_idx + i].last_read = last_read; ret.id = component_idx / 4; ret.allocated = true; + liveness->reg_count = max(liveness->reg_count, ret.id + align(component_count, 4)); return ret; }
@@ -1008,6 +1011,7 @@ static void allocate_temp_registers(struct hlsl_ctx *ctx, struct hlsl_ir_functio { struct liveness liveness = {0}; allocate_temp_registers_recurse(ctx, entry_func->body, &liveness); + ctx->temp_count = liveness.reg_count; }
static void allocate_semantic_register(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, unsigned int *counter, bool output) diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 92f854c0..a66bcaae 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -762,6 +762,19 @@ static void write_sm4_dcl_semantic(struct hlsl_ctx *ctx, struct vkd3d_bytecode_b write_sm4_instruction(buffer, &instr); }
+static void write_sm4_dcl_temps(struct vkd3d_bytecode_buffer *buffer, uint32_t temp_count) +{ + struct sm4_instruction instr = + { + .opcode = VKD3D_SM4_OP_DCL_TEMPS, + + .idx = {temp_count}, + .idx_count = 1, + }; + + write_sm4_instruction(buffer, &instr); +} + static void write_sm4_shdr(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc) { const struct hlsl_profile_info *profile = ctx->profile; @@ -797,6 +810,9 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc) write_sm4_dcl_semantic(ctx, &buffer, var); }
+ if (ctx->temp_count) + write_sm4_dcl_temps(&buffer, ctx->temp_count); + dxbc_writer_add_section(dxbc, TAG_SHDR, buffer.data, buffer.size); }