[Mesa-dev] [PATCH 02/11] nir: add array length field

Rob Clark robdclark at gmail.com
Sat Nov 14 08:55:15 PST 2015


well, clone just needs to know the number of elements, so this is the
simplest possible solution.. not against tracking the type as well, if
that is needed elsewhere.. or if there was a helper to map type to #
of elements, I suppose, but for now this makes clone possible.

BR,
-R

On Sat, Nov 14, 2015 at 11:19 AM, Connor Abbott <cwabbott0 at gmail.com> wrote:
> I think it would be better if we kept track of the type of the
> constant instead. That would also allow us to simplify the constant
> construction code in, err, something else...
>
> On Wed, Nov 11, 2015 at 8:23 PM, Jason Ekstrand <jason at jlekstrand.net> wrote:
>> From: Rob Clark <robclark at freedesktop.org>
>>
>> This will simplify things somewhat in clone.
>>
>> Signed-off-by: Rob Clark <robclark at freedesktop.org>
>> Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com>
>> ---
>>  src/glsl/nir/glsl_to_nir.cpp | 5 +++++
>>  src/glsl/nir/nir.h           | 5 +++++
>>  2 files changed, 10 insertions(+)
>>
>> diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
>> index 8e53e22..13fa987 100644
>> --- a/src/glsl/nir/glsl_to_nir.cpp
>> +++ b/src/glsl/nir/glsl_to_nir.cpp
>> @@ -241,6 +241,8 @@ constant_copy(ir_constant *ir, void *mem_ctx)
>>
>>     unsigned total_elems = ir->type->components();
>>     unsigned i;
>> +
>> +   ret->num_elements = 0;
>>     switch (ir->type->base_type) {
>>     case GLSL_TYPE_UINT:
>>        for (i = 0; i < total_elems; i++)
>> @@ -265,6 +267,8 @@ constant_copy(ir_constant *ir, void *mem_ctx)
>>     case GLSL_TYPE_STRUCT:
>>        ret->elements = ralloc_array(mem_ctx, nir_constant *,
>>                                     ir->type->length);
>> +      ret->num_elements = ir->type->length;
>> +
>>        i = 0;
>>        foreach_in_list(ir_constant, field, &ir->components) {
>>           ret->elements[i] = constant_copy(field, mem_ctx);
>> @@ -275,6 +279,7 @@ constant_copy(ir_constant *ir, void *mem_ctx)
>>     case GLSL_TYPE_ARRAY:
>>        ret->elements = ralloc_array(mem_ctx, nir_constant *,
>>                                     ir->type->length);
>> +      ret->num_elements = ir->type->length;
>>
>>        for (i = 0; i < ir->type->length; i++)
>>           ret->elements[i] = constant_copy(ir->array_elements[i], mem_ctx);
>> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
>> index 6ffa60b..f99af4e 100644
>> --- a/src/glsl/nir/nir.h
>> +++ b/src/glsl/nir/nir.h
>> @@ -111,6 +111,11 @@ typedef struct nir_constant {
>>      */
>>     union nir_constant_data value;
>>
>> +   /* we could get this from the var->type but makes clone *much* easier to
>> +    * not have to care about the type.
>> +    */
>> +   unsigned num_elements;
>> +
>>     /* Array elements / Structure Fields */
>>     struct nir_constant **elements;
>>  } nir_constant;
>> --
>> 2.5.0.400.gff86faf
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list