Mesa (master): nir: Add new variable modes for ray-tracing

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 6 00:40:27 UTC 2020


Module: Mesa
Branch: master
Commit: 84a8ca1db889564f2ca6bad9f65504615ef4080b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=84a8ca1db889564f2ca6bad9f65504615ef4080b

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Wed Jul 29 14:00:29 2020 -0500

nir: Add new variable modes for ray-tracing

If we were desperate to reduce bits, we could probably also use
shader_in/out for hit attributes as they really are an output from
intersection shaders and read-only in any-hit and closest-hit shaders.
However, other passes such as nir_gether_info like to assume that
anything with nir_var_shader_in/out is indexed using vec4 locations for
interface matching.  It's easier to just add a new variable mode.

Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6479>

---

 src/compiler/nir/nir.c           |  2 ++
 src/compiler/nir/nir.h           |  8 ++++++--
 src/compiler/nir/nir_print.c     |  4 ++++
 src/compiler/nir/nir_serialize.c |  6 +++---
 src/compiler/nir/nir_validate.c  |  8 ++++++++
 src/compiler/shader_enums.h      | 10 ++++++++++
 6 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index fbfee92d5d4..1fc873050f2 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -179,6 +179,8 @@ nir_shader_add_variable(nir_shader *shader, nir_variable *var)
    case nir_var_system_value:
    case nir_var_mem_push_const:
    case nir_var_mem_constant:
+   case nir_var_shader_call_data:
+   case nir_var_ray_hit_attrib:
       break;
 
    case nir_var_mem_global:
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index de29aab1e27..f177de75e96 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -134,9 +134,13 @@ typedef enum {
                               nir_var_mem_global),
    nir_var_mem_push_const  = (1 << 10), /* not actually used for variables */
    nir_var_mem_constant    = (1 << 11),
+   /** Incoming call or ray payload data for ray-tracing shaders */
+   nir_var_shader_call_data = (1 << 12),
+   /** Ray hit attributes */
+   nir_var_ray_hit_attrib  = (1 << 13),
    nir_var_read_only_modes = nir_var_shader_in | nir_var_uniform |
                              nir_var_system_value | nir_var_mem_constant,
-   nir_num_variable_modes  = 12,
+   nir_num_variable_modes  = 14,
    nir_var_all             = (1 << nir_num_variable_modes) - 1,
 } nir_variable_mode;
 MESA_DEFINE_CPP_ENUM_BITFIELD_OPERATORS(nir_variable_mode)
@@ -345,7 +349,7 @@ typedef struct nir_variable {
        *
        * \sa nir_variable_mode
        */
-      unsigned mode:12;
+      unsigned mode:14;
 
       /**
        * Is the variable read-only?
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index e1c17ccbb2b..8c62b1235d8 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -473,6 +473,10 @@ get_variable_mode_str(nir_variable_mode mode, bool want_local_global_mode)
       return want_local_global_mode ? "shader_temp" : "";
    case nir_var_function_temp:
       return want_local_global_mode ? "function_temp" : "";
+   case nir_var_shader_call_data:
+      return "shader_call_data";
+   case nir_var_ray_hit_attrib:
+      return "ray_hit_attrib";
    default:
       return "";
    }
diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
index 2617a731f9e..7f99d2fd138 100644
--- a/src/compiler/nir/nir_serialize.c
+++ b/src/compiler/nir/nir_serialize.c
@@ -637,9 +637,9 @@ union packed_instr {
       unsigned instr_type:4;
       unsigned deref_type:3;
       unsigned cast_type_same_as_last:1;
-      unsigned modes:12; /* deref_var redefines this */
+      unsigned modes:14; /* deref_var redefines this */
       unsigned packed_src_ssa_16bit:1; /* deref_var redefines this */
-      unsigned _pad:3;  /* deref_var redefines this */
+      unsigned _pad:1;  /* deref_var redefines this */
       unsigned dest:8;
    } deref;
    struct {
@@ -984,7 +984,7 @@ static void
 write_deref(write_ctx *ctx, const nir_deref_instr *deref)
 {
    assert(deref->deref_type < 8);
-   assert(deref->modes < (1 << 12));
+   assert(deref->modes < (1 << 14));
 
    union packed_instr header;
    header.u32 = 0;
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index b1b742c5080..808592c224d 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -1551,6 +1551,14 @@ nir_validate_shader(nir_shader *shader, const char *when)
       nir_var_mem_push_const |
       nir_var_mem_constant;
 
+   if (gl_shader_stage_is_callable(shader->info.stage))
+      valid_modes |= nir_var_shader_call_data;
+
+   if (shader->info.stage == MESA_SHADER_ANY_HIT ||
+       shader->info.stage == MESA_SHADER_CLOSEST_HIT ||
+       shader->info.stage == MESA_SHADER_INTERSECTION)
+      valid_modes |= nir_var_ray_hit_attrib;
+
    exec_list_validate(&shader->variables);
    nir_foreach_variable_in_shader(var, shader)
      validate_var_decl(var, valid_modes, &state);
diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index 5bab7fed120..c6ea75c9570 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -72,6 +72,16 @@ gl_shader_stage_is_compute(gl_shader_stage stage)
    return stage == MESA_SHADER_COMPUTE || stage == MESA_SHADER_KERNEL;
 }
 
+static inline bool
+gl_shader_stage_is_callable(gl_shader_stage stage)
+{
+   return stage == MESA_SHADER_ANY_HIT ||
+          stage == MESA_SHADER_CLOSEST_HIT ||
+          stage == MESA_SHADER_MISS ||
+          stage == MESA_SHADER_INTERSECTION ||
+          stage == MESA_SHADER_CALLABLE;
+}
+
 /**
  * Number of STATE_* values we need to address any GL state.
  * Used to dimension arrays.



More information about the mesa-commit mailing list