mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/ir: Check that IF blocks are correctly nested.
This commit is contained in:
parent
0a7e200f89
commit
2f7d52dba4
Notes:
Alexandre Julliard
2023-11-07 22:40:09 +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/444
@ -1477,6 +1477,10 @@ struct validation_context
|
||||
struct vkd3d_shader_parser *parser;
|
||||
size_t instruction_idx;
|
||||
bool dcl_temps_found;
|
||||
|
||||
enum vkd3d_shader_opcode *blocks;
|
||||
size_t depth;
|
||||
size_t blocks_capacity;
|
||||
};
|
||||
|
||||
static void VKD3D_PRINTF_FUNC(3, 4) validator_error(struct validation_context *ctx,
|
||||
@ -1637,6 +1641,32 @@ static void vsir_validate_instruction(struct validation_context *ctx)
|
||||
instruction->declaration.count, ctx->parser->shader_desc.temp_count);
|
||||
break;
|
||||
|
||||
case VKD3DSIH_IF:
|
||||
vsir_validate_dst_count(ctx, instruction, 0);
|
||||
vsir_validate_src_count(ctx, instruction, 1);
|
||||
if (!vkd3d_array_reserve((void **)&ctx->blocks, &ctx->blocks_capacity, ctx->depth + 1, sizeof(*ctx->blocks)))
|
||||
return;
|
||||
ctx->blocks[ctx->depth++] = instruction->handler_idx;
|
||||
break;
|
||||
|
||||
case VKD3DSIH_ELSE:
|
||||
vsir_validate_dst_count(ctx, instruction, 0);
|
||||
vsir_validate_src_count(ctx, instruction, 0);
|
||||
if (ctx->depth == 0 || ctx->blocks[ctx->depth - 1] != VKD3DSIH_IF)
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INSTRUCTION_NESTING, "ELSE instruction doesn't terminate IF block.");
|
||||
else
|
||||
ctx->blocks[ctx->depth - 1] = instruction->handler_idx;
|
||||
break;
|
||||
|
||||
case VKD3DSIH_ENDIF:
|
||||
vsir_validate_dst_count(ctx, instruction, 0);
|
||||
vsir_validate_src_count(ctx, instruction, 0);
|
||||
if (ctx->depth == 0 || (ctx->blocks[ctx->depth - 1] != VKD3DSIH_IF && ctx->blocks[ctx->depth - 1] != VKD3DSIH_ELSE))
|
||||
validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INSTRUCTION_NESTING, "ENDIF instruction doesn't terminate IF/ELSE block.");
|
||||
else
|
||||
--ctx->depth;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1651,4 +1681,9 @@ void vsir_validate(struct vkd3d_shader_parser *parser)
|
||||
|
||||
for (ctx.instruction_idx = 0; ctx.instruction_idx < parser->instructions.count; ++ctx.instruction_idx)
|
||||
vsir_validate_instruction(&ctx);
|
||||
|
||||
if (ctx.depth != 0)
|
||||
validator_error(&ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INSTRUCTION_NESTING, "%zu nested blocks were not closed.", ctx.depth);
|
||||
|
||||
free(ctx.blocks);
|
||||
}
|
||||
|
@ -210,6 +210,7 @@ enum vkd3d_shader_error
|
||||
VKD3D_SHADER_ERROR_VSIR_DUPLICATE_DCL_TEMPS = 9013,
|
||||
VKD3D_SHADER_ERROR_VSIR_INVALID_DCL_TEMPS = 9014,
|
||||
VKD3D_SHADER_ERROR_VSIR_INVALID_INDEX = 9015,
|
||||
VKD3D_SHADER_ERROR_VSIR_INVALID_INSTRUCTION_NESTING = 9016,
|
||||
};
|
||||
|
||||
enum vkd3d_shader_opcode
|
||||
|
Loading…
x
Reference in New Issue
Block a user