From 44222ea7397fe4a181f34ba57bdcf4befd541036 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Wed, 11 Sep 2024 13:48:31 +0200 Subject: [PATCH] vkd3d-shader/ir: Introduce a helper for validating ENDREP. --- libs/vkd3d-shader/ir.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index f8529c12..4b79a058 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -6201,6 +6201,16 @@ static void vsir_validate_endloop(struct validation_context *ctx, const struct v --ctx->depth; } +static void vsir_validate_endrep(struct validation_context *ctx, const struct vkd3d_shader_instruction *instruction) +{ + vsir_validate_cf_type(ctx, instruction, VSIR_CF_STRUCTURED); + if (ctx->depth == 0 || ctx->blocks[ctx->depth - 1] != VKD3DSIH_REP) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, + "ENDREP instruction doesn't terminate REP block."); + else + --ctx->depth; +} + static void vsir_validate_if(struct validation_context *ctx, const struct vkd3d_shader_instruction *instruction) { vsir_validate_cf_type(ctx, instruction, VSIR_CF_STRUCTURED); @@ -6239,6 +6249,7 @@ static const struct vsir_validator_instruction_desc vsir_validator_instructions[ [VKD3DSIH_ELSE] = {0, 0, vsir_validate_else}, [VKD3DSIH_ENDIF] = {0, 0, vsir_validate_endif}, [VKD3DSIH_ENDLOOP] = {0, 0, vsir_validate_endloop}, + [VKD3DSIH_ENDREP] = {0, 0, vsir_validate_endrep}, [VKD3DSIH_IF] = {0, 1, vsir_validate_if}, [VKD3DSIH_IFC] = {0, 2, vsir_validate_ifc}, [VKD3DSIH_LOOP] = {0, ~0u, vsir_validate_loop}, @@ -6405,16 +6416,6 @@ static void vsir_validate_instruction(struct validation_context *ctx) switch (instruction->opcode) { - case VKD3DSIH_ENDREP: - vsir_validate_cf_type(ctx, instruction, VSIR_CF_STRUCTURED); - vsir_validate_dst_count(ctx, instruction, 0); - vsir_validate_src_count(ctx, instruction, 0); - if (ctx->depth == 0 || ctx->blocks[ctx->depth - 1] != VKD3DSIH_REP) - validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "ENDREP instruction doesn't terminate REP block."); - else - --ctx->depth; - break; - case VKD3DSIH_SWITCH: vsir_validate_cf_type(ctx, instruction, VSIR_CF_STRUCTURED); vsir_validate_dst_count(ctx, instruction, 0);