Shaders: avoid quadratic planning on unconditional empty-block chains #2638
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2640"
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 Marvisak/VIctory. Originally posted by SinisterRob on 2026-11-25T17:24:06Z.
Folding a linear chain of empty blocks walks the growing chain twice per block. The writer follows predecessor links back to the source, then scans the source’s successor through the folded blocks to check whether two edges land at the same target.
This change records the resolved source when accepting a fold. If that source later folds, its link still leads to the final source. With only one outgoing edge the source cannot split a critical edge or reach the target twice, so the planner can skip the duplicate-edge walk. The existing cycle check still runs before accepting the fold.
These are CPU planning times, median of nine calls to
Module::planon a prebuilt module, using an optimized standalone Linux test build ofbitcode.rs(rustc 1.97.0). Each module consists of a straight chain of branches ending in a return. All four emitted byte streams matched the base revision. I also compared emitted bytes on 10,000 seeded small control-flow graphs containing branches, joins and back edges. All matched. The 12 existing non-ignored writer tests passed.Title shader chain lengths and frame-time impact are unmeasured. This is independent of the phi correctness change in #2622. AI-assisted, synthetic inputs throughout.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:47:57Z.
Reviewed: two changes, both right.
fold[b]now records the ultimate source (plan.src(*p)) so the source survives its own later fold — matching the updated doc. Thesuccs(from).len() == 1early-out is sound: with a single outgoing edge the fold can neither create a critical edge nor a second path to the target, so the reject checks are skipped — that removes the quadratic filter over successors. CI green.Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T17:58:11Z.
Independent verification of head
f01104eca8947cf6dd309f24841833e1575194e6merged ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca.-j 4, CPU-only. I still setVICTORY_WARP=1,VICTORY_D3D12_WARP=1and put dxil.dll (1.8.2502.11) on PATH as a precaution, sincevictory-shadertests also dispatch on WARP.bitcode.rsModule::plan: the fold source is resolved when stored, and a single-successor source skips the critical-edge and duplicate-path checks. I traced that those checks cannot trigger with one outgoing edge; the existingplan.foldassertions still hold. Merges cleanly.-p victory-shader --all-targets): no warnings.cargo test --locked --no-fail-fast -p victory-shader: 267 passed, 3 failed, 3 ignored, identical toorigin/mainon WARP (267/3/3). The same 3 fail on both:a_mask_joined_with_data_at_a_uniform_loop_is_its_number,gathers_at_a_level_match_the_hardware,permutes_read_the_lane_named_and_zero_from_lanes_left_out(WARP baseline, "no pipeline for a wave of 32"); not caused by this PR.plan().origin/main: N=4000 77.5 ms, 8000 299 ms, 16000 1.216 s (about 4x per doubling, quadratic). PR head: 1.89 ms, 3.66 ms, 7.04 ms (linear). Layout is the same on both (entry + exit).Independent verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or shader names were used. Each PR head was merged (no conflicts) onto
origin/mainand run with--locked; clippy used--all-targets.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:22:07Z.
Automated triage for the maintainers.
In
Module::plan(crates/victory-shader/src/emit/bitcode.rs) a folded block now records its resolved source (plan.src(*p)), and a source with a single successor skips the critical-edge and duplicate-target checks, removing the quadratic walk on long chains of empty blocks. I checked that the only reader of the stored source isPlan::src, which still walks the chain, so the result is unchanged; and that with one outgoing edge the old checks could not reject (criticalneeds more than one successor, and that successor'splan.tois the fold's target through the chain just folded). There is no regression test for the complexity; a small doubling-ratio test would be welcome but is not required. CI:checkpassing.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:07:03Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-shader --lib emit::bitcode::tests: 12 passed, 0 failed, 1 ignored.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by reallyvibe on 2026-11-29T00:18:15Z.
Would you be comfortable with me opening a follow-up PR that preserves your original commit and authorship and adds the regression coverage separately? If you set this aside because of a concern or have a replacement in mind, I’d defer to that.
I checked the patch on Windows against main
63bcca43. On a 1,024-block unconditional chain, source hops fell from 524,800 to 1,023, target hops from 524,800 to zero, and duplicate-edge scans from 1,024 to zero. Disabling either optimization independently tripped the corresponding counter assertion. The extended branching-root test also preserved distinct phi predecessors through a multi-hop chain.The separate #2665 and #2657 combinations passed the synthetic DXIL checks after resolving #2665’s folding-loop conflict. The measurements are synthetic, so real-title performance remains unmeasured.
AI-assisted (OpenAI Codex).
Pull request closed