perf(shader): share the BDA byte read fallback between read sites #1043

Merged
Celegans12 merged 1 commit from upstream-pr/1043 into main 2026-10-07 12:45:25 +00:00
Celegans12 commented 2026-10-07 03:09:37 +00:00 (Migrated from github.com)

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


What

When the probe rejects a BDA dword read (a span across ranges, an unaligned mirror), it falls back to four get_bda_pointer byte lookups, and each fault is recorded inline with a compare-exchange and seven stores. Both are copied into every read site, twice under wave64 on 32-lane subgroups, so PPSA26344's compute shader 0x8000196500 reaches a million SPIR-V words and 91-95 s in vkCreateComputePipelines.

  • DefineGetBdaPointer defines, once per module, DontInline record_bda_fault(reason, address, bytes, pc) and read_bda_dword_bytes[_stop][_coherent](address, pc), the existing overflow check and byte lookups of one dword returning (value, stopped). The stop variants exist only where invocations may stop, and the coherent ones only when the program has a coherent access.
  • RecordBdaFault emits a call. The EmitBdaDwordReads fallback calls the reader per extracted dword, in order, and stops on stopped where invocations may stop; in a reader, StopBdaInvocationIf returns (0, 1).
  • Fault reasons, addresses, pcs, Volatile, stopping or reading zero, the probe path and 8/16-bit reads are unchanged. Inlinable helpers compiled slower (186 s).
  • SourceVersion follows the sources; the cache format is unchanged, so FormatVersion stays 4.
  • #757 (with #758, #759, #920) also edits RecordBdaFault and the same spot in ShaderMemory.cpp; I'll rebase whichever lands second. #639 (draft) edits DefineGetBdaPointer nearby.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main dc2bf2a5: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 377/377 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 376/376 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New agc_shader_memory check: with or without a barrier or glc, one DontInline record_bda_fault and reader, one compare-exchange, no byte lookups in main, Volatile only in the coherent reader, 198 words per extra read (627 on main). Fails on main.
  • agc_driver_bda_device_tests (not in ctest) gains dword and dwordx4 reads across ranges, plain and coherent, stopping and not (unmapped bytes read zero, the first fault is published); they pass on main too. NVIDIA and lavapipe, also with -DANYPS5_ENABLE_SPIRV_TOOLS=ON.
  • RTX 3080 Laptop, offline: 0x8000196500 1,001,541 to 830,054 words, 91-95 to 43-46 s; 7 of 115 captured programs shrink, none grow.
  • PPSA26344 v1.008: in game the three 0x8000196500 variants (~835k words) took 45.4-45.7 s each.
  • Not tested: Linux (CI), console behaviour.

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:4767418872 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1043). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T03:09:37Z. --- ### What When the probe rejects a BDA dword read (a span across ranges, an unaligned mirror), it falls back to four `get_bda_pointer` byte lookups, and each fault is recorded inline with a compare-exchange and seven stores. Both are copied into every read site, twice under wave64 on 32-lane subgroups, so PPSA26344's compute shader 0x8000196500 reaches a million SPIR-V words and 91-95 s in `vkCreateComputePipelines`. - `DefineGetBdaPointer` defines, once per module, DontInline `record_bda_fault(reason, address, bytes, pc)` and `read_bda_dword_bytes[_stop][_coherent](address, pc)`, the existing overflow check and byte lookups of one dword returning `(value, stopped)`. The stop variants exist only where invocations may stop, and the coherent ones only when the program has a coherent access. - `RecordBdaFault` emits a call. The `EmitBdaDwordReads` fallback calls the reader per extracted dword, in order, and stops on `stopped` where invocations may stop; in a reader, `StopBdaInvocationIf` returns `(0, 1)`. - Fault reasons, addresses, pcs, `Volatile`, stopping or reading zero, the probe path and 8/16-bit reads are unchanged. Inlinable helpers compiled slower (186 s). - SourceVersion follows the sources; the cache format is unchanged, so FormatVersion stays 4. - #757 (with #758, #759, #920) also edits `RecordBdaFault` and the same spot in `ShaderMemory.cpp`; I'll rebase whichever lands second. #639 (draft) edits `DefineGetBdaPointer` nearby. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` dc2bf2a5: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 377/377 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 376/376 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `agc_shader_memory` check: with or without a barrier or `glc`, one DontInline `record_bda_fault` and reader, one compare-exchange, no byte lookups in `main`, `Volatile` only in the coherent reader, 198 words per extra read (627 on main). Fails on main. - `agc_driver_bda_device_tests` (not in ctest) gains dword and dwordx4 reads across ranges, plain and coherent, stopping and not (unmapped bytes read zero, the first fault is published); they pass on main too. NVIDIA and lavapipe, also with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`. - RTX 3080 Laptop, offline: 0x8000196500 1,001,541 to 830,054 words, 91-95 to 43-46 s; 7 of 115 captured programs shrink, none grow. - PPSA26344 v1.008: in game the three 0x8000196500 variants (~835k words) took 45.4-45.7 s each. - Not tested: Linux (CI), console behaviour. ### 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
adriadam10 commented 2026-10-07 12:45:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T12:45:22Z.


Checked on RADV merged onto current main: build + ctest green, the new agc_shader_memory check fails on main, and the new agc_driver_bda_device_tests cases give the same results with this PR's emitter and with main's (values, unmapped bytes, first fault, stop/no-stop, coherent). No ISA semantics change, so nothing to measure on the HW oracle. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6038190730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1043#issuecomment-6038190730). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T12:45:22Z. --- Checked on RADV merged onto current `main`: build + ctest green, the new `agc_shader_memory` check fails on `main`, and the new `agc_driver_bda_device_tests` cases give the same results with this PR's emitter and with `main`'s (values, unmapped bytes, first fault, stop/no-stop, coherent). No ISA semantics change, so nothing to measure on the HW oracle. Merging.
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!1043
No description provided.