tombox-xshader: declare raw buffers as ByteAddressBuffer and address them by byte #346
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/346"
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 omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T22:28:37Z.
Library / area: tombox-xshader, MUBUF/MTBUF buffer accesses (
hlsl.rs,hlsl/atomic.rs,hlsl/mtbuf.rs, newhlsl/bufref.rs)What was wrong
Every title buffer reached through MUBUF/MTBUF is declared
StructuredBuffer<TbElem_*>with an element guessed from the touched extent (usually 16 bytes), also when PSV0 says the resource is raw (SRVRaw4 /UAVRaw7). Titles create raw views for those (StructureByteStride0), so on the PC the element index is scaled by a stride the view does not have.D3D12 GPU-based validation shows it directly, e.g. on The Matrix Awakens (native Windows 11; not run under Proton):
In that title the persistent Nanite culling kernels (
PersistentClusterCull) keep their node and cluster-batch queues in such raw UAVs (PSV0type=7 kind=11at u2/u3/u4).The change
buf_is_rawlooks the slot up in PSV0 (register + space, not bindless).RWByteAddressBuffer/ByteAddressBuffer; all accesses use the byte address: dword loads/stores (Load/Store), sub-dword loads/stores (maskedInterlockedAnd/InterlockedOron the containing dword), atomics including the compare-exchange loops ofsmin/smax/inc/dec, MTBUF loads/stores, and scalar loads from the SRV/UAV table (tb_sbw_*becomesLoad).BufRef(element expression or raw buffer + byte address) carries the target intoatomic_rmwand the sub-dword path, so structured and typed buffers emit exactly the HLSL they emitted before.Tests
tests/exec.rs: the exec harness creates a raw view (R32_TYPELESS,D3D12_BUFFER_UAV_FLAG_RAW) when the translated shader declaresRWByteAddressBuffer.buffer_mubufruns its 178 non-IDXEN, non-format cases a second time with a raw PSV0 entry against that raw view (mubuf_raw_view): byte/short/dword loads and stores, D16 variants, all atomics.mubuf_atomic_scalar_offset: the raw group now runs against a raw view with plain byte addresses (its expected values used to replicate the extent heuristic); IDXEN forms are not run for raw buffers.tests/synthetic.rs: raw SRV ->ByteAddressBuffer+Load(DXC-compiled); structured SRV keepsStructuredBuffer<TbElem_sbuf0>; raw + IDXEN refused for an atomic and a store; the existing raw UAV store + atomic test now expectsubuf0.Store(/ubuf0.InterlockedOr(.cargo test -p tombox-xshader --no-fail-faston WARP: all pass (exec 128 passed, 2 ignored).TOMBOX_EXEC_HW=1on an AMD Radeon RX 6600 XT (RDNA2):buffer_mubuf(includingmubuf_raw_view),mubuf_atomic_scalar_offsetandmubuf_scalar_offsetpass.In a title
The Matrix Awakens, native Windows 11 (not run under Proton), D3D12 debug layer with GPU-based validation, same point in the title (second presented frame):
STRUCTURED_BUFFER_STRIDE_MISMATCHdesc: 0)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). With correct bindings the title still does not reach ray dispatches; this PR only fixes the addressing.
Not verified / limits
atomic.rs) and with #199 (globallycoherentdeclarations): whichever lands second needs a rebase; with #199 the raw declaration becomesgloballycoherent RWByteAddressBufferfor coherent UAVs (done and used in the title runs above).Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:50:31Z.
Applied on main in
36d9c51(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed