[Mesa-dev] [PATCH v3 010/104] prog/nir: Simplify some load/store operations

Jason Ekstrand jason at jlekstrand.net
Tue Apr 3 18:32:37 UTC 2018


---
 src/compiler/nir/nir_builder.h |  6 +++++
 src/mesa/program/prog_to_nir.c | 53 +++++++++++-------------------------------
 2 files changed, 19 insertions(+), 40 deletions(-)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 076c583..edae559 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -525,6 +525,12 @@ nir_ssa_for_alu_src(nir_builder *build, nir_alu_instr *instr, unsigned srcn)
    return nir_imov_alu(build, *src, num_components);
 }
 
+static inline nir_ssa_def *
+nir_load_reg(nir_builder *build, nir_register *reg)
+{
+   return nir_ssa_for_src(build, nir_src_for_reg(reg), reg->num_components);
+}
+
 static inline nir_deref_instr *
 nir_build_deref_var(nir_builder *build, nir_variable *var)
 {
diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
index b49616c..3ee44ce 100644
--- a/src/mesa/program/prog_to_nir.c
+++ b/src/mesa/program/prog_to_nir.c
@@ -136,15 +136,8 @@ ptn_get_src(struct ptn_compile *c, const struct prog_src_register *prog_src)
 
       assert(prog_src->Index >= 0 && prog_src->Index < VARYING_SLOT_MAX);
 
-      nir_intrinsic_instr *load =
-         nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_var);
-      load->num_components = 4;
-      load->variables[0] = nir_deref_var_create(load, c->input_vars[prog_src->Index]);
-
-      nir_ssa_dest_init(&load->instr, &load->dest, 4, 32, NULL);
-      nir_builder_instr_insert(b, &load->instr);
-
-      src.src = nir_src_for_ssa(&load->dest.ssa);
+      nir_variable *var = c->input_vars[prog_src->Index];
+      src.src = nir_src_for_ssa(nir_load_var(b, var));
       break;
    }
    case PROGRAM_STATE_VAR:
@@ -861,27 +854,17 @@ ptn_add_output_stores(struct ptn_compile *c)
    nir_builder *b = &c->build;
 
    nir_foreach_variable(var, &b->shader->outputs) {
-      nir_intrinsic_instr *store =
-         nir_intrinsic_instr_create(b->shader, nir_intrinsic_store_var);
-      store->num_components = glsl_get_vector_elements(var->type);
-      nir_intrinsic_set_write_mask(store, (1 << store->num_components) - 1);
-      store->variables[0] =
-         nir_deref_var_create(store, c->output_vars[var->data.location]);
-
+      nir_ssa_def *src = nir_load_reg(b, c->output_regs[var->data.location]);
       if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB &&
           var->data.location == FRAG_RESULT_DEPTH) {
          /* result.depth has this strange convention of being the .z component of
           * a vec4 with undefined .xyw components.  We resolve it to a scalar, to
           * match GLSL's gl_FragDepth and the expectations of most backends.
           */
-         nir_alu_src alu_src = { NIR_SRC_INIT };
-         alu_src.src = nir_src_for_reg(c->output_regs[FRAG_RESULT_DEPTH]);
-         alu_src.swizzle[0] = SWIZZLE_Z;
-         store->src[0] = nir_src_for_ssa(nir_fmov_alu(b, alu_src, 1));
-      } else {
-         store->src[0].reg.reg = c->output_regs[var->data.location];
+         src = nir_channel(b, src, 2);
       }
-      nir_builder_instr_insert(b, &store->instr);
+      unsigned num_components = glsl_get_vector_elements(var->type);
+      nir_store_var(b, var, src, (1 << num_components) - 1);
    }
 }
 
@@ -914,26 +897,16 @@ setup_registers_and_variables(struct ptn_compile *c)
              */
             var->type = glsl_float_type();
 
-            nir_intrinsic_instr *load_x =
-               nir_intrinsic_instr_create(shader, nir_intrinsic_load_var);
-            load_x->num_components = 1;
-            load_x->variables[0] = nir_deref_var_create(load_x, var);
-            nir_ssa_dest_init(&load_x->instr, &load_x->dest, 1, 32, NULL);
-            nir_builder_instr_insert(b, &load_x->instr);
-
-            nir_ssa_def *f001 = nir_vec4(b, &load_x->dest.ssa, nir_imm_float(b, 0.0),
-                                         nir_imm_float(b, 0.0), nir_imm_float(b, 1.0));
-
             nir_variable *fullvar =
                nir_local_variable_create(b->impl, glsl_vec4_type(),
                                          "fogcoord_tmp");
-            nir_intrinsic_instr *store =
-               nir_intrinsic_instr_create(shader, nir_intrinsic_store_var);
-            store->num_components = 4;
-            nir_intrinsic_set_write_mask(store, WRITEMASK_XYZW);
-            store->variables[0] = nir_deref_var_create(store, fullvar);
-            store->src[0] = nir_src_for_ssa(f001);
-            nir_builder_instr_insert(b, &store->instr);
+
+            nir_store_var(b, fullvar,
+                          nir_vec4(b, nir_load_var(b, var),
+                                   nir_imm_float(b, 0.0),
+                                   nir_imm_float(b, 0.0),
+                                   nir_imm_float(b, 1.0)),
+                          WRITEMASK_XYZW);
 
             /* We inserted the real input into the list so the driver has real
              * inputs, but we set c->input_vars[i] to the temporary so we use
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list