From 76981e5615fae277dd2f2ed0b6f2a455bd7d5fc1 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 11 Jun 2022 19:57:38 -0400 Subject: [PATCH] agx: Handle loop { if { loop { .. } } } We need to push loop nesting to handle this correctly -- at the end of the innermost loop, the correct nesting is 1 (from the if), not 0. Fixes assertion failure in dEQP-GLES2.functional.shaders.struct.local.dynamic_loop_nested_struct_array_fragment,UnexpectedPass dEQP-GLES2.functional.shaders.struct.local.dynamic_loop_nested_struct_array_vertex,UnexpectedPass dEQP-GLES2.functional.shaders.struct.uniform.dynamic_loop_nested_struct_array_fragment,UnexpectedPass dEQP-GLES2.functional.shaders.struct.uniform.dynamic_loop_nested_struct_array_vertex,UnexpectedPass Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index e787ddfc1a4..321c2d437ca 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -1206,7 +1206,8 @@ emit_if(agx_context *ctx, nir_if *nif) static void emit_loop(agx_context *ctx, nir_loop *nloop) { - /* We only track nesting within the innermost loop, so reset */ + /* We only track nesting within the innermost loop, so push and reset */ + unsigned pushed_nesting = ctx->loop_nesting; ctx->loop_nesting = 0; agx_block *popped_break = ctx->break_block; @@ -1246,6 +1247,9 @@ emit_loop(agx_context *ctx, nir_loop *nloop) /* All nested control flow must have finished */ assert(ctx->loop_nesting == 0); + + /* Restore loop nesting (we might be inside an if inside an outer loop) */ + ctx->loop_nesting = pushed_nesting; } /* Before the first control flow structure, the nesting counter (r0l) needs to