Shaders, GPU: one back edge per loop header, and a large stack for pipeline threads #1885

Open
github-bot wants to merge 2 commits from github-bot/gh-1885 into main AGit
Owner

@⁠powplusplus on GitHub · 2026-11-25 00:04 UTC · original
powplusplus:shader/one-back-edge → main · +147 −20 · 5 files · 2 commits · open

Two hangs in vkd3d-proton's pipeline creation, both in its DXIL conversion (dxil-spirv), which runs on the thread that creates the pipeline.

  • One back edge per loop header. dxil-spirv keeps one back edge per loop header, as DXC's code has. With several, the others stay among the header's forward predecessors and form a cycle, and in programs with wave shuffles its dominator search then recurses without end. Module::single_latches, before writing, sends the back edges of a header with several through one new block that joins their phi values.
  • A large stack for pipeline threads. The conversion recurses over the control flow, and the largest ray-tracing passes overflow the default 2 MiB stack; under Wine the overflow hangs the thread instead of failing. The pipeline workers and the translate command's workers get 256 MiB, reserved only.

Found with a native dxil-spirv build under gdb on the DXIL vkd3d-proton dumped.

Results

No program changes whether it emits or validates (translate --validate over shaders.rpf, identical to 70564ae). On main the programs that hit this do not translate yet; with #1883 they do, and then, on an RTX 3080 under Proton, each pipeline created on its own with a 120 s limit:

pipelines hung
#1883 10 of 45 35
#1883 and this, first 35 35 of 35 0

The second run stopped after 35 of the 45 (the machine ran short of memory, nothing to do with the run). Those 35 include 30 of the 35 that hung. Not run yet with this: the four CS_RaytraceVBuffer_*ShaderBinning* passes and CS_RaytraceShadows_Shared, which hung before, and the five CS_Subdivision_* programs.

Testing

  • A unit test: a header with two back edges gets one, through a block whose phi joins both values.
  • cargo test -p victory-shader -p victory-gpu under Proton (RTX 3080 and WARP): as on main (victory-shader 204 passed, victory-gpu 74 passed; the same 5 and 4 fail on main there).
  • clippy, default and all features.
**@⁠powplusplus** on GitHub · 2026-11-25 00:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/1885) `powplusplus:shader/one-back-edge` → `main` · +147 −20 · 5 files · 2 commits · open Two hangs in vkd3d-proton's pipeline creation, both in its DXIL conversion (dxil-spirv), which runs on the thread that creates the pipeline. - **One back edge per loop header.** dxil-spirv keeps one back edge per loop header, as DXC's code has. With several, the others stay among the header's forward predecessors and form a cycle, and in programs with wave shuffles its dominator search then recurses without end. `Module::single_latches`, before writing, sends the back edges of a header with several through one new block that joins their phi values. - **A large stack for pipeline threads.** The conversion recurses over the control flow, and the largest ray-tracing passes overflow the default 2 MiB stack; under Wine the overflow hangs the thread instead of failing. The pipeline workers and the translate command's workers get 256 MiB, reserved only. Found with a native dxil-spirv build under gdb on the DXIL vkd3d-proton dumped. ## Results No program changes whether it emits or validates (`translate --validate` over shaders.rpf, identical to `70564ae`). On main the programs that hit this do not translate yet; with #1883 they do, and then, on an RTX 3080 under Proton, each pipeline created on its own with a 120 s limit: | | pipelines | hung | |---|---:|---:| | #1883 | 10 of 45 | 35 | | #1883 and this, first 35 | 35 of 35 | 0 | The second run stopped after 35 of the 45 (the machine ran short of memory, nothing to do with the run). Those 35 include 30 of the 35 that hung. Not run yet with this: the four `CS_RaytraceVBuffer_*ShaderBinning*` passes and `CS_RaytraceShadows_Shared`, which hung before, and the five `CS_Subdivision_*` programs. ## Testing - A unit test: a header with two back edges gets one, through a block whose phi joins both values. - `cargo test -p victory-shader -p victory-gpu` under Proton (RTX 3080 and WARP): as on main (victory-shader 204 passed, victory-gpu 74 passed; the same 5 and 4 fail on main there). - clippy, default and all features.
vkd3d-proton's DXIL conversion keeps one back edge per loop header, as
DXC's code has. With several, the others stay in the header's forward
predecessors and form a cycle, and in programs with wave shuffles its
dominator search then recursed without end: the thread overflowed its
stack and, under Wine, hung. The ray-tracing shadow passes do this once
they translate. The back edges of a header with several now go through
one new block that joins their phi values.
vkd3d-proton converts DXIL on the thread that creates the pipeline,
recursively over its control flow. The ray-tracing shadow passes
overflowed the default 2 MiB, and under Wine the overflow hung the
thread instead of failing. The pipeline workers and the translate
command's workers now get 256 MiB, reserved only.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:47:36 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:18 UTC · original · edited 2026-11-25 16:00 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/bitcode.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7156856244) · edited 2026-11-25 16:00 UTC <!-- victory-triage v1 head=5aa10e54597d4a5324bcb8494917f2320aa26f4a verdict=needs-rebase at=2026-11-25T16:08:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/bitcode.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 11:52 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 5aa10e54 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 11:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7161614010) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 5aa10e54 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

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

@⁠powplusplus a coordination question from #2309, which carries one commit of yours (364c1bc, one back edge per loop header) together with a follow-up for loops with several back edges per block. The triage asked that it not land twice. Would you rather it land here in #1885 (then #2309 drops it and keeps only its own commit on top), or in #2309 (with your credit kept in the commit)? Either is fine with me; I'll follow whatever you prefer.

**@⁠desplmfao** on GitHub · 2026-11-25 15:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7167271865) @⁠powplusplus a coordination question from #2309, which carries one commit of yours (`364c1bc`, one back edge per loop header) together with a follow-up for loops with several back edges per block. The triage asked that it not land twice. Would you rather it land here in #1885 (then #2309 drops it and keeps only its own commit on top), or in #2309 (with your credit kept in the commit)? Either is fine with me; I'll follow whatever you prefer.
Author
Owner

@⁠Foxiquek on GitHub · 2026-11-26 04:24 UTC · original

Tested on Linux/Proton, and it fixes the stack overflow and the resulting warm hang.

Setup: RX 9070 XT (RADV), Linux Mint 22.3, GE-Proton11-14. Release build cross-compiled with cargo xwin. Both commits were cherry-picked onto the copy of VIctory in LooperSalty/AnyXboxX (third_party/victory, Neptune 2026-11-25c base), not onto this repo's main. 5aa10e5 conflicted there, so its two stack changes were applied by hand, and that tree's victory warm workers got PIPELINE_STACK too.

victory warm shaders.rpf, same environment, before and after:

without #1885 with #1885
has overflowed its stack 3 0
ends hangs: the overflowing workers die under Wine and std::thread::scope waits forever exits after 238 s
compute pipelines 2,672; none for a1b20bc47e3c9597, e8c962358d862e3f, 559d9f0184e15fe3 2,675, 0 refused

The three hashes are the ones that overflowed. They're the same three programs as #2754. A 64 MiB worker stack alone (no emitter change) still overflowed on all three, which fits the unbounded recursion described there. The emitter commit is what fixes it.

cargo test -p victory-shader --release: 185 passed, 0 failed, 2 ignored.

Not tested yet: a game run with this, and Windows.

**@⁠Foxiquek** on GitHub · 2026-11-26 04:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7182562584) Tested on Linux/Proton, and it fixes the stack overflow and the resulting `warm` hang. **Setup:** RX 9070 XT (RADV), Linux Mint 22.3, GE-Proton11-14. Release build cross-compiled with `cargo xwin`. Both commits were cherry-picked onto the copy of VIctory in [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX) (`third_party/victory`, Neptune 2026-11-25c base), not onto this repo's `main`. 5aa10e5 conflicted there, so its two stack changes were applied by hand, and that tree's `victory warm` workers got `PIPELINE_STACK` too. **`victory warm shaders.rpf`, same environment, before and after:** | | without #1885 | with #1885 | |---|---|---| | `has overflowed its stack` | 3 | 0 | | ends | hangs: the overflowing workers die under Wine and `std::thread::scope` waits forever | exits after 238 s | | compute pipelines | 2,672; none for `a1b20bc47e3c9597`, `e8c962358d862e3f`, `559d9f0184e15fe3` | 2,675, 0 refused | The three hashes are the ones that overflowed. They're the same three programs as #2754. A 64 MiB worker stack alone (no emitter change) still overflowed on all three, which fits the unbounded recursion described there. The emitter commit is what fixes it. `cargo test -p victory-shader --release`: 185 passed, 0 failed, 2 ignored. Not tested yet: a game run with this, and Windows.
Author
Owner

@⁠Foxiquek on GitHub · 2026-11-26 05:25 UTC · original

I rebased this onto current main (63bcca4), in case it helps it land: Foxiquek/VIctory@rebase/pr1885-one-back-edge (compare). The conflict was in emit/bitcode.rs. main added a free successors(term) helper, so single_latches and the new test use it instead of the second successors method. Nothing else changed, and authorship is kept.

Checked on the rebased branch:

  • cargo xwin build --release -p victory builds.
  • clippy reports nothing in the PR's lines, and rustfmt shows no new differences from main.
  • victory-shader tests, run under GE-Proton11-14 on an RX 9070 XT: 301 passed, 2 failed, 3 ignored. main gets 300 passed with the same 2 failing (hosts_that_do_not_fuse_are_named, stub_pipeline_is_created). Both are Wine-host tests: no real WARP, and vkd3d accepts an unsigned stub. a_header_with_two_back_edges_gets_one and written_bytes_unchanged pass.

Not tested on Windows, or in game on this rebase. The in-game result in my comment above was the same two commits on AnyXboxX's tree.

**@⁠Foxiquek** on GitHub · 2026-11-26 05:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7183475636) I rebased this onto current `main` (`63bcca4`), in case it helps it land: [Foxiquek/VIctory@rebase/pr1885-one-back-edge](https://github.com/Foxiquek/VIctory/tree/rebase/pr1885-one-back-edge) ([compare](https://github.com/Marvisak/VIctory/compare/main...Foxiquek:VIctory:rebase/pr1885-one-back-edge)). The conflict was in `emit/bitcode.rs`. `main` added a free `successors(term)` helper, so `single_latches` and the new test use it instead of the second `successors` method. Nothing else changed, and authorship is kept. Checked on the rebased branch: - `cargo xwin build --release -p victory` builds. - `clippy` reports nothing in the PR's lines, and `rustfmt` shows no new differences from `main`. - `victory-shader` tests, run under GE-Proton11-14 on an RX 9070 XT: 301 passed, 2 failed, 3 ignored. `main` gets 300 passed with the same 2 failing (`hosts_that_do_not_fuse_are_named`, `stub_pipeline_is_created`). Both are Wine-host tests: no real WARP, and vkd3d accepts an unsigned stub. `a_header_with_two_back_edges_gets_one` and `written_bytes_unchanged` pass. Not tested on Windows, or in game on this rebase. The in-game result in my comment above was the same two commits on AnyXboxX's tree.
github-bot force-pushed github-bot/gh-1885 from 5aa10e5459 to 2e6b2c2b51 2026-11-26 11:39:53 +00:00 Compare
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 00:32 UTC · original · reviewed

Mixed PR: shader/formats parts are macOS-tested in the batch; GPU/HLE parts are Windows-only statics.

One back edge per loop header + large-stack…: apps+gpu+shader mixed — shader part in batch.

**@⁠catminou4** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1885#pullrequestreview-6049697115) · **reviewed** Mixed PR: shader/formats parts are macOS-tested in the batch; GPU/HLE parts are Windows-only statics. One back edge per loop header + large-stack…: apps+gpu+shader mixed — shader part in batch.
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/1885/head:github-bot/gh-1885'
git switch 'github-bot/gh-1885'

Merge

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