GPU: keep only the bytes shaders may write, each once per submission #1267
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!1267
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1267"
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?
@TG0000 on GitHub · 2026-11-24 16:57 UTC · original
TG0000:perf/declared-snapshots→main· +297 −92 · 2 files · 3 commits · openWhy
Before a submission's shaders run, the copy of a buffer is kept so that copy-back can tell what the GPU wrote. The snapshot covers everything from the first declared range to the last. World frames declare ranges that are far apart, and overlapping ones, in a 174 MB heap dozens of times, so most of what is copied is never written, and each new range copies the whole union again.
What
Measured
Time of a looped world frame's submissions (preparation, GPU, copy-back), all ways in one launch (RX 6800, Windows; 8 frames, each repeated with every way; a frame has 36 submissions). This is not frame time, and nothing here is an fps claim. One launch, one area of the world, in a build of
main(ffe310e) with measuring tools and other local changes, the same in every row; about 1,400 of 5,000 draws a frame are still dropped there.mainThe last row is the median of the paired differences, the range is over the 8 frames. A control (the same switches in another order) differed by 9 ms.
Other ways to make the same snapshots cheaper, as my own ports into that tool, 2 frames only, so a hint and not a result: with this change 307 ms, with #440's in its place 464 ms, with #991's 469 ms. These are ports of other people's pull requests; their authors' code may do better.
A model (only the memory copies of each way, with 64 distinct ranges declared 4 times each in a 174 MB block, not the code itself):
main785.5 MB, 68 ms; #1186 atc1dd5b18,363.5 MB, 658 ms (it lost the early return for a range the snapshot already covers); this change 16.0 MB, 2.6 ms.Tests
shadow::snapshot_tests): each declared byte once; only changed declared bytes come back; a dropped copy leaves no snapshot; two copies in one submission do not share theirs. The last two fail without theDrop.cargo test --workspace --locked, clippy with-D warningswith and without--all-featureson Windows, clippy on macOS: pass at4cefaac(346 tests).frame::tests::waits_end_on_ticks_and_count_framesmeasures time: it failed in two runs while a game ran beside it, passes 10 of 10 alone onmainand here, and the run counted above is clean.main's way and this one: title memory and the copies are byte for byte equal in every run, with the writes as recorded and with random ones added (shader writes, undeclared host writes, title writes before copy-back). Seven sets (no change, each of five, all five), 504 runs, 34.7 GB compared, with synthetic overlapping declared ranges too: 0 differences; 0 snapshots left over. Three deliberate faults put into this change are all found with the overlapping ranges (two of three without). The set covers only one frame, and title writes come before, not during, the copy-back.Not handled on purpose
A list reset while its submission is in flight keeps its snapshots until the copy is dropped.
executereturns only after copy-back, inside the title'sExecuteCommandLists, so such a reset is already an error and ends infail(); dropping parts fromreset()could take those of another submission that has the same range.Overlapping copy-backs can replay an earlier CPU edit; that is so on
mainand unchanged here (#1186 is about it).Not verified
Conflicts
shadow.rsconflicts with #440, #991, #1124 and #1186; the other open pull requests that touch this code (#943, #1010, #1024, #1215) merge cleanly.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@justlovett0 on GitHub · 2026-11-24 17:32 UTC · original
Verified on Win10 21H2 / RTX 3080 (driver 621.24) stacked with #986 and #1260: the 174 MB heap-union re-copy was a large part of the ~400 ms/frame copy cost; with this the world runs ~20 fps with no device removal. Combined result on #986. AI use: Qwen Code (model name not disclosed); user-confirmed.
@ChruutvoLuzi on GitHub · 2026-11-24 17:33 UTC · original
Merged at
4cefaaconto r4tedxintegration/testersupdate 9 (94e0ea5), which conflicts inshadow.rs, and measured on an RTX 4090 (driver 621.01, Windows 11 26200).The conflict. The tester tree has #261's
a2243ad("copy-back puts back only what shaders wrote, in two more cases"), written for the single grown snapshot. It does two things:keptreturns a read-only slice, so I added a smallstorethat writes the title's bytes into the parts covering the piece, right after the loop that compares them.Without
store, that tree's testoverlapping_ranges_keep_the_titles_newer_bytesfails; with it, it passes.mainhas that gap too, without this PR: the fix is #261 (a2243ad), which isn't merged. If #261 lands first, this PR will need the samestore. That tree's two tests also need this PR'sONElock now that the snapshots are shared (pub(super)here). With both, all six shadow tests and the 110victory-gputests pass.In the title: diagnostics build, DRED off, same settings and save for both runs. Frames are binned by draws per frame because the runs weren't in the same scene at the same time:
Most of the gain is copy-back, about 190 ms down to about 125 ms per frame. No device removal in either run.
AI-assisted (Claude Code).
@TG0000 on GitHub · 2026-11-24 18:00 UTC · original
Thanks both for merging and measuring this, and @ChruutvoLuzi for tracing the
storegap: noted, if #261 lands first I will rebase and add the same write into the parts covering the piece (withoverlapping_ranges_keep_the_titles_newer_bytesas the check), and the two tests under the shared lock.@BitWuehler on GitHub · 2026-11-24 20:06 UTC · original
Linux + Proton + NVIDIA RTX 5080 runtime data point (filling in the "NVIDIA / Linux and Proton / in-game frame time" items in
Not verified).Note on attribution: I stacked
#1267(4cefaac) together with#1260(incl.#986, replacing#206) and a localMIN_DYNAMIC = 1 << 18(#747) bump on top of#994 + #177 + #454, so the frame-time/draw deltas reflect that combined step rather than#1267in isolation.Setup
620.73.04), CachyOS (Linux 7.3.6-1-cachyos).GE-Proton11-14viaumu-run(VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains).1.0.2.1,--console series-x,diagbuild (--features diagnostics),VICTORY_D3D12_DRED=1,VICTORY_DEBUG_PS=1,VICTORY_SHOW_TARGET=2560x1440-f28-3,VICTORY_NO_WATCHDOG=1.A/B comparison on the same machine & setup (
draws >= 100world intervals)#994 + #177 + #454 + #206(2^16dyn,n = 68)#994 + #177 + #454 + #1260 + #1267(2^18dyn,n = 30)2,867.0 ms/0.30 fps(max2.50)2,016.6 ms/0.50 fps(max5.00)1,076/4,6392,076/5,662copy-back(median ms / MB)228.8 ms/15.2 MB220.8 ms/24.6 MBcopiesprep (median ms / MB)1,565.3 ms/112.6 MB1,235.5 ms/301.9 MB0/0/00/0/0Observations
15.2 -> 24.6 MB), mediancopy-backstayed flat (228.8 -> 220.8 ms) and median frame time dropped by ~30% with noticeably richer debug geometry on screen and no visual/snapshot regressions.copies(input upload/refreshes under Wine) still dominates (~1.24 smedian, peaking at3,842.8 mswith6,656 refreshes/4,805.7 MB, e.g. the 174 MB0x1a3f0000+0xae00000range refreshed10.5x/frame), which matches audio still stuttering/cutting out later in the run.frame=1443), then hit a silent title hang (draws=26,black_frames=17; no0x887A0006, nocrashes.logentry becauseVICTORY_NO_WATCHDOG=1).AI-assisted log analysis and summary; built and run locally on my own retail copy, no game files or raw logs attached.
@marquezinii on GitHub · 2026-11-24 21:48 UTC · original
Measured with the benchmark in #1743, which replays a world frame's refreshes, snapshots and copy-back on a made-up 174 MB heap (36 submissions, 24 overlapping declared ranges each). This PR was merged alone onto
ffe310e. Host: RTX 5070, release build, 6 runs of each build.mainmain's range.@TG0000 on GitHub · 2026-11-24 23:00 UTC · original
Merged main in (fast-forward): its compared-once set, kept writes and counters stay, its snapshot segments become this PR's parts.
Main now snapshots declared ranges only, so the numbers in the description (
ffe310e) are too large for it; what is left is copying a segment again when a range grows it.Benchmark of #1743 on both (Ryzen 9 5900X, RX 6800, release, 3 launches each): median frame 770-784 ms on main, 512-583 ms here; snapshots 384-524 ms against 194-264 ms; copy-back about the same; its checks pass.
Thanks @marquezinii for the benchmark and the measurement. The frame time in the game was not measured again.
victory-gpu 82 and victory-shader 209 tests pass on Windows (RX 6800), clippy clean. AI-assisted (Claude Code).
1277 perf/view-memory-cache : DROP (reported only, not closed)
No local ref. Main's new change tracking asks about the memory once per host copy (watch::track), not at each check: the cost this PR removes is gone, and the function it changes (guard) no longer exists.
Left over in main: xmem::unmap still reports the remapping before it unmaps. A take in between can guard, and mark as taken, a page that is going away. map() reports again and opens it, so I see no wrong result from it (by reading, not tested). Not worth a PR without a failing test.
Draft comment (only if the user wants it closed; the review has no open question):
Main now asks whether memory is a view once per host copy (
c75fdba), so what this PR saves is no longer spent. Thanks @adamdotpy for the careful review.I found no case on the new code where the unmapping order gives a wrong result (by reading only). AI-assisted (Claude Code).
1010 perf/user-mode-title-copies : PUSH
local ref: prready/1010 (
caa937c), GitHub head79c9b93git push fork prready/1010:perf/user-mode-title-copies
Resolved: main's per-step diagnostics timer and this PR's run of fills timed as one, both kept (the timer takes its own clock, in diagnostics builds only); module list.
Checks: Mac lint 0. Windows tests gpu 87 (title_copy and fills tests among them), shader 209, 0 failed. Benchmark not run again.
Draft comment:
Merged main in (fast-forward); both the per-step timer of main and the run of fills timed as one are kept.
victory-gpu 87 and victory-shader 209 tests pass on Windows (RX 6800), clippy clean with and without all features. The microbenchmark was not run again and I still claim no frame-time gain.
Thanks @adnanoos for the run in the world. AI-assisted (Claude Code).
139 perf/shader-address-sums : PUSH
local ref: prready/139 (
90cf2f6), GitHub head697c4bcgit push fork prready/139:perf/shader-address-sums
Resolved: took main's tracer whole; the cache sits in a RefCell so its &self stays, and is emptied after the spilled parameters change the origins. One test expected a refusal that main turned into title memory: expectation changed, and the same test file passes on main without the cache.
Checks: Mac lint 0, Mac tests formats 23, shader 118 + 3. Windows tests gpu 78, shader 209 + 3, 0 failed. Benchmark and census not run again.
Draft comment:
Merged main in (fast-forward). Main's tracer is unchanged; the sums are cached behind a RefCell and dropped when the spilled parameters change the origins.
One test follows main's rule that an address from no root parameter is title memory; the same file passes on main without the cache.
victory-shader 209 + 3 tests pass on Windows (RX 6800). The benchmark was not run again. AI-assisted (Claude Code).
999 perf/shader-lane-condition-search : MERGED, CENSUS BEFORE THE PUSH
local ref: prready/999 (255377d), GitHub head
3ca9456git push fork prready/999:perf/shader-lane-condition-search
Resolved: main now remembers refuted states in Bools::meet too; kept this PR's search, tables and implies, added main's
decideson the new node table. The pass that finds all missing phis was REWRITTEN: it looks at main's live edges only and skips edges main calls never taken or dead.Checks: Mac lint 0, Mac tests formats 23, shader 120. Windows tests gpu 78, shader 211, 0 failed.
Not done: the census against main. "None goes from translating to refused", the byte-for-byte check and all timings in the body are from
ffe310eand the old phi pass. Do not repeat them for this head.Draft comment (if pushed without the census):
Merged main in (fast-forward). Main's search now remembers failed states as well, so item 1 gains less than the table says.
The pass that finds every missing phi was rewritten: it follows main's live edges and skips the edges main calls never taken or dead.
victory-shader 211 tests pass on Windows (RX 6800), clippy clean. The corpus comparison and the timings in the description are from
ffe310eand were not run again on this head.AI-assisted (Claude Code).
No push needed (mergeable, no failing check, no open question)
prready/1000, 993, 188, 172, 153, 126 = head + main, only to prove that they merge and build: do not push.
All six: clean merge, Mac lint 0, Mac tests pass (formats 23 to 25, shader 118 to 121). Their Windows-only tests (1000 and 153 gpu, 188 loader) were not run on the merge.
#1000: the two nits promised for its next change (a message when the test is skipped, one line on the order) are still open.
#124 is closed on GitHub: nothing done.
Worktree: C:\Users\theo_\victory-prs (detached at origin/main).
@Marvisak on GitHub · 2026-11-25 01:20 UTC · original · edited 2026-11-25 16:02 UTC
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-gpu/src/shadow.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (merge-candidate) was for an older state ofmain.Generated by Claude Code
@TG0000 on GitHub · 2026-11-25 12:28 UTC · original
Merged main
940d32fin (fast-forward). Two things of main are kept with it: ranges whose shaders mark their writes take no snapshot, and what a refresh puts into a busy range now goes into the parts kept for it (that code merged without a conflict but used the old segments).Because marked ranges take no snapshot any more, what is left to gain is smaller than in the description. Neither the benchmark nor the frame time was measured again on this head.
Windows (RX 6800 and WARP, one thread): victory-gpu 147 and victory-shader 247 passed; clippy
-D warningsclean for the Windows target, with and without all features. AI-assisted (Claude Code).View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.