glsl: Create a field to store fractional varying locations.
authorPaul Berry <stereotype441@gmail.com>
Wed, 5 Dec 2012 18:47:55 +0000 (10:47 -0800)
committerPaul Berry <stereotype441@gmail.com>
Fri, 14 Dec 2012 18:48:52 +0000 (10:48 -0800)
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.

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/ir.cpp
src/glsl/ir.h
src/glsl/linker.cpp

index 7b0a487b6fc6c5b976f8be6246bb9260a6eb706e..703f5ec58eff5faa93f5be6da375e10b0511dba7 100644 (file)
@@ -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;
index e2ecb3d9dfdef515521961a7402ca712259789fa..85fc5ce95da144965827c428bcb5078c36a3ce66 100644 (file)
@@ -445,6 +445,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.
     *
index ee6dc2596d04f2274dfea25061928008ebba4079..b13a6aa1ab649e318b8ac3503aa3590cc1a6e9dd 100644 (file)
@@ -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;
+      }
    }
 }