Repository navigation
Shaders: every loop has one back edge (vkd3d-proton's converter recursed without end on four compute pipelines) - #119
Conversation
…does not recurse without end Under Wine + vkd3d-proton, four of the title's compute pipelines were never made: dxil-spirv recursed until the stack overflowed (flatten_subgroup_shuffles -> recompute_cfg -> recompute_immediate_dominator <-> find_common_dominator) on a module that uses WaveReadLaneAt and has a loop header with two back edges, or a block that branches back to two headers. The worker thread was lost with its stack and the pipeline stayed "being made" for the whole run. The writer now gives every loop header one latch and every block at most one branch back (Module::one_back_edge_each, before write()), and the empty-latch fold never creates a second back edge. The program does the same. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TsTmwWj9LVy4o3qDH52Jas Signed-off-by: Impre-visible <69050895+Impre-visible@users.noreply.github.com>
|
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,
A sample of 400 other saved translations also converts on So this PR is a workaround for the vkd3d-proton builds people actually run today (I hit it with 🤖 Generated with Claude Code |
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