From 72354b0e9dd338f28e0422be81ccb31cf241a36c Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 6 Aug 2020 15:16:26 -0500 Subject: [PATCH] intel/rt: Add a helper to create a trivial return shader These are required for ray-tracing. There are many cases where the ray-tracing hardware may decide to execute some but not all of our shaders. In these cases, it needs a shader to execute at the end which will pop the stack back to the shader which called traceRay(). Reviewed-by: Caio Marcelo de Oliveira Filho Part-of: --- .../compiler/brw_nir_lower_shader_calls.c | 23 +++++++++++++++++++ src/intel/compiler/brw_nir_rt.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/src/intel/compiler/brw_nir_lower_shader_calls.c b/src/intel/compiler/brw_nir_lower_shader_calls.c index 506a71933e5..c4f67a6c86b 100644 --- a/src/intel/compiler/brw_nir_lower_shader_calls.c +++ b/src/intel/compiler/brw_nir_lower_shader_calls.c @@ -1181,3 +1181,26 @@ brw_nir_lower_shader_calls(nir_shader *shader, return true; } + +/** Creates a trivial return shader + * + * This is a callable shader that doesn't really do anything. It just loads + * the resume address from the stack and does a return. + */ +nir_shader * +brw_nir_create_trivial_return_shader(const struct brw_compiler *compiler, + void *mem_ctx) +{ + const nir_shader_compiler_options *nir_options = + compiler->glsl_compiler_options[MESA_SHADER_CALLABLE].NirOptions; + + nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_CALLABLE, + nir_options, + "RT Trivial Return"); + ralloc_steal(mem_ctx, b.shader); + nir_shader *nir = b.shader; + + NIR_PASS_V(nir, brw_nir_lower_shader_returns); + + return nir; +} diff --git a/src/intel/compiler/brw_nir_rt.h b/src/intel/compiler/brw_nir_rt.h index a474498be20..88763183875 100644 --- a/src/intel/compiler/brw_nir_rt.h +++ b/src/intel/compiler/brw_nir_rt.h @@ -59,6 +59,10 @@ bool brw_nir_lower_shader_calls(nir_shader *shader, void brw_nir_lower_rt_intrinsics(nir_shader *shader, const struct gen_device_info *devinfo); +nir_shader * +brw_nir_create_trivial_return_shader(const struct brw_compiler *compiler, + void *mem_ctx); + #ifdef __cplusplus } #endif