GPU: whole pages a copy's shaders wrote stay in the copy until a touch (VICTORY_OWNER, opt-in) #3677
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3677"
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?
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-28T05:42:41Z.
What's wrong
At the end of a submission, every 64 KiB page shaders marked as written goes
back into title memory (
crate::shadow::copy_back_marked): read the pagethrough the kernel, compare it with the copy's bytes from before the
submission, write back what differs. Most of that work is thrown away. A
census of the pages written back on our integration tree (the switch that
names who first touches each page,
VICTORY_OWNER_CENSUS) found that87 % of them are overwritten by the GPU before anything reads them; of
the rest, the first toucher is mostly our own copy-back of another copy.
The change
VICTORY_OWNER=1(off by default) leaves a whole page the title did notwrite in its copy instead of writing it back:
PAGE_NOACCESS, and the copykeeps the bytes that go back.
writable view of the page's section (
Section::whole, reported to the GPUside with
set_writable_alias), while every title mapping still has noaccess: no reader ever sees the old bytes.
reads and writes (they fault into the existing vectored handler, which
resolves the page before the access retries; a read fault on a page that is
readable again — another thread resolved it, or a mapping replaced it —
continues); our kernel reads (
host::read_into/copy_mappedserve thebytes from the copy without writing title memory); kernel writes
(
watch::writing); DirectStorage's writes into physical pages(
xmem::will_write, before the bytes land, thenreport_writtenafter);the runtime mapping or unmapping memory; the copy going (
Shadow's drop);and a withholding (
Shadow::withhold).lowered only after it is readable again, and a page that cannot be guarded
again is left readable: a count of zero never covers a page with no access,
so the handler's lock-free early out and
serveeither take the lock andfind the page readable, or serve a page that is still held.
the copy already holds the newest bytes (
owning/again), the otherholders are marked changed with the page's bytes kept first, and this
copy's armed held pages keep their bytes at arming (
arm_keeping) so itsown copy-back merges against them.
submission, it is not guarded, it is shown at another address, or its
section has no writable view) is written back through that same view, and
every other holder of the page and of its other mappings is marked changed
with its bytes kept first: the title's mapping is never opened, so a title
write during the copy faults, waits for the guard lock, and lands after
ours. A page kept in the copy reports no bytes written.
submission's shaders wrote goes back by the bytes kept at arming (what
title memory would have held) and the withheld ones are dropped; a held
page they did not write goes back by its older, valid bytes. Another copy's
held page is left to that copy's own copy-back or withholding.
gone, is not written: title memory keeps its bytes and its copy reads them
again. No new page is kept while a later submission may be writing its
copy (
VICTORY_GPU_OVERLAP), and a released title buffer gives its heldpages back at
shadow::unregister.With the switch off nothing is kept: the added costs in the default path are
one relaxed atomic load per
read_into/changed, and for a read accessviolation one relaxed load (the switch) before the handler gives up.
Measured
These numbers are from our integration tree (the fork's
main: upstreamplus 320 merged PRs and our measured changes), with this mechanism plus the
lazy-view base it was built on there — not from this branch, which is the
port. Setup: prison yard, Series X profile, 2560x1440, ray tracing on, 420 s
runs, warm cache, median of the last 30
victory_gpu::host: ... ms/framelines; RTX 5090 (32-lane waves), Wine 11.22 + vkd3d-proton (GE-Proton 11-14),
VICTORY_GPU_OVERLAP=1 VICTORY_CLAMP_WINDOW=1 VICTORY_EARLY_RELEASE=1 VICTORY_EARLY_BARRIERS=1. Two adjacent on/off pairs (on first) are thin evidence. (Edited 2026-11-29: this said "A-B-A-B pairs".)anything reads them; of the remainder the first toucher is mostly our own
copy-back of another copy.
What the switch needs to do anything
Pages must be section-backed (the runtime's physical-page views) so a
writable view of the page exists. Title memory from the runtime's
write-watched pools is not: it goes back as it does today.
Known limits
when both write that page in one submission (it is marked changed, keeps no
bytes to merge against, and its copy-back then keeps title memory). Our
fork's
mainavoids this withmark_others/arm_keepingfor every holder;that is not done here, to keep the memory
arm_keepingallocates bounded.copy_back_marks' held-page loop and theaddress-driven path (
memory.rs) is untested; the tested path iskeep_writes→Shadow::withhold. A copy that did not arm a page it wroteleaks the withheld bytes there (its held page is resolved instead of
dropped).
arm_keeping's cost (64 KiB per armed held page of the copy) isunmeasured on this branch.
later submission may be writing it; only new pages are refused under
overlap.
owner()reads the environment on its first call, which can happen insidethe fault handler (once per process).
Tests
crates/victory-gpu/src/watch.rs(CPU), on a section's page, the runtime'sown writable view of it and a copy. The title's reads and writes are real
loads and stores into a
PAGE_NOACCESSpage, so they prove the handlerresolves the page and the access retries.
The mechanism:
a_lazy_page_leaves_title_memory_alone_until_a_touch,a_title_read_of_a_lazy_page_gets_its_copys_bytes,a_title_write_of_a_lazy_page_keeps_the_copys_other_bytes,kernel_reads_are_served_a_lazy_pages_copys_bytes,a_kernel_write_gives_a_lazy_page_its_copys_bytes_first,a_lazy_page_written_again_is_never_written_in_between,put_back_writes_through_our_own_mapping,a_page_written_again_and_again_goes_back_once,pages_that_cannot_stay_lazy_go_back,a_copy_going_gives_its_lazy_pages_back,the_count_of_held_pages_covers_the_pages_with_no_access,random_touches_lose_no_title_visible_byte(400 random touches of one page).crates/victory-gpu/src/shadow.rs(device, gated):marked_pages_stay_in_the_copy_and_merge_a_title_write,a_held_page_written_again_marks_the_other_copy,a_withheld_held_page_gives_back_the_bytes_kept_at_arming.The review's findings. "Fails with the defect back" means the defect was put
back with the APIs kept and the test run.
the_count_of_held_pages_covers_the_pages_with_no_accesspins the count at both ends; the order insidelazify/resolveis not observable from one threadagainnever reached)shadow::tests::a_held_page_written_again_marks_the_other_copy— a second copy over the page boundary, no title touch between the two copy-backsput_back_marks_the_other_holders_of_the_pageput_back_writes_the_bytes_it_is_given, and the wiring test's second halfa_withheld_page_gives_back_the_bytes_kept_at_arming(CPU) andshadow::tests::a_withheld_held_page_gives_back_the_bytes_kept_at_armingthroughkeep_writes→Shadow::withholda_read_fault_after_the_last_resolve_continues) and a two-thread stress testheld_pagestakes the tracker; no dedicated testarm_keepingcost)lazify_refuses_a_page_whose_own_view_is_not_writableput_kepton a replaced mapping)resolve's code path; no test stages a replaced mappinglazify_refuses_while_a_later_submission_runs— no new page is kept; held ones are not re-checkedreadablebits, switch-off cost)Checks at
9ef6bdb9f, Linux + Wine 11.22 (vkd3d-proton GE-Proton 11-14,RTX 5090): clippy
--workspace --all-targetsand--all-featuresclean;cargo xtask policy191 files ok; rustfmt on the changed lines only, noformatting-only hunks against the base; CPU tests headless — 36/36
watch::with the switch off and on; gated device tests at
ea9b65bfe(the commitbefore the counter order, which cannot change device behaviour) — 57 of 60
pass with the switch off and on, the same 3 fail as the base binary
63bcca43c(34 pass there):D3DCompilerejects unbounded resource arrays×2 and this host caps its view heaps below
HEAP_VIEWS.Not tested
tree. A frame-time run of this branch and a picture comparison are still to
do; the
arm_keepingcost is unmeasured here too.staged deterministically, and the two-thread test is a stress check.
AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-29T08:00:37Z.
Where the measurement lives, and two things the body did not say.
RESULT: https://github.com/neonbyte1/VIctory/issues/178#issuecomment-7252778852).VICTORY_OWNER(on first; the body said "A-B-A-B pairs", edited) on one exe of our integration stack: RTX 5090, Linux/Wine 11.22, vkd3d-proton of GE-Proton11-14, warm pipeline library. Frame -9.0 and -9.1 ms, copy-back -9.3 and -10.0 ms, preparing unchanged.arm_keepingcost, and a pair on our current integration tree, where the mechanism is nearly idle (0 pages offered and 955 lazy pages a frame, against about 12,000 lazy pages in the measured runs).We now hold our own PRs to a rule on the fork: a hardware test with an adjacent control of the PR's own tree before it leaves draft. This one does not meet it yet and stays a draft.
AI-assisted (Claude); measured on my machine, no game data shared.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.