diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 8f521e53..8acd769a 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -6180,6 +6180,17 @@ static void vsir_validate_else(struct validation_context *ctx, const struct vkd3 ctx->blocks[ctx->depth - 1] = VKD3DSIH_ELSE; } +static void vsir_validate_endif(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_IF + && ctx->blocks[ctx->depth - 1] != VKD3DSIH_ELSE)) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, + "ENDIF instruction doesn't terminate IF/ELSE 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); @@ -6203,6 +6214,7 @@ static const struct vsir_validator_instruction_desc vsir_validator_instructions[ { [VKD3DSIH_DCL_TEMPS] = {0, 0, vsir_validate_dcl_temps}, [VKD3DSIH_ELSE] = {0, 0, vsir_validate_else}, + [VKD3DSIH_ENDIF] = {0, 0, vsir_validate_endif}, [VKD3DSIH_IF] = {0, 1, vsir_validate_if}, [VKD3DSIH_IFC] = {0, 2, vsir_validate_ifc}, }; @@ -6367,16 +6379,6 @@ static void vsir_validate_instruction(struct validation_context *ctx) switch (instruction->opcode) { - case VKD3DSIH_ENDIF: - 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_IF && ctx->blocks[ctx->depth - 1] != VKD3DSIH_ELSE)) - validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_CONTROL_FLOW, "ENDIF instruction doesn't terminate IF/ELSE block."); - else - --ctx->depth; - break; - case VKD3DSIH_LOOP: vsir_validate_cf_type(ctx, instruction, VSIR_CF_STRUCTURED); vsir_validate_dst_count(ctx, instruction, 0);