shader: exchange between host waves in a block that holds the title's barrier (2 of the 3 other G-buffer culling shaders, #182; 898d9c1a5605ad81 is still refused) #253

Manually merged
github merged 4 commits from github-bot/gh-253 into main 2026-11-27 12:15:55 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-27 05:22 UTC · original
Olima34:fix/exchange-at-title-barriers → main · +443 −8 · 5 files · 4 commits · merged 2026-11-27 12:04 UTC

Current head (e3d3ce69): barrier blocks behind a first-lane branch are excluded, except when that first lane reads an LDS word right after the title's barrier that no reachable write can touch before the next barrier (barrier_reads). With that, 4e2edbd69fe414f1 and f44473ebe75e0047 translate and 898d9c1a5605ad81 stays refused; see the latest comment for the sweep.

Follow-up to #245. With both PRs, 5 of the 6 culling compute shaders that write the G-buffer's indirect mesh-draw group counts translate and run (#182); 898d9c1a5605ad81 is still refused.

Shape. The other three culling shaders (4e2edbd69fe414f1, f44473ebe75e0047, 898d9c1a5605ad81) were refused with "a cross-lane operation between host waves in divergent code". Each is a group of two console waves (128 threads), so the lockstep fallback doesn't apply. The shader:

  1. ORs a flag over its wave in a whole-wave section;
  2. reads lane 63 with EXEC set to lane 0 alone;
  3. ORs that value into LDS word 0;
  4. reads it back after the title's s_barrier.

The lane reads cross host waves and need group barriers. Those went only in blocks that every thread runs exactly once. This block is reached by uniform branches, and a culled wave ends early, so the shaders were refused.

Rule added. A block outside any loop that holds one of the title's own s_barriers is an exchange site too (barrier_blocks).

  • The console's barrier waits for every wave of the group that hasn't ended, so the title brings every live wave there together.
  • The host already lowers that barrier to a group barrier on the same promise.
  • The exchange's barriers therefore go only where a group barrier already is.

Evidence:

  • GPU test: split_wave_tests::a_whole_wave_or_one_lane_puts_in_lds_reaches_the_group_at_its_barrier runs a synthetic program of the culler's shape (written from the description, with its own registers and reduction) in 128-thread groups. The second wave ends early, as a culled wave does, and both host halves hold flags. It reads 6 in wave 0 and the canary in wave 1, and 14 when both waves stay. Without this change it is refused.
  • Offline sweep: I translated 3,338 refused containers dumped from a game run. Two more compute shaders translate (4e2edbd69fe414f1, f44473ebe75e0047); no other outcome changes.

Barrier blocks behind a first-lane branch (review question). Such a branch can precede the block. The console wave takes a branch on an SCC from v_readfirstlane as a whole, so a title may return early before its s_barrier. But each host half computes that SCC from its own first lane, so one half could skip the block while the other waits at the exchange's barrier. barrier_blocks now excludes a block whose reach condition holds such an SCC (split_scc), as wave_blocks does. wave32_tests::a_barrier_block_behind_a_first_lane_branch_is_no_exchange_site shows the case refused; without the exclusion it translated with the exchange. With marcus-4's branch for #254, the exclusion only becomes conservative for compute: the first-lane read is then exact or refused, split_scc is unchanged, and the two compose.

In game (M5 Pro, Series S, warm runs that lived 240 s, target dumps every 15 s from +105 s): before this PR, 255/309/140 culling dispatches were dropped over a run; with the first head (where all three translated) none were. With the merged head, 898d9c1a5605ad81's dispatches still drop. The G-buffer is still almost black, though:

G-buffer lit (max per dump) HDR lit
Before 0–3.5% 0–0.12%
After 0–1.1% 0–0.03%

The culling was necessary, but it isn't the gate any more. About 470 G-buffer draws are still dropped per world frame. The top refusals are:

  • "a descriptor read only as data": 192
  • "a buffer's dword 1": 84
  • lane-mask joins: 66
  • remembered Metal compiler crashes: 37

We're looking at the drawn half next.

Checks (rebased on c1b95875): victory-shader 331 and victory-gpu 317 tests pass. Windows clippy on the workspace is clean with -D warnings, and cargo xtask policy passes. docs/native-host.md (the #182 subsection) and the halves.rs module doc are updated.

**@⁠Olima34** on GitHub · 2026-11-27 05:22 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253) `Olima34:fix/exchange-at-title-barriers` → `main` · +443 −8 · 5 files · 4 commits · merged 2026-11-27 12:04 UTC > **Current head (e3d3ce69):** barrier blocks behind a first-lane branch are excluded, except when that first lane reads an LDS word right after the title's barrier that no reachable write can touch before the next barrier (`barrier_reads`). With that, `4e2edbd69fe414f1` and `f44473ebe75e0047` translate and `898d9c1a5605ad81` stays refused; see the latest comment for the sweep. Follow-up to #245. With both PRs, 5 of the 6 culling compute shaders that write the G-buffer's indirect mesh-draw group counts translate and run (#182); `898d9c1a5605ad81` is still refused. **Shape.** The other three culling shaders (`4e2edbd69fe414f1`, `f44473ebe75e0047`, `898d9c1a5605ad81`) were refused with "a cross-lane operation between host waves in divergent code". Each is a group of two console waves (128 threads), so the lockstep fallback doesn't apply. The shader: 1. ORs a flag over its wave in a whole-wave section; 2. reads lane 63 with EXEC set to lane 0 alone; 3. ORs that value into LDS word 0; 4. reads it back after the title's `s_barrier`. The lane reads cross host waves and need group barriers. Those went only in blocks that every thread runs exactly once. This block is reached by uniform branches, and a culled wave ends early, so the shaders were refused. **Rule added.** A block outside any loop that holds one of the title's own `s_barrier`s is an exchange site too (`barrier_blocks`). - The console's barrier waits for every wave of the group that hasn't ended, so the title brings every live wave there together. - The host already lowers that barrier to a group barrier on the same promise. - The exchange's barriers therefore go only where a group barrier already is. **Evidence:** - **GPU test:** `split_wave_tests::a_whole_wave_or_one_lane_puts_in_lds_reaches_the_group_at_its_barrier` runs a synthetic program of the culler's shape (written from the description, with its own registers and reduction) in 128-thread groups. The second wave ends early, as a culled wave does, and both host halves hold flags. It reads 6 in wave 0 and the canary in wave 1, and 14 when both waves stay. Without this change it is refused. - **Offline sweep:** I translated 3,338 refused containers dumped from a game run. Two more compute shaders translate (`4e2edbd69fe414f1`, `f44473ebe75e0047`); no other outcome changes. **Barrier blocks behind a first-lane branch (review question).** Such a branch can precede the block. The console wave takes a branch on an SCC from `v_readfirstlane` as a whole, so a title may return early before its `s_barrier`. But each host half computes that SCC from its own first lane, so one half could skip the block while the other waits at the exchange's barrier. `barrier_blocks` now excludes a block whose reach condition holds such an SCC (`split_scc`), as `wave_blocks` does. `wave32_tests::a_barrier_block_behind_a_first_lane_branch_is_no_exchange_site` shows the case refused; without the exclusion it translated with the exchange. With marcus-4's branch for #254, the exclusion only becomes conservative for compute: the first-lane read is then exact or refused, `split_scc` is unchanged, and the two compose. **In game** (M5 Pro, Series S, warm runs that lived 240 s, target dumps every 15 s from +105 s): before this PR, 255/309/140 culling dispatches were dropped over a run; with the first head (where all three translated) none were. With the merged head, `898d9c1a5605ad81`'s dispatches still drop. **The G-buffer is still almost black**, though: | | G-buffer lit (max per dump) | HDR lit | |---|---|---| | Before | 0–3.5% | 0–0.12% | | After | 0–1.1% | 0–0.03% | The culling was necessary, but it isn't the gate any more. About 470 G-buffer draws are still dropped per world frame. The top refusals are: - "a descriptor read only as data": 192 - "a buffer's dword 1": 84 - lane-mask joins: 66 - remembered Metal compiler crashes: 37 We're looking at the drawn half next. **Checks** (rebased on c1b95875): victory-shader 331 and victory-gpu 317 tests pass. Windows clippy on the workspace is clean with `-D warnings`, and `cargo xtask policy` passes. `docs/native-host.md` (the #182 subsection) and the `halves.rs` module doc are updated.
The other three G-buffer culling shaders (4e2edbd69fe414f1,
f44473ebe75e0047, 898d9c1a5605ad81) were refused as "a cross-lane
operation between host waves in divergent code". Each is a group of two
console waves (128 threads, so not the lockstep fallback) that ORs a flag
over its wave in a whole-wave section, reads lane 63 with EXEC set to
lane 0 alone, ORs that into LDS word 0 and reads it back after the
title's s_barrier. The lane reads cross the host waves and need group
barriers, which went only in blocks every thread runs exactly once. This
block is reached by uniform branches, and a culled wave ends early.

The title's own barrier in that block already needs every live wave of
the group there together: the console's waits for each wave that has not
ended, and the host lowers it to a group barrier on that same promise. So
a block outside any loop that holds one of the title's s_barriers is an
exchange site too (barrier_blocks).

Test on the GPU: split_wave_tests::a_whole_wave_or_one_lane_puts_in_lds_
reaches_the_group_at_its_barrier runs the title's words in groups of two
console waves, with the second wave ending early and flags in both host
halves. It is refused without this change. Over 3,338 refused containers
dumped from a game run, four more compute shaders translate and no other
outcome changes. With the gather fix before it, all six culling shaders
of the G-buffer's indirect mesh draws now translate (#182).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 05:24:10 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 05:41 UTC · original

This overlaps a local branch of ours that does the same thing for the same three shaders, so thank you; we would rather take yours. One question before merge: the rule says that if any wave reaches the barrier block, every live wave does, but the block is only checked to be outside a cycle and to hold s_barrier. once_blocks and wave_blocks also require that it is reached by uniform branches, because an SCC that comes from v_readfirstlane can differ between the two host halves of one console wave. Can such a branch precede the barrier block? If it can, please exclude it (a hang would be the failure); if it cannot, please say why in the comment on barrier_blocks. Related: #254 (v_readfirstlane_b32 ignores EXEC on a split wave) is in the tails of these same shaders. Please also give the sweep by output fingerprint, and note that #182 is closed and #258 continues it.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 05:41 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7210850809) This overlaps a local branch of ours that does the same thing for the same three shaders, so thank you; we would rather take yours. One question before merge: the rule says that if any wave reaches the barrier block, every live wave does, but the block is only checked to be outside a cycle and to hold `s_barrier`. `once_blocks` and `wave_blocks` also require that it is reached by uniform branches, because an SCC that comes from `v_readfirstlane` can differ between the two host halves of one console wave. Can such a branch precede the barrier block? If it can, please exclude it (a hang would be the failure); if it cannot, please say why in the comment on `barrier_blocks`. Related: #254 (`v_readfirstlane_b32` ignores EXEC on a split wave) is in the tails of these same shaders. Please also give the sweep by output fingerprint, and note that #182 is closed and #258 continues it.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 08:07 UTC · original

Sandile-0511's corpus run (his comment in #258) shows four compute shaders newly translated with this pull request, three of them in the world, and no other output changes, no new refusal. Thank you; that is the comparison by output I asked for.

My question about the barrier block is still open: can a branch whose SCC comes from v_readfirstlane and differs between the two host halves precede the barrier block? If it can, exclude it; if it cannot, say why in the comment on barrier_blocks. The branch is also behind main. Note that marcus-4's branch for #254 changes what a first lane read does in the same shaders, so the answer may depend on it.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 08:07 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7213185729) Sandile-0511's corpus run (his comment in #258) shows four compute shaders newly translated with this pull request, three of them in the world, and no other output changes, no new refusal. Thank you; that is the comparison by output I asked for. My question about the barrier block is still open: can a branch whose SCC comes from `v_readfirstlane` and differs between the two host halves precede the barrier block? If it can, exclude it; if it cannot, say why in the comment on `barrier_blocks`. The branch is also behind main. Note that marcus-4's branch for #254 changes what a first lane read does in the same shaders, so the answer may depend on it.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 08:53 UTC · original

My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1):

4 compute shaders gained (the three cullers f44473ebe75e0047, 4e2edbd69fe414f1, 898d9c1a5605ad81, and 7675b795738af176), nothing lost, no output changed, no hang. Same as Sandile-0511's table. Only the barrier-block question is left.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 08:53 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7214034296) My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1): 4 compute shaders gained (the three cullers f44473ebe75e0047, 4e2edbd69fe414f1, 898d9c1a5605ad81, and 7675b795738af176), nothing lost, no output changed, no hang. Same as Sandile-0511's table. Only the barrier-block question is left.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 09:04 UTC · original

Thanks for the two corpus runs. On the barrier block: we're checking now whether a branch whose SCC comes from v_readfirstlane can precede it.

  • If it can, the block will be excluded, using the same set of first-lane SCC values that once_blocks and wave_blocks rely on, with a test where such a branch comes first and the exchange stays refused.
  • If it can't, the comment on barrier_blocks will say why.

We'll also rebase onto main and check the answer against marcus-4's branch for #254.

**@⁠Olima34** on GitHub · 2026-11-27 09:04 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7214240829) Thanks for the two corpus runs. On the barrier block: we're checking now whether a branch whose SCC comes from `v_readfirstlane` can precede it. - If it can, the block will be excluded, using the same set of first-lane SCC values that `once_blocks` and `wave_blocks` rely on, with a test where such a branch comes first and the exchange stays refused. - If it can't, the comment on `barrier_blocks` will say why. We'll also rebase onto main and check the answer against marcus-4's branch for #254.
github-bot force-pushed github-bot/gh-253 from 8ebef8573a to e3d3ce691c 2026-11-27 10:38:01 +00:00 Compare
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 09:24 UTC · original

Updated (rebased on c1b95875, head a06ac02e):

  • The barrier block: yes, a branch on an SCC from v_readfirstlane can precede it, and such blocks are now excluded through split_scc, as wave_blocks does. Test: wave32_tests::a_barrier_block_behind_a_first_lane_branch_is_no_exchange_site; without the exclusion it translated with the exchange. With marcus-4's #254 branch the two compose: the first-lane read there is exact or refused, and split_scc is unchanged. Details are in the description.
  • A correction on my side: the GPU test in the first revision used a run of the culler's own instructions. That shouldn't have gone in the repo. It is now a synthetic program of the same shape, written from the description, with its own registers and reduction steps. It still fails without the change, and "the title's words" is gone from the code, docs and commit messages. The earlier commit (8ebef857) is no longer on the branch.
**@⁠Olima34** on GitHub · 2026-11-27 09:24 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7214648603) Updated (rebased on c1b95875, head a06ac02e): - **The barrier block:** yes, a branch on an SCC from `v_readfirstlane` can precede it, and such blocks are now excluded through `split_scc`, as `wave_blocks` does. Test: `wave32_tests::a_barrier_block_behind_a_first_lane_branch_is_no_exchange_site`; without the exclusion it translated with the exchange. With marcus-4's #254 branch the two compose: the first-lane read there is exact or refused, and `split_scc` is unchanged. Details are in the description. - **A correction on my side:** the GPU test in the first revision used a run of the culler's own instructions. That shouldn't have gone in the repo. It is now a synthetic program of the same shape, written from the description, with its own registers and reduction steps. It still fails without the change, and "the title's words" is gone from the code, docs and commit messages. The earlier commit (8ebef857) is no longer on the branch.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 09:50 UTC · original

A correction to my update. With the exclusion in the current head (a06ac02e), the three cullers this PR was for are refused again, on main + #263 + #264 + #267 + #278:

  • 898d9c1a5605ad81 at 0xfc4
  • 4e2edbd69fe414f1 at 0xf60
  • f44473ebe75e0047 at 0x1014

All three give "a cross-lane operation between host waves in divergent code". So a branch on an SCC from v_readfirstlane does precede their barrier block, and the hang risk you raised is real for them. Your 09:10Z run used the first head (8ebef857), which accepted them unsafely.

Please don't merge the current head expecting the G-buffer gain. We're looking at whether the first-lane value behind that SCC is provably the same in both host halves of these cullers. If it is, split_scc can leave it out; if not, it needs the exchange #254 is about. I'll update here.

**@⁠Olima34** on GitHub · 2026-11-27 09:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7215168923) A correction to my update. With the exclusion in the current head (a06ac02e), the three cullers this PR was for are refused again, on main + #263 + #264 + #267 + #278: - `898d9c1a5605ad81` at 0xfc4 - `4e2edbd69fe414f1` at 0xf60 - `f44473ebe75e0047` at 0x1014 All three give "a cross-lane operation between host waves in divergent code". So a branch on an SCC from `v_readfirstlane` does precede their barrier block, and the hang risk you raised is real for them. Your 09:10Z run used the first head (8ebef857), which accepted them unsafely. Please don't merge the current head expecting the G-buffer gain. We're looking at whether the first-lane value behind that SCC is provably the same in both host halves of these cullers. If it is, `split_scc` can leave it out; if not, it needs the exchange #254 is about. I'll update here.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 10:17 UTC · original

Update (head e3d3ce69). This fixes the regression I reported: two of the three cullers translate again, safely.

What the cullers do. After the title's barrier, every lane reads LDS word 0 (the group flag) and branches on its first lane. That read is the SCC behind every excluded barrier block in all three cullers.

The rule. Such a first-lane read now splits nothing when all of the following hold:

  • it is a ds_read_b32 at a constant address;
  • it follows one of the title's s_barriers in its block, with no LDS write in between;
  • no LDS write that can follow it before a barrier can touch that word. Writes at constant bytes elsewhere are fine.

The group barrier brings every thread there with the same LDS, and nothing changes the word until all of them have passed the next barrier (barrier_reads). wave_blocks and the mesh joins keep the old rule.

Test. wave32_tests::a_barrier_block_behind_a_branch_on_an_lds_word_read_after_a_barrier covers four cases:

  • the basic case is accepted;
  • a write to another word is accepted;
  • a write to the word before the read is refused;
  • a write to the word before the next barrier is refused.

Sweep. I translated 4,129 refused containers dumped from a run (with the native host's options), and compared each one's outcome and DXIL fingerprint before (a06ac02e) and after:

  • 4e2edbd69fe414f1 and f44473ebe75e0047 now translate.
  • 898d9c1a5605ad81 stays refused. LDS writes at computed addresses can follow its read before the next barrier, so I can't prove they miss the word.
  • The other 4,126 are unchanged.

Checks: victory-shader 332 and victory-gpu 317 tests pass, Windows clippy is clean on the workspace, and cargo xtask policy passes.

Not done yet: a game run with this head. Game runs are paused on our Mac for now (GPU hangs, #79), so I haven't measured G-buffer coverage with it.

**@⁠Olima34** on GitHub · 2026-11-27 10:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7215713521) Update (head e3d3ce69). This fixes the regression I reported: two of the three cullers translate again, safely. **What the cullers do.** After the title's barrier, every lane reads LDS word 0 (the group flag) and branches on its first lane. That read is the SCC behind every excluded barrier block in all three cullers. **The rule.** Such a first-lane read now splits nothing when all of the following hold: - it is a `ds_read_b32` at a constant address; - it follows one of the title's `s_barrier`s in its block, with no LDS write in between; - no LDS write that can follow it before a barrier can touch that word. Writes at constant bytes elsewhere are fine. The group barrier brings every thread there with the same LDS, and nothing changes the word until all of them have passed the next barrier (`barrier_reads`). `wave_blocks` and the mesh joins keep the old rule. **Test.** `wave32_tests::a_barrier_block_behind_a_branch_on_an_lds_word_read_after_a_barrier` covers four cases: - the basic case is accepted; - a write to another word is accepted; - a write to the word before the read is refused; - a write to the word before the next barrier is refused. **Sweep.** I translated 4,129 refused containers dumped from a run (with the native host's options), and compared each one's outcome and DXIL fingerprint before (a06ac02e) and after: - `4e2edbd69fe414f1` and `f44473ebe75e0047` now translate. - `898d9c1a5605ad81` stays refused. LDS writes at computed addresses can follow its read before the next barrier, so I can't prove they miss the word. - The other 4,126 are unchanged. **Checks:** victory-shader 332 and victory-gpu 317 tests pass, Windows clippy is clean on the workspace, and `cargo xtask policy` passes. **Not done yet:** a game run with this head. Game runs are paused on our Mac for now (GPU hangs, #79), so I haven't measured G-buffer coverage with it.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 10:32 UTC · original

Thank you for the straight account, including the correction about the head that accepted the cullers unsafely. My question about the barrier block is answered: yes it can precede it, and the exclusion is in.

What counts for the merge now is the current head, e3d3ce69, which has a new rule. My corpus run (four shaders gained) was on the first head, so it does not apply. Your sweep covers the 4,129 shaders that were refused, so it does not show that the shaders that translate today keep their output. I will run my whole corpus on e3d3ce69 and post the table (gained, regressed, changed per stage); I have not done it yet.

Two questions on the new rule. Does "an LDS write" include atomics and ds_append and ds_consume? And the argument that nothing changes the word until every thread has passed the next barrier: please say what covers the case where one console wave ends early.

Also, a force-push does not remove the old commit from GitHub at once. If 8ebef857 holds the culler's instructions, tell me and I will ask GitHub to remove it.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 10:32 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7216001706) Thank you for the straight account, including the correction about the head that accepted the cullers unsafely. My question about the barrier block is answered: yes it can precede it, and the exclusion is in. What counts for the merge now is the current head, e3d3ce69, which has a new rule. My corpus run (four shaders gained) was on the first head, so it does not apply. Your sweep covers the 4,129 shaders that were refused, so it does not show that the shaders that translate today keep their output. I will run my whole corpus on e3d3ce69 and post the table (gained, regressed, changed per stage); I have not done it yet. Two questions on the new rule. Does "an LDS write" include atomics and `ds_append` and `ds_consume`? And the argument that nothing changes the word until every thread has passed the next barrier: please say what covers the case where one console wave ends early. Also, a force-push does not remove the old commit from GitHub at once. If 8ebef857 holds the culler's instructions, tell me and I will ask GitHub to remove it.
barrier_reads checked only the LDS writes reachable from the read before
the next barrier. Another wave can pass the same group barrier on a path
without the read, or at another s_barrier instruction (a group barrier's
k-th instance pairs every live wave's k-th s_barrier), and write the word
while the two host halves read it: that was accepted with an exchange.

Now each block gets the numbers of barriers a path from the entry can
have passed (barrier_phases: a bit set, any where a loop holds a
barrier). The read must run in one phase n >= 1, and every LDS write of
the program that can run in phase n, on any path, must miss the word
(atomics, ds_append and ds_consume count; writes at constant bytes
elsewhere are fine). Writes of earlier phases, such as the cullers' OR
of their flag before the barrier, are ordered by the barriers around
them. A wave that ends early writes nothing more, and what it wrote
before is in some phase and checked the same way. The read no longer
has to share a block with its barrier.

Test: wave32_tests::a_barrier_block_behind_a_branch_on_an_lds_word_read_
after_a_barrier now also covers an atomic to the word, ds_append, a write
to the word in an earlier phase (accepted), and another wave that passes
the barrier (or its own barrier instruction) on a path without the read,
writes the word and ends (refused; the second was accepted before this
change). Over the 4,129 refused dumped containers the outcome and output
are the same as with the previous rule: 4e2edbd69fe414f1 and
f44473ebe75e0047 translate, nothing else changes.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 10:49 UTC · original

Answers, plus a fix your second question led to. The new head is 834f730c.

1. Atomics, ds_append, ds_consume. Yes, all of them count as LDS writes: every non-GDS DS instruction except ds_read*, ds_swizzle, ds_permute and ds_bpermute.

  • An atomic at a constant address is checked against the word's bytes like a store. Test: ds_or_b32 to the word is refused.
  • ds_append, ds_consume and the addtid forms have no constant address, so they count as touching any word. On a console wave the host splits, ds_append/ds_consume are refused before this rule anyway; the test checks that too.

2. A console wave that ends early, and the gap it revealed. Checking this showed that e3d3ce69 was wrong. It looked only at writes reachable from the read. Another wave can pass a different s_barrier instruction, on a path without the read, then write the word. The console pairs every live wave's k-th barrier, whichever instruction that is. e3d3ce69 accepted such a program, and it is refused now.

The rule now works by barrier phase, not by path:

  • barrier_phases gives each block the set of barrier counts a path from the entry can have passed ("any" where a loop holds a barrier).
  • The read must be in a single phase n ≥ 1.
  • Every LDS write in the program that can run in phase n, on any path and in any wave, must miss the word.

A wave that ends early writes nothing more. What it wrote before ending lies in some phase and is checked the same way. A write in an earlier phase (the cullers OR the flag into word 0 before the barrier) is ordered against the read by the barriers in between. Refusing every write after any barrier instead would refuse the cullers themselves.

Test. wave32_tests::a_barrier_block_behind_a_branch_on_an_lds_word_read_after_a_barrier now covers:

  • accepted: the basic case, a write to another word, and an earlier-phase write;
  • refused: a write to the word before the read, a write to the word before the next barrier, an atomic, ds_append, and another wave writing the word through the same barrier or through its own.

Sweep. On our 4,129 refused containers, the results are identical to e3d3ce69: 4e2edbd69fe414f1 and f44473ebe75e0047 translate with the same DXIL fingerprints, and nothing else changes. Your full-corpus run should use 834f730c rather than e3d3ce69.

Checks: victory-shader 332 and victory-gpu 317 tests pass, Windows clippy is clean, and cargo xtask policy passes.

8ebef857: yes, please ask GitHub to remove it. Its GPU test held about 24 of the culler's instructions verbatim, the block marked "The title's words from here" in split_wave_tests.rs. Sorry about that. The rewritten test is a synthetic program of the same shape.

**@⁠Olima34** on GitHub · 2026-11-27 10:49 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7216348752) Answers, plus a fix your second question led to. The new head is 834f730c. **1. Atomics, `ds_append`, `ds_consume`.** Yes, all of them count as LDS writes: every non-GDS DS instruction except `ds_read*`, `ds_swizzle`, `ds_permute` and `ds_bpermute`. - An atomic at a constant address is checked against the word's bytes like a store. Test: `ds_or_b32` to the word is refused. - `ds_append`, `ds_consume` and the `addtid` forms have no constant address, so they count as touching any word. On a console wave the host splits, `ds_append`/`ds_consume` are refused before this rule anyway; the test checks that too. **2. A console wave that ends early, and the gap it revealed.** Checking this showed that e3d3ce69 was wrong. It looked only at writes reachable from the read. Another wave can pass a *different* `s_barrier` instruction, on a path without the read, then write the word. The console pairs every live wave's k-th barrier, whichever instruction that is. e3d3ce69 accepted such a program, and it is refused now. The rule now works by barrier phase, not by path: - `barrier_phases` gives each block the set of barrier counts a path from the entry can have passed ("any" where a loop holds a barrier). - The read must be in a single phase n ≥ 1. - Every LDS write in the program that can run in phase n, on any path and in any wave, must miss the word. A wave that ends early writes nothing more. What it wrote before ending lies in some phase and is checked the same way. A write in an earlier phase (the cullers OR the flag into word 0 before the barrier) is ordered against the read by the barriers in between. Refusing every write after any barrier instead would refuse the cullers themselves. **Test.** `wave32_tests::a_barrier_block_behind_a_branch_on_an_lds_word_read_after_a_barrier` now covers: - accepted: the basic case, a write to another word, and an earlier-phase write; - refused: a write to the word before the read, a write to the word before the next barrier, an atomic, `ds_append`, and another wave writing the word through the same barrier or through its own. **Sweep.** On our 4,129 refused containers, the results are identical to e3d3ce69: `4e2edbd69fe414f1` and `f44473ebe75e0047` translate with the same DXIL fingerprints, and nothing else changes. Your full-corpus run should use 834f730c rather than e3d3ce69. **Checks:** victory-shader 332 and victory-gpu 317 tests pass, Windows clippy is clean, and `cargo xtask policy` passes. **8ebef857:** yes, please ask GitHub to remove it. Its GPU test held about 24 of the culler's instructions verbatim, the block marked "The title's words from here" in `split_wave_tests.rs`. Sorry about that. The rewritten test is a synthetic program of the same shape.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 11:54 UTC · original

Thank you for the answers, and for catching the case with another wave at a different barrier.

I ran every shader by output on 834f730c: 2 gained (4e2edbd69fe414f1 and f44473ebe75e0047), none lost, none changed, no hang. 898d9c1a5605ad81 is still refused, so the title and description should say 2 of the 3 now; please fix them.

I also ran this head in the game, together with #263, #264 and #278 on main ce2b7860: the 1280x720 G-buffer targets are 60 to 87% covered (31 dumps at 60% or more). The run ended after 238 s in the GPU time-out and title fault we already know, at the same address as before, so that is not from this change.

Two things are left before I merge. The old commit 8ebef857 has to be gone from GitHub; I will say here when it is. And in the new test, WORD_0 and WORD_1 (the two ds_write_b32 words) are the same as in the old one. Please say they are made up for the test and not copied from a shader, or change them.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 11:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7217612317) Thank you for the answers, and for catching the case with another wave at a different barrier. I ran every shader by output on 834f730c: 2 gained (`4e2edbd69fe414f1` and `f44473ebe75e0047`), none lost, none changed, no hang. `898d9c1a5605ad81` is still refused, so the title and description should say 2 of the 3 now; please fix them. I also ran this head in the game, together with #263, #264 and #278 on main ce2b7860: the 1280x720 G-buffer targets are 60 to 87% covered (31 dumps at 60% or more). The run ended after 238 s in the GPU time-out and title fault we already know, at the same address as before, so that is not from this change. Two things are left before I merge. The old commit 8ebef857 has to be gone from GitHub; I will say here when it is. And in the new test, `WORD_0` and `WORD_1` (the two `ds_write_b32` words) are the same as in the old one. Please say they are made up for the test and not copied from a shader, or change them.
github manually merged commit 465db23bcd into main 2026-11-27 12:15:55 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 12:04 UTC · original

Merged. The corpus is clean on 834f730c (2 gained, none lost, none changed) and the game run with it fills the G-buffer. The title and description still say 3 of the 3 cullers; it is 2 now (898d9c1a5605ad81 is still refused), which is worth a follow-up. Thank you @⁠Olima34.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 12:04 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7217801946) Merged. The corpus is clean on 834f730c (2 gained, none lost, none changed) and the game run with it fills the G-buffer. The title and description still say 3 of the 3 cullers; it is 2 now (`898d9c1a5605ad81` is still refused), which is worth a follow-up. Thank you @⁠Olima34.
github-bot changed title from shader: exchange between host waves in a block that holds the title's barrier (the other 3 G-buffer culling shaders, #182) to shader: exchange between host waves in a block that holds the title's barrier (2 of the 3 other G-buffer culling shaders, #182; 898d9c1a5605ad81 is still refused) 2026-11-27 12:49:46 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 12:38 UTC · original

On WORD_0 and WORD_1: they're made up. 0xD834_0000 is the only first dword ds_write_b32 can have at offset 0. The second dwords (address v20/v23, data v22) don't occur in the removed 8ebef857 block. The only words the tests share with it are the lane setup we wrote (v_cmp_eq_u32 against 5/40/70, v_cndmask_b32). Title and description are corrected to 2 of the 3.

**@⁠Olima34** on GitHub · 2026-11-27 12:38 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/253#issuecomment-7218488344) On `WORD_0` and `WORD_1`: they're made up. `0xD834_0000` is the only first dword `ds_write_b32` can have at offset 0. The second dwords (address v20/v23, data v22) don't occur in the removed 8ebef857 block. The only words the tests share with it are the lane setup we wrote (`v_cmp_eq_u32` against 5/40/70, `v_cndmask_b32`). Title and description are corrected to 2 of the 3.
This discussion has been locked. Commenting is limited to contributors.
No description provided.