tombox-xshader: amplification payload byte/short stores were lost on hardware; edge-case AS tests (stacked on #313) #343
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!343
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/343/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?
@MeNoSkills on GitHub · 2026-11-23 22:05 UTC · original
MeNoSkills:test/amp-edge→main· +329 −9 · 2 files · 3 commits · closed without mergingWhat
Stacked on #313: the first commit in this branch is #313's harness, only the top commit is new. Opened as a draft until #313 is on main.
An amplification shader that stores a byte or a short into the payload ring never got that store to the mesh stage on hardware. The partial store was merged with
InterlockedAnd/InterlockedOron the groupshared payload variable, and on an RTX 4070 Ti those atomics are lost: the payload keeps its old dword. The same atomics on the args dwords work. The partial store into the payload is now a plain read-modify-write (hlsl/amp.rs). Every thread of the group runs the same stores, so every thread writes the same merged value.Tests added (
tests/amp.rs, on the synthetic AS + MS pair)gpu_synthetic_amplification_group_count_zero_launches_nothing: AS group 0 writes count 0 and group 1 writes count 1, only group 1's pixel is drawn; both groups at 0 draw nothing.gpu_synthetic_amplification_four_mesh_groups_each_see_their_own_payload: count 4 from each AS group fills all 8 pixels, each with its own AS group's payload and its own mesh group index.gpu_synthetic_amplification_payload_stride_rounds_up_to_sixteen: a 40-byte payload has a 48-byte ring stride (as in the console fixture as2); AS group 1's entry at 48 is accepted and 0 global misses.gpu_synthetic_amplification_group_count_from_a_byte_store: the group count written withglobal_store_byteinto the zeroed args dword.gpu_synthetic_amplification_sub_dword_payload_stores_merge:global_store_byte,_short,_byte_d16_hiand_short_d16_hiinto the payload merge into the dword already there. This is the test that fails without the fix: all four stores were dropped.gpu_synthetic_mesh_sub_dword_payload_loads_extend_correctly(second commit): the mesh stage reads the payload withglobal_load_ubyte/sbyte/ushort/sshort, including unaligned 16-bit loads at +13; zero extension for the u forms and sign extension for the s forms. No defect found, it was only covered by a compile test.synth_askeeps its signature;synth_as_withtakes an optional tail and a payload stride, andsynth_pair_witha payload size.Testing
TOMBOX_EXEC_HW=1 cargo test --locked --release -p tombox-xshader --test amp --test mesh --test syntheticon an RTX 4070 Ti (Windows 10 19045): all pass (amp 8 passed, 4 ignored fixture tests).hlsl/amp.rschange the sub-dword payload test fails with the payload unchanged ([0x100, 0, 0, 0x5a5a] where [0xab00, 0, 0xbeef0000, 0x7e575acd] is expected).TOMBOX_EXEC_HW=1here; I could not check the WARP path. If the atomics only fail on NVIDIA, a different mapping may be preferable and I am happy to change it.pr_gate.py --base upstream/main: 0 problems.Limits
Hand-written instruction sequences, not console compiler output; no game files involved. The plain read-modify-write can in theory race between threads that store different bytes of the same dword; in these tests all threads of the group run in lockstep on one warp.
@BuHHuTlyx on GitHub · 2026-11-23 22:20 UTC · original
I reproduced the original partial-store failure on an RTX 3070 (
32.0.16.2124, Windows 11 24H2, DXC 1.9.2609.5). With the old emitter and this PR's tests, the payload stayed unchanged on hardware and the test passed on WARP. At2f055b6, the existingamptests passed on both backends (9 passed, 4 fixture tests ignored).I added a synthetic case where different lanes write four disjoint bytes of the same payload dword. The expected word is
0x14131211. This PR's plain read-modify-write produced0x00005a11on the RTX 3070 and0x14005a5aon WARP in my runs.A prototype plus the regression test keeps the masked atomics on a separate flat groupshared array, then copies its dwords into the mesh payload after the group barrier. That passed all 10
amptests on each backend, including both partial-store cases. A direct compare-exchange loop on the payload itself reachedCreatePipelineState(AS+MS)with0x8007000eon the RTX 3070.The staging experiment needs a shared-memory budget decision. Its two arrays and dispatch arguments use
2 * align16(payload_bytes) + 16bytes even before any other shared declarations, which exceeds the 32 KiB budget at the 16 KiB payload limit. DirectX mesh shader limits.@BuHHuTlyx on GitHub · 2026-11-23 22:40 UTC · original
I reduced this to two handwritten HLSL shaders using the existing test harness. The amplification shader initializes a payload word to
0x12345678, then usesInterlockedAndandInterlockedOrto assemble0x14131211from four byte lanes. The mesh shader displays the received word.32.0.16.2124), the direct atomics left0x12345678with both constant and group-dependent indexing. A normal read and an atomic read from the AS after the barrier also reported the old value when copied to a second payload word.0x14131211. WARP returned the expected value for every variant.atomicrmw andandatomicrmw orin every variant. The results matched with default optimization and-Od.Run
cargo test --locked -p tombox-xshader --test amp handwritten_amplification_payload_atomics -- --exact --nocaptureon the repro branch. SetTOMBOX_EXEC_HW=1for the hardware device or leave it unset for WARP. The test asserts the staged control and reports hardware-specific direct results.@omonkeyz on GitHub · 2026-11-25 13:51 UTC · original
Thanks. Your tests and sub-dword load cases landed through #345, which replaces the plain read-modify-write with a staging ring and atomics after byte stores from different lanes were lost on hardware.
Pull request closed