mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/hlsl: Use a simple counter for indexable temps.
This commit is contained in:
committed by
Henri Verbeet
parent
8db9465693
commit
a44d79a13c
Notes:
Henri Verbeet
2025-09-04 14:12:02 +02:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1713
@@ -1187,8 +1187,8 @@ struct hlsl_ctx
|
|||||||
} constant_defs;
|
} constant_defs;
|
||||||
/* 'c' registers where the constants expected by SM2 sincos are stored. */
|
/* 'c' registers where the constants expected by SM2 sincos are stored. */
|
||||||
struct hlsl_reg d3dsincosconst1, d3dsincosconst2;
|
struct hlsl_reg d3dsincosconst1, d3dsincosconst2;
|
||||||
/* Number of allocated SSA and temp IDs, used in translation to vsir. */
|
/* Number of allocated registers, used in translation to vsir. */
|
||||||
unsigned int ssa_count, temp_count;
|
unsigned int ssa_count, temp_count, indexable_temp_count;
|
||||||
|
|
||||||
/* Number of threads to be executed (on the X, Y, and Z dimensions) in a single thread group in
|
/* Number of threads to be executed (on the X, Y, and Z dimensions) in a single thread group in
|
||||||
* compute shader profiles. It is set using the numthreads() attribute in the entry point. */
|
* compute shader profiles. It is set using the numthreads() attribute in the entry point. */
|
||||||
|
@@ -5931,11 +5931,7 @@ struct register_allocator
|
|||||||
} *allocations;
|
} *allocations;
|
||||||
size_t count, capacity;
|
size_t count, capacity;
|
||||||
|
|
||||||
/* Indexable temps are allocated separately and always keep their index regardless of their
|
/* Total number of registers allocated so far. */
|
||||||
* lifetime. */
|
|
||||||
uint32_t indexable_count;
|
|
||||||
|
|
||||||
/* Total number of registers allocated so far. Used to declare sm4 temp count. */
|
|
||||||
uint32_t reg_count;
|
uint32_t reg_count;
|
||||||
|
|
||||||
/* Special flag so allocations that can share registers prioritize those
|
/* Special flag so allocations that can share registers prioritize those
|
||||||
@@ -6099,18 +6095,14 @@ static struct hlsl_reg allocate_numeric_registers_for_type(struct hlsl_ctx *ctx,
|
|||||||
unsigned int first_write, unsigned int last_read, const struct hlsl_type *type)
|
unsigned int first_write, unsigned int last_read, const struct hlsl_type *type)
|
||||||
{
|
{
|
||||||
unsigned int reg_size = type->reg_size[HLSL_REGSET_NUMERIC];
|
unsigned int reg_size = type->reg_size[HLSL_REGSET_NUMERIC];
|
||||||
struct hlsl_reg ret;
|
|
||||||
|
|
||||||
/* FIXME: We could potentially pack structs or arrays more efficiently... */
|
/* FIXME: We could potentially pack structs or arrays more efficiently... */
|
||||||
|
|
||||||
if (type->class <= HLSL_CLASS_VECTOR)
|
if (type->class <= HLSL_CLASS_VECTOR)
|
||||||
ret = allocate_register(ctx, allocator, first_write, last_read,
|
return allocate_register(ctx, allocator, first_write, last_read,
|
||||||
type->e.numeric.dimx, type->e.numeric.dimx, 0, false, false);
|
type->e.numeric.dimx, type->e.numeric.dimx, 0, false, false);
|
||||||
else
|
else
|
||||||
ret = allocate_range(ctx, allocator, first_write, last_read, reg_size, 0, false);
|
return allocate_range(ctx, allocator, first_write, last_read, reg_size, 0, false);
|
||||||
if (allocator->type == VKD3DSPR_TEMP)
|
|
||||||
ctx->temp_count = max(ctx->temp_count, ret.id + ret.allocation_size);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *debug_register(struct hlsl_reg reg, const struct hlsl_type *type)
|
static const char *debug_register(struct hlsl_reg reg, const struct hlsl_type *type)
|
||||||
@@ -6275,8 +6267,7 @@ static void calculate_resource_register_counts(struct hlsl_ctx *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void allocate_instr_temp_register(struct hlsl_ctx *ctx,
|
static void allocate_instr_temp_register(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr)
|
||||||
struct hlsl_ir_node *instr, struct register_allocator *allocator)
|
|
||||||
{
|
{
|
||||||
unsigned int dst_writemask = 0;
|
unsigned int dst_writemask = 0;
|
||||||
bool is_per_component = false;
|
bool is_per_component = false;
|
||||||
@@ -6322,8 +6313,6 @@ static void allocate_instr_temp_register(struct hlsl_ctx *ctx,
|
|||||||
instr->reg.allocated = true;
|
instr->reg.allocated = true;
|
||||||
instr->reg.type = VKD3DSPR_TEMP;
|
instr->reg.type = VKD3DSPR_TEMP;
|
||||||
instr->reg.id = ctx->temp_count++;
|
instr->reg.id = ctx->temp_count++;
|
||||||
|
|
||||||
record_allocation(ctx, allocator, ctx->temp_count - 1, VKD3DSP_WRITEMASK_ALL, 1, UINT_MAX, 0, false);
|
|
||||||
}
|
}
|
||||||
else if (is_per_component)
|
else if (is_per_component)
|
||||||
{
|
{
|
||||||
@@ -6332,8 +6321,6 @@ static void allocate_instr_temp_register(struct hlsl_ctx *ctx,
|
|||||||
instr->reg.allocated = true;
|
instr->reg.allocated = true;
|
||||||
instr->reg.type = VKD3DSPR_TEMP;
|
instr->reg.type = VKD3DSPR_TEMP;
|
||||||
instr->reg.id = ctx->temp_count++;
|
instr->reg.id = ctx->temp_count++;
|
||||||
|
|
||||||
record_allocation(ctx, allocator, ctx->temp_count - 1, VKD3DSP_WRITEMASK_ALL, 1, UINT_MAX, 0, false);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -6348,8 +6335,7 @@ static void allocate_instr_temp_register(struct hlsl_ctx *ctx,
|
|||||||
debug_register(instr->reg, instr->data_type), instr->index, instr->last_read);
|
debug_register(instr->reg, instr->data_type), instr->index, instr->last_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void allocate_variable_temp_register(struct hlsl_ctx *ctx,
|
static void allocate_variable_temp_register(struct hlsl_ctx *ctx, struct hlsl_ir_var *var)
|
||||||
struct hlsl_ir_var *var, struct register_allocator *allocator)
|
|
||||||
{
|
{
|
||||||
struct hlsl_reg *reg = &var->regs[HLSL_REGSET_NUMERIC];
|
struct hlsl_reg *reg = &var->regs[HLSL_REGSET_NUMERIC];
|
||||||
|
|
||||||
@@ -6360,7 +6346,7 @@ static void allocate_variable_temp_register(struct hlsl_ctx *ctx,
|
|||||||
{
|
{
|
||||||
if (var->indexable)
|
if (var->indexable)
|
||||||
{
|
{
|
||||||
reg->id = allocator->indexable_count++;
|
reg->id = ctx->indexable_temp_count++;
|
||||||
reg->allocation_size = 1;
|
reg->allocation_size = 1;
|
||||||
reg->writemask = 0;
|
reg->writemask = 0;
|
||||||
reg->allocated = true;
|
reg->allocated = true;
|
||||||
@@ -6376,9 +6362,6 @@ static void allocate_variable_temp_register(struct hlsl_ctx *ctx,
|
|||||||
reg->writemask = vkd3d_write_mask_from_component_count(var->data_type->e.numeric.dimx);
|
reg->writemask = vkd3d_write_mask_from_component_count(var->data_type->e.numeric.dimx);
|
||||||
reg->allocated = true;
|
reg->allocated = true;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < reg->allocation_size; ++i)
|
|
||||||
record_allocation(ctx, allocator, ctx->temp_count + i, VKD3DSP_WRITEMASK_ALL, 1, UINT_MAX, 0, false);
|
|
||||||
|
|
||||||
ctx->temp_count += reg->allocation_size;
|
ctx->temp_count += reg->allocation_size;
|
||||||
|
|
||||||
TRACE("Allocated %s to %s (liveness %u-%u).\n", var->name,
|
TRACE("Allocated %s to %s (liveness %u-%u).\n", var->name,
|
||||||
@@ -6387,8 +6370,7 @@ static void allocate_variable_temp_register(struct hlsl_ctx *ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx,
|
static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block)
|
||||||
struct hlsl_block *block, struct register_allocator *allocator)
|
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *instr;
|
struct hlsl_ir_node *instr;
|
||||||
|
|
||||||
@@ -6398,15 +6380,15 @@ static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx,
|
|||||||
if (ctx->profile->major_version >= 4 && instr->type == HLSL_IR_CONSTANT)
|
if (ctx->profile->major_version >= 4 && instr->type == HLSL_IR_CONSTANT)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
allocate_instr_temp_register(ctx, instr, allocator);
|
allocate_instr_temp_register(ctx, instr);
|
||||||
|
|
||||||
switch (instr->type)
|
switch (instr->type)
|
||||||
{
|
{
|
||||||
case HLSL_IR_IF:
|
case HLSL_IR_IF:
|
||||||
{
|
{
|
||||||
struct hlsl_ir_if *iff = hlsl_ir_if(instr);
|
struct hlsl_ir_if *iff = hlsl_ir_if(instr);
|
||||||
allocate_temp_registers_recurse(ctx, &iff->then_block, allocator);
|
allocate_temp_registers_recurse(ctx, &iff->then_block);
|
||||||
allocate_temp_registers_recurse(ctx, &iff->else_block, allocator);
|
allocate_temp_registers_recurse(ctx, &iff->else_block);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6415,21 +6397,21 @@ static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx,
|
|||||||
struct hlsl_ir_load *load = hlsl_ir_load(instr);
|
struct hlsl_ir_load *load = hlsl_ir_load(instr);
|
||||||
/* We need to at least allocate a variable for undefs.
|
/* We need to at least allocate a variable for undefs.
|
||||||
* FIXME: We should probably find a way to remove them instead. */
|
* FIXME: We should probably find a way to remove them instead. */
|
||||||
allocate_variable_temp_register(ctx, load->src.var, allocator);
|
allocate_variable_temp_register(ctx, load->src.var);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case HLSL_IR_LOOP:
|
case HLSL_IR_LOOP:
|
||||||
{
|
{
|
||||||
struct hlsl_ir_loop *loop = hlsl_ir_loop(instr);
|
struct hlsl_ir_loop *loop = hlsl_ir_loop(instr);
|
||||||
allocate_temp_registers_recurse(ctx, &loop->body, allocator);
|
allocate_temp_registers_recurse(ctx, &loop->body);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case HLSL_IR_STORE:
|
case HLSL_IR_STORE:
|
||||||
{
|
{
|
||||||
struct hlsl_ir_store *store = hlsl_ir_store(instr);
|
struct hlsl_ir_store *store = hlsl_ir_store(instr);
|
||||||
allocate_variable_temp_register(ctx, store->lhs.var, allocator);
|
allocate_variable_temp_register(ctx, store->lhs.var);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6440,7 +6422,7 @@ static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx,
|
|||||||
|
|
||||||
LIST_FOR_EACH_ENTRY(c, &s->cases, struct hlsl_ir_switch_case, entry)
|
LIST_FOR_EACH_ENTRY(c, &s->cases, struct hlsl_ir_switch_case, entry)
|
||||||
{
|
{
|
||||||
allocate_temp_registers_recurse(ctx, &c->body, allocator);
|
allocate_temp_registers_recurse(ctx, &c->body);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -6756,10 +6738,11 @@ static void allocate_const_registers(struct hlsl_ctx *ctx, struct hlsl_block *bo
|
|||||||
* does not handle constants. */
|
* does not handle constants. */
|
||||||
static void allocate_temp_registers(struct hlsl_ctx *ctx, struct hlsl_block *body, struct list *semantic_vars)
|
static void allocate_temp_registers(struct hlsl_ctx *ctx, struct hlsl_block *body, struct list *semantic_vars)
|
||||||
{
|
{
|
||||||
struct register_allocator allocator = {.type = VKD3DSPR_TEMP};
|
|
||||||
struct hlsl_scope *scope;
|
struct hlsl_scope *scope;
|
||||||
struct hlsl_ir_var *var;
|
struct hlsl_ir_var *var;
|
||||||
|
|
||||||
|
ctx->indexable_temp_count = 0;
|
||||||
|
|
||||||
/* Reset variable temp register allocations. */
|
/* Reset variable temp register allocations. */
|
||||||
LIST_FOR_EACH_ENTRY(scope, &ctx->scopes, struct hlsl_scope, entry)
|
LIST_FOR_EACH_ENTRY(scope, &ctx->scopes, struct hlsl_scope, entry)
|
||||||
{
|
{
|
||||||
@@ -6777,16 +6760,13 @@ static void allocate_temp_registers(struct hlsl_ctx *ctx, struct hlsl_block *bod
|
|||||||
{
|
{
|
||||||
if (var->is_output_semantic)
|
if (var->is_output_semantic)
|
||||||
{
|
{
|
||||||
record_allocation(ctx, &allocator, 0, VKD3DSP_WRITEMASK_ALL,
|
|
||||||
var->first_write, UINT_MAX, 0, false);
|
|
||||||
ctx->temp_count = 1;
|
ctx->temp_count = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allocate_temp_registers_recurse(ctx, body, &allocator);
|
allocate_temp_registers_recurse(ctx, body);
|
||||||
vkd3d_free(allocator.allocations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum vkd3d_shader_interpolation_mode sm4_get_interpolation_mode(struct hlsl_type *type,
|
static enum vkd3d_shader_interpolation_mode sm4_get_interpolation_mode(struct hlsl_type *type,
|
||||||
|
Reference in New Issue
Block a user