Repository navigation
asahi/lib,borealis: add and optimize subgroup sample-equivalence fast path for G17P MSAA local-read - #892
Conversation
986f71b to
9ffd7a2
Compare
c6c7ffd to
1c5f1c9
Compare
9ffd7a2 to
4708ad9
Compare
1c5f1c9 to
3e214d5
Compare
4708ad9 to
60974fa
Compare
3e214d5 to
38e672c
Compare
…hic MSAA local-read In hk_g17p_local_read_inline_epilog_part(), monolithic MSAA local-read shaders previously unrolled the full shading body once per sample even when every sample of an interior pixel had full coverage and identical tilebuffer inputs. Add agx_nir_unroll_g17p_samples_equiv() to probe eligible top-level local-read tile loads (up to 8 dwords), subgroup-ballot full coverage plus bitwise sample equivalence, and run the body once with a whole-pixel tile store on the fast path while keeping only sample 0 live into the branches. Add a unit test compiling for both G16G and G17P with zero spills. Signed-off-by: Diljit Singh <hey@djdev.me>
…cross-branch v0 reuse Fix a latent bug in struct g17p_equiv_probe where nir_intrinsic_target() was omitted when matching and emitting load_local_pixel_agx probes. Lift G17P_EQUIV_MAX_DWORDS from 8 to 16 while keeping cross-branch v0 reuse capped at G17P_EQUIV_REUSE_DWORDS (8). When a shader probes more than 8 dwords (such as 4-MRT deferred MSAA local-read lighting passes), drop probe values after the subgroup ballot and reload sample 0 in the fast path (writing all samples via store_samples = 0xFF), narrowing 32-bit R8_UNORM/R8_SNORM probe loads to f16 for the equality check while keeping exact f32 reloads in the shading body. Run nir_opt_dce in the inline epilog algebraic loop and add a 4-MRT 4x MSAA deferred unit test. Signed-off-by: Diljit Singh <hey@djdev.me>
clang rejects passing the table's unsigned base to the int base index of nir_load_local_pixel_agx() in C++ (-Wc++11-narrowing), so libasahi_tests did not build and none of its tests ran, including the MSAA local-read sample-equivalence tests in this file. Declare the table's base as int. Signed-off-by: Diljit Singh <hey@djdev.me>
…e probe
The sample-equivalence fast path of a monolithic MSAA local-read program
first probes every sample of each input attachment and only shades once
when all samples of every lane in the subgroup match. The probe read each
input in the body's own format, so an 8-bit normalized input was decoded
(normflt) for all four samples before the comparison, then narrowed from
f32 to f16 when the probe was wide, and every sample and channel got its
own compare and select.
An AGX3 tile load names a lane width, not a format, and equal bytes decode
to equal values in every format. Probe the raw lanes instead: four or two
8-bit lanes as one 32-bit or 16-bit word at the same byte offset, 16-bit
lanes as 16-bit integers, packed 32-bit formats as their word. OR the
differing bits per bit size and test them once. A probe that is the body's
own read (16- and 32-bit integer lanes) is still reused for sample 0 when
the footprint is small; a raw probe of a decoded format is not, and the
body decodes its own sample-0 reload. Bytes that differ but decode alike
(snorm -128 and -127, NaN payloads) take the per-sample path, which is
always correct.
gpubench render.deferred mode=tile msaa=4 lighting pass (RGBA8, RGBA16F,
RGBA8 and R32F inputs, per-sample shading), compiled for G16G and G17P
under the asahi drm-shim:
probe fast path whole program
before 172 301 802
after 77 204 703
The fast path is what interior pixels run; the 1x lighting program is 125
instructions.
Update the two equivalence unit tests for the raw probes.
Signed-off-by: Diljit Singh <hey@djdev.me>
…n G17P MSAA equiv In agx_nir_unroll_g17p_samples_equiv(), monolithic MSAA local-read shaders (such as 4x MSAA deferred lighting with an RGBA16F normal buffer and three RGBA8 G-buffers) spent ~25 extra instructions on the whole-pixel fast path: 1. Four- and two-channel 16-bit targets at 4-byte-aligned tile offsets were probed as four 16-bit lanes, doubling probe XOR/OR traffic and forcing a separate 16-bit difference accumulator. Probe them as 2x32-bit or 1x32-bit raw R32_UINT words (witnessed on AGX3B/AGX3C at AGX3_TILE_W32 with chan_mask=3/1 at the same tilebuffer partition offset), fold their differences directly into diff32, and unpack sample 0's 32-bit words via nir_unpack_32_2x16_split_x/y (zero-cost agx_subdivide_to) so R16_UINT and R16_FLOAT bodies still reuse sample 0 without reloading the tile. 2. Coverage was read repeatedly from SR39: once for the equivalence check and again in every basic block by agx_nir_lower_g17p_tile_samples(). Because eligible shaders reject discard, demote, zs_emit, and all other sample-mask mutations, hardware coverage is invariant after force_early. Read native W16 SR39 once via nir_load_active_samples_agx(), derive cov_low and the per-sample masks once in block 0, and pass them to the probes, fast path, and slow path. 3. Fold the coverage mismatch (cov_low ^ full_mask) and probe diff bits into a single 32-bit mismatch word and ballot once with nir_ballot(mismatch != 0), removing the 3x icmpsel + invert chain while emitting a single witnessed 32-bit AGX3B icmp_ballot. Signed-off-by: Diljit Singh <hey@djdev.me>
38e672c to
6aeaa4e
Compare
|
Rebased onto
|
satchlj
left a comment
There was a problem hiding this comment.
Verdict at 6aeaa4e17372
APPROVED
Blockers
None
Checked
- Audited
agx_nir_unroll_g17p_samples_equiv()insrc/asahi/lib/agx_nir_lower_msaa.c,agx_nir_unroll_g17p_samples_equivwiring +nir_opt_dcecleanup insrc/asahi/vulkan/hk_cmd_draw.c, and the new tests insrc/asahi/lib/tests/test-msaa.cpp. - Verified
enum ail_isa_formatvalues aliasenum pipe_formatinsrc/asahi/layout/layout.h, sog17p_equiv_set_raw_form()safely probes raw undecoded tile words (R32_UINT/R16_UINT), shares oneload_active_samples_agx(SR39) read, folds coverage mismatch (cov_low ^ full_mask) and inter-sample XOR diffs into one subgroup-uniformnir_ballot(mismatch != 0) == 0guard, unpacks 2x/4x 16-bit probes vianir_unpack_32_2x16_split_{x,y}, and falls back cleanly toagx_nir_unroll_g17p_samples_layout()when ineligible. - Built and ran the non-layout
asahitest suite (261/261 PASS, including all 3 newG17PMSAAEpilog/G17PMsaaEpilogtests) plus Borealis Vulkan compute smoke on Apple M5 Max (G17C B1), Linux 7.3 withMESA_SHADER_CACHE_DISABLE=1and0GPU faults indmesg. - Untested scope: Live G17P/G16G hardware execution of the new
agx_nir_unroll_g17p_samples_equivfast path (verified via G17P/G16G compiler and NIR lowering unit tests; live hardware check ran on Apple M5 Max (G17C B1)), andasahi_layout_tests(pre-existing GCC C++20 designator-order error insrc/asahi/layout/tests/test-layout.cpp:374).
Evidence
meson test --suite asahi(non-layout):261/261 PASS(0 FAIL)libasahi_tests --gtest_filter="*Equiv*":3/3 PASSG17PMSAAEpilog.MonolithicLocalReadSampleEquivFastPathCompilesG17PMsaaEpilog.MonolithicLocalReadDeferred4MRTMsaa4EquivCompilesG17PMsaaEpilog.MonolithicLocalReadDeferred4MRTMsaa4Half16EquivCompiles
- Live Borealis Vulkan CTS on Apple M5 Max (
G17C B1), Linux 7.3 (MESA_SHADER_CACHE_DISABLE=1,0GPU faults indmesg):dEQP-VK.compute.pipeline.basic.*:80/81 PASS,0 FAIL,1 NotSupported
|
6aeaa4e J773g M4 mini (Apple M4, G16G B0) PASS (413 Pass / 165 NotSupported / 0 Fail across Vulkan dynamic-rendering local-read & MSAA sample-shading CTS; 6/6 gpubench render.deferred CRCs exact; 184/184 asahi unit tests; 0 GPU faults/recoveries/dmesg). Exact-head G16G verification details
|
|
Merged into |
Summary
Adds and optimizes the subgroup sample-equivalence fast path for monolithic MSAA local-read shaders on G17P/G16G:
v0reuse and fixes the 4-MRT unit test narrowing initializer.SR39coverage across probes, and folds the coverage mismatch into the subgroup ballot.Verification
git diff --check: clean across all 5 commits.G16G B0,26B123) silicon:gpubench:vk-fullrender.deferred tile m4 d=2+10.4%;vk-full202/202 PASS (1.094×vs Metal 4; Wave-21.001×); full suite 440/440 PASS (0faults,0bad CRCs).dEQP-VK.renderpasses.dynamic_rendering.*.local_read.*+ MSAA 148/148 PASS (4/4 feedback_loop_msaa).