Commit graph

180516 commits

Author SHA1 Message Date
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
Daniel Almeida
831d1ee2d6 nak: Do not allocate vectors needlessly in optimization passes
All passes allocate a Vec per Instr during map(). This is wasteful,
because most instances of map()  produce a single instruction (by
mapping one instruction to another instruction) or no instructions at
all.

In such cases, they return an empty Vec, or a Vec with a single entry.

Rework the signatures so that a Vec is only when mapping one instruction
into many.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Daniel Almeida
5014b4697d nak: Heap-allocate Instrs
Heap-allocate Instrs to avoid copying them around whenever they are
mutated by a pass. This lowers the amount of copies in detriment of
cache-locality.

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
fa0891d37c nak: Implement nir_op_b2b1 and nir_op_b2b32
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
3bf0882ea8 nak: Implement indirect UBO loads
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
0ff7fbf093 nak: Rework cbufs a bit
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
86684fa9aa nak: Legalize everything
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
9fcc0eaa8a nak: Fix multisampled textureing
Needed to handle txf_ms a few places and force LOD_MODE_ZERO

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
cc88a1c78e nak: Add a Pred struct move the enum to PredRef
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
38c9d6dfbb nak: Add accum predicates to Op[FI]Setp
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
c6edf43f70 nak: Delete unused imports and dead code
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
d48bea6638 nak: Fold fsat into FAdd/FFma/FMul
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
4c3a5b16e9 nak: Rework source modifiers instructions a bit
Instead of I/D/FMov instructions, just use [DF]Add instead. For ineg, we
add a new INeg instruction which we can lower to IADD3 later.  The
reason for this is that IAdd3 is complicated and makes detecting an ineg
rather annoying.  Also, if we ever bring NAK up on older hardware, not
all hardware has IAdd3 and INeg will be lowerable everywhere.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
8ba1429216 nak: DCE things with constant false predicates
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
818ec3242b nak: Optimize OpLop3 and OpPLop3
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
59f6d657f3 nak: Fix the 2nd predicate on LOP3
I put it in the wrong spot.  Also, it's a source so we should use
set_pred_src() for it.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
4367e0786b nak: Implement image atomics
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
82e5b0dd93 nak: Implement global/shared_atomic_comp_swap
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
d359c64b2a nak: Implement nir_intrinsic_shared_atomic_*
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
d1c56b12b9 nak: Implement nir_intrinsic_global_atomic_*
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
18a11aa449 nak: Rework copy-prop to use soruce type decorations
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
9bc2bdd78f nak: Add a Src::supports_src_type() helper
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
42d31b4bfd nak: Rework source modifiers a bit
They now carry some type informaiton so FNeg and INeg are different
modifiers.  Since only INeg exists in hardware, we don't need IAbs or
INegAbs.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
a2390fdbc1 nak: Only divide FS inputs by .w for smooth interpolation
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
7398a262da nak: Decorate sources with types
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
4def64545a nak: Add a mechanism for decorating sources with types
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
3207f29a09 nak: Integers don't have abs() source modifiers
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
2a2103d73b nak: Implement load/store_shared
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
73976c3f31 nvk: Plumb num_barriers through from NAK
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
4c2ce288f9 nak: Implement barriers
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
53a372ec3d nak: Add F2F and implement fquantize16
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
dc3b2c7d10 nak: sin() and cos() require we divide by 2pi
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Faith Ekstrand
a6e1167a83 nak: Don't allow r255 in texture or surface ops
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Daniel Almeida
b70d998180 nak: compiler: replace Instr::new(..) with OpFoo {}.into()
As Instr now implements From<T: Into<Op>>, replace
Instr::new(Op::Foo(OpFoo {})) with OpFoo {}.into() to improve
readability.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
2023-11-14 00:48:10 +00:00
Daniel Almeida
ab9cf27c02 nak: compiler: add From<T:Into<Op>> for Instr
Adding this From implementation makes it possible to clean up
the code in the next commit.

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