Shaders: avoid quadratic planning on unconditional empty-block chains #2640
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!2640
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@SinisterRob on GitHub · 2026-11-25 17:24 UTC · original
shader/linear-unconditional-folds→main· +10 −4 · 1 files · 1 commits · closed without mergingFolding 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.
@kotekompotek on GitHub · 2026-11-25 17:47 UTC · original
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.@oni-swr on GitHub · 2026-11-25 17:58 UTC · original
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.@Marvisak on GitHub · 2026-11-25 23:22 UTC · original
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
Pull request closed