tombox-xshader: size structured buffer elements from the FSSM stride (stacked on #289) #347

Closed
GDAgent wants to merge 3 commits from upstream-pr/347 into main
GDAgent commented 2026-11-23 22:43:44 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T22:43:44Z.


Stacked 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, new fssm_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:

StructureByteStride in UAV/SRV desc: 44, ByteStride for struct used in shader: 48
StructureByteStride in UAV/SRV desc: 32, ByteStride for struct used in shader: 16
StructureByteStride in UAV/SRV desc: 8,  ByteStride for struct used in shader: 16
StructureByteStride in UAV/SRV desc: 16, ByteStride for struct used in shader: 4
[ EXECUTION ERROR #1387: GPU_BASED_VALIDATION_STRUCTURED_BUFFER_STRIDE_MISMATCH ]

One example is the 44-byte queue-state buffer of the persistent Nanite culling kernels: their buffer_atomic_add at byte offsets 8, 12, 16 and 20 became ubuf1[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_strides collects the strides per (SRV/UAV, register) once per shader; sbuf_words uses 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 on w[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.
  • Full cargo test -p tombox-xshader --no-fail-fast on 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_MISMATCH errors 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

  • Only space-0 registers: the FSSM table carries no register space.
  • The FSSM stride is taken as the view stride; the validation run above found no case where they differ, but titles could bind a view with another stride.
<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6570353959 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/347). Originally posted by [GDAgent](https://github.com/GDAgent) on 2026-11-23T22:43:44Z. --- **Stacked 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`, new `fssm_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: ``` StructureByteStride in UAV/SRV desc: 44, ByteStride for struct used in shader: 48 StructureByteStride in UAV/SRV desc: 32, ByteStride for struct used in shader: 16 StructureByteStride in UAV/SRV desc: 8, ByteStride for struct used in shader: 16 StructureByteStride in UAV/SRV desc: 16, ByteStride for struct used in shader: 4 [ EXECUTION ERROR #1387: GPU_BASED_VALIDATION_STRUCTURED_BUFFER_STRIDE_MISMATCH ] ``` One example is the 44-byte queue-state buffer of the persistent Nanite culling kernels: their `buffer_atomic_add` at byte offsets 8, 12, 16 and 20 became `ubuf1[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_strides` collects the strides per `(SRV/UAV, register)` once per shader; `sbuf_words` uses 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 on `w[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`. - Full `cargo test -p tombox-xshader --no-fail-fast` on 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_MISMATCH` errors 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 - Only space-0 registers: the FSSM table carries no register space. - The FSSM stride is taken as the view stride; the validation run above found no case where they differ, but titles could bind a view with another stride.
omonkeyz commented 2026-11-25 13:50:33 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:50:33Z.


Applied on main in a618736 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7164369388 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/347#issuecomment-7164369388). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:50:33Z. --- Applied on main in a618736 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.
tyr0nsur commented 2026-11-25 20:48:12 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by tyr0nsur on 2026-11-25T20:48:12Z.


I ran your FSSM binding suite on Windows x64 at a618736df7 and 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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7174208328 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/347#issuecomment-7174208328). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-25T20:48:12Z. --- I ran your FSSM binding suite on Windows x64 at a618736df799d21d9a565d08893355fc3c96fdf5 and 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!347
No description provided.