mesa.git
9 years agoi965/gen6: Fix crash with VS+TF after rendering with GS
Iago Toral Quiroga [Wed, 7 Jan 2015 09:08:57 +0000 (10:08 +0100)]
i965/gen6: Fix crash with VS+TF after rendering with GS

Rendering with a GS and then using transform feedback with a program that does
not have a GS can crash in gen6. The reason for this is that
brw_begin_transform_feedback checks brw->geometry_program to decide if there
is a GS program, but this is not correct: brw->geometry_program is updated when
issuing drawing commands, so after rendering with a GS it will be non-NULL
until we draw again with a program that does not have a GS. If the next
program uses TF, we will call glBegintransformFeedback before issuing
the drawing command and hence brw->geometry_program will be non-NULL if
the previous rendering used a GS. The right thing to do here is to check
ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY] instead. This is what the
gen7 code path does too.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=87694
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
9 years agonir/live_variables: Use a worklist
Jason Ekstrand [Fri, 19 Dec 2014 19:49:58 +0000 (11:49 -0800)]
nir/live_variables: Use a worklist

This is a rework of the liveness algorithm using a worklist as suggested by
Connor.  Doing so reduces the number of times we walk over the instructions
because we don't have to do an entire pointless walk over the instructions
just to figure out it's time to stop.  Also, the stuff after the last loop
in the funciton will only ever get visited once.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a worklist helper structure
Jason Ekstrand [Fri, 19 Dec 2014 19:05:02 +0000 (11:05 -0800)]
nir: Add a worklist helper structure

A worklist is a common concept in optimizations.  This adds a structure
that we can reuse for many different types of optimizations.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: fix incorrect argument passed to validate_src() in validate_tex_instr()
Brian Paul [Fri, 16 Jan 2015 00:38:39 +0000 (17:38 -0700)]
nir: fix incorrect argument passed to validate_src() in validate_tex_instr()

Silences a compiler warning.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: silence compiler warning from visit_src() call
Brian Paul [Thu, 15 Jan 2015 22:28:14 +0000 (15:28 -0700)]
nir: silence compiler warning from visit_src() call

v2: use proper argument

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agomesa: move GET_CURRENT_CONTEXT() to top of _mesa_init_renderbuffer()
Brian Paul [Thu, 15 Jan 2015 22:30:40 +0000 (15:30 -0700)]
mesa: move GET_CURRENT_CONTEXT() to top of _mesa_init_renderbuffer()

To fix MSVC build.

Reviewed-by: Matt Turner <mattst88@gmail.com>
9 years agomesa: Fix render buffer initial internal format in GLES 3
Mike Mason [Wed, 14 Jan 2015 20:12:27 +0000 (12:12 -0800)]
mesa: Fix render buffer initial internal format in GLES 3

Changes the initial internal format of a render buffer
to GL_RGBA4 in GLES 3. This fixes a failure in the following
DrawElements test:

  dEQP-GLES3.functional.state_query.rbo.renderbuffer_internal_format

Reviewed-by: Chad Versace <chad.versace@intel.com>
9 years agoutil/hash_set: Rework the API to know about hashing
Jason Ekstrand [Thu, 15 Jan 2015 17:31:18 +0000 (09:31 -0800)]
util/hash_set:  Rework the API to know about hashing

Previously, the set API required the user to do all of the hashing of keys
as it passed them in.  Since the hashing function is intrinsically tied to
the comparison function, it makes sense for the hash set to know about
it.  Also, it makes for a somewhat clumsy API as the user is constantly
calling hashing functions many of which have long names.  This is
especially bad when the standard call looks something like

_mesa_set_add(ht, _mesa_pointer_hash(key), key);

In the above case, there is no reason why the hash set shouldn't do the
hashing for you.  We leave the option for you to do your own hashing if
it's more efficient, but it's no longer needed.  Also, if you do do your
own hashing, the hash set will assert that your hash matches what it
expects out of the hashing function.  This should make it harder to mess up
your hashing.

This is analygous to 94303a0750 where we did this for hash_table

Signed-off-by: Jason Ekstrand <jason.ekstrand@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
9 years agoutil: Move main/set to util/hash_set
Jason Ekstrand [Thu, 15 Jan 2015 16:06:05 +0000 (08:06 -0800)]
util: Move main/set to util/hash_set

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
9 years agohash_table: Rename insert_with_hash to insert_pre_hashed
Jason Ekstrand [Thu, 15 Jan 2015 15:58:07 +0000 (07:58 -0800)]
hash_table: Rename insert_with_hash to insert_pre_hashed

We already have search_pre_hashed.  This makes the APIs match better.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
9 years agoi965: Don't consider null dst instructions as matching non-null dst.
Matt Turner [Mon, 12 Jan 2015 21:58:06 +0000 (13:58 -0800)]
i965: Don't consider null dst instructions as matching non-null dst.

When performing common subexpression elimination on instructions with
non-null destinations we emit a MOV to copy the result to a new
register that must have no other uses. In the case of:

   cmp.g.f0.0(8) null:D, vgrf43:F, 0.500000f
   ...
   cmp.g.f0.0(8) vgrf113:D, vgrf43:F, 0.500000f

we put the first instruction in the AEB and decided that we could reuse
its result when we found the second. Unfortunately, that meant that we'd
emit a MOV from the first's destination, which is null.

Don't do anything if the entry's destination is null and the
instruction's destination is non-null.

Tested-by: Tapani Pälli <tapani.palli@intel.com>
9 years agoi965/vec4: Make sure that imm writes are to registers in the same file.
Matt Turner [Mon, 12 Jan 2015 18:48:04 +0000 (10:48 -0800)]
i965/vec4: Make sure that imm writes are to registers in the same file.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=87887

9 years agoi965/fs: Emit MADs from (x + abs(y * z)).
Matt Turner [Tue, 13 Jan 2015 21:35:15 +0000 (13:35 -0800)]
i965/fs: Emit MADs from (x + abs(y * z)).

Just use the abs source modifier on both of the multiplicand
arguments.

instructions in affected programs:     300 -> 296 (-1.33%)

Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
9 years agoi965/fs: Emit MADs from (x + -(y * z)).
Matt Turner [Sat, 20 Dec 2014 05:30:16 +0000 (21:30 -0800)]
i965/fs: Emit MADs from (x + -(y * z)).

Just use the negation source modifier on one of the multiplicand
arguments.

total instructions in shared programs: 5889529 -> 5880016 (-0.16%)
instructions in affected programs:     600846 -> 591333 (-1.58%)

Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
9 years agonir/algebraic: Only replace an instruction once
Jason Ekstrand [Thu, 15 Jan 2015 03:08:32 +0000 (19:08 -0800)]
nir/algebraic: Only replace an instruction once

Without the break, it was possible that an instruction would match multiple
expressions.  If this happened, you could end up trying to replace it
multiple times and get a segfault.  This makes it so that, after a
successful replacement, it moves on to the next instruction.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/nir: Do a final copy lowering pass before lowering locals to regs
Jason Ekstrand [Wed, 14 Jan 2015 23:25:52 +0000 (15:25 -0800)]
i965/nir: Do a final copy lowering pass before lowering locals to regs

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/vars_to_ssa: Use the copy lowering from lower_var_copies
Jason Ekstrand [Wed, 14 Jan 2015 23:20:49 +0000 (15:20 -0800)]
nir/vars_to_ssa: Use the copy lowering from lower_var_copies

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a pass for lowering copy instructions
Jason Ekstrand [Wed, 14 Jan 2015 23:19:49 +0000 (15:19 -0800)]
nir: Add a pass for lowering copy instructions

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/vars_to_ssa: Refactor get_deref_node
Jason Ekstrand [Wed, 14 Jan 2015 22:00:12 +0000 (14:00 -0800)]
nir/vars_to_ssa: Refactor get_deref_node

This refactor allows you to more easily get the deref node associated with
a given variable.  We then use that new functionality in the
deref_may_be_aliased function instead of creating a 1-element deref chain.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Rename lower_variables to lower_vars_to_ssa
Jason Ekstrand [Wed, 14 Jan 2015 20:41:15 +0000 (12:41 -0800)]
nir: Rename lower_variables to lower_vars_to_ssa

The original name wasn't particularly descriptive.  This one indicates that
it actually gives you SSA values as opposed to the old pass which lowered
variables to registers.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/tex_instr: Add a nir_tex_src struct and dynamically allocate the src array
Jason Ekstrand [Sat, 10 Jan 2015 04:01:13 +0000 (20:01 -0800)]
nir/tex_instr: Add a nir_tex_src struct and dynamically allocate the src array

This solves a number of problems.  First is the ability to change the
number of sources that a texture instruction has.  Second, it solves the
delema that may occur if a texture instruction has more than 4 sources.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/validate: Only build in debug mode
Jason Ekstrand [Wed, 7 Jan 2015 00:11:57 +0000 (16:11 -0800)]
nir/validate: Only build in debug mode

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/lower_variables: Improve documentation
Jason Ekstrand [Tue, 6 Jan 2015 21:15:40 +0000 (13:15 -0800)]
nir/lower_variables: Improve documentation

Additional description was added to a variety of places.  Also, we no
longer use the term "leaf" to describe fully-qualified direct derefs.
Instead, we simply use the term "direct" or spell it out completely.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/lower_variables: Use a for loop for get_deref_node
Jason Ekstrand [Tue, 6 Jan 2015 21:14:00 +0000 (13:14 -0800)]
nir/lower_variables: Use a for loop for get_deref_node

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Use the actual FNV-1a hash for hashing derefs
Jason Ekstrand [Tue, 6 Jan 2015 19:13:22 +0000 (11:13 -0800)]
nir: Use the actual FNV-1a hash for hashing derefs

We also switch to using loops rather than recursion.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoutil/hash_table: Pull the details of the FNV-1a into helpers
Jason Ekstrand [Tue, 6 Jan 2015 06:31:23 +0000 (22:31 -0800)]
util/hash_table: Pull the details of the FNV-1a into helpers

This way the basics of the FNV-1a hash can be reused to easily create other
hashing functions.

Reviewed-by: Eric Anholt <eric@anholt.net>
9 years agonir: Make intrinsic flags into an enum
Jason Ekstrand [Fri, 19 Dec 2014 23:56:55 +0000 (15:56 -0800)]
nir: Make intrinsic flags into an enum

This should be much better for debugging as GDB will pick up on the fact
that it's an enum and actually tell you what you're looking at instead of
giving you some arbitrary hex value you have to go look up.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Use static inlines instead of macros for list getters
Jason Ekstrand [Fri, 19 Dec 2014 23:30:15 +0000 (15:30 -0800)]
nir: Use static inlines instead of macros for list getters

This should make debugging a lot easier as GDB handles static inlines much
better than macros.  Also, static inlines are typesafe.

Reviewed-By: Glenn Kennard <glenn.kennard@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/variable: Remove the constant_value field
Jason Ekstrand [Fri, 19 Dec 2014 22:55:45 +0000 (14:55 -0800)]
nir/variable: Remove the constant_value field

This was a left-over relic of GLSL IR that we aren't using for anything.
If we ever want that value again, we can add it back, but NIR constant
folding should be just as good as GLSL IR's if not better pretty soon, so
I'm not worried about it.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add some documentation
Jason Ekstrand [Fri, 19 Dec 2014 01:13:22 +0000 (17:13 -0800)]
nir: Add some documentation

Signed-off-by: Jason Ekstrand <jason.ekstrand@intel.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/lower_variables: Follow the Cytron paper more closely
Jason Ekstrand [Thu, 18 Dec 2014 22:42:01 +0000 (14:42 -0800)]
nir/lower_variables: Follow the Cytron paper more closely

Previously, our variable renaming algorithm, while similar to the one in
the Cytron paper, was not the same.  While I'm pretty sure it was correct,
it will be easier for readers of the code in the variable renaming pass if
it follows more closely.  This commit removes the automatic stack popping
we were doing and replaces it with explicit popping like Cytron does.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/print: Various cleanups recommended by Eric
Jason Ekstrand [Thu, 18 Dec 2014 22:01:37 +0000 (14:01 -0800)]
nir/print: Various cleanups recommended by Eric

Cc: Eric Anholt <eric@anholt.net>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/lower_variables: Add a bunch of comments and re-arrange a few things
Jason Ekstrand [Thu, 18 Dec 2014 21:49:43 +0000 (13:49 -0800)]
nir/lower_variables: Add a bunch of comments and re-arrange a few things

This commit seeks to make the lower_variables pass much more clear by
adding a pile of comments and re-arranging a few things.  There are no
functional or algorithmic changes.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Rename parallel_copy_copy to parallel_copy_entry and add a foreach macro
Jason Ekstrand [Thu, 18 Dec 2014 00:53:04 +0000 (16:53 -0800)]
nir: Rename parallel_copy_copy to parallel_copy_entry and add a foreach macro

parallel_copy_copy was a silly name.  Also, things were getting long and
annoying, so I added a foreach macro.  For historical reasons, several of
the original iterations over parallel copy entries in from_ssa used the
_safe variants of the loop.  However, all of these no longer ever remove an
entry so it's ok to make them all use the normal iterator.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/from_ssa: Clean up parallel copy handling and document it better
Jason Ekstrand [Wed, 17 Dec 2014 23:34:47 +0000 (15:34 -0800)]
nir/from_ssa: Clean up parallel copy handling and document it better

Previously, we were doing a lazy creation of the parallel copy
instructions.  This is confusing, hard to get right, and involves some
extra state tracking of the copies.  This commit adds an extra walk over
the basic blocks to add the block-end parallel copies up front.  This
should be much less confusing and, consequently, easier to get right.  This
commit also adds more comments about parallel copies to help explain what
all is going on.

As a consequence of these changes, we can now remove the at_end parameter
from nir_parallel_copy_instr.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Rename nir_block_following_if to nir_block_get_following_if
Jason Ekstrand [Wed, 17 Dec 2014 22:49:24 +0000 (14:49 -0800)]
nir: Rename nir_block_following_if to nir_block_get_following_if

The new name is a little longer but less confusing.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/fs_nir: Handle sample ID, position, and mask better
Jason Ekstrand [Wed, 17 Dec 2014 20:34:27 +0000 (12:34 -0800)]
i965/fs_nir: Handle sample ID, position, and mask better

Before, we were emitting the full pile of setup instructions for sample_id
and sample_pos every time they were used.  With this commit, we emit them
in their own pass once at the beginning of the shader and simply emit uses
later on.  When it comes time for setting up VS, we can put setup for its
special values in the same pass.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/opcodes: Remove the per_component info field
Jason Ekstrand [Tue, 16 Dec 2014 22:43:26 +0000 (14:43 -0800)]
nir/opcodes: Remove the per_component info field

Originally, this field was intended for determining if the given
instruction acted per-component or if it had mismatching source and
destination sizes that would have to be interpreted specially.  However, we
can easily derive this from output_size == 0, so it's not really that
useful.  Also, the values we were setting in nir_opcodes.h for this field
were completely bogus and it was never used.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/search: Use nir_op_infos to determine if an operation is commutative
Jason Ekstrand [Tue, 16 Dec 2014 20:26:38 +0000 (12:26 -0800)]
nir/search: Use nir_op_infos to determine if an operation is commutative

Prior to this commit, we had a big switch statement for this.  Now it's
baked into the opcode metadata so we can just use that.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/opcodes: Add algebraic properties metadata
Jason Ekstrand [Tue, 16 Dec 2014 20:22:01 +0000 (12:22 -0800)]
nir/opcodes: Add algebraic properties metadata

This commit adds some algebraic properties to the metadata of each opcode
in NIR.  In particular, you now know, just from the metadata, if a given
opcode is commutative or associative.  This will be useful for algebraic
transformation passes that want to be able to match a + b as well as b + a
in one go.

v2: Make algebraic properties all caps.  This was more consistent with the
    intrinsics flags and seems better for flags in general.

    Also, the enums are now declared with (1 << n) rather then hex values.

v3: fmin and fmax technically aren't commutative or associative.  Things
    get funny when one of the arguments is a NaN.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Make load_const SSA-only
Jason Ekstrand [Tue, 16 Dec 2014 01:32:56 +0000 (17:32 -0800)]
nir: Make load_const SSA-only

As it was, we weren't ever using load_const in a non-SSA way.  This allows
us to substantially simplify the load_const instruction.  If we ever need a
non-SSA constant load, we can do a load_const and an imov.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Make nir_ssa_undef_instr_create initialize the destination
Jason Ekstrand [Tue, 16 Dec 2014 01:44:37 +0000 (17:44 -0800)]
nir: Make nir_ssa_undef_instr_create initialize the destination

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/nir: Move the other lowering passes to before out-of-SSA
Jason Ekstrand [Tue, 16 Dec 2014 00:12:04 +0000 (16:12 -0800)]
i965/nir: Move the other lowering passes to before out-of-SSA

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/lower_system_values: Handle SSA destinations
Jason Ekstrand [Tue, 16 Dec 2014 01:37:07 +0000 (17:37 -0800)]
nir/lower_system_values: Handle SSA destinations

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/lower_atomics: Use/support SSA
Jason Ekstrand [Tue, 16 Dec 2014 00:23:21 +0000 (16:23 -0800)]
nir/lower_atomics: Use/support SSA

Previously, lower_atomics was non-SSA only.  We assert-failed if the
destination of an atomic operation intrinsic was an SSA def and we used
temporary registers for computing offsets.  This commit changes both of
these behaviors.  We now use SSA values for computing offsets (so we can
optimize them) and we handle SSA destinations.  We also move the pass to
run before we go out of SSA on i965 as it now generates SSA values.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/live_variables: Use the new ssa_def iterator
Jason Ekstrand [Mon, 15 Dec 2014 23:15:01 +0000 (15:15 -0800)]
nir/live_variables: Use the new ssa_def iterator

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Use nir_foreach_ssa_def for setting up ssa destinations
Jason Ekstrand [Tue, 16 Dec 2014 03:38:14 +0000 (19:38 -0800)]
nir: Use nir_foreach_ssa_def for setting up ssa destinations

Before, we were using foreach_dest and switching on whether the destination
was an SSA value.  This works, except not all destinations are SSA values
so we have to special-case ssa_undef instructions.  Now that we have a
foreach_ssa_def function, we can iterate over all of the register
destinations in one pass and iterate over the SSA destinations in a second.
This way, if we add other ssa-only instructions, we won't have to worry
about adding them to the special case we have for ssa_undef.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a foreach_ssa_def function
Jason Ekstrand [Mon, 15 Dec 2014 23:12:59 +0000 (15:12 -0800)]
nir: Add a foreach_ssa_def function

There are some functions whose destinations are SSA-only and so aren't a
nir_dest.  This provides a function that is capable of iterating over the
SSA definitions defined by those functions.  If you want registers, you
should use the old iterator.

v2: Kenneth Graunke <kenneth@whitecape.org>:
 - Fix nir_foreach_ssa_def's return value.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/lower_variables: Use a real dominance DFS for variable renaming
Jason Ekstrand [Mon, 15 Dec 2014 22:06:58 +0000 (14:06 -0800)]
nir/lower_variables: Use a real dominance DFS for variable renaming

Previously, we were just iterating over the program "in order" which
kind-of approximates a DFS, but not really.  In particular, we got the
following case wrong:

loop {
   a = 3;
   if (foo) {
      a = 5;
   } else {
      break;
   }
   use(a);
}

where use(a) would get 3 instead of 5 because of premature popping of the
SSA def stack.  Now, since we do an actaul DFS, we should evaluate use(a)
immediately after a = 5 and we should be ok.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Remove predication
Jason Ekstrand [Sat, 13 Dec 2014 06:38:41 +0000 (22:38 -0800)]
nir: Remove predication

We stopped generating predicates in glsl_to_nir some time ago.  Right now,
it's all dead untested code that I'm not convinced always worked in the
first place.  If we decide we want them back, we can revert this patch.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Make bcsel a fully vector operation
Jason Ekstrand [Sat, 13 Dec 2014 04:37:04 +0000 (20:37 -0800)]
nir: Make bcsel a fully vector operation

Previously, the condition was a scalar that applied to all components
simultaneously.  As of this commit, the condition is a vector and each
component is switched seperately.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Call nir_metadata_preserve more places
Jason Ekstrand [Sat, 13 Dec 2014 00:25:38 +0000 (16:25 -0800)]
nir: Call nir_metadata_preserve more places

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/metadata: Rename metadata_dirty to metadata_preserve
Jason Ekstrand [Sat, 13 Dec 2014 00:22:46 +0000 (16:22 -0800)]
nir/metadata: Rename metadata_dirty to metadata_preserve

nir_metadata_dirty was a terrible name because the parameter it takes is
the metadata to be preserved.  This is really confusing because it looks
like it's doing the opposite of what it is actually doing.  Now it's named
sensibly.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/fs_nir: Add support for indirect texture arrays
Jason Ekstrand [Sat, 6 Dec 2014 00:43:56 +0000 (16:43 -0800)]
i965/fs_nir: Add support for indirect texture arrays

v2 Jason Ekstrand <jason.ekstrand@intel.com>:
 - Use the nir_tex_src_sampler_offset source type instead of the
   sampler_indirect thing that I cooked up before.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
9 years agonir: Rework the way samplers are lowered
Jason Ekstrand [Sat, 6 Dec 2014 00:09:53 +0000 (16:09 -0800)]
nir: Rework the way samplers are lowered

v2 Jason Ekstrand <jason.ekstrand@intel.com>:
 - Use the nir_tex_src_sampler_offset source type instead of the
   sampler_indirect thing that I cooked up before.

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
9 years agonir/tex_instr_create: Initialize all 4 sources
Jason Ekstrand [Thu, 8 Jan 2015 01:52:37 +0000 (17:52 -0800)]
nir/tex_instr_create: Initialize all 4 sources

This helps a lot with things like lowering passes that may need to add
sources.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/tex_instr: Rename the indirect source type and add an array size
Jason Ekstrand [Fri, 5 Dec 2014 22:46:24 +0000 (14:46 -0800)]
nir/tex_instr: Rename the indirect source type and add an array size

In particular, we rename nir_tex_src_sampler_index to _sampler_offset and
add a sampler_array_size field to nir_tex_instr.  This way we can pass the
size of sampler arrays through to backends even after removing the variable
information and, with it, the type.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Use a source for uniform buffer indices instead of an index
Jason Ekstrand [Tue, 9 Dec 2014 01:34:52 +0000 (17:34 -0800)]
nir: Use a source for uniform buffer indices instead of an index

In GLSL-to-NIR we were just setting the base index to 0 whenever there was
an indirect so having it expressed as a sum makes no sense.  Also, while a
base offset may make sense for the memory location (first element in the
array, etc.) it makes less sense for the actual uniform buffer index.  This
may change later, but it seems to make more sense for now.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Constant fold array indirects
Jason Ekstrand [Fri, 5 Dec 2014 20:05:55 +0000 (12:05 -0800)]
nir: Constant fold array indirects

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Make texture instruction names more consistent
Jason Ekstrand [Fri, 5 Dec 2014 19:03:06 +0000 (11:03 -0800)]
nir: Make texture instruction names more consistent

This commit renames nir_instr_as_texture to nir_instr_as_tex and renames
nir_instr_type_texture to nir_instr_type_tex to be consistent with
nir_tex_instr.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Remove the ffma peephole
Jason Ekstrand [Sat, 15 Nov 2014 06:09:27 +0000 (22:09 -0800)]
nir: Remove the ffma peephole

This is no longer needed because it's now part of the algebraic
optimization pass

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a basic constant folding pass
Jason Ekstrand [Sat, 15 Nov 2014 05:35:25 +0000 (21:35 -0800)]
nir: Add a basic constant folding pass

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add an algebraic optimization pass
Jason Ekstrand [Fri, 12 Dec 2014 19:13:10 +0000 (11:13 -0800)]
nir: Add an algebraic optimization pass

This pass uses the previously built algebraic transformations framework and
should act as an example for anyone else wanting to make an algebraic
transformation pass for NIR.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add infastructure for generating algebraic transformation passes
Jason Ekstrand [Sat, 15 Nov 2014 01:47:56 +0000 (17:47 -0800)]
nir: Add infastructure for generating algebraic transformation passes

This commit builds on the nir_search.h infastructure by adding a bit of
python code that makes it stupid easy to write an algebraic transformation
pass.  The nir_algebraic.py file contains four python classes that
correspond directly to the datastructures in nir_search.c and allow you to
easily generate the C code to represent them.  Given a list of
search-and-replace operations, it can then generate a function that applies
those transformations to a shader.

The transformations can be specified manually, or they can be specified
using nested tuples.  The nested tuples make a neat little language for
specifying expression trees and search-and-replace operations in a very
readable and easy-to-edit fasion.

The generated code is also fairly efficient.  Insteady of blindly calling
nir_replace_instr with every single transformation and on every single
instruction, it uses a switch statement on the instruction opcode to do a
first-order culling and only calls nir_replace_instr if the opcode is known
to match the first opcode in the search expression.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add an expression matching framework
Jason Ekstrand [Fri, 14 Nov 2014 05:19:28 +0000 (21:19 -0800)]
nir: Add an expression matching framework

This framework provides a simple way to do simple search-and-replace
operations on NIR code.  The nir_search.h header provides four simple data
structures for representing expressions:  nir_value and four subtypes:
nir_variable, nir_constant, and nir_expression.  An expression tree can
then be represented by nesting these data structures as needed.  The
nir_replace_instr function takes an instruction, an expression, and a
value; if the instruction matches the expression, it is replaced with a new
chain of instructions to generate the given replacement value.  The
framework keeps track of swizzles on sources and automatically generates
the currect swizzles for the replacement value.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/glsl: Emit abs, neg, and sat operations instead of source modifiers
Jason Ekstrand [Fri, 14 Nov 2014 01:23:58 +0000 (17:23 -0800)]
nir/glsl: Emit abs, neg, and sat operations instead of source modifiers

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Make the type casting operations static inline functions
Jason Ekstrand [Fri, 5 Dec 2014 19:00:05 +0000 (11:00 -0800)]
nir: Make the type casting operations static inline functions

Previously, the casting operations were macros.  While this is usually
fine, the casting macro used the input parameter twice leading to strange
behavior when you passed the result of another function into it.  Since we
know the source and destination types explicitly, we don't loose anything
by making it a function.

Also, this gives us a nice little macro for creating cast function that
will hopefully prevent mistyping.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a lowering pass for adding source modifiers where possible
Jason Ekstrand [Thu, 13 Nov 2014 03:18:05 +0000 (19:18 -0800)]
nir: Add a lowering pass for adding source modifiers where possible

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add neg, abs, and sat opcodes
Jason Ekstrand [Fri, 14 Nov 2014 01:19:20 +0000 (17:19 -0800)]
nir: Add neg, abs, and sat opcodes

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/fs_nir: Implement the ARB_gpu_shader5 interpolation intrinsics
Jason Ekstrand [Thu, 4 Dec 2014 23:24:13 +0000 (15:24 -0800)]
i965/fs_nir: Implement the ARB_gpu_shader5 interpolation intrinsics

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
9 years agoi965/fs_nir: Add a has_indirect flag and clean up some of the input/output code
Jason Ekstrand [Thu, 4 Dec 2014 20:27:29 +0000 (12:27 -0800)]
i965/fs_nir: Add a has_indirect flag and clean up some of the input/output code

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a helper for getting a constant value from an SSA source
Jason Ekstrand [Tue, 9 Dec 2014 01:34:23 +0000 (17:34 -0800)]
nir: Add a helper for getting a constant value from an SSA source

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/glsl: Add support for gpu_shader5 interpolation instrinsics
Jason Ekstrand [Thu, 4 Dec 2014 20:16:33 +0000 (12:16 -0800)]
nir/glsl: Add support for gpu_shader5 interpolation instrinsics

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add gpu_shader5 interpolation intrinsics
Jason Ekstrand [Thu, 4 Dec 2014 20:16:06 +0000 (12:16 -0800)]
nir: Add gpu_shader5 interpolation intrinsics

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/validate: Validate intrinsic source/destination sizes
Jason Ekstrand [Thu, 4 Dec 2014 18:41:17 +0000 (10:41 -0800)]
nir/validate: Validate intrinsic source/destination sizes

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Vectorize intrinsics
Jason Ekstrand [Thu, 4 Dec 2014 01:03:19 +0000 (17:03 -0800)]
nir: Vectorize intrinsics

We used to have the number of components built into the intrinsic.  This
meant that all of our load/store intrinsics had vec1, vec2, vec3, and vec4
variants.  This lead to piles of switch statements to generate the correct
intrinsic names, and introspection to figure out the number of components.
We can make things much nicer by allowing "vectorized" intrinsics.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Remove the old variable lowering code
Jason Ekstrand [Thu, 4 Dec 2014 00:25:35 +0000 (16:25 -0800)]
nir: Remove the old variable lowering code

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/validate: Ensure that outputs are write-only and inputs are read-only
Jason Ekstrand [Wed, 3 Dec 2014 22:47:17 +0000 (14:47 -0800)]
nir/validate: Ensure that outputs are write-only and inputs are read-only

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/fs_nir: Use the new variable lowering code
Jason Ekstrand [Wed, 26 Nov 2014 23:07:27 +0000 (15:07 -0800)]
i965/fs_nir: Use the new variable lowering code

This commit switches us over to the new variable lowering code which is
capable of properly handling lowering indirects as we go.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/glsl: Generate SSA NIR
Jason Ekstrand [Mon, 1 Dec 2014 22:11:04 +0000 (14:11 -0800)]
nir/glsl: Generate SSA NIR

With this commit, the GLSL IR -> NIR pass generates NIR in more-or-less SSA
form.  It's SSA in the sense that it doesn't have any registers, but it
isn't really useful SSA because it still has a pile of load/store
intrinsics that we will need to get rid of.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a pass to lower global variables to local variables
Jason Ekstrand [Tue, 2 Dec 2014 20:48:38 +0000 (12:48 -0800)]
nir: Add a pass to lower global variables to local variables

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a pass for lowering input/output loads/stores
Jason Ekstrand [Tue, 2 Dec 2014 06:01:05 +0000 (22:01 -0800)]
nir: Add a pass for lowering input/output loads/stores

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a pass to lower local variables to registers
Jason Ekstrand [Tue, 2 Dec 2014 04:29:35 +0000 (20:29 -0800)]
nir: Add a pass to lower local variables to registers

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a pass to lower local variable accesses to SSA values
Jason Ekstrand [Fri, 14 Nov 2014 01:16:31 +0000 (17:16 -0800)]
nir: Add a pass to lower local variable accesses to SSA values

This pass analizes all of the load/store operations and, when a variable is
never aliased (potentially used by an indirect operation), it is lowered
directly to an SSA value.  This pass translates to SSA directly and does
not require any fixup by the original to-SSA pass.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a copy splitting pass
Jason Ekstrand [Wed, 19 Nov 2014 22:52:30 +0000 (14:52 -0800)]
nir: Add a copy splitting pass

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Automatically update SSA if uses
Jason Ekstrand [Mon, 1 Dec 2014 22:39:10 +0000 (14:39 -0800)]
nir: Automatically update SSA if uses

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/fs_nir: Don't dump the shader.
Jason Ekstrand [Mon, 1 Dec 2014 23:09:17 +0000 (15:09 -0800)]
i965/fs_nir: Don't dump the shader.

This is killing piglit.  I'll leave the logging local

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/glsl: Don't allocate a state_slots array for 0 state slots
Jason Ekstrand [Wed, 3 Dec 2014 02:07:13 +0000 (18:07 -0800)]
nir/glsl: Don't allocate a state_slots array for 0 state slots

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Validate that the sources of a phi have the same size as the destination
Jason Ekstrand [Tue, 25 Nov 2014 05:26:41 +0000 (21:26 -0800)]
nir: Validate that the sources of a phi have the same size as the destination

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/copy_propagate: Don't cause size mismatches on phi node sources
Jason Ekstrand [Tue, 25 Nov 2014 06:42:16 +0000 (22:42 -0800)]
nir/copy_propagate: Don't cause size mismatches on phi node sources

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Don't require a function in ssa_def_init
Jason Ekstrand [Thu, 20 Nov 2014 00:06:32 +0000 (16:06 -0800)]
nir: Don't require a function in ssa_def_init

Instead, we give SSA definitions a temporary index of 0xFFFFFFFF if the
instruction does not have a block and a proper index when it actually gets
added to the list.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Use an integer index for specifying structure fields
Jason Ekstrand [Wed, 26 Nov 2014 05:36:25 +0000 (21:36 -0800)]
nir: Use an integer index for specifying structure fields

Previously, we used a string name.  It was nice for translating out of GLSL
IR (which also does that) but cumbersome the rest of the time.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a concept of a wildcard array dereference
Jason Ekstrand [Wed, 19 Nov 2014 20:59:57 +0000 (12:59 -0800)]
nir: Add a concept of a wildcard array dereference

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Make array deref direct vs. indirect an enum
Jason Ekstrand [Wed, 19 Nov 2014 20:53:08 +0000 (12:53 -0800)]
nir: Make array deref direct vs. indirect an enum

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Clean up nir_deref helper functions
Jason Ekstrand [Thu, 13 Nov 2014 22:53:01 +0000 (14:53 -0800)]
nir: Clean up nir_deref helper functions

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/lower_samplers: Use the nir_instr_rewrite_src function
Jason Ekstrand [Fri, 14 Nov 2014 17:46:48 +0000 (09:46 -0800)]
nir/lower_samplers: Use the nir_instr_rewrite_src function

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir: Add a helper for rewriting an instruction source
Jason Ekstrand [Fri, 14 Nov 2014 03:07:22 +0000 (19:07 -0800)]
nir: Add a helper for rewriting an instruction source

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/fs_nir: Properly saturate multiplies
Jason Ekstrand [Fri, 14 Nov 2014 05:34:41 +0000 (21:34 -0800)]
i965/fs_nir: Properly saturate multiplies

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agonir/from_ssa: Don't lower constant SSA values to registers
Jason Ekstrand [Wed, 14 Jan 2015 19:19:41 +0000 (11:19 -0800)]
nir/from_ssa: Don't lower constant SSA values to registers

Backends want to be able to do special things with constant values such as
put them into immediates or make decisions based on whether or not a value
is constant.  Before, constants always got lowered to a load_const into a
register and then a register use.  Now we leave constants as SSA values so
backends can special-case them if they want.  Since handling constant SSA
values is trivial, this shouldn't be a problem for backends.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
9 years agoi965/fs_nir: Handle SSA constants
Jason Ekstrand [Thu, 13 Nov 2014 00:24:21 +0000 (16:24 -0800)]
i965/fs_nir: Handle SSA constants

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>