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.

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.

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

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work.

There are two parts. Module::single_latches (crates/victory-shader/src/emit/bitcode.rs, called from Shader before write) sends all the back edges of a loop header through one new block. Pipeline worker threads (pipeline/make.rs queue) and translate workers also get a 256 MiB reserved stack. The rewrite reads correctly to me: back edges are found by DFS, which assumes reducible flow, and the header phis' back-edge values are joined in the new block, so semantics stay the same. Note that the new block has several predecessors, so write's empty-latch folding leaves it in place.

What needs answering before a merge:

  • This changes the DXIL for every host, not just vkd3d-proton. Module::write on main folds empty latches "so the exiting block is the latch as in DXC's loops; the AMD driver hangs on divergent loops otherwise". After this rewrite, a loop whose back edges came from exiting blocks (like the test's body/mid) ends in a non-exiting shared latch, which is the shape that comment warns about. Please show it runs on native Windows with an AMD GPU, or limit the rewrite so exiting back edges keep that shape. The evidence so far is from RTX 3080 under Proton only.
  • Misplaced doc comment. The new test sits between the existing doc comment ("The written bytes are pinned...") and written_bytes_unchanged, so that comment now documents the wrong test. Move the new test above it.
  • The 256 MiB stack is there for a Wine-specific failure mode. It is cheap because it is only reserved, but the maintainer may want to confirm it is wanted on the native Windows target.

CI: no check runs on this head.


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

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.

4 participants