Mesa (master): glsl: Restrict functions to not return arrays or SOAs in GLSL 1.00.

Eric Anholt anholt at kemper.freedesktop.org
Mon May 8 19:34:58 UTC 2017


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

Author: Eric Anholt <eric at anholt.net>
Date:   Mon May  1 16:00:47 2017 -0700

glsl: Restrict functions to not return arrays or SOAs in GLSL 1.00.

>From the spec,

    Arrays are allowed as arguments, but not as the return type. [...] The
    return type can also be a structure if the structure does not contain
    an array.

Fixes DEQP shaders.functions.invalid.return_array_in_struct_fragment.

v2: Spec cite wording change

Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Tested-by: Matt Turner <mattst88 at gmail.com>

---

 src/compiler/glsl/ast_to_hir.cpp | 12 ++++++++++++
 src/compiler/glsl_types.cpp      | 13 +++++++++++++
 src/compiler/glsl_types.h        |  6 ++++++
 3 files changed, 31 insertions(+)

diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 1114d9e459..33490c831c 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -5825,6 +5825,18 @@ ast_function::hir(exec_list *instructions,
                        "sized", name);
    }
 
+   /* From Section 6.1 (Function Definitions) of the GLSL 1.00 spec:
+    *
+    *     "Arrays are allowed as arguments, but not as the return type. [...]
+    *      The return type can also be a structure if the structure does not
+    *      contain an array."
+    */
+   if (state->language_version == 100 && return_type->contains_array()) {
+      YYLTYPE loc = this->get_location();
+      _mesa_glsl_error(& loc, state,
+                       "function `%s' return type contains an array", name);
+   }
+
    /* From section 4.1.7 of the GLSL 4.40 spec:
     *
     *    "[Opaque types] can only be declared as function parameters
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 43c0188e47..0fd12305b7 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -220,6 +220,19 @@ glsl_type::contains_sampler() const
    }
 }
 
+bool
+glsl_type::contains_array() const
+{
+   if (this->is_record() || this->is_interface()) {
+      for (unsigned int i = 0; i < this->length; i++) {
+         if (this->fields.structure[i].type->contains_array())
+            return true;
+      }
+      return false;
+   } else {
+      return this->is_array();
+   }
+}
 
 bool
 glsl_type::contains_integer() const
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index 67c152119f..9da0cbcc3b 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -563,6 +563,12 @@ struct glsl_type {
    bool contains_sampler() const;
 
    /**
+    * Query whether or not type is an array or for struct, interface and
+    * array types, contains an array.
+    */
+   bool contains_array() const;
+
+   /**
     * Get the Mesa texture target index for a sampler type.
     */
    gl_texture_index sampler_index() const;




More information about the mesa-commit mailing list