aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/spirv/vtn_cfg.c
Commit message (Collapse)AuthorAgeFilesLines
* nir/spirv: return after emitting a branch in blockcros-mesa-19.0-r1-vanillachadv/cros-mesa-19.0-r1-vanillaJuan A. Suarez Romero2019-02-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | When emitting a branch in a block, it does not make sense to continue processing further instructions, as they will not be reachable. This fixes a nasty case with a loop with a branch that both then-part and else-part exits the loop: %1 = OpLabel OpLoopMerge %2 %3 None OpBranchConditional %false %2 %2 %3 = OpLabel OpBranch %1 %2 = OpLabel [...] We know that block %1 will branch always to block %2, which is the merge block for the loop. And thus a break is emitted. If we keep continuing processing further instructions, we will be processing the branch conditional and thus emitting the proper NIR conditional, which leads to instructions after the break. This fixes dEQP-VK.graphicsfuzz.continue-and-merge. CC: Jason Ekstrand <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir/spirv: handle ContractionOff execution modeKarol Herbst2019-01-211-0/+2
| | | | | | Signed-off-by: Karol Herbst <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]> Reviewed-by: Bas Nieuwenhuizen <[email protected]>
* nir: rename nir_var_function to nir_var_function_tempKarol Herbst2019-01-191-1/+1
| | | | | | | | Signed-off-by: Karol Herbst <[email protected]> Acked-by: Jason Ekstrand <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Bas Nieuwenhuizen <[email protected]>
* src/compiler: use new hash table and set creation helpersCaio Marcelo de Oliveira Filho2019-01-141-2/+1
| | | | | | | | | Replace calls to create hash tables and sets that use _mesa_hash_pointer/_mesa_key_pointer_equal with the helpers _mesa_pointer_hash_table_create() and _mesa_pointer_set_create(). Reviewed-by: Jason Ekstrand <[email protected]> Acked-by: Eric Engestrom <[email protected]>
* spirv: Emit switch conditions on-the-flyJason Ekstrand2019-01-121-36/+26
| | | | | | | | | | | | | Instead of emitting all of the conditions for the cases of a switch statement up-front, emit them on-the-fly as we emit the code for each case. The original justification for this was that we were going to have to build a default case anyway which would need them all. However, we can just trust CSE to clean up the mess in that case. Emitting each condition right before the if statement that uses it reduces register pressure and, in one customer benchmark, reduces spilling and improves performance by about 2x. Reviewed-by: Lionel Landwerlin <[email protected]>
* nir: rename global/local to private/function memoryKarol Herbst2019-01-081-1/+1
| | | | | | | | | | | | | | | | | | the naming is a bit confusing no matter how you look at it. Within SPIR-V "global" memory is memory accessible from all threads. glsl "global" memory normally refers to shader thread private memory declared at global scope. As we already use "shared" for memory shared across all thrads of a work group the solution where everybody could be happy with is to rename "global" to "private" and use "global" later for memory usually stored within system accessible memory (be it VRAM or system RAM if keeping SVM in mind). glsl "local" memory is memory only accessible within a function, while SPIR-V "local" memory is memory accessible within the same workgroup. v2: rename local to function as well v3: rename vtn_variable_mode_local as well Signed-off-by: Karol Herbst <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Add a ptr_as_array deref typeJason Ekstrand2019-01-081-1/+1
| | | | | | | | | | | | | | These correspond directly to SPIR-V's OpPtrAccessChain. As such, they treat whatever their parent gives them as if it's the first element in some array and dereferences that array. If the parent is, itself, an array deref, then the two indices can just be added together to get the final array deref. However, it can also be used in cases where what you have is a dereference to some random vec2 value somewhere. In this case, we require a cast before the ptr_as_array and use the ptr_stride field in the cast to provide a stride for the ptr_as_array derefs. Reviewed-by: Alejandro Piñeiro <[email protected]> Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]>
* spirv: Propagate layout decorations to created glsl_typesJason Ekstrand2019-01-081-2/+6
| | | | | | | | | | | | | | | Instead of just storing the decorations in the vtn_type, propagate them all the way through to the glsl_type. For array strides, this means we need to handle them earlier so we break array stride handling into it's own function and explicitly call it for both pointer and array types. Due to type deduplication in the SPIR-V, we may have explicit layout decorations on all sorts of types that don't actually want them. In order to prevent these leaking into unfortunate places in NIR, we explicitly strip them off before creating NIR variables and when casting pointers to non-external memory. Reviewed-by: Alejandro Piñeiro <[email protected]>
* spirv: Emit NIR deref instructions on-the-flyJason Ekstrand2019-01-081-0/+2
| | | | | | | | | | | | | | | This simplifies our deref handling by emitting the actual NIR deref instructions on-the-fly instead of of building up a deref chain and then emitting them at the last moment. In order for this to work with the parts of the compiler that assume they can chase deref chains, we have to run nir_rematerialize_derefs_in_use_blocks_impl to put the derefs back in the right places. Otherwise, in cases such as loop continues where the SPIR-V blocks are not in the same order as the NIR blocks, we may end up with a deref chain with a parent that does not dominate it's child and nir_repair_ssa_impl will insert phis in the deref chain. Reviewed-by: Alejandro Piñeiro <[email protected]> Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]>
* spirv: Fix matrix parameters in function calls.Bas Nieuwenhuizen2019-01-081-0/+4
| | | | | | | | | | They can be handled exactly the same as arrays, we just need to handle the base type correctly in the switches. Fixes: a45b6fb4524 "spirv: Pass SSA values through functions" Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109204 Reviewed-by: Jason Ekstrand <[email protected]> Reviewed-by: Samuel Pitoiset <[email protected]>
* spirv: Pass SSA values through functionsJason Ekstrand2018-10-301-41/+139
| | | | | | | | Previously, we would create temporary variables and fill them out. Instead, we create as many function parameters as we need and pass them through as SSA defs. Reviewed-by: Iago Toral Quiroga <[email protected]>
* nir/builder: Add a nir_imm_true/false helpersJason Ekstrand2018-10-261-5/+5
| | | | | Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* spirv: Move function call handling to vtn_cfgJason Ekstrand2018-10-021-0/+63
| | | | | | | It makes way more sense for it to live there with the rest of function handling. Reviewed-by: Iago Toral Quiroga <[email protected]>
* nir,spirv: Rework function callsJason Ekstrand2018-06-221-118/+103
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit completely reworks function calls in NIR. Instead of having a set of variables for the parameters and return value, nir_call_instr now has simply has a number of sources which get mapped to load_param intrinsics inside the functions. It's up to the client API to build an ABI on top of that. In SPIR-V, out parameters are handled by passing the result of a deref through as an SSA value and storing to it. This virtue of this approach can be seen by how much it allows us to delete from core NIR. In particular, nir_inline_functions gets halved and goes from a fairly difficult pass to understand in detail to almost trivial. It also simplifies spirv_to_nir somewhat because NIR functions never were a good fit for SPIR-V. Unfortunately, there is no good way to do this without a mega-commit. Core NIR and SPIR-V have to be changed at the same time. This also requires changes to anv and radv because nir_inline_functions couldn't handle deref instructions before this change and can't work without them after this change. Acked-by: Rob Clark <[email protected]> Acked-by: Bas Nieuwenhuizen <[email protected]> Acked-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* spirv/cfg: Make the builder fully capable for both walksJason Ekstrand2018-06-221-0/+2
| | | | | | | | | | | | | | We were only initializing vtn_builder::func for the pre-walk where we build the CFG. We were only initializing the nir_builder for the later walk through the instructions even though were were setting b->cursor for the pre-walk. Let's set both both places so that everything is consistent. This useful because we handle OpFunctionParameter in the pre-walk and we're going to need to be able to emit instructions. Acked-by: Rob Clark <[email protected]> Acked-by: Bas Nieuwenhuizen <[email protected]> Acked-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* spirv: Record the type of functionsJason Ekstrand2018-06-221-2/+2
| | | | | | | Acked-by: Rob Clark <[email protected]> Acked-by: Bas Nieuwenhuizen <[email protected]> Acked-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* spirv: Use deref instructions for most variablesJason Ekstrand2018-06-221-4/+4
| | | | | | | | | The only thing still using old-school drefs are function calls. Acked-by: Rob Clark <[email protected]> Acked-by: Bas Nieuwenhuizen <[email protected]> Acked-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* spirv: Get rid of vtn_variable_mode_image/samplerNeil Roberts2018-06-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | vtn_variable_mode_image and _sampler are instead replaced with vtn_variable_mode_uniform which encompasses both of them. In the few places where it was neccessary to distinguish between the two, the GLSL type of the pointer is used instead. The main reason to do this is that on OpenGL it is permitted to put images and samplers into structs and declare a uniform with them. That means that variables can now have a mix of uniform, sampler and image modes so picking a single one of those modes for a variable no longer makes sense. This fixes OpLoad on a sampler within a struct which was previously using the variable mode to determine whether it was a sampler or not. The type of the variable is a struct so it was not being considered to be uniform mode even though the member being loaded should be sampler mode. The previous code appeared to be using var->interface_type as a place to store the type of the variable without the enclosing array for images and samplers. I guess this worked because opaque types can not appear in interfaces so the interface_type is sort of unused. This patch removes the overloading of var->interface_type and any places that needed the type without the array can now just deduce it from var->type. v2: squash in this patch the changes to anv/nir (Timothy) Signed-off-by: Eduardo Lima <[email protected]> Signed-off-by: Neil Roberts <[email protected] Signed-off-by: Alejandro Piñeiro <[email protected]> Reviewed-by: Timothy Arceri <[email protected]>
* spirv: fix visiting inner loops with same break/continue blockSamuel Pitoiset2018-05-151-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | We should stop walking through the CFG when the inner loop's break block ends up as the same block as the outer loop's continue block because we are already going to visit it. This fixes the following assertion which ends up by crashing in RADV or ANV: SPIR-V parsing FAILED: In file ../src/compiler/spirv/vtn_cfg.c:381 block->node.link.next == NULL 0 bytes into the SPIR-V binary This also fixes a crash with a camera shader from SteamVR. v2: make use of vtn_get_branch_type() and add an assertion Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106090 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106504 CC: 18.0 18.1 <[email protected]> Signed-off-by: Samuel Pitoiset <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* spirv: s/uint/unsigned/ to fix MSVC buildBrian Paul2018-03-301-1/+1
| | | | Reviewed-by: Neil Roberts <[email protected]>
* spirv: consider bitsize when handling OpSwitch casesEero Tamminen2017-12-281-3/+11
| | | | | | | | | | | | This reverts commit 7665383a33f9ce9256aa121cbe4d3bd948dff145 and is squashed together with https://patchwork.freedesktop.org/patch/194610/ (spirv: avoid infinite loop / freeze in vtn_cfg_walk_blocks()) which fixes https://bugs.freedesktop.org/show_bug.cgi?id=104359 properly. Fixes: 9702fac68e (spirv: consider bitsize when handling OpSwitch cases) Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104359 Reviewed-by: Lionel Landwerlin <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* Revert "spirv: consider bitsize when handling OpSwitch cases"Mark Janes2017-12-211-11/+3
| | | | | | | | | | This reverts commit 9702fac68e8bd07be8871f7925d7f9fb98da3699, which hangs vulkancts and crucible on all platforms. The patch is being reverted because it disables continuous integration testing. The patch from bug 104359 does not apply to master. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104359
* spirv: consider bitsize when handling OpSwitch casesJuan A. Suarez Romero2017-12-201-3/+11
| | | | | | | When walking over all the cases in a OpSwitch, take in account the bitsize of the literals to avoid getting wrong cases. Reviewed-by: Jason Ekstrand <[email protected]>
* spirv: Handle image and sampler function parametersJason Ekstrand2017-12-121-0/+73
|
* spirv/cfg: Refactor the function parameter loop a bitJason Ekstrand2017-12-121-5/+9
|
* spirv/cfg: Be a bit more precise about function parametersJason Ekstrand2017-12-121-3/+2
| | | | | | Pointers with no storage type are converted to inout variables but SSA values and pointers with a storage type (which turns into a uint or uvec2) are just input variables.
* spirv: Add support for all bit sizes in OpSwitchJason Ekstrand2017-12-111-8/+26
| | | | | Reviewed-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101560
* spirv: Restructure the case loop in OpSwitch handlingJason Ekstrand2017-12-111-3/+11
| | | | | | | | | Instead of calling vtn_add_case for the default case and then looping, add an is_default variable and do everything inside the loop. This will make the next commit easier. Reviewed-by: Samuel Iglesias Gonsálvez <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* spirv: Replace unreachable with vtn_failJason Ekstrand2017-12-041-4/+4
| | | | | Reviewed-by: Tapani Pälli <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* spirv: Replace assert with vtn_assertJason Ekstrand2017-12-041-25/+26
| | | | | Reviewed-by: Tapani Pälli <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* spirv: Only emit functions which are actually usedJason Ekstrand2017-12-021-0/+2
| | | | | | | | | | Instead of emitting absolutely everything, just emit the few functions that are actually referenced in some way by the entrypoint. This should save us quite a bit of time when handed large shader modules containing many entrypoints. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Kristian H. Kristensen <[email protected]>
* spirv: Drop the impl field from vtn_builderJason Ekstrand2017-12-021-1/+1
| | | | | | | We have a nir_builder and it has an impl field. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Kristian H. Kristensen <[email protected]>
* nir/spirv: Allow loop breaks in a switch body.Bas Nieuwenhuizen2017-10-021-1/+1
| | | | | | | | | | | | | | | | | | | | | Per the SPIR-V spec 2.11 Structured Control Flow: "The only blocks in a construct that can branch outside the construct are ... - a break block for the innermost loop it is inside of. ..." With "Break block: A block containing a branch to the Merge Block of a loop header's merge instruction." Note that it puts no restriction on not being in an if or switch within the innermost loop. This passes the loop_break block to the switch body so it can properly detect loop breaks. CC: <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir/spirv: handle if's with same label in both branchesJuan A. Suarez Romero2017-09-121-2/+10
| | | | | | | | | | | | | | When a conditional branch has the same labels in the "if" part and in the "else" part, then we have the same cfg block, and it must be handled once. v2: handle it the same way as OpBranch (Jason). Fixes: dEQP-VK.spirv_assembly.instruction.compute.conditional_branch.same_labels* dEQP-VK.spirv_assembly.instruction.graphics.conditional_branch.same_labels* Reviewed-by: Jason Ekstrand <[email protected]>
* nir/spirv: Add support for SPV_KHR_variable_pointersJason Ekstrand2017-07-181-2/+3
| | | | Reviewed-by: Iago Toral Quiroga <[email protected]>
* nir/spirv: Add a helper for pushing SSA valuesJason Ekstrand2017-07-181-6/+5
| | | | Reviewed-by: Iago Toral Quiroga <[email protected]>
* nir/spirv: Rework function argument setupJason Ekstrand2017-07-051-24/+32
| | | | | | | | Now that we have proper pointer types, we can be more sensible about the way we set up function arguments and deal with the two cases of pointer vs. SSA parameters distinctly. Reviewed-by: Connor Abbott <[email protected]>
* nir/spirv: Use real pointer typesJason Ekstrand2017-07-051-3/+11
| | | | Reviewed-by: Connor Abbott <[email protected]>
* nir/spirv: Stop using glsl_type for function typesJason Ekstrand2017-07-051-21/+9
| | | | | | | We're going to want the full vtn_type available to us anyway at which point glsl_type isn't really buying us anything. Reviewed-by: Connor Abbott <[email protected]>
* nir/spirv: Wrap access chains in a new vtn_pointer data structureJason Ekstrand2017-07-051-8/+6
| | | | | | | | | | | | The vtn_pointer structure provides a bit better abstraction than passing access chains around directly. For one thing, if the pointer just points to a variable, we don't need the access chain at all. Also, pointers know what their dereferenced type is so we can avoid passing the type in a bunch of places. Finally, pointers can, in theory, be extended to the case where you don't actually know what variable is being referenced. Reviewed-by: Connor Abbott <[email protected]>
* nir/spirv: Rename some things from access_chain to pointerJason Ekstrand2017-07-051-5/+4
| | | | | | | We're about to add a vtn_pointer data structure and this will prevent some rename churn in the next commit. Reviewed-by: Connor Abbott <[email protected]>
* nir: Port to u_dynarrayThomas Helland2017-06-071-3/+3
| | | | | Reviewed-by: Marek Olšák <[email protected]> Reviewed-by: Eric Engestrom <[email protected]>
* spirv: Use nir_builder for control flowJason Ekstrand2017-03-011-31/+14
| | | | Reviewed-by: Samuel Iglesias Gonsálvez <[email protected]>
* spirv: Move cursor before calling vtn_ssa_value() in phi 2nd pass.Kenneth Graunke2017-01-091-1/+2
| | | | | | | | | | | | | | vtn_ssa_value() can produce variable loads, and the cursor might be after a return statement, causing nir_builder assert failures about not inserting instructions after a jump. This fixes: dEQP-VK.spirv_assembly.instruction.graphics.barrier.in_if dEQP-VK.spirv_assembly.instruction.graphics.barrier.in_switch Cc: "13.0 12.0" <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir/spirv/cfg: Use a nop intrinsic for tagging the ends of blocksJason Ekstrand2016-10-031-2/+4
| | | | | | | | | | | | | | | | | | | | | Previously, we were saving off the last nir_block in a vtn_block before moving on so that we could find the nir_block again when it came time to handle phi sources. Unfortunately, NIR's control flow modification code is inconsistent when it comes to how it splits blocks so the block pointer we saved off may point to a block somewhere else in the shader by the time we get around to handling phi sources. In order to get around this, we insert a nop instruction and use that as the logical end of our block. Since the control flow manipulation code respects instructions, the nop will keeps its place like any other instruction and we can easily find the end of our block when we need it. This fixes a bug triggered by a couple of vkQuake shaders. Signed-off-by: Jason Ekstrand <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97233 Cc: "12.0" <[email protected]> Tested-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* nir/spirv/cfg: Detect switch_break after loop_break/continueJason Ekstrand2016-10-011-2/+2
| | | | | | | | | | | While the current CFG code is valid in the case where a switch break also happens to be a loop continue, it's a bit suboptimal. Since hardware is capable of handling the continue as a direct jump, it's better to use a continue instruction when we can than to bother with all of the nasty switch break lowering. Signed-off-by: Jason Ekstrand <[email protected]> Cc: "12.0" <[email protected]>
* nir/spirv/cfg: Handle switches whose break block is a loop continueJason Ekstrand2016-10-011-0/+13
| | | | | | | | | | | | | | | | It is possible that the break block of a switch is actually the continue of the loop containing the switch. In this case, we need to identify the break block as a continue and break out of current level of CFG handling. If we don't, the continue portion of the loop will get handled twice, once by following after the break and a second time by the loop handling code handling it explicitly. This fixes 6 of the new Vulkan CTS tests: - dEQP-VK.spirv_assembly.instruction.graphics.opphi.out_of_order* - dEQP-VK.spirv_assembly.instruction.graphics.selection_block_order.out_of_order* Signed-off-by: Jason Ekstrand <[email protected]> Cc: "12.0" <[email protected]>
* spirv: fix warning in release buildGrazvydas Ignotas2016-04-251-1/+1
| | | | | | | | Mark variable MAYBE_UNUSED to avoid unused-but-set-variable warning in release build. Signed-off-by: Grazvydas Ignotas <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
* spirv: Move to compiler/Jason Ekstrand2016-04-141-0/+778
While it does rely on NIR, it's not really part of the NIR core. At the moment, it still builds as part of libnir but that can be changed later if desired.