[Mesa-dev] [PATCH 04/16] glsl: Add is_{matrix, record, interface}_or_array_of predicates

Ian Romanick idr at freedesktop.org
Wed Jul 23 15:23:02 PDT 2014


On 07/21/2014 08:03 PM, Timothy Arceri wrote:
> On Mon, 2014-07-21 at 14:04 -0700, Ian Romanick wrote:
>> From: Ian Romanick <ian.d.romanick at intel.com>
>>
>> There are a bunch of places, especially in the UBO code, where we check
>> whether something is a matrix (or record) when we actually want to know
>> if it a matrix or an array of matrices (ditto for records).
> 
> Hi Ian,
> 
> I sent an alternative to this as part of and arrays of arrays series
> (patch 2) back in May [1]. The advantage is that it means adding only
> one extra function to glsl_types rather than three, it supports arrays
> of arrays and is more generic so can be used for other types. 
> I guess it may be a little less readable then your alternative but that
> could probably be fixed by giving it a better name (its wrong anyway as
> it should be innermost not outermost). 

I kind of like that.  I'm not sure about the naming, though.  Neither
innermost_element_type nor outermost_element_type is a good name.  To
me, that would imply that ivec4->innermost_element_type() is float, but
it's actually vec4.

Since this method only peels off array types, the name should
communicate that.  Maybe type_without_array or just without_array?  Then
the code would look like:

    if (var->type->without_array()->is_matrix())
        ...

> Anyway its just a suggestion. It will be easy enough to add arrays of
> arrays support to these functions later on.
> I haven't been working on this for a few weeks but I recall that uniform
> code you changed seems to be fairly arrays of arrays friendly allowing
> my suggestion to be used there [2]
> 
> [1] http://lists.freedesktop.org/archives/mesa-dev/2014-May/059271.html
> [2]
> https://github.com/tarceri/Mesa_arrays_of_arrays/commit/ba422820d0e8b9944fd3d0278913ae3cfbb184b2
> 
> 
>> This will be used in later patches in this series.
>>
>> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
>> ---
>>  src/glsl/glsl_types.h | 24 ++++++++++++++++++++++++
>>  1 file changed, 24 insertions(+)
>>
>> diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
>> index 0b63d48..2dfa8dd 100644
>> --- a/src/glsl/glsl_types.h
>> +++ b/src/glsl/glsl_types.h
>> @@ -354,6 +354,14 @@ struct glsl_type {
>>     }
>>  
>>     /**
>> +    * Query whether or not a type is a matrix or an array of matrices
>> +    */
>> +   bool is_matrix_or_array_of() const
>> +   {
>> +      return is_matrix() || (is_array() && fields.array->is_matrix());
>> +   }
>> +
>> +   /**
>>      * Query whether or not a type is a non-array numeric type
>>      */
>>     bool is_numeric() const
>> @@ -441,6 +449,14 @@ struct glsl_type {
>>     }
>>  
>>     /**
>> +    * Query whether or not a type is a record or an array of records
>> +    */
>> +   bool is_record_or_array_of() const
>> +   {
>> +      return is_record() || (is_array() && fields.array->is_record());
>> +   }
>> +
>> +   /**
>>      * Query whether or not a type is an interface
>>      */
>>     bool is_interface() const
>> @@ -449,6 +465,14 @@ struct glsl_type {
>>     }
>>  
>>     /**
>> +    * Query whether or not a type is an interface or an array of interfaces
>> +    */
>> +   bool is_interface_or_array_of() const
>> +   {
>> +      return is_interface() || (is_array() && fields.array->is_interface());
>> +   }
>> +
>> +   /**
>>      * Query whether or not a type is the void type singleton.
>>      */
>>     bool is_void() const



More information about the mesa-dev mailing list