Mesa (master): glsl: Don' t consider things with a type containing a sampler as an lvalue.

Eric Anholt anholt at kemper.freedesktop.org
Thu Aug 26 06:43:45 UTC 2010


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

Author: Eric Anholt <eric at anholt.net>
Date:   Wed Aug 25 23:27:56 2010 -0700

glsl: Don't consider things with a type containing a sampler as an lvalue.

We had ad-hoc handled some common cases by flagging sampler-typed
variables as read_only, and rejected initializers of samplers.
However, people could sneak them in in all sorts of surprising ways,
like using whole-array or structure assignment.

Fixes:
glslparsertest/glsl2/sampler-01.frag
glslparsertest/glsl2/sampler-03.frag
glslparsertest/glsl2/sampler-04.frag
glslparsertest/glsl2/sampler-06.frag

Bug #27403.

---

 src/glsl/ir.cpp |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index e5ed10d..31e40ca 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -697,6 +697,20 @@ ir_dereference_record::ir_dereference_record(ir_variable *var,
       ? this->record->type->field_type(field) : glsl_type::error_type;
 }
 
+bool type_contains_sampler(const glsl_type *type)
+{
+   if (type->is_array()) {
+      return type_contains_sampler(type->fields.array);
+   } else if (type->is_record()) {
+      for (unsigned int i = 0; i < type->length; i++) {
+	 if (type_contains_sampler(type->fields.structure[i].type))
+	    return true;
+      }
+      return false;
+   } else {
+      return type->is_sampler();
+   }
+}
 
 bool
 ir_dereference::is_lvalue()
@@ -711,6 +725,15 @@ ir_dereference::is_lvalue()
    if (this->type->is_array() && !var->array_lvalue)
       return false;
 
+   /* 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 (type_contains_sampler(this->type))
+      return false;
+
    return true;
 }
 




More information about the mesa-commit mailing list