[Mesa-dev] [PATCH 1/2] intel: fail to compile in case of bad uniform access

Frank Henigman fjhenigman at google.com
Wed Feb 6 11:17:55 PST 2013


On Mon, Jan 28, 2013 at 9:50 PM, Ian Romanick <idr at freedesktop.org> wrote:

> On 01/28/2013 05:06 PM, Frank Henigman wrote:
>
>> An assertion in fs_visitor::remove_dead_**constants() would fail on
>> code like this, which accesses a non-existent uniform:
>>    uniform vec u[1];
>>    ...
>>    a += u[0] + u[1];
>> Shader code is checked for that error, but apparently only before
>> transformations like loop unrolling.  So the following code would get
>> transformed to the same as above and then the assertion would fail:
>>    for (int i = 0; i < 2; ++i) a += u[i];
>>
>> This patch changes the assertion failure to a compile failure.
>>
>
> The behavior of an out-of-bounds access is undefined, but compilation is
> not allowed to fail.  I think there are two good solutions:
>

It's a shame we have to resort to undefined behavior instead of giving a
somewhat useful error, but ok.
Out of curiosity, would be ok to fail at compile time instead of link time?
 (I wrote "compile failure" above but it happened at link time.)


> 1. Always generate zero.  I believe this is what DX requires, so there may
> be apps ported from DX that assume this behavior.  This is also what
> happens when you access out of bounds of a UBO.
>
> 2. Clamp the index to the bounds of the array.


Do you mean at compile time or run time?  Or both?  Would run-time checks
ever fly in mesa or is it too bad for performance?  Sorry about all the
questions.

There is a third option which is even simpler: do nothing.  But it occurs
to me there may be other functions (now or in the future) besides
remove_dead_constants() which might be similarly unprepared for
out-of-bounds access, so there's something to be said for zeroing/clamping
them all out early, in addition to your DX point.


>  https://bugs.freedesktop.org/**show_bug.cgi?id=59429<https://bugs.freedesktop.org/show_bug.cgi?id=59429>
>>
>
> Also... if you're working on a bug, you should assign it to yourself.  I
> was planning to start working on this bug tomorrow. :)
>

I assigned to Eric when I opened the bug, changed to myself later.  Did
that not show up when you viewed the bug?
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130206/b2b21761/attachment.html>


More information about the mesa-dev mailing list