vkd3d-shader/ir: Avoid direct instruction array access in validation_error().

This commit is contained in:
Francisco Casas
2025-09-01 12:45:24 -04:00
committed by Henri Verbeet
parent 05b5a48c1d
commit 500d54d588
Notes: Henri Verbeet 2025-09-09 15:10:17 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1707

View File

@@ -9057,7 +9057,7 @@ struct validation_context
struct vkd3d_shader_message_context *message_context; struct vkd3d_shader_message_context *message_context;
const struct vsir_program *program; const struct vsir_program *program;
size_t instruction_idx; size_t instruction_idx;
struct vkd3d_shader_location null_location; struct vkd3d_shader_location location;
bool invalid_instruction_idx; bool invalid_instruction_idx;
enum vkd3d_result status; enum vkd3d_result status;
bool dcl_temps_found; bool dcl_temps_found;
@@ -9116,13 +9116,12 @@ static void VKD3D_PRINTF_FUNC(3, 4) validator_error(struct validation_context *c
if (ctx->invalid_instruction_idx) if (ctx->invalid_instruction_idx)
{ {
vkd3d_shader_error(ctx->message_context, &ctx->null_location, error, "%s", buf.buffer); vkd3d_shader_error(ctx->message_context, &ctx->location, error, "%s", buf.buffer);
WARN("VSIR validation error: %s\n", buf.buffer); WARN("VSIR validation error: %s\n", buf.buffer);
} }
else else
{ {
const struct vkd3d_shader_instruction *ins = &ctx->program->instructions.elements[ctx->instruction_idx]; vkd3d_shader_error(ctx->message_context, &ctx->location, error,
vkd3d_shader_error(ctx->message_context, &ins->location, error,
"instruction %zu: %s", ctx->instruction_idx + 1, buf.buffer); "instruction %zu: %s", ctx->instruction_idx + 1, buf.buffer);
WARN("VSIR validation error: instruction %zu: %s\n", ctx->instruction_idx + 1, buf.buffer); WARN("VSIR validation error: instruction %zu: %s\n", ctx->instruction_idx + 1, buf.buffer);
} }
@@ -12029,7 +12028,7 @@ enum vkd3d_result vsir_program_validate(struct vsir_program *program, uint64_t c
{ {
.message_context = message_context, .message_context = message_context,
.program = program, .program = program,
.null_location = {.source_name = source_name}, .location = {.source_name = source_name},
.status = VKD3D_OK, .status = VKD3D_OK,
.phase = VSIR_OP_INVALID, .phase = VSIR_OP_INVALID,
.invalid_instruction_idx = true, .invalid_instruction_idx = true,
@@ -12154,11 +12153,13 @@ enum vkd3d_result vsir_program_validate(struct vsir_program *program, uint64_t c
for (ins = vsir_program_iterator_head(&it); ins && ctx.status != VKD3D_ERROR_OUT_OF_MEMORY; for (ins = vsir_program_iterator_head(&it); ins && ctx.status != VKD3D_ERROR_OUT_OF_MEMORY;
ins = vsir_program_iterator_next(&it)) ins = vsir_program_iterator_next(&it))
{ {
ctx.location = ins->location;
vsir_validate_instruction(&ctx, ins); vsir_validate_instruction(&ctx, ins);
++ctx.instruction_idx; ++ctx.instruction_idx;
} }
ctx.invalid_instruction_idx = true; ctx.invalid_instruction_idx = true;
ctx.location = (struct vkd3d_shader_location){.source_name = source_name};
if (ctx.depth != 0) if (ctx.depth != 0)
validator_error(&ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "%zu nested blocks were not closed.", ctx.depth); validator_error(&ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "%zu nested blocks were not closed.", ctx.depth);