feat(recompiler): FLAT addresses in the shared and private apertures reach LDS and scratch #1190
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1190"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T17:03:45Z.
What
A compute FLAT access whose address has the console's shared aperture in its high dword (0x8000xxxx) reads or writes the workgroup's LDS at its low dword. One in the private aperture (0x7000xxxx) reaches the lane's scratch. Other addresses stay guest memory through BDA, as before. This holds for every FLAT access kind in compute:
GTA V's ray traversal keeps its stack in LDS and spills it to scratch through such addresses. Treated as guest memory, the pushes were lost and the traversal never ended (device lost).
tests/execution/FlatApertures.cppruns a table of 121 rows: dword loads and stores, sub-dword stores (aligned and crossing a dword), 32- and 64-bit atomics on shared, private and guest addresses, a wave whose lanes mix LDS, scratch and guest addresses, and wave64.Source of the aperture bases: the values GTA V's traversal addresses use (shared 0x8000, private 0x7000 in the high 16 bits). No public source confirms them for gfx10 or the console; they, the unaligned aperture semantics and the out-of-range LDS/scratch behaviour are listed as inferred in TechnicalDebt.md, with the scalar operands 235-238 (
src_shared_base,src_private_base, ...) that stay unmodelled.Tested
Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB, MinGW-w64 GCC 15.2.0.
gta-v/testingbranch (Performance mode, the prologue); not re-run with the routed atomics and byte-wise accesses yet.agc_driver_flat_aperturespasses (83 of its 121 rows fail on the previous version), and the FLAT, global, LDS, BDA, atomic, scratch and recompiler tests pass. Fullctest: all pass except the relinker's Python tests (my local Python does not find their helper modules) andguest_gameupdate.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T18:30:10Z.
Yōtei's ray-traversal kernels (see my note on #1182) are a real-world case for this one: they push the traversal stack with
flat_store_dwordto generic addresses whose high dword is 0x80000000 (LDS) or 0x70000000 (scratch), chosen per lane, and pop it withds_read/scratch_load.Replaying the seven programs on #1182 + #1190, the two big kernels recompile (their next stop is LDS over the device limit), and the results match what I got with my own version. Two gaps showed up:
unsupported scalar source operand code 235. It readssrc_shared_base/src_private_base(235/237) as 64-bit values to build its aperture pointers, so those two need decoding too.BDA access failed: address=0x8000000000000401, while the dword stores land in LDS as expected. Byte and short loads/stores into both apertures would need the same routing as the dword ones.Tested on an RTX 3080 (Windows 11) and on lavapipe. I can share the execution test, which covers per-lane LDS/scratch/global mixes, x2/x4 and byte/short accesses, if you'd like it for this PR.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T09:30:28Z.
Review: CHANGES_REQUESTED
Thanks, the approach (routing on the high dword in the compute FLAT path) looks reasonable. Things to fix before this can land:
a2fb99fb7(the #1182 commit), which is already onmainas20e055c24; it now conflicts intests/Graphics.cpp. Please rebase so only the aperture commit remains (the serialization version should then be the next free version after what has landed).SpirvMemoryInstructions.cpp:852, "still stored through BDA") and flat atomics (EmitBdaAtomicpath, ~line 1224) whose address is in the shared/private aperture go to BDA with a bogus address and silently do the wrong thing. Either route them too or throw when the aperture can't be excluded; a plausible wrong result is worse than the previous failure.FlatApertures.cppcovers only dword load/store. Please add rows for the paths above (route or throw), a lane-varying case mixing LDS/scratch/global addresses in one wave, and a wave64 run.src_shared_base/src_private_base, operand 235, reported by @Celegans12 on #1182) under "Unknown function info"/the matching section.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-08T16:08:28Z.
Thanks. Rebased onto main, so only the aperture commit remains (the #1182 commit is gone). This push:
agc_driver_global_atomics_float(a 64-bit float max on a global address), so they route too.FlatApertures.cppis now a 121-row table: dword, sub-dword (aligned and crossing) and unaligned accesses, 32- and 64-bit atomics on shared, private and guest addresses, a wave mixing LDS, scratch and guest addresses, and wave64. On the previous version 83 rows fail; guest rows pass on both. Byte readbacks also caught an address truncation the old byte path had.src_shared_base,src_private_base, ...) stay unmodelled and throw at decode; listed together with the inferred unaligned and out-of-range aperture behaviour, a few lines up from the end of the section.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T18:56:02Z.
I ran Ghost of Yōtei (PPSA26344 v1.008) for an hour with this PR at bb70ded, the version before your last push, and the two big ray-traversal kernels run now. 0x8000173b00 and 0x800014e300 push their traversal stacks through your aperture path and ran on queue 0x51, about 47 dispatches and 2.0 s a frame, with no device fault, no BDA fault and no GPU hang. The SCRATCH_EN skips from the run before (13.9 a frame, now covered by #1182) are gone too.
The LDS half is now #1776, which doesn't depend on this one. At bb70ded your shared-aperture arm went through the same LDS element pointer, so it followed the device-memory LDS without changes; I haven't checked your new byte-wise and atomic routes against it yet. The cost has moved to pipeline creation: each data variant of these kernels is about 1.06M SPIR-V words and took 215-243 s to create, which has nothing to do with your change.
The three small kernels (0x8000356b00 and the two that stop at a runtime formatted V#) didn't come up in this run, so I couldn't try the operand 235-238 handling in the game. I'll put your current head f36e64cc into the next run and report back.
Details
Windows 11, RTX 3080 Laptop, our integration tree on main
4b005b22(which has #1182) + this PR at bb70ded + #1776 (as 1a4c9b07, before its rebase onto #639) + our other open PRs; a 1,200 s capture pass, then 3,600 s.All nine watchdog "stuck" lines in the run were pipeline compiles and cleared; 0x8000117800 and 0x8000167500 did not run.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:33:37Z.
@Celegans12 thanks for the hour-long run. Good to see the traversal stacks of both kernels going through the apertures on Yōtei too.
Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T08:37:34Z.
@MichonGoddijn231849 the new
agc_driver_flat_aperturesfails on current main (CachyOS Linux; RTX 4070 Ti, Radeon 610M RADV and lavapipe 26.2.4 alike), tested at f36e64cc rebased ona8b032b2:Since #639 the buffer path follows OOB_SELECT in V# dword3. The test's
0x01016facis mode 0 (structured), and with stride 0 every table load and output store is out of bounds, so the lane addresses read as 0 and the first flat store faults at BDA address 0.fa2df2e2moved the memory and wave execution tests to0x31016fac; the same one-line change inBufferDescriptor(FlatApertures.cpp:99) makes it pass on all three drivers. The routing change itself needed nothing. CI did not see this because it ran on the PR's old base, before #639.It is still too slow for CI: 21 s on NVIDIA, 14 s on RADV, about 300 s on lavapipe (the CI run timed out at 120 s). Nearly all of it is lavapipe compiling each 64-bit atomic kernel once, 5-38 s each (16 kernels, about 210-250 s in total). The shared/private/guest rows reuse the kernel and cost about 0.2 s each. Fewer distinct 64-bit ops, or splitting the file (each
tests/execution/*.cppis its own ctest test), should get it under the 30 s in CONTRIBUTING.md.Imported from boykopovar/AnyPS5. Originally posted by danzaio on 2026-10-09T21:59:26Z.
Ran the new test on real hardware since CI Windows skips it: RTX 4050 laptop, Windows, MinGW 15.2 build of f36e64cc, ANYPS5_GPU=4050.
First run after the build timed out at 60s (same picture as the Linux job: alive past device setup, then silence after the write-watch line, no result rows). Every run after that passes in about a second, five in a row, plus one 14s pass with APS5_TRACE_DISPATCH_IO on.
So I could not reproduce a logic hang. This looks like cold Vulkan pipeline compilation on the first run rather than an infinite loop in the routing: a fresh CI runner pays the same cost, and llvmpipe pays it slower, which fits the 120s Linux timeout. If it keeps biting CI, a longer timeout for this test or a shared pipeline cache would tell the two apart for good.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T22:10:44Z.
@danzaio thanks, that fits a cold pipeline compile. The Linux job's 120 s timeout on lavapipe is probably the same thing.
@CouchRiv your report is a different failure, and I had missed it:
flat_store8 shared offset 0 wave32reads0xdeadbeefback. That is a wrong value, not a timeout, and on three drivers. So the 8-bit FLAT store into the shared aperture does not reach LDS at all on those drivers. I will reproduce it on lavapipe tomorrow and fix it. While doing that I'll also do the rebase @adriadam10 asked for: only the aperture commit, on the next free serialization version.Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-10T04:27:09Z.
Fourth driver for @CouchRiv's failure. Head
f36e64ccmerged onto currentmainc72d5ce1, Windows 11 10.0.26200, RTX 4090 (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 r7, Release:It fails in 0.25 s, so this is not the cold pipeline compile @danzaio saw; the BDA fault at address 0 fits the OOB_SELECT reading of the V# (
0x01016fac) after #639. The rest of the suite in that build is 573 of 573 (3 environment skips). I can rerun the test with0x31016facinBufferDescriptoron this GPU once the next push is up.Tested with AI assistance (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by danzaio on 2026-10-10T04:38:43Z.
Verified the fix commit on real hardware: RTX 4050 laptop, Windows, MinGW 15.2 build of f36e64ccf, ANYPS5_GPU=4050. agc_driver_flat_apertures passes in about 1.5s, all 121 rows including the shared/private aperture routing and the sub-dword store cases from the report. Nothing else in the run looks off. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T08:16:34Z.
Rebased onto
main(af1a8edf), head5122e721. @frankea was right about the cause. Thanks, and thanks @CouchRiv and @danzaio for the runs.0x01016fac, OOB_SELECT 0. After #639 that made its output buffer read as out of range, which produced the BDA fault at address 0 and the0xdeadbeefread-back. It is now0x31016fac(OOB_SELECT 3, raw), as in main's other execution tests.flat_atomic64_swap sharedreturned0xdeadbeef. Main'sStoreAddressU32x2..x4(b95842597, one BDA lookup per wide store) bypassed the aperture routing, so theflat_store_dwordx2that sets up LDS went to BDA at0x8000000000000000. Wide FLAT stores now store each component through the aperture, like the 32-bit store and the wide load. Outside the apertures they keep the single BDA lookup.Tested on Windows, RTX 5080:
agc_driver_flat_aperturespasses all rows.agc_driver_flat_*,agc_driver_global_*,agc_driver_bda_*andagc_driver_masked_global_storetests andagc_shader_memorypass.check_conventions.pypasses.@adriadam10 the branch holds only the two aperture commits now, and it no longer changes the request serialization version.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T09:06:07Z.
Review: CHANGES_REQUESTED
Thanks for the fixes and to everyone who ran it. I measured the routed semantics on real RDNA2 (gfx1035, HSA, LDS of 4096 bytes, Linux's unaligned mode) with flat accesses into the shared aperture. Unaligned in-range loads and stores (byte-wise, little-endian),
lo >= 0x10000reading 0 with no wrap,flat_atomic_add/_x2and an out-of-range atomic returning 0 all match the PR. Two things don't:The aperture is a 4 GB window, not a 16-bit tag (
SpirvMemoryInstructions.cpp:355-356). On gfx1035,src_shared_base/src_shared_limitread0x00010000_00000000/0x00010000_ffffffff, andsrc_private_*read0x00020000_00000000/0x00020000_ffffffff. That is the gfx9+ layout in Linux'skfd_flat_memory.c(MAKE_LDS_APP_BASE_V9() = 0x1 << 48,MAKE_LDS_APP_LIMIT(base) = base | 0xFFFFFFFF): the SH_MEM_BASES field becomes bits 63:48 and the window covers 4 GB from there.SplitApertureonly compares the top 16 bits, so a high dword of0x8000_0001reaches LDS here while the hardware sends it to global memory. Comparing the whole high dword with0x80000000/0x70000000fixes it. That also makes the TechnicalDebt line at:330inaccurate: there is a public source for the layout, and only the PS5's base values are inferred.An access that runs past the end of LDS is dropped as a whole, not byte by byte (
:397-405,:442-447). If any byte is out of range, the hardware reads 0 or writes nothing for that dword access. Multi-dword accesses are handled per dword. The rows that differ (LDS pre-filled so byteaholdsa & 0xff, store data0xaabbccdd,0x11223344):flat_load_dword0xffd0x000000000x00fffefdflat_load_dword0xfff0x000000000x000000ffflat_load_ushort0xfff0x00000x00ffflat_store_dword0xffe0xffcunchanged0xfffefdfc0xccddfdfcflat_store_short0xfff0xffcunchanged0xfffefdfc0xddfefdfcflat_store_dwordx20xffa0xffc=0xfffeaabb0x3344aabbChecking that the element's last byte is in range before the byte loop (and skipping the whole element otherwise) would match these. Rows for them in
FlatApertures.cppwould pin the behaviour.I couldn't measure scratch reached through flat addresses or the console's alignment mode (SH_MEM_CONFIG). The TechnicalDebt line already lists both as inferred, which is fine.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-10T09:59:06Z.
Thanks @adriadam10, both measurements are now in
4ab7fb7a.SplitAperturecompares the whole high dword with0x80000000(shared) and0x70000000(private), so0x8000_0001goes to global memory. The TechnicalDebt line now nameskfd_flat_memory.cand your gfx1035 values as the layout's source, and keeps only the PS5's two base values as inferred.dwordx2at0xffawrites its first dword and drops its second, as in your table.New rows in
FlatApertures.cpp, with the test's 1 KiB LDS:With the old byte-wise behaviour the dword row fails ("lane 31 read 0x00b5392f back from an access past the end of LDS"); with the change it passes. The other 21 flat/global/BDA tests,
agc_shader_memoryandcheck_conventions.pypass on Windows (RTX 5080).Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T19:12:18Z.
4ab7fb7amerges cleanly onto currentmain(4a747c48) butagc_driver_flat_apertures_testsdoes not build there:tests/execution/FlatApertures.cpp:81callsGuestAllocations::Mutation().Add(block, GuestBytes, true, true), and sincec11a9cb5Addtakes a fifthgpuargument (no matching function for call to ... Add(uint8_t*&, const std::size_t&, bool, bool)). #374 and #1619 made the same one-argument adaptation.With that call changed to
Add(block, GuestBytes, true, true, true)locally, on llvmpipe:agc_driver_flat_aperturesand the other 21 flat/global/BDA tests pass (flat_aperturestakes about 90 s on llvmpipe), and the new rows pin4ab7fb7a: withSpirvMemoryInstructions.cppat5122e721, the test fails with "flat_store32 shared offset 773 wave32: lane 31 read 0x00b5392f back from an access past the end of LDS, expected 0 (the store is dropped whole)".SplitAperturecompares the whole high dword against0x80000000/0x70000000. The hardware side rests on your gfx1035 measurements; nothing here checks it.AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:13:42Z.
Review: APPROVED
Thanks for the fixes and for everyone's runs. Rebased onto current
mainand merging:docs/dev/TechnicalDebt.md(adjacent lines), both kept.FlatApertures.cpp:81now passes the fifthgpuargument toGuestAllocations::Mutation().Add, as @orishamir reported; the test did not compile onmain.agc_driver_flat_apertures(121 rows) and the FLAT, global, BDA, LDS and scratch tests pass; the test fails with the recompiler changes reverted.