fix(shader): read a 16-bit buffer load that crosses a dword boundary from both dwords #21925
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21925"
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:02Z.
What
A 16-bit buffer load (
buffer_load_ushort,buffer_load_sshort) at a byte offset of 3 mod 4 crosses a dword boundary. The recompiler read only the dword holding the first byte, so it returned the low byte with a zero or sign-extended high byte, on any GPU and for any range. On RDNA2 the load returns both bytes: the low byte from the first dword and the high byte from the next one. The access is still all-or-nothing: ifoffset + 2is past the range, the whole load returns 0.This PR adds
readBufferHalfto the non-BDA path ofSpirvRuntimeBuffer.cpp. A 16-bit load at offset 3 mod 4 reads the high byte from the next dword, under the same whole-access enable as the low byte. Other offsets take the existing path. The BDA path already reads 16-bit values byte by byte and is unchanged.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. Raw V# word 30x31016fac. Rows cover ushort and sshort at every offset mod 4, withsoffset, an immediate offset, and a short range where the second byte falls outside (NUM_RECORDS8, offset 7: returns 0).The new execution test
BufferHalfStraddleruns eight cases (ushort and sshort, each with a 64-byte range at no offset, atsoffset3, at immediate offset 3, and an 8-byte range) over 64 lanes, so lane offsets 0 to 63 cover every offset mod 4. Each lane is compared with the measured rule above (both bytes joined, 0 whenoffset + 2is past the range): 512 lane checks per wave size, wave32 and wave64, with 0 mismatches.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). Whether DWORD mode splits or aligns a 16-bit access that crosses a dword is unmeasured, so this PR matches the measured PC hardware and records the console case in the debt fragment.Typed 16-bit loads (
tbuffer_load_format_xwith a 16-bit format) at odd offsets are a separate path. Measured on a structured V# they return 0 at offsets 1, 3, 7, 11 and 15, and the recompiler's result there is not measured, so they are recorded in the debt fragment, not changed. gfx1013 itself is not measured.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, head
6037d3f541(code atd3335727b9) onmainbca2d36814.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:BufferHalfStraddlepasses in 3/3 runs on each GPU;Selected GPU name=names the requested GPU. With the fix reverted it fails on both GPUs (184 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).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>' -V; the branch side adds the new test:was not foundVUID-bca2d36814bca2d36814No new
VUID-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, #7642, #7689, #10193, #13928, #13929, #14217, #18515 and #20248 do not touch 16-bit buffer reads. The new test avoids unaligned dword loads, so it does not depend on #16415.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T14:25:59Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
6037d3f5417d278335f5f08196e0558d6f3db68bagainst the prepared diff. I used the repository reader to inspect all three changed files and the relatedreadBufferand runtime address logic. I ran no build or tests; results reported in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
BufferHalfStraddle.cppcovers every lane for offsets 0–63 (and a short-range case), not 512 distinct rows as stated in the description. The test checks the straddle offset and both signedness modes across wave32 and wave64, but consider correcting the claim or expanding the matrix if the larger row count is intended.Not verified
No build or tests were run in this review. The reported GPU measurements and test results were not independently verified. The console's DWORD alignment behavior and gfx1013 behavior remain unmeasured per the description. Read:
BufferHalfStraddle.cpp,SpirvRuntimeBuffer.cpp, andfix-shader-buffer-short-dword-straddle.md. Excluded: none of the changed files; there is nofiles.jsonin the prepared review folder.To get this to a good state
Nothing is required. Optional: align the “512 measured rows” description with the execution test’s actual cases.