From 8cf5581e925ed0d85d5a4a78984d821870492964 Mon Sep 17 00:00:00 2001 From: Sviatoslav Peleshko Date: Fri, 5 May 2023 10:00:48 +0300 Subject: [PATCH] nir/lower_shader_calls: Fix cursor if broken after nir_cf_extract() call Fixes: e2dadda3 ("Revert "nir/lower_shader_calls: put inserted instructions into a dummy block") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8978 Signed-off-by: Sviatoslav Peleshko Reviewed-by: Konstantin Seurer Part-of: (cherry picked from commit 08e95f8f8e9eb3020a564db1bf364289fa1b138c) --- .pick_status.json | 2 +- src/compiler/nir/nir_lower_shader_calls.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index 53f4beda572..3d2f0426a99 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2524,7 +2524,7 @@ "description": "nir/lower_shader_calls: Fix cursor if broken after nir_cf_extract() call", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "e2dadda35f87af08358f0ea43a12434c1626ea82" }, diff --git a/src/compiler/nir/nir_lower_shader_calls.c b/src/compiler/nir/nir_lower_shader_calls.c index aac15f93fe2..8ba3d1c3b78 100644 --- a/src/compiler/nir/nir_lower_shader_calls.c +++ b/src/compiler/nir/nir_lower_shader_calls.c @@ -1115,6 +1115,21 @@ found_resume: nir_after_cf_list(child_list)); } + /* If the resume instruction is in the first block of the child_list, + * and the cursor is still before that block, the nir_cf_extract() may + * extract the block object pointed by the cursor, and instead create + * a new one for the code before the resume. In such case the cursor + * will be broken, as it will point to a block which is no longer + * in a function. + * + * Luckily, in both cases when this is possible, the intended cursor + * position is right before the child_list, so we can fix the cursor here. + */ + if (child_list_contains_cursor && + b->cursor.option == nir_cursor_before_block && + b->cursor.block->cf_node.parent == NULL) + b->cursor = nir_before_cf_list(child_list); + if (cursor_is_after_jump(b->cursor)) { /* If the resume instruction is in a loop, it's possible cf_list ends * in a break or continue instruction, in which case we don't want to