From f7fab09a07b4196eb68c31ff42057f10b3e55cb1 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: --- .../compiler/brw_nir_lower_shader_calls.c | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/intel/compiler/brw_nir_lower_shader_calls.c b/src/intel/compiler/brw_nir_lower_shader_calls.c index 149128facd6..d4b2cf88ddb 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;