From 87f6095557170dcaa91ae54ea084ff1cc2d8220d Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Tue, 19 Jul 2022 22:04:35 +0300 Subject: [PATCH] intel/nir/rt: change scratch check validation It's very unfortunate that we have the RT scratch being conflated with the usual scratch. In our implementation those are 2 different buffers. The usual scratch access are done through the scratch surface state (delivered through thread payload), while RT scratch (which outlives thread dispatch with shader calls) is its own buffer. So checking the NIR scratch size makes no sense as we can have normal scratch accesses completely unrelated to RT scratch accesses. This change switches the validation by looking at whether the scratch base pointer intrinsic is being used (which is what we use/abuse to implement RT scratch). Signed-off-by: Lionel Landwerlin Fixes: c78be5da300ae3 ("intel/fs: lower ray query intrinsics") Reviewed-by: Ivan Briano Part-of: (cherry picked from commit f7fab09a07b4196eb68c31ff42057f10b3e55cb1) --- .pick_status.json | 2 +- .../compiler/brw_nir_lower_shader_calls.c | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 95a52ca3ffb..4d0b01fb2c2 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1039,7 +1039,7 @@ "description": "intel/nir/rt: change scratch check validation", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "c78be5da300ae386a12b91a22efb064335e2043a" }, diff --git a/src/intel/compiler/brw_nir_lower_shader_calls.c b/src/intel/compiler/brw_nir_lower_shader_calls.c index 9a7f330e70c..90beab18dc9 100644 --- a/src/intel/compiler/brw_nir_lower_shader_calls.c +++ b/src/intel/compiler/brw_nir_lower_shader_calls.c @@ -25,6 +25,28 @@ #include "brw_nir_rt_builder.h" #include "nir_phi_builder.h" +UNUSED static bool +no_load_scratch_base_ptr_intrinsic(nir_shader *shader) +{ + nir_foreach_function(func, shader) { + if (!func->impl) + continue; + + nir_foreach_block(block, func->impl) { + nir_foreach_instr(instr, block) { + if (instr->type != nir_instr_type_intrinsic) + continue; + + nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); + if (intrin->intrinsic == nir_intrinsic_load_scratch_base_ptr) + return false; + } + } + } + + return true; +} + /** Insert the appropriate return instruction at the end of the shader */ void brw_nir_lower_shader_returns(nir_shader *shader) @@ -46,7 +68,7 @@ brw_nir_lower_shader_returns(nir_shader *shader) * This isn't needed for ray-gen shaders because they end the thread and * never return to the calling trampoline shader. */ - assert(shader->scratch_size == 0); + assert(no_load_scratch_base_ptr_intrinsic(shader)); if (shader->info.stage != MESA_SHADER_RAYGEN) shader->scratch_size = BRW_BTD_STACK_CALLEE_DATA_SIZE;