Skip to content

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

Open
powplusplus wants to merge 2 commits into
Marvisak:mainfrom
powplusplus:shader/one-back-edge
Open

powplusplus wants to merge 2 commits into
Marvisak:mainfrom
powplusplus:shader/one-back-edge

Conversation

@powplusplus

@powplusplus powplusplus commented Nov 25, 2026 •

Copy link
Copy Markdown

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 5aa10e5 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

Copy link
Copy Markdown
Contributor

@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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

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.
whiteh4cker-tr pushed a commit to whiteh4cker-tr/cool_fox that referenced this pull request Nov 26, 2026
vkd3d-proton's DXIL conversion (dxil-spirv) keeps one back edge per loop
header, as DXC's code has. With several, it takes the others for forward
edges and recurses without end over the cycle that makes (in programs
with wave shuffles). Under Wine the stack overflow then hangs the thread,
and with it the process (seen here as a deadlock on the heap lock).

Before writing, Module::single_latches sends the back edges of a header
with several through one new block that joins their phi values.

Ported from Marvisak/VIctory#1885 (d48ec767, by powplusplus); see also
Marvisak/VIctory#2754.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ck4nRpEBizbYrjNarbDQc4
whiteh4cker-tr pushed a commit to whiteh4cker-tr/cool_fox that referenced this pull request Nov 26, 2026
vkd3d-proton converts DXIL on the thread that creates the pipeline,
recursively over its control flow. The largest ray-tracing passes
overflow the default 2 MiB, and under Wine the overflow hangs the thread
instead of failing. The pipeline workers now get 256 MiB, reserved only.

Ported from Marvisak/VIctory#1885 (5aa10e54, by powplusplus), without its
change to the offline translate command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ck4nRpEBizbYrjNarbDQc4
DoubleGhosty pushed a commit to DoubleGhosty/cool_fox that referenced this pull request Nov 26, 2026
vkd3d-proton's DXIL conversion (dxil-spirv) keeps one back edge per loop
header, as DXC's code has. With several, it takes the others for forward
edges and recurses without end over the cycle that makes (in programs
with wave shuffles). Under Wine the stack overflow then hangs the thread,
and with it the process (seen here as a deadlock on the heap lock).

Before writing, Module::single_latches sends the back edges of a header
with several through one new block that joins their phi values.

Ported from Marvisak/VIctory#1885 (d48ec767, by powplusplus); see also
Marvisak/VIctory#2754.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ck4nRpEBizbYrjNarbDQc4
DoubleGhosty pushed a commit to DoubleGhosty/cool_fox that referenced this pull request Nov 26, 2026
vkd3d-proton converts DXIL on the thread that creates the pipeline,
recursively over its control flow. The largest ray-tracing passes
overflow the default 2 MiB, and under Wine the overflow hangs the thread
instead of failing. The pipeline workers now get 256 MiB, reserved only.

Ported from Marvisak/VIctory#1885 (5aa10e54, by powplusplus), without its
change to the offline translate command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ck4nRpEBizbYrjNarbDQc4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants