perf(shader): share the BDA dword span read between read sites #1267

Merged
Celegans12 merged 1 commit from upstream-pr/1267 into main 2026-10-09 22:43:41 +00:00
Celegans12 commented 2026-10-07 20:34:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T20:34:09Z.


What

Every BDA dword read site still emits, in the entry function, the first-address add with its overflow fault, a probe_bda_pointer call, the wide loads and one read_bda_dword_bytes call per extracted dword. On NVIDIA every call left in the entry function costs compile time (one call doubles it), and PPSA26344's 0x8000196500 family has 911 of them, 47-77 s per pipeline in game.

  • A read site is now one call to read_bda_span[_stop][_coherent](address, offset, extracted, pc), DontInline and defined once per module, which does the same steps in the same order: first-address add and fault, span probe, wide loads of the extracted dwords, or per dword the address, overflow check and byte reader.
  • The stop variant returns (values, stopped) and the caller stops; continue targets keep the non-stop variant.
  • Fault reasons, addresses, pcs, Volatile, the stop behaviour and APS5_BDA_BYTE_READS=1 are unchanged. SourceVersion follows the sources; the cache format is unchanged.
  • #757-#759 and #920 (ours) edit DefineGetBdaPointer and SpirvBda.hpp nearby and merge cleanly; #639 (draft) edits the BDA write path. #1265 puts the BDA byte stores into shared functions and conflicts next to each new declaration and definition (both are kept); #1227 changes RunBdaExecutionTests next to the new test helper in BdaShader.hpp.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main c5e10184: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 396/396 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 395/395 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • agc_shader_memory: one read_bda_span* call per site. Fails on main.
  • New agc_driver_bda_span_reads (byte path); agc_driver_bda_device_tests cases (not part of ctest).
  • RTX 3080 Laptop, offline: four PPSA26344 compute programs (0x8000196500 family), 11-14 % faster.
  • PPSA26344 v1.008: in a 2,700 s run with this change, 30 in-game pipeline creations of the four ~830k-word programs (0x8000196500 family) took 41-57 s, median 47 s; a 2,700 s run without it had 15 at 47-77 s, median 60 s.
  • Not tested: Linux (CI), console behaviour, GPU time.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4778149014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1267). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T20:34:09Z. --- ### What Every BDA dword read site still emits, in the entry function, the first-address add with its overflow fault, a `probe_bda_pointer` call, the wide loads and one `read_bda_dword_bytes` call per extracted dword. On NVIDIA every call left in the entry function costs compile time (one call doubles it), and PPSA26344's 0x8000196500 family has 911 of them, 47-77 s per pipeline in game. - A read site is now one call to `read_bda_span[_stop][_coherent](address, offset, extracted, pc)`, DontInline and defined once per module, which does the same steps in the same order: first-address add and fault, span probe, wide loads of the extracted dwords, or per dword the address, overflow check and byte reader. - The stop variant returns `(values, stopped)` and the caller stops; continue targets keep the non-stop variant. - Fault reasons, addresses, pcs, `Volatile`, the stop behaviour and `APS5_BDA_BYTE_READS=1` are unchanged. SourceVersion follows the sources; the cache format is unchanged. - #757-#759 and #920 (ours) edit `DefineGetBdaPointer` and `SpirvBda.hpp` nearby and merge cleanly; #639 (draft) edits the BDA write path. #1265 puts the BDA byte stores into shared functions and conflicts next to each new declaration and definition (both are kept); #1227 changes `RunBdaExecutionTests` next to the new test helper in `BdaShader.hpp`. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` c5e10184: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 396/396 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 395/395 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - `agc_shader_memory`: one `read_bda_span*` call per site. Fails on main. - New `agc_driver_bda_span_reads` (byte path); `agc_driver_bda_device_tests` cases (not part of ctest). - RTX 3080 Laptop, offline: four PPSA26344 compute programs (0x8000196500 family), 11-14 % faster. - PPSA26344 v1.008: in a 2,700 s run with this change, 30 in-game pipeline creations of the four ~830k-word programs (0x8000196500 family) took 41-57 s, median 47 s; a 2,700 s run without it had 15 at 47-77 s, median 60 s. - Not tested: Linux (CI), console behaviour, GPU time. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Celegans12 commented 2026-10-07 20:54:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T20:54:16Z.


The Windows failure here is guest_raise_exception (libkernel) timing out on its second repeat: it passed the first repeat in 7.3 s, then hit the 30 s timeout on the next. This PR only changes the shader recompiler's BDA read emission, so it looks like a flaky timeout; a re-run of the windows job should clear it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6046660308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1267#issuecomment-6046660308). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T20:54:16Z. --- The Windows failure here is `guest_raise_exception` (libkernel) timing out on its second repeat: it passed the first repeat in 7.3 s, then hit the 30 s timeout on the next. This PR only changes the shader recompiler's BDA read emission, so it looks like a flaky timeout; a re-run of the windows job should clear it.
github-actions[bot] commented 2026-10-08 10:39:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T10:39:16Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2259 core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp L328-347
#2305 core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp L9, L69
core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp L9
#2349 core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp L289-290
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6058049912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1267#issuecomment-6058049912). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T10:39:16Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2259 | `core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp` [L328-347](https://github.com/boykopovar/AnyPS5/blob/64fe74399528c84fd74c3f736e632f89f4a7f211/core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp#L328-L347) | | | | #2305 | `core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp` [L9](https://github.com/boykopovar/AnyPS5/blob/64fe74399528c84fd74c3f736e632f89f4a7f211/core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp#L9), [L69](https://github.com/boykopovar/AnyPS5/blob/64fe74399528c84fd74c3f736e632f89f4a7f211/core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp#L69)<br>`core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp` [L9](https://github.com/boykopovar/AnyPS5/blob/64fe74399528c84fd74c3f736e632f89f4a7f211/core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp#L9) | | | | #2349 | `core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp` [L289-290](https://github.com/boykopovar/AnyPS5/blob/64fe74399528c84fd74c3f736e632f89f4a7f211/core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp#L289-L290) | | |
fisherjoey commented 2026-10-08 17:49:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T17:49:36Z.


Linux results, since this was tested on Windows only. Everything passes here, including agc_shader_memory and the new agc_driver_bda_span_reads.

Nobara 44 (Linux 7.2), GCC 16.2.1, Release, BUILD_TESTING=ON. This PR merged onto main 29e533ac.

main 29e533ac main + this PR
RTX 5070 Ti, driver 595.91.07, ctest -R agc_driver -j1 183 / 183 184 / 184
RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1, same 183 / 183 184 / 184
CPU tests (-E agc_driver) 279 / 280 279 / 280

The one CPU failure is guest_dynamic_loader (subprocess aborted), and it fails the same way on main. I didn't measure GPU time.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065786345 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1267#issuecomment-6065786345). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T17:49:36Z. --- Linux results, since this was tested on Windows only. Everything passes here, including `agc_shader_memory` and the new `agc_driver_bda_span_reads`. Nobara 44 (Linux 7.2), GCC 16.2.1, Release, `BUILD_TESTING=ON`. This PR merged onto `main` 29e533ac. | | `main` 29e533ac | `main` + this PR | |---|---|---| | RTX 5070 Ti, driver 595.91.07, `ctest -R agc_driver -j1` | 183 / 183 | 184 / 184 | | RADV, Ryzen 5 7600X iGPU (gfx1036), Mesa 26.2.1, same | 183 / 183 | 184 / 184 | | CPU tests (`-E agc_driver`) | 279 / 280 | 279 / 280 | The one CPU failure is `guest_dynamic_loader` (subprocess aborted), and it fails the same way on `main`. I didn't measure GPU time.
adriadam10 commented 2026-10-09 22:43:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:43:38Z.


Checked the new read_bda_span* against the inline sequence it replaces (first-address add and overflow fault, span probe, wide loads, per-dword byte reader, stop variant, coherence mask): same steps and order. Built merged onto current main: ctest 551/551, including agc_shader_memory (fails without the change) and agc_driver_bda_span_reads. Linux/NVIDIA/RADV results from @fisherjoey also line up; merging.

Note for #2259 and #2305: both conflict with this PR in SpirvBdaRead.cpp / BdaShader.cpp, they will need to rebase on top of it (the wide load path now lives in read_bda_span).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090514791 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1267#issuecomment-6090514791). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T22:43:38Z. --- Checked the new `read_bda_span*` against the inline sequence it replaces (first-address add and overflow fault, span probe, wide loads, per-dword byte reader, stop variant, coherence mask): same steps and order. Built merged onto current `main`: ctest 551/551, including `agc_shader_memory` (fails without the change) and `agc_driver_bda_span_reads`. Linux/NVIDIA/RADV results from @fisherjoey also line up; merging. Note for #2259 and #2305: both conflict with this PR in `SpirvBdaRead.cpp` / `BdaShader.cpp`, they will need to rebase on top of it (the wide load path now lives in `read_bda_span`).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1267
No description provided.