Mesa (master): svga: fix varying var remapping for unused FS outputs

Brian Paul brianp at kemper.freedesktop.org
Fri Nov 4 22:06:17 UTC 2011


Module: Mesa
Branch: master
Commit: 1ca48b3161449945b769b27c33f88f397f98084a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1ca48b3161449945b769b27c33f88f397f98084a

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Nov  4 14:36:59 2011 -0600

svga: fix varying var remapping for unused FS outputs

If the VS has outputs that aren't consumed by the FS we were mapping
them all to one unused VS output index, but that's illegal.  Instead,
map unused VS outputs to unique indexes.

Reviewed-by: José Fonseca <jfonseca at vmware.com>

---

 src/gallium/drivers/svga/svga_swtnl_state.c |    2 +-
 src/gallium/drivers/svga/svga_tgsi.c        |   27 ++++++++++++++++++++-------
 src/gallium/drivers/svga/svga_tgsi.h        |    2 +-
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_swtnl_state.c b/src/gallium/drivers/svga/svga_swtnl_state.c
index d7fa1aa..7d0a1c5 100644
--- a/src/gallium/drivers/svga/svga_swtnl_state.c
+++ b/src/gallium/drivers/svga/svga_swtnl_state.c
@@ -153,7 +153,7 @@ svga_swtnl_update_vdecl( struct svga_context *svga )
    SVGA3dVertexDecl vdecl[PIPE_MAX_ATTRIBS];
    const enum interp_mode colorInterp =
       svga->curr.rast->templ.flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
-   const struct svga_fragment_shader *fs = svga->curr.fs;
+   struct svga_fragment_shader *fs = svga->curr.fs;
    int offset = 0;
    int nr_decls = 0;
    int src, i;
diff --git a/src/gallium/drivers/svga/svga_tgsi.c b/src/gallium/drivers/svga/svga_tgsi.c
index 821def4..2be6f05 100644
--- a/src/gallium/drivers/svga/svga_tgsi.c
+++ b/src/gallium/drivers/svga/svga_tgsi.c
@@ -208,20 +208,22 @@ svga_remap_generics(unsigned generics_mask,
       remap_table[index] = count++;
       generics_mask &= ~(1 << index);
    }
-
-   for (i = 0; i < MAX_GENERIC_VARYING; i++) {
-      if (remap_table[i] == -1)
-         remap_table[i] = count;
-   }
 }
 
 
 /**
  * Use the generic remap table to map a TGSI generic varying variable
- * index to a small integer.
+ * index to a small integer.  If the remapping table doesn't have a
+ * valid value for the given index (the table entry is -1) it means
+ * the fragment shader doesn't use that VS output.  Just allocate
+ * the next free value in that case.  Alternately, we could cull
+ * VS instructions that write to register, or replace the register
+ * with a dummy temp register.
+ * XXX TODO: we should do one of the later as it would save precious
+ * texcoord registers.
  */
 int
-svga_remap_generic_index(const int8_t remap_table[MAX_GENERIC_VARYING],
+svga_remap_generic_index(int8_t remap_table[MAX_GENERIC_VARYING],
                          int generic_index)
 {
    assert(generic_index < MAX_GENERIC_VARYING);
@@ -231,6 +233,17 @@ svga_remap_generic_index(const int8_t remap_table[MAX_GENERIC_VARYING],
       generic_index = MAX_GENERIC_VARYING - 1;
    }
 
+   if (remap_table[generic_index] == -1) {
+      /* This is a VS output that has no matching PS input.  Find a
+       * free index.
+       */
+      int i, max = 0;
+      for (i = 0; i < MAX_GENERIC_VARYING; i++) {
+         max = MAX2(max, remap_table[i]);
+      }
+      remap_table[generic_index] = max + 1;
+   }
+
    return remap_table[generic_index];
 }
 
diff --git a/src/gallium/drivers/svga/svga_tgsi.h b/src/gallium/drivers/svga/svga_tgsi.h
index 01367e9..7e93bf5 100644
--- a/src/gallium/drivers/svga/svga_tgsi.h
+++ b/src/gallium/drivers/svga/svga_tgsi.h
@@ -160,7 +160,7 @@ svga_remap_generics(unsigned generics_mask,
                     int8_t remap_table[MAX_GENERIC_VARYING]);
 
 int
-svga_remap_generic_index(const int8_t remap_table[MAX_GENERIC_VARYING],
+svga_remap_generic_index(int8_t remap_table[MAX_GENERIC_VARYING],
                          int generic_index);
 
 #endif




More information about the mesa-commit mailing list