victory-gpu: a copy of title memory in video memory, prepared and tested #3295
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!3295
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3295"
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?
@pes7 on GitHub · 2026-11-26 16:16 UTC · original
pes7:perf/vram-copies→main· +564 −0 · 2 files · 2 commits · openWhat this is
shadow's copies of title memory live in system memory —Host::shared_bufferis aCUSTOMheap buffer withCPU_PAGE_PROPERTY_WRITE_BACKandMEMORY_POOL_L0— because the title's memory is host memory and the copy has to be something the CPU can refresh and compare. The cost is that every shader read of game data crosses PCIe, where on the console the same read is GDDR6.This PR is the mechanism for the other arrangement: the copy a shader reads lives in video memory (
D3D12_HEAP_TYPE_DEFAULT), kept up to date by a copy per changed range and read back through a readback buffer.Why it is not wired in
Deliberately: the integration is a rewrite of
Shadow's write path (Batch::flushstages instead of memcpying,Shadow::copy_back_pagereads throughread), and a rewrite nobody can A/B is worth nothing. Landing the unit first means the next PR is a measured before/after with this underneath it. The module doc lists the four places the integration touches, and#![allow(dead_code)]says so at the top of the file.What the tests are, and what they caught
The six tests are the semantics the integration needs. They run on any host GPU (and skip where there is none or no shader compiler), so CI keeps them honest:
uploaded_bytes_reach_a_shader_and_its_result_reads_backwhat_a_shader_writes_reads_backtwo_ranges_in_one_list_do_not_overwrite_each_otheran_upload_reads_back_without_a_shadera_range_past_the_end_is_refuseda_copy_is_whole_pagesThe first version was wrong, and the tests said why.
upload/readcopied fromCOMMON; the readback came back zeroed — the shader read the buffer before the copy landed. A copy fromCOMMONis not ordered against a shader access on either side of it. Both operations now enter and leave an explicit state:which is the shape
capture.rsalready uses for its readback, and the reason its comment says a title buffer's copy, never transitioned, is only ever read.Verification
No frame-time claim: nothing in the frame path changes.
Where this can go
If it pays, the order that makes it measurable is: (1) this unit, (2)
ShadowwithOption<VramCopy>for copies above a size and within a VRAM budget, behind a switch, (3) the same scene twice. If it does not pay, the switch stays off and the module stays as the documented reason why — which is also worth having, becauseVICTORY_COPIES_IN_VIDEO_MEMORY's result (worse, 3 196 -> 4 289 ms) is easy to misread as "video memory does not help".`shadow`'s copies of title memory live in system memory (`Host::shared_buffer` is a `CUSTOM`/`L0` buffer): the title's memory is host memory, so the copy is something the CPU refreshes and compares, and every shader read of it crosses PCIe. On the console the same read is GDDR6. The one experiment so far (`VICTORY_COPIES_IN_VIDEO_MEMORY`) put them in a `GPU_UPLOAD` heap and measured *worse* (3 196 -> 4 289 ms a frame in the world): that is a BAR window, not video memory. This is the mechanism for the other arrangement, small enough to review on its own and not wired into the frame path: VramCopy::new(len) a buffer in D3D12_HEAP_TYPE_DEFAULT upload(list, offset, bytes) staged now, copied when the list runs read(list, offset, len) -> Read a readback after the list ran gpu() the address a shader reads Nothing is committed to using it yet - `#![allow(dead_code)]` and the module doc say where it plugs in (`Shadow` gaining an `Option<VramCopy>`, `Batch::flush` staging instead of memcpying, `Shadow::copy_back_page` reading through `read`). Landing it separately means the integration PR can be a measured before/after rather than a rewrite nobody can A/B. The tests are the semantics the integration depends on (and they are what found the one non-obvious rule): * `uploaded_bytes_reach_a_shader_and_its_result_reads_back` - bytes the host stages arrive at a shader that reads the copy by GPU address, and the shader's result reads back; * `what_a_shader_writes_reads_back` - what a shader writes is what the write-back path would see; * `two_ranges_in_one_list_do_not_overwrite_each_other` - staged ranges are not shared behind the caller's back; * `a_range_past_the_end_is_refused`, `a_copy_is_whole_pages`, `an_upload_reads_back_without_a_shader` - the edges, and the copy path with no shader in it at all. **What the tests found:** a copy from `COMMON` is not ordered against a shader access on either side of it. The first version of `upload`/`read` copied from `COMMON` and the readback came back zeroed - the shader read the buffer before the copy landed. Both now enter and leave an explicit state (`COMMON -> COPY_DEST -> COMMON`, `COMMON -> COPY_SOURCE -> COMMON`), which is the same shape `capture.rs` uses for its readback and the reason its comment says a title buffer's copy, never transitioned, is only ever read. Verification: `cargo test --release -p victory-gpu` - 237 passed, 1 ignored (the new six among them); clippy `--all-targets -D warnings` clean on `main`. No frame-time claim: nothing in the frame path changes here.A synthetic measurement, no title involved: the same copy of 128 MiB read by a compute shader, once from video memory (`VramCopy`) and once from the system memory `shadow`'s copies live in today (`Host::shared_buffer`), with two access shapes - a stride-1 scan and a random 16-byte line a thread - one 16-byte read a thread and no stores, so the timing is the reads. Measured here (RX 9070 XT, shared machine, best of three, ten dispatches a list): 128 MiB read video system ratio stride-1 scan 3.829ms 4.021ms 1.05x random lines 56.301ms 57.100ms 1.01x Earlier shapes agreed before the parallism was raised (1.21x / 1.04x), and the one in-game experiment that exists - `VICTORY_COPIES_IN_VIDEO_MEMORY`, a `GPU_UPLOAD` heap - measured *worse* (3 196 -> 4 289 ms a frame). So: on this machine, putting these copies in video memory does not make shader reads faster, in either access shape. Two readings of that, and both matter before anyone writes the integration: * either the reads are not what the frame spends its time on (then variant A would have bought nothing, and the frame's cost is elsewhere), or * the `CUSTOM`/`L0` copies already come back at PCIe speed on this machine (~32 GB/s measured) and video memory has no headroom left to give. Either way the number that decides the integration now exists, and it says no. The unit stays (its own tests hold the mechanism), and this test is the record of why it is not wired in - and the thing to re-run on a machine whose result differs. Verification: `cargo test --release -p victory-gpu` - 238 passed, 1 ignored; `clippy --all-targets -D warnings` clean.@pes7 on GitHub · 2026-11-26 16:29 UTC · original
Update: the measure that decides the integration is in, and it says no
The two commits before this one prepared the mechanism; this one answers whether it is worth integrating, on the machine, in seconds, without the title: the same 128 MiB copy read by a compute shader, once from video memory (
VramCopy) and once from the system memoryshadow's copies live in today (Host::shared_buffer), with two access shapes — a stride-1 scan, and a random 16-byte line a thread — one read a thread and no stores, so the timing is the reads.(Earlier, lower-parallelism shapes agreed: 1.21x / 1.04x. Best of three, ten dispatches a list, RX 9070 XT on a shared machine.)
So video memory buys nothing here. Two readings, and both matter:
CUSTOM/L0copies already come back at PCIe speed on this machine (~32 GB/s measured) and there is no headroom for video memory to give.Either way, the number that decided whether to rewrite
Shadow's write path now exists, and it does not justify a week of it. The one in-game datapoint agrees:VICTORY_COPIES_IN_VIDEO_MEMORY(aGPU_UPLOADheap) measured worse, 3 196 → 4 289 ms.What stays useful:
cargo test -p victory-gpu --release the_read_cost -- --nocapture) and is the honest way to decide this on hardware where the answer may differ;cargo test --release -p victory-gpu— 238 passed, 1 ignored; clippy--all-targets -D warningsclean.@Dukestar69 on GitHub · 2026-11-26 17:10 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):
vram.rsmodule cleanly implements and tests VRAM-backed title memory copies (whole-page rounding, out-of-range guards, upload/shader/readback paths, and disjoint ranges in one list).cargo test -p victory-gpu --lib vram:: -- --test-threads=1(RTX 5090): 7 passed, 0 failed.VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib vram:: -- --test-threads=1(WARP): 7 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (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.