[Mesa-dev] [FLAG-DAY-PREP 1/9] nir: start to abstract deref chains/instructions

Rob Clark robdclark at gmail.com
Thu Mar 15 14:28:00 UTC 2018


Prep work to convert from deref chains to deref instruction chains, add
a accessors so we can start moving code away from direct access to deref
chain just for the sake of finding the nir_variable.

After conversion to deref instructions, this would be converted to chase
the deref instruction ssa links back to the originating nir_variable.

We probably could do the same for nir_call_instr, but there aren't many
places in the code that deal with the params/return derefs, and
currently functions are inlined before the driver back-end so it would
not effect any nir consumers.
---
 src/compiler/nir/nir.h | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 6a51b7c4ab1..1e2ab459bd6 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1003,6 +1003,10 @@ typedef struct {
 
    int const_index[NIR_INTRINSIC_MAX_CONST_INDEX];
 
+   /**
+    * Note: drivers should not access intr->variables[n]->var directly, but
+    * instead use nir_intrinsic_var()
+    */
    nir_deref_var *variables[2];
 
    nir_src src[];
@@ -1166,6 +1170,20 @@ INTRINSIC_IDX_ACCESSORS(interp_mode, INTERP_MODE, unsigned)
 INTRINSIC_IDX_ACCESSORS(reduction_op, REDUCTION_OP, unsigned)
 INTRINSIC_IDX_ACCESSORS(cluster_size, CLUSTER_SIZE, unsigned)
 
+/**
+ * Access the nir_variable that an intrinsic refers to.
+ *
+ * Drivers should use this rather than directly accessing
+ * intr->variables[n]->var to prepare for conversion of deref chains
+ * to deref instructions.
+ */
+static inline nir_variable *
+nir_intrinsic_var(nir_intrinsic_instr *intr, unsigned n)
+{
+   assert(n < nir_intrinsic_infos[intr->intrinsic].num_variables);
+   return intr->variables[n]->var;
+}
+
 /**
  * \group texture information
  *
@@ -1274,6 +1292,22 @@ typedef struct {
    nir_deref_var *sampler;
 } nir_tex_instr;
 
+static inline nir_variable *
+nir_tex_texture_var(nir_tex_instr *instr)
+{
+	if (instr->texture)
+		return instr->texture->var;
+	return NULL;
+}
+
+static inline nir_variable *
+nir_tex_sampler_var(nir_tex_instr *instr)
+{
+	if (instr->sampler)
+		return instr->sampler->var;
+	return NULL;
+}
+
 static inline unsigned
 nir_tex_instr_dest_size(const nir_tex_instr *instr)
 {
-- 
2.14.3



More information about the mesa-dev mailing list