Skip to content

Shaders: one back edge per block, for the dxil-spirv in Proton - #2977

Open
neonbyte1 wants to merge 1 commit into
Marvisak:mainfrom
neonbyte1:pr/one-back-edge
Open

neonbyte1 wants to merge 1 commit into
Marvisak:mainfrom
neonbyte1:pr/one-back-edge

Conversation

@neonbyte1

@neonbyte1 neonbyte1 commented Nov 26, 2026 •

Copy link
Copy Markdown

A latch block that branches back to both its own loop's header and the outer loop's makes dxil-spirv recurse until its stack runs out in LoopMergeTracer::trace_from_parent, when the shader also reads other lanes. The pipeline creation never returns. I reported it as HansKristian-Work/dxil-spirv#380; the fix there (#381) isn't in any vkd3d-proton release yet, and the vkd3d-proton GE-Proton ships pins the affected dxil-spirv.

DXC never emits this shape, because its loops get a latch per back edge. So the translator now does the same:

  • The outer back edge leaves through a latch block of its own. That block counts the outer loop's iterations like any other back edge, and aborts at the limit.
  • The bitcode writer no longer folds an empty outer latch into a block that already branches back to another header.

Translation over the whole shader pack: the emitted counts per stage are unchanged, and 9 programs emit different DXIL. Those are the 9 that had such blocks:

  • InstanceCulling: CS_Prop_BatchNoCull, CS_Prop_BatchCullReflect, CS_Tree_BatchNoCull, CS_Tree_BatchCullReflect
  • ShallowWaterSim: CS_PreSim, CS_PreSimWithDisturb, CS_SurfaceWaveSimUpdate
  • WaterSimMgr:CS_UpdateDynamicFoam
  • indirect_light_probes:CS_IrradianceCache_SpatialFilter_Separable

Byte-identical everywhere else.

Pipelines (RTX 5090, driver 620.73.04, Wine 11.22, vkd3d-proton 3.1-83 from GE-Proton11-14, victory translate --pipelines on CS_Prop_BatchNoCull's container, shader cache off):

Tests: two new ones, a_latch_branches_back_to_one_header (lowering) and an_inner_latch_keeps_the_outer_latch (writer). victory-shader under Wine: 300 passed and 4 failed, against 298/4 on main; the same 4 Wine failures, fixed by #2968, #2973 and #1266. Clippy (with and without diagnostics) and cargo xtask policy are clean.

Not tested on Windows. There, DXC-shaped loops are simply what the driver usually sees, so I don't expect a change beyond the 9 programs.

AI-assisted (Claude); measured on my machine, no game data shared.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified both layers of the dxil-spirv#380 fix. Lowering: when a conditional has back edges to two different headers, the outer (lower rpo) edge goes through a dedicated latch block that counts the iteration itself — so the inner edge keeps normal counting and no block branches back twice. The plan() pass is the safety net: any written block that would still reach two back-edge headers un-folds the extra successors. Both the unit test (folded empty outer latch stays a block) and the real GCN nest test assert <=1 back header everywhere.

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

Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP + dxil.dll, VICTORY_D3D12_DEBUG=1) — clean CFG transformation and ready to merge:

  • Splitting dual-back-edge conditional branches in lower.rs:10197-10239, 10320-10334 via latch(b, to) updates self.edges, fill_phis, pending_masks, and counters consistently, and bitcode.rs:738-756 prevents empty-block folding from re-creating multi-back-edge headers without breaking plan.src PHI mappings or irreducible-loop splits.
  • Note on 512 KiB file-size cap: on 63bcca43, emit/lower.rs reaches 523,660 B (only 628 B below 524,288 B), so merging after any other lower.rs PR will require moving helpers to a submodule.

Local verification:

  • victory-shader (ir::, structure::, emit::bitcode::, emit::lower::tests, emit::flow_tests, emit::crosslane_tests, emit::synthetic_tests, emit::semantics_tests): 119 passed (only failure is pre-existing RTX 5090 baseline gathers_at_a_level_match_the_hardware), including both new latch tests
  • cargo clippy --locked -p victory-shader --tests -- -D warnings (default & --all-features) + cargo xtask policy (191 files ok): 0 warnings

@neonbyte1

Copy link
Copy Markdown
Author

Thanks, good catch on the size. For whoever merges: this PR and #2968 both grow emit/lower.rs. On 63bcca43 the file is 520,563 bytes; #2968 adds 601 and this one 3,097, which together leaves about 27 bytes under the 512 KiB limit. Any further lower.rs change after both will need the file split (moving its mod tests out, as some branches already do). If you'd rather have that split in this PR, I can add it.

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work; needs the maintainer's decision. This gives an inner latch that also continues the outer loop its own counted latch (Lower::latch in lower.rs). In bitcode.rs, the plan's folding no longer folds that latch back in, so no written block branches back to two headers. The code reads consistently, and the two tests check that shape.

On your reply:

What would still help: a pipeline run of the 9 changed programs on a Windows host (native D3D12), from anyone who has one, to show the new shape costs nothing there.

CI: passing.


Generated by Claude Code

ntgata1-dotcom added a commit to ntgata1-dotcom/VIctory-Linux that referenced this pull request Nov 26, 2026
…il-spirv in Proton

From Marvisak/VIctory#2977 (opened by neonbyte1; original commits and authors kept). Not yet merged upstream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A latch that branches back to both its loop's header and the outer loop's
makes dxil-spirv recurse until its stack runs out when the shader also
reads other lanes (HansKristian-Work/dxil-spirv#380; the dxil-spirv that
GE-Proton's vkd3d-proton pins has it): pipeline creation never returns.
The outer back edge now leaves through a latch of its own that counts the
outer loop's iteration, and the writer no longer folds an empty outer
latch into a block that already branches back (it keeps the block's own
back edge, else the one to its innermost header).

Over shaders.rpf for 32-lane hosts the emitted counts are unchanged; 9
programs change (the four InstanceCulling batch shaders, three
ShallowWaterSim, WaterSimMgr's UpdateDynamicFoam, an IrradianceCache
filter), the 9 that had such blocks (35 before, none after). The four
InstanceCulling pipelines are now created on GE-Proton11-14's
vkd3d-proton.
@neonbyte1

Copy link
Copy Markdown
Author

Fixed the doc comment's indentation on count_iteration (amended, same single commit).

On the other points:

  • Why change the output for a Linux converter: the shape we emitted, one block branching back to two loop headers, is legal DXIL, but DXC never produces it. The change brings VIctory's output to the shape DXC gives these loops. dxil-spirv#381 fixes the converter, but it isn't in any vkd3d-proton release yet, and Proton users will run pinned versions for a while after. Without the change, CS_Prop_BatchNoCull and the other instance-culling pipelines never finish building under Proton, and the game waits on them.
  • Windows: I have no Windows machine, so a run of the 9 changed programs' pipelines on Windows would need someone else. They are byte-identical everywhere else.
  • lower.rs size: happy to move its mod tests into lower_tests.rs (#[path], as some branches do) in a separate PR, so this one stays reviewable. Say if you'd prefer it here.

@neonbyte1

Copy link
Copy Markdown
Author

The lower.rs test move is now its own PR, #3097: lower.rs goes to 468,320 bytes, so this PR and #2968 both fit with room to spare. The tests are unchanged, 33 before and after.

AI-assisted (Claude); measured on my machine, no game data shared.

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