Commit graph

180500 commits

Author SHA1 Message Date
Faith Ekstrand
fc35dd6aba nak: Use the builder for the legalize pass
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
4c798afb25 nak: Add a new OpCopy instruction for parallel copy lowering
This is different from OpMov because OpMov is an actual hardware
instruction and we want OpCopy to be able to do magic.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
b78ccebf4b nak: Rework map_instrs()
Consume a FnMut so that we can pass in mutable references to things.  If
we don't want mutable references, we can also pass a whole closure.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
72f4cd3300 nak: Use u32 for register indices
This increases the size of RegRef to 32 bits but that's fine given that
it's usually in a union with SSARef which is 128 bits.  The real
advantage is that it allows us to start treating memory as a register
type which will come in really useful for spilling.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
5c3e7bf0b7 nak: Refactor nak_assign_regs a bit
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
e6b0c3e220 nak: Add a phi allocator
We need to be able to add phis later.  If we want phi numbers to be
unique, we need to be able to allocate them.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
741f7067f1 nak: Add loop detection to the CFG
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
a560356b71 nak: Base liveness on CFG indices
This gets rid of most of the per-block hash maps and replaces them all
with vectors.  This is both simpler and should be quite a bit more
efficient (though block lookup isn't common).

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
ea9390cd21 nak: Store the blocks in the CFG
This renames CFG to CFG2 and moves to storing the blocks in a CFG
instead of a Vec.  This should let us make a bunch of other data
structures drop to a vec instead of a hash map now that we can rely on
the CFG instead of BasicBlock::id.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
7ce3dfa43b nak: Add a more awesome CFG data structure
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
c1b62f1d15 nak: Emit if branches in the predecessor block
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
0143f4566f nak/nir: Add more helpers
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
756d0c0ba3 nak: Add a new VecPair type
This is a pair of vectors but it acts a bit like a vector of a pair.
Everything is inserted, removed, iterated, etc. in tandem to ensure that
we never mismatch between the two vectors.  However, because they're two
separate vectors, we ensure that it can be used to store Src and Dst and
keep everything contiguous.

Of particular interest is the new retain() method which is equivalent to
Vec::retain() which allows filtering a VecPair.  This tricky operation
is performed three different times by DCE and will be needed in spilling
as well.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
67c13aea9e nak: Add more SSA iterator options
This should make things like liveness a bit more reliable as it ensures
we won't accidentally miss anything.  It also makes them a bit simpler
to iterate.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
dc26c826b9 nak: Add a RegFileSet struct
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
2fd0a2e207 nak: Accurately set num_gprs
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
e25bbc9b7b nak: Add mum_gprs and tls_size to Shader
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
8e9f5416bb nak: Bring back bitset-based liveness
This one is much faster to compute because we can use bitops for the
fixed-point data-flow algorithm rather than the clumsy walking of hash
sets. The faster version is sufficient for RA and checking for register
pressure. We only need to fall back to the slower version for spilling.
Thanks to traits, we can get some of the same behavior with both.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
26748d6fbf nak: Make calc_max_live a function of the Liveness trait
If we rework things a bit to compute live-out hash sets internally to
the pass we can make it work with just the information provided by the
trait.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
80d58b3521 nak: Handle dead destinations in RA
It's possible for a destination component to be killed immediately if
it's never used.  To handle this, we need to track killed destinations
as well as killed sources.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
865d6c303f nak: Require Rust 1.70.0
This is when std::sync::OnceLock gets stabilized which we require for
parsing debug options.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
71c5bbc5a8 nak: Break guts of liveness into traits
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
f1cb99d06b nak: Separate the CFG from liveness
One could argue that this should go in the function and not be an
on-demand analysis pass but we can do that later.  For now, we just
break it out into a separate data structure.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
497046412e nak: Allocate the minimum number of GPRs.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
d9c606fb08 nak/ra: Pass a PerRegFile num_regs into the allocator
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
7b3d62e51a nak: Print to stderr
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Dave Airlie
2a7df0a03e nak: fix backtrace crash running computeheadless
Doesn't fix the example, but stops the crash.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
d7d330754b nak: add support for nir_op_unpack_half_2x16_split_{x|y}
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
59c05e16e4 nak: add support for packhalf2x16_split
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
1f10cdbbbe nak: add support for findmsb,findlsb
These all map into OpBFind, which is sourced from PTX and NV50.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
e887c4d07a nak: add support for nir_op_bitfield_reverse
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
d27e271ba5 nak: Add support for nir_op_bitcount
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
d133603c7d nak: add support for nir_op_isign
Fixes dEQP-VK.glsl.builtin.function.common.sign.*

Notice that ISel support appears not to be wired up in the old compiler, so
ISetP + Sel was chosen.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
22b4d1c559 nak: change ishl data type to I32
This matches NV50 as getDType always returns nv50_ir::TYPE_S32 for
nir_op_ishl

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
30824fa6a5 nak: more lowerings
Add more lowerings based on nv50.

Fixes
dEQP-VK.glsl.builtin.precision.ldexp.highp.scalar

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
e03cc1f542 nak: Add some documentation for SSA values
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Daniel Almeida
11ca78f923 nak: run nir_lower_frexp and nir_opt_algebraic_late
These two are needed to get dEQP-VK.glsl.builtin.precision.frexp.* to pass.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Daniel Almeida
394bd770bc nak: add support for floor, ceil and trunc
These instructions are not supported and this shows when running the CTS.

Add support for them.

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
4dd277e233 nak: Rework RA a bit
Instead of tracking pinned things in the register allocator, we split
the register allocator into RegAllocator and PinnedRegAllocator.  The
RegAllocator struct only allows for very simple single-SSA allocations
and frees. It tracks locations of everything, what's used, etc. but
otherwise knows nothing about pinning or vectors.

The new PinnedRegAllocator struct wraps a RegAllocator by taking a
mutable reference to it.  It provides support for pinning and all the
vector stuff.  To destroy a PinnedRegAllocator, finish() is called which
re-places any evicted SSA values and populates an OpParCopy with any
needed copies.  Because PinnedRegAllocator owns a mutable reference to
the RegAllocator, it's impossible to mix uses of PinnedRegAllocator and
RegAllocator.  This ensures that, for as long as the pinned version
exists, nothing can be allocated which migh escape the pinning.

This fixes a bunch of corner cases when register pressure gets tight.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
c9a6073754 nak: Use pcopy.push() in RA
This version guarantees that the source and destination vector stay in
sync.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
c0e6d80063 nak: Use num_regs instead of max_reg in RA
Since the top value is always the default register, we don't need to
worry about overflowing a u8.  What we do need to worry about is
register files with zero registers which is a thing pre-Turing for
uniform register files.  Use num instead of max so we don't end up
subtracting 1 from 0.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
19806cc9e4 nak: Initialize RA with only live registers
While coping the entire RA struct from the predecessor is probably
faster, it may contain values which are not live in the current block.
We could purge those but the iteration gets tricky with Rust.  It's far
clearer and more rust-friendly to deal with it as an initialization
problem.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
ec47843cca nak: Record register pressure in liveness
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
7c98dd8bfd nak: Add a PerRegFile helper struct
Sometimes it's useful to have something that's per-register-file like we
do for register allocation.  Since this is generally useful, add a
struct for it.  In future, it might be neat to pull in the enum_map
crate which basically does this generically.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
b661279e6e nak: Rework liveness to add next-use information
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
f67fecf196 nak: Compute liveness in reverse block order
If we walk the blocks forwards, we end up having a minimum O(n^2)
algorithm because everything has to propagate bottom to top.  Looping
over the blocks bacwards ensures that all the liveness information is
propgated in the first pass in the absence of back edges.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
82f0c6cf77 nak: Use the builder in some lowering passes
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
2d69a2c1d7 nak: Add a builder
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
063c9f41fa nak: Work in terms of bits for type sizes
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
ced6b44ba6 nak: Follow memcpy semantics with OpParCopy
Destination first followed by source.  Otherwise, we'll screw ourselves
up endlessly.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00