[Mesa-dev] [PATCH 04/10] glsl: Create a field to store fractional varying locations.

Paul Berry stereotype441 at gmail.com
Tue Dec 11 15:09:10 PST 2012


Currently, the location of each varying is recorded in ir_variable as
a multiple of the size of a vec4.  In order to pack varyings, we need
to be able to record, e.g. that a vec2 is stored in the second half of
a varying slot rather than the first half.

This patch introduces a field ir_variable::location_frac, which
represents the offset within a vec4 where a varying's value is stored.
Varyings that are not subject to packing will always have a
location_frac value of zero.
---
 src/glsl/ir.cpp     | 1 +
 src/glsl/ir.h       | 9 +++++++++
 src/glsl/linker.cpp | 6 ++++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 7b0a487..703f5ec 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1492,6 +1492,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
    this->explicit_location = false;
    this->has_initializer = false;
    this->location = -1;
+   this->location_frac = 0;
    this->uniform_block = -1;
    this->warn_extension = NULL;
    this->constant_value = NULL;
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index e2ecb3d..85fc5ce 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -446,6 +446,15 @@ public:
    unsigned is_unmatched_generic_inout:1;
 
    /**
+    * If non-zero, then this variable may be packed along with other variables
+    * into a single varying slot, so this offset should be applied when
+    * accessing components.  For example, an offset of 1 means that the x
+    * component of this variable is actually stored in component y of the
+    * location specified by \c location.
+    */
+   unsigned location_frac:2;
+
+   /**
     * \brief Layout qualifier for gl_FragDepth.
     *
     * This is not equal to \c ir_depth_layout_none if and only if this
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index ee6dc25..b13a6aa 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -226,10 +226,12 @@ link_invalidate_variable_locations(gl_shader *sh, int input_base,
       if ((var->location >= base) && !var->explicit_location)
          var->location = -1;
 
-      if ((var->location == -1) && !var->explicit_location)
+      if ((var->location == -1) && !var->explicit_location) {
          var->is_unmatched_generic_inout = 1;
-      else
+         var->location_frac = 0;
+      } else {
          var->is_unmatched_generic_inout = 0;
+      }
    }
 }
 
-- 
1.8.0.1



More information about the mesa-dev mailing list