Shaders: every DXIL loop gets one latch, and every block one back edge #1524
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1524
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1524/head"
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?
@brunofgmag on GitHub · 2026-11-24 18:45 UTC · original
brunofgmag:shader/single-latch-loops→main· +473 −50 · 1 files · 1 commits · closed without mergingvkd3d-proton's dxil-spirv expects loops in the shape DXC emits: each loop header has one back edge, and each block branches back to at most one header. The DXIL writer did not guarantee either one, and a few console shaders produce both shapes.
What breaks. On Linux under Proton, creating the pipeline for such a shader never returns:
CFGStructurizer::build_immediate_dominatorsrecurse forever betweenCFGNode::recompute_immediate_dominatorandfind_common_dominator.CFGStructurizer::visit(cfg_structurizer.cpp:3486). Release builds skip the assert and then recurse forever inLoopMergeTracer::trace_from_parent.Either way, the thread that creates the pipeline overflows its stack. Wine ends that thread without a message, and anything waiting for the pipeline waits forever. A bigger stack does not help: 2, 16 and 256 MiB all overflow at the same address.
Where it comes from.
lower.rskeeps each console back edge as its own latch ("Back edges stay as they are: the exiting block is the latch").Module::writefolds an empty latch into its predecessor. A console loop with twocontinuepaths therefore ends up with two latches.The change.
Module::writenow normalizes the module before it writes anything:Block::keeps_own_block), so it cannot bring the second back edge back.Headers and blocks with zero or one back edge are not touched. The pinned
written_bytes_unchangedtest still passes, and a new test checks that a single-latch loop writes the same bytes as before.writenow takes&mut self.How it was checked.
bitcode.rscover three latches (one of them a conditional branch with both arms to the header), a self-loop with a second latch, a block with back edges to an inner and an outer header, and that block's new latch joining the other latches of the outer header.victory translatefrom this branch's base (mainatffe310e) over a GTA VI dump and fed every emitted shader to it:PS_MirrorReflectionDeferredDecalTextured, 38 other ped pixel shaders and the computevfx_proj_decal_vbuffer:CS_ProjDecalResolve_Scalarized.translateemits the same number of programs per stage either way.spirv-val --target-env vulkan1.3, andvictory translate --pipelinescreates all 13 pipelines on an RTX 4080 under Proton, where before 7 of them never returned.-D warnings(with and without--all-features) is clean for the Windows target. The workspace tests ran under Proton: the bitcode tests pass, and the 6 tests that fail there also fail on plainmainin the same setup.@brunofgmag on GitHub · 2026-11-24 18:47 UTC · original
This touches the same code as #1145 and #1471: both edit the empty-latch fold in
Module::write, which this PR moves intoModule::folded_latches. Neither one covers a header with several back edges or a block with two back edges. I'll rebase onto whichever of them lands first.@sinan-cmyk on GitHub · 2026-11-24 19:33 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count changes against
main, and the tests pass on Ada.Offline. I merged head
8e14d23ontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost. No program changes its failure reason either.This is the expected result for a correctness fix whose instructions sit behind the earlier failures on
main. The count shows that the change rejects nothing. It does not show whether the output is right.Tests. With the same merge,
cargo test --locked -p victory-shader --libpassed 125, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@geiyiliyabumo on GitHub · 2026-11-24 19:34 UTC · original
Verified commit
8e14d23on Windows 11 / AMD Radeon RX 9060 XT (RDNA4,gfx1200, SM 6.6) + WARP:cargo test -p victory-shader --lib: 125 passed, 0 failed, 1 ignored (all new single-latch / single-back-edge DXIL bitcode tests pass alongside the full GPU VALU & waterfall suites).AI-assisted; synthetic tests only, no game files.
@Marvisak on GitHub · 2026-11-25 00:42 UTC · original
Automated triage for the maintainers. Closing because it is outside the project's scope (VIctory targets Windows hosts; ports, launchers and tooling for other platforms are not being taken).
Rewrites every multi-latch loop so vkd3d-proton's dxil-spirv does not hang: Linux/Proton support, outside the project's scope. It funnels back edges through a new non-exiting latch block, the shape main folds away because the AMD driver hangs on it, and changes Module::write for all hosts (470 lines).
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed