meta/blit: Add stencil texturing mode save and restore

v2 (Ken): Only restore the mode if it has changed.

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Cc: "10.2" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
i965/meta: Store stencil texturing mode

Meta path needs to keep the current texture object's state. Fixes
the following gles3 cts tests on bdw:

framebuffer_blit_functionality_negative_width_blit.test: fail
framebuffer_blit_functionality_all_buffer_blit.test: fail
framebuffer_blit_functionality_negative_height_blit.test: fail
framebuffer_blit_functionality_missing_buffers_blit.test: fail
framebuffer_blit_functionality_negative_dimensions_blit.test: fail
framebuffer_blit_functionality_minifying_blit.test: fail
framebuffer_blit_functionality_magnifying_blit.test: fail

Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Cc: "10.2" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
glsl: be more consistent about printing constants

Make sure that we print the same number of digits when printing 0.0 as
any other floating-point number. This will make generating expected
output files for tests easier. To avoid breaking "make check," update
the generated tests for lower_jumps before the next commit which will
bring create_test_cases.py in line with them.
glsl/tests/lower_jumps: fix generated sexpr's for loops

In 088494aa (as well as other commits in the series) Paul Berry modified
the tests for lower_jumps to account for the fact that the s-expression
for the loop IR instruction changed from
(loop () () () () (statements...)) to (loop (statements...)), but he
forgot to update create_test_cases.py which he used to create the tests.
Fix that, so that now create_test_cases.py is synced with the generated
tests.
glsl/tests: call create_test_cases.py in optimization-test

This way, when someone modifies create_test_cases.py and forgets to
commit their changes again, people will notice.

v2: make sure we parse the right directories and check for existance the
right way.
glsl/tests: remove generated tests from the repo

They were made unneccesary by the last commit.
glsl: fix handling of quadop_vector constant expression

We forgot to handle the case where the base type was a boolean.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add as_loop_jump() method to ir_instruction

This will let us dynamically downcast to ir_loop_jump, which will be
needed later.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add a foreach_list_reverse macro

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add dead branch analysis

Dead branch analysis determines when the then or else branches of an
if statement will always terminate in a loop jump or return statement,
and hence once we enter that branch we will never get to the statements
after the if. This is useful for determining the dominance tree, which
is needed for the conversion to SSA, as well as various other SSA-based
optimizations.

v2:
-fix & add more comments, store outer_db instead of looking it up (Paul
Berry)

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add loop jump visitor

This visitor will allow us to determine all the loop jumps that
correspond to each loop. In SSA form, each input to a phi node is
associated with a predecessor basic block. In the case of phi nodes
at the beginning and end of loops, these predecessor blocks will
include all blocks that end with a loop_jump (break or continue), and
so in order to insert phi nodes we must know all the loop_jump
instructions that correspond to each loop.

v2:
-add more comments
-store outer_lj instead of looking it up (Paul Berry)

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add swizzle_component() to ir_builder

Like swizzle_x(), swizzle_y(), etc., except the index is programmable.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add SSA infrastructure

This patch introduces all the changes to the IR that are necessary for
representing programs in the SSA form. This consists of a new variable
mode, the SSA temporary, which is guarenteed to be written to exactly
once, and classes to represent phi nodes in the IR.

In the current code, variables are first declared using an ir_variable
instruction inserted into the instruction stream, and then every
dereference will point to the ir_variable declared earlier. SSA
temporaries, however, do not work this way. Instead, the variable
is declared when it is assigned. That is, the variable is "owned" by
the one and only instruction where it is defined.

In SSA, phi nodes may exist at the beginning of any "join nodes," or
basic blocks with more than one predecessor. In our IR, this can happen
in one of three places:

- After an if statement, where the then branch and the else branch
converge.
- At the beginning of a loop, which can be reached from either before
the loop (on the first iteration), the end of the loop (when we get to
the end of the loop and jump back to the beginning), or any continue
statement.
- At the end of a loop, which can be reached from any break statement
within the loop.

Accordingly, there are three different types of phi nodes: if phi nodes,
phi nodes at the beginning of a loop, and phi nodes at the end of a
loop, all of which derive from the ir_phi base class.

v2:

-make ir_phi constructor take the destination (Paul)
-merge ssa_phi, ssa_call, and ssa_assignment into ssa_owner (Paul)
-make ir_phi an abstract class and remove visit(ir_phi *) from ir_visitor
(Paul)
-fix bugs in ir_clone where ssa_owner sometimes wasn't being set
-simplify printing phi node sources (Paul)
-make the name of if/loop phi nodes more consistent when printing (Paul)
-add more invariants to ir_validate (Paul)
glsl: add ssa_assign() to ir_builder

ssa_assign() creates an SSA variable and assignment at the same
time. With this, simple sequences of SSA statements can be easily
created.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add pass to convert GLSL IR to SSA form

opt_to_ssa will convert temporaries and local variables to SSA form,
although for now it can't handle array and record dereferences.

v2:
-move class declarations out to a separate header file, move
convert_to_ssa() to the beginning (Paul)
-tons more comments (Paul)
-move some code from ir_ssa_variable_state::stack_push() to
ir_ssa_variable_state::new_var(), add more asserts (Paul)
-fix logic in ir_phi_insertion_visitor::visit(ir_dereference_variable *)
(Paul) and optimize it to bail out early in the case of duplicate phi
nodes
-make the control flow stack be a singly-linked list instead of an
exec_list (Paul)
-reorder and rename things in the rewrite visitors to make what's
happening more obvious
-make sure to delete undefined_var when removing a variable from
consideration for conversion to SSA
-use the correct semantics when generating ir_triop_csel (the condition
must be the size of the inputs)
glsl: fixup ir_reader for SSA

Make it understand phi nodes and labeled breaks and continues.
glsl: fixup existing unit tests for SSA changes

This is just adding empty lists for phi nodes and adding names to
breaks and continues.
glsl: add a pass to convert out of SSA form

Right now we are being basically as naive as possible, and inserting
more copies than necessary. It is possible to implement a more
sophisticated algorithm later, although extending the current copy
propagation pass to support loops better and/or relying on backends to
do copy propagation may make this unecessary.

v2:
-fix potentially confusing comment (Paul)
-don't manually walk through function signatures (Paul)
-fix bug where ssa_owner wasn't getting set to NULL

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: convert to and from SSA form in the compiler

This patch is mainly for allowing me to test these changes with piglit.
In the future, a do_ssa_optimizations() function will need to be
created and used by this code, as well as all other users of
do_common_optimizations().

Reviewed-by: Paul Berry <stereotype441@gmail.com>