From: Giovanni Mascellani gmascellani@codeweavers.com
--- libs/vkd3d-shader/ir.c | 27 ++++++++++++++++++++++++ libs/vkd3d-shader/vkd3d_shader_private.h | 1 + 2 files changed, 28 insertions(+)
diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 80eb06bdb..49b5ea4a1 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -1467,6 +1467,8 @@ struct validation_context { struct vkd3d_shader_parser *parser; size_t instruction_idx; + bool dcl_temps_found; + unsigned int temp_count; };
static void VKD3D_PRINTF_FUNC(3, 4) validator_error(struct validation_context *ctx, @@ -1517,6 +1519,25 @@ static void vsir_validate_register(struct validation_context *ctx, validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX, "Unused index %u has offset %#x and non-NULL relative address.", i, reg->idx[i].offset); } + + switch (reg->type) + { + case VKD3DSPR_TEMP: + if (reg->idx_count != 1) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX_COUNT, "Invalid index count %u for a TEMP register.", + reg->idx_count); + + if (reg->idx_count >= 1 && reg->idx[0].rel_addr) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX, "Non-NULL relative address for a TEMP register."); + + if (reg->idx_count >= 1 && reg->idx[0].offset >= ctx->temp_count) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX, "TEMP register index %u exceeds the declared count %u.", + reg->idx[0].offset, ctx->temp_count); + break; + + default: + break; + } }
static void vsir_validate_dst_param(struct validation_context *ctx, @@ -1603,6 +1624,12 @@ static void vsir_validate_instruction(struct validation_context *ctx) case VKD3DSIH_DCL_TEMPS: vsir_validate_dst_count(ctx, instruction, 0); vsir_validate_src_count(ctx, instruction, 0); + /* TODO Check that each phase in a hull shader has a at + * most one occurrence. */ + if (ctx->dcl_temps_found && ctx->parser->shader_version.type != VKD3D_SHADER_TYPE_HULL) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_DUPLICATE_DCL_TEMPS, "Duplicate DCL_TEMPS instruction."); + ctx->dcl_temps_found = true; + ctx->temp_count = instruction->declaration.count; break;
default: diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index e57cb44c5..bfb8edb5b 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -205,6 +205,7 @@ enum vkd3d_shader_error VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX = 9011, VKD3D_SHADER_ERROR_VSIR_INVALID_DEST_COUNT = 9012, VKD3D_SHADER_ERROR_VSIR_INVALID_SOURCE_COUNT = 9013, + VKD3D_SHADER_ERROR_VSIR_DUPLICATE_DCL_TEMPS = 9014, };
enum vkd3d_shader_opcode