Shaders: one back edge per block, for the dxil-spirv in Proton #2977

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

@⁠neonbyte1 on GitHub · 2026-11-26 02:03 UTC · original
neonbyte1:pr/one-back-edge → main · +163 −5 · 2 files · 1 commits · open

A latch block that branches back to both its own loop's header and the outer loop's makes dxil-spirv recurse until its stack runs out in LoopMergeTracer::trace_from_parent, when the shader also reads other lanes. The pipeline creation never returns. I reported it as HansKristian-Work/dxil-spirv#380; the fix there (#381) isn't in any vkd3d-proton release yet, and the vkd3d-proton GE-Proton ships pins the affected dxil-spirv.

DXC never emits this shape, because its loops get a latch per back edge. So the translator now does the same:

  • The outer back edge leaves through a latch block of its own. That block counts the outer loop's iterations like any other back edge, and aborts at the limit.
  • The bitcode writer no longer folds an empty outer latch into a block that already branches back to another header.

Translation over the whole shader pack: the emitted counts per stage are unchanged, and 9 programs emit different DXIL. Those are the 9 that had such blocks:

  • InstanceCulling: CS_Prop_BatchNoCull, CS_Prop_BatchCullReflect, CS_Tree_BatchNoCull, CS_Tree_BatchCullReflect
  • ShallowWaterSim: CS_PreSim, CS_PreSimWithDisturb, CS_SurfaceWaveSimUpdate
  • WaterSimMgr:CS_UpdateDynamicFoam
  • indirect_light_probes:CS_IrradianceCache_SpatialFilter_Separable

Byte-identical everywhere else.

Pipelines (RTX 5090, driver 620.73.04, Wine 11.22, vkd3d-proton 3.1-83 from GE-Proton11-14, victory translate --pipelines on CS_Prop_BatchNoCull's container, shader cache off):

  • On main these programs are 64-lane waves, which a 32-lane host refuses before the converter runs. The hang appears once they're allowed in the console flow, as with #233/#439.
  • On that base, without this change, there's no pipeline after 150 s (the native repro in dxil-spirv#380 overflows the stack in about 0.08 s). With it, the pipeline is created in 8 s.
  • In game on our NVIDIA/Wine build (main with #233/#320/#439 and this change), every instance-culling pipeline the title asks for is made.

Tests: two new ones, a_latch_branches_back_to_one_header (lowering) and an_inner_latch_keeps_the_outer_latch (writer). victory-shader under Wine: 300 passed and 4 failed, against 298/4 on main; the same 4 Wine failures, fixed by #2968, #2973 and #1266. Clippy (with and without diagnostics) and cargo xtask policy are clean.

Not tested on Windows. There, DXC-shaped loops are simply what the driver usually sees, so I don't expect a change beyond the 9 programs.

AI-assisted (Claude); measured on my machine, no game data shared.

**@⁠neonbyte1** on GitHub · 2026-11-26 02:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2977) `neonbyte1:pr/one-back-edge` → `main` · +163 −5 · 2 files · 1 commits · open A latch block that branches back to both its own loop's header and the outer loop's makes dxil-spirv recurse until its stack runs out in `LoopMergeTracer::trace_from_parent`, when the shader also reads other lanes. The pipeline creation never returns. I reported it as HansKristian-Work/dxil-spirv#380; the fix there (#381) isn't in any vkd3d-proton release yet, and the vkd3d-proton GE-Proton ships pins the affected dxil-spirv. DXC never emits this shape, because its loops get a latch per back edge. So the translator now does the same: - The outer back edge leaves through a latch block of its own. That block counts the outer loop's iterations like any other back edge, and aborts at the limit. - The bitcode writer no longer folds an empty outer latch into a block that already branches back to another header. **Translation** over the whole shader pack: the emitted counts per stage are unchanged, and 9 programs emit different DXIL. Those are the 9 that had such blocks: - `InstanceCulling`: `CS_Prop_BatchNoCull`, `CS_Prop_BatchCullReflect`, `CS_Tree_BatchNoCull`, `CS_Tree_BatchCullReflect` - `ShallowWaterSim`: `CS_PreSim`, `CS_PreSimWithDisturb`, `CS_SurfaceWaveSimUpdate` - `WaterSimMgr:CS_UpdateDynamicFoam` - `indirect_light_probes:CS_IrradianceCache_SpatialFilter_Separable` Byte-identical everywhere else. **Pipelines** (RTX 5090, driver 620.73.04, Wine 11.22, vkd3d-proton 3.1-83 from GE-Proton11-14, `victory translate --pipelines` on `CS_Prop_BatchNoCull`'s container, shader cache off): - On `main` these programs are 64-lane waves, which a 32-lane host refuses before the converter runs. The hang appears once they're allowed in the console flow, as with #233/#439. - On that base, without this change, there's no pipeline after 150 s (the native repro in dxil-spirv#380 overflows the stack in about 0.08 s). With it, the pipeline is created in 8 s. - In game on our NVIDIA/Wine build (`main` with #233/#320/#439 and this change), every instance-culling pipeline the title asks for is made. **Tests**: two new ones, `a_latch_branches_back_to_one_header` (lowering) and `an_inner_latch_keeps_the_outer_latch` (writer). `victory-shader` under Wine: 300 passed and 4 failed, against 298/4 on `main`; the same 4 Wine failures, fixed by #2968, #2973 and #1266. Clippy (with and without `diagnostics`) and `cargo xtask policy` are clean. Not tested on Windows. There, DXC-shaped loops are simply what the driver usually sees, so I don't expect a change beyond the 9 programs. _AI-assisted (Claude); measured on my machine, no game data shared._
A latch that branches back to both its loop's header and the outer loop's
makes dxil-spirv recurse until its stack runs out when the shader also
reads other lanes (HansKristian-Work/dxil-spirv#380; the dxil-spirv that
GE-Proton's vkd3d-proton pins has it): pipeline creation never returns.
The outer back edge now leaves through a latch of its own that counts the
outer loop's iteration, and the writer no longer folds an empty outer
latch into a block that already branches back (it keeps the block's own
back edge, else the one to its innermost header).

Over shaders.rpf for 32-lane hosts the emitted counts are unchanged; 9
programs change (the four InstanceCulling batch shaders, three
ShallowWaterSim, WaterSimMgr's UpdateDynamicFoam, an IrradianceCache
filter), the 9 that had such blocks (35 before, none after). The four
InstanceCulling pipelines are now created on GE-Proton11-14's
vkd3d-proton.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:07 +00:00
github-bot force-pushed github-bot/gh-2977 from a9ad7769de to d9f18613fa 2026-11-26 07:37:15 +00:00 Compare
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 02:26 UTC · original · reviewed

Verified both layers of the dxil-spirv#380 fix. Lowering: when a conditional has back edges to two different headers, the outer (lower rpo) edge goes through a dedicated latch block that counts the iteration itself — so the inner edge keeps normal counting and no block branches back twice. The plan() pass is the safety net: any written block that would still reach two back-edge headers un-folds the extra successors. Both the unit test (folded empty outer latch stays a block) and the real GCN nest test assert <=1 back header everywhere.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2977#pullrequestreview-6067745556) · **reviewed** Verified both layers of the dxil-spirv#380 fix. Lowering: when a conditional has back edges to two different headers, the outer (lower rpo) edge goes through a dedicated latch block that counts the iteration itself — so the inner edge keeps normal counting and no block branches back twice. The plan() pass is the safety net: any written block that would still reach two back-edge headers un-folds the extra successors. Both the unit test (folded empty outer latch stays a block) and the real GCN nest test assert <=1 back header everywhere.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 02:26 UTC · original · reviewed

Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP + dxil.dll, VICTORY_D3D12_DEBUG=1) — clean CFG transformation and ready to merge:

  • Splitting dual-back-edge conditional branches in lower.rs:10197-10239, 10320-10334 via latch(b, to) updates self.edges, fill_phis, pending_masks, and counters consistently, and bitcode.rs:738-756 prevents empty-block folding from re-creating multi-back-edge headers without breaking plan.src PHI mappings or irreducible-loop splits.
  • Note on 512 KiB file-size cap: on 63bcca43, emit/lower.rs reaches 523,660 B (only 628 B below 524,288 B), so merging after any other lower.rs PR will require moving helpers to a submodule.

Local verification:

  • victory-shader (ir::, structure::, emit::bitcode::, emit::lower::tests, emit::flow_tests, emit::crosslane_tests, emit::synthetic_tests, emit::semantics_tests): 119 passed (only failure is pre-existing RTX 5090 baseline gathers_at_a_level_match_the_hardware), including both new latch tests
  • cargo clippy --locked -p victory-shader --tests -- -D warnings (default & --all-features) + cargo xtask policy (191 files ok): 0 warnings
**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2977#pullrequestreview-6067747548) · **reviewed** Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP + `dxil.dll`, `VICTORY_D3D12_DEBUG=1`) — clean CFG transformation and ready to merge: - Splitting dual-back-edge conditional branches in `lower.rs:10197-10239, 10320-10334` via `latch(b, to)` updates `self.edges`, `fill_phis`, `pending_masks`, and `counters` consistently, and `bitcode.rs:738-756` prevents empty-block folding from re-creating multi-back-edge headers without breaking `plan.src` PHI mappings or irreducible-loop splits. - **Note on 512 KiB file-size cap**: on `63bcca43`, `emit/lower.rs` reaches **523,660 B** (only **628 B** below `524,288 B`), so merging after any other `lower.rs` PR will require moving helpers to a submodule. **Local verification**: - `victory-shader` (`ir::`, `structure::`, `emit::bitcode::`, `emit::lower::tests`, `emit::flow_tests`, `emit::crosslane_tests`, `emit::synthetic_tests`, `emit::semantics_tests`): **119 passed** (only failure is pre-existing RTX 5090 baseline `gathers_at_a_level_match_the_hardware`), including both new latch tests - `cargo clippy --locked -p victory-shader --tests -- -D warnings` (default & `--all-features`) + `cargo xtask policy` (`191 files ok`): 0 warnings
Author
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 03:38 UTC · original

Thanks, good catch on the size. For whoever merges: this PR and #2968 both grow emit/lower.rs. On 63bcca43 the file is 520,563 bytes; #2968 adds 601 and this one 3,097, which together leaves about 27 bytes under the 512 KiB limit. Any further lower.rs change after both will need the file split (moving its mod tests out, as some branches already do). If you'd rather have that split in this PR, I can add it.

**@⁠neonbyte1** on GitHub · 2026-11-26 03:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2977#issuecomment-7181890595) Thanks, good catch on the size. For whoever merges: this PR and #2968 both grow `emit/lower.rs`. On `63bcca43` the file is 520,563 bytes; #2968 adds 601 and this one 3,097, which together leaves about 27 bytes under the 512 KiB limit. Any further `lower.rs` change after both will need the file split (moving its `mod tests` out, as some branches already do). If you'd rather have that split in this PR, I can add it.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:33 UTC · original · edited 2026-11-26 08:26 UTC

Automated triage for the maintainers.

Needs work; needs the maintainer's decision. This gives an inner latch that also continues the outer loop its own counted latch (Lower::latch in lower.rs). In bitcode.rs, the plan's folding no longer folds that latch back in, so no written block branches back to two headers. The code reads consistently, and the two tests check that shape.

On your reply:

  • Doc comment: fixed. d9f1861 differs from a9ad776 only in that line's indentation on count_iteration.
  • lower.rs size: settled by #3097, which moves the tests out of lower.rs. With #3097 this PR no longer needs to split the file itself.
  • Why change the output: your point that DXC always gives each back edge its own latch is fair. It makes the change a move toward the shape drivers usually see, not a Proton-only special case. Still, its only measured effect is under Proton with a dxil-spirv version that is fixed upstream (#381). So whether to take it stays the maintainer's call.

What would still help: a pipeline run of the 9 changed programs on a Windows host (native D3D12), from anyone who has one, to show the new shape costs nothing there.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2977#issuecomment-7183592255) · edited 2026-11-26 08:26 UTC <!-- victory-triage v1 head=d9f18613fa942025faa5f77f5be6a17fff04841e verdict=needs-work at=2026-11-26T08:20:18Z --> Automated triage for the maintainers. **Needs work; needs the maintainer's decision.** This gives an inner latch that also continues the outer loop its own counted latch (`Lower::latch` in `lower.rs`). In `bitcode.rs`, the plan's folding no longer folds that latch back in, so no written block branches back to two headers. The code reads consistently, and the two tests check that shape. On your reply: - **Doc comment:** fixed. `d9f1861` differs from `a9ad776` only in that line's indentation on `count_iteration`. - **`lower.rs` size:** settled by #3097, which moves the tests out of `lower.rs`. With #3097 this PR no longer needs to split the file itself. - **Why change the output:** your point that DXC always gives each back edge its own latch is fair. It makes the change a move toward the shape drivers usually see, not a Proton-only special case. Still, its only measured effect is under Proton with a dxil-spirv version that is fixed upstream (#381). So whether to take it stays the maintainer's call. What would still help: a pipeline run of the 9 changed programs on a Windows host (native D3D12), from anyone who has one, to show the new shape costs nothing there. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

Fixed the doc comment's indentation on count_iteration (amended, same single commit).

On the other points:

  • Why change the output for a Linux converter: the shape we emitted, one block branching back to two loop headers, is legal DXIL, but DXC never produces it. The change brings VIctory's output to the shape DXC gives these loops. dxil-spirv#381 fixes the converter, but it isn't in any vkd3d-proton release yet, and Proton users will run pinned versions for a while after. Without the change, CS_Prop_BatchNoCull and the other instance-culling pipelines never finish building under Proton, and the game waits on them.
  • Windows: I have no Windows machine, so a run of the 9 changed programs' pipelines on Windows would need someone else. They are byte-identical everywhere else.
  • lower.rs size: happy to move its mod tests into lower_tests.rs (#[path], as some branches do) in a separate PR, so this one stays reviewable. Say if you'd prefer it here.
**@⁠neonbyte1** on GitHub · 2026-11-26 07:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2977#issuecomment-7185466332) Fixed the doc comment's indentation on `count_iteration` (amended, same single commit). On the other points: - **Why change the output for a Linux converter:** the shape we emitted, one block branching back to two loop headers, is legal DXIL, but DXC never produces it. The change brings VIctory's output to the shape DXC gives these loops. dxil-spirv#381 fixes the converter, but it isn't in any vkd3d-proton release yet, and Proton users will run pinned versions for a while after. Without the change, `CS_Prop_BatchNoCull` and the other instance-culling pipelines never finish building under Proton, and the game waits on them. - **Windows:** I have no Windows machine, so a run of the 9 changed programs' pipelines on Windows would need someone else. They are byte-identical everywhere else. - **`lower.rs` size:** happy to move its `mod tests` into `lower_tests.rs` (`#[path]`, as some branches do) in a separate PR, so this one stays reviewable. Say if you'd prefer it here.
Author
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 07:46 UTC · original

The lower.rs test move is now its own PR, #3097: lower.rs goes to 468,320 bytes, so this PR and #2968 both fit with room to spare. The tests are unchanged, 33 before and after.

AI-assisted (Claude); measured on my machine, no game data shared.

**@⁠neonbyte1** on GitHub · 2026-11-26 07:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2977#issuecomment-7185824493) The `lower.rs` test move is now its own PR, #3097: `lower.rs` goes to 468,320 bytes, so this PR and #2968 both fit with room to spare. The tests are unchanged, 33 before and after. _AI-assisted (Claude); measured on my machine, no game data shared._
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:26 UTC · original · approved these changes

Re-reviewed at d9f18613fa942025faa5f77f5be6a17fff04841e against main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK dxil.dll) — the count_iteration doc-comment indentation fix is clean and the PR is ready to approve.

Verified locally on d9f18613fa:

  • Policy & size: crates/victory-shader/src/emit/lower.rs is 523,664 B (624 B below the 524,288 B cap, so coordinating merge order with #3097 or splitting tests remains important if another lower.rs change lands first). cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed (asset policy: 191 files ok).
  • Clippy: cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features): clean.
  • RTX 5090 (VICTORY_WARP=0, skipping the pre-existing heap_direct_texture_reads_mark_their_heap_index crash): 300 passed; 3 failed; 3 ignored; 1 filtered out (the same 3 pre-existing RTX 5090 failures as main; emit::flow_tests, emit::diff_tests, emit::tests::constant_color_validates, a_latch_branches_back_to_one_header, and an_inner_latch_keeps_the_outer_latch all pass).
  • WARP (VICTORY_WARP=1): 300 passed; 4 failed; 3 ignored (the exact 4 pre-existing WARP wave-of-32/gather failures as main).

One minor non-blocking note on lower.rs:10208-10226: when an inner-loop back edge reaches LOOP_LIMIT, the And/Or gate sends those lanes into Lower::latch for the outer header, which re-enters the outer loop if the outer counter is still below LOOP_LIMIT (still bounded by outer LOOP_LIMIT, and an improvement over main where a not_taken back edge was uncounted).

**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2977#pullrequestreview-6078968470) · **approved these changes** Re-reviewed at `d9f18613fa942025faa5f77f5be6a17fff04841e` against `main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK `dxil.dll`) — the `count_iteration` doc-comment indentation fix is clean and the PR is ready to approve. Verified locally on `d9f18613fa`: - **Policy & size**: `crates/victory-shader/src/emit/lower.rs` is **523,664 B** (624 B below the 524,288 B cap, so coordinating merge order with #3097 or splitting tests remains important if another `lower.rs` change lands first). `cargo test -p xtask --locked policy::tests::repository_passes_policy`: `1 passed` (`asset policy: 191 files ok`). - **Clippy**: `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`): clean. - **RTX 5090 (`VICTORY_WARP=0`, skipping the pre-existing `heap_direct_texture_reads_mark_their_heap_index` crash)**: `300 passed; 3 failed; 3 ignored; 1 filtered out` (the same 3 pre-existing RTX 5090 failures as `main`; `emit::flow_tests`, `emit::diff_tests`, `emit::tests::constant_color_validates`, `a_latch_branches_back_to_one_header`, and `an_inner_latch_keeps_the_outer_latch` all pass). - **WARP (`VICTORY_WARP=1`)**: `300 passed; 4 failed; 3 ignored` (the exact 4 pre-existing WARP wave-of-32/gather failures as `main`). One minor non-blocking note on `lower.rs:10208-10226`: when an inner-loop back edge reaches `LOOP_LIMIT`, the `And`/`Or` gate sends those lanes into `Lower::latch` for the outer header, which re-enters the outer loop if the outer counter is still below `LOOP_LIMIT` (still bounded by outer `LOOP_LIMIT`, and an improvement over `main` where a `not_taken` back edge was uncounted).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2977'
git switch 'github-bot/gh-2977'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2977'
git switch 'github-bot/gh-2977'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2977'
git switch 'main'
git merge --squash 'github-bot/gh-2977'
git switch 'main'
git merge --ff-only 'github-bot/gh-2977'
git switch 'main'
git merge 'github-bot/gh-2977'
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!2977
No description provided.