Pipelines: recover when a host compile thread dies (VICTORY_PIPE_FIX=1) #162

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

@⁠jtrudeau1530 on GitHub · 2026-11-26 08:33 UTC · original
jtrudeau1530:pipe-fix-dead-compile-threads → main · +416 −12 · 5 files · 3 commits · open

Problem

On Linux (Wine + vkd3d-proton + RADV) a few compute programs, the screen-space and tiled ray-traced shadow traces among them, never get a host pipeline. vkd3d-proton's dxil-spirv recurses without bound on a loop header with several back edges in a program with lane shuffles (flatten_subgroup_shuffles, then the dominator recursion), the thread creating the pipeline overflows its stack and Wine ends it silently (err:virtual:virtual_setup_exception stack overflow), as described in #111.

That thread is a pipeline worker inside Pending::make, so the pipeline stays "being made" for the rest of the run. Every first use then waits for it and spends the frame's whole wait budget (#73), every frame, and a worker is lost each time.

Change

Behind VICTORY_PIPE_FIX=1 (off by default, read and explained in pipeline/make.rs):

  • The host compile runs on a thread of its own (8 MiB stack, below-normal priority). The worker waits on the thread handle, which is signalled however the thread ends. If no result was sent, the compile thread died.

  • The pipeline is then compiled again with its shaders translated in another control-flow shape (victory_shader::emit::CFG_FORM_RETRIES), each try on a new thread:

    1. CFG_ONE_LATCH: one back edge per loop header, through a new empty latch block (what DXC emits; ir::single_latches).
    2. CFG_ONE_LATCH | CFG_STOP_PER_LOOP: also one loop-limit return block per loop instead of one shared by every loop (lower.rs, abort_block).

    These retranslations bypass the shader cache, and a shape is used only if it binds exactly like the first translation (user data, samplers, root views). The draw tables are re-planned with TablePlan::new.

  • Only if every shape dies is the pipeline dropped: it becomes "made, none" instead of "being made" for ever. Diagnostics name it as "the host compile thread ended without an answer". A panic while making a pipeline also leaves it dropped instead of pending, and the worker survives.

  • With the switch off, nothing changes: the shape is a thread-local that is 0 outside with_cfg_form, so normal translations and the translation fingerprint are unchanged.

Measurements

Linux, Wine 11.18, RADV, RX 7900 XT, vkd3d-proton. Build: avatarmanz main 39031cb merged into codec-d/cool_fox, plus this patch. 150 s runs at the opening of the story, same build and same other switches:

fps waiting for pipelines
VICTORY_PIPE_FIX=1 13.8 0.0 ms
off 3.4 475-525 ms per frame

None of our other switches was worth more than 5-10% each. Because the difference on Linux is this large, I'd suggest making it default-on there, or default-on everywhere if you agree. It only does anything when a compile thread dies. I left it off by default to follow the repo's convention for new switches.

I ported this onto current main (0ce46d5) without the rest of our local patches. That port builds and passes the tests below. The fps numbers above come from the 39031cb-based build; I haven't rerun the game on this exact branch.

Tests

  • New unit test ir::tests::a_loop_with_two_back_edges_gets_one_latch: two back edges to one header give a single empty latch, the same instructions, a header phi with two incoming values, and it is idempotent. A loop with one back edge is left alone.
  • cargo test -p victory-shader (host): 210 passed, 0 failed, 2 ignored.
  • cargo build --locked --profile diag -p victory --features diagnostics --target x86_64-pc-windows-msvc: OK.
  • cargo clippy -p victory-gpu -p victory-shader --target x86_64-pc-windows-msvc -- -D warnings (with and without diagnostics): clean.

Refs #111, #73.

AI-assisted (Claude Code); tested on my machine.

**@⁠jtrudeau1530** on GitHub · 2026-11-26 08:33 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/162) `jtrudeau1530:pipe-fix-dead-compile-threads` → `main` · +416 −12 · 5 files · 3 commits · open ## Problem On Linux (Wine + vkd3d-proton + RADV) a few compute programs, the screen-space and tiled ray-traced shadow traces among them, never get a host pipeline. vkd3d-proton's dxil-spirv recurses without bound on a loop header with several back edges in a program with lane shuffles (`flatten_subgroup_shuffles`, then the dominator recursion), the thread creating the pipeline overflows its stack and Wine ends it silently (`err:virtual:virtual_setup_exception stack overflow`), as described in #111. That thread is a pipeline worker inside `Pending::make`, so the pipeline stays "being made" for the rest of the run. Every first use then waits for it and spends the frame's whole wait budget (#73), every frame, and a worker is lost each time. ## Change Behind `VICTORY_PIPE_FIX=1` (off by default, read and explained in `pipeline/make.rs`): - The host compile runs on a thread of its own (8 MiB stack, below-normal priority). The worker waits on the thread handle, which is signalled however the thread ends. If no result was sent, the compile thread died. - The pipeline is then compiled again with its shaders translated in another control-flow shape (`victory_shader::emit::CFG_FORM_RETRIES`), each try on a new thread: 1. `CFG_ONE_LATCH`: one back edge per loop header, through a new empty latch block (what DXC emits; `ir::single_latches`). 2. `CFG_ONE_LATCH | CFG_STOP_PER_LOOP`: also one loop-limit return block per loop instead of one shared by every loop (`lower.rs`, `abort_block`). These retranslations bypass the shader cache, and a shape is used only if it binds exactly like the first translation (user data, samplers, root views). The draw tables are re-planned with `TablePlan::new`. - Only if every shape dies is the pipeline dropped: it becomes "made, none" instead of "being made" for ever. Diagnostics name it as "the host compile thread ended without an answer". A panic while making a pipeline also leaves it dropped instead of pending, and the worker survives. - With the switch off, nothing changes: the shape is a thread-local that is 0 outside `with_cfg_form`, so normal translations and the translation fingerprint are unchanged. ## Measurements Linux, Wine 11.18, RADV, RX 7900 XT, vkd3d-proton. Build: avatarmanz main 39031cb merged into codec-d/cool_fox, plus this patch. 150 s runs at the opening of the story, same build and same other switches: | | fps | waiting for pipelines | |---|---|---| | `VICTORY_PIPE_FIX=1` | **13.8** | 0.0 ms | | off | 3.4 | 475-525 ms per frame | None of our other switches was worth more than 5-10% each. Because the difference on Linux is this large, I'd suggest making it default-on there, or default-on everywhere if you agree. It only does anything when a compile thread dies. I left it off by default to follow the repo's convention for new switches. I ported this onto current main (0ce46d5) without the rest of our local patches. That port builds and passes the tests below. The fps numbers above come from the 39031cb-based build; I haven't rerun the game on this exact branch. ## Tests - New unit test `ir::tests::a_loop_with_two_back_edges_gets_one_latch`: two back edges to one header give a single empty latch, the same instructions, a header phi with two incoming values, and it is idempotent. A loop with one back edge is left alone. - `cargo test -p victory-shader` (host): 210 passed, 0 failed, 2 ignored. - `cargo build --locked --profile diag -p victory --features diagnostics --target x86_64-pc-windows-msvc`: OK. - `cargo clippy -p victory-gpu -p victory-shader --target x86_64-pc-windows-msvc -- -D warnings` (with and without `diagnostics`): clean. Refs #111, #73. AI-assisted (Claude Code); tested on my machine.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:37:36 +00:00
Author
Owner

@⁠jtrudeau1530 on GitHub · 2026-11-26 08:40 UTC · original

Measured on this PR's own branch (78f0b2e = main 0ce46d5 + this change). Diag build; Linux, Wine 11.18 with the tree-index wineserver (#111), vkd3d-proton, RADV, RX 7900 XT, Series X profile. Two consecutive 150 s runs into the opening of the story, same switches; only VICTORY_PIPE_FIX differs.

VICTORY_PIPE_FIX=1 unset
fps (5 s meter lines, last minute) 13.7 – 15.1 (one 8.2) 2.8 – 3.6
"waiting for pipelines" per frame 0.0 ms 500.1 – 500.2 ms (the whole budget, every frame)
"a host compile thread died; … another control-flow shape compiled" 6 0 (the pipelines never arrive)
world reached at frame 838 895
picture normal normal, but darker (passes missing)

So the earlier cf-x6 numbers hold on the PR branch alone. On Linux/vkd3d-proton, six pipelines whose compile thread dies are enough to cost the full 500 ms pipeline-wait budget in every frame, which matches #73's description.

**@⁠jtrudeau1530** on GitHub · 2026-11-26 08:40 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/162#issuecomment-7186881061) **Measured on this PR's own branch** (`78f0b2e` = main `0ce46d5` + this change). Diag build; Linux, Wine 11.18 with the tree-index wineserver (#111), vkd3d-proton, RADV, RX 7900 XT, Series X profile. Two consecutive 150 s runs into the opening of the story, same switches; only `VICTORY_PIPE_FIX` differs. | | `VICTORY_PIPE_FIX=1` | unset | |---|---:|---:| | fps (5 s meter lines, last minute) | **13.7 – 15.1** (one 8.2) | 2.8 – 3.6 | | "waiting for pipelines" per frame | **0.0 ms** | **500.1 – 500.2 ms** (the whole budget, every frame) | | "a host compile thread died; … another control-flow shape compiled" | 6 | 0 (the pipelines never arrive) | | world reached at frame | 838 | 895 | | picture | normal | normal, but darker (passes missing) | So the earlier cf-x6 numbers hold on the PR branch alone. On Linux/vkd3d-proton, six pipelines whose compile thread dies are enough to cost the full 500 ms pipeline-wait budget in every frame, which matches #73's description.
Author
Owner

@⁠compaccount1-coder on GitHub · 2026-11-26 16:28 UTC · original

Heads-up: merged onto current main (c9c932c), this no longer compiles. Git reports no conflict, so the merge looks clean:

error[E0063]: missing field `probe` in initializer of `Shader`
   --> crates\victory-gpu\src\pipeline.rs:216:21

main gave Shader a probe: Option<crate::lightprobe::Role> field in b4ba4bb (light and texture probes) after this branch's base (0ce46d5), and the Shader { ... } this PR builds for the retranslated program doesn't set it. It's the same program's bytes, so the same role applies. Role is Copy:

        let other = Shader {
            stage: self.stage,
            hash: self.hash.clone(),
            container: self.container.clone(),
            ambient: self.ambient,
            probe: self.probe,
            translated: OnceLock::new(),
        };

With that line, this PR merged onto main builds, and cargo test -p victory-gpu --lib passes on an RX 6700 XT (380 passed). The one failure is views_are_made_beside_the_heap_and_copied_in, which fails on every RDNA 2 card on main too (#298). I found this while running every open GPU PR's tests on real hardware.

AI-assisted: yes (Claude Code)

**@⁠compaccount1-coder** on GitHub · 2026-11-26 16:28 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/162#issuecomment-7197687383) Heads-up: merged onto current `main` (`c9c932c`), this no longer compiles. Git reports no conflict, so the merge looks clean: ``` error[E0063]: missing field `probe` in initializer of `Shader` --> crates\victory-gpu\src\pipeline.rs:216:21 ``` `main` gave `Shader` a `probe: Option<crate::lightprobe::Role>` field in b4ba4bb (light and texture probes) after this branch's base (`0ce46d5`), and the `Shader { ... }` this PR builds for the retranslated program doesn't set it. It's the same program's bytes, so the same role applies. `Role` is `Copy`: ```rust let other = Shader { stage: self.stage, hash: self.hash.clone(), container: self.container.clone(), ambient: self.ambient, probe: self.probe, translated: OnceLock::new(), }; ``` With that line, this PR merged onto `main` builds, and `cargo test -p victory-gpu --lib` passes on an RX 6700 XT (380 passed). The one failure is `views_are_made_beside_the_heap_and_copied_in`, which fails on every RDNA 2 card on `main` too (#298). I found this while running every open GPU PR's tests on real hardware. AI-assisted: yes (Claude Code)
Author
Owner

@⁠jtrudeau1530 on GitHub · 2026-11-26 17:39 UTC · original

Thanks @⁠compaccount1-coder, you're right. I merged current main (c9c932c) into the branch and added probe: self.probe. It now builds clean (diag + diagnostics, x86_64-pc-windows-msvc, 0 warnings). We had already been running the same fix locally on a c9c932c merge (our cf-x9/cf-x10 builds) since this morning, with VICTORY_PIPE_FIX=1 in every run.

AI-assisted (Claude Code).

**@⁠jtrudeau1530** on GitHub · 2026-11-26 17:39 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/162#issuecomment-7199392805) Thanks @⁠compaccount1-coder, you're right. I merged current `main` (`c9c932c`) into the branch and added `probe: self.probe`. It now builds clean (diag + diagnostics, x86_64-pc-windows-msvc, 0 warnings). We had already been running the same fix locally on a `c9c932c` merge (our cf-x9/cf-x10 builds) since this morning, with `VICTORY_PIPE_FIX=1` in every run. _AI-assisted (Claude Code)._
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/pipeline/make.rs
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.
git fetch -u origin '+refs/pull/162/head:github-bot/gh-162'
git switch 'github-bot/gh-162'

Merge

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