Repository navigation
fix(shader): read a 16-bit buffer load that crosses a dword boundary from both dwords - #21925
Conversation
…from both dwords buffer_load_ushort and _sshort at an offset of 3 modulo 4 returned only the low byte, because the load looked at one dword. RDNA2 (gfx1036, AMD Windows driver 32.0.21043.5001, through the hardware oracle; IEEE 0, DX10 clamp 1, denorm32 0, denorm16 3, round32/16 0, fp16 overflow 0) returns both bytes whenever offset + 2 <= NUM_RECORDS. The second byte now comes from the following dword, for every V# range. BufferHalfStraddle pins ushort and sshort loads against 512 rows measured on that GPU, with soffset, an immediate offset and a short range, in wave32 and wave64. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nned Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
…t mode UNALIGNED Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Ran the focused tests with the Khronos validation layer on Linux and an NVIDIA GPU, since CI runs the GPU tests only on lavapipe and the RTX 4070 run in the Tested section is on Windows. Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor
Negative control: with main's No new AI-assisted: yes (Claude Code) |
|
Head No new failures and no new validation messages on either GPU.
Layer runs used AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head 6037d3f5417d278335f5f08196e0558d6f3db68b against the prepared diff. I used the repository reader to inspect all three changed files and the related readBuffer and runtime address logic. I ran no build or tests; results reported in the PR description are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Changed code review | passed | All changed lines were read |
| Build and tests | not run | Author reports passing hardware runs |
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, and fix-shader-buffer-short-dword-straddle.md. Excluded: none of the changed files; there is no files.json in 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.
GPU test run: no
|
| Test | main | head run 1 | head run 2 | head run 3 |
|---|---|---|---|---|
agc_driver_buffer_half_straddle |
not on main (negative control above: Failed 1.15 s) | Passed 0.35 s | Passed 0.27 s | Passed 0.29 s |
agc_driver_buffer_load_store |
Passed 1.32 s | Passed 0.51 s | Passed 0.26 s | Passed 0.30 s |
agc_driver_buffer_load_store_draw_pipeline |
Passed 0.26 s | Passed 0.22 s | Passed 0.25 s | Passed 0.30 s |
agc_driver_buffer_load_store_plan_verify |
Passed 0.25 s | Passed 0.22 s | Passed 0.25 s | Passed 0.31 s |
agc_driver_runtime_buffer_spans |
Passed 0.44 s | Passed 0.38 s | Passed 0.32 s | Passed 0.44 s |
agc_driver_runtime_buffer_spans_fault_barrier |
Passed 0.28 s | Passed 0.26 s | Passed 0.26 s | Passed 0.30 s |
agc_driver_runtime_buffer_spans_fault_stop |
Passed 0.27 s | Passed 0.27 s | Passed 0.27 s | Passed 0.33 s |
agc_driver_runtime_buffer_spans_x2_reference |
Passed 0.39 s | Passed 0.37 s | Passed 0.36 s | Passed 0.39 s |
agc_driver_runtime_buffer_spans_x2_spans |
Passed 0.47 s | Passed 0.41 s | Passed 0.39 s | Passed 0.44 s |
agc_driver_runtime_buffer_spans_x3_reference |
Passed 0.40 s | Passed 0.36 s | Passed 0.38 s | Passed 0.45 s |
agc_driver_runtime_buffer_spans_x3_spans |
Passed 0.48 s | Passed 0.42 s | Passed 0.42 s | Passed 0.46 s |
agc_driver_runtime_buffer_spans_x4_reference |
Passed 0.41 s | Passed 0.37 s | Passed 0.36 s | Passed 0.41 s |
agc_driver_runtime_buffer_spans_x4_spans |
Passed 0.45 s | Passed 0.39 s | Passed 0.40 s | Passed 0.42 s |
- All 13 are GPU tests. Each selected the R9700 (
subgroup=64) in every run, and none skipped. - The new test runs wave32 and wave64 (
:105). - The
agc_driver_buffer_load_storetime onmainincludes a cold start after a clean rebuild.
Validation:
Insert instance layer "VK_LAYER_KHRONOS_validation"appears 12 times in themainlog and 13 times in each head log, once per test.was not found but was requested by env var VK_INSTANCE_LAYERSappears in no log.VUID-lines: 0 onmain, and 0, 0 and 0 on the three head runs.
Host:
- GPU: AMD Radeon AI PRO R9700 (gfx1201, 1002:7551), driver 32.0.31044.16, Vulkan 1.4.349
- Validation layer: Khronos 1.4.363 (LunarG SDK)
- CPU and OS: Ryzen 9 9950X3D, Windows 11 Pro 26300
- Build: WinLibs GCC 15.2, Release
- Commits: main
8e1af3d9b0, head6037d3f541(merge9aa6b42cb7)
AI-assisted: yes
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: fix(recompiler): defer the TYPE check of a guarded read-only static V# #6412, feat(agc): look up table images at run time through a device image table on the GPU heap (APS5_GPU_PATH) #7642, fix(shader): defer guarded fragment V# type faults #7689, feat(agc): serve lane-keyed, pointer and runtime image-table columns #10193, feat(agc): resolve table samplers through device image keys #13928, feat(agc): resolve runtime sampler addresses through device image keys #13929, fix(shader): synchronize GLC and DLC buffer accesses on MoltenVK with device atomics and the guest's release and acquire #14217, UFC 6 profiling: tracking draft (not for merge) #18515 and feat(shader): add opt-in native buffer descriptor tables #20248 do not touch 16-bit buffer reads. The new test avoids unaligned dword loads, so it does not depend on fix(shader): align raw vector buffer dword accesses to the V# base #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)