Shaders: every loop has one back edge (vkd3d-proton's converter recursed without end on four compute pipelines) #119
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/119"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Zettrox/ztrx. Originally posted by Impre-visible on 2026-11-25T12:40:12Z.
What
Under Wine + vkd3d-proton, four of the title's compute pipelines are never made on this tree:
CreateComputePipelineStatedoes not return, thevictory-pipelines-Nworker that called it is lost, and the frame line shows(4 being made)for the whole run. This change makes the bitcode writer emit every loop with a single back edge, which avoids the converter bug behind it. Windows is not affected by the bug (no vkd3d there); the change is in the writer, so it applies everywhere.Reported and discussed in #62.
Cause
It is unbounded recursion in dxil-spirv, the DXIL to SPIR-V converter inside vkd3d-proton, on valid input. Built natively at its HEAD (
061225d) and run on the translated shaders saved withVICTORY_SHADER_SAVE:flatten_subgroup_shufflesruns when the module usesWaveReadLaneAt, and itsrecompute_cfgsees the raw CFG beforerewrite_multiple_back_edges. A loop header with two or more back edges, or one block that branches back to two loop headers, then makes the two dominator routines call each other without end. Under Wine each lost thread shows as onevirtual_setup_exception stack overflowline; a larger stack does not help (tried 64 MiB).I am reporting the converter bug upstream separately.
Change
Module::one_back_edge_each(), called just beforewrite(): a block that branches back to several headers keeps the branch to the innermost one and reaches the others through new empty blocks; a header with several latches gets one new latch block that takes the header's phis from them.write()no longer creates a second back edge.every_loop_has_one_branch_back, built from a synthetic program and checked with the existing interpreter.Measured
Translator (Linux,
cargo test -p victory-shader --lib): 171 passed, 0 failed, 2 ignored on this branch.Native dxil-spirv
--validateover all 2,568 translations saved from one run of the title (counts only):27 modules change; the other 2,541 are byte-identical. The 27 were also executed before and after the rewrite in a bitcode interpreter on random inputs (400 to 4,000 seeds from the entry, 300 from each rewritten loop header, every rewritten back edge taken): 0 differences in calls, loads, stores and atomics.
In the title (GTX 1660, Wine from GE-Proton11-6, vkd3d-proton
2576c0b, Linux), first playable scene:stack overflowlines per run(4 being made)all run(0 being made)Not tested / limits
write()says the AMD driver hangs on divergent loops whose exiting block is not the latch. In the merged-latch case the exiting blocks now branch to a new latch, so they are no longer the latch. That is 27 modules. I have no AMD card; this needs a run there before merging.No game files, shader bytes or hashes in this PR.
🤖 Generated with Claude Code
Imported from Zettrox/ztrx. Originally posted by Impre-visible on 2026-11-25T12:51:04Z.
Update on "I am reporting the converter bug upstream separately": I did not need to. Before filing I rebuilt dxil-spirv at today's master,
694cc67("Only run fixup passes after structurizer has run.", 2026-11-25), and the bug is already fixed there:WaveReadLaneAtreproducer061225d(2026-11-24)694cc67(2026-11-25)--validatepassesA sample of 400 other saved translations also converts on
694cc67.So this PR is a workaround for the vkd3d-proton builds people actually run today (I hit it with
2576c0bfrom Proton Experimentalexperimental-11.0-20261112; the tester in #62 saw the same stack-overflow lines with GE-Proton11-14), not for something that will stay broken. Once Proton ships a vkd3d-proton with dxil-spirv at or after694cc67, the rewrite is no longer needed for correctness. Whether to carry it until then is your call; the AMD caveat in the description still applies.🤖 Generated with Claude Code
Imported from Zettrox/ztrx. Originally posted by Impre-visible on 2026-11-25T13:37:31Z.
A caveat I have to add after more runs, before anyone merges this.
Since this change the four pipelines exist and their programs run. On this card (GTX 1660), default settings, the same tree:
Xid 109(context switch timeout)One event of each kind in 33 runs is not proof, and I have not yet identified which submission was on the card in those two cases. But the plausible reading is that one of the four programs that now run can occasionally take very long (they read structures that the ray-tracing structure builder, off by default, never built). I am checking that now and will report here either way.
So please treat this PR as "fixes the converter recursion, may expose a rare long GPU job" until that is settled.
🤖 Generated with Claude Code
Imported from Zettrox/ztrx. Originally posted by Impre-visible on 2026-11-25T13:46:05Z.
Follow-up on the caveat above, from reading the two logs and the four programs:
Xid 109run is still open. The log cannot name the submission that was on the card (a slow submission is only logged when it ends). In that run the four pipelines had already been running for about 90 s in submissions of 7 to 50 ms.memory.rsdefines the programs that walk the ray-tracing structures. Each has loops nested two deep with the writer's 4096-iteration guard per loop, so the worst case is about 4096 × 4096 inner iterations: seconds on a GTX 1660, against a few milliseconds when only the outer limit is reached. With the structure builder off by default they walk structures nobody built. That fits a rare context-switch timeout, but it is an inference; I have one event.The comment on
Builderinpipeline.rssays nothing reads the structures because the programs that walk them do not translate. With this change three of them get a host pipeline, so that assumption no longer holds on vkd3d-proton (and never held on Windows, where these pipelines were always made).I am not proposing anything further in this PR. Options I see, for the maintainer to judge: (a) leave it, since Windows already runs these programs; (b) run the walkers only while the builder's structures are valid, extending the builder's own all-or-none policy to its readers; (c) wait for a working builder. I am working on (c) locally and will report.
🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.