<div class="gmail_quote">On Tue, Aug 31, 2010 at 2:14 AM, Ian Romanick <span dir="ltr">&lt;<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
While I was trying to get one of the Humus demos working today, it<br>
occurred to me that we can possibly do better than<br>
ir_vec_index_to_cond_assign to lower variable indexing of vectors.  In<br>
addition to using conditional assignment, we can also use a dot-product<br>
to pick a single element out of a vector.  The variable index operation<br>
becomes:<br>
<br>
const vec4 gl_vec_selector[4] =<br>
    vec4[4](vec4(1.0, 0.0, 0.0, 0.0),<br>
            vec4(0.0, 1.0, 0.0, 0.0),<br>
            vec4(0.0, 0.0, 1.0, 0.0),<br>
            vec4(0.0, 0.0, 0.0, 1.0));<br>
<br>
...<br>
<br>
float f = dot(v, gl_vec_selector[i]);<br>
<br>
This potentially replaces a big pile of instructions with three:<br>
<br>
 1. Load the address register.<br>
 2. Do the dot-product.<br>
 3. Re-load the address register.<br>
<br>
This means we&#39;d also want to add support to ir_algebraic to convert<br>
dot(v, vec3(0.0, 1.0, 0.0)) to v.y.<br>
<br>
The down-side is that it uses constant slots.  Architectures that lack<br>
the ability to do real vector indexing also tend to be starved for both<br>
instructions and constant slots.  R500 may be an exception here, but<br>
R300 and i915 are definitely in this category.  Are there cases where<br>
this optimization could cause a shader to not fit in hardware limits<br>
when it would have otherwise?<br></blockquote><div><br>Neither r300 nor r500 supports the ARL opcode in fragment shaders (it&#39;s a D3D10 feature), which kind of makes this optimization a no-go. I suggest using SEQ instead:<br>

<br>bvec4 selector = equal(vec4(i), vec4(0,1,2,3));<br>float f = dot(v, vec4(selector));<br><br>which should end up being just SEQ followed by DP4.<br><br>Marek<br></div></div>