nir: Add compute shader shared variable storage class
authorJordan Justen <jordan.l.justen@intel.com>
Sat, 9 Jan 2016 01:16:29 +0000 (17:16 -0800)
committerJordan Justen <jordan.l.justen@intel.com>
Thu, 21 Jan 2016 08:31:29 +0000 (00:31 -0800)
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@intel.com>
src/glsl/nir/nir.c
src/glsl/nir/nir.h
src/glsl/nir/nir_clone.c
src/glsl/nir/nir_lower_atomics.c
src/glsl/nir/nir_print.c
src/glsl/nir/nir_sweep.c
src/glsl/nir/nir_validate.c

index 273cac3e0ac3e84457f827c66286e4c7a6fe2a0e..deed3233da03fefcaaf43fed10a1ca2a23a644c6 100644 (file)
@@ -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));
@@ -132,6 +133,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;
index 49af2f31e9ebd1901789fb85fecc50b7bd1b9607..80e93c1047168842585247d3e96b84e94a6f1dc7 100644 (file)
@@ -88,6 +88,7 @@ typedef enum {
    nir_var_local,
    nir_var_uniform,
    nir_var_shader_storage,
+   nir_var_shared,
    nir_var_system_value
 } nir_variable_mode;
 
@@ -1635,6 +1636,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
index 0ea8da77421ea04a136729fa23d4ad77cb9453db..702219a5a343e6d1986e4e1e5d089f1929a45302 100644 (file)
@@ -673,6 +673,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);
 
index 1aa78e18a85ed58e59addcafb6f20511f5f10453..a9d0ddbbd415dda6250cf93eb08670e27bba3c0f 100644 (file)
@@ -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);
index e1261aed5ef54f1bb67fc3139014e0b6ca8f33e9..1bbdaa21177ba3cbf5a03ddc0bdfb46d66f6b766 100644 (file)
@@ -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],
@@ -1053,6 +1054,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);
    }
index 0710bdba7c7c950aa8346738c3aa1daf92e2cce7..5c62154ec7f69a30e869a7f7786a752941982977 100644 (file)
@@ -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);
index 91c01ff8727fc73c0f12fad71de6ec3642c0f3ee..1a943d76314bb973c3767544914f796398fd48d7 100644 (file)
@@ -1036,6 +1036,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);