On Mon, Jan 28, 2013 at 9:50 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 01/28/2013 05:06 PM, Frank Henigman wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
An assertion in fs_visitor::remove_dead_<u></u>constants() would fail on<br>
code like this, which accesses a non-existent uniform:<br>
uniform vec u[1];<br>
...<br>
a += u[0] + u[1];<br>
Shader code is checked for that error, but apparently only before<br>
transformations like loop unrolling. So the following code would get<br>
transformed to the same as above and then the assertion would fail:<br>
for (int i = 0; i < 2; ++i) a += u[i];<br>
<br>
This patch changes the assertion failure to a compile failure.<br>
</blockquote>
<br>
The behavior of an out-of-bounds access is undefined, but compilation is not allowed to fail. I think there are two good solutions:<br></blockquote><div><br></div><div>It's a shame we have to resort to undefined behavior instead of giving a somewhat useful error, but ok.</div>
<div>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.)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br>
2. Clamp the index to the bounds of the array.</blockquote><div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<a href="https://bugs.freedesktop.org/show_bug.cgi?id=59429" target="_blank">https://bugs.freedesktop.org/<u></u>show_bug.cgi?id=59429</a><br>
</blockquote>
<br>
Also... if you're working on a bug, you should assign it to yourself. I was planning to start working on this bug tomorrow. :)<br></blockquote><div><br></div><div>I assigned to Eric when I opened the bug, changed to myself later. Did that not show up when you viewed the bug?</div>
<div>Thanks.</div></div>