nir: Use a single list for all shader variables Instead of having separate lists of variables, roughly sorted by mode, use a single list for all shader-level NIR variables. This makes a few list walks a bit longer here and there but list walks aren't a very common thing in NIR at all. On the other hand, it makes a lot of things like validation, printing, etc. way simpler. Also, there are a number of cases where we move variables from inputs/outputs to globals and this makes it way easier because we no longer have to move them between lists. We only have to deal with that if moving them from the shader to a nir_function_impl. Reviewed-by: Rob Clark <robdclark@chromium.org> Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5966>
nir: Add nir_foreach_shader_in/out_variable helpers Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5966>
nir/lower_clip: make the pass compatible with Vulkan semantics Vulkan allows fragment shaders to read gl_ClipDistance[], in which case the SPIR-V compiler inserts a single compact array variable for VARYING_SLOW_CLIP_DIST0 and the lowering should not try to inject its own variables, but instead work in terms of the existing one. Vulkan drivers are expected to call this with use_clipdist_array set to true to be consistent with this setup. Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6022>
nir/lower_clip: Fix picking of unused driver locations. This fixes things when the last input/output is a struct or matrix. Reviewed-by: Connor Abbott <cwabbott0@gmail.com> Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4670>
nir: fix 5 warnings Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3970>
nir/lower_clip: Fix incorrect driver loc for clipdist outputs Somehow adjusting maxloc based on existing outputs got lost, resulting in the clipdist varying clobbering the position varying. Causing a shader that had no position output in freedreno/ir3, which triggers GPU hangs in neverball. Fixes: d0f746b6458 ("nir: Save nir_variable pointers in nir_lower_clip_vs rather than locs.") Signed-off-by: Rob Clark <robdclark@chromium.org> Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
nir: patch up deref-vars when lowering clip-planes Otherwise, we fail validation and potentially generate invalid code. Let's fix up the mode of the accesses to the variable. Signed-off-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
nir: support feeding state to nir_lower_clip_[vg]s Reviewed-by: Marek Olšák <marek.olsak@amd.com>
nir: support lowering clipdist to arrays This allows us to make sure clipdist is emitted as a scalar array rather than two vec4s. This matches SPIR-V semantics, and will be useful for Zink. Reviewed-by: Marek Olšák <marek.olsak@amd.com>
nir/lower_clip: add support for geometry shaders This will be used to enabled compat profile support for geometry shaders. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
nir/lower_clip: add lower_clip_outputs() helper This will be reused in the following patch to add support for clip vertex lowering in geometry shaders. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
nir/lower_clip: add create_clipdist_vars() helper Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
nir/lower_clip: add a find_clipvertex_and_position_outputs() helper This will allow code sharing in a following patch that adds support for lowering in geometry shaders. It also allows us to exit early if there is no lowering to do which allows a small code tidy up. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
nir: rename nir_var_private to nir_var_shader_temp Signed-off-by: Karol Herbst <kherbst@redhat.com> Acked-by: Jason Ekstrand <jason@jlekstrand.net> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
nir: rename global/local to private/function memory 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 <kherbst@redhat.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
nir: Make nir_lower_clip_vs optionally work with variables. The way nir_lower_clip_vs() works with store_output intrinsics makes a ton of assumptions about the driver_location field. In i965 and iris, I'd rather do this lowering early and work with variables. v3d may want to switch to that as well, and ir3 could too, but I'm not sure exactly what would need updating. For now, handle both methods. Reviewed-by: Eric Anholt <eric@anholt.net>
nir: Save nir_variable pointers in nir_lower_clip_vs rather than locs. I'll want the variables in the next patch. Reviewed-by: Eric Anholt <eric@anholt.net>
nir: Inline lower_clip_vs() into nir_lower_clip_vs(). It's now called exactly once, and there's not really any distinction. Reviewed-by: Eric Anholt <eric@anholt.net>
nir: Use nir_shader_get_entrypoint in nir_lower_clip_vs(). Reviewed-by: Eric Anholt <eric@anholt.net>
nir: replace nir_load_system_value calls with appropiate builder functions this helps reduce the overall code changes when a bit_size parameter is added to nir_load_system_value Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Karol Herbst <kherbst@redhat.com>