st/xa: Bind destination before setting new state

Binding a new destination may cause the svga driver to emit draw calls
while propagating the surface. Make sure this doesn't happen in the middle
of sampler state setup where state may be incosistent.

In practice, surface propagation should never happen here and even if it did,
it wouldn't be a valid reason for the svga driver to emit partially set up
state, but to avoid future uncertainties, make sure this doesn't happen
anyway.

Found while auditing the state tracker for inconsistent sampler state /
sampler view setup.

Cc: "10.1" <mesa-stable@freedesktop.org>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
st/xa: Make sure unused samplers are set to NULL

renderer_copy_prepare was setting the first sampler but never telling
the cso code how many samplers were actually used. Fix this.

Cc: "10.1" <mesa-stable@freedesktop.org>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
i965: Use the correct program when uploading Broadwell SOL state.

This is the equivalent of commit 43e77215b13b2f86e461cd8a62b542f.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
i965: Drop BRW_NEW_RASTERIZER_DISCARD flag from Broadwell SOL atom.

Nothing actually uses this---we handle rasterizer discard in the
clipper in order for statistics counters to work.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
i965: Fix missing dirty bits in the gen8_sbe_state atom.

These are clearly needed---the comments in the function are even present
for each one of them.   I originally had two separate state atoms for
3DSTATE_SBE and 3DSTATE_SBE_SWIZ.  When I combined the functions, I must
have forgotten to add the atoms for 3DSTATE_SBE_SWIZ.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
i965: Fix "SIMD16 unsupported" messages via KHR_debug.

Performance warnings are logged via KHR_debug in addition to when the
INTEL_DEBUG=perf environment variable is set.  Without this, messages in
debug contexts would have "(null)" for the reason.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
mesa: Move is_power_of_two() function from brw_context.h to macros.h.

This makes the function available from core Mesa code, including the
GLSL compiler.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
glsl: Make is_16bit_constant from i965 an ir_constant method.

The i965 MUL instruction doesn't natively support 32-bit by 32-bit
integer multiplication; additional instructions (MACH/MOV) are required.
However, we can avoid those if we know one of the operands can be
represented in 16 bits or less.  The vector backend's is_16bit_constant
static helper function checks for this.

We want to be able to use it in the scalar backend as well, which means
moving the function to a more generally-usable location.  Since it isn't
i965 specific, I decided to make it an ir_constant method, in case it
ends up being useful to other people as well.

v2: Rename from is_16bit_integer_constant to is_uint16_constant, as
    suggested by Ilia Mirkin.  Update comments to clarify that it does
    apply to both int and uint types, as long as the value is
    non-negative and fits in 16-bits.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
i965/fs: Skip emitting MACH/MOV for small integers.

The vector backend already implemented this optimization, but
surprisingly, we never bothered to implement it in the scalar backend.

In addition to saving two instructions, this eliminates a use of the
accumulator as an explicit source, which is unsupported in SIMD16 mode
on Gen7+, which could help us gain SIMD16 programs.

Cuts 19.23% of the instructions in dolphin/efb2ram.shader_test.

v2: Rebase on is_16bit_integer_constant -> is_uint16_constant rename.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
glsl: Fix lack of i2u in lower_ubo_reference.

ir_binop_ubo_load takes unsigned integer operands.  However, the array
index used to compute these offsets may be a signed integer.  (For
example, see Piglit's spec/glsl-1.40/uniform_buffer/fs-bvec-array).

For some reason, we were missing an ir_binop_i2u cast, and ir_validator
was failing to catch that.

Without this change, ir_builder's type inference code broke for me when
writing a new optimization pass.

Cc: mesa-stable@lists.freedesktop.org
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
glsl: Validate that base types match for a number of binops.

The IR is not supposed to support implicit type conversions; we just
failed to validate it.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
glsl: Pass ctx->Const.NativeIntegers to do_common_optimization().

The next few patches will introduce an optimization that only works when
integers are not represented as floating point values.

v2: Re-word-wrap a line, as requested by Ian Romanick.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
glsl: Pass ctx->Const.NativeIntegers to do_algebraic.

The next patch will introduce an optimization that only works when
integers are not represented as floating point values.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
i915: Fix build error.

is_power_of_two() is now provided by mesa so its definition must be removed
from the i915 driver code.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
glsl: Skip making a temporary for assignments when we don't need one.

While we wish our optimization passes could identify all the cases where
we can coalesce our variables, we miss out on a lot of opportunities.

total instructions in shared programs: 1673849 -> 1673166 (-0.04%)
instructions in affected programs:     299521 -> 298838 (-0.23%)
GAINED:                                7
LOST:                                  0

Note that many programs are "hurt".  The notable ones are where we produce
unrolling in cases we didn't before (presumably just because of the lower
instruction count).  But there are also some cases where pushing things
right into the variables prevents copy propagation and tree grafting,
since we don't split our variable usage webs apart.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
glsl: Move tree grafting's debug output to stderr.

The rest of our compiler dumps are there, now.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
i965: Remove stale comment.

We stopped doing variable index lowering for uniforms in
a64c1eb9b110f29b8abf803a8256306702629bdc, 5 months after the comment was
added.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
i965: Drop pointless check for variable declarations in splitting.

We're walking the whole instruction stream, so we know the declaration
will be found.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
i965/fs: Fix vgrf0 live interval when no interpolation was done.

When you've got a simple solid-color shader that doesn't generate
pixel_x/y interpolation, we were deciding that the first vgrf was both the
undefined pixel_x and pixel_y, and extending its live interval to avoid
the stride problem.  That tricked other optimization that tries to see if
a particular instruction is the last use of a variable.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
i965/fs: Fix dump_instructions() on uniforms.

All of a vec4 uniform was being printed as "u0"

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>