From 4140b87499a8d684113aaec02f27af90689409a4 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Tue, 24 Oct 2023 20:08:00 -0500 Subject: [PATCH] vkd3d-shader/ir: Validate the DCL_TEMPS instruction. --- libs/vkd3d-shader/ir.c | 29 ++++++++++++++++++++++++ libs/vkd3d-shader/vkd3d_shader_private.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 1b52f866..96d77e99 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -1560,6 +1560,24 @@ static void vsir_validate_src_param(struct validation_context *ctx, src->modifiers); } +static void vsir_validate_dst_count(struct validation_context *ctx, + const struct vkd3d_shader_instruction *instruction, unsigned int count) +{ + if (instruction->dst_count != count) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_DEST_COUNT, + "Invalid destination count %u for an instruction of type %#x, expected %u.", + instruction->dst_count, instruction->handler_idx, count); +} + +static void vsir_validate_src_count(struct validation_context *ctx, + const struct vkd3d_shader_instruction *instruction, unsigned int count) +{ + if (instruction->src_count != count) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_SOURCE_COUNT, + "Invalid source count %u for an instruction of type %#x, expected %u.", + instruction->src_count, instruction->handler_idx, count); +} + static void vsir_validate_instruction(struct validation_context *ctx) { const struct vkd3d_shader_instruction *instruction = &ctx->parser->instructions.elements[ctx->instruction_idx]; @@ -1578,6 +1596,17 @@ static void vsir_validate_instruction(struct validation_context *ctx) validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_HANDLER, "Invalid instruction handler %#x.", instruction->handler_idx); } + + switch (instruction->handler_idx) + { + case VKD3DSIH_DCL_TEMPS: + vsir_validate_dst_count(ctx, instruction, 0); + vsir_validate_src_count(ctx, instruction, 0); + break; + + default: + break; + } } void vsir_validate(struct vkd3d_shader_parser *parser) diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 8e744593..7578820c 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -204,6 +204,8 @@ enum vkd3d_shader_error VKD3D_SHADER_ERROR_VSIR_INVALID_DATA_TYPE = 9008, VKD3D_SHADER_ERROR_VSIR_INVALID_DIMENSION = 9009, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX_COUNT = 9010, + VKD3D_SHADER_ERROR_VSIR_INVALID_DEST_COUNT = 9011, + VKD3D_SHADER_ERROR_VSIR_INVALID_SOURCE_COUNT = 9012, }; enum vkd3d_shader_opcode