victory-gpu: a copy of title memory in video memory, prepared and tested #3295

Closed
pes7 wants to merge 2 commits from upstream-pr/3295 into main
pes7 commented 2026-11-26 16:16:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-26T16:16:49Z.


What this is

shadow's copies of title memory live in system memory — Host::shared_buffer is a CUSTOM heap buffer with CPU_PAGE_PROPERTY_WRITE_BACK and MEMORY_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.

VramCopy::new(len)               // a buffer in video memory, ALLOW_UNORDERED_ACCESS, common
.upload(list, offset, bytes)     // staged in upload memory now, copied when the list runs
.read(list, offset, len) -> Read // a readback recorded on the list, read after it ran
.gpu()                           // the address a shader reads it at

Why it is not wired in

Deliberately: the integration is a rewrite of Shadow's write path (Batch::flush stages instead of memcpying, Shadow::copy_back_page reads through read), 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:

test what it holds
uploaded_bytes_reach_a_shader_and_its_result_reads_back the staged bytes reach a shader that reads the copy by GPU address, and its result reads back
what_a_shader_writes_reads_back what the write-back path would compare is what the shader wrote
two_ranges_in_one_list_do_not_overwrite_each_other two staged ranges of one list land where they were asked for
an_upload_reads_back_without_a_shader the copy path alone: bytes in, bytes out
a_range_past_the_end_is_refused the edges (last element fits, one past does not, empty is refused)
a_copy_is_whole_pages the length is whole 64 KiB and the address is aligned

The first version was wrong, and the tests said why. upload/read copied from COMMON; the readback came back zeroed — the shader read the buffer before the copy landed. A copy from COMMON is not ordered against a shader access on either side of it. Both operations now enter and leave an explicit state:

COMMON -> COPY_DEST   -> copy  -> COPY_DEST   -> COMMON
COMMON -> COPY_SOURCE -> copy  -> COPY_SOURCE -> COMMON

which is the shape capture.rs already 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   (six new)
cargo clippy -p victory-gpu --all-targets -- -D warnings        clean

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) Shadow with Option<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, because VICTORY_COPIES_IN_VIDEO_MEMORY's result (worse, 3 196 -> 4 289 ms) is easy to misread as "video memory does not help".

<!-- greyfinch-sync:Marvisak/VIctory:issue:5513510575 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3295). Originally posted by [pes7](https://github.com/pes7) on 2026-11-26T16:16:49Z. --- ## What this is `shadow`'s copies of title memory live in **system memory** — `Host::shared_buffer` is a `CUSTOM` heap buffer with `CPU_PAGE_PROPERTY_WRITE_BACK` and `MEMORY_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. ```rust VramCopy::new(len) // a buffer in video memory, ALLOW_UNORDERED_ACCESS, common .upload(list, offset, bytes) // staged in upload memory now, copied when the list runs .read(list, offset, len) -> Read // a readback recorded on the list, read after it ran .gpu() // the address a shader reads it at ``` ## Why it is not wired in Deliberately: the integration is a rewrite of `Shadow`'s write path (`Batch::flush` stages instead of memcpying, `Shadow::copy_back_page` reads through `read`), 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: | test | what it holds | |---|---| | `uploaded_bytes_reach_a_shader_and_its_result_reads_back` | the staged bytes reach a shader that reads the copy by GPU address, and its result reads back | | `what_a_shader_writes_reads_back` | what the write-back path would compare is what the shader wrote | | `two_ranges_in_one_list_do_not_overwrite_each_other` | two staged ranges of one list land where they were asked for | | `an_upload_reads_back_without_a_shader` | the copy path alone: bytes in, bytes out | | `a_range_past_the_end_is_refused` | the edges (last element fits, one past does not, empty is refused) | | `a_copy_is_whole_pages` | the length is whole 64 KiB and the address is aligned | **The first version was wrong, and the tests said why.** `upload`/`read` copied from `COMMON`; the readback came back zeroed — the shader read the buffer before the copy landed. A copy from `COMMON` is not ordered against a shader access on either side of it. Both operations now enter and leave an explicit state: ``` COMMON -> COPY_DEST -> copy -> COPY_DEST -> COMMON COMMON -> COPY_SOURCE -> copy -> COPY_SOURCE -> COMMON ``` which is the shape `capture.rs` already 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 (six new) cargo clippy -p victory-gpu --all-targets -- -D warnings clean ``` 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) `Shadow` with `Option<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, because `VICTORY_COPIES_IN_VIDEO_MEMORY`'s result (worse, 3 196 -> 4 289 ms) is easy to misread as "video memory does not help".
pes7 commented 2026-11-26 16:29:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-26T16:29:54Z.


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 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 read a thread and no stores, so the timing is the reads.

128 MiB read        video     system    ratio
stride-1 scan      3.829ms    4.021ms   1.05x
random lines      56.301ms   57.100ms   1.01x

(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:

  1. the reads are not what the frame spends its time on — then variant A would have bought nothing and the cost is elsewhere; or
  2. the CUSTOM/L0 copies 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 (a GPU_UPLOAD heap) measured worse, 3 196 → 4 289 ms.

What stays useful:

  • the unit and its six semantics tests (a copy of title memory that lives in video memory has to be ordered by explicit transitions around its copies — that is what the tests found, and it will bite whoever wires it later);
  • the benchmark itself, which is four lines to re-run on any other machine (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;
  • the note in the module doc of where the integration plugs in, if it ever does.

cargo test --release -p victory-gpu — 238 passed, 1 ignored; clippy --all-targets -D warnings clean.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197723197 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3295#issuecomment-7197723197). Originally posted by [pes7](https://github.com/pes7) on 2026-11-26T16:29:54Z. --- ## 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 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 read a thread and no stores, so the timing is the reads. ``` 128 MiB read video system ratio stride-1 scan 3.829ms 4.021ms 1.05x random lines 56.301ms 57.100ms 1.01x ``` (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: 1. the reads are not what the frame spends its time on — then variant A would have bought nothing and the cost is elsewhere; or 2. the `CUSTOM`/`L0` copies 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` (a `GPU_UPLOAD` heap) measured **worse**, 3 196 → 4 289 ms. What stays useful: * the unit and its six semantics tests (a copy of title memory that lives in video memory has to be ordered by explicit transitions around its copies — that is what the tests found, and it will bite whoever wires it later); * the benchmark itself, which is four lines to re-run on any other machine (`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; * the note in the module doc of where the integration plugs in, if it ever does. `cargo test --release -p victory-gpu` — 238 passed, 1 ignored; clippy `--all-targets -D warnings` clean.
Dukestar69 commented 2026-11-26 17:10:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T17:10:44Z.

Review: APPROVED


Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):

  • Standalone vram.rs module 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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6078118620 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3295#pullrequestreview-6078118620). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T17:10:44Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP): - Standalone `vram.rs` module 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).
pes7 commented 2026-11-27 12:39:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-27T12:39:12Z.


Closing: measured no gain in the title, so it isn't worth the extra complexity.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218512059 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3295#issuecomment-7218512059). Originally posted by [pes7](https://github.com/pes7) on 2026-11-27T12:39:12Z. --- Closing: measured no gain in the title, so it isn't worth the extra complexity.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3295
No description provided.