tombox-xshader: size structured buffer elements from the FSSM stride (stacked on #289) #347
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!347
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/347/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?
@GDAgent on GitHub · 2026-11-23 22:43 UTC · original
GDAgent:feat/xshader-fssm-buffer-strides→main· +947 −8 · 9 files · 3 commits · closed without mergingStacked on #289 (FSSM binding table parser). Review only the last commit,
tombox-xshader: size structured buffer elements from the FSSM stride; the two commits below it are #289.Library / area: tombox-xshader, structured buffer declarations (
hlsl.rs:sbuf_words, newfssm_buffer_strides)What was wrong
The element of a translated
StructuredBuffer<TbElem_*>is guessed from the byte extent the ISA touches (sbuf_words, documented as a heuristic,TECHNICAL_DEBT). D3D12 takes the stride from the HLSL element type, so when the guess differs from the title's view every element after the first is read and written at the wrong address. GPU-based validation on The Matrix Awakens (native Windows 11; not run under Proton) reports, among others:One example is the 44-byte queue-state buffer of the persistent Nanite culling kernels: their
buffer_atomic_addat byte offsets 8, 12, 16 and 20 becameubuf1[0].w[2],ubuf1[0].w[3],ubuf1[1].w[0],ubuf1[1].w[1]with a 16-byte element, i.e. bytes 8, 12, 44, 48 on a 44-byte view.The change
The FSSM binding table (#289) records the original stride of every SRV and UAV it binds (for that kernel: 12, 44, 16, 800, 8, and 1 for its raw buffers).
fssm_buffer_stridescollects the strides per(SRV/UAV, register)once per shader;sbuf_wordsuses that stride when there is exactly one for the slot's register (space 0) and it is a multiple of 4. Everything else keeps the extent heuristic: registers with conflicting strides, strides 0/1 (textures, raw buffers; raw buffers are handled by #346), slots in other spaces, bindless slots, and shaders without a readable table.After the change the kernel above declares
uint w[11]for the queue state and its atomics land onw[2],w[3],w[4],w[5](bytes 8..20), as on the console.Tests
tests/fssm_bind.rs:buffer_elements_take_the_fssm_stride(FSSM stride 44 ->uint w[11], indexed by 11 words, DXC-compiled);conflicting_fssm_strides_keep_the_extent_heuristic.cargo test -p tombox-xshader --no-fail-faston WARP: all pass (exec 128 passed, 2 ignored; lib 122 passed, 3 ignored).In a title
The Matrix Awakens with this PR and #346, D3D12 debug layer with GPU-based validation, same point in the title (second presented frame): 26
STRUCTURED_BUFFER_STRIDE_MISMATCHerrors before, 0 GPU-based validation errors over a 600 s run after. The after-run used a local diagnostic that limits the 2040-group persistent culling dispatch to 8 groups, because that dispatch still exceeds the GPU timeout on this RDNA2 card (under investigation, not changed by this PR).Not verified / limits
@omonkeyz on GitHub · 2026-11-25 13:50 UTC · original
Applied on main in
a618736(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.@tyr0nsur on GitHub · 2026-11-25 20:48 UTC · original
I ran your FSSM binding suite on Windows x64 at
a618736df7and extended the conflict fixture to compile the three resulting pixel shaders with Microsoft DXC. With strides [44, 44] the emitted element has 11 DWORDs. Both [44, 32] and [32, 44] fall back to one DWORD. All 15 tests passed. The smallest addition to the existing fixture is to loop over those three pairs and pass each HLSL result to its existing compile helper. This caught an order-dependent stride choice in our separate DXIL emitter. Thanks for publishing the original regression.Pull request closed