fix(shader): return zero from formatted buffer loads and drop stores off the element's alignment #21971
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21971"
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-16T23:52:18Z.
What
Formatted buffer accesses (
tbuffer_load_format_*,buffer_load_format_*,tbuffer_store_format_*,buffer_store_format_*, d16 forms included) at an address off their element's alignment read and wrote the shifted bytes. For example, a 16_UINT load at+1returned bytes 1 and 2. On RDNA2 hardware such an access reads zero and drops the store.soffset+ VGPR offset + immediate) must be a multiple ofmin(element bytes, 4), where the element is the data format's element, not the instruction's component count. 8-bit elements are always aligned, 16-bit elements need an even address, and 32-bit and wider need a multiple of 4.SH_MEM_CONFIGalignment mode applies only to non-formatted ops. The measurement agrees. In one dispatch on the same driver, which runs mode UNALIGNED, a rawbuffer_load_dwordat+1reads the exact bytes whiletbuffer_load_format_x32_UINT at+1returns 0. The console runs mode DWORD (docs/dev/debt/shader.md, V# bases off a DWORD boundary), and its formatted behaviour is not measured, which the debt states.SpirvRuntimeBuffer.cppANDs the element alignment into the whole-access in-bounds condition offormatted(),genericFormattedLoadandgenericFormattedStore.The debt entry "V# bases off a DWORD boundary" said "Formatted accesses off their element's alignment throw". That is not what
maindoes: it reads the shifted bytes. The fragment replaces that sentence with the measured rule and the ISA citation, and moves the entry's atomics sentence unchanged into its own entry so both stay under 1000 characters.Measurement: AMD Radeon Graphics (Ryzen iGPU, PCI 1002:13c0), AMD Windows driver 32.0.21043.5001,
tools/hw-oraclethrough HIP, assembly target gfx1036, wave32 and wave64. Float controls on every run: IEEE 0, DX10 clamp 1, denorm32 0, denorm16 3, round32 and round16 0, FP16 overflow 0.tbuffer_store_format_x/xy/xyz/xyzwand the d16 forms on 22 formats at offsets 0-7 (1408 rows);buffer_store_format_*with the V# format on 9 formats (576 rows).Tests:
TypedBufferAlignment(wave32 and wave64) pins the load rule, d16 and DST_SEL, with 14 literal hardware rows over 7 formats.BufferFormat(00f7cb9c21),FormattedStoreUnaligned(066a8fbe30) andRuntimeFormattedStoreat base +33 (07a0189e0f). They now assert the measured behaviour.FormattedStoreUnalignedgains aligned stores so its coverage stays, andRuntimeFormattedStoreruns at bases 33 and 32.Not pinned, recorded in the debt fragment:
add_tidV#s;A side finding is also recorded there: a tbuffer load through a V# whose format field differs from the instruction's format returns zero on
main, but the hardware ignores the V# format.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, head
92074134f5onmainbc84729655.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1):TypedBufferAlignmentpasses in 3/3 runs on each GPU, andSelected GPU name=names the requested GPU. Onmainthe new test fails on both GPUs.agc_formatted_buffer_onceandagc_formatted_buffer_byte_stores. Those two could not be built here because Windows Defender quarantines their executables (Trojan:Win64/ShellCode.MKA!MTB, a heuristic detection on the generated test binaries; see BUILD.md on antivirus).mainbc84729655and on this branch, same machine, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R '<typed_buffer_alignment, formatted_store*, buffer_format, tbuffer_format_d16, gcn_buffer_format and neighbours>' -V. No newVUID-errors.was not foundVUID-check_conventions.py --base upstream/main(no[debt-length]warning),check_test_registration.pyanddebt_fold.py --checkpass.pr_overlap.pyalso reports #20251 (Remi-Bon, a refactor that converts the formatted load components in a loop) atgenericFormattedLoad, lines 699-729. That is a textual conflict with no change in behaviour: whichever lands second carries the alignment term into the loop's in-bounds condition. It could not compare eight PRs that conflict withmain. In #7642, #10193, #13928 and #13929 the changes toBufferFormat.cpponly switch the device target and check the descriptor heap, and do not touch the subword rows changed here. InSpirvRuntimeBuffer.cpp, #6412, #7689 and #18515 do not change the formatted alignment. #20248's opt-in native descriptor tables add table arguments to thereadBuffercalls of the formatted path and carry their own base misalignment. If both PRs land, that table path also needs the element alignment in its in-bounds condition.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-18T02:36:53Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation has no verified blocking defect, but this review is incomplete because I could not run checks or read every changed file in full.
What I ran
Reviewed head
ed03eeb45198f3789def9724f939e2110114c00eusing the prepared diff andrepo_read.py. No commands or tests were run. The author reports Windows 11, GCC 15.2.0, Vulkan validation, and repository checks in the PR description; those results were not independently verified.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
I read
review/description.md,review/commits.md,review/manifest.json, andreview/diff.patch. From changed files, I read all ofTypedBufferAlignment.cppandRuntimeFormattedStore.cpp, plus selected ranges ofSpirvRuntimeBuffer.cpp. I did not read the full text ofBufferFormat.cpp,FormattedStoreUnaligned.cpp,ShaderDiskCache.hpp, or the debt change file, and did not inspect the unread portions ofSpirvRuntimeBuffer.cpp. No build, tests, or validation were run.To get this to a good state
Nothing is required. The implementation and tests inspected support the stated behavior; the uninspected files and checks remain unverified.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T16:56:39Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
4a58e4068ad10aff44977bd6e751a305e07f3bbeagainst the prepared diff. I did not run tests or build commands. The description reports hardware, validation-layer, and repository checks; those are author-reported results.Results
Findings
Blocking
None.
Non-blocking
docs/dev/debt/changes/fix-shader-typed-16bit-buffer-alignment.md:15.Not verified
Tests, builds, physical-console formatted behavior, and the claimed hardware and validation-layer runs were not independently verified. The prepared diff excluded no changed files; all files marked
includedin the manifest were read. Nofiles.jsonartifact was available.To get this to a good state
Nothing is required. Optional: add execution coverage for the unpinned paths and formats noted in the debt entry.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:05:56Z.
Review: COMMENTED
Reviewed — no blocking findings
The alignment checks use the format element size capped at four bytes and include the descriptor base in the effective address; the reviewed paths match the stated rule.
What I ran
Reviewed head
89ca848c01b571c102cb3d56d8eee13b36edc268. No commands or tests were run;repo_read.pywas used to inspect the prepared diff and source ranges.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
All seven changed files listed as reviewed in the manifest were read at least in part:
BufferFormat.cpp,FormattedStoreUnaligned.cpp,RuntimeFormattedStore.cpp,TypedBufferAlignment.cpp,ShaderDiskCache.hpp,SpirvRuntimeBuffer.cpp, andfix-shader-typed-16bit-buffer-alignment.md. The new test’s full source and the full text of the other changed files were not all read; its registration and execution, uninspected code, and author-reported hardware and CI results were not independently verified.files.jsonwas unavailable, so exclusions could not be checked.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T09:38:25Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the focused code paths and changed files reviewed support the alignment behavior described.
What I ran
Reviewed head
5f84c9823164ede24f5953b737c25929ee3d3828from the prepared diff and pinned repository readerrepo_read.py. I did not run commands or tests; reported test results below are author supplied.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
The implementation checks alignment against
min(element bytes, 4)in constant-format loads/stores and runtime-format loads/stores. The new execution test exercises formats, offsets, structured and raw descriptors, d16 loads, DST_SEL, and wave32/wave64. The shader disk cache format version is incremented alongside the behavior change.Not verified
I did not execute tests, inspect hardware measurements, or verify the author-reported environment and test output. The review folder listed all seven changed files as included, and I read each changed file. The reader does not provide a separate
files.json; the manifest shows no excluded changed files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:13:44Z.
Review: COMMENTED
The trial merge onto
a1b75b0947conflicts inShaderDiskCache.hpp. Please assign the cache schema from the merged shader semantics and keep the execution matrix for static and dynamic formats. The change removes the alignment restriction for byte-width elements. The existing 16- and 32-bit controls should continue to exercise their separate width rules on the merged head.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T16:14:58Z.
Review: COMMENTED
Actionable comments
094bf4dd-d584-4f37-b160-50af11e09c30Reviewing files that changed from the base of the PR and between
2fbf8b4391and3a8b5ee999.core/libs/prx/libSceAgcDriver/tests/execution/BufferFormat.cppcore/libs/prx/libSceAgcDriver/tests/execution/FormattedStoreUnaligned.cppcore/libs/prx/libSceAgcDriver/tests/execution/RuntimeFormattedStore.cppcore/libs/prx/libSceAgcDriver/tests/execution/TypedBufferAlignment.cppcore/shader/recompiler/ShaderDiskCache.hppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppdocs/dev/debt/changes/fix-shader-typed-16bit-buffer-alignment.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T16:48:13Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
dc4f1fb0aef0a931a1bfc060666f40786c5608b6againstmainusing the prepared diff and head files. No tests, builds, or merged-preview checks were run. The author-reported test results were not independently verified.Read the changed hunks and relevant code in all eight files listed under
reviewedinfiles.json. No files were excluded.Results
Negative control
Not run; no tests were executed.
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:633,:749).Sources
Not verified
To get this to a good state
Nothing is required.
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.