shader: apply a storage buffer's host offset at byte granularity #448
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!448
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/448/head"
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?
@MehmetCambaz on GitHub · 2026-09-01 22:14 UTC · original
MehmetCambaz:ai/work/teardown-storage-offset→main· +90 −11 · 4 files · 1 commits · closed without mergingProblem
A storage buffer is bound at the guest base rounded down to
minStorageBufferOffsetAlignment,and the bytes that were rounded off are handed to the shader as an 8-bit offset per buffer.
The shader took them as a dword index:
so the low two bits were dropped, and
NativeStorageBufferrejected any binding that neededthem with
storage buffer offset adjustment is unsupported. The device alignment here is 16,so three of every four guest base addresses land in that guard.
Teardown (PPSA15246) hits it about a second into boot. Its first compute shader reads a byte
buffer whose base is 13 bytes past the boundary:
Fix
Nothing here needs a new mechanism. A
Bufferaccess already derives both its element indexand its byte within that element from one byte address:
LoadSubwordPreparedcomputesaddress >> 2for the index andLoadSubwordInBoundsusesaddress & 3for the shift. Theoffset was being folded in after that split instead of before it.
So fold it into the byte address, in
BufferByteAddress, which everyBufferconsumerderives from. The element index, the sub-word shift and the bounds check then all stay exact
for any offset.
ScalarBufferkeeps the dword index.ReadConstBufferloads a whole dword ataddress >> 2and has no byte address to fold into, so a base that is not dword aligned would straddle two
elements. The guard still rejects that, and still rejects anything else that touches 32 bits
at a time — a 32-bit component, a packed bitfield, an atomic.
BufferAccessIsSubDwordnamesthe case that is safe rather than widening the check, and the message now prints its operands
so the next title to reach it does not need a debug build.
Test plan
Windows 11, clang-cl 20.1.8, RTX 2060, Release.
BufferStoreByteAppliesByteHostOffset: offset 13, one byte stored, expected at byte13. Reverting just the emitter change makes it fail with
expected [...0x0000ab00...] actual [...0x000000ab...]— the byte lands at 12 insteadof 13, which is exactly the two bits the shift discarded. The harness itself asserted
offset % 4 == 0; that assumption was part of the bug and is relaxed.shader_recompiler_compute_tests: 344 cases, all pass, including all 272 compute cases.ctest36/36 with #446 applied. On plainmainit is 34/36, unchanged from baseline —the two failures are the pre-existing
RenderExecutorStencilBindingDiscoveryones.then stops in resource tracking with
GetBufferResource dword 0 is not a valid runtime value, which is unrelated to this.Teardown still does not boot — this removes one blocker and nothing more is claimed.
correctly, checked against a screenshot, with no shader or storage errors in the log.
Reaching the Teardown blocker at all needs #443, which is still open; the fix here is
independent of it and is based on plain
main.Worth flagging: #427 also edits
NativeStorageBuffer, for range clamping rather than thisguard, so the two will conflict textually if both land.
AI use
Developed with AI assistance (Claude). It reproduced the blocker, added the diagnostic that
exposed the format and access flags, traced the address path to
BufferByteAddress, wrote thechange and the regression test, and ran the builds, the test suite and the game runs above on
my machine. I reviewed the diff and confirmed the
ScalarBufferpath still takes the dwordindex.
@Nmzik on GitHub · 2026-10-06 17:18 UTC · original
superseded by main changes
Pull request closed