vkd3d-shader/ir: Validate instruction handlers.

This commit is contained in:
Giovanni Mascellani 2023-08-29 21:35:01 +02:00 committed by Alexandre Julliard
parent c052cd8998
commit b09cfbda90
Notes: Alexandre Julliard 2023-09-22 22:46:19 +02:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/317
2 changed files with 37 additions and 0 deletions

View File

@ -1302,10 +1302,46 @@ enum vkd3d_result vkd3d_shader_normalise(struct vkd3d_shader_parser *parser,
struct validation_context
{
struct vkd3d_shader_parser *parser;
size_t instruction_idx;
};
static void VKD3D_PRINTF_FUNC(3, 4) validator_error(struct validation_context *ctx,
enum vkd3d_shader_error error, const char *format, ...)
{
struct vkd3d_string_buffer buf;
va_list args;
vkd3d_string_buffer_init(&buf);
va_start(args, format);
vkd3d_string_buffer_vprintf(&buf, format, args);
va_end(args);
vkd3d_shader_parser_error(ctx->parser, error, "instruction %zu: %s", ctx->instruction_idx + 1, buf.buffer);
vkd3d_string_buffer_cleanup(&buf);
}
static void vsir_validate_instruction(struct validation_context *ctx)
{
const struct vkd3d_shader_instruction *instruction = &ctx->parser->instructions.elements[ctx->instruction_idx];
ctx->parser->location = instruction->location;
if (instruction->handler_idx >= VKD3DSIH_INVALID)
{
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_HANDLER, "Invalid instruction handler %#x.",
instruction->handler_idx);
}
}
void vsir_validate(struct vkd3d_shader_parser *parser)
{
struct validation_context ctx = { .parser = parser };
if (!(parser->config_flags & VKD3D_SHADER_CONFIG_FLAG_FORCE_VALIDATION))
return;
for (ctx.instruction_idx = 0; ctx.instruction_idx < parser->instructions.count; ++ctx.instruction_idx)
vsir_validate_instruction(&ctx);
}

View File

@ -183,6 +183,7 @@ enum vkd3d_shader_error
VKD3D_SHADER_WARNING_DXIL_UNHANDLED_INTRINSIC = 8305,
VKD3D_SHADER_ERROR_VSIR_NOT_IMPLEMENTED = 9000,
VKD3D_SHADER_ERROR_VSIR_INVALID_HANDLER = 9001,
};
enum vkd3d_shader_opcode