Re: [Mesa-dev] [PATCH 1/6] nir: const_index helpers

2016-02-08 Thread Jason Ekstrand
On Mon, Feb 8, 2016 at 12:16 PM, Rob Clark  wrote:

> On Mon, Feb 8, 2016 at 3:13 PM, Jason Ekstrand 
> wrote:
> >> +   if (info->index_map[NIR_INTRINSIC_BASE] ||
> >> +   info->index_map[NIR_INTRINSIC_WRMASK]) {
> >> +  fprintf(fp, " /*");
> >> +  if (info->index_map[NIR_INTRINSIC_BASE])
> >> + fprintf(fp, " base=%d", nir_intrinsic_base(instr));
> >> +  if (info->index_map[NIR_INTRINSIC_WRMASK]) {
> >> +  unsigned wrmask = nir_intrinsic_write_mask(instr);
> >> +  fprintf(fp, " wrmask=");
> >> +  for (unsigned i = 0; i < 4; i++)
> >> + if ((wrmask >> i) & 1)
> >> +fprintf(fp, "%c", "xyzw"[i]);
> >> +  }
> >> +  fprintf(fp, " */");
> >> +   }
> >
> >
> > Can we use an enum -> name table to name all of them?  Right now, it
> looks
> > like it only names baes and writemask.
>
> Hmm.. sure.  I think writemask is really the only one needing special
> casing.  I guess all the others would just show as %d..
>

Sure.  That one makes sense as hex.  The others shouldn't matter.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/6] nir: const_index helpers

2016-01-21 Thread Rob Clark
From: Rob Clark 

Direct access to intr->const_index[n], where different slots have
different meanings, is somewhat confusing.

Instead, let's put some extra info in nir_intrinsic_infos[] about which
slots map to what, and add some get/set helpers.  The helpers validate
that the field being accessed (base/writemask/etc) is applicable for the
intrinsic opc, for some extra safety.  And nir_print can use this to
dump out decoded const_index fields.

Signed-off-by: Rob Clark 
---
 src/glsl/nir/nir.h|  64 ++-
 src/glsl/nir/nir_intrinsics.c |  10 ++-
 src/glsl/nir/nir_intrinsics.h | 177 +-
 src/glsl/nir/nir_print.c  |  30 ---
 4 files changed, 181 insertions(+), 100 deletions(-)

diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index e2bd2bf..9812b89 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -786,7 +786,7 @@ typedef struct {
 } nir_call_instr;
 
 #define INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, \
-  num_variables, num_indices, flags) \
+  num_variables, num_indices, idx0, idx1, idx2, flags) \
nir_intrinsic_##name,
 
 #define LAST_INTRINSIC(name) nir_last_intrinsic = nir_intrinsic_##name,
@@ -799,6 +799,8 @@ typedef enum {
 #undef INTRINSIC
 #undef LAST_INTRINSIC
 
+#define NIR_INTRINSIC_MAX_CONST_INDEX 3
+
 /** Represents an intrinsic
  *
  * An intrinsic is an instruction type for handling things that are
@@ -842,7 +844,7 @@ typedef struct {
 */
uint8_t num_components;
 
-   int const_index[3];
+   int const_index[NIR_INTRINSIC_MAX_CONST_INDEX];
 
nir_deref_var *variables[2];
 
@@ -871,6 +873,39 @@ typedef enum {
NIR_INTRINSIC_CAN_REORDER = (1 << 1),
 } nir_intrinsic_semantic_flag;
 
+/**
+ * \name NIR intrinsics const-index flag
+ *
+ * Indicates the usage of a const_index slot.
+ *
+ * \sa nir_intrinsic_info::index_map
+ */
+typedef enum {
+   /**
+* Generally instructions that take a offset src argument, can encode
+* a constant 'base' value which is added to the offset.
+*/
+   NIR_INTRINSIC_BASE = 1,
+
+   /**
+* For store instructions, a writemask for the store.
+*/
+   NIR_INTRINSIC_WRMASK = 2,
+
+   /**
+* The stream-id for GS emit_vertex/end_primitive intrinsics.
+*/
+   NIR_INTRINSIC_STREAM_ID = 3,
+
+   /**
+* The clip-plane id for load_user_clip_plane intrinsic.
+*/
+   NIR_INTRINSIC_UCP_ID = 4,
+
+   NIR_INTRINSIC_NUM_INDEX_FLAGS,
+
+} nir_intrinsic_index_flag;
+
 #define NIR_INTRINSIC_MAX_INPUTS 4
 
 typedef struct {
@@ -900,12 +935,37 @@ typedef struct {
/** the number of constant indices used by the intrinsic */
unsigned num_indices;
 
+   /** indicates the usage of intr->const_index[n] */
+   unsigned index_map[NIR_INTRINSIC_NUM_INDEX_FLAGS];
+
/** semantic flags for calls to this intrinsic */
nir_intrinsic_semantic_flag flags;
 } nir_intrinsic_info;
 
 extern const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics];
 
+
+#define INTRINSIC_IDX_ACCESSORS(name, flag, type) \
+static inline type\
+nir_intrinsic_##name(nir_intrinsic_instr *instr)  \
+{ \
+   const nir_intrinsic_info *info = _intrinsic_infos[instr->intrinsic];   \
+   assert(info->index_map[NIR_INTRINSIC_##flag] > 0); \
+   return instr->const_index[info->index_map[NIR_INTRINSIC_##flag] - 1];  \
+} \
+static inline void\
+nir_intrinsic_set_##name(nir_intrinsic_instr *instr, type val)\
+{ \
+   const nir_intrinsic_info *info = _intrinsic_infos[instr->intrinsic];   \
+   assert(info->index_map[NIR_INTRINSIC_##flag] > 0); \
+   instr->const_index[info->index_map[NIR_INTRINSIC_##flag] - 1] = val;   \
+}
+
+INTRINSIC_IDX_ACCESSORS(write_mask, WRMASK, unsigned)
+INTRINSIC_IDX_ACCESSORS(base, BASE, int)
+INTRINSIC_IDX_ACCESSORS(stream_id, STREAM_ID, unsigned)
+INTRINSIC_IDX_ACCESSORS(ucp_id, UCP_ID, unsigned)
+
 /**
  * \group texture information
  *
diff --git a/src/glsl/nir/nir_intrinsics.c b/src/glsl/nir/nir_intrinsics.c
index a7c868c..0257b19 100644
--- a/src/glsl/nir/nir_intrinsics.c
+++ b/src/glsl/nir/nir_intrinsics.c
@@ -30,7 +30,8 @@
 #define OPCODE(name) nir_intrinsic_##name
 
 #define INTRINSIC(_name, _num_srcs, _src_components, _has_dest, \
-  _dest_components, _num_variables, _num_indices, _flags) \
+  _dest_components, _num_variables, _num_indices, \
+  idx0, idx1, idx2, _flags) \
 { \
.name = #_name, \
.num_srcs =