GPU: refresh a copy's distant ranges apart, not their span #4808
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!4808
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4807"
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?
@Jineggegg on GitHub · 2026-12-01 09:33 UTC · original
Jineggegg:disjoint-refresh-ranges→main· +298 −66 · 1 files · 15 commits · closed without mergingBased on
mainate1251c31; one commit.Problem
Batch::add(crates/victory-gpu/src/host.rs) merges all of one submission's refreshes of a host copy into a single range, bymin/max. So two lists that each ask for 4 KiB, one at each end of a 64 MiB buffer, produce a 64 MiB refresh:Shadow::updatecopies the whole range. The bytes between the two asks are copied for nothing.Reproduction
In one submission, issue two refreshes of the same buffer copy, far apart: for example at offset 0 and at offset 12 × 64 KiB, each half a page long. Then flush.
PREPARING[1](bytes copied) grows by up to 12.5 pages.The GPU test
host::batch::distant_refreshes_of_a_copy_are_refreshed_apart(below) does exactly this.Change
Spans: one copy's ranges to refresh, kept sorted and disjoint.JOIN_WITHINof (one write-watch page, 64 KiB). Ranges it bridges join together.Batch::refreshesholds(copy, Spans)instead of(copy, from, to).add,flush_oneandflush_allgo through the ranges.flush_all:nothing_new_all) gets one entry per range.Spans::retainconsumes the answers in the same order.nothing_new_withper range, against the same snapshot of what was asked ahead (ahead_snap) thatmainuses.sift_spans(one span per copy) becomessift_refreshes(all of a copy's ranges). It is the same parallel, 64-item chunked sift over the same snapshot, and it keeps theVec's capacity. A copy is kept if any of its ranges may copy something. Its existing test now checkssift_refreshesand keeps the same subset.ask_aheadgets every range.wide_each_scoped,wide_run, the sequential no-op path and the plain sequential path refresh a copy's ranges one after the other.What is not changed:
ahead/ refresh-front coverage is still one span per copy and is untouched.Tests
New unit tests, no GPU needed (
host::spans_tests):distant_ranges_stay_apart_and_near_ones_join: a gap of exactly a page joins, a page and one byte does not, a bridging range joins all, and insertion below the first range works.spans_match_a_brute_force_join: 2,000 random submissions of 1–12 ranges over a 32-page window, compared with a brute-force join. It checks that no byte asked for is dropped and that the gap between any two kept ranges is more than a page.retain_keeps_what_is_kept.A test that needs a GPU (
#[ignore = "needs a host GPU: run in the GPU window"]),host::batch::distant_refreshes_of_a_copy_are_refreshed_apart. It registers a 16-page title buffer, adds two distant refreshes and one near one throughBatch::add, checks the twoSpans, flushes, and checks that at most the bytes asked for were copied.Results on Windows (toolchain pinned in
rust-toolchain.toml, Rust 1.98.1; RTX 5090, driver 621.14):main(e1251c31) does not pass-D warningsat the moment: 4 warnings without--all-features(fieldloop_capsis never read incrates/victory-shader/src/emit/lower.rs; manual implementation of.is_multiple_of()incrates/victory-gpu/src/host.rs; match can be simplified with.unwrap_or_default()incrates/victory-hle/src/modules/xmem.rs; methodrangedis never used incrates/victory-gpu/src/shadow.rs) and 5 with it (also functionmbis never used incrates/victory-gpu/src/copystat.rs). Both CI configurations were therefore run without-Dand compared withmain's diagnostics. This branch adds none, in either configuration.cargo test --workspace --locked --no-run: builds.cargo test -p victory-gpu --lib:host::spans_tests: 3 passed, 0 failed;host::refresh_tests: 7 passed, 0 failed.cargo test --workspace --locked --no-fail-faston the GPU: 2523 passed, 5 failed, 97 ignored (main: 2520 passed, 5 failed, 96 ignored). No new failure: the failures are the onesmainhas itself (list::thin::tests::bindings_record_no_work,shader_cache::tests::every_switch_of_the_translator_is_in_the_key,modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it,emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity,policy::tests::repository_passes_policy).host::batch::distant_refreshes_of_a_copy_are_refreshed_apart(ignored, run by name): passed (1 passed, 0 failed).Performance
There is no micro-benchmark in the repository that isolates this, and the effect does not need timing to show: it is in the bytes a refresh copies. Where a submission asks for distant parts of one buffer, fewer bytes are copied and fewer write-watch pages are queried. In the reproduction above, an unwatched copy goes from up to 12.5 pages copied to at most the 1.25 pages asked for. That bound is asserted by the GPU test. Where every copy is asked for in one range (most copies), the code path does the same work as before, through the inline first range. This is an edge-case improvement, not a frame-time claim.
Risk
updatecalls instead of one, and each is a write-watch query of its own range. With the 64 KiB join rule, the number of calls is bounded by the number of separate asks.Attribution
The idea and the join-within-a-page rule come from upstream Marvisak/VIctory#2428 by borosf (open, not merged). This is an adaptation to this repository's
Batch(refresh ahead, wide refresh). The upstream PR also tracks what flushes have copied; that is not needed here, because thisBatchkeeps no such coverage. The commit carriesCo-authored-by: borosf <[email protected]>.AI assistance: the change, its tests and this description were prepared with an AI coding assistant (Claude Code) and checked by the results above.
🤖 Generated with Claude Code
@KruIN689 on GitHub · 2026-12-01 10:36 UTC · original
Independent in-game test: neutral on a CPU-bound PC with hardware RT.
Setup
84bd61e2plus #4760's port. One build as is ("main"); one with this PR's22e0b79echerry-picked. Onlyhost.rschanges; it applies cleanly to that tree although GitHub shows the PR as conflicting.VICTORY_HW_RT=1, Series X native 1440p.What I read from it
cargo test -p victory-gpu --lib batchgives 30 passed, 4 ignored.Limits
Tested with the help of Claude Code (Claude Opus 5.5).
@KruIN689 on GitHub · 2026-12-01 10:37 UTC · original
Correction on the 3.1 s frame above: it was a compute program met for the first time, made inline. The log shows
compute pipelines: this frame waited its most for them ... waited_ms=5919, and the run saved 8 new pipelines to the library. That is the deliberate first-run wait (VICTORY_PIPELINE_COMPUTE_WAIT_MS, 3 s, with one make running over it). It has nothing to do with this PR or with the route. The verdict stays neutral.Claude Code (Claude Opus 5.5).
5fabb46e) into disjoint-refresh-ranges 52d9c5ffc9@tillo88 on GitHub · 2026-12-01 15:26 UTC · original
Measured this PR (head
52d9c5ff) merged on top of v2026.11.30.03 (it applied without conflicts), 2 runs, against the release as it is.Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing off. Same save restored before each run (start of the game), prison cutscene, plane cutscene, first boat section, about 6 minutes; warm-up run not counted for speed.
Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.
@trustno1-coder on GitHub · 2026-12-01 18:31 UTC · original
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed