[Mesa-dev] [PATCH 01/19] tgsi/ureg: allow specifying the UsageMask of array temporaries

Nicolai Hähnle nhaehnle at gmail.com
Tue Aug 9 10:36:30 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/gallium/auxiliary/tgsi/tgsi_ureg.c     | 14 ++++++++++----
 src/gallium/auxiliary/tgsi/tgsi_ureg.h     |  1 +
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index b67c383..3ddbd4b 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -170,21 +170,24 @@ struct ureg_program
       unsigned index;
       bool atomic;
    } buffer[PIPE_MAX_SHADER_BUFFERS];
    unsigned nr_buffers;
 
    struct util_bitmask *free_temps;
    struct util_bitmask *local_temps;
    struct util_bitmask *decl_temps;
    unsigned nr_temps;
 
-   unsigned array_temps[UREG_MAX_ARRAY_TEMPS];
+   struct {
+      unsigned start;
+      unsigned usagemask;
+   } array_temps[UREG_MAX_ARRAY_TEMPS];
    unsigned nr_array_temps;
 
    struct const_decl const_decls;
    struct const_decl const_decls2D[PIPE_MAX_CONSTANT_BUFFERS];
 
    unsigned properties[TGSI_PROPERTY_COUNT];
 
    unsigned nr_addrs;
    unsigned nr_preds;
    unsigned nr_instructions;
@@ -556,39 +559,41 @@ struct ureg_dst ureg_DECL_temporary( struct ureg_program *ureg )
    return alloc_temporary(ureg, FALSE);
 }
 
 struct ureg_dst ureg_DECL_local_temporary( struct ureg_program *ureg )
 {
    return alloc_temporary(ureg, TRUE);
 }
 
 struct ureg_dst ureg_DECL_array_temporary( struct ureg_program *ureg,
                                            unsigned size,
+                                           unsigned usagemask,
                                            boolean local )
 {
    unsigned i = ureg->nr_temps;
    struct ureg_dst dst = ureg_dst_register( TGSI_FILE_TEMPORARY, i );
 
    if (local)
       util_bitmask_set(ureg->local_temps, i);
 
    /* Always start a new declaration at the start */
    util_bitmask_set(ureg->decl_temps, i);
 
    ureg->nr_temps += size;
 
    /* and also at the end of the array */
    util_bitmask_set(ureg->decl_temps, ureg->nr_temps);
 
    if (ureg->nr_array_temps < UREG_MAX_ARRAY_TEMPS) {
-      ureg->array_temps[ureg->nr_array_temps++] = i;
-      dst.ArrayID = ureg->nr_array_temps;
+      ureg->array_temps[ureg->nr_array_temps].start = i;
+      ureg->array_temps[ureg->nr_array_temps].usagemask = usagemask;
+      dst.ArrayID = ++ureg->nr_array_temps;
    }
 
    return dst;
 }
 
 void ureg_release_temporary( struct ureg_program *ureg,
                              struct ureg_dst tmp )
 {
    if(tmp.File == TGSI_FILE_TEMPORARY)
       util_bitmask_set(ureg->free_temps, tmp.Index);
@@ -1543,20 +1548,21 @@ emit_decl_temps( struct ureg_program *ureg,
    out[0].decl.File = TGSI_FILE_TEMPORARY;
    out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
    out[0].decl.Local = local;
 
    out[1].value = 0;
    out[1].decl_range.First = first;
    out[1].decl_range.Last = last;
 
    if (arrayid) {
       out[0].decl.Array = 1;
+      out[0].decl.UsageMask = ureg->array_temps[arrayid - 1].usagemask;
       out[2].value = 0;
       out[2].array.ArrayID = arrayid;
    }
 }
 
 static void emit_decl_range( struct ureg_program *ureg,
                              unsigned file,
                              unsigned first,
                              unsigned count )
 {
@@ -1894,21 +1900,21 @@ static void emit_decls( struct ureg_program *ureg )
 
    if (ureg->nr_temps) {
       unsigned array = 0;
       for (i = 0; i < ureg->nr_temps;) {
          boolean local = util_bitmask_get(ureg->local_temps, i);
          unsigned first = i;
          i = util_bitmask_get_next_index(ureg->decl_temps, i + 1);
          if (i == UTIL_BITMASK_INVALID_INDEX)
             i = ureg->nr_temps;
 
-         if (array < ureg->nr_array_temps && ureg->array_temps[array] == first)
+         if (array < ureg->nr_array_temps && ureg->array_temps[array].start == first)
             emit_decl_temps( ureg, first, i - 1, local, ++array );
          else
             emit_decl_temps( ureg, first, i - 1, local, 0 );
       }
    }
 
    if (ureg->nr_addrs) {
       emit_decl_range( ureg,
                        TGSI_FILE_ADDRESS,
                        0, ureg->nr_addrs );
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
index b4258fd..e7b0f25 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
@@ -291,20 +291,21 @@ ureg_DECL_temporary( struct ureg_program * );
  */
 struct ureg_dst
 ureg_DECL_local_temporary( struct ureg_program * );
 
 /**
  * Declare "size" continuous temporary registers.
  */
 struct ureg_dst
 ureg_DECL_array_temporary( struct ureg_program *,
                            unsigned size,
+                           unsigned usagemask,
                            boolean local );
 
 void 
 ureg_release_temporary( struct ureg_program *ureg,
                         struct ureg_dst tmp );
 
 struct ureg_dst
 ureg_DECL_address( struct ureg_program * );
 
 struct ureg_dst
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 362559f..4a19fe6 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5352,21 +5352,21 @@ dst_register(struct st_translate *t, gl_register_file file, unsigned index,
 
       return t->temps[index];
 
    case PROGRAM_ARRAY:
       array = index >> 16;
 
       assert(array < t->num_temp_arrays);
 
       if (ureg_dst_is_undef(t->arrays[array]))
          t->arrays[array] = ureg_DECL_array_temporary(
-            t->ureg, t->array_sizes[array], TRUE);
+            t->ureg, t->array_sizes[array], TGSI_WRITEMASK_XYZW, TRUE);
 
       return ureg_dst_array_offset(t->arrays[array],
                                    (int)(index & 0xFFFF) - 0x8000);
 
    case PROGRAM_OUTPUT:
       if (!array_id) {
          if (t->procType == PIPE_SHADER_FRAGMENT)
             assert(index < FRAG_RESULT_MAX);
          else if (t->procType == PIPE_SHADER_TESS_CTRL ||
                   t->procType == PIPE_SHADER_TESS_EVAL)
-- 
2.7.4



More information about the mesa-dev mailing list