History log of /external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
1595c79d9c60d8cc03763e64285b691d6748be95 19-Oct-2011 Kenneth Graunke <kenneth@whitecape.org> glsl: Short-circuit lower_if_to_cond_assign when MaxIfDepth is UINT_MAX.

Setting MaxIfDepth to UINT_MAX effectively means "don't lower anything."

Explicitly checking for this common case allows us to avoid walking the
IR, computing nesting levels, and so on.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Bryan Cain <bryancain3@gmail.com>
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
64f11db5587dcfb04446dc9521a70ee8ce692b66 18-Aug-2011 Kenneth Graunke <kenneth@whitecape.org> glsl: Remove unused variable.
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
a352e2d08e0a141298275e77f25541218a97afb7 01-Aug-2011 Ian Romanick <ian.d.romanick@intel.com> glsl: Modify strategy for accumulating conditions when lowering if-statements

Previously if-statements were lowered from inner-most to outer-most
(i.e., bottom-up). All assignments within an if-statement would have
the condition of the if-statement appended to its existing condition.
As a result the assignments from a deeply nested if-statement would
have a very long and complex condition.

Several shaders in the OpenGL ES2 conformance test suite contain
non-constant array indexing that has been lowered by the shader
writer. These tests usually look something like:

if (i == 0) {
value = array[0];
} else if (i == 1) {
value = array[1];
} else ...

The IR for the last assignment ends up as:

(assign (expression bool && (expression bool ! (var_ref if_to_cond_assign_condition) ) (expression bool && (expression bool ! (var_ref if_to_cond_assign_condition@20) ) (expression bool && (expression bool ! (var_ref if_to_cond_assign_condition@22) ) (expression bool && (expression bool ! (var_ref if_to_cond_assign_condition@24) ) (var_ref if_to_cond_assign_condition@26) ) ) ) ) (x) (var_ref value) (array_ref (var_ref array) (constant int (5)))

The Mesa IR that is generated from this is just as awesome as you
might expect.

Three changes are made to the way if-statements are lowered.

1. Two condition variables, if_to_cond_assign_then and
if_to_cond_assign_else, are created for each if-then-else structure.
The former contains the "positive" condition, and the later contains
the "negative" condtion. This change was implemented in the previous
patch.

2. Each condition variable is added to a hash-table when it is created.

3. When lowering an if-statement, assignments to existing condtion
variables get the current condition anded. This ensures that nested
condition variables are only set to true when the condition variable
for all outer if-statements is also true.

Changes #1 and #3 combine to ensure the correctness of the resulting
code.

4. When a condition assignment is encountered with a condition that is
a dereference of a previously added condition variable, the condition
is not modified.

Change #4 prevents the continuous accumulation of conditions on
assignments.

If the original if-statements were:

if (x) {
if (a && b && c && d && e) {
...
} else {
...
}
} else {
if (g && h && i && j && k) {
...
} else {
...
}
}

The lowered code will be

if_to_cond_assign_then@1 = x;
if_to_cond_assign_then@2 = a && b && c && d && e
&& if_to_cond_assign_then@1;
...
if_to_cond_assign_else@2 = !if_to_cond_assign_then
&& if_to_cond_assign_then@1;
...

if_to_cond_assign_else@1 = !if_to_cond_assign_then@1;
if_to_cond_assign_then@3 = g && h && i && j;
&& if_to_cond_assign_else@1;
...
if_to_cond_assign_else@3 = !if_to_cond_assign_then
&& if_to_cond_assign_else@1;
...

Depending on how instructions are emitted, there may be an extra
instruction due to the duplication of the '&&
if_to_cond_assign_{then,else}@1' on the nested else conditions. In
addition, this may cause some unnecessary register pressure since in
the simple case (where the nested conditions are not complex) the
nested then-condition variables are live longer than strictly
necessary.

Before this change, one of the shaders in the OpenGL ES2 conformance
test suite's acos_float_frag_xvary generated 348 Mesa IR instructions.
After this change it only generates 124. Many, but not all, of these
instructions would have also been eliminated by CSE.

Reviewed-by: Eric Anholt <eric@anholt.net>
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
4a026d6ba50034c326eb6cfd0b555f57d83ab609 01-Aug-2011 Ian Romanick <ian.d.romanick@intel.com> glsl: Slight change to the code generated by if-flattening

Now the condition (for the then-clause) and the inverse condition (for
the else-clause) get written to separate temporary variables. In the
presence of complex conditions, this shouldn't result in more code
being generated. If the original if-statement was

if (a && b && c && d && e) {
...
} else {
...
}

The lowered code will be

if_to_cond_assign_then = a && b && c && d && e;
...
if_to_cond_assign_else = !if_to_cond_assign_then;
...

Reviewed-by: Eric Anholt <eric@anholt.net>
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
13df36ecb6c24ea36534fa0dfea917aca8233710 01-Aug-2011 Ian Romanick <ian.d.romanick@intel.com> glsl: Replace foreach_iter with foreach_list_safe

Reviewed-by: Eric Anholt <eric@anholt.net>
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
5c843785417225ba582878a15a5ae13b7b961aaa 01-Aug-2011 Ian Romanick <ian.d.romanick@intel.com> glsl: Make move_block_to_cond_assign not care which branch it's processing

This will make some future changes a bit easier to digest.

Reviewed-by: Eric Anholt <eric@anholt.net>
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
d2c6cef18aa37d197eb323a0795969d271d02819 02-Jun-2011 Ian Romanick <ian.d.romanick@intel.com> glsl: Fix depth unbalancing problem in if-statement flattening

Previously, if max_depth were 1, the following code would see the
first if-statement (correctly) not get flattened, but the second
if-statement would (incorrectly) get flattened:

void main()
{
if (a)
gl_Position = vec4(0);

if (b)
gl_Position = vec4(1);
}

This is because the visit_leave(ir_if*) method would not decrement the
depth before returning on the first if-statement.

NOTE: This is a candidate for the 7.10 and 7.11 branches.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
d3073f58c17d8675a2ecdd5dfa83e5520c78e1a8 21-Jan-2011 Kenneth Graunke <kenneth@whitecape.org> Convert everything from the talloc API to the ralloc API.
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
9ac6a9b2fa45debac63f2e2b20d78c4776d06e37 27-Dec-2010 Kenneth Graunke <kenneth@whitecape.org> glsl: Support if-flattening beyond a given maximum nesting depth.

This adds a new optional max_depth parameter (defaulting to 0) to
lower_if_to_cond_assign, and makes the pass only flatten if-statements
nested deeper than that.

By default, all if-statements will be flattened, just like before.

This patch also renames do_if_to_cond_assign to lower_if_to_cond_assign,
to match the new naming conventions.
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
df883eb1575a740bf91e01cbe2eaa4dbc1f9f154 17-Nov-2010 Chad Versace <chad.versace@intel.com> glsl: Fix Doxygen tag \file in recently renamed files
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp
32aaf89823de11e98cb59d5ec78c66cd3e74bcd4 15-Nov-2010 Kenneth Graunke <kenneth@whitecape.org> glsl: Rename various ir_* files to lower_* and opt_*.

This helps distinguish between lowering passes, optimization passes, and
other compiler code.
/external/mesa3d/src/glsl/lower_if_to_cond_assign.cpp