fix(shader): address swizzled buffers like RDNA2 #21970
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21970"
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:44:38Z.
What
The recompiler's swizzled buffer addressing (V# word 1 bit 31 with a nonzero stride) differed from RDNA2 hardware in three ways:
QA found a fourth case in the formatted-load path:
buffer_load_format_xwith OFFEN only and bit 31 set was still swizzled, because the specialization-constant branch rebuilt the swizzle from the stride and bit 31 alone. That case is fixed too.Measured rule, which reproduces every row (about 12,000 single-dword and 4,600 multi-dword rows, wave32 and wave64):
step = 8 << INDEX_STRIDEaddress = ((index / step) * stride + (offset & ~3)) * step + (index % step) * 4 + (offset & 3) + soffset, whereoffsetis the VGPR offset plus the instruction offsetELEMENT_SIZEhas no effect; the element is 4 bytesoffset + 4kMeasurement: AMD Radeon Graphics (Ryzen iGPU, PCI 1002:13c0), AMD Windows driver 32.0.21043.5001,
tools/hw-oraclethrough HIP, assembly target gfx1036. Float controls on every run: IEEE 0, DX10 clamp 1, denorm32 0, denorm16 3, round32 and round16 0, FP16 overflow 0. The source buffer holds a distinct value in every byte, so each result identifies the byte it came from. The address rule is set by the buffer swizzle fields, not by the alignment mode. The driver here runs alignment mode UNALIGNED and the console runs DWORD (docs/dev/debt/shader.md, V# bases off a DWORD boundary), so the(offset & 3)term of an unaligned access is measured only in UNALIGNED mode.The new execution test
BufferSwizzledAddress(wave32 and wave64) checks the measured formula. Its load expectations were compared directly with the hardware in 88 cases. Its store expectations rest on single-lane hardware measurements, because multi-lane stores overlap. Theswizzledcase inRuntimeBufferSpansexpected an index-0 swizzle ofoffset * 8, which was a model, not a measurement; the hardware addresses that access linearly. The case is renamed "swizzle bit without index" and now expects the linear access.Not fixed, recorded in the debt fragment: in 38 of 256 measured bound cases (
NUM_RECORDS4 or 16, stride 16), the hardware returns data where the recompiler returns 0. The recompiler's range test passes in those cases, but the bound storage buffer ends atNUM_RECORDS * stride, before the address the hardware reads. Two things cause this: a swizzled index group spans8 << INDEX_STRIDErecords, and a linear V# withOOB_SELECT2 or 3 does not compare the index withNUM_RECORDS.tbuffer_*, typed stores, atomics, SOFFSET, graphics stages and gfx1013 are not measured.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, head
507ee5621aonmainbc84729655.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:BufferSwizzledAddressandRuntimeBufferSpanspass in 3/3 runs on each GPU;Selected GPU name=names the requested GPU. The new test fails onmainon both GPUs. Without the formatted-load fix, the fourbuffer_load_format_xcases fail.mainbc84729655and 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 '<buffer tests>' -V:was not foundVUID-No new
VUID-errors.agc_formatted_buffer_onceandagc_formatted_buffer_byte_storescould 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).check_conventions.py --base upstream/main,check_test_registration.pyanddebt_fold.py --checkpass.RuntimeBufferSpans.cpp, the in-bounds model. The resolution keeps #21924'soffset + 4u <= strideand this PR's removal of the swizzle clause.SpirvRuntimeBuffer.cppmerges cleanly, and swizzled accesses passoffset + tailto the per-dword range check, so the two rules compose. #21925 merges cleanly.pr_overlap.pyalso reports #16415 (raw dword alignment for the console's DWORD mode) atSpirvRuntimeBuffer.cpplines 196-197. Those are textual neighbours: #16415 addsAlignsRawDwordAddressafterdescriptorand masks the final byte address after the swizzle/linear select, so the two compose. The eight PRs it could not compare (#6412, #7642, #7689, #10193, #13928, #13929, #18515, #20248) touch V# type checks, image and sampler tables, profiling and native descriptor tables. I read their hunks. None of them changes the swizzle address or the IDXEN/ADD_TID index, with one exception: #20248's opt-in native descriptor tables build their own swizzle flag from the stride and bit 31. If both PRs land, that path would also need the IDXEN/ADD_TID 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-17T00:19:07Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
ea6589ad0f099626620b3b2939e907290d9b0585. No commands or tests were run; this review used the prepared diff and targeted reads at the pinned head.Results
Findings
Blocking
None.
Non-blocking
Sources
Not verified
No tests, builds, or hardware checks were run independently. Read the prepared description, commits, manifest, and diff; inspected relevant portions of all five changed files listed in the manifest. No changed files were excluded by the manifest. Full-file contents were not read for the larger changed files.
To get this to a good state
Nothing is required. Optional: add measured cases for the paths listed above when hardware data is available.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T16:59:13Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the address changes are covered by the added execution test, and the reported hardware and validation runs support the stated behavior.
What I ran
Reviewed head
89b1f8f3fdf370f789120600c432e954e571d2abusing the prepared diff and pinned reader. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Tests and hardware runs were not performed for this review. The description reports Windows 11 test runs and AMD RDNA2 measurements, and identifies unmeasured paths including gfx1013, graphics stages, atomics, SOFFSET, typed stores, and
tbuffer_*.Files read:
description.md,commits.md,manifest.json,diff.patch,README.md, and all five changed repository files:BufferSwizzledAddress.cpp,RuntimeBufferSpans.cpp,ShaderDiskCache.hpp,SpirvRuntimeBuffer.cpp, andfix-shader-swizzled-buffer-address.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-11-22T10:35:56Z.
Review: APPROVED
Reviewed — looks good
The change implements the described swizzled buffer address rules and adds execution coverage; no verified blocking defect was found in the reviewed changes.
What I ran
Reviewed head
27268840280119efa477604b98b23c97619c563cusingrepo_read.pyaccess to the prepared review bundle and pinned repository. No commands or tests were run by me; test results below are author-reported.Read all five changed files:
BufferSwizzledAddress.cpp,RuntimeBufferSpans.cpp,ShaderDiskCache.hpp,SpirvRuntimeBuffer.cpp, andfix-shader-swizzled-buffer-address.md. No files were excluded by the manifest.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the tests, build, or confirm console behavior. Author-reported hardware measurements and Windows test results were not independently verified. The debt note records measured buffer-bound cases that remain unresolved, as well as unmeasured paths including
tbuffer_*, typed stores, atomics, SOFFSET, graphics stages, and gfx1013.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:13:46Z.
Review: COMMENTED
The trial merge onto
a1b75b0947conflicts inShaderDiskCache.hpp. The new wave32 and wave64 cases cover the swizzled addressing rule across lanes and interleaved components. Please preserve the version bump after rebasing the generated code and run those cases together withRuntimeBufferSpans, which also covers the interaction with range checks. #24781 touches the same address lowering, so the order these land can affect the merged coverage.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T16:50:39Z.
Review: APPROVED
Reviewed — looks good
The changed addressing logic matches the stated IDXEN, ADD_TID, and vector-access rules, with no blocking defects found in the reviewed changes.
What I ran
Reviewed head
e459e25001f3073968f32ef337bdc38ca205153f. I inspected the prepared diff and manifest, then read the changed code and relevant source ranges withrepo_read.py. No tests or builds were run.Results
Negative control
Not run; no tests were run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The author-reported hardware measurements and test runs were not independently reproduced. No files were excluded; the review covered the changed hunks in
core/libs/prx/libSceAgcDriver/tests/execution/BufferSwizzledAddress.cpp,core/libs/prx/libSceAgcDriver/tests/execution/RuntimeBufferSpans.cpp,core/shader/recompiler/ShaderDiskCache.hpp,core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp, anddocs/dev/debt/changes/fix-shader-swizzled-buffer-address.md.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.