Shaders: one back edge per block, so vkd3d-proton converts #439's loops (stacked on #439) #2307

Open
desplmfao wants to merge 74 commits from upstream-pr/2309 into main
desplmfao commented 2026-11-25 10:19:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T10:19:48Z.


Stacked on #439 (r4tedx; it contains #233 and #320). The two commits on top of it are the change. The first is powplusplus's d48ec76 from #1885, cherry-picked with its author kept; the second is ours.

Problem

On NVIDIA (32-lane waves) under Wine/Proton, vkd3d-proton converts each pipeline's DXIL to SPIR-V with dxil-spirv, inside the title's process. Some of #439's console-flow programs have a block that branches back to two loop headers, e.g. br c, 191, 126, where 191 is the inner loop's header and 126 the outer one's. Others have a loop header with three back edges.

dxil-spirv's structurizer expects one back edge per block and per header ("DXIL seems to obey this", forward_visit_resolve). It reads the extra edge as a forward edge, makes a cycle, and recurses until the stack runs out (LoopMergeTracer::trace_from_parent, about 100k frames). With a large stack it uses memory instead (40 GB before I killed it), or the pipeline thread hangs. In the title, the process ends while those pipelines are created, or no pipeline ever finishes.

main has the same shapes in 7 programs. They convert because those programs have no WaveReadLaneAt, and dxil-spirv only walks the graph before fixing it up in flatten_subgroup_shuffles, which runs only when a shader reads other lanes. #439 adds the lane reads, and then the same shapes are fatal.

How it was found

  1. The pipeline journal (#491, VICTORY_PIPELINE_JOURNAL=1). On #439 the title's process died during world load, with no crash log and no GPU fault. The journal's pending notes named the pipelines being created at that moment: b2ff2ef0d6c98dd7, fdd56d97a806bcca, 32ed072b9f845048 and others.
  2. Offline reproduction. Their containers came from the title's shaders.rpf and were translated with #439. A native dxil-spirv build, capped in memory, then crashed on them the same way: it reached 40 GB uncapped and overflowed the stack when capped. gdb showed the recursion (LoopMergeTracer::trace_from_parent, about 100k frames).
  3. The cause. Diffing the DXIL against main showed the block that branches back to two loop headers.
  4. Confirmed in the title with #2292 (VICTORY_PIPELINE_SOFT_CRASH=1). Without this fix, the same two programs are caught as stack overflows (0xc00000fd) inside vkd3d-proton.

Change

All in crates/victory-shader/src/emit/bitcode.rs:

  • 364c1bc (powplusplus, from #1885): Module::single_latches gives each loop header one back edge.
  • 91e3bdf: a block that branches back to two headers sends its edge to the outer header through a new block of its own, fixing that header's phis. The block stays the inner loop's exiting latch, as DXC makes them. The empty-latch fold at write time no longer folds a latch into a block that already branches back, which would undo the split.

The change is generic: lower.rs and wave.rs are untouched, so it should not conflict with #2214.

Tested

  • dxil-spirv (native build, capped at 3 GB):
    • Before: it crashes on fdd56d97a806bcca (InstanceCulling:CS_Prop_BatchNoCull) and 32ed072b9f845048 (deferred_tiled:CS_LaserLightShadowRaytracing).
    • After: both convert, pass spirv-val, and vkCreateComputePipelines returns VK_SUCCESS on native NVIDIA (RTX 5080, no Wine).
  • All 413 dumped programs of the title: only the 8 with these loop shapes change, and the other 405 give byte-identical output. All 8 convert and create on NVIDIA (0.3–1.5 s each).
  • In the title (RTX 5080, Linux, Proton with vkd3d-proton 3.2.0): with #439 alone, the process died or the pipeline workers stalled while these pipelines were created. With this change, all of them create, including the five large *:CS_RaytracingResolve programs, and the run goes past that point.
  • cargo test -p victory-shader --lib: 151 passed on Linux, and 178 passed, 0 failed for the Windows build under Proton on the RTX 5080. That includes the new a_block_branching_back_to_two_headers_gets_one_back_edge and empty_latches_to_two_headers_fold_once.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • #1885 (powplusplus): its first commit is included here. Its second commit (larger pipeline thread stacks) is not.
  • #1145 also changes latch folding. #1540 guards a branch whose two arms are both back edges, in lower.rs.
  • #2214 (draft, also on #439): its barrier wait loops add more nested loops with lane reads, so it probably hits the same converter limit on NVIDIA under vkd3d-proton. This change applies to any form.
  • #2220: the same wave64 problem on native D3D12, where the pipelines are refused instead.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5489409412 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T10:19:48Z. --- **Stacked on #439** (r4tedx; it contains #233 and #320). The two commits on top of it are the change. The first is powplusplus's `d48ec76` from #1885, cherry-picked with its author kept; the second is ours. ## Problem On NVIDIA (32-lane waves) under Wine/Proton, vkd3d-proton converts each pipeline's DXIL to SPIR-V with dxil-spirv, inside the title's process. Some of #439's console-flow programs have a block that branches back to **two** loop headers, e.g. `br c, 191, 126`, where 191 is the inner loop's header and 126 the outer one's. Others have a loop header with three back edges. dxil-spirv's structurizer expects one back edge per block and per header ("DXIL seems to obey this", `forward_visit_resolve`). It reads the extra edge as a forward edge, makes a cycle, and recurses until the stack runs out (`LoopMergeTracer::trace_from_parent`, about 100k frames). With a large stack it uses memory instead (40 GB before I killed it), or the pipeline thread hangs. In the title, the process ends while those pipelines are created, or no pipeline ever finishes. `main` has the same shapes in 7 programs. They convert because those programs have no `WaveReadLaneAt`, and dxil-spirv only walks the graph before fixing it up in `flatten_subgroup_shuffles`, which runs only when a shader reads other lanes. #439 adds the lane reads, and then the same shapes are fatal. ## How it was found 1. **The pipeline journal (#491, `VICTORY_PIPELINE_JOURNAL=1`).** On #439 the title's process died during world load, with no crash log and no GPU fault. The journal's pending notes named the pipelines being created at that moment: `b2ff2ef0d6c98dd7`, `fdd56d97a806bcca`, `32ed072b9f845048` and others. 2. **Offline reproduction.** Their containers came from the title's `shaders.rpf` and were translated with #439. A native dxil-spirv build, capped in memory, then crashed on them the same way: it reached 40 GB uncapped and overflowed the stack when capped. gdb showed the recursion (`LoopMergeTracer::trace_from_parent`, about 100k frames). 3. **The cause.** Diffing the DXIL against `main` showed the block that branches back to two loop headers. 4. **Confirmed in the title** with #2292 (`VICTORY_PIPELINE_SOFT_CRASH=1`). Without this fix, the same two programs are caught as stack overflows (`0xc00000fd`) inside vkd3d-proton. ## Change All in `crates/victory-shader/src/emit/bitcode.rs`: - **`364c1bc`** (powplusplus, from #1885): `Module::single_latches` gives each loop header one back edge. - **`91e3bdf`**: a block that branches back to two headers sends its edge to the outer header through a new block of its own, fixing that header's phis. The block stays the inner loop's exiting latch, as DXC makes them. The empty-latch fold at write time no longer folds a latch into a block that already branches back, which would undo the split. The change is generic: `lower.rs` and `wave.rs` are untouched, so it should not conflict with #2214. ## Tested - **dxil-spirv (native build, capped at 3 GB):** - Before: it crashes on `fdd56d97a806bcca` (`InstanceCulling:CS_Prop_BatchNoCull`) and `32ed072b9f845048` (`deferred_tiled:CS_LaserLightShadowRaytracing`). - After: both convert, pass `spirv-val`, and `vkCreateComputePipelines` returns `VK_SUCCESS` on native NVIDIA (RTX 5080, no Wine). - **All 413 dumped programs of the title:** only the 8 with these loop shapes change, and the other 405 give byte-identical output. All 8 convert and create on NVIDIA (0.3–1.5 s each). - **In the title** (RTX 5080, Linux, Proton with vkd3d-proton 3.2.0): with #439 alone, the process died or the pipeline workers stalled while these pipelines were created. With this change, all of them create, including the five large `*:CS_RaytracingResolve` programs, and the run goes past that point. - `cargo test -p victory-shader --lib`: 151 passed on Linux, and 178 passed, 0 failed for the Windows build under Proton on the RTX 5080. That includes the new `a_block_branching_back_to_two_headers_gets_one_back_edge` and `empty_latches_to_two_headers_fold_once`. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. ## Related - #1885 (powplusplus): its first commit is included here. Its second commit (larger pipeline thread stacks) is not. - #1145 also changes latch folding. #1540 guards a branch whose two arms are both back edges, in `lower.rs`. - #2214 (draft, also on #439): its barrier wait loops add more nested loops with lane reads, so it probably hits the same converter limit on NVIDIA under vkd3d-proton. This change applies to any form. - #2220: the same wave64 problem on native D3D12, where the pipelines are refused instead. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DenRakEiw commented 2026-11-25 10:23:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T10:23:18Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP (focusing on top commit 91e3bdf stacked on #439):

  • Extending single_latches to split any block branching back to two loop headers into a dedicated outer-latch trampoline and preventing write-time empty-latch folding from re-introducing a dual-back-edge block cleanly enforces one back edge per block for vkd3d-proton / dxil-spirv.
  • cargo test -p victory-shader emit::bitcode::tests: 9/9 passed on RTX 5090, 9/9 passed on WARP (including a_block_branching_back_to_two_headers_gets_one_back_edge and empty_latches_to_two_headers_fold_once).
  • cargo test -p victory-shader lane_read_loop_tests: 2/2 passed on RTX 5090, 2/2 passed on WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 186 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6055770962 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#pullrequestreview-6055770962). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T10:23:18Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP (focusing on top commit `91e3bdf` stacked on `#439`): - Extending `single_latches` to split any block branching back to two loop headers into a dedicated outer-latch trampoline and preventing write-time empty-latch folding from re-introducing a dual-back-edge block cleanly enforces one back edge per block for vkd3d-proton / `dxil-spirv`. - `cargo test -p victory-shader emit::bitcode::tests`: 9/9 passed on RTX 5090, 9/9 passed on WARP (including `a_block_branching_back_to_two_headers_gets_one_back_edge` and `empty_latches_to_two_headers_fold_once`). - `cargo test -p victory-shader lane_read_loop_tests`: 2/2 passed on RTX 5090, 2/2 passed on WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 186 files ok. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 10:54:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:54:01Z.

Review: COMMENTED


One back edge per block so vkd3d-proton converts the DXIL (+3763, apps/docs/gpu/shader). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Big mixed PR; the shader lowering side is the portable part — worth splitting or at least a dedicated hardware pass. Extends the --host-lanes CLI from #2214.

<!-- greyfinch-sync:Marvisak/VIctory:review:6056242611 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#pullrequestreview-6056242611). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T10:54:01Z. **Review:** COMMENTED --- One back edge per block so vkd3d-proton converts the DXIL (+3763, apps/docs/gpu/shader). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Big mixed PR; the shader lowering side is the portable part — worth splitting or at least a dedicated hardware pass. Extends the --host-lanes CLI from #2214.
desplmfao commented 2026-11-25 12:03:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T11:18:33Z.


@catminou4 thanks. The size comes from the stacking: this PR's diff against main includes all of #439 (and #320/#233 with it), and that's where the +3,763 lines, the docs and the --host-lanes CLI come from. The change itself is only the last two commits, both in crates/victory-shader/src/emit/bitcode.rs: 364c1bc (powplusplus's commit from #1885) and 91e3bdf. Compare against #439's head to see just those.

r4tedx is taking both commits into #439 (see https://github.com/Marvisak/VIctory/pull/439#issuecomment-7160324713). Once they're in, I'll close this one as included.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160873842 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7160873842). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T11:18:33Z. --- @catminou4 thanks. The size comes from the stacking: this PR's diff against `main` includes all of #439 (and #320/#233 with it), and that's where the +3,763 lines, the docs and the `--host-lanes` CLI come from. The change itself is only the last two commits, both in `crates/victory-shader/src/emit/bitcode.rs`: `364c1bc` (powplusplus's commit from #1885) and `91e3bdf`. Compare against #439's head to see just those. r4tedx is taking both commits into #439 (see https://github.com/Marvisak/VIctory/pull/439#issuecomment-7160324713). Once they're in, I'll close this one as included.
desplmfao commented 2026-11-25 12:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T11:32:05Z.


Update after r4tedx's note on #439: this stays its own PR. I've merged #439's current head (3fab5a1) into it (no conflicts, merged rather than rebased). The change is still the two commits in bitcode.rs, 364c1bc (powplusplus, from #1885) and 91e3bdf. On the merge, cargo test -p victory-shader --lib (Linux) gives 151 passed, and clippy is clean. To review just the change, compare against #439's head.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161171127 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7161171127). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T11:32:05Z. --- Update after r4tedx's note on #439: this stays its own PR. I've merged #439's current head (`3fab5a1`) into it (no conflicts, merged rather than rebased). The change is still the two commits in `bitcode.rs`, `364c1bc` (powplusplus, from #1885) and `91e3bdf`. On the merge, `cargo test -p victory-shader --lib` (Linux) gives 151 passed, and clippy is clean. To review just the change, compare against #439's head.
desplmfao commented 2026-11-25 16:09:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T15:43:02Z.


Thanks for the triage. On the three points:

  1. Landing order: agreed. #439 itself conflicts with main right now, and this PR is stacked on it, so I'll follow #439's next head. Once #439 is in, I'll merge main here (no rebase or force-push, to keep the review history) so the diff comes down to the two bitcode.rs commits.
  2. 364c1bc (from #1885): I'm asking @powplusplus on #1885 whether it lands there or here, so it doesn't land twice. If #1885 lands first, I'll drop it from here.
  3. Native D3D12: the change rewrites the DXIL the translator emits, so it applies on any host, not just under vkd3d-proton. Of the title's 413 dumped programs, the 405 without these loop shapes give byte-identical output, so native D3D12 sees no change for them. The 8 that change get a different but equivalent control-flow graph: the second back edge goes through its own latch block, and the phis are rewritten to it. I haven't run those 8 on a native Windows driver. That would be the one thing worth checking there, and I'll ask on the PR for someone with Windows to try them.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7167270927 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7167270927). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T15:43:02Z. --- Thanks for the triage. On the three points: 1. **Landing order:** agreed. #439 itself conflicts with `main` right now, and this PR is stacked on it, so I'll follow #439's next head. Once #439 is in, I'll merge `main` here (no rebase or force-push, to keep the review history) so the diff comes down to the two `bitcode.rs` commits. 2. **`364c1bc` (from #1885):** I'm asking @powplusplus on #1885 whether it lands there or here, so it doesn't land twice. If #1885 lands first, I'll drop it from here. 3. **Native D3D12:** the change rewrites the DXIL the translator emits, so it applies on any host, not just under vkd3d-proton. Of the title's 413 dumped programs, the 405 without these loop shapes give byte-identical output, so native D3D12 sees no change for them. The 8 that change get a different but equivalent control-flow graph: the second back edge goes through its own latch block, and the phis are rewritten to it. I haven't run those 8 on a native Windows driver. That would be the one thing worth checking there, and I'll ask on the PR for someone with Windows to try them.
Marvisak commented 2026-11-25 16:09:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:22:20Z.


Automated triage for the maintainers.

Needs work. ec845d6 merges cleanly and CI check passes, but the diff against main (+4,971 / -1,457, 28 files) is almost entirely #439 (r4tedx's wave64 console flow, merged with main on update/439-main), plus this PR's own rule in Module::plan (crates/victory-shader/src/emit/bitcode.rs: one back edge per block, commits 364c1bc/91e3bdf) and the move of lower.rs's tests to emit/lower/tests.rs. Merging it would land #439 in a rebased form that #439's own thread has not reviewed; #439 itself still conflicts with main (marked needs-rebase for 3fab5a1).

What would move this forward: #439 rebased and decided on its own (or the maintainer choosing to take it through this branch), and then this PR reduced to its own commits on top, so the back-edge rule can be reviewed by itself.

On your replies: the plan placement and the Module::term use for constant branches sound right, and the tests move fixes the policy failure, but they do not change the stacking problem above. Also note #2084 and #2117 add to lower.rs as well; once the tests move lands, they will need to follow it.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166738625 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7166738625). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:22:20Z. --- <!-- victory-triage v1 head=ec845d633b47e4f98789a8f0353c172f3070d942 verdict=needs-work at=2026-11-26T02:24:00Z --> Automated triage for the maintainers. **Needs work.** `ec845d6` merges cleanly and CI `check` passes, but the diff against `main` (+4,971 / -1,457, 28 files) is almost entirely #439 (r4tedx's wave64 console flow, merged with `main` on `update/439-main`), plus this PR's own rule in `Module::plan` (`crates/victory-shader/src/emit/bitcode.rs`: one back edge per block, commits `364c1bc`/`91e3bdf`) and the move of `lower.rs`'s tests to `emit/lower/tests.rs`. Merging it would land #439 in a rebased form that #439's own thread has not reviewed; #439 itself still conflicts with `main` (marked needs-rebase for `3fab5a1`). What would move this forward: #439 rebased and decided on its own (or the maintainer choosing to take it through this branch), and then this PR reduced to its own commits on top, so the back-edge rule can be reviewed by itself. On your replies: the `plan` placement and the `Module::term` use for constant branches sound right, and the tests move fixes the policy failure, but they do not change the stacking problem above. Also note #2084 and #2117 add to `lower.rs` as well; once the tests move lands, they will need to follow it. --- _Generated by [Claude Code](https://claude.ai/code)_
desplmfao commented 2026-11-26 02:06:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-26T01:18:28Z.


#439 has conflicted with main since this morning, so this PR now sits on update/439-main (f7d4feb). That branch is #439's head 3fab5a1 with main (63bcca4) merged in, and r4tedx's commits are unchanged. f93574a merges it here.

  • main moved block layout and folding into Module::plan, so this PR's rule now sits there. An empty latch is not folded into a block that already branches back, counted over the edges plan writes.
  • successors() uses Module::term, so a branch on a constant doesn't count its dead edge.
  • Clippy is clean, with and without diagnostics. victory-shader under vkd3d-proton gives 340 passed. The 8 failures are the same 8 that plain main fails there.
  • The bitcode tests pass, including empty_latches_to_two_headers_fold_once.

When #439 is updated upstream, this PR follows its head again.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179642422 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7179642422). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-26T01:18:28Z. --- #439 has conflicted with `main` since this morning, so this PR now sits on [`update/439-main`](https://github.com/desplmfao/VIctory/tree/update/439-main) (`f7d4feb`). That branch is #439's head `3fab5a1` with `main` (`63bcca4`) merged in, and r4tedx's commits are unchanged. `f93574a` merges it here. - `main` moved block layout and folding into `Module::plan`, so this PR's rule now sits there. An empty latch is not folded into a block that already branches back, counted over the edges `plan` writes. - `successors()` uses `Module::term`, so a branch on a constant doesn't count its dead edge. - Clippy is clean, with and without diagnostics. victory-shader under vkd3d-proton gives 340 passed. The 8 failures are the same 8 that plain `main` fails there. - The bitcode tests pass, including `empty_latches_to_two_headers_fold_once`. When #439 is updated upstream, this PR follows its head again.
desplmfao commented 2026-11-26 02:07:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-26T01:30:10Z.


The check failure on f93574a was the asset policy's file size limit: with #439 merged into main, crates/victory-shader/src/emit/lower.rs reached 559,370 bytes, past the 524,288-byte limit (xtask repository_passes_policy). 68ba2de on update/439-main moves lower.rs's inline test module unchanged into emit/lower/tests.rs, leaving lower.rs at 506,198 bytes. ec845d6 merges it here.

Anything that changes lower.rs's tests (this PR, #439, or another PR stacked on them) now has to edit emit/lower/tests.rs. A PR that still adds tests inline in lower.rs will conflict, or push the file back over the limit.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179834815 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7179834815). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-26T01:30:10Z. --- The `check` failure on `f93574a` was the asset policy's file size limit: with #439 merged into `main`, `crates/victory-shader/src/emit/lower.rs` reached 559,370 bytes, past the 524,288-byte limit (`xtask` `repository_passes_policy`). `68ba2de` on `update/439-main` moves `lower.rs`'s inline test module unchanged into `emit/lower/tests.rs`, leaving `lower.rs` at 506,198 bytes. `ec845d6` merges it here. Anything that changes `lower.rs`'s tests (this PR, #439, or another PR stacked on them) now has to edit `emit/lower/tests.rs`. A PR that still adds tests inline in `lower.rs` will conflict, or push the file back over the limit.
neonbyte1 commented 2026-11-26 19:17:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-26T19:17:45Z.


Tested in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with vkd3d-proton. This fixes a crash I was chasing: pipeline worker threads dying of stack overflow inside CreateComputePipelineState.

Setup:

  • Base: main plus #439, #233, #320, #1129 (64 MiB pipeline worker stacks), my #2977 and a few others, with this PR's head ec845d6 merged on top.
  • Diagnostics: begin/end log markers around each pipeline build phase.
  • Runs: 10 minutes in the opening yard.

Without this PR, every run had 6 Wine stack overflow errors, on 6 of the 8 victory-pipelines-N threads. Each died inside CreateComputePipelineState, after our own translation had finished with ~3.7 KiB of its 64 MiB stack used, so the depth was in dxil-spirv's conversion. The other 2 workers built everything else, and these 6 compute pipelines never existed:

hash program
32ed072b9f845048 CS_LaserLightShadowRaytracing
559d9f0184e15fe3 CS_TraceShadowRays_Checkerboard
17829ac71aab4e8d, a1b20bc47e3c9597, afeea48bbb9913ad, e8c962358d862e3f the four CS_RTDistantShadowTrace*_Tiled

With this PR:

  • Stack overflows: 6 → 0. All 8 workers stay alive to the end, and the build queue drains to 0. Before, it stayed stuck at 6 for the rest of the run.
  • The 6 pipelines build in 0.16–1.7 s each, and are dispatched every frame after that (they show up in 450–556 of the per-frame reports).
  • No regressions: no Xid or device removal, the same refusals, frame time and dropped draws in the normal range for this scene. The warning kinds are identical; only the slow host submission count drops (578 → 538, max 1471 → 527 ms).
  • Census: 639 of 25,590 DXIL outputs change across 64 programs, mostly decal pixel shaders plus the RT and instance-culling compute. No count changes, nothing newly refused.

My #2977 was also in this build, but on its own it changes 9 other programs and none of these six, so the fix comes from this PR. #2309 covers the same back-edge case more generally, so I'll fold #2977 into it or close it. Also, the 64 MiB stack from #1129 was enough here, so #1885's 256 MiB commit wasn't needed.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7201421224 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7201421224). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-26T19:17:45Z. --- Tested in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with vkd3d-proton. This fixes a crash I was chasing: pipeline worker threads dying of stack overflow inside `CreateComputePipelineState`. **Setup:** - **Base:** `main` plus #439, #233, #320, #1129 (64 MiB pipeline worker stacks), my #2977 and a few others, with this PR's head `ec845d6` merged on top. - **Diagnostics:** begin/end log markers around each pipeline build phase. - **Runs:** 10 minutes in the opening yard. **Without this PR,** every run had 6 Wine `stack overflow` errors, on 6 of the 8 `victory-pipelines-N` threads. Each died inside `CreateComputePipelineState`, after our own translation had finished with ~3.7 KiB of its 64 MiB stack used, so the depth was in dxil-spirv's conversion. The other 2 workers built everything else, and these 6 compute pipelines never existed: | hash | program | |---|---| | `32ed072b9f845048` | `CS_LaserLightShadowRaytracing` | | `559d9f0184e15fe3` | `CS_TraceShadowRays_Checkerboard` | | `17829ac71aab4e8d`, `a1b20bc47e3c9597`, `afeea48bbb9913ad`, `e8c962358d862e3f` | the four `CS_RTDistantShadowTrace*_Tiled` | **With this PR:** - **Stack overflows: 6 → 0.** All 8 workers stay alive to the end, and the build queue drains to 0. Before, it stayed stuck at 6 for the rest of the run. - **The 6 pipelines build in 0.16–1.7 s each, and are dispatched every frame** after that (they show up in 450–556 of the per-frame reports). - **No regressions:** no Xid or device removal, the same refusals, frame time and dropped draws in the normal range for this scene. The warning kinds are identical; only the `slow host submission` count drops (578 → 538, max 1471 → 527 ms). - **Census:** 639 of 25,590 DXIL outputs change across 64 programs, mostly decal pixel shaders plus the RT and instance-culling compute. No count changes, nothing newly refused. My #2977 was also in this build, but on its own it changes 9 other programs and none of these six, so the fix comes from this PR. #2309 covers the same back-edge case more generally, so I'll fold #2977 into it or close it. Also, the 64 MiB stack from #1129 was enough here, so #1885's 256 MiB commit wasn't needed. _AI-assisted (Claude); measured on my machine, no game data shared._
desplmfao commented 2026-11-27 08:24:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-27T08:24:40Z.


@neonbyte1 thanks, this is the in-title confirmation the PR needed, and on a different card and Wine build from mine. Six stack overflows down to none, all eight workers alive, and the six RT shadow pipelines built and dispatched every frame. These are the same pipelines I saw hang or crash pipeline creation here (32ed072b9f845048, 17829ac71aab4e8d, afeea48bbb9913ad). Your census, with no count changes and nothing newly refused, is useful too. On #2977, folding it in or closing it is your call. If its 9 other programs need their own change, it could stay separate.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7213507058 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7213507058). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-27T08:24:40Z. --- @neonbyte1 thanks, this is the in-title confirmation the PR needed, and on a different card and Wine build from mine. Six stack overflows down to none, all eight workers alive, and the six RT shadow pipelines built and dispatched every frame. These are the same pipelines I saw hang or crash pipeline creation here (`32ed072b9f845048`, `17829ac71aab4e8d`, `afeea48bbb9913ad`). Your census, with no count changes and nothing newly refused, is useful too. On #2977, folding it in or closing it is your call. If its 9 other programs need their own change, it could stay separate.
neonbyte1 commented 2026-11-27 08:48:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T08:48:35Z.


@desplmfao thanks. Then I'll keep #2977 separate: it's the standalone one-back-edge-per-block fix for main without #439, and its 9 programs don't include these six. If #2309 lands first, I'll rebase #2977 onto it and drop whatever becomes redundant; if #2977 turns out fully covered at that point, I'll close it with a note here.

For what it's worth, #2309 has stayed in every stack I've measured since (now at ~205 ms/frame in the prison yard on the RTX 5090, details in #3425), with all eight pipeline workers alive in every run.

AI-assisted (Claude); no game data shared.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7213945657 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7213945657). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T08:48:35Z. --- @desplmfao thanks. Then I'll keep #2977 separate: it's the standalone one-back-edge-per-block fix for `main` without #439, and its 9 programs don't include these six. If #2309 lands first, I'll rebase #2977 onto it and drop whatever becomes redundant; if #2977 turns out fully covered at that point, I'll close it with a note here. For what it's worth, #2309 has stayed in every stack I've measured since (now at ~205 ms/frame in the prison yard on the RTX 5090, details in #3425), with all eight pipeline workers alive in every run. _AI-assisted (Claude); no game data shared._
pickles976 commented 2026-11-27 08:50:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-27T08:50:02Z.


Verified the exact Prop BatchNoCull failure/fix on Linux / Wine11 / RTX4060 Laptop8GiB / NVIDIA590.48.1 / 16GiB RAM.

Provenance: newer #439 e2d3cfd50715954fb89ff462edb37a0c4395ecd0 plus only this PR's bitcode writer changes from ec845d633b47e4f98789a8f0353c172f3070d942, and the required Shader::finish → single_latches() call. Two dirty files, not an exact #2309-head result. This preserves #439's newer root-title-memory safety guard. Diagnostic-relaxed vkd3d-proton 2576c0b4adfae4a+, not stock-stack certification.

Before: the original locally extracted InstanceCulling/CS_Prop_BatchNoCull container (fdd56d97a806bcca) translates and SDK-validates, but --pipelines stack-overflows/stalls. Default-stack batch stopped at300s. A separate bounded16MiB RUST_MIN_STACK diagnostic still overflows/stalls at90s. No dispatch and no resource-limit increase.

After the writer fix, normal stack: same six scene containers, translate ... --pipelines --validate --list --jobs 1, fresh intended-worktree release41.29s: 5 emitted / 5 validated / 5 native PSOs created, including fdd56... and all four requested prop/tree InstanceCulling programs. The sixth (02384a60fda6f2d0, VFX heap ComputeRelocations) remains deliberately refused for a group larger than64. Full command finished66.15s including build, with no overflow. These are original-container native-creation checks, not title-shader GPU execution.

Synthetic correctness: writer tests15pass/0fail (one benchmark intentionally ignored), including all three latch/phi/fold regressions; split_tests36/36,0ignored,46.74s, 81 exact readback lines explicitly on NVIDIA with split true. Includes cross-half LDS order, lane reads, whole-wave sums/prefixes and multi-dimensional groups. No skipped-adapter messages, no WARP reference claim.

Evidence: verify-pr439-loop-writer-20261127T084248Z/, verify-pr439-loop-split-20261127T084423Z/, verify-pr439-loop-scene-native-20261127T084551Z/. Native leg peakGPU221MiB/min availableRAM11008MiB; unchanged9GiB/512MiB scope and external guards. Original assets/DXIL remain local and unmodified at source.

This clears the exact compiler boundary on another NVIDIA model. No rendered-title-frame claim yet; integrating into our paging/file-backed-memory runtime next, retaining the all-or-none BVH gate and the remaining unsupported-program refusals.

Mixed-runtime follow-through (2026-11-27 09:15 UTC): integrated this writer and #439 into our existing paging/file-backed-memory runtime (dirty base 3ed7d725, not an exact PR head). Fresh release44.08s; all five repaired prop/tree-culling and VFX RelocateStartIndex keys now have both native-built and title-used records. The 180s guarded run reaches the prologue card, then remains black. The colour texture entering native FFX is exactly zero RGB on two sampled dispatches, with zero nonfinite values; therefore this native-compiler fix is real but is not sufficient scene-rendering proof. Trace1529used/658built,611used with built records,916still pending at last status: incomplete compilation remains a confounder. GPUpeak4012MiB, availableRAMminimum4920.7MiB; wall stop, not a resource/crash stop. Evidence culling-depth-trial-20261127T091527Z/summary.json and matching guard logs. Depth observation was unavailable because the local probe rejected actual R32G8X24_TYPELESS; no geometry conclusion from its missing image. No images or original program assets uploaded.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7213973107 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2309#issuecomment-7213973107). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-27T08:50:02Z. --- Verified the exact Prop BatchNoCull failure/fix on **Linux / Wine11 / RTX4060 Laptop8GiB / NVIDIA590.48.1 / 16GiB RAM**. **Provenance:** newer #439 `e2d3cfd50715954fb89ff462edb37a0c4395ecd0` plus only this PR's bitcode writer changes from `ec845d633b47e4f98789a8f0353c172f3070d942`, and the required `Shader::finish → single_latches()` call. Two dirty files, not an exact #2309-head result. This preserves #439's newer root-title-memory safety guard. Diagnostic-relaxed vkd3d-proton `2576c0b4adfae4a+`, not stock-stack certification. **Before:** the original locally extracted `InstanceCulling/CS_Prop_BatchNoCull` container (`fdd56d97a806bcca`) translates and SDK-validates, but `--pipelines` stack-overflows/stalls. Default-stack batch stopped at300s. A separate bounded16MiB `RUST_MIN_STACK` diagnostic still overflows/stalls at90s. No dispatch and no resource-limit increase. **After the writer fix, normal stack:** same six scene containers, `translate ... --pipelines --validate --list --jobs 1`, fresh intended-worktree release41.29s: **5 emitted / 5 validated / 5 native PSOs created**, including `fdd56...` and all four requested prop/tree InstanceCulling programs. The sixth (`02384a60fda6f2d0`, VFX heap ComputeRelocations) remains deliberately refused for a group larger than64. Full command finished66.15s including build, with no overflow. These are original-container native-creation checks, not title-shader GPU execution. **Synthetic correctness:** writer tests15pass/0fail (one benchmark intentionally ignored), including all three latch/phi/fold regressions; `split_tests`36/36,0ignored,46.74s, **81 exact readback lines explicitly on NVIDIA with `split true`**. Includes cross-half LDS order, lane reads, whole-wave sums/prefixes and multi-dimensional groups. No skipped-adapter messages, no WARP reference claim. Evidence: `verify-pr439-loop-writer-20261127T084248Z/`, `verify-pr439-loop-split-20261127T084423Z/`, `verify-pr439-loop-scene-native-20261127T084551Z/`. Native leg peakGPU221MiB/min availableRAM11008MiB; unchanged9GiB/512MiB scope and external guards. Original assets/DXIL remain local and unmodified at source. This clears the exact compiler boundary on another NVIDIA model. No rendered-title-frame claim yet; integrating into our paging/file-backed-memory runtime next, retaining the all-or-none BVH gate and the remaining unsupported-program refusals. **Mixed-runtime follow-through (2026-11-27 09:15 UTC):** integrated this writer and #439 into our existing paging/file-backed-memory runtime (dirty base `3ed7d725`, not an exact PR head). Fresh release44.08s; all five repaired prop/tree-culling and VFX RelocateStartIndex keys now have both native-built and title-used records. The 180s guarded run reaches the prologue card, then remains black. The colour texture entering native FFX is exactly zero RGB on two sampled dispatches, with zero nonfinite values; therefore this native-compiler fix is real but is not sufficient scene-rendering proof. Trace1529used/658built,611used with built records,916still pending at last status: incomplete compilation remains a confounder. GPUpeak4012MiB, availableRAMminimum4920.7MiB; wall stop, not a resource/crash stop. Evidence `culling-depth-trial-20261127T091527Z/summary.json` and matching guard logs. Depth observation was unavailable because the local probe rejected actual R32G8X24_TYPELESS; no geometry conclusion from its missing image. No images or original program assets uploaded.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2309:upstream-pr/2309'
git switch 'upstream-pr/2309'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2309'
git switch 'upstream-pr/2309'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2309'
git switch 'upstream-pr/2309'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2309'
git switch 'main'
git merge --squash 'upstream-pr/2309'
git switch 'main'
git merge --ff-only 'upstream-pr/2309'
git switch 'main'
git merge 'upstream-pr/2309'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2307
No description provided.