From: Ian Romanick <ian.d.roman...@intel.com> Almost all of the time the location set by layout(location=...) is the location that will be used for the variable. Vertex shader inputs and fragment shader outputs, for example, are visible to the API. We just use those actual settings.
Locations set for varyings, however, are a different story. In those cases, the locations set in the shader are just used to facilitate matching outputs to inputs. We need to track the value so that we can ensure that layout(location=2) out float foo; will be assigned the same resource as layout(location=2) in float bar; but we probably don't want to use 2 as the actual location in the set of varyings. Signed-off-by: Ian Romanick <ian.d.roman...@intel.com> --- src/glsl/ast_to_hir.cpp | 2 ++ src/glsl/ir.cpp | 1 + src/glsl/ir.h | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 8f6e901..965b866 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -2225,6 +2225,8 @@ validate_explicit_location(const struct ast_type_qualifier *qual, assert(!"Unexpected shader type"); break; } + + var->data.user_location = var->data.location; } else { var->data.location = qual->location; } diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index a41eddf..77d02e1 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -1536,6 +1536,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name, this->data.explicit_location = false; this->data.has_initializer = false; this->data.location = -1; + this->data.user_location = -1; this->data.location_frac = 0; this->warn_extension = NULL; this->constant_value = NULL; diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 8fa3b9e..6c77e83 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -672,6 +672,14 @@ public: int location; /** + * Location explicitly set in the shader using a layout qualifier. + * + * \note + * This may not be the location actually uses for this variable. + */ + int user_location; + + /** * output index for dual source blending. */ int index; -- 1.8.1.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev