tgsi/ureg: add support for FS input array declarations
authorMarek Olšák <marek.olsak@amd.com>
Sun, 10 May 2015 10:52:02 +0000 (12:52 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 5 Jun 2015 17:44:32 +0000 (19:44 +0200)
src/gallium/auxiliary/tgsi/tgsi_ureg.c
src/gallium/auxiliary/tgsi/tgsi_ureg.h
src/gallium/state_trackers/nine/nine_shader.c
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 037d31a1643710b90f0b411618c649cdeba69a4b..ca2589ac996de6f6808b71b32d074e4b14286ce4 100644 (file)
@@ -104,8 +104,11 @@ struct ureg_program
       unsigned interp;
       unsigned char cylindrical_wrap;
       unsigned interp_location;
+      unsigned first;
+      unsigned last;
+      unsigned array_id;
    } fs_input[UREG_MAX_INPUT];
-   unsigned nr_fs_inputs;
+   unsigned nr_fs_inputs, nr_fs_input_regs;
 
    unsigned vs_inputs[UREG_MAX_INPUT/32];
 
@@ -254,30 +257,42 @@ ureg_DECL_fs_input_cyl_centroid(struct ureg_program *ureg,
                        unsigned semantic_index,
                        unsigned interp_mode,
                        unsigned cylindrical_wrap,
-                       unsigned interp_location)
+                       unsigned interp_location,
+                       unsigned array_id,
+                       unsigned array_size)
 {
    unsigned i;
 
    for (i = 0; i < ureg->nr_fs_inputs; i++) {
       if (ureg->fs_input[i].semantic_name == semantic_name &&
           ureg->fs_input[i].semantic_index == semantic_index) {
+         assert(ureg->fs_input[i].interp == interp_mode);
+         assert(ureg->fs_input[i].cylindrical_wrap == cylindrical_wrap);
+         assert(ureg->fs_input[i].interp_location == interp_location);
+         assert(ureg->fs_input[i].array_id == array_id);
          goto out;
       }
    }
 
    if (ureg->nr_fs_inputs < UREG_MAX_INPUT) {
+      assert(array_size >= 1);
       ureg->fs_input[i].semantic_name = semantic_name;
       ureg->fs_input[i].semantic_index = semantic_index;
       ureg->fs_input[i].interp = interp_mode;
       ureg->fs_input[i].cylindrical_wrap = cylindrical_wrap;
       ureg->fs_input[i].interp_location = interp_location;
+      ureg->fs_input[i].first = ureg->nr_fs_input_regs;
+      ureg->fs_input[i].last = ureg->nr_fs_input_regs + array_size - 1;
+      ureg->fs_input[i].array_id = array_id;
+      ureg->nr_fs_input_regs += array_size;
       ureg->nr_fs_inputs++;
    } else {
       set_bad(ureg);
    }
 
 out:
-   return ureg_src_register(TGSI_FILE_INPUT, i);
+   return ureg_src_array_register(TGSI_FILE_INPUT, ureg->fs_input[i].first,
+                                  array_id);
 }
 
 
@@ -1281,14 +1296,17 @@ emit_decl_semantic(struct ureg_program *ureg,
 static void
 emit_decl_fs(struct ureg_program *ureg,
              unsigned file,
-             unsigned index,
+             unsigned first,
+             unsigned last,
              unsigned semantic_name,
              unsigned semantic_index,
              unsigned interpolate,
              unsigned cylindrical_wrap,
-             unsigned interpolate_location)
+             unsigned interpolate_location,
+             unsigned array_id)
 {
-   union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 4);
+   union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL,
+                                          array_id ? 5 : 4);
 
    out[0].value = 0;
    out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
@@ -1297,10 +1315,11 @@ emit_decl_fs(struct ureg_program *ureg,
    out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; /* FIXME! */
    out[0].decl.Interpolate = 1;
    out[0].decl.Semantic = 1;
+   out[0].decl.Array = array_id != 0;
 
    out[1].value = 0;
-   out[1].decl_range.First = index;
-   out[1].decl_range.Last = index;
+   out[1].decl_range.First = first;
+   out[1].decl_range.Last = last;
 
    out[2].value = 0;
    out[2].decl_interp.Interpolate = interpolate;
@@ -1310,6 +1329,11 @@ emit_decl_fs(struct ureg_program *ureg,
    out[3].value = 0;
    out[3].decl_semantic.Name = semantic_name;
    out[3].decl_semantic.Index = semantic_index;
+
+   if (array_id) {
+      out[4].value = 0;
+      out[4].array.ArrayID = array_id;
+   }
 }
 
 static void
@@ -1464,12 +1488,14 @@ static void emit_decls( struct ureg_program *ureg )
       for (i = 0; i < ureg->nr_fs_inputs; i++) {
          emit_decl_fs(ureg,
                       TGSI_FILE_INPUT,
-                      i,
+                      ureg->fs_input[i].first,
+                      ureg->fs_input[i].last,
                       ureg->fs_input[i].semantic_name,
                       ureg->fs_input[i].semantic_index,
                       ureg->fs_input[i].interp,
                       ureg->fs_input[i].cylindrical_wrap,
-                      ureg->fs_input[i].interp_location);
+                      ureg->fs_input[i].interp_location,
+                      ureg->fs_input[i].array_id);
       }
    } else {
       for (i = 0; i < ureg->nr_gs_inputs; i++) {
index c3f4012f2b99aa40eb14cb60b3f487561b2d9beb..37846d5be8d43841d06f80102538137bc16b377a 100644 (file)
@@ -172,7 +172,9 @@ ureg_DECL_fs_input_cyl_centroid(struct ureg_program *,
                        unsigned semantic_index,
                        unsigned interp_mode,
                        unsigned cylindrical_wrap,
-                       unsigned interp_location);
+                       unsigned interp_location,
+                       unsigned array_id,
+                       unsigned array_size);
 
 static INLINE struct ureg_src
 ureg_DECL_fs_input_cyl(struct ureg_program *ureg,
@@ -186,7 +188,7 @@ ureg_DECL_fs_input_cyl(struct ureg_program *ureg,
                                  semantic_index,
                                  interp_mode,
                                  cylindrical_wrap,
-                                 0);
+                                 0, 0, 1);
 }
 
 static INLINE struct ureg_src
@@ -199,7 +201,7 @@ ureg_DECL_fs_input(struct ureg_program *ureg,
                                  semantic_name,
                                  semantic_index,
                                  interp_mode,
-                                 0, 0);
+                                 0, 0, 0, 1);
 }
 
 struct ureg_src
@@ -1162,6 +1164,13 @@ ureg_src_dimension_indirect( struct ureg_src reg, struct ureg_src addr,
    return reg;
 }
 
+static INLINE struct ureg_src
+ureg_src_array_offset(struct ureg_src reg, int offset)
+{
+   reg.Index += offset;
+   return reg;
+}
+
 static INLINE struct ureg_dst
 ureg_dst_array_offset( struct ureg_dst reg, int offset )
 {
@@ -1236,8 +1245,9 @@ ureg_dst( struct ureg_src src )
 }
 
 static INLINE struct ureg_src
-ureg_src_register(unsigned file,
-                  unsigned index)
+ureg_src_array_register(unsigned file,
+                        unsigned index,
+                        unsigned array_id)
 {
    struct ureg_src src;
 
@@ -1259,11 +1269,18 @@ ureg_src_register(unsigned file,
    src.DimIndFile = TGSI_FILE_NULL;
    src.DimIndIndex = 0;
    src.DimIndSwizzle = 0;
-   src.ArrayID = 0;
+   src.ArrayID = array_id;
 
    return src;
 }
 
+static INLINE struct ureg_src
+ureg_src_register(unsigned file,
+                  unsigned index)
+{
+   return ureg_src_array_register(file, index, 0);
+}
+
 static INLINE struct ureg_src
 ureg_src( struct ureg_dst dst )
 {
index fd0f76e1118d622e609f2aebbff5c31ea3b5fc97..cdd4918530be2f1236fb1c43c0accdfc30780658 100644 (file)
@@ -1979,7 +1979,7 @@ DECL_SPECIAL(DCL)
                 ureg, tgsi.Name, tgsi.Index,
                 nine_tgsi_to_interp_mode(&tgsi),
                 0, /* cylwrap */
-                sem.reg.mod & NINED3DSPDM_CENTROID);
+                sem.reg.mod & NINED3DSPDM_CENTROID, 0, 1);
         } else
         if (!is_input && 0) { /* declare in COLOROUT/DEPTHOUT case */
             /* FragColor or FragDepth */
index db190c943a4fc7c094fbde5b5f9668966462a250..72b47b7421b0049731bfefb5ec3557d898d5835c 100644 (file)
@@ -5149,7 +5149,7 @@ st_translate_program(
                                                         inputSemanticName[i],
                                                         inputSemanticIndex[i],
                                                         interpMode[i], 0,
-                                                        interpLocation[i]);
+                                                        interpLocation[i], 0, 1);
       }
 
       if (proginfo->InputsRead & VARYING_BIT_POS) {