feat(agc): run BDA byte access without storageBuffer8BitAccess #16571

Open
ycbuzi wants to merge 5 commits from upstream-pr/16571 into main
ycbuzi commented 2026-11-07 05:48:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-11-07T05:48:11Z.


What

Lets the AGC driver run on a Vulkan device without VK_KHR_8bit_storage / storageBuffer8BitAccess. Turnip exposes the feature only on Adreno 7xx (Mesa 25.0.7 and 25.3.6 tu_device.cc), so an Adreno 650 (Quest 2, many phones) stopped at device creation with lacks 2 items AnyPS5 needs: VK_KHR_8bit_storage (extension), storageBuffer8BitAccess (feature).

  • Shader recompiler, BDA path (SpirvBdaRead.cpp): when the target lacks StorageBuffer8BitAccess, a byte load reads the aligned 32-bit word that holds the byte and shifts it out, and a byte store is a 32-bit compare-and-swap that replaces only that byte (AtomicUpdate, the same loop the non-BDA path already uses through byteBuffers()). Byte loads, anchored 8/16-bit reads and the write_bda_bytes functions all go through the two new helpers. With the capability present the emitted code is unchanged, except that StorageBuffer8BitAccess and SPV_KHR_8bit_storage are now declared where a byte pointer is made instead of for every DMA program.
  • ValidateBdaTarget no longer requires the 8-bit capability or extension.
  • Device: QueryBdaByteFeatures reports the feature instead of throwing; VulkanDevice enables the extension, chains the feature struct and advertises capability 4448 / SPV_KHR_8bit_storage only when the device has it. ShaderDeviceProfile treats the capability like the other optional ones (advertised only if enabled, and then SPV_KHR_8bit_storage must be listed). The host report lists VK_KHR_8bit_storage as optional, and USAGE.md drops it from the required list.
  • The fallback touches the three neighbouring bytes of the word, so it relies on BDA host ranges being whole aligned dwords, as guest buffer chunks are. That is recorded in docs/dev/debt/shader.md, together with the unmeasured speed of the atomic byte stores.

Related: #4847 skips adapters without 8-bit storage during selection; after this PR that feature is no longer a reason to skip one.

Overlap: #7392 changes the fault condition at the top of EmitBdaByte (the lines this PR replaces with one LoadPhysicalByte call). The two changes are independent: whichever lands second keeps the other's condition around the single load call, a small rebase.

Tested

Windows 11 Home 26200, MinGW g++ 15.2.0, agc_driver_bda_device, agc_host_report_vulkan, agc_shader_device_profile:

  • agc_driver_bda_device now runs every BDA GPU read, span, anchored and store/write boundary case twice: with 8-bit pointers and with the 32-bit word fallback (SetBdaTestBytePointers). Both pass on all three GPUs (BDA store boundary tests passed with 8-bit pointers / ... with 32-bit word byte access). The store cases use 2- and 3-byte buffers and check that bytes outside the mapped span are unchanged.
  • BdaContracts checks that byte accesses declare 8-bit storage only on a target that has it, that ValidateBdaTarget accepts a target without it, and that the CAS byte store is still seen by SpirvStoresThroughAddresses. The fallback store shaders pass ValidateAndOptimizeSpirv.
  • agc_shader_device_profile profiles a device without the feature; agc_host_report_vulkan expects it as optional.
  • Validation layer A/B, main d7240ef952 vs this branch (6caa78853e; the two later commits change only docs), Vulkan SDK 1.4.363.0 Khronos layer from a non-elevated process, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R '^(agc_driver_bda_device|agc_host_report_vulkan|agc_shader_device_profile)$' -V, two runs per GPU per side: 3/3 passed in every run, 0 VUID- lines, no was not found but was requested by env var VK_INSTANCE_LAYERS line. A best-practices control on agc_driver_bda_device wrote 15 layer log lines on each side, so the layer was loaded.
  • After merging main 2e48261498 (merge c52bc51945; the only conflict was docs/dev/debt/shader.md, both sides' entries kept), the A/B was rerun on main 2e48261498 vs c52bc51945 with the same layer and variables, ctest -R '^agc_(driver_bda_device.*|driver_host_import_failure_handles|host_report_vulkan|shader_device_profile)$' -V, one run per GPU per side on the RTX 4070 SUPER, GTX 1650 SUPER and Radeon iGPU: 5/5 passed in every run, 0 VUID- lines on either side, no missing-layer line, and the branch logs show both BDA store boundary tests passed with 8-bit pointers and ... with 32-bit word byte access on each GPU. A best-practices control wrote 24 layer log lines on each side.
  • Not tested yet: an Adreno 650 under Turnip itself. A Linux build of this branch for that device is in progress.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 SUPER and NVIDIA GeForce GTX 1650 SUPER (driver 616.92 / 32.0.16.1692), AMD Radeon(TM) Graphics iGPU, Ryzen 9 7900 (driver 32.0.21030.2001), Windows 11 Home 26200
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5198881873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16571). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-11-07T05:48:11Z. --- ### What Lets the AGC driver run on a Vulkan device without `VK_KHR_8bit_storage` / `storageBuffer8BitAccess`. Turnip exposes the feature only on Adreno 7xx (Mesa 25.0.7 and 25.3.6 `tu_device.cc`), so an Adreno 650 (Quest 2, many phones) stopped at device creation with `lacks 2 items AnyPS5 needs: VK_KHR_8bit_storage (extension), storageBuffer8BitAccess (feature)`. - Shader recompiler, BDA path (`SpirvBdaRead.cpp`): when the target lacks `StorageBuffer8BitAccess`, a byte load reads the aligned 32-bit word that holds the byte and shifts it out, and a byte store is a 32-bit compare-and-swap that replaces only that byte (`AtomicUpdate`, the same loop the non-BDA path already uses through `byteBuffers()`). Byte loads, anchored 8/16-bit reads and the `write_bda_bytes` functions all go through the two new helpers. With the capability present the emitted code is unchanged, except that `StorageBuffer8BitAccess` and `SPV_KHR_8bit_storage` are now declared where a byte pointer is made instead of for every DMA program. - `ValidateBdaTarget` no longer requires the 8-bit capability or extension. - Device: `QueryBdaByteFeatures` reports the feature instead of throwing; `VulkanDevice` enables the extension, chains the feature struct and advertises capability 4448 / `SPV_KHR_8bit_storage` only when the device has it. `ShaderDeviceProfile` treats the capability like the other optional ones (advertised only if enabled, and then `SPV_KHR_8bit_storage` must be listed). The host report lists `VK_KHR_8bit_storage` as optional, and USAGE.md drops it from the required list. - The fallback touches the three neighbouring bytes of the word, so it relies on BDA host ranges being whole aligned dwords, as guest buffer chunks are. That is recorded in `docs/dev/debt/shader.md`, together with the unmeasured speed of the atomic byte stores. Related: #4847 skips adapters without 8-bit storage during selection; after this PR that feature is no longer a reason to skip one. Overlap: #7392 changes the fault condition at the top of `EmitBdaByte` (the lines this PR replaces with one `LoadPhysicalByte` call). The two changes are independent: whichever lands second keeps the other's condition around the single load call, a small rebase. ### Tested Windows 11 Home 26200, MinGW g++ 15.2.0, `agc_driver_bda_device`, `agc_host_report_vulkan`, `agc_shader_device_profile`: - `agc_driver_bda_device` now runs every BDA GPU read, span, anchored and store/write boundary case twice: with 8-bit pointers and with the 32-bit word fallback (`SetBdaTestBytePointers`). Both pass on all three GPUs (`BDA store boundary tests passed with 8-bit pointers` / `... with 32-bit word byte access`). The store cases use 2- and 3-byte buffers and check that bytes outside the mapped span are unchanged. - `BdaContracts` checks that byte accesses declare 8-bit storage only on a target that has it, that `ValidateBdaTarget` accepts a target without it, and that the CAS byte store is still seen by `SpirvStoresThroughAddresses`. The fallback store shaders pass `ValidateAndOptimizeSpirv`. - `agc_shader_device_profile` profiles a device without the feature; `agc_host_report_vulkan` expects it as optional. - Validation layer A/B, `main` d7240ef9524 vs this branch (6caa78853e8; the two later commits change only docs), Vulkan SDK 1.4.363.0 Khronos layer from a non-elevated process, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest -R '^(agc_driver_bda_device|agc_host_report_vulkan|agc_shader_device_profile)$' -V`, two runs per GPU per side: 3/3 passed in every run, 0 `VUID-` lines, no `was not found but was requested by env var VK_INSTANCE_LAYERS` line. A best-practices control on `agc_driver_bda_device` wrote 15 layer log lines on each side, so the layer was loaded. - After merging `main` 2e48261498a (merge c52bc51945a; the only conflict was `docs/dev/debt/shader.md`, both sides' entries kept), the A/B was rerun on `main` 2e48261498a vs c52bc51945a with the same layer and variables, `ctest -R '^agc_(driver_bda_device.*|driver_host_import_failure_handles|host_report_vulkan|shader_device_profile)$' -V`, one run per GPU per side on the RTX 4070 SUPER, GTX 1650 SUPER and Radeon iGPU: 5/5 passed in every run, 0 `VUID-` lines on either side, no missing-layer line, and the branch logs show both `BDA store boundary tests passed with 8-bit pointers` and `... with 32-bit word byte access` on each GPU. A best-practices control wrote 24 layer log lines on each side. - Not tested yet: an Adreno 650 under Turnip itself. A Linux build of this branch for that device is in progress. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 SUPER and NVIDIA GeForce GTX 1650 SUPER (driver 616.92 / 32.0.16.1692), AMD Radeon(TM) Graphics iGPU, Ryzen 9 7900 (driver 32.0.21030.2001), Windows 11 Home 26200 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabichuuuuu commented 2026-11-08 01:42:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T01:42:36Z.

Review: COMMENTED


Ran 22ae5d725d merged on main 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 610) and an Intel iGPU (driver 101.70xx), with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Khronos validation layer 1.4.368), ctest -R '^(agc_driver_bda|agc_bda|agc_host_report_vulkan|agc_shader_device_profile)' -V.

main main + the PR's test files only change
NVIDIA 11/11 8/11 11/11, twice
Intel 11/11 8/11 11/11, twice
  • Without the driver and recompiler changes, the PR's tests fail on both GPUs: agc_driver_bda_device ("BDA requires unsupported SPIR-V capability 4448"), agc_host_report_vulkan ("the absent 8-bit storage extension is not listed as optional and missing") and agc_shader_device_profile ("shader runtime requires enabled storageBuffer8BitAccess").
  • Both GPUs here have storageBuffer8BitAccess, so the device itself never takes the new path. agc_driver_bda_device still runs the BDA read and store execution tests on each real device twice, and both runs pass on both GPUs: "BDA store boundary tests passed with 8-bit pointers" and "BDA store boundary tests passed with 32-bit word byte access".
  • The layer was inserted in every test that opens a Vulkan device (agc_bda_atomics, agc_driver_bda_device_selection_cpu, agc_host_report_vulkan and agc_shader_device_profile open none). No log has was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has a VUID-: the 32-bit word loads compile to SPIR-V the layer accepts. To be sure validation messages reach these logs, the same layer with best practices on printed 28 BestPractices- warnings into an agc_driver_recorder log on each GPU.

Not covered here: a device that really lacks storageBuffer8BitAccess, where VulkanDevice no longer enables the extension or chains byteFeatures; both GPUs here report the feature.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815979836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16571#pullrequestreview-5815979836). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T01:42:36Z. **Review:** COMMENTED --- Ran `22ae5d725d` merged on `main` 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 610) and an Intel iGPU (driver 101.70xx), with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Khronos validation layer 1.4.368), `ctest -R '^(agc_driver_bda|agc_bda|agc_host_report_vulkan|agc_shader_device_profile)' -V`. | | `main` | `main` + the PR's test files only | change | |---|---|---|---| | NVIDIA | 11/11 | 8/11 | 11/11, twice | | Intel | 11/11 | 8/11 | 11/11, twice | - Without the driver and recompiler changes, the PR's tests fail on both GPUs: `agc_driver_bda_device` ("BDA requires unsupported SPIR-V capability 4448"), `agc_host_report_vulkan` ("the absent 8-bit storage extension is not listed as optional and missing") and `agc_shader_device_profile` ("shader runtime requires enabled storageBuffer8BitAccess"). - Both GPUs here have `storageBuffer8BitAccess`, so the device itself never takes the new path. `agc_driver_bda_device` still runs the BDA read and store execution tests on each real device twice, and both runs pass on both GPUs: "BDA store boundary tests passed with 8-bit pointers" and "BDA store boundary tests passed with 32-bit word byte access". - The layer was inserted in every test that opens a Vulkan device (`agc_bda_atomics`, `agc_driver_bda_device_selection_cpu`, `agc_host_report_vulkan` and `agc_shader_device_profile` open none). No log has `was not found but was requested by env var VK_INSTANCE_LAYERS`, and no log on either side has a `VUID-`: the 32-bit word loads compile to SPIR-V the layer accepts. To be sure validation messages reach these logs, the same layer with best practices on printed 28 `BestPractices-` warnings into an `agc_driver_recorder` log on each GPU. Not covered here: a device that really lacks `storageBuffer8BitAccess`, where `VulkanDevice` no longer enables the extension or chains `byteFeatures`; both GPUs here report the feature. AI-assisted: yes.
MarcZX10 commented 2026-11-21 05:05:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:05:14Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: make the word fallback safe when a mapped BDA range ends inside a 32-bit word.

What I ran

Reviewed head c52bc51945abbb4ed289636d8c78000cf9cc19b2 using repo_read.py to inspect the prepared diff and targeted source context. No commands or tests were run.

Results

Check Result Note
Diff and targeted source review passed BDA access paths and range construction reviewed
Tests not run Author-reported tests were not rerun

Findings

Blocking

  • core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp:68-70,158-162: The fallback rounds the physical byte address down and reads or atomically updates the full containing u32. BDA ranges can be exact-sized copied buffers; the reader-side table construction preserves region.begin/region.end, and the buffer allocation uses that exact region size. A byte access in the last one to three bytes of a range can therefore make the shader touch bytes beyond the mapped range and Vulkan buffer. The debt note records an alignment assumption, but the range construction inspected here does not enforce dword-sized range boundaries. Ensure fallback accesses are contained within the mapped allocation (for example, by padding and mapping edge words or using a safe edge path), and add coverage for reads and writes at a range tail.

Non-blocking

None.

Not verified

  • The full text of core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp was excluded from the review folder due to size; the relevant changed areas were read through repo_read.py.
  • core/libs/prx/libSceAgcDriver/Execution/src/BdaFeatures.cpp, HostReportVulkan.cpp, ShaderDeviceProfile.cpp; tests BdaContracts.cpp, BdaDevice.cpp, BdaShader.cpp, BdaShader.hpp, HostReportVulkan.cpp, ShaderDeviceProfile.cpp; core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp, SpirvMemory/SpirvEmitterHelpers.cpp; and docs/dev/debt/shader.md, docs/user/USAGE.md were read in relevant ranges. Other portions of these files were not read.
  • Adreno 650 / Turnip behavior and the author-reported GPU test runs were not independently verified.

To get this to a good state

Make the fallback safe at BDA range edges, then rerun the BDA contract and device tests, including byte reads and writes at the final bytes of a mapped range.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002972856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16571#pullrequestreview-6002972856). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T05:05:14Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: make the word fallback safe when a mapped BDA range ends inside a 32-bit word. ## What I ran Reviewed head `c52bc51945abbb4ed289636d8c78000cf9cc19b2` using `repo_read.py` to inspect the prepared diff and targeted source context. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | BDA access paths and range construction reviewed | | Tests | not run | Author-reported tests were not rerun | ## Findings ### Blocking - `core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp:68-70,158-162`: The fallback rounds the physical byte address down and reads or atomically updates the full containing `u32`. BDA ranges can be exact-sized copied buffers; the reader-side table construction preserves `region.begin`/`region.end`, and the buffer allocation uses that exact region size. A byte access in the last one to three bytes of a range can therefore make the shader touch bytes beyond the mapped range and Vulkan buffer. The debt note records an alignment assumption, but the range construction inspected here does not enforce dword-sized range boundaries. Ensure fallback accesses are contained within the mapped allocation (for example, by padding and mapping edge words or using a safe edge path), and add coverage for reads and writes at a range tail. ### Non-blocking None. ## Not verified - The full text of `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` was excluded from the review folder due to size; the relevant changed areas were read through `repo_read.py`. - `core/libs/prx/libSceAgcDriver/Execution/src/BdaFeatures.cpp`, `HostReportVulkan.cpp`, `ShaderDeviceProfile.cpp`; tests `BdaContracts.cpp`, `BdaDevice.cpp`, `BdaShader.cpp`, `BdaShader.hpp`, `HostReportVulkan.cpp`, `ShaderDeviceProfile.cpp`; `core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp`, `SpirvMemory/SpirvEmitterHelpers.cpp`; and `docs/dev/debt/shader.md`, `docs/user/USAGE.md` were read in relevant ranges. Other portions of these files were not read. - Adreno 650 / Turnip behavior and the author-reported GPU test runs were not independently verified. ## To get this to a good state Make the fallback safe at BDA range edges, then rerun the BDA contract and device tests, including byte reads and writes at the final bytes of a mapped range.
ligmaSec commented 2026-12-03 22:37:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:37:24Z.

Review: COMMENTED


The trial merge onto c1601e56d5 conflicts in SpirvBdaRead.cpp. Please retain logical byte-range validation ahead of the aligned-word fallback and the fixture that checks a byte write leaves neighboring bytes unchanged. The disabled-8-bit-storage profile should also verify capability emission, so a supported GPU does not mask an extension requirement on the fallback path. Move the direct shader debt edit into a fragment on the resolved head.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179839636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16571#pullrequestreview-6179839636). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:37:24Z. **Review:** COMMENTED --- The trial merge onto `c1601e56d5` conflicts in `SpirvBdaRead.cpp`. Please retain logical byte-range validation ahead of the aligned-word fallback and the fixture that checks a byte write leaves neighboring bytes unchanged. The disabled-8-bit-storage profile should also verify capability emission, so a supported GPU does not mask an extension requirement on the fallback path. Move the direct shader debt edit into a fragment on the resolved head. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/16571:upstream-pr/16571'
git switch 'upstream-pr/16571'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/16571'
git switch 'upstream-pr/16571'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/16571'
git switch 'upstream-pr/16571'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/16571'
git switch 'main'
git merge --squash 'upstream-pr/16571'
git switch 'main'
git merge --ff-only 'upstream-pr/16571'
git switch 'main'
git merge 'upstream-pr/16571'
git push origin 'main'
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!16571
No description provided.