Mesa (main): nir: Add lowered vendor independent raytracing intrinsics.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jun 21 21:47:32 UTC 2021


Module: Mesa
Branch: main
Commit: 02c5dc8035b8b03d1abc74074767303951fd0a5b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=02c5dc8035b8b03d1abc74074767303951fd0a5b

Author: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Date:   Tue Apr 20 03:45:22 2021 +0200

nir: Add lowered vendor independent raytracing intrinsics.

For use in a generic nir_lower_shader_calls.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10339>

---

 src/compiler/nir/nir.c                     |  2 ++
 src/compiler/nir/nir_intrinsics.py         | 27 +++++++++++++++++++++++++++
 src/compiler/nir/nir_opt_combine_stores.c  |  4 +++-
 src/compiler/nir/nir_opt_copy_prop_vars.c  |  8 ++++++--
 src/compiler/nir/nir_opt_dead_write_vars.c |  6 ++++--
 5 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 2e45709dfcf..a15f24eb30a 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -2328,8 +2328,10 @@ nir_get_shader_call_payload_src(nir_intrinsic_instr *call)
 {
    switch (call->intrinsic) {
    case nir_intrinsic_trace_ray:
+   case nir_intrinsic_rt_trace_ray:
       return &call->src[10];
    case nir_intrinsic_execute_callable:
+   case nir_intrinsic_rt_execute_callable:
       return &call->src[1];
    default:
       unreachable("Not a call intrinsic");
diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py
index 6bda991fe91..ff0543fa7cb 100644
--- a/src/compiler/nir/nir_intrinsics.py
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -188,6 +188,12 @@ index("enum pipe_format", "format")
 # not set at the intrinsic if the NIR was created from SPIR-V.
 index("enum gl_access_qualifier", "access")
 
+# call index for split raytracing shaders
+index("unsigned", "call_idx")
+
+# The stack size increment/decrement for split raytracing shaders
+index("unsigned", "stack_size")
+
 # Alignment for offsets and addresses
 #
 # These two parameters, specify an alignment in terms of a multiplier and
@@ -482,6 +488,27 @@ intrinsic("terminate_ray")
 # src[] = { sbt_index, payload }
 intrinsic("execute_callable", src_comp=[1, -1])
 
+# Driver independent raytracing helpers
+
+# rt_resume is a helper that that be the first instruction accesing the
+# stack/scratch in a resume shader for a raytracing pipeline. It includes the
+# resume index (for nir_lower_shader_calls_internal reasons) and the stack size
+# of the variables spilled during the call. The stack size can be use to e.g.
+# adjust a stack pointer.
+intrinsic("rt_resume", indices=[CALL_IDX, STACK_SIZE])
+
+# Lowered version of execute_callabe that includes the index of the resume
+# shader, and the amount of scratch space needed for this call (.ie. how much
+# to increase a stack pointer by).
+# src[] = { sbt_index, payload }
+intrinsic("rt_execute_callable", src_comp=[1, -1], indices=[CALL_IDX,STACK_SIZE])
+
+# Lowered version of trace_ray in a similar vein to rt_execute_callable.
+# src same as trace_ray
+intrinsic("rt_trace_ray", src_comp=[-1, 1, 1, 1, 1, 1, 3, 1, 3, 1, -1],
+          indices=[CALL_IDX, STACK_SIZE])
+
+
 # Atomic counters
 #
 # The *_var variants take an atomic_uint nir_variable, while the other,
diff --git a/src/compiler/nir/nir_opt_combine_stores.c b/src/compiler/nir/nir_opt_combine_stores.c
index 3c69ac4ed20..0732b1ae71b 100644
--- a/src/compiler/nir/nir_opt_combine_stores.c
+++ b/src/compiler/nir/nir_opt_combine_stores.c
@@ -395,7 +395,9 @@ combine_stores_block(struct combine_stores_state *state, nir_block *block)
       }
 
       case nir_intrinsic_trace_ray:
-      case nir_intrinsic_execute_callable: {
+      case nir_intrinsic_execute_callable:
+      case nir_intrinsic_rt_trace_ray:
+      case nir_intrinsic_rt_execute_callable: {
          nir_deref_instr *payload =
             nir_src_as_deref(*nir_get_shader_call_payload_src(intrin));
          combine_stores_with_deref(state, payload);
diff --git a/src/compiler/nir/nir_opt_copy_prop_vars.c b/src/compiler/nir/nir_opt_copy_prop_vars.c
index 1969b09de47..e85e18a648b 100644
--- a/src/compiler/nir/nir_opt_copy_prop_vars.c
+++ b/src/compiler/nir/nir_opt_copy_prop_vars.c
@@ -185,7 +185,9 @@ gather_vars_written(struct copy_prop_var_state *state,
             break;
 
          case nir_intrinsic_trace_ray:
-         case nir_intrinsic_execute_callable: {
+         case nir_intrinsic_execute_callable:
+         case nir_intrinsic_rt_trace_ray:
+         case nir_intrinsic_rt_execute_callable: {
             nir_deref_instr *payload =
                nir_src_as_deref(*nir_get_shader_call_payload_src(intrin));
 
@@ -1141,7 +1143,9 @@ copy_prop_vars_block(struct copy_prop_var_state *state,
       }
 
       case nir_intrinsic_trace_ray:
-      case nir_intrinsic_execute_callable: {
+      case nir_intrinsic_execute_callable:
+      case nir_intrinsic_rt_trace_ray:
+      case nir_intrinsic_rt_execute_callable: {
          if (debug) dump_instr(instr);
 
          nir_deref_and_path payload = {
diff --git a/src/compiler/nir/nir_opt_dead_write_vars.c b/src/compiler/nir/nir_opt_dead_write_vars.c
index aaa87667e13..bd87b39118a 100644
--- a/src/compiler/nir/nir_opt_dead_write_vars.c
+++ b/src/compiler/nir/nir_opt_dead_write_vars.c
@@ -169,14 +169,16 @@ remove_dead_write_vars_local(void *mem_ctx, nir_shader *shader, nir_block *block
          break;
       }
 
-      case nir_intrinsic_execute_callable: {
+      case nir_intrinsic_execute_callable:
+      case nir_intrinsic_rt_execute_callable: {
          /* Mark payload as it can be used by the callee */
          nir_deref_instr *src = nir_src_as_deref(intrin->src[1]);
          clear_unused_for_read(&unused_writes, src);
          break;
       }
 
-      case nir_intrinsic_trace_ray: {
+      case nir_intrinsic_trace_ray:
+      case nir_intrinsic_rt_trace_ray: {
          /* Mark payload as it can be used by the callees */
          nir_deref_instr *src = nir_src_as_deref(intrin->src[10]);
          clear_unused_for_read(&unused_writes, src);



More information about the mesa-commit mailing list