feat(recompiler): format loads and dword atomics through GPU-selected buffer descriptors #1183
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1183"
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-07T16:44:36Z.
What
A buffer access whose V# the shader reads at run time (a waterfall over a descriptor table) already worked for raw dword loads and stores. This adds:
GetFormatInfoknows, then swizzled by its DST_SEL. Any other FORMAT reads zero. The reserved DST_SEL values follow the hardware: 2 reads the output's own component modulo the format's component count, 3 reads zero on multi-component formats and X on single-component ones. Bounds follow the element, not the dword: raw (OOB_SELECT 3) needs offset + element bytes <= num_records, structured needs the whole element inside the stride, and an element out of bounds reads zero as a whole. A typed (tbuffer) load takes its format from the instruction. Format stores and D16 loads are still refused.EmitBdaAtomic, and notes the write for GPU ownership.tests/ControlFlow.cpprecompiles a waterfall-style format load and an atomic through a V# read from a table.tests/execution/GpuSelectedBufferFormat.cpp(agc_driver_gpu_selected_buffer_format) runs the measured rows from the review on the device for wave32 and wave64: element bounds, a stride smaller than the element, selectors 0 to 7, a typed load and the dword atomic.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).agc_driver_gpu_selected_buffer_formatpasses (44 of its 98 checks fail on the previous version of this PR), and the recompiler and buffer tests pass. GTA V has not been re-run with the bounds and selector changes. Not run here: 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 adriadam10 on 2026-10-08T08:43:55Z.
Review: CHANGES_REQUESTED
Thanks. I measured the new runtime path on the HW oracle (gfx1035,
buffer_load_format_xyzwwith the V# built in SGPRs, one row per launch). Unknown FORMAT values (0, 78..127) do read zero, and the dword atomic's bounds match. Three things don't match, and the tests don't catch them:Raw bounds (OOB_SELECT=3) use the dword check, not the element size.
LoadGpuDescriptorFormattedtakesinBoundsfromForEachGpuDescriptorDword(SpirvMemoryInstructions.cpp:711), whosehasDwordtest isnum_records >= 4 && offset <= num_records - 4. On hardware an element is in bounds iffoffset + element bytes <= num_records, and out-of-bounds means the whole element reads 0:Structured bounds (OOB_SELECT=0) need the whole element inside the stride. With
idxen, 32_32_32_32 at stride 8 and 32_32 at stride 4 read 0 on HW. The PR only checksoffset < stride. The typed path uses the sameinBounds, so it has both bound issues.Reserved DST_SEL values don't read zero (
:738). Hardware gives: selector 2 = the slot's own component, modulo the component count (32_32 with all four selectors at 2 gives x, y, x, y; 32_32_32 gives x, y, z, x). Selector 3 = 0 on multi-component formats, but X on single-component ones (32_UINT, 8_UNORM). A runtime selector can't throw, so the measured values have to be modelled.Tests: the two
ControlFlow.cppcases (:925,:937) only check that the shader recompiles. They pin no values, so none of the above shows up. An execution test (tests/execution/) with a V# read from a table would catch these. It should cover the bound rows above, a stride smaller than the element, selectors 0/1/2/3/4-7 on single- and multi-component formats, a typed load, and the atomic (returned value and memory), run in wave64 too.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T09:11:28Z.
I ran Ghost of Yōtei (PPSA26344 v1.008) with this PR at 5a7cd643e, and it gets one compute program past its runtime V#, but that program then compiles to a SPIR-V module so big that the NVIDIA driver ran the machine out of memory building its pipeline.
The program is 0x801cdd2700, 6,596 code words. Without the PR it was skipped with
GetBufferResource dword 0 is not a valid runtime valueat pc 0x234. With it, the recompile succeeds in 248 ms but gives 13,415,426 SPIR-V words.vkCreateComputePipelinesstarted on it about 386 s into the run and never returned: the game was at 58 GB private bytes in our last memory sample, Windows then logged a low-virtual-memory event naming eboot.exe at 73 GB of commit, and the game exited with code 3 at 910 s. Building the same pipeline on its own from the captured request reached 76 GB after about 12 minutes before I stopped it.As far as I can tell the size comes from
LoadGpuDescriptorFormatted. For an untyped format load it emits anOpSwitchwith one arm per known buffer format, each with its own conversion, at every load site, so the module grows with loads times formats. Would you consider emitting that conversion once, as a SPIR-V function that each load calls with descriptor word 3 and the raw dwords? I'm happy to test a new head on this program, and I can send you the captured recompile request (73 KB) if you want to reproduce it.The rest looks good so far: another compute program (0x8000333c00) now gets past its formatted load at pc 0x2e8 and stops at the next unresolved V#, at pc 0x650. To let our hour-long run finish I reverted this PR there, and 0x801cdd2700 went back to being skipped.
Details
Windows 11, RTX 3080 Laptop (16 GB), 32 GB RAM. Build: our integration tree on main
c8a2f0632with this PR at 5a7cd643e (plus our open PRs and env-gated probes).Windows System log, event 2004 at 08:07:57: "eboot.exe (10948) consumed 73118875648 bytes". The game exited with code 3 at 910 s.
Without the PR (previous run):
0x8000333c00:
GetBufferResource dword 0 ... ReadConstBuffer@pc=0x000002e8without the PR,ReadConstBuffer@pc=0x00000650(GetBufferResource(ReadConst(GetSrtResource, Immediate), ...with it.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-08T15:58:21Z.
Thanks, the measured tables made this straightforward. Rebased onto main, and in this push:
tests/execution/GpuSelectedBufferFormat.cpp(agc_driver_gpu_selected_buffer_format) dispatches each row on the device for wave32 and wave64: your table, a stride smaller than the element, selectors 0 to 7 on single- and multi-component formats, a typed load, and the dword atomic (returned value and memory). On the previous version 44 of its 98 checks fail; with this change all pass.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-09T08:32:04Z.
Closing: superseded by #639. Buffer accesses now go through runtime descriptors (
SpirvRuntimeBuffer.cppdecodes the format at runtime), which covers the format loads and dword atomics through GPU-selected V#s this PR added.Pull request closed