[Mesa-dev] [PATCH] glsl: handle unconditional returns inside a loop

Lars Hamre chemecse at gmail.com
Tue Jun 7 14:43:34 UTC 2016


Hmmm looks like you're right. I thought I was also seeing this crash
in dri swrast, but that's not the case after a second look.
Will investigate more, thanks!

Regards,
Lars Hamre

On Tue, Jun 7, 2016 at 10:10 AM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
> On 07.06.2016 03:21, Lars Hamre wrote:
>>
>> Unrolls the loop with a count of 1 if it contains an unconditional
>> return statement.
>>
>> Fixes the following piglit test:
>> /spec/glsl-1.10/execution/fs-loop-return
>>
>> from crashing at this assert:
>> tgsi/tgsi_exec.c:5952:tgsi_exec_machine_run: Assertion `mach->ContStackTop
>> == 0' failed.
>>
>>
>> Signed-off-by: Lars Hamre <chemecse at gmail.com>
>>
>> ---
>>
>> NOTE: Someone with access will need to commit this after the
>>        review process
>>
>>   src/compiler/glsl/loop_unroll.cpp | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/src/compiler/glsl/loop_unroll.cpp
>> b/src/compiler/glsl/loop_unroll.cpp
>> index bc377df..b1674e4 100644
>> --- a/src/compiler/glsl/loop_unroll.cpp
>> +++ b/src/compiler/glsl/loop_unroll.cpp
>> @@ -337,6 +337,13 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
>>            simple_unroll(ir, 1);
>>         }
>>
>> +      /* If the last instruction of the loop is a return statement,
>> +       * unroll the loop with a count of 1.
>> +       */
>> +      if (last_ir->ir_type == ir_type_return) {
>> +         simple_unroll(ir, 1);
>> +      }
>
>
> I think you need to guard this against last_ir == NULL (empty loop body).
>
> Also, why is this a proper fix for an assertion in tgsi_exec? That feels
> like just hiding the real problem.
>
> Cheers,
> Nicolai
>
>> +
>>         /* Don't try to unroll loops where the number of iterations is not
>> known
>>          * at compile-time.
>>          */
>> --
>> 2.5.5
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>
>


More information about the mesa-dev mailing list