vkd3d-shader/hlsl: Track whether a variable is read in any entry function.

This commit is contained in:
Shaun Ren 2024-10-04 20:15:57 -04:00 committed by Henri Verbeet
parent f15a1c0b23
commit 5f8570b933
Notes: Henri Verbeet 2024-10-15 17:03:41 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1154
3 changed files with 20 additions and 2 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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 */