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

Merged
Olima34 merged 1 commit from upstream-pr/245 into main 2026-11-27 04:26:32 +00:00
Olima34 commented 2026-11-27 04:07:26 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T04:07:26Z.


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".

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5521023008 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/245). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T04:07:26Z. --- 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".
LakshanSivakumar commented 2026-11-27 04:26:28 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T04:26:28Z.

Review: APPROVED


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6083481181 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/245#pullrequestreview-6083481181). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T04:26:28Z. **Review:** APPROVED --- Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
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
LakshanSivakumar/Native-Victory-macOS!245
No description provided.