Repository navigation
perf(recompiler): load the written-page slot before the CAS - #1280
Conversation
Every 8- and 16-bit BDA store and the unaligned path of every 32-bit store emitted one get_bda_write_pointer lookup and one note_bda_write per byte at the store site, five write lookups per 32-bit store. They now call write_bda_bytes, which loops over the bytes and does, per byte and in order, the same lookup, the store when it is mapped and the write note, so faults are recorded exactly as before. On an RTX 3060 the agc_driver_flat_store binaries shrink from 496,256 to 138,240 bytes (wave32) and from 928,384 to 225,152 bytes (wave64), and the cold run from 19.7 s to 2.2 s.
note_bda_write unrolled its 8 compare-exchange probes, and drivers inline it at every BDA store and atomic. The probes now run in a loop that tries the same slots in the same order and stops at the same slot, so the recorded pages and the overflow flag are unchanged. With the byte store helper, the agc_driver_flat_store binaries on an RTX 3060 go from 138,240 to 75,648 bytes (wave32) and from 225,152 to 130,560 bytes (wave64), and the cold run from 2.2 s to 1.2 s.
… path The declaration, the state field and the definition of write_bda_bytes now sit next to EmitBdaStore and the other BDA write functions instead of next to the dword read functions, which boykopovar#1267 extends at the same lines. No change to the emitted code.
note_bda_write ran a device-scope compare-exchange on every probe, also when the slot already held the page. The table lives in host-visible memory, so each BDA store paid an atomic across PCIe, and nearly every store hits a page an earlier store noted. Load the slot first and only compare-exchange when it does not hold the page. The slots probed, the pages recorded and the overflow report are unchanged. DOOM (PPSA99666) presents through a compute kernel that stores about two million pixels through raw pointers per frame: 248 ms per dispatch before, 8.1 ms after, on an RTX 5070 Ti. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Measured on AMD and Linux, which the description lists as not run: Ubuntu 24.04.5 (kernel 6.8), GCC 13.3, Release, AMD Radeon RX 7600 (RADV NAVI33, Mesa 25.2.8, resizable BAR on). This PR's head is DOOM homebrew PPSA99666 v1.1.1, built from source, relinked with
|
|
Linux results, since this was tested on Windows only. Everything passes here. Nobara 44 (Linux 7.2), GCC 16.2.1, Release,
The CPU failure is |
|
Checked the diff against the original probe loop: same slots in the same order, same Note: no existing test fails if the page is never recorded through this path (I forced the "slot already holds the page" check to true and |
…note-load perf(recompiler): load the written-page slot before the CAS
What
Depends on #1265. Until it merges, this PR also shows its three commits; only the last commit is new here.
note_bda_writeruns a device-scopeOpAtomicCompareExchangeon every probe, also when the slot already holds the page. The written-page table lives in the BDA fault buffer, which is host-visible memory, so every BDA store pays an atomic across PCIe. Almost every store hits a page that an earlier store already noted.OpAtomicLoadand runs the compare-exchange only when the slot does not hold the page.Why the CAS is the cost
DOOM homebrew PPSA99666 v1.1.1 (lowbit/ps5-doom, GPL-2.0) presents through a small compute kernel: 1080 workgroups of 64, each reads palette-indexed bytes and stores 1920 pixels through raw pointers, about 2.07 M BDA stores per frame. It waits 500 ms for the frame's fence and otherwise falls back to its CPU scaler.
mainAPS5_PROFILE_GPU)APS5_SYNC_DISPATCH, packet time)APS5_PROFILE_GPU, ~590 dispatches per 10 s)Experiments on
mainbefore writing this:DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT(ReBAR) instead of system memory gave the same gain: about 170 ms to about 10 ms per frame.APS5_SPIRV_OPT=fullchanged nothing.This change keeps both buffers where they are and needs no ReBAR.
Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti, Ryzen 7 7800X3D.
agc_*andshader_*tests pass on this branch.ANYPS5_ENABLE_SPIRV_TOOLS=ON, which validates every module before and after optimization:flat_store,global_store_addtid,global_atomics,global_atomics64,global_atomics_float,global_atomics_lanes,global_atomic_csub,flat_cache_bits,global_vcc_base,flat_loads,d16_memoryand the BDA tests pass (13 tests).main, the same change before perf(recompiler): loop the BDA byte stores and written-page probes #1265 also passed all 396 registered tests.CTestTestfile.cmakefiles, because antivirus blocksctest.exeon this machine.APS5_DUMP_SHADERS,shader_202a81800.req, 304 code words) replays withagc_shader_replay; I can attach it.Not run on AMD, Intel or Linux.
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