diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 6a43ed9d..6bec38d0 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -488,6 +488,8 @@ struct hlsl_ir_var * range). The IR instructions are numerated starting from 2, because 0 means unused, and 1 * means function entry. */ unsigned int first_write, last_read; + /* Whether the variable is read in any entry function. */ + bool is_read; /* Offset where the variable's value is stored within its buffer in numeric register components. * This in case the variable is uniform. */ unsigned int buffer_offset; diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 4bf34d56..653afdc1 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -4383,6 +4383,21 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl compute_liveness_recurse(&entry_func->body, 0, 0); } +static void mark_vars_usage(struct hlsl_ctx *ctx) +{ + struct hlsl_scope *scope; + struct hlsl_ir_var *var; + + LIST_FOR_EACH_ENTRY(scope, &ctx->scopes, struct hlsl_scope, entry) + { + LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry) + { + if (var->last_read) + var->is_read = true; + } + } +} + struct register_allocator { struct allocation @@ -5286,7 +5301,7 @@ static void hlsl_calculate_buffer_offset(struct hlsl_ctx *ctx, struct hlsl_ir_va TRACE("Allocated buffer offset %u to %s.\n", var->buffer_offset, var->name); buffer->size = max(buffer->size, var->buffer_offset + var_reg_size); - if (var->last_read) + if (var->is_read) buffer->used_size = max(buffer->used_size, var->buffer_offset + var_reg_size); } @@ -7726,6 +7741,7 @@ static void process_entry_function(struct hlsl_ctx *ctx, struct hlsl_ir_function while (hlsl_transform_ir(ctx, dce, body, NULL)); compute_liveness(ctx, entry_func); + mark_vars_usage(ctx); transform_derefs(ctx, mark_indexable_vars, body); diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index ff86970d..d0ca6e8d 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3864,7 +3864,7 @@ static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc) { uint32_t flags = 0; - if (var->last_read) + if (var->is_read) flags |= D3D_SVF_USED; put_u32(&buffer, 0); /* name */