[Mesa-dev] [PATCH 07/10] glsl: Update ir_variable::max_ifc_array_access properly.

Paul Berry stereotype441 at gmail.com
Wed Oct 9 20:00:55 CEST 2013


On 27 September 2013 12:05, Paul Berry <stereotype441 at gmail.com> wrote:

> This patch adds an implementation of
> ir_dereference_record::update_max_array_access(), which ensures that
> ir_variable::max_ifc_array_access is properly updated to reflect the
> shader's use of arrays appearing within interface blocks.
> ---
>  src/glsl/ir.cpp | 36 ++++++++++++++++++++++++++++++++++++
>  src/glsl/ir.h   |  2 ++
>  2 files changed, 38 insertions(+)
>
> diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
> index 96d4c05..134b100 100644
> --- a/src/glsl/ir.cpp
> +++ b/src/glsl/ir.cpp
> @@ -1367,6 +1367,42 @@
> ir_dereference_record::ir_dereference_record(ir_variable *var,
>     this->type = this->record->type->field_type(field);
>  }
>
> +
> +void
> +ir_dereference_record::update_max_array_access(unsigned idx, YYLTYPE *loc,
> +                                               struct
> _mesa_glsl_parse_state *state)
> +{
> +   /* There are two possibilities we need to consider:
> +    *
> +    * - Accessing an element of an array that is a member of a named
> interface
> +    *   block (e.g. ifc.foo[i])
> +    *
> +    * - Accessing an element of an array that is a member of a named
> interface
> +    *   block array (e.g. ifc[j].foo[i]).
> +    */
> +   ir_dereference_variable *deref_var =
> this->record->as_dereference_variable();
> +   if (deref_var == NULL) {
> +      if (ir_dereference_array *deref_array =
> +          this->record->as_dereference_array()) {
> +         deref_var = deref_array->array->as_dereference_variable();
> +      }
> +   }
> +
> +   if (deref_var != NULL) {
>

Oops, I just noticed that this will crash if it encounters GLSL of the form
foo.bar[i] or foo[i].bar[j] where foo is an ordinary struct (or array of
structs) rather than an interface block.  This is easy to fix--just bail
out if deref_var->var->get_interface_type() returns NULL.

I'll fix this as soon as Jordan and I have resolved our discussion on
"[PATCH 00/10] glsl: Support unsized arrays in interface blocks."


> +      unsigned field_index = this->record->type->field_index(this->field);
> +      assert(field_index < deref_var->var->get_interface_type()->length);

+      if (idx > deref_var->var->max_ifc_array_access[field_index]) {
> +         deref_var->var->max_ifc_array_access[field_index] = idx;
> +
> +         /* Check whether this access will, as a side effect, implicitly
> cause
> +          * the size of a built-in array to be too large.
> +          */
> +         check_builtin_array_max_size(this->field, idx+1, *loc, state);
> +      }
> +   }
> +}
> +
> +
>  bool
>  ir_dereference::is_lvalue() const
>  {
> diff --git a/src/glsl/ir.h b/src/glsl/ir.h
> index 63b7f5d..4f63562 100644
> --- a/src/glsl/ir.h
> +++ b/src/glsl/ir.h
> @@ -1952,6 +1952,8 @@ public:
>     }
>
>     virtual ir_visitor_status accept(ir_hierarchical_visitor *);
> +   virtual void update_max_array_access(unsigned idx, YYLTYPE *loc,
> +                                        struct _mesa_glsl_parse_state
> *state);
>
>     ir_rvalue *record;
>     const char *field;
> --
> 1.8.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20131009/363934f9/attachment-0001.html>


More information about the mesa-dev mailing list