[Mesa-dev] [PATCH 2/9] nir: Add compute shader shared variable storage class

Jordan Justen jordan.l.justen at intel.com
Tue Mar 15 06:56:58 UTC 2016


Previously we were receiving shared variable accesses via a lowered
intrinsic function from glsl. This change allows us to send in
variables instead. For example, when converting from SPIR-V.

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/compiler/nir/nir.c               | 6 ++++++
 src/compiler/nir/nir.h               | 4 ++++
 src/compiler/nir/nir_clone.c         | 1 +
 src/compiler/nir/nir_lower_atomics.c | 3 ++-
 src/compiler/nir/nir_print.c         | 7 ++++++-
 src/compiler/nir/nir_sweep.c         | 1 +
 src/compiler/nir/nir_validate.c      | 5 +++++
 7 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index cd78475..386cdaf 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -39,6 +39,7 @@ nir_shader_create(void *mem_ctx,
    exec_list_make_empty(&shader->uniforms);
    exec_list_make_empty(&shader->inputs);
    exec_list_make_empty(&shader->outputs);
+   exec_list_make_empty(&shader->shared);
 
    shader->options = options;
    memset(&shader->info, 0, sizeof(shader->info));
@@ -136,6 +137,11 @@ nir_shader_add_variable(nir_shader *shader, nir_variable *var)
       exec_list_push_tail(&shader->uniforms, &var->node);
       break;
 
+   case nir_var_shared:
+      assert(shader->stage == MESA_SHADER_COMPUTE);
+      exec_list_push_tail(&shader->shared, &var->node);
+      break;
+
    case nir_var_system_value:
       exec_list_push_tail(&shader->system_values, &var->node);
       break;
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 34f31eb..bbf0ff3 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -90,6 +90,7 @@ typedef enum {
    nir_var_shader_storage,
    nir_var_system_value,
    nir_var_param,
+   nir_var_shared,
 } nir_variable_mode;
 
 /**
@@ -1660,6 +1661,9 @@ typedef struct nir_shader {
    /** list of outputs (nir_variable) */
    struct exec_list outputs;
 
+   /** list of shared compute variables (nir_variable) */
+   struct exec_list shared;
+
    /** Set of driver-specific options for the shader.
     *
     * The memory for the options is expected to be kept in a single static
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c
index 198ca8b..d17d384 100644
--- a/src/compiler/nir/nir_clone.c
+++ b/src/compiler/nir/nir_clone.c
@@ -675,6 +675,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
    clone_var_list(&state, &ns->uniforms, &s->uniforms);
    clone_var_list(&state, &ns->inputs,   &s->inputs);
    clone_var_list(&state, &ns->outputs,  &s->outputs);
+   clone_var_list(&state, &ns->shared,   &s->shared);
    clone_var_list(&state, &ns->globals,  &s->globals);
    clone_var_list(&state, &ns->system_values, &s->system_values);
 
diff --git a/src/compiler/nir/nir_lower_atomics.c b/src/compiler/nir/nir_lower_atomics.c
index 1935a52..eefcb55 100644
--- a/src/compiler/nir/nir_lower_atomics.c
+++ b/src/compiler/nir/nir_lower_atomics.c
@@ -63,7 +63,8 @@ lower_instr(nir_intrinsic_instr *instr,
    }
 
    if (instr->variables[0]->var->data.mode != nir_var_uniform &&
-       instr->variables[0]->var->data.mode != nir_var_shader_storage)
+       instr->variables[0]->var->data.mode != nir_var_shader_storage &&
+       instr->variables[0]->var->data.mode != nir_var_shared)
       return; /* atomics passed as function arguments can't be lowered */
 
    void *mem_ctx = ralloc_parent(instr);
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index 231a4f5..644a214 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -312,7 +312,8 @@ print_var_decl(nir_variable *var, print_state *state)
    const char *const patch = (var->data.patch) ? "patch " : "";
    const char *const inv = (var->data.invariant) ? "invariant " : "";
    const char *const mode[] = { "shader_in ", "shader_out ", "", "",
-                                "uniform ", "shader_storage ", "system " };
+                                "uniform ", "shader_storage ", "shared ",
+                                "system "};
 
    fprintf(fp, "%s%s%s%s%s%s ",
       cent, samp, patch, inv, mode[var->data.mode],
@@ -1069,6 +1070,10 @@ nir_print_shader(nir_shader *shader, FILE *fp)
       print_var_decl(var, &state);
    }
 
+   nir_foreach_variable(var, &shader->shared) {
+      print_var_decl(var, &state);
+   }
+
    nir_foreach_variable(var, &shader->globals) {
       print_var_decl(var, &state);
    }
diff --git a/src/compiler/nir/nir_sweep.c b/src/compiler/nir/nir_sweep.c
index 0710bdb..5c62154 100644
--- a/src/compiler/nir/nir_sweep.c
+++ b/src/compiler/nir/nir_sweep.c
@@ -159,6 +159,7 @@ nir_sweep(nir_shader *nir)
    steal_list(nir, nir_variable, &nir->uniforms);
    steal_list(nir, nir_variable, &nir->inputs);
    steal_list(nir, nir_variable, &nir->outputs);
+   steal_list(nir, nir_variable, &nir->shared);
    steal_list(nir, nir_variable, &nir->globals);
    steal_list(nir, nir_variable, &nir->system_values);
    steal_list(nir, nir_register, &nir->registers);
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 0c9d816..0c32d5f 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -1047,6 +1047,11 @@ nir_validate_shader(nir_shader *shader)
      validate_var_decl(var, true, &state);
    }
 
+   exec_list_validate(&shader->shared);
+   nir_foreach_variable(var, &shader->shared) {
+      validate_var_decl(var, true, &state);
+   }
+
    exec_list_validate(&shader->globals);
    nir_foreach_variable(var, &shader->globals) {
      validate_var_decl(var, true, &state);
-- 
2.7.0



More information about the mesa-dev mailing list