Skip to content

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
Ortomanic wants to merge 3 commits into
fxceless:mainfrom
Ortomanic:fx/dxil-single-latch
Open

Ortomanic wants to merge 3 commits into
fxceless:mainfrom
Ortomanic:fx/dxil-single-latch

Conversation

@Ortomanic

Copy link
Copy Markdown

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.

…several blocks got two back edges; vkd3d-proton's dxil-spirv asserts at cfg_structurizer.cpp:3492 on them, 505 shaders incl. world e4a9f58e3acfcf7b, 38e119267baa5fd9, db07933e964ee6d6)

(cherry picked from commit 0226cdbbc77a159837061932acb966a9891d0bc8)
(cherry picked from commit 20bc18f2869e5a85c38ca40887e01d832d0bb36f)
…ranches back to another loop's header (one block with two back edges asserts in dxil-spirv, cfg_structurizer.cpp:3486: CS_{Prop,Tree}_BatchNoCull, CS_{Prop,Tree}_BatchCullReflect); a block continuing two loops reaches all but one through a block of its own

(cherry picked from commit 4547046286ae5bef1a24f763c9496f03977a878d)

@ErRusso ErRusso left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 39b17eb against 2119b0e.

The emitter now gives each loop one latch, redirecting multiple back edges through a latch block and joining the header's phis there. The extra via-block pass handles a block that continues two loops. The fold guard also prevents putting two back edges on one block.

Verified: emit::bitcode::tests::single_latches passes under Wine. The author's offline run over 505 title programs (none assert after, 505 before) and the live vkd3d-proton run are strong integration evidence.

Non-blocking: the unit test covers the main multiple-back-edge case but not the via-block path (a block continuing two loops). A second bitcode test for that shape would protect the first pass.

LGTM.

@gingertonik

Copy link
Copy Markdown

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).

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 fxceless#257.
@Ortomanic

Copy link
Copy Markdown
Author

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; GPU: clippy passes again on the warnings in victory-gpu #982 and Clippy: main is clean again with -D warnings, with and without --all-features (3 lints) #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 added a commit to Ortomanic/victory-fork that referenced this pull request Nov 25, 2026
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 fxceless#257.
@gingertonik

Copy link
Copy Markdown

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).

Ortomanic added a commit to Ortomanic/victory-fork that referenced this pull request Nov 25, 2026
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 fxceless#257.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants