GPU: cheaper guards and copy refreshes in the world (seven switches, all off by default) #987
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!987
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-987"
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?
@cybx on GitHub · 2026-11-25 15:11 UTC · original
cybx:fps-switches→main· +1115 −136 · 10 files · 10 commits · draftDraft. This branch itself has not been run in the game yet. Every frame time and count below was measured on our integration branch (this repository's
mainwith several open pull requests and these commits on top), not on this branch. Each number names the run it comes from. The checks that were run on this branch are listed further down.Why
In the world of the title we test with, a large share of each frame went into keeping the host copies of title memory current, on the submitting thread:
card_dirtywalked all 3,540 card copies at each of about 29 submissions a frame (run int-m-kb);What changes
Always on. These change how an answer is found, not the answer:
watch.rs).clean(andabsent) are bit sets, 64 blocks to a word. Whether a range is all clean is answered a word at a time.writeslooks up once whether a range is a view the guards know, andwrites_intofills a list the caller keeps between askings. A test checks the bit set against a tree of blocks. Diagnostics builds log the guards' askings, the questions to Windows and the protections asked, per frame.watch.rs). It is still retried block by block, but a block that is not committed answers for the whole uncommitted run it begins: one question to Windows, and no protection asked for the rest of the run. The blocks noted absent are the same as before.shadow.rs).BUFFERSandLOOSEare behind anRwLock. A lookup that finds the copy (nearly every one) takes the lock shared.shadow.rs).card_dirtynow empties a queue of the copies that changed, instead of walking every copy in the card's memory at every submission. The same ranges are sent, in the same submissions.queue::presented()is in every build, not only diagnostics builds.Behind switches, all off unless set:
VICTORY_INDIRECT_WINDOW_DRAWS=1VICTORY_INDIRECT_WINDOW=1, a draw ends an indirect draw window only if its shaders can store to buffers, or if its host pipeline is not known. Dispatches and new host lists still end the window.VICTORY_CARD_BUFFERS_MIN_KB=<KiB>VICTORY_CARD_BUFFERS_MB.VICTORY_GUARD_HOLES_FRAME=1VICTORY_GUARD_HOLES_FRAME=2VirtualAlloc,XMemVirtualAllocwithMEM_COMMIT,XMemAllocDefault, and the layer's own allocations for the title. As a safety net, each hole is looked at again once everyVICTORY_GUARD_HOLES_RECHECKframes (16 if unset; 0: never). A hole found committed with no word from the runtime is logged.VICTORY_REFRESH_COMPARE=1VICTORY_WIDE_COMPARE=1VICTORY_REFRESH_COMPARE=1, a refresh with 1 MiB or more to compare is split into pieces of about 256 KiB. The snapshot threads and the refreshing thread share them.VICTORY_VIEW_RECHECK=<N>VICTORY_VIEW_GUARD=0. Once a frame, a share of the clean guarded blocks is reported written once, so each block's copies read it again every N frames. WithVICTORY_REFRESH_COMPARE=1only the bytes that differ are taken. No protection is asked of Windows.VICTORY_VIEW_GUARD=1gives.On the integration branch we ran these switches together:
VICTORY_GUARD_HOLES_FRAME=2 VICTORY_REFRESH_COMPARE=1 VICTORY_WIDE_COMPARE=1 VICTORY_CARD_BUFFERS_MIN_KB=0 VICTORY_CARD_BUFFERS_MB=2048 VICTORY_INDIRECT_WINDOW=1 VICTORY_INDIRECT_WINDOW_DRAWS=1. We also setVICTORY_VIEW_GUARD=0 VICTORY_VIEW_RECHECK=64, which trades correctness for time (see the table below).Measured on our integration branch, not on this branch
Machine: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB, 32 GB RAM, Windows 11. Frame times are the readings of the frame-rate line in the first world cell, several per run; the noise from run to run is about 3-4 ms. "Before" and "after" are neighbouring runs of the integration branch, so other changes may lie between them where noted.
VICTORY_GUARD_HOLES_FRAME=1card_dirty352-370 ms in a 10 s profile; preparing a frame 50.6-52.8 mscard_dirty19 ms; preparing 48.4-49.6 ms. Frames 70.7-71.5 ms against 65.6-71.5 ms: no changeVICTORY_GUARD_HOLES_FRAME=2VICTORY_REFRESH_COMPARE=1VICTORY_WIDE_COMPARE=1(withVICTORY_HEAP_SYNC=0)Shadow::update_free2,676 ms in a 10 s profile; frames 60.9-63.7 msVICTORY_VIEW_RECHECK=64(withVICTORY_VIEW_GUARD=0)VICTORY_CARD_BUFFERS_MIN_KB=0The trade-off behind
VICTORY_VIEW_RECHECK: withVICTORY_VIEW_GUARD=1the world ran at 96.0-100.8 ms a frame (st-u-vg), against 68.5-72.3 ms with it off (st-u-wc). With it off, our notes record a wall of the first world room missing in 7 of 10 runs, because a write through another view of the same pages does not reach the guarded copy. The wall was drawn in all three runs withVICTORY_VIEW_RECHECK(st-v-rk64, st-v-rk64b, st-v-rk16). Three runs are few, so that cause is still a hypothesis.With all of this and the other pull requests, the integration branch still runs the title at about 13-17 fps in the world: 68.1-77.1 ms a frame with the default switches (st-z-play), and 57.0-64.9 ms with
VICTORY_HEAP_SYNC=0 VICTORY_MERGE_GAP=64(st-z-hs0-gap).Checks on this branch
All on this branch's tree (Windows 11, the toolchain of
rust-toolchain.toml):cargo build --profile diag -p victory --locked(withoutdiagnostics): builds.cargo build --profile diag -p victory --features diagnostics --locked: builds.cargo test --profile diag -p victory-gpu --locked: 175 passed, 0 failed, 5 ignored, in each of the last two runs. One earlier run of the same tree stopped with an access violation in the test process after 54 tests had passed. Run again one test at a time, that binary had 174 passed and 1 failed (indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields, which passed in both later runs). The access violation did not come back, and its cause was not found.cargo xtask policy: passes.Left out
heap_pass::Picked::planover B-tree maps). It needsheap_pass.rsfrom #523, which is still open. On the integration branch it tookPicked::planfrom 1,195 ms to 262 ms in a 10 s profile (st-x-play → st-y-play). It can follow #523.VICTORY_RELAY_COPY_QUEUE, which we also ran with. It is not our work, so it is not part of this pull request.VICTORY_FILL_AHEAD). No gain was measured, andmainalready reads ahead by default (fill_ahead;VICTORY_FILL_WAIT=1turns it off).VICTORY_MERGE_RUNS.mainalready has both (IDLE_MOSTis 512 there).main'sviewedset behindVICTORY_VIEW_KNOWN, off by default; our variant behaved likeVICTORY_VIEW_KNOWN=1.Related
cleanset inwatch.rs, to runs of blocks. Whichever goes in first, the other needs a rebase.@UwUCammie on GitHub · 2026-11-25 22:21 UTC · original · edited 2026-11-25 23:22 UTC
I tried the 4 KiB changed-chunk compare with 64 KiB-and-larger card buffers on an RX 7900 XT (RADV 26.3.1, Wine 11.22). The integration build also tracked dirty card buffers. It presented 665 frames in 73.74 seconds, 9.02 FPS at 4,847 draws/frame. The comparable small-card-buffer run without those two changes was 8.36 FPS. Lower upload volume was visible in the frame measurements, but the two changes were bundled, so this does not isolate the compare’s FPS effect.
I also sampled previously initialized pages about to be refreshed on the RX 7900 XT. Across 9,984 samples from a first-room run, all 646,286,720 bytes were readable. Chunks containing a changed byte covered 31.18% at 4 KiB, 39.27% at 16 KiB and 55.84% at 64 KiB. The samples compare against the CPU staging copy and the renderer still performs its normal refresh. The sampler and build instructions are on my fork.
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.