shader: add a source-built subgroup compaction bridge fixture #785

Merged
FZNull merged 1 commit from upstream-pr/791 into main 2026-11-23 04:30:20 +00:00
FZNull commented 2026-11-23 03:41:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by FZNull on 2026-11-23T03:41:34Z.


Change

Adds the source-built subgroup compaction fixture asked for in #768: one compute program that makes each compaction intermediate separately visible, a direct desktop-HLSL control with the same contract, and a readback operation that compares them with an independent CPU reference computed at the wave width the shader observed.

Files:

  • tests/spirv_window/compaction.spvasm — the source module. One 64-thread group derives a sparse per-lane predicate from a deterministic 64-bit mask, ballots it with OpGroupNonUniformBallot, and writes, in separate words: the lane index each thread observed (0–63), the observed width (64), the four ballot words per wave (65–128), first active lane, count, last active lane and the selected lane's rank per wave (129–192), the per-lane rank (193–256), compacted payloads in wave-disjoint ranges keyed by rank (257–320), and a 7-word guard tail (321–327) that must stay 0xc5c5c5c5.
  • tests/spirv_window/compaction.hlsl — the direct desktop-HLSL control with the same outputs.
  • tests/spirv_window/compaction.py — the driver: spirv-as → spirv-val → spirv-cross → DXC → offscreen_check --spirv-compaction, for both masks and both paths.
  • tests/spirv_window/compaction_readback.cpp — the readback and comparison against the CPU reference.
  • CMakeLists.txt, tests/desktop_gpu.h, tests/offscreen_check.cpp — registration of spirv_compaction_{hardware,warp} behind the existing kGateSm66Ballot-style capability gate (a new kGateSm66Compaction; the existing gate is untouched).
  • tests/spirv_window/require_warp_results.py — the new _warp test is added to the required list, with no machine-dependent thresholds.
  • docs/experiments.md — the measurement and the adapter difference below.

Result

Both adapters match their width-aware CPU reference in all 328 words, for both masks, on the bridge and on the direct-HLSL control: 0 mismatches, guards untouched, repeated dispatches word-identical. The two negative controls (flipped predicate bit, compaction write index shifted by one) are caught at the predicted first words, 65 and 257, on both adapters.

The adapters differ first at word 4, the per-thread lane index: RTX 4060 writes 0x00000004, WARP writes 0x00000000; 259 of 328 words differ with mask A and 260 with mask B. The cause is the lane width each adapter reports: D3D12_OPTIONS1.WaveLaneCountMin/Max is 32/32 on the RTX 4060 and 4/4 on WARP, and WaveGetLaneCount() inside the shader returns 32 and 4. A CPU model computed at width 32 reproduces the same first mismatch against the WARP readback. So this is not a WARP ballot, rank or writeback arithmetic difference — at its native width WARP matches the independent model exactly — it is a wave-width assumption difference, which is the class the #768 replay difference belongs to. It also explains why #774's constant-mask ballot-bit extraction matches on WARP: that operation is width-independent, while a ballot/compaction layout is not.

Verification

Environment: Windows 11 Pro build 26300.10075, debug layer unavailable on both adapters. NVIDIA GeForce RTX 4060, driver 32.0.16.2124 (wave range 32..32). WARP 10.0.26100.10068 (wave range 4..4). MSVC 19.50.35726.0, Windows SDK 10.0.26100, CMake 4.5.1, Ninja 1.13.2, DXC 1.9.2609.5, SPIRV-Tools v2025.5 (262bdab), SPIRV-Cross 57e4efc, Python 3.13.12.

cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^spirv_' -V
# 10/10 passed: the eight existing bridge tests plus spirv_compaction_{hardware,warp}

Direct runs, with a per-word dump:

python -B tests/spirv_window/compaction.py <spirv-as> <spirv-val> <spirv-cross> <dxc> out/build/dev/offscreen_check.exe hardware
out/build/dev/offscreen_check.exe warp --spirv-compaction <module.dxil>

docs_links_check.py and bidi_controls_check.py pass.

Scope

No adapter here exposes a 64-lane wave, so an intra-wave 31/32 ballot-word boundary is a capability skip; the 31/32 mask-bit boundary is still exercised across two 32-lane waves. The exact replay record from #768 is not in the public tree, so this does not prove the original replay used a 32-lane assumption. It isolates a reproducible adapter difference of the same class and shows there is no arithmetic divergence in the WARP ballot/rank/compact path. Next step to close the replay question: run that record through this fixture, or log WaveGetLaneCount() in the replay and recompute its reference at the observed width.

Source-built fixtures only; no game files are involved.

Refs #768, #774, #656, #763.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6551781853 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/791). Originally posted by [FZNull](https://github.com/FZNull) on 2026-11-23T03:41:34Z. --- ## Change Adds the source-built subgroup compaction fixture asked for in #768: one compute program that makes each compaction intermediate separately visible, a direct desktop-HLSL control with the same contract, and a readback operation that compares them with an independent CPU reference computed at the wave width the shader observed. Files: - `tests/spirv_window/compaction.spvasm` — the source module. One 64-thread group derives a sparse per-lane predicate from a deterministic 64-bit mask, ballots it with `OpGroupNonUniformBallot`, and writes, in separate words: the lane index each thread observed (0–63), the observed width (64), the four ballot words per wave (65–128), first active lane, count, last active lane and the selected lane's rank per wave (129–192), the per-lane rank (193–256), compacted payloads in wave-disjoint ranges keyed by rank (257–320), and a 7-word guard tail (321–327) that must stay `0xc5c5c5c5`. - `tests/spirv_window/compaction.hlsl` — the direct desktop-HLSL control with the same outputs. - `tests/spirv_window/compaction.py` — the driver: `spirv-as` → `spirv-val` → `spirv-cross` → DXC → `offscreen_check --spirv-compaction`, for both masks and both paths. - `tests/spirv_window/compaction_readback.cpp` — the readback and comparison against the CPU reference. - `CMakeLists.txt`, `tests/desktop_gpu.h`, `tests/offscreen_check.cpp` — registration of `spirv_compaction_{hardware,warp}` behind the existing `kGateSm66Ballot`-style capability gate (a new `kGateSm66Compaction`; the existing gate is untouched). - `tests/spirv_window/require_warp_results.py` — the new `_warp` test is added to the required list, with no machine-dependent thresholds. - `docs/experiments.md` — the measurement and the adapter difference below. ## Result Both adapters match their width-aware CPU reference in **all 328 words**, for both masks, on the bridge and on the direct-HLSL control: 0 mismatches, guards untouched, repeated dispatches word-identical. The two negative controls (flipped predicate bit, compaction write index shifted by one) are caught at the predicted first words, 65 and 257, on both adapters. The adapters differ first at **word 4, the per-thread lane index: RTX 4060 writes `0x00000004`, WARP writes `0x00000000`**; 259 of 328 words differ with mask A and 260 with mask B. The cause is the lane width each adapter reports: `D3D12_OPTIONS1.WaveLaneCountMin/Max` is 32/32 on the RTX 4060 and 4/4 on WARP, and `WaveGetLaneCount()` inside the shader returns 32 and 4. A CPU model computed at width 32 reproduces the same first mismatch against the WARP readback. So this is not a WARP ballot, rank or writeback arithmetic difference — at its native width WARP matches the independent model exactly — it is a wave-width assumption difference, which is the class the #768 replay difference belongs to. It also explains why #774's constant-mask ballot-bit extraction matches on WARP: that operation is width-independent, while a ballot/compaction layout is not. ## Verification Environment: Windows 11 Pro build 26300.10075, debug layer unavailable on both adapters. NVIDIA GeForce RTX 4060, driver 32.0.16.2124 (wave range 32..32). WARP 10.0.26100.10068 (wave range 4..4). MSVC 19.50.35726.0, Windows SDK 10.0.26100, CMake 4.5.1, Ninja 1.13.2, DXC 1.9.2609.5, SPIRV-Tools v2025.5 (`262bdab`), SPIRV-Cross `57e4efc`, Python 3.13.12. ```powershell cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R '^spirv_' -V # 10/10 passed: the eight existing bridge tests plus spirv_compaction_{hardware,warp} ``` Direct runs, with a per-word dump: ```powershell python -B tests/spirv_window/compaction.py <spirv-as> <spirv-val> <spirv-cross> <dxc> out/build/dev/offscreen_check.exe hardware out/build/dev/offscreen_check.exe warp --spirv-compaction <module.dxil> ``` `docs_links_check.py` and `bidi_controls_check.py` pass. ## Scope No adapter here exposes a 64-lane wave, so an intra-wave 31/32 ballot-word boundary is a capability skip; the 31/32 mask-bit boundary is still exercised across two 32-lane waves. The exact replay record from #768 is not in the public tree, so this does not prove the original replay used a 32-lane assumption. It isolates a reproducible adapter difference of the same class and shows there is no arithmetic divergence in the WARP ballot/rank/compact path. Next step to close the replay question: run that record through this fixture, or log `WaveGetLaneCount()` in the replay and recompute its reference at the observed width. Source-built fixtures only; no game files are involved. Refs #768, #774, #656, #763. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:44:48 +00:00
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
R0Y00/Xbox2Windows!785
No description provided.