perf(shader): look up the BDA range of a user-data pointer once at program entry #5859

Merged
gjonn merged 3 commits from upstream-pr/5859 into main 2026-10-18 13:54:45 +00:00
gjonn commented 2026-10-14 13:54:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-14T13:54:42Z.


What

Address-based reads whose 64-bit base is a pair of user-data registers (GetAddressResource(GetUserData, GetUserData)) search the BDA table at every read, although the base is one value for the whole draw. In the 4K fragment passes of PPSA01317's main map most global/scalar reads are of this kind, and the per-read searches (and the registers they hold across the program) dominate the pass.

With this change, when a program has two or more such read sites of one base (counted after adjacent loads are grouped; at most four bases, those with the most read sites):

  • CollectBdaAnchors picks the bases; bda_anchor_range, a variant of the lookup that returns the range (begin, bound, device) instead of one device address and records no faults, finds the range holding each base once at the program's entry (before the pixel interlock). bound is the range's end, or the next table entry's begin when that comes first: a lookup selects the last range beginning at or below an address, so on tables whose ranges overlap the anchor only covers the addresses for which a lookup would select the same range. When the program already requires subgroup ballots, the subgroup's elected lane searches and broadcasts the result; otherwise each invocation searches once.
  • Each such read (LoadBda, grouped adjacent loads, LoadBdaWide) takes one branch: when the anchor's range holds all of its bytes (offset (base - begin) + zext(low) + immediate checked against size - bytes), and for dword reads the device address is 4-aligned, it loads them directly (device-scope atomic loads for coherent dwords, byte loads for 8/16-bit reads, as the lookup path does). Otherwise it runs the lookup path unchanged, so data, fault records, invocation stops and wraparound are exactly as before.
  • An anchor is not used when its search fails, when its range ends above 0xffffffff00000000 (so base + zext(low) cannot wrap and the lookup path's overflow checks cannot fire for a read the range holds), when the range is longer than 2^62 bytes (so the offset arithmetic cannot wrap with a positive immediate), or when its device addresses wrap.
  • Lookups and anchors rely on the table's ranges ascending by begin; they may overlap (GuestBufferMemory::AddressRanges merges a build's regions read over the address space's ranges). BdaAbi::RangesOrdered states that contract, and BdaResources now requires it when it builds a table (once per new table, not on cache hits). BdaAbi::RangesOrdered is added to shaderCacheReviewedNames.

No switch: anchors are how such reads are generated.

Tested

Windows 11, MinGW-w64 GCC 15.2, NVIDIA GeForce RTX 5090 Laptop GPU (driver 616.92). Built on main at cee9841b6; the branch merges cleanly into the current main.

  • agc_driver_bda_device (new RunBdaAnchorTests): GPU exactness. Programs with 36 read sites (8, 16 and 32-bit reads, 1/3/4-dword reads with all and some dwords used, immediates 0, 4, -1, -8, 0x7ffffff0 and INT32_MIN) are compiled twice, through EmitAnchoredBdaRead and through the lookups alone, and run against a table with byte-granular ranges, a range mapped to an odd device address, a range overlapping the one before it, a range ending at the anchor limit and one above it. For 15 bases (in each range, at range ends, unmapped, near 2^64) and 59 lane offsets per dispatch, values and fault state must match; with invocation stops, single-lane runs must match the whole fault record. Also coherent reads, elected search with 64 lanes, a range without read permission, an invalid table and a range longer than 2^62 bytes. A program whose lookup path returns a sentinel shows which reads load directly: real data inside the anchor's range, the sentinel at its end, across ranges, past the next range's begin, at an odd device address, above the limit, without read permission and with an invalid table. Mutations checked locally: removing the next-begin bound, the address limit, the alignment check or the size check, an off-by-one in the range check, ignoring the first used dword and never taking the direct path each make it fail. Removing the 2^62 span limit does not, because with real device addresses (above 2^32) such a range is already refused for wrapping device addresses.
  • agc_driver_bda_anchor_reads (new): a recompiled wave32/wave64 compute program with three adjacent global_load_dword (grouped into one span read), an unaligned one and two s_load_dword through the user-data base s[0:1] runs on the GPU and must search an anchor and store the expected data. The grouped and unaligned reads take the anchor (shifting their offset fails the test); the scalar reads are evaluated from captured memory at recompile time, so they do not reach the anchor path.
  • agc_shader_memory (new verifyBdaAnchors): codegen. Recompiled compute programs with 0, 1, 2 and 4 global_load_dword through s[4:5] (separate and adjacent offsets) plus one VGPR-addressed load: anchors exactly when two or more read sites share the base (adjacent loads grouped into one span read count once), one search in main before any read, every read keeps its read_bda_span lookup path, anchored reads load directly. With anchors disabled it fails.
  • BdaContracts: RangesOrdered accepts tables ascending by begin, including empty and overlapping ranges, and refuses unsorted ones.
  • ctest -R "^agc_|^shader": 531 of 531 pass (3 skipped by design).
  • spirv-val --target-env vulkan1.3 on the SPIR-V of both new tests (codegen programs and GPU test programs, plain and anchored): valid.
  • python tools/check_conventions.py --base origin/main passes.
  • agc_driver_bda_device takes 6-14 s here instead of 5 s. RunBdaExecutionTests (and so the new GPU tests) is skipped on CPU Vulkan devices, so lavapipe CI does not run them.

Performance. These numbers come from my local branch, not from stock main: that branch carries an earlier version of this change on top of local BDA lookup changes main does not have (a lookup hint and cache), so the baseline differs from main and the gain on main is not measured. I could not replay the same requests on main because its request format has moved on from the dumps.

  • Offline, 8 replayed 4K fragment programs of PPSA01317, median time per 3840x2160 draw over 20 runs: 7.4-10.3 ms before, 3.1-4.9 ms after (49-61% faster); color outputs hash identical before and after. Driver-reported scratch use per program went from 160 to 48 B and from 208 to 112 B.
  • In game, PPSA01317's main map, matched sessions with profiling off: 17.07 to 18.44 FPS (+8%). No performance report traces are attached; I can capture them on request.

Not tested: AMD, Intel, Linux, macOS; real pixel shaders compiled from this branch (only the test programs above).

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: none (speeds up PPSA01317 #4697)
  • GPUs tested: NVIDIA GeForce RTX 5090 Laptop GPU, driver 616.92, Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4858983583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-14T13:54:42Z. --- ### What Address-based reads whose 64-bit base is a pair of user-data registers (`GetAddressResource(GetUserData, GetUserData)`) search the BDA table at every read, although the base is one value for the whole draw. In the 4K fragment passes of PPSA01317's main map most global/scalar reads are of this kind, and the per-read searches (and the registers they hold across the program) dominate the pass. With this change, when a program has two or more such read sites of one base (counted after adjacent loads are grouped; at most four bases, those with the most read sites): - `CollectBdaAnchors` picks the bases; `bda_anchor_range`, a variant of the lookup that returns the range `(begin, bound, device)` instead of one device address and records no faults, finds the range holding each base once at the program's entry (before the pixel interlock). `bound` is the range's end, or the next table entry's begin when that comes first: a lookup selects the last range beginning at or below an address, so on tables whose ranges overlap the anchor only covers the addresses for which a lookup would select the same range. When the program already requires subgroup ballots, the subgroup's elected lane searches and broadcasts the result; otherwise each invocation searches once. - Each such read (`LoadBda`, grouped adjacent loads, `LoadBdaWide`) takes one branch: when the anchor's range holds all of its bytes (offset `(base - begin) + zext(low) + immediate` checked against `size - bytes`), and for dword reads the device address is 4-aligned, it loads them directly (device-scope atomic loads for coherent dwords, byte loads for 8/16-bit reads, as the lookup path does). Otherwise it runs the lookup path unchanged, so data, fault records, invocation stops and wraparound are exactly as before. - An anchor is not used when its search fails, when its range ends above `0xffffffff00000000` (so `base + zext(low)` cannot wrap and the lookup path's overflow checks cannot fire for a read the range holds), when the range is longer than 2^62 bytes (so the offset arithmetic cannot wrap with a positive immediate), or when its device addresses wrap. - Lookups and anchors rely on the table's ranges ascending by begin; they may overlap (`GuestBufferMemory::AddressRanges` merges a build's regions read over the address space's ranges). `BdaAbi::RangesOrdered` states that contract, and `BdaResources` now requires it when it builds a table (once per new table, not on cache hits). `BdaAbi::RangesOrdered` is added to `shaderCacheReviewedNames`. No switch: anchors are how such reads are generated. ### Tested Windows 11, MinGW-w64 GCC 15.2, NVIDIA GeForce RTX 5090 Laptop GPU (driver 616.92). Built on `main` at cee9841b6; the branch merges cleanly into the current `main`. - `agc_driver_bda_device` (new `RunBdaAnchorTests`): GPU exactness. Programs with 36 read sites (8, 16 and 32-bit reads, 1/3/4-dword reads with all and some dwords used, immediates 0, 4, -1, -8, 0x7ffffff0 and INT32_MIN) are compiled twice, through `EmitAnchoredBdaRead` and through the lookups alone, and run against a table with byte-granular ranges, a range mapped to an odd device address, a range overlapping the one before it, a range ending at the anchor limit and one above it. For 15 bases (in each range, at range ends, unmapped, near 2^64) and 59 lane offsets per dispatch, values and fault state must match; with invocation stops, single-lane runs must match the whole fault record. Also coherent reads, elected search with 64 lanes, a range without read permission, an invalid table and a range longer than 2^62 bytes. A program whose lookup path returns a sentinel shows which reads load directly: real data inside the anchor's range, the sentinel at its end, across ranges, past the next range's begin, at an odd device address, above the limit, without read permission and with an invalid table. Mutations checked locally: removing the next-begin bound, the address limit, the alignment check or the size check, an off-by-one in the range check, ignoring the first used dword and never taking the direct path each make it fail. Removing the 2^62 span limit does not, because with real device addresses (above 2^32) such a range is already refused for wrapping device addresses. - `agc_driver_bda_anchor_reads` (new): a recompiled wave32/wave64 compute program with three adjacent `global_load_dword` (grouped into one span read), an unaligned one and two `s_load_dword` through the user-data base `s[0:1]` runs on the GPU and must search an anchor and store the expected data. The grouped and unaligned reads take the anchor (shifting their offset fails the test); the scalar reads are evaluated from captured memory at recompile time, so they do not reach the anchor path. - `agc_shader_memory` (new `verifyBdaAnchors`): codegen. Recompiled compute programs with 0, 1, 2 and 4 `global_load_dword` through `s[4:5]` (separate and adjacent offsets) plus one VGPR-addressed load: anchors exactly when two or more read sites share the base (adjacent loads grouped into one span read count once), one search in `main` before any read, every read keeps its `read_bda_span` lookup path, anchored reads load directly. With anchors disabled it fails. - `BdaContracts`: `RangesOrdered` accepts tables ascending by begin, including empty and overlapping ranges, and refuses unsorted ones. - `ctest -R "^agc_|^shader"`: 531 of 531 pass (3 skipped by design). - `spirv-val --target-env vulkan1.3` on the SPIR-V of both new tests (codegen programs and GPU test programs, plain and anchored): valid. - `python tools/check_conventions.py --base origin/main` passes. - `agc_driver_bda_device` takes 6-14 s here instead of 5 s. `RunBdaExecutionTests` (and so the new GPU tests) is skipped on CPU Vulkan devices, so lavapipe CI does not run them. Performance. These numbers come from my local branch, not from stock `main`: that branch carries an earlier version of this change on top of local BDA lookup changes `main` does not have (a lookup hint and cache), so the baseline differs from `main` and the gain on `main` is not measured. I could not replay the same requests on `main` because its request format has moved on from the dumps. - Offline, 8 replayed 4K fragment programs of PPSA01317, median time per 3840x2160 draw over 20 runs: 7.4-10.3 ms before, 3.1-4.9 ms after (49-61% faster); color outputs hash identical before and after. Driver-reported scratch use per program went from 160 to 48 B and from 208 to 112 B. - In game, PPSA01317's main map, matched sessions with profiling off: 17.07 to 18.44 FPS (+8%). No performance report traces are attached; I can capture them on request. Not tested: AMD, Intel, Linux, macOS; real pixel shaders compiled from this branch (only the test programs above). ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Unblocks: none (speeds up PPSA01317 #4697) - [x] GPUs tested: NVIDIA GeForce RTX 5090 Laptop GPU, driver 616.92, Windows 11 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-14 14:06:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T14:06:56Z.


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
PR 6639 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp L1189
PR 6706 core/libs/prx/libSceAgcDriver/tests/BdaContracts.cpp L11, L183
PR 6801 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp L1189

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1341 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CMakeLists.txt
PR 4650 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 5021 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp
PR 5371 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 5500 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 5925 core/shader/recompiler/CMakeLists.txt
PR 6094 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6177 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
PR 6222 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6232 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6292 core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp
PR 6373 core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp
core/libs/prx/libSceAgcDriver/tests/BdaExecution.cpp
core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp
core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp
core/shader/recompiler/BdaAbi.hpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6416 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvBda.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6503 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
PR 6615 core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp
PR 6645 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6767 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
PR 6879 core/shader/recompiler/CMakeLists.txt
PR 6946 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CMakeLists.txt
PR 6947 core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/BdaAbi.hpp
core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvBda.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 6977 core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
PR 6987 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6989 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6995 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7002 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7201 core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp
core/shader/recompiler/CMakeLists.txt
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 7390 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6170272237 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859#issuecomment-6170272237). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T14:06:56Z. --- <!-- 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 | |---|---|---|---| | [PR 6639](https://www.github.com/boykopovar/AnyPS5/pull/6639) | `core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` [L1189](https://github.com/boykopovar/AnyPS5/blob/385ed71f2cfa8d67ff466d050d5e88e136d3ec28/core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp#L1189) | | | | [PR 6706](https://www.github.com/boykopovar/AnyPS5/pull/6706) | `core/libs/prx/libSceAgcDriver/tests/BdaContracts.cpp` [L11](https://github.com/boykopovar/AnyPS5/blob/385ed71f2cfa8d67ff466d050d5e88e136d3ec28/core/libs/prx/libSceAgcDriver/tests/BdaContracts.cpp#L11), [L183](https://github.com/boykopovar/AnyPS5/blob/385ed71f2cfa8d67ff466d050d5e88e136d3ec28/core/libs/prx/libSceAgcDriver/tests/BdaContracts.cpp#L183) | | | | [PR 6801](https://www.github.com/boykopovar/AnyPS5/pull/6801) | `core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` [L1189](https://github.com/boykopovar/AnyPS5/blob/385ed71f2cfa8d67ff466d050d5e88e136d3ec28/core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp#L1189) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1341](https://www.github.com/boykopovar/AnyPS5/pull/1341) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`<br>`core/shader/recompiler/CMakeLists.txt` | | [PR 4650](https://www.github.com/boykopovar/AnyPS5/pull/4650) | `core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp`<br>`core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp`<br>`core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp` | | [PR 5371](https://www.github.com/boykopovar/AnyPS5/pull/5371) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 5500](https://www.github.com/boykopovar/AnyPS5/pull/5500) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`<br>`core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `core/shader/recompiler/CMakeLists.txt` | | [PR 6094](https://www.github.com/boykopovar/AnyPS5/pull/6094) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`<br>`core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`<br>`core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp`<br>`core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` | | [PR 6232](https://www.github.com/boykopovar/AnyPS5/pull/6232) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`<br>`core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` | | [PR 6292](https://www.github.com/boykopovar/AnyPS5/pull/6292) | `core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp` | | [PR 6373](https://www.github.com/boykopovar/AnyPS5/pull/6373) | `core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaExecution.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp`<br>`core/shader/recompiler/BdaAbi.hpp` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6416](https://www.github.com/boykopovar/AnyPS5/pull/6416) | `core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvBda.hpp`<br>`core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp` | | [PR 6488](https://www.github.com/boykopovar/AnyPS5/pull/6488) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6503](https://www.github.com/boykopovar/AnyPS5/pull/6503) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`<br>`core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp` | | [PR 6615](https://www.github.com/boykopovar/AnyPS5/pull/6615) | `core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp` | | [PR 6645](https://www.github.com/boykopovar/AnyPS5/pull/6645) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6767](https://www.github.com/boykopovar/AnyPS5/pull/6767) | `core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/shader/recompiler/CMakeLists.txt` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`<br>`core/shader/recompiler/CMakeLists.txt` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`<br>`core/shader/recompiler/BdaAbi.hpp`<br>`core/shader/recompiler/CMakeLists.txt`<br>`core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvBda.hpp`<br>`core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp`<br>`core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp`<br>`core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/shader/recompiler/CMakeLists.txt`<br>`core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp` | | [PR 6987](https://www.github.com/boykopovar/AnyPS5/pull/6987) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6989](https://www.github.com/boykopovar/AnyPS5/pull/6989) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6995](https://www.github.com/boykopovar/AnyPS5/pull/6995) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 7002](https://www.github.com/boykopovar/AnyPS5/pull/7002) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libSceAgcDriver/Graphics/src/BdaResources.cpp`<br>`core/shader/recompiler/CMakeLists.txt`<br>`core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp`<br>`core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` | | [PR 7390](https://www.github.com/boykopovar/AnyPS5/pull/7390) | `core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp` |
CnRJay commented 2026-10-14 16:56:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T16:56:11Z.

Review: COMMENTED


Resolving the range of a user-data base once per invocation is a good idea for these 4K passes. The exactness test (anchored against lookup-only compiles, faults included) is thorough. I'd like to see two costs measured before this becomes the only way such reads are generated:

1. Pipeline compile time and module size. Every anchored read now carries both paths: the direct load, plus the full lookup path kept as the fallback branch. Programs with many read sites therefore grow, and so does the driver compile, which shows up as hitches on first use rather than in steady-state FPS. A table of SPIR-V word counts and vkCreateGraphicsPipelines/vkCreateComputePipelines time for the eight PPSA01317 programs, with and without anchors, would show whether that is small. A warm-cache run won't capture it, so a cold-cache start of the main map with the shader disk cache disabled would be the place to look.

2. Gains measured on main. The 49–61 % offline and +8 % in-game figures come from a branch with other BDA lookup changes (a hint and a cache) that main doesn't have. Those reduce the cost of the lookup path, so they change how much an anchor saves. The aps5-summary.jsonl lines of main and of main + this PR from the same scene, with no APS5_PROFILE_* switch, are what the Performance report form asks for, and you offered to capture them.

Also: everything was measured on NVIDIA. RADV/ACO and the AMD Windows driver handle the extra branch and the coherent atomic loads differently, so one AMD run would be worth having, since the change applies to every title. With no switch, the anchors can't be turned off to compare in the field. APS5_NO_BDA_ANCHORS would let testers isolate a regression.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5521554419 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859#pullrequestreview-5521554419). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T16:56:11Z. **Review:** COMMENTED --- Resolving the range of a user-data base once per invocation is a good idea for these 4K passes. The exactness test (anchored against lookup-only compiles, faults included) is thorough. I'd like to see two costs measured before this becomes the only way such reads are generated: **1. Pipeline compile time and module size.** Every anchored read now carries both paths: the direct load, plus the full lookup path kept as the fallback branch. Programs with many read sites therefore grow, and so does the driver compile, which shows up as hitches on first use rather than in steady-state FPS. A table of SPIR-V word counts and `vkCreateGraphicsPipelines`/`vkCreateComputePipelines` time for the eight PPSA01317 programs, with and without anchors, would show whether that is small. A warm-cache run won't capture it, so a cold-cache start of the main map with the shader disk cache disabled would be the place to look. **2. Gains measured on `main`.** The 49–61 % offline and +8 % in-game figures come from a branch with other BDA lookup changes (a hint and a cache) that `main` doesn't have. Those reduce the cost of the lookup path, so they change how much an anchor saves. The `aps5-summary.jsonl` lines of `main` and of `main` + this PR from the same scene, with no `APS5_PROFILE_*` switch, are what the Performance report form asks for, and you offered to capture them. Also: everything was measured on NVIDIA. RADV/ACO and the AMD Windows driver handle the extra branch and the coherent atomic loads differently, so one AMD run would be worth having, since the change applies to every title. With no switch, the anchors can't be turned off to compare in the field. `APS5_NO_BDA_ANCHORS` would let testers isolate a regression.
EagleBearerYS commented 2026-10-15 00:35:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-15T00:35:50Z.


A note before the full Build runs on this. With ANYPS5_ENABLE_SPIRV_TOOLS=ON, as CI configures it, programs without 64-bit integers fail SPIR-V validation on this head (3265cb6d7) merged onto current main (ab9a47684):

Using a 64-bit integer type requires the Int64 capability.
  %ulong = OpTypeInt 64 0

EmitBdaAnchors runs for every program (SpirvModuleEmitter.cpp:1167), and its first line declares the 64-bit type (TypeScalarU64, SpirvBdaRead.cpp:544) even when the program has no anchors.

  • On Linux with lavapipe (CI's configure flags), agc_shader_memory and agc_formatted_buffer_once fail that way.
  • With if (state.bdaAnchors.empty()) return; at the top of EmitBdaAnchors, both pass, and so does agc_shader_bindless.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181623052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859#issuecomment-6181623052). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-15T00:35:50Z. --- A note before the full Build runs on this. With `ANYPS5_ENABLE_SPIRV_TOOLS=ON`, as CI configures it, programs without 64-bit integers fail SPIR-V validation on this head (3265cb6d7) merged onto current `main` (ab9a47684): ``` Using a 64-bit integer type requires the Int64 capability. %ulong = OpTypeInt 64 0 ``` `EmitBdaAnchors` runs for every program (`SpirvModuleEmitter.cpp:1167`), and its first line declares the 64-bit type (`TypeScalarU64`, `SpirvBdaRead.cpp:544`) even when the program has no anchors. - On Linux with lavapipe (CI's configure flags), `agc_shader_memory` and `agc_formatted_buffer_once` fail that way. - With `if (state.bdaAnchors.empty()) return;` at the top of `EmitBdaAnchors`, both pass, and so does `agc_shader_bindless`.
oneandonlydean commented 2026-10-17 00:41:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T00:41:50Z.


@EagleBearerYS's finding is the blocker: with SPIRV-Tools on, as CI configures it, programs without 64-bit integers fail validation on this head because EmitBdaAnchors declares the u64 type for every program. @gjonn, please declare it only when the program has an anchor. @CnRJay's two measurements (compile time and module size with both paths in every anchored read) are still needed before this becomes the only way such reads are generated.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227475927 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859#issuecomment-6227475927). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T00:41:50Z. --- @EagleBearerYS's finding is the blocker: with SPIRV-Tools on, as CI configures it, programs without 64-bit integers fail validation on this head because `EmitBdaAnchors` declares the u64 type for every program. @gjonn, please declare it only when the program has an anchor. @CnRJay's two measurements (compile time and module size with both paths in every anchored read) are still needed before this becomes the only way such reads are generated.
oneandonlydean commented 2026-10-18 03:22:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T03:22:57Z.


@gjonn this one is approved to merge and CI is green on 88642b874f, but it's still marked as a draft, so it can't be merged yet. Could you mark it ready for review when you get a chance? Please don't push new commits, or we'll need to re-run checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6245149655 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859#issuecomment-6245149655). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T03:22:57Z. --- @gjonn this one is approved to merge and CI is green on 88642b874f, but it's still marked as a draft, so it can't be merged yet. Could you mark it ready for review when you get a chance? Please don't push new commits, or we'll need to re-run checks.
gjonn commented 2026-10-18 13:10:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-18T13:10:44Z.


@EagleBearerYS thanks for catching that. Fixed in 88642b874: EmitBdaAnchors now returns before TypeScalarU64 when the program has no anchors (if (state.bdaAnchors.empty()) return; at the top, as you suggested), so programs without anchors no longer declare a 64-bit integer type.

Thanks for marking it approved, @oneandonlydean. It's out of draft now, and I won't push anything else to it.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250314301 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859#issuecomment-6250314301). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-18T13:10:44Z. --- @EagleBearerYS thanks for catching that. Fixed in 88642b874: `EmitBdaAnchors` now returns before `TypeScalarU64` when the program has no anchors (`if (state.bdaAnchors.empty()) return;` at the top, as you suggested), so programs without anchors no longer declare a 64-bit integer type. Thanks for marking it approved, @oneandonlydean. It's out of draft now, and I won't push anything else to it. AI-assisted: yes
milescoviello commented 2026-10-18 14:53:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T14:53:31Z.


A heads-up for NVIDIA: since this PR, agc_driver_bda_device hangs on an RTX 4070 Ti (driver 595.99.02, Linux). It fails 3 of 3 with vkWaitForFences graphics: Vulkan result 2, and the kernel logs Xid 109 ... CTX SWITCH TIMEOUT. 385ed71f2c, the commit before the merge, passes, and main passes on Intel ANV.

The dispatch that hangs is in RunBdaAnchorTests, but in the plain program, through get_bda_pointer and probe_bda_pointer. The new test inputs reach a case the existing lookups had: a subgroup whose invocations leave the lookup through three different returns. #7571 has the reduction and makes the lookups return once, keeping DontInline. With it, the test passes 3 of 3 on both GPUs.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251331814 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859#issuecomment-6251331814). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T14:53:31Z. --- A heads-up for NVIDIA: since this PR, `agc_driver_bda_device` hangs on an RTX 4070 Ti (driver 595.99.02, Linux). It fails 3 of 3 with `vkWaitForFences graphics: Vulkan result 2`, and the kernel logs `Xid 109 ... CTX SWITCH TIMEOUT`. 385ed71f2c, the commit before the merge, passes, and `main` passes on Intel ANV. The dispatch that hangs is in `RunBdaAnchorTests`, but in the plain program, through `get_bda_pointer` and `probe_bda_pointer`. The new test inputs reach a case the existing lookups had: a subgroup whose invocations leave the lookup through three different returns. #7571 has the reduction and makes the lookups return once, keeping `DontInline`. With it, the test passes 3 of 3 on both GPUs. AI-assisted: yes (Claude Code)
screamm commented 2026-10-18 15:54:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-18T15:54:47Z.


@gjonn

Found by cross-validation on an RTX 4070: agc_driver_bda_device now times out in vkWaitForFences (VK_TIMEOUT) on main. Bisected to d422c760c from this PR; the parent 385ed71f2 passes 3/3. Details in #7584.

Written with Claude Code assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251951896 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5859#issuecomment-6251951896). Originally posted by [screamm](https://github.com/screamm) on 2026-10-18T15:54:47Z. --- @gjonn Found by cross-validation on an RTX 4070: `agc_driver_bda_device` now times out in `vkWaitForFences` (VK_TIMEOUT) on main. Bisected to d422c760c from this PR; the parent 385ed71f2 passes 3/3. Details in #7584. Written with Claude Code assistance.
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!5859
No description provided.