[Mesa-dev] [PATCH 03/13] tgsi/ureg: add layout/component input declarations

Nicolai Hähnle nhaehnle at gmail.com
Fri Oct 7 19:55:14 UTC 2016


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

---
 src/gallium/auxiliary/tgsi/tgsi_ureg.c | 69 +++++++++++++++++++++++++++-------
 src/gallium/auxiliary/tgsi/tgsi_ureg.h | 21 +++++++++++
 2 files changed, 77 insertions(+), 13 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index 6ad514d..7b4b49e 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -70,23 +70,23 @@ union tgsi_any_token {
 };
 
 
 struct ureg_tokens {
    union tgsi_any_token *tokens;
    unsigned size;
    unsigned order;
    unsigned count;
 };
 
-#define UREG_MAX_INPUT PIPE_MAX_SHADER_INPUTS
+#define UREG_MAX_INPUT (4 * PIPE_MAX_SHADER_INPUTS)
 #define UREG_MAX_SYSTEM_VALUE PIPE_MAX_ATTRIBS
-#define UREG_MAX_OUTPUT PIPE_MAX_SHADER_OUTPUTS
+#define UREG_MAX_OUTPUT (4 * PIPE_MAX_SHADER_OUTPUTS)
 #define UREG_MAX_CONSTANT_RANGE 32
 #define UREG_MAX_IMMEDIATE 4096
 #define UREG_MAX_ADDR 3
 #define UREG_MAX_PRED 1
 #define UREG_MAX_ARRAY_TEMPS 256
 
 struct const_decl {
    struct {
       unsigned first;
       unsigned last;
@@ -101,20 +101,21 @@ struct ureg_program
 {
    unsigned processor;
    bool supports_any_inout_decl_range;
    int next_shader_processor;
 
    struct {
       unsigned semantic_name;
       unsigned semantic_index;
       unsigned interp;
       unsigned char cylindrical_wrap;
+      unsigned char usage_mask;
       unsigned interp_location;
       unsigned first;
       unsigned last;
       unsigned array_id;
    } input[UREG_MAX_INPUT];
    unsigned nr_inputs, nr_input_regs;
 
    unsigned vs_inputs[PIPE_MAX_ATTRIBS/32];
 
    struct {
@@ -262,77 +263,116 @@ static union tgsi_any_token *retrieve_token( struct ureg_program *ureg,
 }
 
 void
 ureg_property(struct ureg_program *ureg, unsigned name, unsigned value)
 {
    assert(name < ARRAY_SIZE(ureg->properties));
    ureg->properties[name] = value;
 }
 
 struct ureg_src
-ureg_DECL_fs_input_cyl_centroid(struct ureg_program *ureg,
+ureg_DECL_fs_input_cyl_centroid_layout(struct ureg_program *ureg,
                        unsigned semantic_name,
                        unsigned semantic_index,
                        unsigned interp_mode,
                        unsigned cylindrical_wrap,
                        unsigned interp_location,
+                       unsigned index,
                        unsigned array_id,
-                       unsigned array_size)
+                       unsigned array_size,
+                       unsigned usage_mask)
 {
    unsigned i;
 
+   assert(usage_mask != 0);
+   assert(usage_mask <= TGSI_WRITEMASK_XYZW);
+
    for (i = 0; i < ureg->nr_inputs; i++) {
       if (ureg->input[i].semantic_name == semantic_name &&
           ureg->input[i].semantic_index == semantic_index) {
          assert(ureg->input[i].interp == interp_mode);
          assert(ureg->input[i].cylindrical_wrap == cylindrical_wrap);
          assert(ureg->input[i].interp_location == interp_location);
-         assert(ureg->input[i].array_id == array_id);
-         goto out;
+         if (ureg->input[i].array_id == array_id) {
+            ureg->input[i].usage_mask |= usage_mask;
+            goto out;
+         }
+         assert((ureg->input[i].usage_mask & usage_mask) == 0);
       }
    }
 
    if (ureg->nr_inputs < UREG_MAX_INPUT) {
       assert(array_size >= 1);
       ureg->input[i].semantic_name = semantic_name;
       ureg->input[i].semantic_index = semantic_index;
       ureg->input[i].interp = interp_mode;
       ureg->input[i].cylindrical_wrap = cylindrical_wrap;
       ureg->input[i].interp_location = interp_location;
-      ureg->input[i].first = ureg->nr_input_regs;
-      ureg->input[i].last = ureg->nr_input_regs + array_size - 1;
+      ureg->input[i].first = index;
+      ureg->input[i].last = index + array_size - 1;
       ureg->input[i].array_id = array_id;
-      ureg->nr_input_regs += array_size;
+      ureg->input[i].usage_mask = usage_mask;
+      ureg->nr_input_regs = MAX2(ureg->nr_input_regs, index + array_size);
       ureg->nr_inputs++;
    } else {
       set_bad(ureg);
    }
 
 out:
    return ureg_src_array_register(TGSI_FILE_INPUT, ureg->input[i].first,
                                   array_id);
 }
 
+struct ureg_src
+ureg_DECL_fs_input_cyl_centroid(struct ureg_program *ureg,
+                       unsigned semantic_name,
+                       unsigned semantic_index,
+                       unsigned interp_mode,
+                       unsigned cylindrical_wrap,
+                       unsigned interp_location,
+                       unsigned array_id,
+                       unsigned array_size)
+{
+   return ureg_DECL_fs_input_cyl_centroid_layout(ureg,
+         semantic_name, semantic_index, interp_mode, cylindrical_wrap, interp_location,
+         ureg->nr_input_regs, array_id, array_size, TGSI_WRITEMASK_XYZW);
+}
+
 
 struct ureg_src 
 ureg_DECL_vs_input( struct ureg_program *ureg,
                     unsigned index )
 {
    assert(ureg->processor == PIPE_SHADER_VERTEX);
    assert(index / 32 < ARRAY_SIZE(ureg->vs_inputs));
 
    ureg->vs_inputs[index/32] |= 1 << (index % 32);
    return ureg_src_register( TGSI_FILE_INPUT, index );
 }
 
 
 struct ureg_src
+ureg_DECL_input_layout(struct ureg_program *ureg,
+                unsigned semantic_name,
+                unsigned semantic_index,
+                unsigned index,
+                unsigned array_id,
+                unsigned array_size,
+                unsigned usage_mask)
+{
+   return ureg_DECL_fs_input_cyl_centroid_layout(ureg,
+               semantic_name, semantic_index, 0, 0, 0,
+               index, array_id, array_size, usage_mask);
+}
+
+
+struct ureg_src
 ureg_DECL_input(struct ureg_program *ureg,
                 unsigned semantic_name,
                 unsigned semantic_index,
                 unsigned array_id,
                 unsigned array_size)
 {
    return ureg_DECL_fs_input_cyl_centroid(ureg, semantic_name, semantic_index,
                                           0, 0, 0, array_id, array_size);
 }
 
@@ -1529,30 +1569,31 @@ emit_decl_semantic(struct ureg_program *ureg,
 static void
 emit_decl_fs(struct ureg_program *ureg,
              unsigned file,
              unsigned first,
              unsigned last,
              unsigned semantic_name,
              unsigned semantic_index,
              unsigned interpolate,
              unsigned cylindrical_wrap,
              unsigned interpolate_location,
-             unsigned array_id)
+             unsigned array_id,
+             unsigned usage_mask)
 {
    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;
    out[0].decl.NrTokens = 4;
    out[0].decl.File = file;
-   out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; /* FIXME! */
+   out[0].decl.UsageMask = usage_mask;
    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 = first;
    out[1].decl_range.Last = last;
 
    out[2].value = 0;
    out[2].decl_interp.Interpolate = interpolate;
@@ -1785,35 +1826,37 @@ static void emit_decls( struct ureg_program *ureg )
          for (i = 0; i < ureg->nr_inputs; i++) {
             emit_decl_fs(ureg,
                          TGSI_FILE_INPUT,
                          ureg->input[i].first,
                          ureg->input[i].last,
                          ureg->input[i].semantic_name,
                          ureg->input[i].semantic_index,
                          ureg->input[i].interp,
                          ureg->input[i].cylindrical_wrap,
                          ureg->input[i].interp_location,
-                         ureg->input[i].array_id);
+                         ureg->input[i].array_id,
+                         ureg->input[i].usage_mask);
          }
       }
       else {
          for (i = 0; i < ureg->nr_inputs; i++) {
             for (j = ureg->input[i].first; j <= ureg->input[i].last; j++) {
                emit_decl_fs(ureg,
                             TGSI_FILE_INPUT,
                             j, j,
                             ureg->input[i].semantic_name,
                             ureg->input[i].semantic_index +
                             (j - ureg->input[i].first),
                             ureg->input[i].interp,
                             ureg->input[i].cylindrical_wrap,
-                            ureg->input[i].interp_location, 0);
+                            ureg->input[i].interp_location, 0,
+                            ureg->input[i].usage_mask);
             }
          }
       }
    } else {
       if (ureg->supports_any_inout_decl_range) {
          for (i = 0; i < ureg->nr_inputs; i++) {
             emit_decl_semantic(ureg,
                                TGSI_FILE_INPUT,
                                ureg->input[i].first,
                                ureg->input[i].last,
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
index c2c2f1a..9a914f0 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
@@ -166,20 +166,32 @@ ureg_create_shader_and_destroy( struct ureg_program *p,
 
 void
 ureg_property(struct ureg_program *ureg, unsigned name, unsigned value);
 
 
 /***********************************************************************
  * Build shader declarations:
  */
 
 struct ureg_src
+ureg_DECL_fs_input_cyl_centroid_layout(struct ureg_program *,
+                       unsigned semantic_name,
+                       unsigned semantic_index,
+                       unsigned interp_mode,
+                       unsigned cylindrical_wrap,
+                       unsigned interp_location,
+                       unsigned index,
+                       unsigned array_id,
+                       unsigned array_size,
+                       unsigned usage_mask);
+
+struct ureg_src
 ureg_DECL_fs_input_cyl_centroid(struct ureg_program *,
                        unsigned semantic_name,
                        unsigned semantic_index,
                        unsigned interp_mode,
                        unsigned cylindrical_wrap,
                        unsigned interp_location,
                        unsigned array_id,
                        unsigned array_size);
 
 static inline struct ureg_src
@@ -208,20 +220,29 @@ ureg_DECL_fs_input(struct ureg_program *ureg,
                                  semantic_index,
                                  interp_mode,
                                  0, 0, 0, 1);
 }
 
 struct ureg_src
 ureg_DECL_vs_input( struct ureg_program *,
                     unsigned index );
 
 struct ureg_src
+ureg_DECL_input_layout(struct ureg_program *,
+                unsigned semantic_name,
+                unsigned semantic_index,
+                unsigned index,
+                unsigned array_id,
+                unsigned array_size,
+                unsigned usage_mask);
+
+struct ureg_src
 ureg_DECL_input(struct ureg_program *,
                 unsigned semantic_name,
                 unsigned semantic_index,
                 unsigned array_id,
                 unsigned array_size);
 
 struct ureg_src
 ureg_DECL_system_value(struct ureg_program *,
                        unsigned semantic_name,
                        unsigned semantic_index);
-- 
2.7.4



More information about the mesa-dev mailing list