[Mesa-dev] [PATCH 1/5] glsl: Restrict functions to not return arrays or SOAs in GLSL 1.00.
Samuel Pitoiset
samuel.pitoiset at gmail.com
Tue May 2 20:38:57 UTC 2017
On 05/02/2017 07:36 PM, Eric Anholt wrote:
> 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.
> ---
> 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 1159b2cdfbf9..9e02529dffb9 100644
> --- a/src/compiler/glsl/ast_to_hir.cpp
> +++ b/src/compiler/glsl/ast_to_hir.cpp
> @@ -5608,6 +5608,18 @@ ast_function::hir(exec_list *instructions,
> "sized", name);
> }
>
> + /* Section 6.1 (Function Definitions) of the GLSL 1.00 spec says:
Looks like we usually format like:
/* 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 0480bef80eca..a52625ad7b52 100644
> --- a/src/compiler/glsl_types.cpp
> +++ b/src/compiler/glsl_types.cpp
> @@ -225,6 +225,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 403663f7b87a..6b2de11117c2 100644
> --- a/src/compiler/glsl_types.h
> +++ b/src/compiler/glsl_types.h
> @@ -561,6 +561,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-dev
mailing list