[Mesa-dev] [PATCH 7/9] tgsi: add ArrayID to declarations

Christian König deathsimple at vodafone.de
Mon Mar 18 06:36:31 PDT 2013


From: Christian König <christian.koenig at amd.com>

Remember which declarations are declared as "arrays" and so
can be indirectly addressed. ArrayIDs start at 1, cause for
compatibility reasons zero is treaded as no array present.

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 src/gallium/auxiliary/tgsi/tgsi_dump.c     |    6 ++++++
 src/gallium/auxiliary/tgsi/tgsi_parse.c    |    4 ++++
 src/gallium/auxiliary/tgsi/tgsi_parse.h    |    1 +
 src/gallium/auxiliary/tgsi/tgsi_text.c     |   22 +++++++++++++++++++++
 src/gallium/auxiliary/tgsi/tgsi_ureg.c     |   29 +++++++++++++++++++++++++---
 src/gallium/include/pipe/p_shader_tokens.h |    8 +++++++-
 6 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c
index 177be0f..adca6af 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_dump.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c
@@ -272,6 +272,12 @@ iter_declaration(
       ctx,
       decl->Declaration.UsageMask );
 
+   if (decl->Declaration.Array) {
+      TXT( ", ARRAY(" );
+      SID(decl->Array.ArrayID);
+      CHR(')');
+   }
+
    if (decl->Declaration.Local)
       TXT( ", LOCAL" );
 
diff --git a/src/gallium/auxiliary/tgsi/tgsi_parse.c b/src/gallium/auxiliary/tgsi/tgsi_parse.c
index 720d68d..29079ef 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_parse.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_parse.c
@@ -129,6 +129,10 @@ tgsi_parse_token(
          next_token(ctx, &decl->SamplerView);
       }
 
+      if( decl->Declaration.Array ) {
+         next_token(ctx, &decl->Array);
+      }
+
       break;
    }
 
diff --git a/src/gallium/auxiliary/tgsi/tgsi_parse.h b/src/gallium/auxiliary/tgsi/tgsi_parse.h
index 78210ed..ae40f13 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_parse.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_parse.h
@@ -66,6 +66,7 @@ struct tgsi_full_declaration
    struct tgsi_declaration_semantic Semantic;
    struct tgsi_declaration_resource Resource;
    struct tgsi_declaration_sampler_view SamplerView;
+   struct tgsi_declaration_array Array;
 };
 
 struct tgsi_full_immediate
diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
index 7d580e6..8a2a760 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
@@ -1114,6 +1114,28 @@ static boolean parse_declaration( struct translate_ctx *ctx )
 
    cur = ctx->cur;
    eat_opt_white( &cur );
+   if (*cur == ',') {
+      cur2 = cur;
+      cur2++;
+      eat_opt_white( &cur2 );
+      if (str_match_nocase_whole( &cur2, "ARRAY(" )) {
+         int arrayid;
+         eat_opt_white( &cur2 );
+         if (!parse_int( &cur2, &arrayid )) {
+            report_error( ctx, "Expected `,'" );
+            return FALSE;
+         }
+         eat_opt_white( &cur2 );
+         if (*cur2 != ')') {
+            report_error( ctx, "Expected `,'" );
+            return FALSE;
+         }
+         decl.Declaration.Array = 1;
+         decl.Array.ArrayID = arrayid;
+         cur = cur2;
+      }
+   }
+
    if (*cur == ',' && !is_vs_input) {
       uint i, j;
 
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index 88acdcb..1e862cb 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -50,6 +50,7 @@ union tgsi_any_token {
    struct tgsi_declaration_interp decl_interp;
    struct tgsi_declaration_semantic decl_semantic;
    struct tgsi_declaration_sampler_view decl_sampler_view;
+   struct tgsi_declaration_array array;
    struct tgsi_immediate imm;
    union  tgsi_immediate_data imm_data;
    struct tgsi_instruction insn;
@@ -78,6 +79,7 @@ struct ureg_tokens {
 #define UREG_MAX_IMMEDIATE 256
 #define UREG_MAX_ADDR 2
 #define UREG_MAX_PRED 1
+#define UREG_MAX_ARRAY_TEMPS 256
 
 struct const_decl {
    struct {
@@ -156,6 +158,9 @@ struct ureg_program
    struct util_bitmask *decl_temps;
    unsigned nr_temps;
 
+   unsigned array_temps[UREG_MAX_ARRAY_TEMPS];
+   unsigned nr_array_temps;
+
    struct const_decl const_decls;
    struct const_decl const_decls2D[PIPE_MAX_CONSTANT_BUFFERS];
 
@@ -584,11 +589,17 @@ struct ureg_dst ureg_DECL_array_temporary( struct ureg_program *ureg,
    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;
+
    return dst;
 }
 
@@ -1284,9 +1295,11 @@ emit_decl_fs(struct ureg_program *ureg,
 static void
 emit_decl_temps( struct ureg_program *ureg,
                  unsigned first, unsigned last,
-                 boolean local )
+                 boolean local,
+                 unsigned arrayid )
 {
-   union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 );
+   union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL,
+                                           arrayid ? 3 : 2 );
 
    out[0].value = 0;
    out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
@@ -1298,6 +1311,12 @@ emit_decl_temps( struct ureg_program *ureg,
    out[1].value = 0;
    out[1].decl_range.First = first;
    out[1].decl_range.Last = last;
+
+   if (arrayid) {
+      out[0].decl.Array = 1;
+      out[2].value = 0;
+      out[2].array.ArrayID = arrayid;
+   }
 }
 
 static void emit_decl_range( struct ureg_program *ureg,
@@ -1555,6 +1574,7 @@ 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;
@@ -1562,7 +1582,10 @@ static void emit_decls( struct ureg_program *ureg )
          if (i == UTIL_BITMASK_INVALID_INDEX)
             i = ureg->nr_temps;
 
-         emit_decl_temps( ureg, first, i - 1, local );
+         if (array < ureg->nr_array_temps && ureg->array_temps[array] == first)
+            emit_decl_temps( ureg, first, i - 1, local, ++array );
+         else
+            emit_decl_temps( ureg, first, i - 1, local, 0 );
       }
    }
 
diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
index 81e4a6b..eac75e6 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -119,7 +119,8 @@ struct tgsi_declaration
    unsigned Interpolate : 1;  /**< any interpolation info? */
    unsigned Invariant   : 1;  /**< invariant optimization? */
    unsigned Local       : 1;  /**< optimize as subroutine local variable? */
-   unsigned Padding     : 7;
+   unsigned Array       : 1;  /**< extra array info? */
+   unsigned Padding     : 6;
 };
 
 struct tgsi_declaration_range
@@ -185,6 +186,11 @@ struct tgsi_declaration_sampler_view {
    unsigned ReturnTypeW : 6; /**< one of enum pipe_type */
 };
 
+struct tgsi_declaration_array {
+   unsigned ArrayID : 10;
+   unsigned Padding : 22;
+};
+
 /*
  * Special resources that don't need to be declared.  They map to the
  * GLOBAL/LOCAL/PRIVATE/INPUT compute memory spaces.
-- 
1.7.9.5



More information about the mesa-dev mailing list