feat(agc): run BDA byte access without storageBuffer8BitAccess #16571
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16571"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.6tu_device.cc), so an Adreno 650 (Quest 2, many phones) stopped at device creation withlacks 2 items AnyPS5 needs: VK_KHR_8bit_storage (extension), storageBuffer8BitAccess (feature).SpirvBdaRead.cpp): when the target lacksStorageBuffer8BitAccess, 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 throughbyteBuffers()). Byte loads, anchored 8/16-bit reads and thewrite_bda_bytesfunctions all go through the two new helpers. With the capability present the emitted code is unchanged, except thatStorageBuffer8BitAccessandSPV_KHR_8bit_storageare now declared where a byte pointer is made instead of for every DMA program.ValidateBdaTargetno longer requires the 8-bit capability or extension.QueryBdaByteFeaturesreports the feature instead of throwing;VulkanDeviceenables the extension, chains the feature struct and advertises capability 4448 /SPV_KHR_8bit_storageonly when the device has it.ShaderDeviceProfiletreats the capability like the other optional ones (advertised only if enabled, and thenSPV_KHR_8bit_storagemust be listed). The host report listsVK_KHR_8bit_storageas optional, and USAGE.md drops it from the required list.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 oneLoadPhysicalBytecall). 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_devicenow 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.BdaContractschecks that byte accesses declare 8-bit storage only on a target that has it, thatValidateBdaTargetaccepts a target without it, and that the CAS byte store is still seen bySpirvStoresThroughAddresses. The fallback store shaders passValidateAndOptimizeSpirv.agc_shader_device_profileprofiles a device without the feature;agc_host_report_vulkanexpects it as optional.maind7240ef952vs 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, 0VUID-lines, nowas not found but was requested by env var VK_INSTANCE_LAYERSline. A best-practices control onagc_driver_bda_devicewrote 15 layer log lines on each side, so the layer was loaded.main2e48261498(mergec52bc51945; the only conflict wasdocs/dev/debt/shader.md, both sides' entries kept), the A/B was rerun onmain2e48261498vsc52bc51945with 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, 0VUID-lines on either side, no missing-layer line, and the branch logs show bothBDA store boundary tests passed with 8-bit pointersand... with 32-bit word byte accesson each GPU. A best-practices control wrote 24 layer log lines on each side.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T01:42:36Z.
Review: COMMENTED
Ran
22ae5d725dmerged onmain302864d48con Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 610) and an Intel iGPU (driver 101.70xx), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_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.mainmain+ the PR's test files onlyagc_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") andagc_shader_device_profile("shader runtime requires enabled storageBuffer8BitAccess").storageBuffer8BitAccess, so the device itself never takes the new path.agc_driver_bda_devicestill 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".agc_bda_atomics,agc_driver_bda_device_selection_cpu,agc_host_report_vulkanandagc_shader_device_profileopen none). No log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has aVUID-: 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 28BestPractices-warnings into anagc_driver_recorderlog on each GPU.Not covered here: a device that really lacks
storageBuffer8BitAccess, whereVulkanDeviceno longer enables the extension or chainsbyteFeatures; both GPUs here report the feature.AI-assisted: yes.
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
c52bc51945abbb4ed289636d8c78000cf9cc19b2usingrepo_read.pyto inspect the prepared diff and targeted source context. No commands or tests were run.Results
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 containingu32. BDA ranges can be exact-sized copied buffers; the reader-side table construction preservesregion.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
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppwas excluded from the review folder due to size; the relevant changed areas were read throughrepo_read.py.core/libs/prx/libSceAgcDriver/Execution/src/BdaFeatures.cpp,HostReportVulkan.cpp,ShaderDeviceProfile.cpp; testsBdaContracts.cpp,BdaDevice.cpp,BdaShader.cpp,BdaShader.hpp,HostReportVulkan.cpp,ShaderDeviceProfile.cpp;core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp,SpirvMemory/SpirvEmitterHelpers.cpp; anddocs/dev/debt/shader.md,docs/user/USAGE.mdwere read in relevant ranges. Other portions of these files were not read.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.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:37:24Z.
Review: COMMENTED
The trial merge onto
c1601e56d5conflicts inSpirvBdaRead.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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.