[Mesa-dev] [PATCH v2 6/6] glsl: Ignore loop-too-large heuristic if there's bad variable indexing.
Eric Anholt
eric at anholt.net
Fri Apr 11 15:41:43 PDT 2014
Kenneth Graunke <kenneth at whitecape.org> writes:
> Many shaders use a pattern such as:
>
> for (int i = 0; i < NUM_LIGHTS; i++) {
> ...access a uniform array, or shader input/output array...
> }
>
> where NUM_LIGHTS is a small constant (such as 2, 4, or 8).
>
> The expectation is that the compiler will unroll those loops, turning
> the array access into constant indexing, which is more efficient, and
> which may enable array splitting and other optimizations.
>
> In many cases, our heuristic fails - either there's another tiny nested
> loop inside, or the estimated number of instructions is just barely
> beyond the threshold. So, we fail to unroll the loop, leaving the
> variable indexing in place.
>
> Drivers which don't support the particular flavor of variable indexing
> will call lower_variable_index_to_cond_assign(), which generates piles
> and piles of immensely inefficient code. We'd like to avoid generating
> that.
>
> This patch detects unsupported forms of variable-indexing in loops, where
> the array index is a loop induction variable. In that case, it bypasses
> the loop-too-large heuristic and forces unrolling.
>
> Improves performance in a PCF soft-shadow microbenchmark by 2x.
> No changes in shader-db.
>
> v2: Check ir->array for being an array or matrix, rather than the
> ir_dereference_array itself.
>
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
This series is:
Reviewed-by: Eric Anholt <eric at anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140411/7b50557d/attachment.sig>
More information about the mesa-dev
mailing list