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

Open
powplusplus wants to merge 2 commits from upstream-pr/1885 into main
powplusplus commented 2026-11-25 00:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by powplusplus on 2026-11-25T00:04:05Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6593992542 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1885). Originally posted by [powplusplus](https://github.com/powplusplus) on 2026-11-25T00:04:05Z. --- 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.
catminou4 commented 2026-11-25 01:07:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T00:32:44Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6049697115 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1885#pullrequestreview-6049697115). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T00:32:44Z. **Review:** COMMENTED --- 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.
Marvisak commented 2026-11-25 09:06:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:18:04Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156856244 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7156856244). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:18:04Z. --- <!-- 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)_
sinan-cmyk commented 2026-11-25 12:03:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T11:52:19Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161614010 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7161614010). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T11:52:19Z. --- ### 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).
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:05Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167271865 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7167271865). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T15:43:05Z. --- @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.
Foxiquek commented 2026-11-26 05:04:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Foxiquek on 2026-11-26T04:24:08Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182562584 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7182562584). Originally posted by [Foxiquek](https://github.com/Foxiquek) on 2026-11-26T04:24:08Z. --- 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.
Foxiquek commented 2026-11-26 06:03:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Foxiquek on 2026-11-26T05:25:40Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183475636 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7183475636). Originally posted by [Foxiquek](https://github.com/Foxiquek) on 2026-11-26T05:25:40Z. --- 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.
ColorMeBoom commented 2026-11-29 17:36:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-29T17:36:32Z.


Linux + NVIDIA under Wine: #1885 tested, four programs still need dxil-spirv b540c8a; reaches gameplay with it

Tested #1885 on Linux with an NVIDIA GPU, running the title from first boot into gameplay. Short version: #1885 removes most of the overflows, but four compute programs still overflow the older dxil-spirv on any stack size. With vkd3d-proton built against dxil-spirv b540c8a they all convert, and the title reaches gameplay with faces rendering.

Setup

GPU / driver RTX 4070 SUPER, NVIDIA 620.73.04
CPU / RAM i7-14700K, 32 GB
OS CachyOS, kernel 7.3.5
Wine 11.22 (WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n")
D3D12 vkd3d-proton from GE-Proton11-14 (3.1-83), then vkd3d-proton master 71cae091 built locally (dxil-spirv b540c8a)
dxgi DXVK from GE-Proton11-14
Display gamescope 3.17 headless, 1920×1080
VIctory main at 63bcca4 + #2723, #2118, #439, #2703, #2101, #2312, #2969, #1722, #2968, #1885, diagnostics build cross-compiled with clang-cl/lld-link

1. translate --pipelines with #1885 and the older dxil-spirv

Four compute programs still overflow, even with a 256 MB worker stack. Each overflows within about 50 ms:

fdd56d97a806bcca
da96a8117d87567a
ec34a3f2e09aed11
6b638f32efd6f858

vkd3d-proton's shader dump shows the DXIL reaching it and no SPIR-V coming out, so the recursion is inside dxil-spirv. Proton Experimental's vkd3d-proton (3.2.0, 20261123b) gives the same result as GE's.

Under Wine a stack overflow ends only the thread that overflowed, not the whole process. So the pre-build never finishes: it waits forever on jobs whose workers have died. I worked around that on my branch (happy to open PRs if they're wanted):

  • a dead-worker watchdog, which names the stuck jobs, saves the library and exits 2 after 300 s;
  • translate --pipelines honours VICTORY_SKIP_PIPELINES in diagnostics builds.

With those four programs skipped, the pre-build finishes in about 15 minutes (23,441 pipelines made).

2. The same with dxil-spirv b540c8a

With vkd3d-proton master (dxil-spirv b540c8a) and no skip list, there are no overflows. All four programs convert, and the pre-build exits 0 in 18 minutes (23,443 made). This agrees with #2754: b540c8a or later is needed under Wine even with #1885.

3. Running the title (headless, input scripted with VICTORY_KEYS)

  • Older dxil-spirv, the four programs skipped: first-boot screens, the legal screens and the opening cutscene all render at 30 fps in menus. In the world it runs at about 0.5–1 fps. Faces are missing: hair, eyes, teeth and earrings draw, but the head and face skin don't. The log shows skipped shader fdd56d97a806bcca dropped 1–2 times per frame once in the world.
  • dxil-spirv b540c8a, nothing skipped: faces render in the opening cutscene. It got through to the first gameplay area (the prison yard) within 20 minutes.
  • Both runs: no crash, no NVIDIA Xid errors in the kernel log, nothing in crashes.log. Peak usage was 33 GB committed memory, 22 GB RSS and 11.3 GB of GPU memory.

Still open

  • Further in, many mesh pipelines are dropped with mesh: no dynamic slots for root views. There were 1,013 log lines in the longer run, for example [mesh 3b408d7e675fddc5, pixel c5d4ff74b695d1f2]. In the prison yard the player character's head may be missing, possibly related. I haven't checked further.
  • About 0.5 fps in the world. It isn't yet clear how much of that is first-run shader compilation.

Screenshots and full logs are available if useful.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7259824191 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1885#issuecomment-7259824191). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-29T17:36:32Z. --- ## Linux + NVIDIA under Wine: #1885 tested, four programs still need dxil-spirv b540c8a; reaches gameplay with it Tested #1885 on Linux with an NVIDIA GPU, running the title from first boot into gameplay. Short version: #1885 removes most of the overflows, but four compute programs still overflow the older dxil-spirv on any stack size. With vkd3d-proton built against dxil-spirv `b540c8a` they all convert, and the title reaches gameplay with faces rendering. ### Setup | | | |---|---| | GPU / driver | RTX 4070 SUPER, NVIDIA 620.73.04 | | CPU / RAM | i7-14700K, 32 GB | | OS | CachyOS, kernel 7.3.5 | | Wine | 11.22 (`WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n"`) | | D3D12 | vkd3d-proton from GE-Proton11-14 (3.1-83), then vkd3d-proton master `71cae091` built locally (dxil-spirv `b540c8a`) | | dxgi | DXVK from GE-Proton11-14 | | Display | gamescope 3.17 headless, 1920×1080 | | VIctory | `main` at `63bcca4` + #2723, #2118, #439, #2703, #2101, #2312, #2969, #1722, #2968, #1885, diagnostics build cross-compiled with clang-cl/lld-link | ### 1. `translate --pipelines` with #1885 and the older dxil-spirv Four compute programs still overflow, even with a 256 MB worker stack. Each overflows within about 50 ms: ``` fdd56d97a806bcca da96a8117d87567a ec34a3f2e09aed11 6b638f32efd6f858 ``` vkd3d-proton's shader dump shows the DXIL reaching it and no SPIR-V coming out, so the recursion is inside dxil-spirv. Proton Experimental's vkd3d-proton (3.2.0, 20261123b) gives the same result as GE's. Under Wine a stack overflow ends only the thread that overflowed, not the whole process. So the pre-build never finishes: it waits forever on jobs whose workers have died. I worked around that on my branch (happy to open PRs if they're wanted): - a dead-worker watchdog, which names the stuck jobs, saves the library and exits 2 after 300 s; - `translate --pipelines` honours `VICTORY_SKIP_PIPELINES` in diagnostics builds. With those four programs skipped, the pre-build finishes in about 15 minutes (23,441 pipelines made). ### 2. The same with dxil-spirv `b540c8a` With vkd3d-proton master (dxil-spirv `b540c8a`) and no skip list, there are no overflows. All four programs convert, and the pre-build exits 0 in 18 minutes (23,443 made). This agrees with #2754: `b540c8a` or later is needed under Wine even with #1885. ### 3. Running the title (headless, input scripted with `VICTORY_KEYS`) - **Older dxil-spirv, the four programs skipped:** first-boot screens, the legal screens and the opening cutscene all render at 30 fps in menus. In the world it runs at about 0.5–1 fps. **Faces are missing**: hair, eyes, teeth and earrings draw, but the head and face skin don't. The log shows `skipped shader fdd56d97a806bcca` dropped 1–2 times per frame once in the world. - **dxil-spirv `b540c8a`, nothing skipped:** faces render in the opening cutscene. It got through to the first gameplay area (the prison yard) within 20 minutes. - **Both runs:** no crash, no NVIDIA Xid errors in the kernel log, nothing in `crashes.log`. Peak usage was 33 GB committed memory, 22 GB RSS and 11.3 GB of GPU memory. ### Still open - Further in, many mesh pipelines are dropped with `mesh: no dynamic slots for root views`. There were 1,013 log lines in the longer run, for example `[mesh 3b408d7e675fddc5, pixel c5d4ff74b695d1f2]`. In the prison yard the player character's head may be missing, possibly related. I haven't checked further. - About 0.5 fps in the world. It isn't yet clear how much of that is first-run shader compilation. Screenshots and full logs are available if useful.
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/1885:upstream-pr/1885'
git switch 'upstream-pr/1885'

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/1885'
git switch 'upstream-pr/1885'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1885'
git switch 'upstream-pr/1885'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1885'
git switch 'main'
git merge --squash 'upstream-pr/1885'
git switch 'main'
git merge --ff-only 'upstream-pr/1885'
git switch 'main'
git merge 'upstream-pr/1885'
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!1883
No description provided.