From 92c36615ed9f341e57b5b89f18482e4714ac8c95 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Mon, 6 Nov 2023 13:54:07 +0100 Subject: [PATCH] vkd3d-shader/ir: Check that LOOP blocks are correctly nested. --- libs/vkd3d-shader/ir.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 57180c91..71a23fa0 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -1667,6 +1667,23 @@ static void vsir_validate_instruction(struct validation_context *ctx) --ctx->depth; break; + case VKD3DSIH_LOOP: + vsir_validate_dst_count(ctx, instruction, 0); + vsir_validate_src_count(ctx, instruction, 0); + 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_ENDLOOP: + vsir_validate_dst_count(ctx, instruction, 0); + vsir_validate_src_count(ctx, instruction, 0); + if (ctx->depth == 0 || ctx->blocks[ctx->depth - 1] != VKD3DSIH_LOOP) + validator_error(ctx, VKD3D_SHADER_ERROR_VSIR_INVALID_INSTRUCTION_NESTING, "ENDLOOP instruction doesn't terminate LOOP block."); + else + --ctx->depth; + break; + default: break; }