fix(shader): bound structured buffer accesses by their size #21924
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21924"
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 AlfaRojo on 2026-11-16T21:50:00Z.
What
A structured V# (
OOB_SELECT0, nonzero stride) accepted any access whose first byte was below the stride, so a dword at offsetstride - 3or a ushort atstride - 1read or wrote bytes of the next record. Measured on RDNA2, the whole access has to fit in the record: an access is in range only whenindex < NUM_RECORDSandoffset + size <= stride, checked per dword of a vector access. Otherwise loads return 0 and stores are dropped, and a partial access is never split.This PR changes only the
OOB_SELECT0 term inSpirvRuntimeBuffer.cpptooffset + size <= stride.OOB_SELECT1, 2 and 3 and raw buffers are unchanged. The rule applies to every access that goes through that range check: byte, short, dword and multi-dword loads and stores, typed (tbuffer) and d16 forms, and atomics.Measurement: AMD Radeon Graphics (Ryzen iGPU, PCI 1002:13c0), AMD Windows driver 32.0.21043.5001,
tools/hw-oraclethrough HIP, assembly target gfx1036, wave32. Float controls on every run: IEEE 0, DX10 clamp 1, denorm32 0, denorm16 3, round32 and round16 0, FP16 overflow 0. V# word 30x01016fac.buffer_load_ubyte/ byte storebuffer_load_ushort/ short storebuffer_load_dwordbuffer_load_dwordx2,dwordx4tbuffer8_UINTStrides 6, 8, 10 and 14 follow the same rule (a dword at stride 6 is in range only at offsets 0 to 2). Atomics also follow it: a dword
buffer_atomic_addat stride 18 applies at offset 12 and is dropped at 16;buffer_atomic_add_x2at stride 20 applies at offset 8 and is dropped at 16.The new execution test
BufferStructuredStride(wave32 and wave64) checks ubyte and dword loads and byte and short stores at strides 6, 10 and 16 against the rule, which matches all 588 measured rows.RuntimeBufferSpansexpected a dword at offset 4 of a 6-byte stride to be in range; the hardware returns 0 there, so that expectation changes.Alignment mode. These rows come from the AMD Windows driver, which runs alignment mode UNALIGNED (an unaligned
buffer_load_dwordreads the exact bytes there). The console runs mode DWORD (docs/dev/debt/shader.md, V# bases off a DWORD boundary, measured on a PS5). Aligned accesses do not depend on the mode; for an unaligned dword near the end of a record DWORD mode may align the address before the range check, so that case is recorded in the debt fragment as unmeasured on the console.The swizzled V# layout (word 1 bit 31) is not changed here. An earlier debt entry for it was dropped in
62b61dea7d: its odd values came from a source buffer whose bytes did not identify themselves, not from the address rule. gfx1013 itself is not measured.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, head
6faf7ec8c9(code at147d891e09) onmainbca2d36814.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:BufferStructuredStridepasses in 3/3 runs on each GPU;Selected GPU name=names the requested GPU. With the fix reverted it fails on both GPUs (16 mismatches each). With the test copied ontomainit fails on both GPUs.ctest -R 'buffer|mubuf|mtbuf'(AGC tests): 63/63 pass on both GPUs.agc_formatted_buffer_onceandagc_formatted_buffer_byte_storescould not be built here: Windows Defender quarantines their executables (Trojan:Win64/ShellCode.MKA!MTB, a heuristic detection on the generated test binaries; see BUILD.md on antivirus).mainbca2d36814and on this branch, same machine:ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R '<runtime buffer spans, buffer load/store and buffer execution tests>' -Vwas not foundVUID-The new test, run separately on the branch, passes on both GPUs with the layer and no
VUID-. No newVUID-errors.check_conventions.py --base upstream/main,check_test_registration.pyanddebt_fold.py --checkpass.pr_overlap.pycould not compare nine PRs that conflict withmainand touchSpirvRuntimeBuffer.cpp. I read their hunks: #6412 and #7689 (deferred V# type checks), #7642, #10193, #13928 and #13929 (image and sampler tables), #14217 (GLC/DLC synchronization), #18515 (profiling draft) and #20248 (native buffer descriptor tables, reads the stride into its own table) do not change the structured range rule.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:20:47Z.
Review: APPROVED
Reviewed — looks good
The change at
e0d28e66654ef220346785c63d98e8eec5cee5b1applies full-access bounds to structured buffer accesses; the implementation and the focused test logic I read are consistent with that goal. Nothing blocks this; the points below are optional.What I ran
No build or tests were run in this review. I read the prepared diff and the changed files at the pinned head through
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read all five files listed as reviewed in
manifest.json:BufferStructuredStride.cpp,RuntimeBufferSpans.cpp,ShaderDiskCache.hpp,SpirvRuntimeBuffer.cpp, andfix-shader-structured-buffer-stride-range.md. No files were excluded byfiles.jsonin the material returned. I did not run the reported tests, verify the hardware measurements, inspect behavior on PS5 hardware, or verify additional callers beyond the targeted search ofbyteAddressandaddress.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T15:44:18Z.
Review: APPROVED
Reviewed — looks good
The change applies the whole-access bounds check to structured accesses, and I found no blocking defects in the changed files.
What I ran
Reviewed head
1e4737b0e8dc66e7f60f461368b8f60a376c83dcusingrepo_read.pyfor the prepared diff and changed files. No tests or builds were run in this review; the test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed
SpirvRuntimeBuffer.cpp,BufferStructuredStride.cpp,RuntimeBufferSpans.cpp,ShaderDiskCache.hpp, and the new debt entry at the pinned head.Not verified
Build and test results were not independently verified. The PR notes that unaligned dword behavior on the PS5 console remains unmeasured.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T19:51:36Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reported hardware measurements and test runs support the new structured access bound, with console behavior for certain unaligned accesses still unverified.
What I ran
Reviewed head
3f62cd19161cc60938b6572c8c26462db74afa01using the prepared diff and pinned repository reader. No tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Console behavior for unaligned dword accesses near a structured record boundary remains unmeasured, as documented by the PR. Build and test results were reported by the author and were not independently run. Read:
BufferStructuredStride.cpp,RuntimeBufferSpans.cpp,ShaderDiskCache.hpp,SpirvRuntimeBuffer.cpp, andfix-shader-structured-buffer-stride-range.md. No changed files were excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T00:10:03Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review supports merging.
What I ran
Reviewed head
6afebbfdc244a43c2625b8dc44797fdaae2901b6against the prepared diff and inspected relevant source withrepo_read.py. No build, tests, or negative control were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The changed files marked
reviewedinfiles.jsonwere read;files.jsonlists no excluded files. Hardware behavior, console behavior, and the author-reported test results were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:02:17Z.
Review: APPROVED
I read the diff at
6afebbfdc2. Windows 11, GCC 15.2, merged intomainat6c6b29320fetogether with other open PRs (so not an isolated build), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationon an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).agc_driver_buffer_structured_strideand theagc_driver_runtime_buffer_spans_*tests: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has aVUID-orSYNC-HAZARDline.Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:13:50Z.
Review: COMMENTED
The trial merge onto
a1b75b0947was clean. I checked that the structured bound combines the record index check with an access-width check against stride. The fixture varies access width, immediate offset, and wave size. Please keep the debt entry’s distinction between measured RDNA2 unaligned accesses and console dword-alignment order, which remains unmeasured near the end of a record. Paired runtime-buffer validation is pending.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.