shader: a gather's level is whole where only the lanes that gather wrote it (half of the black G-buffer, #182) #245

Manually merged
github merged 1 commit from github-bot/gh-245 into main 2026-11-27 04:27:17 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-27 04:07 UTC · original
Olima34:fix/gather-level-guarded-writes → main · +82 −12 · 3 files · 1 commits · merged 2026-11-27 04:26 UTC

This finds where the black G-buffer comes from (#182), and fixes half of the cause.

The chain, traced in game:

  • About 95% of the G-buffer draws in the world are ExecuteIndirect DispatchMesh records. In every record traced (600), the group count read [0, 1, 1].
  • Those arguments (32 KB) are reset each frame by compute e85d0ba6. Six culling compute shaders then fill them, in three pairs over the same buffers.
  • All six were refused, so their dispatches were dropped, X stayed 0, and the mesh draws drew nothing. That is why the G-buffer stays black even with VICTORY_DEBUG_NO_DEPTH.

This PR (the first member of each pair). b30937e9de066fa9, 5833c0c20c5bec9b and ff826810673a0198 were refused with "a gather at a level that may not be whole".

  • Their level is in fact whole: ceil(log2(...)) - 1, clamped at 0, then a v_cmpx_le_i32 and a v_mov_b32 of another whole level.
  • But those writes are guarded, and whole() also asked that the value each write keeps in the lanes that skip it be whole. Here that value is an unrelated product, kept only in lanes that never reach the gathers.
  • whole() now takes the gather's site. It looks at a guarded write's kept value only when a lane that runs the gather may have skipped the write (avoids(site, Skip)).

Still refused (the second member of each pair). 4e2edbd69fe414f1, f44473ebe75e0047 and 898d9c1a5605ad81 are refused with "a cross-lane operation between host waves in divergent code".

  • They are 128-thread groups, two console waves, so lockstep doesn't apply.
  • The shape: a whole-wave OR reduction, then s_mov exec, 1 and readlane 63, then ds_or to LDS[0] and a barrier.
  • The G-buffer stays dark (0–0.8% lit) until these run. We're working on that shape next.

Evidence:

  • Test: emit::sample_tests::gathers_at_a_level_whole_in_the_lanes_that_gather_translate fails without the fix. It also checks that the gather stays refused when every lane gathers.
  • Offline sweep: I translated 3,338 refused compute and graphics containers dumped from a game run (offline, with wave32_host and zero_copy_memory as on the native host). The six refused this way translate, and no other outcome changes.
  • In game (M5 Pro, Series S, warm, 300 s): the three culling shaders now run (ran (indirect)), and the first non-zero mesh group counts appear: [1,1,1], [5,1,1], [16,1,1], [24,1,1].

Checks: victory-shader 310 tests pass. victory-hle, victory, victory-gpu (arm64) and xtask pass. Windows clippy is clean with -D warnings. cargo xtask policy passes. docs/native-host.md has the whole chain under "The G-buffer's mesh draws dispatch no groups".

**@⁠Olima34** on GitHub · 2026-11-27 04:07 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/245) `Olima34:fix/gather-level-guarded-writes` → `main` · +82 −12 · 3 files · 1 commits · merged 2026-11-27 04:26 UTC This finds where the black G-buffer comes from (#182), and fixes half of the cause. **The chain, traced in game:** - About 95% of the G-buffer draws in the world are ExecuteIndirect `DispatchMesh` records. In every record traced (600), the group count read `[0, 1, 1]`. - Those arguments (32 KB) are reset each frame by compute `e85d0ba6`. Six culling compute shaders then fill them, in three pairs over the same buffers. - All six were refused, so their dispatches were dropped, X stayed 0, and the mesh draws drew nothing. That is why the G-buffer stays black even with `VICTORY_DEBUG_NO_DEPTH`. **This PR (the first member of each pair).** `b30937e9de066fa9`, `5833c0c20c5bec9b` and `ff826810673a0198` were refused with "a gather at a level that may not be whole". - Their level is in fact whole: `ceil(log2(...)) - 1`, clamped at 0, then a `v_cmpx_le_i32` and a `v_mov_b32` of another whole level. - But those writes are guarded, and `whole()` also asked that the value each write keeps in the lanes that skip it be whole. Here that value is an unrelated product, kept only in lanes that never reach the gathers. - `whole()` now takes the gather's site. It looks at a guarded write's kept value only when a lane that runs the gather may have skipped the write (`avoids(site, Skip)`). **Still refused (the second member of each pair).** `4e2edbd69fe414f1`, `f44473ebe75e0047` and `898d9c1a5605ad81` are refused with "a cross-lane operation between host waves in divergent code". - They are 128-thread groups, two console waves, so lockstep doesn't apply. - The shape: a whole-wave OR reduction, then `s_mov exec, 1` and `readlane 63`, then `ds_or` to LDS[0] and a barrier. - **The G-buffer stays dark (0–0.8% lit) until these run.** We're working on that shape next. **Evidence:** - **Test:** `emit::sample_tests::gathers_at_a_level_whole_in_the_lanes_that_gather_translate` fails without the fix. It also checks that the gather stays refused when every lane gathers. - **Offline sweep:** I translated 3,338 refused compute and graphics containers dumped from a game run (offline, with `wave32_host` and `zero_copy_memory` as on the native host). The six refused this way translate, and no other outcome changes. - **In game** (M5 Pro, Series S, warm, 300 s): the three culling shaders now run (`ran (indirect)`), and the first non-zero mesh group counts appear: `[1,1,1]`, `[5,1,1]`, `[16,1,1]`, `[24,1,1]`. **Checks:** victory-shader 310 tests pass. victory-hle, victory, victory-gpu (arm64) and xtask pass. Windows clippy is clean with `-D warnings`. `cargo xtask policy` passes. `docs/native-host.md` has the whole chain under "The G-buffer's mesh draws dispatch no groups".
The G-buffer's mesh draws in the world are ExecuteIndirect records whose
group counts the title's culling compute shaders write. Three of them
(b30937e9de066fa9, 5833c0c20c5bec9b, ff826810673a0198) were refused, "a
gather at a level that may not be whole", so their dispatches were
dropped and every record kept the [0, 1, 1] the frame starts it with: the
G-buffer draws drew nothing.

Their level is whole: ceil(log2(...)) - 1, clamped at 0, then
v_cmpx_le_i32 and a v_mov_b32 of another whole level. But those writes
are guarded, and the proof asked the value each one keeps in the lanes
that skip it to be whole as well. Here it is an unrelated product, kept
only in lanes that never reach the gathers.

whole() now takes the gather's site and looks at a guarded write's kept
value only when a lane that runs the gather may have skipped the write
(avoids(site, Skip)). Every step it follows is the lane's own, and a lane
that reads the value at the gather went through the write's block, so
only those lanes count.

Over 3,338 refused compute and graphics containers dumped from a game run
(offline, wave32_host and zero_copy_memory as the native host), the six
refused this way translate and no other outcome changes. In a warm game
run the three culling shaders now run and the first non-zero group
counts appear. Their partners (4e2edbd69fe414f1, f44473ebe75e0047,
898d9c1a5605ad81) are still refused as a cross-lane operation between
host waves in divergent code, so the G-buffer is not lit yet (#182).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 04:11:26 +00:00
github manually merged commit 2552563d94 into main 2026-11-27 04:27:17 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 04:26 UTC · original · approved these changes

Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 04:26 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/245#pullrequestreview-6083481181) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.