[Mesa-dev] [PATCH] tgsi/scan: add support to figure out max nesting depth

Brian Paul brianp at vmware.com
Thu Sep 10 07:23:54 PDT 2015


On 09/09/2015 04:47 PM, Kenneth Graunke wrote:
> On Wednesday, September 09, 2015 06:31:06 PM Rob Clark wrote:
>> From: Rob Clark <robclark at freedesktop.org>
>>
>> Sometimes a useful thing for compilers (or, for example, tgsi_to_nir) to
>> know.  And pretty trivial for scan to figure this out for us.
>>
>> Signed-off-by: Rob Clark <robclark at freedesktop.org>
>> ---
>>   src/gallium/auxiliary/tgsi/tgsi_scan.c | 16 ++++++++++++++++
>>   src/gallium/auxiliary/tgsi/tgsi_scan.h |  5 +++++
>>   2 files changed, 21 insertions(+)
>>
>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.c b/src/gallium/auxiliary/tgsi/tgsi_scan.c
>> index 9810b54..66306d7 100644
>> --- a/src/gallium/auxiliary/tgsi/tgsi_scan.c
>> +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.c
>> @@ -56,6 +56,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
>>   {
>>      uint procType, i;
>>      struct tgsi_parse_context parse;
>> +   unsigned current_depth = 0;
>>
>>      memset(info, 0, sizeof(*info));
>>      for (i = 0; i < TGSI_FILE_COUNT; i++)
>> @@ -100,6 +101,21 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
>>               assert(fullinst->Instruction.Opcode < TGSI_OPCODE_LAST);
>>               info->opcode_count[fullinst->Instruction.Opcode]++;
>>
>> +            switch (fullinst->Instruction.Opcode) {
>> +            case TGSI_OPCODE_IF:
>> +            case TGSI_OPCODE_UIF:
>> +            case TGSI_OPCODE_BGNLOOP:
>> +               current_depth++;
>> +               info->max_depth = MAX2(info->max_depth, current_depth);
>> +               break;
>> +            case TGSI_OPCODE_ENDIF:
>> +            case TGSI_OPCODE_ENDLOOP:
>> +               current_depth--;
>> +               break;
>> +            default:
>> +               break;
>> +            }
>> +
>>               if (fullinst->Instruction.Opcode >= TGSI_OPCODE_F2D &&
>>                   fullinst->Instruction.Opcode <= TGSI_OPCODE_DSSG)
>>                  info->uses_doubles = true;
>> diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.h b/src/gallium/auxiliary/tgsi/tgsi_scan.h
>> index c5900bc..42539ee 100644
>> --- a/src/gallium/auxiliary/tgsi/tgsi_scan.h
>> +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.h
>> @@ -113,6 +113,11 @@ struct tgsi_shader_info
>>      unsigned indirect_files_written;
>>
>>      unsigned properties[TGSI_PROPERTY_COUNT]; /* index with TGSI_PROPERTY_ */
>> +
>> +   /**
>> +    * Max nesting limit of loops/if's
>> +    */
>> +   unsigned max_depth;
>>   };
>>
>>   extern void
>>
>
> FWIW, this is
> Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
>
> but you should probably have other Gallium folks review it too.


Reviewed-by: Brian Paul <brianp at vmware.com>




More information about the mesa-dev mailing list