vkd3d-shader/ir: Store the temporary register count in struct vsir_program.

This commit is contained in:
Henri Verbeet 2024-01-17 21:28:23 +01:00 committed by Alexandre Julliard
parent 94ca46916a
commit adc02eada8
Notes: Alexandre Julliard 2024-01-22 22:53:09 +01:00
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/585
5 changed files with 16 additions and 15 deletions

View File

@ -765,13 +765,13 @@ static void record_constant_register(struct vkd3d_shader_sm1_parser *sm1,
static void shader_sm1_scan_register(struct vkd3d_shader_sm1_parser *sm1,
const struct vkd3d_shader_register *reg, unsigned int mask, bool from_def)
{
struct vkd3d_shader_desc *desc = &sm1->p.shader_desc;
struct vsir_program *program = &sm1->p.program;
uint32_t register_index = reg->idx[0].offset;
switch (reg->type)
{
case VKD3DSPR_TEMP:
desc->temp_count = max(desc->temp_count, register_index + 1);
program->temp_count = max(program->temp_count, register_index + 1);
break;
case VKD3DSPR_CONST:

View File

@ -2369,7 +2369,7 @@ static void vsir_validate_register(struct validation_context *ctx,
/* SM1-3 shaders do not include a DCL_TEMPS instruction. */
if (ctx->program->shader_version.major <= 3)
temp_count = ctx->parser->shader_desc.temp_count;
temp_count = ctx->program->temp_count;
if (reg->type >= VKD3DSPR_COUNT)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_REGISTER_TYPE, "Invalid register type %#x.",
@ -2421,10 +2421,10 @@ static void vsir_validate_register(struct validation_context *ctx,
break;
}
/* parser->shader_desc.temp_count might be smaller then
* temp_count if the parser made a mistake; we still don't
* want to overflow the array. */
if (reg->idx[0].offset >= ctx->parser->shader_desc.temp_count)
/* program->temp_count might be smaller then temp_count if the
* parser made a mistake; we still don't want to overflow the
* array. */
if (reg->idx[0].offset >= ctx->program->temp_count)
break;
data = &ctx->temps[reg->idx[0].offset];
@ -2788,9 +2788,10 @@ static void vsir_validate_instruction(struct validation_context *ctx)
vsir_validate_src_count(ctx, instruction, 0);
if (ctx->dcl_temps_found)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_DUPLICATE_DCL_TEMPS, "Duplicate DCL_TEMPS instruction.");
if (instruction->declaration.count > ctx->parser->shader_desc.temp_count)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DCL_TEMPS, "Invalid DCL_TEMPS count %u, expected at most %u.",
instruction->declaration.count, ctx->parser->shader_desc.temp_count);
if (instruction->declaration.count > ctx->program->temp_count)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DCL_TEMPS,
"Invalid DCL_TEMPS count %u, expected at most %u.",
instruction->declaration.count, ctx->program->temp_count);
ctx->dcl_temps_found = true;
ctx->temp_count = instruction->declaration.count;
break;
@ -3005,7 +3006,7 @@ enum vkd3d_result vsir_validate(struct vkd3d_shader_parser *parser)
if (!(parser->config_flags & VKD3D_SHADER_CONFIG_FLAG_FORCE_VALIDATION))
return VKD3D_OK;
if (!(ctx.temps = vkd3d_calloc(parser->shader_desc.temp_count, sizeof(*ctx.temps))))
if (!(ctx.temps = vkd3d_calloc(ctx.program->temp_count, sizeof(*ctx.temps))))
goto fail;
if (!(ctx.ssas = vkd3d_calloc(ctx.program->ssa_count, sizeof(*ctx.ssas))))

View File

@ -9687,8 +9687,8 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
if ((result = vkd3d_shader_normalise(parser, compile_info)) < 0)
return result;
if (parser->shader_desc.temp_count)
spirv_compiler_emit_temps(compiler, parser->shader_desc.temp_count);
if (program->temp_count)
spirv_compiler_emit_temps(compiler, program->temp_count);
if (program->ssa_count)
spirv_compiler_allocate_ssa_register_ids(compiler, program->ssa_count);

View File

@ -1072,7 +1072,7 @@ static void shader_sm4_read_declaration_count(struct vkd3d_shader_instruction *i
{
ins->declaration.count = *tokens;
if (opcode == VKD3D_SM4_OP_DCL_TEMPS)
priv->p.shader_desc.temp_count = max(priv->p.shader_desc.temp_count, *tokens);
priv->p.program.temp_count = max(priv->p.program.temp_count, *tokens);
}
static void shader_sm4_read_declaration_dst(struct vkd3d_shader_instruction *ins, uint32_t opcode,

View File

@ -1022,7 +1022,6 @@ struct vkd3d_shader_desc
unsigned int input_control_point_count, output_control_point_count;
uint32_t temp_count;
unsigned int block_count;
struct
@ -1272,6 +1271,7 @@ struct vsir_program
struct vkd3d_shader_version shader_version;
struct vkd3d_shader_instruction_array instructions;
unsigned int temp_count;
unsigned int ssa_count;
bool use_vocp;
};