Shaders: single-RPO sparse 1-pass propagate_copies, compact Def table, O(log S) scalar lookup, and stack scratch in resource::track #2785
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!2785
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2785"
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?
@RVZO6 on GitHub · 2026-11-25 20:23 UTC · original
RVZO6:rvzo/resource-track-fast→main· +413 −111 · 1 files · 1 commits · openClaimed in #1633: #1633
Summary
Speeds up
resource::track(crates/victory-shader/src/resource.rs,+415/-113including reference-equivalence test and benchmark) with 100% identicalResourcesoutput:propagate_copies: computesir::reverse_postorder(&p.blocks)once inTracer::new(instead of 2–3×). Round 0 settles every non-copy and constant write once while collecting only phis and value-copy edges into an RPO-orderedworklist; when no phi argument or copy source observesNoneon round 0 (acyclic CFG), copy propagation converges in 1 pass instead of always running ≥2 full-program passes re-runningspilled.get,copy_source, andrestored.Vec<Def>table: mergesdefs,phis, andinputs(3Vecs, 52 B/Value) into oneVec<Def>(12 B/Value).out.scalar.binary_search_by_key(&load, |s| s.0)on strictly-sortedout.scalarintrack().Vecs infew_atoms(),descriptor(),edge_taken(), andselect()on the common path (<= 8dwords).Measured on
13f91ca(--release resource::tests::bench_resource_track, median of 3×50 runs)13f91ca)245.6 µs/run138.0 µs/run46.3 µs/run27.7 µs/runNot a duplicate of
track(), orthogonal toTracerinternals /propagate_copies/Def/binary_search_by_key/ stack scratch) and #1633; no overlapping PR or claim.Verification
windows-latestMSVC + WARP SM 6.6 CI (both clippy-D warningsprofiles,xtaskpolicy 6/6,victory-shader272/272 including newsparse_copy_propagation_matches_full_passes_on_acyclic_and_cyclic_cfgverifying exact equality with the full-pass algorithm on acyclic, cyclic, and waterfall CFGs): https://github.com/RVZO6/VIctory/actions/runs/45693633259AI-assisted: T3 Code (Antigravity, gemini-4-neon)
5dc17ab554to77176dad56@kotekompotek on GitHub · 2026-11-25 20:41 UTC · original
This hits the right hot path (resource::track dominates translate time on large shader sets). The load-bearing test is sparse_copy_propagation_matches_full_passes_on_acyclic_and_cyclic_cfg - a differential check against the old algorithm is the correct way to prove a copy-prop rewrite. def_site/phi_of/input_of accessors replacing the eager maps is consistent with #2784's lazy-table direction; the two PRs overlap in the same struct so expect a small merge tangle.
@oni-swr on GitHub · 2026-11-25 20:57 UTC · original
Independent WARP/CPU verification of head
d09e563d42eac61c7e4e0a679c792f22a489ba8emerged cleanly ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca.Environment: Windows 11 x64, WARP/CPU only (
VICTORY_WARP=1,VICTORY_D3D12_WARP=1), no physical GPU, no game files; Windows SDK 10.0.26100.0 x64dxil.dll1.8.2502.11.Tests (
cargo test --no-fail-fast): victory-shader: 268 passed, 3 failed, 4 ignored (baseline 267 passed, 3 failed, 3 ignored; +1 new test, +1 ignored benchmark). victory-shader baseline onorigin/main: 267 passed, 3 failed, 3 ignored; the 3 failures (synthetic_tests::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) fail identically onorigin/mainunder WARP, so they are not caused by this PR.Negative control: forcing the early-return in
propagate_copies(if !saw_none→if true) makessparse_copy_propagation_matches_full_passes_on_acyclic_and_cyclic_cfgfail; restored afterwards.Clippy:
cargo clippy -p <affected crates> --all-targets -- -D warningsclean (exit 0).fmt:
cargo fmt --checkis not clean onorigin/mainitself (891 diff hunks across many files); this PR: 894 hunks (+3 vs main, in the touched file).Review: Single forward pass converges only when no phi argument or copy source was unresolved, otherwise the worklist iterates to the same fixpoint as the old full passes; the new test compares against a reference implementation on acyclic, cyclic and waterfall CFGs. The
binary_search_by_keyonout.scalarrelies on it being sorted by load site, which holds since it is pushed in program order. Diff contains no game files, dumps, shader names or retail hashes.AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5).
@fuzeofficlal on GitHub · 2026-11-25 21:13 UTC · original
Reviewed and benchmarked
d09e563don Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll) againstmain(13f91ca).Code review
!saw_none(every read phi arg, copy source, andfirst_spilledreload was alreadySome) is algebraically equivalent to full fixed-point iteration; any back-edge, later-defined phi, self-referential phi, or out-of-order reload setssaw_none = trueand falls back to the sparse1..MAX_ROUNDSloop (64 total rounds, matching prior0..64).out.scalar.binary_search_by_keyrelies on(b, i)insertion order fromtrack, which is strictly monotonic;few_atoms's[Bool::FALSE; 65]stack pops 1 and pushes at most 2 per node with early exit atnodes > 32(max depth33 < 65).git merge-treevs13f91ca,#2664,#2784,#2786,#2787,#2385, and#2154; conflicts inresource.rs::propagate_copieswith#2387(which addsxor_cancelledthere—easy to adapt by settingsaw_none = trueifxor_cancelledsees an unresolved operand).Verification & same-machine
--releasebenchmark (rustc 1.98.1MSVC)dxil.dllvictory-shader --features host: 268 passed, 0 failed (includingsparse_copy_propagation_matches_full_passes_on_acyclic_and_cyclic_cfg); RTX 5090 +dxil.dll: 255 passed, 0 failed (0 regressions).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings;cargo xtask policy: 184 files ok.resource::tests::bench_resource_track(--release, 3-run median × 50 iters, vs13f91ca):acyclic_4584:194.7 µs/run->103.8 µs/run(1.88× / -46.7%)loop_2007:19.6 µs/run->13.3 µs/run(1.47× / -32.1%)@Marvisak on GitHub · 2026-11-25 23:14 UTC · original · edited 2026-11-26 07:18 UTC
Automated triage for the maintainers.
Needs work. Re-reviewed at
77176da. The first point is resolved:track()incrates/victory-shader/src/resource.rsagain uses the linearout.scalar.iter().find(..), so a non-monotonic push order, as with #2422's RPO walk, stays correct.The second point is still open. The only end-to-end numbers in the thread, from @steven-seagull27, show no gain for full translation (74.2 vs 74.7 ms, 38.9 vs 39.1 ms, 55.0 vs 56.8 ms). Dropping the binary search also gives back part of the in-pass gain. A ~500-line rewrite of a subtle pass needs either an end-to-end improvement, for example
translate --cachetime over a real program set, or a cut-down to the parts that clearly pay off.Reply to the author: thanks for the fix. Please add a measurement or narrow the change.
CI:
checkpassing.Generated by Claude Code
@RVZO6 on GitHub · 2026-11-26 00:20 UTC · original
Rebased onto current
main(63bcca4, head5dc17ab). PreservedTracer::sums(t.sums.take()) from63bcca4. Verified green onwindows-latestMSVC + WARP SM 6.6 CI (clippy, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45727774760.@steven-seagull27 on GitHub · 2026-11-26 03:15 UTC · original
I merged
5dc17abonto the gameplay reporter's Part 7 build (4fdad62) and compared the two Windows release builds. Across 192 public compute shaders, all emitted DXIL bytes and host binding metadata matched. All 384 DXIL outputs passed the Windows SDK validator.resource::track, 4,584 instructions, 128 scalar loads and 256 buffer loadsresource::track, 2,007-instruction loopThe first two rows are medians of seven 50-call runs. Each full-batch result is the median of 21 samples in seven alternating trials. These inputs show a repeatable reduction inside the resource pass. The eight-worker totals were close, with substantial run-to-run variation. The full-translation fixture accepts
VICTORY_BENCH_CORPUS=table-loadsfor the third batch.One integration detail for #2422. Its RPO walk appends scalar
(block, instruction)keys in a different order than this PR's binary search expects. I moved the setup of the existing indexed waterfall to a higher-numbered block. Each PR independently retained the dynamic table load. Taking both changes as written droppedwaterfall.loadsfrom[(1, 2)]to[]. The two static loads executed before that loop and made the lookup table unsorted by block number.The regression fixture and integration fix are available on my fork. The fix searches by the existing RPO rank and instruction index, and uses the same traversal for tracing and insertion. On the combined build all 32 lanes sampled the expected alternating texture values on the RTX 5080, built-in WARP and WARP 1.0.22. The combined resource suite passed 38 tests, the waterfall suite passed six, and strict Clippy and asset policy passed. This applies when taking both changes together;
5dc17abalone passed the regression.@RVZO6 on GitHub · 2026-11-26 05:43 UTC · original
Addressed the
out.scalarordering feedback in77176da:out.scalar.iter().find(|s| s.0 == load)lookup intrack()so non-monotonic block insertion orders (such as #2422's RPO walk) remain sound.Verified green on
windows-latestMSVC + WARP SM 6.6 CI (clippy default +--all-features,xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45762903919AI-assisted: T3 Code (Antigravity, gemini-4-neon)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.