intel/rt: Add return instructions at the end of ray-tracing shaders

Each callable ray-tracing shader shader stage has to perform a return
operation at the end.  In the case of raygen shaders, it retires the
bindless thread because the raygen shader is always the root of the call
tree.  In the case of any-hit shaders, the default action is accep the
hit.  For callable, miss, and closest-hit shaders, it does a return
operation.  The assumption is that the calling shader has placed a
BINDLESS_SHADER_RECORD address for the return in the first QWord of the
callee's scratch space.  The return operation simply loads this value
and calls a btd_spawn intrinsic to jump to it.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7356>
This commit is contained in:
Jason Ekstrand
2020-08-06 13:53:34 -05:00
committed by Marge Bot
parent 49778a7253
commit ca88cd8e5a
7 changed files with 158 additions and 0 deletions

View File

@@ -65,6 +65,50 @@ brw_nir_rt_store_scratch(nir_builder *b, uint32_t offset, unsigned align,
value, write_mask);
}
static inline void
nir_accept_ray_intersection(nir_builder *b)
{
nir_intrinsic_instr *accept =
nir_intrinsic_instr_create(b->shader,
nir_intrinsic_accept_ray_intersection);
nir_builder_instr_insert(b, &accept->instr);
}
static inline void
brw_nir_btd_spawn(nir_builder *b, nir_ssa_def *record_addr)
{
nir_intrinsic_instr *spawn =
nir_intrinsic_instr_create(b->shader,
nir_intrinsic_btd_spawn_intel);
spawn->src[0] = nir_src_for_ssa(nir_load_btd_global_arg_addr_intel(b));
spawn->src[1] = nir_src_for_ssa(record_addr);
nir_builder_instr_insert(b, &spawn->instr);
}
static inline void
brw_nir_btd_retire(nir_builder *b)
{
nir_intrinsic_instr *retire =
nir_intrinsic_instr_create(b->shader,
nir_intrinsic_btd_retire_intel);
nir_builder_instr_insert(b, &retire->instr);
}
/** This is a pseudo-op which does a bindless return
*
* It loads the return address from the stack and calls btd_spawn to spawn the
* resume shader.
*/
static inline void
brw_nir_btd_return(struct nir_builder *b)
{
assert(b->shader->scratch_size == BRW_BTD_STACK_CALLEE_DATA_SIZE);
nir_ssa_def *resume_addr =
brw_nir_rt_load_scratch(b, BRW_BTD_STACK_RESUME_BSR_ADDR_OFFSET,
8 /* align */, 1, 64);
brw_nir_btd_spawn(b, resume_addr);
}
static inline void
assert_def_size(nir_ssa_def *def, unsigned num_components, unsigned bit_size)
{