llvmpipe: don't assert on exceeding if_stack size

Rather than assert (and otherwise write past the array size), guard against
this (and miscompile the shader), to make the code more robust.
This mimics the behavior of exceeding the cond_stack size (and other similar
stacks) - the if_stack is only used together with the cond_stack, the behavior
should be the same.

Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33338>
This commit is contained in:
Roland Scheidegger
2024-10-15 20:46:05 +02:00
committed by Marge Bot
parent 9cc0b497b3
commit 8aae760144

View File

@@ -2079,7 +2079,11 @@ static void lp_build_skip_branch(struct lp_build_nir_context *bld_base, bool fla
LLVMValueRef any_active = LLVMBuildICmp(builder, LLVMIntNE, bitmask, lp_build_const_int32(gallivm, 0), "any_active");
assert(bld_base->if_stack_size < LP_MAX_TGSI_NESTING);
if (bld_base->if_stack_size >= LP_MAX_TGSI_NESTING) {
bld_base->if_stack_size++;
return;
}
lp_build_if(&bld_base->if_stack[bld_base->if_stack_size], gallivm, any_active);
bld_base->if_stack_size++;
}
@@ -2091,6 +2095,9 @@ static void lp_build_skip_branch_end(struct lp_build_nir_context *bld_base, bool
assert(bld_base->if_stack_size);
bld_base->if_stack_size--;
if (bld_base->if_stack_size >= LP_MAX_TGSI_NESTING)
return;
lp_build_endif(&bld_base->if_stack[bld_base->if_stack_size]);
}