Commit graph

181332 commits

Author SHA1 Message Date
Faith Ekstrand
3e8344a4c8 nak: Remap GLSL_SAMPLER_DIM_SUBPASS and SUBPASS_MS to 2D and MS
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
80230731ec nak: IMAD also has a destination predicate
Also use set_pred_dst(.., Dst::None) for IMAD64

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
ab7a4b531d nak: Disable lower_image_size_to_txs for NAK
We don't need it for NAK and it actually screws up cubes.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
86c7bcc9e3 nak/legalize: Fix too many IADD3 source modifiers
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
0222107699 nak: Move all the IADD3 insanity to a new OpIAdd3X opcode
Because of its crazy behavior around overflow, we don't want the full
IADD3 opcode to support any sort of source modifier propagation.  This
makes us a new OpIAdd3X opcode which contains all the crazy and lets
IAdd3 remain the usual 32-bit integer thing everyone knows and loves.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
c5b9d42ac2 nak: Add an alloc_vec() to SSAValueAllocator
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
52acb12f75 nak: Document spilling and RA
This isn't full documentation but it at least sprinkles paper citations
all over as well as descriptions of where we diverge from said papers.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
a0bf406057 nak/spill: Tweak the construction of S sets
Instead of just taking live-in \ W, consider anything previously spilled
to be spilled.  This lets us avoid a bunch of redundant spills because
we now allow spills to persist across blocks even if the value is in W.
In the loop header case, however, we still need to add in live-in \ W or
else we can end up in cases where a value is neither in W nor S.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
ea0ae395a9 nak/ra: Improve coalescing
We now delete OpParCopy src/dst pairs when they get coalesced.  We
can also coalesce OpCopy which is potentially useful given they are
generated by spilling.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
46d489fa4d nak: Implement shader clock
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
84d1765690 nak: Add a debug flag to test spilling
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
07b9465b5d nak: Spill registers before RA
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
aa93578915 nak: Use the correct number of GPRs on Turing+
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
bcad2add47 nak: Add a spilling pass
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
a502a994e8 nak: Add more NextUseLiveness helpers
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
72a4721412 nak: Add a RegFileSet filter to NextUseLiveness::for_function()
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
002ee9e40e nak: Expose LiveSet for incremental liveness tracking
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:12 +00:00
Faith Ekstrand
8c04737a6a nak/ra: Don't free killed for OpPhiSrcs
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
efee3264b2 nak/ra: Handle parallel copies as a special case
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
4d5bf265b0 nak/ra: Drop the pointless AssignRegs struct
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
57a7932bb5 nak: Union find
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
4a08105922 nak: Add an SSA repair pass
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
214b7e4b88 nak: Add a to-CSSA pass
Conventional SSA (also called CSSA) requires phi nodes be isolated by
parallel copies such that there is no interference between SSA values.
This is required for many out-of-SSA algorithms and, in our case, a
prerequisite for spilling.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
d574d29102 nak: Add helpers to BasicBlock to get phis
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
2f9565e725 nak: Add a dominance check to CFG
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
bef6c1095e nak: Add interference helpers
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
0fd3510166 nak: Restructure liveness construction
Drop the for_block() stuff and instead have the parent add defs and uses
one at a time.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
2c3eb239f8 nak: Allow DCE on functions
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
002022a0b1 nak: Handle RegFile::Mem in parallel copy lowering
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
4f05308ad9 nak: Add a Mem register file
For spilling, we want to be able to treat TLS as if it were a register
file.  It unifies and makes everything easier.  Also add support to
OpCopy to for copying between GPR and Mem.  We cannot, however copy
directly from Mem to Mem.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
fe7ac83a94 nak: Use more OpCopy
Instead of using OpMov or OpParCopy, use OpCopy directly.  This reserves
OpParCopy for RA type things and OpMOv for actual codegen.  We can also
drop OpMov from copy propagation now.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
Faith Ekstrand
8185f3064e nak: Use OpCopy in legalize
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:11 +00:00
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