Shaders: one latch per loop in emitted DXIL (dxil-spirv asserts on two back edges and stalls the pipeline workers under vkd3d-proton) #257

Open
github-bot wants to merge 3 commits from github-bot/gh-257 into main AGit
Owner

@⁠Ortomanic on GitHub · 2026-11-24 23:01 UTC · original
Ortomanic:fx/dxil-single-latch → main · +243 −0 · 2 files · 3 commits · open

Changes

  • The DXIL emitter gives every loop one latch. A loop header the console code continues to from several blocks got several back edges.
  • An empty latch is no longer folded into a block that already branches back to another loop's header, which put two back edges on one block.

vkd3d-proton's dxil-spirv asserts on both shapes (cfg_structurizer.cpp:3492 and :3486). Under Wine the assert ends the thread, so each failing program takes one pipeline worker with it. On 4e17478 all eight workers were gone by world entry, and about 2,100 pipelines stayed "being made" for the rest of the run, with a black world frame.

This is a different failure from the one #210 documents (a merge block without a terminator in the legacy structurizer), and it does not replace that note. Here the converter asserts instead of emitting invalid SPIR-V, and the emitter change avoids it.

Validation

  • CachyOS, Wine 11.22, vkd3d-proton 3.1.r64 (f2963ee2), RTX 5080, driver 620.73.04.
  • Before, on 4e17478: 8 _wassert hits on 8 threads, no host pipeline logged afterwards, 2,111 pipelines still pending three minutes later.
  • After: no assert. The four directional shadow tracers and the checkerboard shadow-ray program, which each translated and then asserted before, get host pipelines, and the backlog drains to 0.
  • Offline, on the tree these commits come from: 505 programs of the title's shader pack hit the :3492 assert in standalone dxil-spirv before the first commit and none after; the second commit clears the four batch-cull compute programs that hit :3486.
  • cargo clippy --workspace --all-targets --locked -- -D warnings for the Windows target, with and without --all-features, and cargo test -p victory-shader -p xtask pass on this branch (cross-compiled from Linux with the pinned toolchain). One unit test is added.
  • Not run on Windows or on AMD. The change only adds blocks to loops that had more than one back edge, so native D3D12 should see the same programs with one extra branch.

AI-assisted patch with local build and runtime validation.

**@⁠Ortomanic** on GitHub · 2026-11-24 23:01 UTC · [original](https://github.com/fxceless/victory-fork/pull/257) `Ortomanic:fx/dxil-single-latch` → `main` · +243 −0 · 2 files · 3 commits · open ## Changes - The DXIL emitter gives every loop one latch. A loop header the console code continues to from several blocks got several back edges. - An empty latch is no longer folded into a block that already branches back to another loop's header, which put two back edges on one block. vkd3d-proton's dxil-spirv asserts on both shapes (`cfg_structurizer.cpp:3492` and `:3486`). Under Wine the assert ends the thread, so each failing program takes one pipeline worker with it. On `4e17478` all eight workers were gone by world entry, and about 2,100 pipelines stayed "being made" for the rest of the run, with a black world frame. This is a different failure from the one #210 documents (a merge block without a terminator in the legacy structurizer), and it does not replace that note. Here the converter asserts instead of emitting invalid SPIR-V, and the emitter change avoids it. ## Validation - CachyOS, Wine 11.22, vkd3d-proton 3.1.r64 (`f2963ee2`), RTX 5080, driver 620.73.04. - Before, on `4e17478`: 8 `_wassert` hits on 8 threads, no host pipeline logged afterwards, 2,111 pipelines still pending three minutes later. - After: no assert. The four directional shadow tracers and the checkerboard shadow-ray program, which each translated and then asserted before, get host pipelines, and the backlog drains to 0. - Offline, on the tree these commits come from: 505 programs of the title's shader pack hit the `:3492` assert in standalone dxil-spirv before the first commit and none after; the second commit clears the four batch-cull compute programs that hit `:3486`. - `cargo clippy --workspace --all-targets --locked -- -D warnings` for the Windows target, with and without `--all-features`, and `cargo test -p victory-shader -p xtask` pass on this branch (cross-compiled from Linux with the pinned toolchain). One unit test is added. - Not run on Windows or on AMD. The change only adds blocks to loops that had more than one back edge, so native D3D12 should see the same programs with one extra branch. AI-assisted patch with local build and runtime validation.
(cherry picked from commit 0226cdbbc77a159837061932acb966a9891d0bc8)
(cherry picked from commit 20bc18f2869e5a85c38ca40887e01d832d0bb36f)
(cherry picked from commit 4547046286ae5bef1a24f763c9496f03977a878d)
The single-latch test covered a header continued from several blocks. This
one covers the other pass: a block with back edges to an inner and an outer
header keeps one, the other goes through a block of its own, and that
header's phis name the new block. Asked for in review of #257.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:39:21 +00:00
Author
Owner

@⁠gingertonik on GitHub · 2026-11-25 05:08 UTC · original

Tested on Linux with an RTX 4080, on top of c96b4f2 (plus local Linux patches that do not touch the emitter). For our set, both commits are needed: the second is what fixes fdd56d97a806bcca.

Offline gate. 935 compute programs saved from one world run (compute only, so not the whole pack), translated for 32-lane waves as the runtime does on this card, then each run through dxil-spirv 114e664e (the version inside vkd3d-proton 2576c0b4a), built natively, Release:

tree convert fail
c96b4f2 931 559d9f0184e15fe3, a1b20bc47e3c9597, e8c962358d862e3f, fdd56d97a806bcca
c96b4f2 + our own one-latch-per-loop change (its output is identical to this PR's on 931 of the 935) 934 fdd56d97a806bcca
c96b4f2 + this PR 935 none
  • fdd56d97a806bcca has a block with back edges to two different loop headers. That is the second commit's case.
  • Same failure as the PR body describes. A Debug build of 114e664e (asserts on) stops at cfg_structurizer.cpp:3492 on the first three and at :3486 on fdd56d97a806bcca. In Release, with asserts compiled out, the same shapes run on into unbounded recursion and the process dies of a stack overflow.

In game (GE-Proton11-12's Wine, vkd3d-proton 2576c0b4a). Each failing program kills one pipeline worker ("has overflowed its stack"), and its pipeline is never built.

  • c96b4f2: 4 overflows and 4 pipelines "being made", in each of 4 runs.
  • With our one-latch change: 1 and 1, in 2 runs.
  • With this PR: 0 and 0, over 15 minutes in the world at 3.6-3.9 fps (259-275 ms a frame), with no device loss.

Not checked:

  • whether the 4 programs this PR changes render correctly (no validator run on them, no image comparison);
  • other GPUs, or 64-lane waves;
  • this PR on current main (310c6eb).

Environment: CachyOS, kernel 7.3.5, NVIDIA 620.73.04, RTX 4080; GE-Proton11-12 (Wine) with vkd3d-proton 2576c0b4a; offline dxil-spirv 114e664e.

AI-assisted (Hermes).

**@⁠gingertonik** on GitHub · 2026-11-25 05:08 UTC · [original](https://github.com/fxceless/victory-fork/pull/257#issuecomment-7153494488) Tested on Linux with an RTX 4080, on top of c96b4f2 (plus local Linux patches that do not touch the emitter). For our set, both commits are needed: the second is what fixes fdd56d97a806bcca. **Offline gate.** 935 compute programs saved from one world run (compute only, so not the whole pack), translated for 32-lane waves as the runtime does on this card, then each run through dxil-spirv 114e664e (the version inside vkd3d-proton 2576c0b4a), built natively, Release: | tree | convert | fail | |---|---|---| | c96b4f2 | 931 | 559d9f0184e15fe3, a1b20bc47e3c9597, e8c962358d862e3f, fdd56d97a806bcca | | c96b4f2 + our own one-latch-per-loop change (its output is identical to this PR's on 931 of the 935) | 934 | fdd56d97a806bcca | | c96b4f2 + this PR | 935 | none | - fdd56d97a806bcca has a block with back edges to two different loop headers. That is the second commit's case. - **Same failure as the PR body describes.** A Debug build of 114e664e (asserts on) stops at `cfg_structurizer.cpp:3492` on the first three and at `:3486` on fdd56d97a806bcca. In Release, with asserts compiled out, the same shapes run on into unbounded recursion and the process dies of a stack overflow. **In game** (GE-Proton11-12's Wine, vkd3d-proton 2576c0b4a). Each failing program kills one pipeline worker ("has overflowed its stack"), and its pipeline is never built. - c96b4f2: 4 overflows and 4 pipelines "being made", in each of 4 runs. - With our one-latch change: 1 and 1, in 2 runs. - With this PR: 0 and 0, over 15 minutes in the world at 3.6-3.9 fps (259-275 ms a frame), with no device loss. Not checked: - whether the 4 programs this PR changes render correctly (no validator run on them, no image comparison); - other GPUs, or 64-lane waves; - this PR on current main (310c6eb). Environment: CachyOS, kernel 7.3.5, NVIDIA 620.73.04, RTX 4080; GE-Proton11-12 (Wine) with vkd3d-proton 2576c0b4a; offline dxil-spirv 114e664e. AI-assisted (Hermes).
Author
Owner

@⁠Ortomanic on GitHub · 2026-11-25 15:11 UTC · original

Thanks @⁠ErRusso and @⁠gingertonik.

  • Test for the via-block path (review note): added in 89f027a, a_block_continuing_two_loops_keeps_one_back_edge. A block with back edges to an inner and an outer header keeps one; the other goes through a block of its own, and that header's phis name the new block. It also checks that no block is left with back edges to two headers and that a second pass adds nothing.
  • Current main (@⁠gingertonik's "not checked"): the branch merges cleanly with 0b0074e. On the merged tree cargo test -p victory-shader -p xtask passes (177) and both bitcode tests pass under Wine. Clippy with -D warnings fails on the merged tree, but with the same errors as 0b0074e alone (dead code and two lints in victory-gpu; #982 and #841 are open for them); on the branch itself it passes in both feature sets.
  • Still not checked here: Windows, AMD, 64-lane waves, and an image comparison of the four programs the second commit changes.

I did not rebase, so the reviewed commits are unchanged; the head is 39b17eb plus the test commit.

AI-assisted (Claude Code); built and tested locally on CachyOS, Wine 11.22, RTX 5080.

**@⁠Ortomanic** on GitHub · 2026-11-25 15:11 UTC · [original](https://github.com/fxceless/victory-fork/pull/257#issuecomment-7166436836) Thanks @⁠ErRusso and @⁠gingertonik. - **Test for the via-block path (review note):** added in `89f027a`, `a_block_continuing_two_loops_keeps_one_back_edge`. A block with back edges to an inner and an outer header keeps one; the other goes through a block of its own, and that header's phis name the new block. It also checks that no block is left with back edges to two headers and that a second pass adds nothing. - **Current main (@⁠gingertonik's "not checked"):** the branch merges cleanly with `0b0074e`. On the merged tree `cargo test -p victory-shader -p xtask` passes (177) and both bitcode tests pass under Wine. Clippy with `-D warnings` fails on the merged tree, but with the same errors as `0b0074e` alone (dead code and two lints in `victory-gpu`; #982 and #841 are open for them); on the branch itself it passes in both feature sets. - Still not checked here: Windows, AMD, 64-lane waves, and an image comparison of the four programs the second commit changes. I did not rebase, so the reviewed commits are unchanged; the head is `39b17eb` plus the test commit. AI-assisted (Claude Code); built and tested locally on CachyOS, Wine 11.22, RTX 5080.
Author
Owner

@⁠gingertonik on GitHub · 2026-11-25 15:26 UTC · original

Thanks. One more data point for current main, at the conversion level rather than unit tests.

On 0b0074e with this PR's two commits, the same offline gate as before (compute programs saved from one world run, translated for 32-lane waves, each run through dxil-spirv 114e664e): 936 of 936 convert. One more program translates on main than on c96b4f2 (ceb5eb68cd99cb07). The other 935 are byte-identical to this PR's output on c96b4f2.

The tree I used carries local patches outside victory-shader. Its victory-shader/src matches 0b0074e merged with 89f027a, except for the new test.

Still not checked here: an image comparison of the four programs the second commit changes, and an in-game run on the merged tree (next).

Environment: CachyOS, kernel 7.3.5, NVIDIA 620.73.04, RTX 4080; offline dxil-spirv 114e664e.

AI-assisted (Hermes).

**@⁠gingertonik** on GitHub · 2026-11-25 15:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/257#issuecomment-7166843973) Thanks. One more data point for current main, at the conversion level rather than unit tests. On `0b0074e` with this PR's two commits, the same offline gate as before (compute programs saved from one world run, translated for 32-lane waves, each run through dxil-spirv 114e664e): **936 of 936 convert**. One more program translates on main than on c96b4f2 (ceb5eb68cd99cb07). The other 935 are byte-identical to this PR's output on c96b4f2. The tree I used carries local patches outside `victory-shader`. Its `victory-shader/src` matches `0b0074e` merged with `89f027a`, except for the new test. Still not checked here: an image comparison of the four programs the second commit changes, and an in-game run on the merged tree (next). Environment: CachyOS, kernel 7.3.5, NVIDIA 620.73.04, RTX 4080; offline dxil-spirv 114e664e. AI-assisted (Hermes).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/257/head:github-bot/gh-257'
git switch 'github-bot/gh-257'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-257'
git switch 'github-bot/gh-257'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-257'
git switch 'github-bot/gh-257'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-257'
git switch 'main'
git merge --squash 'github-bot/gh-257'
git switch 'main'
git merge --ff-only 'github-bot/gh-257'
git switch 'main'
git merge 'github-bot/gh-257'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.