vkd3d-shader/ir: Check that all instructions appear in a block.

This commit is contained in:
Giovanni Mascellani 2024-01-12 11:20:26 +01:00 committed by Alexandre Julliard
parent 72e2eeaf14
commit fb6409bda1
Notes: Alexandre Julliard 2024-01-23 23:03:03 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/559

View File

@ -2312,6 +2312,7 @@ struct validation_context
CF_TYPE_STRUCTURED,
CF_TYPE_BLOCKS,
} cf_type;
bool inside_block;
struct validation_context_temp_data
{
@ -2781,6 +2782,33 @@ static void vsir_validate_instruction(struct validation_context *ctx)
ctx->cf_type = CF_TYPE_STRUCTURED;
}
if (ctx->cf_type == CF_TYPE_BLOCKS && !vsir_instruction_is_dcl(instruction))
{
switch (instruction->handler_idx)
{
case VKD3DSIH_LABEL:
if (ctx->inside_block)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "Invalid LABEL instruction inside a block.");
ctx->inside_block = true;
break;
case VKD3DSIH_RET:
case VKD3DSIH_BRANCH:
case VKD3DSIH_SWITCH_MONOLITHIC:
if (!ctx->inside_block)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "Invalid instruction %#x outside any block.",
instruction->handler_idx);
ctx->inside_block = false;
break;
default:
if (!ctx->inside_block)
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "Invalid instruction %#x outside any block.",
instruction->handler_idx);
break;
}
}
switch (instruction->handler_idx)
{
case VKD3DSIH_DCL_TEMPS:
@ -3020,6 +3048,9 @@ enum vkd3d_result vsir_validate(struct vkd3d_shader_parser *parser)
if (ctx.depth != 0)
validator_error(&ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "%zu nested blocks were not closed.", ctx.depth);
if (ctx.inside_block)
validator_error(&ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "Last block was not closed.");
for (i = 0; i < ctx.program->ssa_count; ++i)
{
struct validation_context_ssa_data *data = &ctx.ssas[i];