fix(shader): return zero when an s_buffer_load offset passes 2^32 #604
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/604"
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 adriadam10 on 2026-10-05T02:30:10Z.
What
s_buffer_load_*computed the byte address of each dword (soffset + imm + 4*i) in 32 bits. When that sum passes 2^32 it wrapped and read the start of the buffer. Hardware does not wrap: those dwords are out of range and read 0. The fix adds a carry check to the bounds condition inEmitReadConstBuffer, for both the bound V# path and the GPU-computed V# path (gpuDescriptor, added in21cb5676). The CPU-sideSrtEvaluatoralready does this math in 64 bits.Found by a test-only batch:
s_load_dwordx16,s_buffer_load_dwordx4ands_buffer_load_dwordx16were decoded but no test executed them.Behaviour measured on HW (gfx1035, wave32, 32 rows x 7 load groups, model matches 100%)
ireads from(soffset + imm + 4*i) & ~3. The low two offset bits are ignored. It reads 0 when that address is>= num_records, with the check done per dword, so a load that straddles the end returns its in-range dwords and zeros after them.soffset = 0xfffffffcwithoffset:0x14reads 0, whilemainreturned the dword at byte 0x10.OOB_SELECTin the V# has no effect on SMEM (word30x01016facand0x31016facgive identical results).s_load_dwordx16with an unaligned immediate (0x26) reads from0x24, whichmainalready does.Tested
Linux, new execution test
agc_driver_scalar_wide_loads(tests/execution/ScalarWideLoads.cpp). Expected values come from the hardware capture. It coverss_buffer_load_dwordx4/x16with SGPR, SGPR + immediate and immediate-only offsets (in range, unaligned, straddlingnum_records, past it, and past 2^32), ones_buffer_load_dwordthrough a V# whosenum_recordsis computed in the shader (GPU-descriptor path), ands_load_dwordx16with a constant offset.main(lane 2buffer_load_dwordx4 s9 offset 0x14 dword 0 is 0x00000004, expected 0x00000000). Removing the carry check from either path alone also fails the test, on the matching row.agc_driver_pixel_helper_lanes, which already fails onmainon local RADV.GuestAllocationsblock, as inFlatGlobalLoads.cpp, because the GPU-descriptor read goes through the BDA page table. Without it, lavapipe crashes in the shader, onmaintoo.s_load_dwordx16with an SGPR offset goes through BDA reads. One such load takes 37 s cold on CI's lavapipe, so the test only runs the constant-offset form, which the SRT walker resolves. Its SGPR-offset results matched the hardware locally (RADV + lavapipe).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T03:09:16Z.
Thanks, this checks out. I disassembled the test kernel with
llvm-mc -mcpu=gfx1013and it matches the description:s_buffer_load_dwordx4andx16with SGPR, SGPR plus immediate and immediate-only offsets (includingoffset:0xfffffand the straddling cases), thes_buffer_load_dwordthrough the V# built in the shader, ands_load_dwordx16at0x26.The carry check is right: each dword is its own
ReadConstBufferwithsoffsetas the argument andimm + 4*iasmem.offset, soaddress >= soffsetis exactly "the 32-bit add didn't wrap", and it's applied on both the bound V# path and the GPU-descriptor path. The new test fails on main with the row you quote (offset 0x14 dword 0 is 0x00000004) and passes with the fix; the full ctest passes with it merged.One note for the merge order: PPSA21564 uses
s_buffer_load_*in almost every shader (5,626 of the 5,688 I have dumped, 538 of them with an SGPR offset). None of them should come anywhere near 2^32, so I don't expect a visible change, but since the extra compare goes into nearly every shader I'll run it through my visual check of PPSA21564 before it goes in.Ready to merge from my side once that run is done.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:04:10Z.
Gated on PPSA21564: no visual or FPS change.