Shaders: guard mesh output bounds, init all primitives, and omit sync on divergent s_barrier #587
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!587
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-587"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 · openProblem
On NVIDIA D3D12, translated mesh shaders and compute shaders can fault or hang when:
s_barrieris emitted inside divergent control flow, which deadlocks on 32-lane NVIDIA warps when not all lanes reach the barrier.Fix
s_barrierinstructions 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 warningscargo test -p victory-shader -- --test-threads=1—69 passed, 0 failed@ghost on GitHub · 2026-11-24 07:26 UTC · original
In-game data point for
1052a90on AMD RDNA4 (RX 9060 XT), stacked on #160: without this PR, mesh792314eae4f7da77(with pixel7bdefdfde461f6e3, 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: #160AI-assisted (Claude Code, Claude Opus 5.5); no game data.
@CrooLyyCheck on GitHub · 2026-11-24 10:43 UTC · original
RTX 5080 (native Windows 11, driver 621.24): still
DEVICE_HUNGin the world with this PRI tested
1052a90merged locally ontomainffe310e(clean merge, nothing else applied). Setup: diag build withVICTORY_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.ffe310ecommand 289 of 422 (op 42): mesh37f363f0a5dcd806/ pixel4a45195a99ac14f7ffe310e+ this PRcommand 166 of 1507 (op 42): mesh38ad582f523fd7cf/ pixeld42a2d8a9d2c954aBoth runs ended in
0x887A0006with no DRED page fault. Windows loggednvlddmkmevent 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.
@dpalacios69 on GitHub · 2026-11-24 10:46 UTC · original
The mesh bounds guards and multi-pass
emitIndicesinitialization look solid (and @nullmarsh's RX 9060 XT numbers are a great signal). Two questions on thedivergent_barrierspart (lower.rs:6622–6708):SYNC_THREAD_GROUP:divergent_barriersstripsSYNC_THREAD_GROUP(bit 0) whenever any divergent branch has one path reaching the barrier and the other reachingEnd(can_reach[t] && can_bypass[f]). That matches both an early-exit guard (if (lane < N) return;followed bys_barrier+ LDS reads) and a divergent loop exit whose back-edge reaches ans_barrierin the loop body. Leaving only the memory fence (mode = 8 | 2) removes threadgroup synchronization and can introduce silent LDS data races.SYNC_THREAD_GROUP, and add unit tests covering both the mesh bounds/init guards anddivergent_barriers? Since the mesh bounds fix already has real AMD hardware confirmation whiledivergent_barriershas only been exercised on WARP/existing tests so far, would it make sense to splitdivergent_barriersinto its own PR so the mesh fix can land independently?Static code review only; AI-assisted.
@EduBertozzi on GitHub · 2026-11-24 12:50 UTC · original
On the
divergent_barrierspart: where the divergence comes from, which may be why the RTX 5080 above still hangs.On the console,
s_barrieris 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_barrierssees the per-lane branch and can't tell that apart from a barrier that is really divergent. DroppingSYNC_THREAD_GROUPthere 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 theshaders.rpfcount 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
ifguards ans_barrierwith 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.
@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:
mainffe310e+ #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.VICTORY_SKIP_WAVE64=meshThe 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:40 UTC · original
Correction to my note above: two longer runs (900 s budget) with the same tree (
mainffe310e+ #439 + #431 + #579 + #587, mesh programs enabled) did hang, in a mesh dispatch each time:DispatchMesh(159), mesh4adfa13bea1c556a, the same program and dispatch that hangs without #587;DispatchMesh(1), mesh18bbb989c875c8fb.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.
@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.1.0.2.1,--console series-s, release build onffe310e+#587+#452withVICTORY_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 0DXGI_ERROR_DEVICE_HUNGremovals (closed manually).Code review of
emitIndicesmulti-pass init, mesh export bounds guards, anddivergent_barriers(fence_only_barrieromittingSYNC_THREAD_GROUPwhile keeping the memory fence) looks solid. Ready to merge once rebased onmain.@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.
@contatopablow-spec on GitHub · 2026-11-24 18:54 UTC · original · edited 2026-11-24 20:25 UTC
CPU-only regression for
divergent_barriersat1052a90a407242812ea02caffe806b92c5f462ae.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 existingmod tests(uses its existingirandstructureimports):cargo test -p victory-shader --locked --offline --lib divergent_barriers_after_reconvergence_with_uniform_bypass -- --nocaptureExpected
{}, 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
Uniformclassification. 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 ofs2explicitly equal zero;s_cmp_eq_u32 s2, 1is 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::structureanddivergent_barriersassertion as above, with this exact replacement word sequence:On the same PR head
1052a90,cargo test --offline --locked -p victory-shader --lib divergent_barriers_equal_constant_phi_after_reconvergence -- --nocapture --test-threads=1failed withequal 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@82c7739e5aThe 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::Uniformchange.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:267andvictory-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
s2PHI fixture with[numthreads(64,1,1)]and realdx.op.threadIdInGroupinput, usings_cmp_eq_u32 s2, 1followed bys_cbranch_scc1(equal arm writes 0, unequal arm writes 1). Temporary test-only harness invokes the actuallowerpipeline, saves synthetic DXIL outside the repository, validates via the Windows SDKdxil.dll1.9.2602.17, and disassembles via matchingdxc.exe -dumpbin.1052a9082c7739dx.op.barrier(80, 8)dx.op.barrier(80, 9)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 isTGSMFence; mode 9 addsSyncThreadGroup(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
1052a90with published candidate82c7739. 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-256A14BAC805712FDB4C0A358CADF54892EFA078600C7812C5A2BABB01A3E60FFEE). 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).@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
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.Merge
Merge the changes and update on Forgejo.