summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Berry <stereotype441@gmail.com>2011-07-12 12:03:02 -0700
committerIan Romanick <ian.d.romanick@intel.com>2011-07-19 16:39:56 -0700
commitf80ae99cbd21f48d1ade360f18748fce5ca1d8f8 (patch)
tree13a8408d26a4c60c49cbe79511f5418f14d200f3
parentae11fb02dd267fa103093290b3fe51022eb16d57 (diff)
glsl: Ensure that sampler declarations are always uniform or "in" parameters.
This brings us into compliance with page 17 (page 22 of the PDF) of the GLSL 1.20 spec: "[Sampler types] can only be declared as function parameters or uniform variables (see Section 4.3.5 "Uniform"). ... [Samplers] cannot be used as out or inout function parameters." The spec isn't explicit about whether this rule applies to structs/arrays containing shaders, but the intent seems to be to ensure that it can always be determined at compile time which sampler is being used in each texture lookup. So to avoid creating a loophole, the rule needs to apply to structs/arrays containing shaders as well. Fixes piglit tests spec/glsl-1.10/compiler/samplers/*.frag, and fixes bug 38987. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38987 Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> (cherry picked from commit f07221056e1822187546b76387714b3172f9b2c5)
-rw-r--r--src/glsl/ast_to_hir.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 35cb2067060..11e76c4f5d7 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2696,6 +2696,17 @@ ast_declarator_list::hir(exec_list *instructions,
: "and integer");
}
+ /* From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
+ *
+ * "[Sampler types] can only be declared as function
+ * parameters or uniform variables (see Section 4.3.5
+ * "Uniform")".
+ */
+ if (var_type->contains_sampler() &&
+ !this->type->qualifier.flags.q.uniform) {
+ _mesa_glsl_error(&loc, state, "samplers must be declared uniform");
+ }
+
/* Process the initializer and add its instructions to a temporary
* list. This list will be added to the instruction stream (below) after
* the declaration is added. This is done because in some cases (such as
@@ -2856,6 +2867,18 @@ ast_parameter_declarator::hir(exec_list *instructions,
*/
apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc);
+ /* From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
+ *
+ * "Samplers cannot be treated as l-values; hence cannot be used
+ * as out or inout function parameters, nor can they be assigned
+ * into."
+ */
+ if ((var->mode == ir_var_inout || var->mode == ir_var_out)
+ && type->contains_sampler()) {
+ _mesa_glsl_error(&loc, state, "out and inout parameters cannot contain samplers");
+ type = glsl_type::error_type;
+ }
+
instructions->push_tail(var);
/* Parameter declarations do not have r-values.
@@ -2984,6 +3007,18 @@ ast_function::hir(exec_list *instructions,
"function `%s' return type has qualifiers", name);
}
+ /* From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
+ *
+ * "[Sampler types] can only be declared as function parameters
+ * or uniform variables (see Section 4.3.5 "Uniform")".
+ */
+ if (return_type->contains_sampler()) {
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(&loc, state,
+ "function `%s' return type can't contain a sampler",
+ name);
+ }
+
/* Verify that this function's signature either doesn't match a previously
* seen signature for a function with the same name, or, if a match is found,
* that the previously seen signature does not have an associated definition.