summaryrefslogtreecommitdiffstats
path: root/src/glsl/nir/nir.c
Commit message (Collapse)AuthorAgeFilesLines
* nir: Add a function for rewriting the condition of an if statementJason Ekstrand2015-05-081-0/+22
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Rewrite instr_rewrite_srcJason Ekstrand2015-04-221-24/+28
| | | | | | | The old code wasn't correctly handling the case where the new value of the source contains an indirect. Reviewed-by: Connor Abbott <[email protected]>
* nir: Move get_const_initializer_load from vars_to_ssa to NIR coreJason Ekstrand2015-04-221-0/+60
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Make nir_*_instr_create take a nir_shader instead of a void * contextJason Ekstrand2015-04-071-18/+18
| | | | | Signed-off-by: Jason Ekstrand <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* nir: Allocate dereferences out of their parent instruction or deref.Kenneth Graunke2015-04-071-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | Jason pointed out that variable dereferences in NIR are really part of their parent instruction, and should have the same lifetime. Unlike in GLSL IR, they're not used very often - just for intrinsic variables, call parameters & return, and indirect samplers for texturing. Also, nir_deref_var is the top-level concept, and nir_deref_array/nir_deref_record are child nodes. This patch attempts to allocate nir_deref_vars out of their parent instruction, and any sub-dereferences out of their parent deref. It enforces these restrictions in the validator as well. This means that freeing an instruction should free its associated dereference chain as well. The memory sweeper pass can also happily ignore them. v2: Rename make_deref to evaluate_deref and make it take a nir_instr * instead of void *. This involves adding &instr->instr everywhere. (Requested by Jason Ekstrand.) Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Allocate nir_ssa_def::uses/if_uses out of the instruction.Kenneth Graunke2015-04-071-4/+2
| | | | | | | | | | We can't allocate them out of the nir_ssa_def itself, because it may not be ralloc'd (for example, nir_dest embeds a nir_ssa_def). However, allocating them out of the instruction should work. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Allocate nir_call_instr::params out of the nir_call itself.Kenneth Graunke2015-04-071-1/+1
| | | | | | | | The lifetime of the params array needs to be match the nir_call_instr itself. So, allocate it using the instruction itself as the context. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Allocate nir_tex_instr::sources out of the instruction itself.Kenneth Graunke2015-04-021-1/+1
| | | | | | | | The lifetime of the sources array needs to be match the nir_tex_instr itself. So, allocate it using the instruction itself as the context. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Allocate predecessor and dominance frontier sets from block itself.Kenneth Graunke2015-04-021-2/+2
| | | | | | | | These sets are part of the block, and their lifetime needs to match the block itself. So, allocate them using the block itself as the context. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Allocate register fields out of the register itself.Kenneth Graunke2015-04-021-3/+3
| | | | | | | | | The lifetime of each register's use/def/if_use sets needs to match the register itself. So, allocate them using the register itself as the context. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Make nir_create_function() strdup the function name.Kenneth Graunke2015-04-021-1/+1
| | | | | | | | | | | | glsl_to_nir passes in the ir_function's name field; we were copying the pointer, but not duplicating the memory. We want to be able to free the linked GLSL IR program after translating to NIR, so we'll need to create a copy of the function name that the NIR shader actually owns. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Use a list instead of a hash_table for inputs, outputs, and uniformsJason Ekstrand2015-03-191-6/+3
| | | | | | | | | | | | We never did a single hash table lookup in the entire NIR code base that I found so there was no real benifit to doing it that way. I suppose that for linking, we'll probably want to be able to lookup by name but we can leave building that hash table to the linker. In the mean time this was causing problems with GLSL IR -> NIR because GLSL IR doesn't guarantee us unique names of uniforms, etc. This was causing massive rendering isues in the unreal4 Sun Temple demo. Reviewed-by: Connor Abbott <[email protected]>
* nir: Delete nir_shader::user_structures and num_user_structures.Kenneth Graunke2015-03-081-3/+0
| | | | | | | | | | | Nothing actually uses these, and the only caller of glsl_to_nir() (brw_fs_nir.cpp) always passes NULL for the _mesa_glsl_parse_state pointer, meaning they'll always be NULL and 0, respectively. Just delete them. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir/register: Add a parent_instr fieldJason Ekstrand2015-02-241-0/+1
| | | | | | | | | | | | | This adds a parent_instr field similar to the one for ssa_def. The difference here is that the parent_instr field on a nir_register can be NULL if the register does not have a unique definition or if that definition does not dominate all its uses. We set this field in the out-of-SSA pass so that backends can get SSA-like information even after they have gone out of SSA. Reviewed-by: Connor Abbott <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* nir: Properly clean up CF nodes when we remove themJason Ekstrand2015-02-191-0/+54
| | | | | | | | | | Previously, if you remved a CF node that still had instructions in it, none of the use/def information from those instructions would get cleaned up. Also, we weren't removing if statements from the if_uses of the corresponding register or SSA def. This commit fixes both of these problems Reviewed-by: Connor Abbott <[email protected]>
* nir: use nir_foreach_ssa_def for indexing ssa defsJason Ekstrand2015-02-191-23/+5
| | | | | | | This is both simpler and more correct. The old code didn't properly index load_const instructions. Reviewed-by: Connor Abbott <[email protected]>
* nir: Add a nir_shader_compiler_options struct pointed to by the shaders.Eric Anholt2015-02-181-1/+3
| | | | | | | | | This will be used to give the optimization passes a chance to customize behavior for the particular target device. v2: Rebase to master (no TGSI->NIR present) Reviewed-by: Kenneth Graunke <[email protected]> (v1)
* nir: Remove casts from void*.Matt Turner2015-02-101-8/+8
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Fix a bit of broken indentation.Eric Anholt2015-01-291-1/+1
| | | | | Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Use pointers for nir_src_copy and nir_dest_copyJason Ekstrand2015-01-261-31/+25
| | | | | | | | This avoids the overhead of copying structures and better matches the newly added nir_alu_src_copy and nir_alu_dest_copy. Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Connor Abbott <[email protected]>
* nir: Make some helpers for copying ALU src/dests.Eric Anholt2015-01-231-0/+18
| | | | | | | | | There aren't many users yet, but I wanted to do this from my scalarizing pass. v2: Constify the src arguments. Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Make an easier helper for setting up SSA defs.Eric Anholt2015-01-221-0/+8
| | | | | | | | Almost all instructions we nir_ssa_def_init() for are nir_dests, and you have to keep from forgetting to set is_ssa when you do. Just provide the simpler helper, instead. Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Add a nir_foreach_phi_src helper macroJason Ekstrand2015-01-201-2/+2
| | | | Reviewed-by: Connor Abbott <cwabbott02gmail.com>
* nir: silence compiler warning from visit_src() callBrian Paul2015-01-151-1/+1
| | | | | | v2: use proper argument Reviewed-by: Connor Abbott <[email protected]>
* util/hash_set: Rework the API to know about hashingJason Ekstrand2015-01-151-29/+27
| | | | | | | | | | | | | | | | | | | | | | | | 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 <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* nir/tex_instr: Add a nir_tex_src struct and dynamically allocate the src arrayJason Ekstrand2015-01-151-2/+3
| | | | | | | | 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 <[email protected]>
* nir: Rename parallel_copy_copy to parallel_copy_entry and add a foreach macroJason Ekstrand2015-01-151-5/+5
| | | | | | | | | | 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 <[email protected]>
* nir/from_ssa: Clean up parallel copy handling and document it betterJason Ekstrand2015-01-151-1/+0
| | | | | | | | | | | | | | | 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 <[email protected]>
* nir: Rename nir_block_following_if to nir_block_get_following_ifJason Ekstrand2015-01-151-1/+1
| | | | | | The new name is a little longer but less confusing. Reviewed-by: Connor Abbott <[email protected]>
* nir: Make load_const SSA-onlyJason Ekstrand2015-01-151-20/+6
| | | | | | | | 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 <[email protected]>
* nir: Make nir_ssa_undef_instr_create initialize the destinationJason Ekstrand2015-01-151-3/+2
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Use nir_foreach_ssa_def for setting up ssa destinationsJason Ekstrand2015-01-151-13/+11
| | | | | | | | | | | | 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 <[email protected]>
* nir: Add a foreach_ssa_def functionJason Ekstrand2015-01-151-0/+40
| | | | | | | | | | | | 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 <[email protected]>: - Fix nir_foreach_ssa_def's return value. Reviewed-by: Connor Abbott <[email protected]>
* nir: Remove predicationJason Ekstrand2015-01-151-35/+0
| | | | | | | | 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 <[email protected]>
* nir/metadata: Rename metadata_dirty to metadata_preserveJason Ekstrand2015-01-151-5/+5
| | | | | | | | | 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 <[email protected]>
* nir/tex_instr_create: Initialize all 4 sourcesJason Ekstrand2015-01-151-1/+1
| | | | | | | This helps a lot with things like lowering passes that may need to add sources. Reviewed-by: Connor Abbott <[email protected]>
* nir/tex_instr: Rename the indirect source type and add an array sizeJason Ekstrand2015-01-151-0/+4
| | | | | | | | | 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 <[email protected]>
* nir: Make texture instruction names more consistentJason Ekstrand2015-01-151-5/+5
| | | | | | | | 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 <[email protected]>
* nir: Add a helper for getting a constant value from an SSA sourceJason Ekstrand2015-01-151-0/+19
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Automatically update SSA if usesJason Ekstrand2015-01-151-5/+4
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Don't require a function in ssa_def_initJason Ekstrand2015-01-151-10/+32
| | | | | | | | 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 <[email protected]>
* nir: Use an integer index for specifying structure fieldsJason Ekstrand2015-01-151-3/+3
| | | | | | | 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 <[email protected]>
* nir: Make array deref direct vs. indirect an enumJason Ekstrand2015-01-151-5/+5
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Clean up nir_deref helper functionsJason Ekstrand2015-01-151-1/+4
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Add a helper for rewriting an instruction sourceJason Ekstrand2015-01-151-0/+61
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir/nir: Patch up phi predecessors in move_successorsJason Ekstrand2015-01-151-2/+23
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir/nir: Use safe iterators when iterating over the CFGJason Ekstrand2015-01-151-8/+10
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir/nir: Fix a bug in move_successorsJason Ekstrand2015-01-151-1/+2
| | | | | | | | The unlink_blocks function moves successors around to make sure that, if there is a remaining successor, it is in the first successors slot and not the second. To fix this, we simply get both successors up front. Reviewed-by: Connor Abbott <[email protected]>
* nir: Add a function for comparing two sourcesJason Ekstrand2015-01-151-0/+27
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir: Add a parallel copy instruction typeJason Ekstrand2015-01-151-1/+44
| | | | Reviewed-by: Connor Abbott <[email protected]>