Shaders: guard mesh output bounds, init all primitives, and omit sync on divergent s_barrier #587

Open
github-bot wants to merge 1 commit from github-bot/gh-587 into main AGit
Owner

@⁠FibbS6 on GitHub · 2026-11-24 05:13 UTC · original
FibbS6:fix/mesh-output-bounds-and-divergent-barrier → main · +167 −17 · 1 files · 1 commits · open

Problem

On NVIDIA D3D12, translated mesh shaders and compute shaders can fault or hang when:

  1. Mesh output vertex/primitive indices exceed declared limits or primitives are left uninitialized.
  2. s_barrier is emitted inside divergent control flow, which deadlocks on 32-lane NVIDIA warps when not all lanes reach the barrier.

Fix

  • Guard mesh output writes against declared bounds and ensure all primitives are initialized.
  • Detect s_barrier instructions inside divergent control flow and omit the full threadgroup execution sync (keeping memory fence semantics).

Verification

  • cargo xtask policy — passed (151 files ok)
  • cargo clippy -p victory-shader --lib -- -D warnings — 0 warnings
  • cargo test -p victory-shader -- --test-threads=1 — 69 passed, 0 failed
**@⁠FibbS6** on GitHub · 2026-11-24 05:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/587) `FibbS6:fix/mesh-output-bounds-and-divergent-barrier` → `main` · +167 −17 · 1 files · 1 commits · open ### Problem On NVIDIA D3D12, translated mesh shaders and compute shaders can fault or hang when: 1. Mesh output vertex/primitive indices exceed declared limits or primitives are left uninitialized. 2. `s_barrier` is emitted inside divergent control flow, which deadlocks on 32-lane NVIDIA warps when not all lanes reach the barrier. ### Fix - Guard mesh output writes against declared bounds and ensure all primitives are initialized. - Detect `s_barrier` instructions inside divergent control flow and omit the full threadgroup execution sync (keeping memory fence semantics). ### Verification - `cargo xtask policy` — passed (`151 files ok`) - `cargo clippy -p victory-shader --lib -- -D warnings` — 0 warnings - `cargo test -p victory-shader -- --test-threads=1` — `69 passed, 0 failed`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:09:20 +00:00
Author
Owner

@⁠ghost on GitHub · 2026-11-24 07:26 UTC · original

In-game data point for 1052a90 on AMD RDNA4 (RX 9060 XT), stacked on #160: without this PR, mesh 792314eae4f7da77 (with pixel 7bdefdfde461f6e3, which #160 makes translate) fills the G-buffer and depth targets almost completely with near-constant values; with it, those targets match the control again (about 5% covered). Numbers: #160

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

**@⁠ghost** on GitHub · 2026-11-24 07:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7124987569) In-game data point for `1052a90` on AMD RDNA4 (RX 9060 XT), stacked on #160: without this PR, mesh `792314eae4f7da77` (with pixel `7bdefdfde461f6e3`, which #160 makes translate) fills the G-buffer and depth targets almost completely with near-constant values; with it, those targets match the control again (about 5% covered). Numbers: https://git.gtahub.st/github/Marvisak--VIctory/pulls/160 AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Author
Owner

@⁠CrooLyyCheck on GitHub · 2026-11-24 10:43 UTC · original

RTX 5080 (native Windows 11, driver 621.24): still DEVICE_HUNG in the world with this PR

I tested 1052a90 merged locally onto main ffe310e (clean merge, nothing else applied). Setup: diag build with VICTORY_D3D12_DRED=1, empty shader cache, Xbox Series 1.0.2.1 (build unknown (b99f876b…)), Series X mode. cargo test --workspace --locked: 342 passed, 0 failed, 6 ignored.

Build Time in the world before the hang Where DRED stops
ffe310e 117 s list 1 of 11, command 289 of 422 (op 42): mesh 37f363f0a5dcd806 / pixel 4a45195a99ac14f7
ffe310e + this PR 33 s (the first mission's title card was on screen) command 166 of 1507 (op 42): mesh 38ad582f523fd7cf / pixel d42a2d8a9d2c954a

Both runs ended in 0x887A0006 with no DRED page fault. Windows logged nvlddmkm event 153 (TDR) both times.

This is one run per build, so the shorter time may be noise. On this card the hang is not fixed, and it still moves between mesh programs, as described in #71.

**@⁠CrooLyyCheck** on GitHub · 2026-11-24 10:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7129160367) **RTX 5080 (native Windows 11, driver 621.24): still `DEVICE_HUNG` in the world with this PR** I tested `1052a90` merged locally onto `main` `ffe310e` (clean merge, nothing else applied). Setup: diag build with `VICTORY_D3D12_DRED=1`, empty shader cache, Xbox Series 1.0.2.1 (`build unknown (b99f876b…)`), Series X mode. `cargo test --workspace --locked`: 342 passed, 0 failed, 6 ignored. | Build | Time in the world before the hang | Where DRED stops | |---|---|---| | `ffe310e` | 117 s | list 1 of 11, `command 289 of 422 (op 42)`: mesh `37f363f0a5dcd806` / pixel `4a45195a99ac14f7` | | `ffe310e` + this PR | 33 s (the first mission's title card was on screen) | `command 166 of 1507 (op 42)`: mesh `38ad582f523fd7cf` / pixel `d42a2d8a9d2c954a` | Both runs ended in `0x887A0006` with no DRED page fault. Windows logged `nvlddmkm` event 153 (TDR) both times. This is one run per build, so the shorter time may be noise. On this card the hang is not fixed, and it still moves between mesh programs, as described in #71.
Author
Owner

@⁠dpalacios69 on GitHub · 2026-11-24 10:46 UTC · original

The mesh bounds guards and multi-pass emitIndices initialization look solid (and @⁠nullmarsh's RX 9060 XT numbers are a great signal). Two questions on the divergent_barriers part (lower.rs:6622–6708):

  1. Over-approximation on SYNC_THREAD_GROUP: divergent_barriers strips SYNC_THREAD_GROUP (bit 0) whenever any divergent branch has one path reaching the barrier and the other reaching End (can_reach[t] && can_bypass[f]). That matches both an early-exit guard (if (lane < N) return; followed by s_barrier + LDS reads) and a divergent loop exit whose back-edge reaches an s_barrier in the loop body. Leaving only the memory fence (mode = 8 | 2) removes threadgroup synchronization and can introduce silent LDS data races.
  2. Scope & test coverage: Could you share what shader pattern motivated stripping SYNC_THREAD_GROUP, and add unit tests covering both the mesh bounds/init guards and divergent_barriers? Since the mesh bounds fix already has real AMD hardware confirmation while divergent_barriers has only been exercised on WARP/existing tests so far, would it make sense to split divergent_barriers into its own PR so the mesh fix can land independently?

Static code review only; AI-assisted.

**@⁠dpalacios69** on GitHub · 2026-11-24 10:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7129220477) The mesh bounds guards and multi-pass `emitIndices` initialization look solid (and @⁠nullmarsh's RX 9060 XT numbers are a great signal). Two questions on the `divergent_barriers` part (`lower.rs:6622–6708`): 1. **Over-approximation on `SYNC_THREAD_GROUP`:** `divergent_barriers` strips `SYNC_THREAD_GROUP` (bit 0) whenever any divergent branch has one path reaching the barrier and the other reaching `End` (`can_reach[t] && can_bypass[f]`). That matches both an early-exit guard (`if (lane < N) return;` followed by `s_barrier` + LDS reads) and a divergent loop exit whose back-edge reaches an `s_barrier` in the loop body. Leaving only the memory fence (`mode = 8 | 2`) removes threadgroup synchronization and can introduce silent LDS data races. 2. **Scope & test coverage:** Could you share what shader pattern motivated stripping `SYNC_THREAD_GROUP`, and add unit tests covering both the mesh bounds/init guards and `divergent_barriers`? Since the mesh bounds fix already has real AMD hardware confirmation while `divergent_barriers` has only been exercised on WARP/existing tests so far, would it make sense to split `divergent_barriers` into its own PR so the mesh fix can land independently? Static code review only; AI-assisted.
Author
Owner

@⁠EduBertozzi on GitHub · 2026-11-24 12:50 UTC · original

On the divergent_barriers part: where the divergence comes from, which may be why the RTX 5080 above still hangs.

On the console, s_barrier is a scalar instruction. A wave runs it whatever EXEC holds, and it skips the block around it only when every lane of the wave is off (s_cbranch_execz). HLSL already requires group barriers in group-uniform control flow. So a barrier the console compiler placed under an EXEC branch is reached by every wave of the group whenever any of its lanes is on.

The divergence comes from our side. The per-lane form turns EXEC into per-lane branches, and on 32-lane hosts a console wave runs as two host waves. If one half has no lane on the path, it skips the barrier that its console wave reaches. divergent_barriers sees the per-lane branch and can't tell that apart from a barrier that is really divergent. Dropping SYNC_THREAD_GROUP there removes the ordering the console relies on, as dpalacios69 noted above: LDS written before the barrier, by other waves or by the other half, isn't guaranteed to be there after it. That makes it a data race instead of a hang. Every mesh program in the title is wave64 (per the shaders.rpf count on #578), so on NVIDIA this applies to all of them.

What would keep both, ordering and no hang, is running such programs so that both halves take every branch together: #439's console flow. That works for compute today in groups of up to 64 threads. Mesh shaders can't declare a wave size, which is why I'm prototyping a compute form of mesh programs (#3) that could use it. On #778 I've asked for a census of the title's mesh group sizes to see whether they fit.

So +1 to splitting. The bounds and initialization guards have hardware evidence (RX 9060 XT above) and could land on their own. The barrier change would need a test where a lane-dependent if guards an s_barrier with LDS written before it and read after it. That test would show the race this form allows.

AI-assisted (Claude Code); reasoning from the code and the console's ISA semantics, not a title run.

**@⁠EduBertozzi** on GitHub · 2026-11-24 12:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7131985194) On the `divergent_barriers` part: where the divergence comes from, which may be why the RTX 5080 above still hangs. On the console, `s_barrier` is a scalar instruction. A wave runs it whatever EXEC holds, and it skips the block around it only when *every* lane of the wave is off (`s_cbranch_execz`). HLSL already requires group barriers in group-uniform control flow. So a barrier the console compiler placed under an EXEC branch is reached by every wave of the group whenever any of its lanes is on. The divergence comes from our side. The per-lane form turns EXEC into per-lane branches, and on 32-lane hosts a console wave runs as two host waves. If one half has no lane on the path, it skips the barrier that its console wave reaches. `divergent_barriers` sees the per-lane branch and can't tell that apart from a barrier that is really divergent. Dropping `SYNC_THREAD_GROUP` there removes the ordering the console relies on, as dpalacios69 noted above: LDS written before the barrier, by other waves or by the other half, isn't guaranteed to be there after it. That makes it a data race instead of a hang. Every mesh program in the title is wave64 (per the `shaders.rpf` count on #578), so on NVIDIA this applies to all of them. What would keep both, ordering and no hang, is running such programs so that both halves take every branch together: #439's console flow. That works for compute today in groups of up to 64 threads. Mesh shaders can't declare a wave size, which is why I'm prototyping a compute form of mesh programs (#3) that could use it. On #778 I've asked for a census of the title's mesh group sizes to see whether they fit. So +1 to splitting. The bounds and initialization guards have hardware evidence (RX 9060 XT above) and could land on their own. The barrier change would need a test where a lane-dependent `if` guards an `s_barrier` with LDS written before it and read after it. That test would show the race this form allows. AI-assisted (Claude Code); reasoning from the code and the console's ISA semantics, not a title run.
Author
Owner

@⁠Ilokaxt on GitHub · 2026-11-24 13:10 UTC · original

On an RTX 3070 Ti Laptop (wave lanes 32..32, NVIDIA driver 610.88, Windows 11 build 26300) this PR removes the world hang in wave64 mesh programs, without skipping them.

Tree: main ffe310e + #439 + #431 + #579 + this PR, plus a local fix that creates the device on the high-performance adapter. Diagnostics build, VICTORY_SHADER_LOOP_LIMIT=1000, DRED on, scripted Enter presses, 420 s.

world draws kept per frame (median) world fps device removed
without this PR, VICTORY_SKIP_WAVE64=mesh 352 0.4 no
without this PR, mesh programs enabled – – yes, in the world (see #778)
with this PR, mesh programs enabled 1746 0.5–0.7 no, in 420 s

The opening credits render correctly in the world. The run ended still inside the credits, so I have not seen the scene behind them yet.

**@⁠Ilokaxt** on GitHub · 2026-11-24 13:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7132447942) On an **RTX 3070 Ti Laptop** (wave lanes 32..32, NVIDIA driver 610.88, Windows 11 build 26300) this PR removes the world hang in wave64 mesh programs, **without skipping them**. Tree: `main` `ffe310e` + #439 + #431 + #579 + this PR, plus a local fix that creates the device on the high-performance adapter. Diagnostics build, `VICTORY_SHADER_LOOP_LIMIT=1000`, DRED on, scripted Enter presses, 420 s. | | world draws kept per frame (median) | world fps | device removed | |---|---|---|---| | without this PR, `VICTORY_SKIP_WAVE64=mesh` | 352 | 0.4 | no | | without this PR, mesh programs enabled | – | – | yes, in the world (see #778) | | **with this PR, mesh programs enabled** | **1746** | 0.5–0.7 | **no, in 420 s** | The opening credits render correctly in the world. The run ended still inside the credits, so I have not seen the scene behind them yet.
Author
Owner

@⁠Ilokaxt on GitHub · 2026-11-24 13:40 UTC · original

Correction to my note above: two longer runs (900 s budget) with the same tree (main ffe310e + #439 + #431 + #579 + #587, mesh programs enabled) did hang, in a mesh dispatch each time:

  • at 296 s: DRED stopped at DispatchMesh(159), mesh 4adfa13bea1c556a, the same program and dispatch that hangs without #587;
  • at 479 s: DRED stopped at DispatchMesh(1), mesh 18bbb989c875c8fb.

My 420 s run had simply not reached them. So #587 does not remove the mesh hangs on the RTX 3070 Ti. It only let the world run longer with the mesh programs enabled (about 1,400–2,000 draws kept per frame) before one of them hangs. Sorry for the noise.

**@⁠Ilokaxt** on GitHub · 2026-11-24 13:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7133160932) **Correction to my note above:** two longer runs (900 s budget) with the same tree (`main` `ffe310e` + #439 + #431 + #579 + #587, mesh programs enabled) **did hang**, in a mesh dispatch each time: - at 296 s: DRED stopped at `DispatchMesh(159)`, **mesh `4adfa13bea1c556a`**, the same program and dispatch that hangs without #587; - at 479 s: DRED stopped at `DispatchMesh(1)`, **mesh `18bbb989c875c8fb`**. My 420 s run had simply not reached them. So #587 does not remove the mesh hangs on the RTX 3070 Ti. It only let the world run longer with the mesh programs enabled (about 1,400–2,000 draws kept per frame) before one of them hangs. Sorry for the noise.
Author
Owner

@⁠Yaekai on GitHub · 2026-11-24 15:55 UTC · original

Independent verification on Windows 11 + NVIDIA RTX 3070 (Ampere, Wave32, Rust 1.98.1) at head 1052a90:

  • cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests: 62 passed, 0 failed.
  • cargo clippy -p victory-shader -- -D warnings: 0 warnings.
  • Live GTA VI (1.0.2.1, --console series-s, release build on ffe310e + #587 + #452 with VICTORY_SHADER_LOOP_LIMIT=1024 + #493 + #211 + #492): stayed up in the 3D world for 19+ minutes (~2,300 draws/frame, ~120–215 ms GPU/frame) with 0 DXGI_ERROR_DEVICE_HUNG removals (closed manually).

Code review of emitIndices multi-pass init, mesh export bounds guards, and divergent_barriers (fence_only_barrier omitting SYNC_THREAD_GROUP while keeping the memory fence) looks solid. Ready to merge once rebased on main.

**@⁠Yaekai** on GitHub · 2026-11-24 15:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7136837565) Independent verification on Windows 11 + NVIDIA RTX 3070 (Ampere, Wave32, Rust 1.98.1) at head `1052a90`: - `cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests`: 62 passed, 0 failed. - `cargo clippy -p victory-shader -- -D warnings`: 0 warnings. - Live GTA VI (`1.0.2.1`, `--console series-s`, release build on `ffe310e` + `#587` + `#452` with `VICTORY_SHADER_LOOP_LIMIT=1024` + `#493` + `#211` + `#492`): stayed up in the 3D world for **19+ minutes** (~2,300 draws/frame, ~120–215 ms GPU/frame) with **0 `DXGI_ERROR_DEVICE_HUNG` removals** (closed manually). Code review of `emitIndices` multi-pass init, mesh export bounds guards, and `divergent_barriers` (`fence_only_barrier` omitting `SYNC_THREAD_GROUP` while keeping the memory fence) looks solid. Ready to merge once rebased on `main`.
Author
Owner

@⁠justlovett0 on GitHub · 2026-11-24 18:48 UTC · original

Verified + integrated. Stack: main ffe310e + #175/#994/#747/#302/#193/#704/#309/#953/#1067/#986/#1260/#1267/#1254/#1276/#189 (wave64 emulation), RTX 3080 10 GB / Win10 21H2 (19044.7846) / driver 621.24 (32.0.16.2124). Re-census of captured runtime containers; world stable ~9 min, 0 device removals.

Mesh output bounds / primitive init / divergent-barrier sync merged cleanly. Our runtime mesh emission is 4/31 (the mesh refusals are descriptor-class, not output-bounds), so no runtime delta here, but the fix is sound and carries no regression.

AI use: Qwen Code; local measurements. No game data posted.

**@⁠justlovett0** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7141180867) **Verified + integrated.** Stack: main `ffe310e` + #175/#994/#747/#302/#193/#704/#309/#953/#1067/#986/#1260/#1267/#1254/#1276/#189 (wave64 emulation), RTX 3080 10 GB / Win10 21H2 (19044.7846) / driver 621.24 (32.0.16.2124). Re-census of captured runtime containers; world stable ~9 min, 0 device removals. Mesh output bounds / primitive init / divergent-barrier sync merged cleanly. Our runtime mesh emission is 4/31 (the mesh refusals are descriptor-class, not output-bounds), so no runtime delta here, but the fix is sound and carries no regression. AI use: Qwen Code; local measurements. No game data posted.
Author
Owner

@⁠contatopablow-spec on GitHub · 2026-11-24 18:54 UTC · original · edited 2026-11-24 20:25 UTC

CPU-only regression for divergent_barriers at 1052a90a407242812ea02caffe806b92c5f462ae.

The existing reachability test can classify a barrier after reconvergence as divergent even when only a subsequent uniform branch controls whether it executes. Both arms of the earlier split reach the same join; the later uniform bypass supplies both the reach and bypass routes, so the classifier incorrectly attributes the decision to the earlier divergent split.

Add this test inside emit/lower.rs's existing mod tests (uses its existing ir and structure imports):

#[test]
fn divergent_barriers_after_reconvergence_with_uniform_bypass() {
    let words: [u32; 9] = [
        0x7D84_0080, // v_cmp_eq_u32 vcc, 0, v0
        0xBE80_3C6A, // s_and_saveexec_b32 s0, vcc_lo
        0xBF88_0001, // s_cbranch_execz -> 16
        0x7E02_0280, // v_mov_b32 v1, 0
        0x887E_007E, // restore exec_lo
        0xBF06_0302, // s_cmp_eq_u32 s2, s3
        0xBF85_0001, // s_cbranch_scc1 -> 32
        0xBF8A_0000, // s_barrier
        0xBF81_0000, // s_endpgm
    ];
    let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
    let p = ir::build(&code, false, 256).unwrap();
    let st = structure::structure(&p).unwrap();
    let classified = super::divergent_barriers(&p, &st, &Default::default());
    assert!(classified.is_empty(), "classified {classified:?}");
}

cargo test -p victory-shader --locked --offline --lib divergent_barriers_after_reconvergence_with_uniform_bypass -- --nocapture

Expected {}, actual {3} on repeated runs. Three contrast cases on the original classifier passed: a barrier in one arm, a divergent early exit, and an SCC branch depending on a lane-dependent scalar write after reconvergence. In the last case the word sequence is [0xBE82_0380, 0x7D84_0080, 0xBE80_3C6A, 0xBF88_0001, 0xBE82_0381, 0x887E_007E, 0xBF06_8002, 0xBF85_0001, 0xBF8A_0000, 0xBF81_0000]; the expected classification is {3}.

A proposed direct-forward-join filter passed the first three cases but failed the lane-dependent SCC case, so we reverted it. Reconvergence alone is insufficient: scalar definitions merged into a lane-varying phi can affect the subsequent SCC decision despite its Uniform classification. This supports splitting mesh guards from the barrier heuristic, and treating uniformity/control dependence together. No proposed production fix yet.

Validation on Rust 1.98.1 / Windows: 5 existing structure tests passed, targeted Clippy (--lib --tests -D warnings) passed, asset policy passed (151 files), diff check passed. Workspace formatting check reports pre-existing differences. The mesh differential test skipped because the console compiler was unavailable. No GPU workload or gameplay was run; all added instruction sequences are synthetic. AI-assisted testing/review/reporting (ChatGPT and Codex).


Update Ôö£├ÂÔö£├ºÔö£├é fully defined constant-PHI reproduction (2026-11-24): The initial fixture compares entry SGPRs s2/s3, whose group-uniformity is not established just by their register class. The following stronger CPU-only fixture avoids that assumption entirely. Both lane-selected incoming definitions of s2 explicitly equal zero; s_cmp_eq_u32 s2, 1 is therefore false on both paths, and after reconvergence all lanes in this acyclic model fall through to the barrier.

Use the same ir::build, structure::structure and divergent_barriers assertion as above, with this exact replacement word sequence:

let words: [u32; 10] = [
    0xBE82_0380, // s_mov_b32 s2, 0
    0x7D84_0080, // v_cmp_eq_u32 vcc, 0, v0
    0xBE80_3C6A, // s_and_saveexec_b32 s0, vcc_lo
    0xBF88_0001, // s_cbranch_execz -> 20
    0xBE82_0380, // s_mov_b32 s2, 0
    0x887E_007E, // restore exec_lo
    0xBF06_8102, // s_cmp_eq_u32 s2, 1
    0xBF85_0001, // s_cbranch_scc1 -> 36
    0xBF8A_0000, // s_barrier
    0xBF81_0000, // s_endpgm
];

On the same PR head 1052a90, cargo test --offline --locked -p victory-shader --lib divergent_barriers_equal_constant_phi_after_reconvergence -- --nocapture --test-threads=1 failed with equal constants after reconvergence; classified {3} (exit 101). The existing unequal-PHI/SCC contrast test passed (exit 0).

A separate test-only SSA proof experiment distinguished equal constants from unequal lane-selected PHIs and declined to prove unknown inputs or cyclic dependencies group-uniform. All 3 new proof tests and all 9 structure tests passed in that isolated copy. This is not a production fix: group-wide value uniformity and dynamic barrier participation both require proof. In particular, wave-uniform resource tracing (#1231) is not by itself sufficient for a group barrier. No game data or GPU dispatch used. AI-assisted (ChatGPT/Codex).


Follow-up candidate for #587 (based exactly on 1052a90a407242812ea02caffe806b92c5f462ae): github.com/contatopablow-spec/VIctory@82c7739e5a

The patch only restores a previously omitted thread-group sync when all paths in the acyclic structured lane CFG must execute the barrier. Constant SCC decisions are proved using a limited SSA whitelist (ordinary scalar moves/equality comparisons, explicit integer constants, equal constant PHI inputs). Unknown branches retain both edges; backedges and indirect exits are rejected. Restoration is limited to thread-group stages without whole-wave substitution or PHI retry state. No global Atom::Uniform change.

Validation on pinned PR head: focused CPU tests RED 3 passed/2 failed, GREEN 7/7 (independently repeated in the publication worktree); workspace 272 passed, 0 failed, 4 existing ignores. Shader crate all-target/all-feature Clippy, changed-file rustfmt, asset policy, staged policy and diff checks passed. Both workspace Clippy variants still fail on pre-existing lints in unchanged victory-gpu/src/host.rs:267 and victory-hle/src/modules/xmem.rs:747. The prior unknown-entry-SGPR fixture now explicitly expects fence-only: scalar register class is not proof of group scope.

Independent review added taken-edge coverage and a thread-group-stage restriction. This is a conservative review candidate, not a claim that the original classifier is sound for unknown-SCC-only bypasses, nor a gameplay fix. The new barrier regressions are CPU-only; serialized DXIL barrier flags and GPU runtime participation remain unverified. No proprietary game data. AI-assisted implementation, tests and review (ChatGPT/Codex).

Sharing the exact incremental commit here rather than opening a duplicate PR against upstream main; it can be reviewed or cherry-picked onto this PR's branch if useful.


DXIL A/B verification ÔÇö serialized barrier mode confirmed. Same synthetic s2 PHI fixture with [numthreads(64,1,1)] and real dx.op.threadIdInGroup input, using s_cmp_eq_u32 s2, 1 followed by s_cbranch_scc1 (equal arm writes 0, unequal arm writes 1). Temporary test-only harness invokes the actual lower pipeline, saves synthetic DXIL outside the repository, validates via the Windows SDK dxil.dll 1.9.2602.17, and disassembles via matching dxc.exe -dumpbin.

Fixture Original PR head 1052a90 Candidate 82c7739
Equal constant PHI (0/0) dx.op.barrier(80, 8) dx.op.barrier(80, 9)
Unequal lane-selected PHI (0/1) dx.op.barrier(80, 8) dx.op.barrier(80, 8)

All four emitted containers passed the SDK validator; both harness runs exited 0 and all four dumpbin calls exited 0. Full disassembly diff for the equal case changes only the barrier mode operand, and the unequal case is byte-identical (SHA-256 AE6679D8171A9914F07437327F071ED33D1912D04C9EB3A93FE48B207903E2AA). Mode 8 is TGSMFence; mode 9 adds SyncThreadGroup (1), consistent with https://microsoft.github.io/DirectX-Specs/d3d/WorkGraphs.html .

This closes the serialized-DXIL verification gap noted above for these synthetic compute fixtures. It does not validate dynamic GPU execution, mesh-specific lowering, UAV fences, or gameplay. No GPU dispatch, no game assets, no additional production changes. AI-assisted testing (ChatGPT).


Additional DXIL A/B: LDS + UAV memory fences. Extended the synthetic compute fixture to 64 threads, 512 bytes of LDS, per-lane LDS writes and reads, and raw UAV stores at per-lane byte offsets. Compared original PR head 1052a90 with published candidate 82c7739. Both test harnesses exited 0; all four emitted containers passed SDK dxil.dll 1.9.2602.17 validation and dxc -dumpbin. Equal PHI: barrier mode 10 -> 11. Unequal PHI: 10 -> 10. Full equal-case disassembly differs only in the barrier operand; unequal-case DXIL is byte-identical (SHA-256 A14BAC805712FDB4C0A358CADF54892EFA078600C7812C5A2BABB01A3E60FFEE). Modes 10/11 preserve global UAV and TGSM fences; 11 adds group synchronization, per https://microsoft.github.io/DirectX-Specs/d3d/WorkGraphs.html . This validates emitted flags and container acceptance, not GPU runtime or cross-lane memory visibility. No GPU dispatch, proprietary game data, or changes to the published candidate. Temporary synthetic test harness only. AI-assisted (ChatGPT).

**@⁠contatopablow-spec** on GitHub · 2026-11-24 18:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7141330070) · edited 2026-11-24 20:25 UTC CPU-only regression for `divergent_barriers` at `1052a90a407242812ea02caffe806b92c5f462ae`. The existing reachability test can classify a barrier after reconvergence as divergent even when only a subsequent uniform branch controls whether it executes. Both arms of the earlier split reach the same join; the later uniform bypass supplies both the reach and bypass routes, so the classifier incorrectly attributes the decision to the earlier divergent split. Add this test inside `emit/lower.rs`'s existing `mod tests` (uses its existing `ir` and `structure` imports): ```rust #[test] fn divergent_barriers_after_reconvergence_with_uniform_bypass() { let words: [u32; 9] = [ 0x7D84_0080, // v_cmp_eq_u32 vcc, 0, v0 0xBE80_3C6A, // s_and_saveexec_b32 s0, vcc_lo 0xBF88_0001, // s_cbranch_execz -> 16 0x7E02_0280, // v_mov_b32 v1, 0 0x887E_007E, // restore exec_lo 0xBF06_0302, // s_cmp_eq_u32 s2, s3 0xBF85_0001, // s_cbranch_scc1 -> 32 0xBF8A_0000, // s_barrier 0xBF81_0000, // s_endpgm ]; let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect(); let p = ir::build(&code, false, 256).unwrap(); let st = structure::structure(&p).unwrap(); let classified = super::divergent_barriers(&p, &st, &Default::default()); assert!(classified.is_empty(), "classified {classified:?}"); } ``` `cargo test -p victory-shader --locked --offline --lib divergent_barriers_after_reconvergence_with_uniform_bypass -- --nocapture` Expected `{}`, actual `{3}` on repeated runs. Three contrast cases on the original classifier passed: a barrier in one arm, a divergent early exit, and an SCC branch depending on a lane-dependent scalar write after reconvergence. In the last case the word sequence is `[0xBE82_0380, 0x7D84_0080, 0xBE80_3C6A, 0xBF88_0001, 0xBE82_0381, 0x887E_007E, 0xBF06_8002, 0xBF85_0001, 0xBF8A_0000, 0xBF81_0000]`; the expected classification is `{3}`. A proposed direct-forward-join filter passed the first three cases but failed the lane-dependent SCC case, so we reverted it. Reconvergence alone is insufficient: scalar definitions merged into a lane-varying phi can affect the subsequent SCC decision despite its `Uniform` classification. This supports splitting mesh guards from the barrier heuristic, and treating uniformity/control dependence together. No proposed production fix yet. Validation on Rust 1.98.1 / Windows: 5 existing structure tests passed, targeted Clippy (`--lib --tests -D warnings`) passed, asset policy passed (151 files), diff check passed. Workspace formatting check reports pre-existing differences. The mesh differential test skipped because the console compiler was unavailable. No GPU workload or gameplay was run; all added instruction sequences are synthetic. AI-assisted testing/review/reporting (ChatGPT and Codex). --- **Update Ôö£├ÂÔö£├ºÔö£├é fully defined constant-PHI reproduction (2026-11-24):** The initial fixture compares entry SGPRs `s2`/`s3`, whose group-uniformity is not established just by their register class. The following stronger CPU-only fixture avoids that assumption entirely. Both lane-selected incoming definitions of `s2` explicitly equal zero; `s_cmp_eq_u32 s2, 1` is therefore false on both paths, and after reconvergence all lanes in this acyclic model fall through to the barrier. Use the same `ir::build`, `structure::structure` and `divergent_barriers` assertion as above, with this exact replacement word sequence: ```rust let words: [u32; 10] = [ 0xBE82_0380, // s_mov_b32 s2, 0 0x7D84_0080, // v_cmp_eq_u32 vcc, 0, v0 0xBE80_3C6A, // s_and_saveexec_b32 s0, vcc_lo 0xBF88_0001, // s_cbranch_execz -> 20 0xBE82_0380, // s_mov_b32 s2, 0 0x887E_007E, // restore exec_lo 0xBF06_8102, // s_cmp_eq_u32 s2, 1 0xBF85_0001, // s_cbranch_scc1 -> 36 0xBF8A_0000, // s_barrier 0xBF81_0000, // s_endpgm ]; ``` On the same PR head `1052a90`, `cargo test --offline --locked -p victory-shader --lib divergent_barriers_equal_constant_phi_after_reconvergence -- --nocapture --test-threads=1` failed with `equal constants after reconvergence; classified {3}` (exit 101). The existing unequal-PHI/SCC contrast test passed (exit 0). A separate test-only SSA proof experiment distinguished equal constants from unequal lane-selected PHIs and declined to prove unknown inputs or cyclic dependencies group-uniform. All 3 new proof tests and all 9 structure tests passed in that isolated copy. This is not a production fix: group-wide value uniformity and dynamic barrier participation both require proof. In particular, wave-uniform resource tracing (#1231) is not by itself sufficient for a group barrier. No game data or GPU dispatch used. AI-assisted (ChatGPT/Codex). --- Follow-up candidate for #587 (based exactly on `1052a90a407242812ea02caffe806b92c5f462ae`): https://github.com/contatopablow-spec/VIctory/commit/82c7739e5a28bf3bf4d7db753efb723477acc456 The patch only restores a previously omitted thread-group sync when all paths in the acyclic structured lane CFG must execute the barrier. Constant SCC decisions are proved using a limited SSA whitelist (ordinary scalar moves/equality comparisons, explicit integer constants, equal constant PHI inputs). Unknown branches retain both edges; backedges and indirect exits are rejected. Restoration is limited to thread-group stages without whole-wave substitution or PHI retry state. No global `Atom::Uniform` change. Validation on pinned PR head: focused CPU tests RED 3 passed/2 failed, GREEN 7/7 (independently repeated in the publication worktree); workspace 272 passed, 0 failed, 4 existing ignores. Shader crate all-target/all-feature Clippy, changed-file rustfmt, asset policy, staged policy and diff checks passed. Both workspace Clippy variants still fail on pre-existing lints in unchanged `victory-gpu/src/host.rs:267` and `victory-hle/src/modules/xmem.rs:747`. The prior unknown-entry-SGPR fixture now explicitly expects fence-only: scalar register class is not proof of group scope. Independent review added taken-edge coverage and a thread-group-stage restriction. This is a conservative review candidate, not a claim that the original classifier is sound for unknown-SCC-only bypasses, nor a gameplay fix. The new barrier regressions are CPU-only; serialized DXIL barrier flags and GPU runtime participation remain unverified. No proprietary game data. AI-assisted implementation, tests and review (ChatGPT/Codex). Sharing the exact incremental commit here rather than opening a duplicate PR against upstream main; it can be reviewed or cherry-picked onto this PR's branch if useful. --- **DXIL A/B verification ÔÇö serialized barrier mode confirmed.** Same synthetic `s2` PHI fixture with `[numthreads(64,1,1)]` and real `dx.op.threadIdInGroup` input, using `s_cmp_eq_u32 s2, 1` followed by `s_cbranch_scc1` (equal arm writes 0, unequal arm writes 1). Temporary test-only harness invokes the actual `lower` pipeline, saves synthetic DXIL outside the repository, validates via the Windows SDK `dxil.dll` 1.9.2602.17, and disassembles via matching `dxc.exe -dumpbin`. | Fixture | Original PR head `1052a90` | Candidate `82c7739` | |---|---|---| | Equal constant PHI (0/0) | `dx.op.barrier(80, 8)` | `dx.op.barrier(80, 9)` | | Unequal lane-selected PHI (0/1) | `dx.op.barrier(80, 8)` | `dx.op.barrier(80, 8)` | All four emitted containers passed the SDK validator; both harness runs exited 0 and all four dumpbin calls exited 0. Full disassembly diff for the equal case changes only the barrier mode operand, and the unequal case is byte-identical (SHA-256 `AE6679D8171A9914F07437327F071ED33D1912D04C9EB3A93FE48B207903E2AA`). Mode 8 is `TGSMFence`; mode 9 adds `SyncThreadGroup` (1), consistent with https://microsoft.github.io/DirectX-Specs/d3d/WorkGraphs.html . This closes the serialized-DXIL verification gap noted above for these synthetic compute fixtures. It does not validate dynamic GPU execution, mesh-specific lowering, UAV fences, or gameplay. No GPU dispatch, no game assets, no additional production changes. AI-assisted testing (ChatGPT). --- **Additional DXIL A/B: LDS + UAV memory fences.** Extended the synthetic compute fixture to 64 threads, 512 bytes of LDS, per-lane LDS writes and reads, and raw UAV stores at per-lane byte offsets. Compared original PR head `1052a90` with published candidate `82c7739`. Both test harnesses exited 0; all four emitted containers passed SDK dxil.dll 1.9.2602.17 validation and dxc -dumpbin. Equal PHI: barrier mode 10 -> 11. Unequal PHI: 10 -> 10. Full equal-case disassembly differs only in the barrier operand; unequal-case DXIL is byte-identical (SHA-256 `A14BAC805712FDB4C0A358CADF54892EFA078600C7812C5A2BABB01A3E60FFEE`). Modes 10/11 preserve global UAV and TGSM fences; 11 adds group synchronization, per https://microsoft.github.io/DirectX-Specs/d3d/WorkGraphs.html . This validates emitted flags and container acceptance, not GPU runtime or cross-lane memory visibility. No GPU dispatch, proprietary game data, or changes to the published candidate. Temporary synthetic test harness only. AI-assisted (ChatGPT).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:28 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/587#issuecomment-7148552583) <!-- victory-triage v1 head=1052a90a407242812ea02caffe806b92c5f462ae verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/587/head:github-bot/gh-587'
git switch 'github-bot/gh-587'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-587'
git switch 'github-bot/gh-587'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-587'
git switch 'github-bot/gh-587'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-587'
git switch 'main'
git merge --squash 'github-bot/gh-587'
git switch 'main'
git merge --ff-only 'github-bot/gh-587'
git switch 'main'
git merge 'github-bot/gh-587'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!587
No description provided.