GPU: opt-in video-memory side for host copies of title buffers #2705

Open
github-bot wants to merge 4 commits from github-bot/gh-2705 into main AGit
Owner

@⁠MrEjecutor on GitHub · 2026-11-25 18:31 UTC · original
MrEjecutor:card-copies → main · +925 −4 · 4 files · 4 commits · open

Claimed in #1633; design and the A/B that led to it are in #407.

What

An opt-in video-memory side for host copies of title buffers. Today every copy is one Host::shared_buffer (custom heap, write-back, MEMORY_POOL_L0), so every shader read of title buffer data crosses PCIe. With VICTORY_CARD_COPIES=1:

  • a copy of at least VICTORY_CARD_COPIES_MIN_MB (1) gets a DEFAULT-heap buffer that views, root descriptors and title-address page tables use; Shadow::data stays the system-memory side the CPU reads and writes. Runs of a shared buffer stay single-sided (their card side would be the whole shared buffer). VICTORY_CARD_COPIES_MB (1024) caps the card sides; past it a copy stays single-sided.
  • a submission runs as three ExecuteCommandLists, so buffers decay to COMMON between them and promote implicitly as they do now: a copy-up list for every 64 KiB page whose system-memory side is newer (every write into data marks its page: refreshes, zero fills, copy-back merges, write_host), the title's lists unchanged, then after their fence a copy-down list for the pages that may hold GPU writes (declared unmarked ranges whole, marked ranges by their marked pages, the title-memory page tables' bits), before the CPU copy-back runs unchanged.
  • off by default; with the switch off nothing changes. The frame-rate line gets the bytes copied up and down per frame when it is on.

Why

On the fork fxceless/victory-fork, which has a similar card side on by default, an RTX 5060 Ti runs a frame in ~315 ms with it and ~2,084 ms without it; the hair strand constraint solvers and the skinning that feeds ray tracing are what slows down without it (#407).

Measured here (RTX 5060 Ti 16 GB, driver 621.24, Windows 11 26200)

  • Tests: four new GPU tests in memory.rs (a title write reaches a shader through the card side, first and later; a declared GPU write comes back to title memory; a write through the title-memory page table comes back; a page both the title and the GPU wrote is seen whole by the next submission). Negative controls: with the copy-up removed the two read tests fail, with the copy-down removed the three write tests fail. cargo test -p victory-gpu --lib -- --test-threads=1: 193 pass, 2 fail; the same 2 fail on 13f91ca without this change on this card (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views).

  • In the title, main + this + #1751 + #1763 (the stack that boots on NVIDIA here), the three programs of #1968 skipped (so the world is black and the strand simulation does not run), VICTORY_GPU_TIMING=1, 600–900 s runs:

    • copy-down: about 48–54 MB a frame once marked ranges come down by their marked pages (806 MB a frame when every declared range came down whole);
    • the same programs' time per command, with against without: 0.92 (ten programs that ran ≥ 20 commands in both);
    • device removals in that stack: 1 of 3 runs without the switch, 1 of 5 with it, at different places, so not from this.
  • With the world drawn: main + this + #1751 + #1763 + #1906 + #2098 (the last two merged by hand onto current main: its 16-byte view-address entries with #1906's dynamic slots and #2098's view_address; their tests adapted to 16 bytes and passing), nothing skipped, the warnings #1800 rate-limits silenced by log level, one binary, 900 s each, no removal in either:

VICTORY_CARD_COPIES unset =1
ms per frame (last 40 samples) 578 565
on the GPU 270 222
draws per frame 2,081 2,749
time in slow list commands (VICTORY_GPU_TIMING) 3.6 s, 420 commands 0.9 s, 126 commands
copied up / down per frame – ~50 / ~50 MB

The GPU does a third more draws in less time; the frame barely moves because on main the CPU's preparing and copy-back run before and after each submission, not beside it.

Review

@⁠DrDarkDK's point is in 0af0273: a failed copy list or wait ends the run through fail() before stale data can reach title lists or title memory.

Not tested

Other cards; AMD; Linux; a second run of each; the same scene in both runs (draws differ). @⁠desplmfao offered a Linux/NVIDIA run in #407.

AI use: implemented with Codex (gpt-6-luna) from a design reviewed by Codex (gpt-6-sol), then reviewed, fixed, tested and measured with Claude Code (Claude Opus 5.5); checked by mrejecutor. No game data attached.

🤖 Generated with Claude Code

**@⁠MrEjecutor** on GitHub · 2026-11-25 18:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705) `MrEjecutor:card-copies` → `main` · +925 −4 · 4 files · 4 commits · open Claimed in #1633; design and the A/B that led to it are in #407. ## What An opt-in video-memory side for host copies of title buffers. Today every copy is one `Host::shared_buffer` (custom heap, write-back, `MEMORY_POOL_L0`), so every shader read of title buffer data crosses PCIe. With `VICTORY_CARD_COPIES=1`: - a copy of at least `VICTORY_CARD_COPIES_MIN_MB` (1) gets a DEFAULT-heap buffer that views, root descriptors and title-address page tables use; `Shadow::data` stays the system-memory side the CPU reads and writes. Runs of a shared buffer stay single-sided (their card side would be the whole shared buffer). `VICTORY_CARD_COPIES_MB` (1024) caps the card sides; past it a copy stays single-sided. - a submission runs as three `ExecuteCommandLists`, so buffers decay to COMMON between them and promote implicitly as they do now: a copy-up list for every 64 KiB page whose system-memory side is newer (every write into `data` marks its page: refreshes, zero fills, copy-back merges, `write_host`), the title's lists unchanged, then after their fence a copy-down list for the pages that may hold GPU writes (declared unmarked ranges whole, marked ranges by their marked pages, the title-memory page tables' bits), before the CPU copy-back runs unchanged. - off by default; with the switch off nothing changes. The frame-rate line gets the bytes copied up and down per frame when it is on. ## Why On the fork `fxceless/victory-fork`, which has a similar card side on by default, an RTX 5060 Ti runs a frame in ~315 ms with it and ~2,084 ms without it; the hair strand constraint solvers and the skinning that feeds ray tracing are what slows down without it (#407). ## Measured here (RTX 5060 Ti 16 GB, driver 621.24, Windows 11 26200) - **Tests**: four new GPU tests in `memory.rs` (a title write reaches a shader through the card side, first and later; a declared GPU write comes back to title memory; a write through the title-memory page table comes back; a page both the title and the GPU wrote is seen whole by the next submission). Negative controls: with the copy-up removed the two read tests fail, with the copy-down removed the three write tests fail. `cargo test -p victory-gpu --lib -- --test-threads=1`: 193 pass, 2 fail; the same 2 fail on `13f91ca` without this change on this card (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`). - **In the title**, `main` + this + #1751 + #1763 (the stack that boots on NVIDIA here), the three programs of #1968 skipped (so the world is black and the strand simulation does not run), `VICTORY_GPU_TIMING=1`, 600–900 s runs: - copy-down: about 48–54 MB a frame once marked ranges come down by their marked pages (806 MB a frame when every declared range came down whole); - the same programs' time per command, with against without: 0.92 (ten programs that ran ≥ 20 commands in both); - device removals in that stack: 1 of 3 runs without the switch, 1 of 5 with it, at different places, so not from this. - **With the world drawn**: `main` + this + #1751 + #1763 + #1906 + #2098 (the last two merged by hand onto current `main`: its 16-byte view-address entries with #1906's dynamic slots and #2098's `view_address`; their tests adapted to 16 bytes and passing), nothing skipped, the warnings #1800 rate-limits silenced by log level, one binary, 900 s each, no removal in either: | | `VICTORY_CARD_COPIES` unset | `=1` | |---|---|---| | ms per frame (last 40 samples) | 578 | 565 | | on the GPU | 270 | **222** | | draws per frame | 2,081 | 2,749 | | time in slow list commands (`VICTORY_GPU_TIMING`) | 3.6 s, 420 commands | **0.9 s, 126 commands** | | copied up / down per frame | – | ~50 / ~50 MB | The GPU does a third more draws in less time; the frame barely moves because on `main` the CPU's preparing and copy-back run before and after each submission, not beside it. ## Review @⁠DrDarkDK's point is in `0af0273`: a failed copy list or wait ends the run through `fail()` before stale data can reach title lists or title memory. ## Not tested Other cards; AMD; Linux; a second run of each; the same scene in both runs (draws differ). @⁠desplmfao offered a Linux/NVIDIA run in #407. AI use: implemented with Codex (gpt-6-luna) from a design reviewed by Codex (gpt-6-sol), then reviewed, fixed, tested and measured with Claude Code (Claude Opus 5.5); checked by mrejecutor. No game data attached. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With VICTORY_CARD_COPIES=1, a host copy of a title buffer of at least
VICTORY_CARD_COPIES_MIN_MB (1) gets a DEFAULT-heap side that views, root
descriptors and title-address page tables use; the system-memory copy
stays the CPU's side (`Shadow::data`). Runs of a shared buffer stay
single-sided. VICTORY_CARD_COPIES_MB (1024) caps the card sides.

A submission runs as three ExecuteCommandLists, so buffers decay to
COMMON between them and promote implicitly as before: a copy-up list for
every page whose system-memory side is newer (each write into `data`
marks its 64 KiB page), the title's lists, then after their fence a
copy-down list for the pages that may hold GPU writes (unmarked declared
ranges whole, marked ranges by their marked pages, title-memory page
table bits), before the CPU copy-back runs unchanged.

Off by default; with the switch off nothing changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
copy_up_cards and copy_down_cards return a Result; a list that does not reset or close, a fence that is not signalled or a wait that fails go through fail(), as a removed device does, so neither stale card data reaches title lists nor stale system-memory bytes reach title memory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:25 +00:00
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 18:34 UTC · original

If the card copy-down list fails to reset or close, copy_down_cards returns 0 and Host::execute still runs the usual copy-back. The GPU writes are still in the DEFAULT buffer, so copy-back reads the old staging bytes and the title can be told the submission is complete without seeing those writes. If the fence wait fails after submission, the CPU can also read staging before the download finishes.

Could copy_down_cards return a Result and route failures through the existing GPU failure path before copy-back or the title’s completion writes? A regression could inject a copy-down failure after the test shader writes and check that the title completion write is withheld.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 18:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7171092963) If the card copy-down list fails to reset or close, `copy_down_cards` returns `0` and `Host::execute` still runs the usual copy-back. The GPU writes are still in the DEFAULT buffer, so copy-back reads the old staging bytes and the title can be told the submission is complete without seeing those writes. If the fence wait fails after submission, the CPU can also read staging before the download finishes. Could `copy_down_cards` return a `Result` and route failures through the existing GPU failure path before copy-back or the title’s completion writes? A regression could inject a copy-down failure after the test shader writes and check that the title completion write is withheld. *AI-assisted with Codex.*
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 18:57 UTC · original

Read the core paths - the design is sound: strict =1 opt-in with a thread-local test override (no env races), cap accounting via reserve/release, the three-ECL split relying on COMMON promotion (legal for buffer copies), copy-down waited on its own fence before CPU copy-back, and download selection keeps the ~800MB/frame whole-range blowup out via marked pages + page-table bits. The negative controls (remove the copy-up -> reads fail, remove copy-down -> writes fail) are the strongest part of the test story.

One ordering question: copy_up_cards submits the ECL, then clear_stale() drops the marks for the copied range. If the CPU writes a stale-marked page in the window between ExecuteCommandLists returning and clear_stale running, and the GPU has already executed the copy by then, that write's mark is cleared without its data ever reaching the card side - the page stays stale on the GPU indefinitely (until another write re-marks it). Narrow window, but real: a write to page X after the copy executes and before clear_stale loses both ways. Clearing the marks before recording the copies, or snapshotting the stale set and clearing only what was snapshotted, would close it - worth a thought while this is still opt-in.

**@⁠kotekompotek** on GitHub · 2026-11-25 18:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7171633829) Read the core paths - the design is sound: strict =1 opt-in with a thread-local test override (no env races), cap accounting via reserve/release, the three-ECL split relying on COMMON promotion (legal for buffer copies), copy-down waited on its own fence before CPU copy-back, and download selection keeps the ~800MB/frame whole-range blowup out via marked pages + page-table bits. The negative controls (remove the copy-up -> reads fail, remove copy-down -> writes fail) are the strongest part of the test story. One ordering question: copy_up_cards submits the ECL, then clear_stale() drops the marks for the copied range. If the CPU writes a stale-marked page in the window between ExecuteCommandLists returning and clear_stale running, and the GPU has already executed the copy by then, that write's mark is cleared without its data ever reaching the card side - the page stays stale on the GPU indefinitely (until another write re-marks it). Narrow window, but real: a write to page X after the copy executes and before clear_stale loses both ways. Clearing the marks before recording the copies, or snapshotting the stale set and clearing only what was snapshotted, would close it - worth a thought while this is still opt-in.
Author
Owner

@⁠MrEjecutor on GitHub · 2026-11-25 19:19 UTC · original

@⁠DrDarkDK thanks, agreed: both directions had the same hole. 0af0273 makes copy_up_cards and copy_down_cards return a Result; a list that does not reset or close, a fence that is not signalled, or a wait that does not return WAIT_OBJECT_0 now goes through fail() before the title's lists (copy-up) or before any copy-back and the completion writes (copy-down), so neither stale card data nor stale system-memory bytes can reach the title.

On the regression test: fail() ends the process, as it does for a removed device, so an in-process test cannot see the withheld completion write after it. I have not added one; if you want it, I could add a #[cfg(test)] hook that makes the copy-down return an error and check copy_down_cards's Result, or run it as a child process and check the exit. Say which you'd prefer.

Not tested: an injected failure (no hook yet); cargo test -p victory-gpu --lib -- --test-threads=1 gives the same 193 pass / 2 pre-existing failures as before, and clippy is clean on the changed code.

AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.

**@⁠MrEjecutor** on GitHub · 2026-11-25 19:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7172132804) @⁠DrDarkDK thanks, agreed: both directions had the same hole. `0af0273` makes `copy_up_cards` and `copy_down_cards` return a `Result`; a list that does not reset or close, a fence that is not signalled, or a wait that does not return `WAIT_OBJECT_0` now goes through `fail()` before the title's lists (copy-up) or before any copy-back and the completion writes (copy-down), so neither stale card data nor stale system-memory bytes can reach the title. On the regression test: `fail()` ends the process, as it does for a removed device, so an in-process test cannot see the withheld completion write after it. I have not added one; if you want it, I could add a `#[cfg(test)]` hook that makes the copy-down return an error and check `copy_down_cards`'s `Result`, or run it as a child process and check the exit. Say which you'd prefer. Not tested: an injected failure (no hook yet); `cargo test -p victory-gpu --lib -- --test-threads=1` gives the same 193 pass / 2 pre-existing failures as before, and clippy is clean on the changed code. AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 19:30 UTC · original

Thanks. The failure handling you described resolves my concern in both directions. The explicit fail() calls are enough for this review.

If you add a regression later, I’d prefer a child-process test that also checks a completion sentinel. The exit status alone can’t show whether the completion write happened before the process exited.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 19:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7172390981) Thanks. The failure handling you described resolves my concern in both directions. The explicit `fail()` calls are enough for this review. If you add a regression later, I’d prefer a child-process test that also checks a completion sentinel. The exit status alone can’t show whether the completion write happened before the process exited. *AI-assisted with Codex.*
Author
Owner

@⁠MrEjecutor on GitHub · 2026-11-25 19:42 UTC · original

@⁠kotekompotek thanks for reading it closely. On the ordering question: writes into a copy's system-memory side run on the submitting thread, under the same lock as the copy-up, so I don't think the window can be hit today; but nothing in the code says so, and the fix is free. 185e36f takes and clears each copy's stale pages under one lock in card_uploads, before the copy-up is recorded; a page marked after that goes up with the next submission. CardCopy::clear_stale is gone.

@⁠DrDarkDK thanks; noted on the child-process test if I add one.

Not tested: a concurrent writer (none exists today); the suite gives the same 193 pass / 2 pre-existing failures, clippy clean on the changed code.

AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.

**@⁠MrEjecutor** on GitHub · 2026-11-25 19:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7172652692) @⁠kotekompotek thanks for reading it closely. On the ordering question: writes into a copy's system-memory side run on the submitting thread, under the same lock as the copy-up, so I don't think the window can be hit today; but nothing in the code says so, and the fix is free. `185e36f` takes and clears each copy's stale pages under one lock in `card_uploads`, before the copy-up is recorded; a page marked after that goes up with the next submission. `CardCopy::clear_stale` is gone. @⁠DrDarkDK thanks; noted on the child-process test if I add one. Not tested: a concurrent writer (none exists today); the suite gives the same 193 pass / 2 pre-existing failures, clippy clean on the changed code. AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:55 UTC · original

Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and code review of 185e36f9 (on 13f91ca):

Verification (rustc 1.98.1 MSVC)

  • cargo xtask policy: 184 files ok; cargo clippy --locked -p victory-gpu --all-targets (default & --features diagnostics): 0 warnings.
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics --test-threads=1): 202 passed, 0 failed, 1 ignored (all 4 memory::tests::card_* tests pass).
  • NVIDIA GeForce RTX 5090 (VICTORY_CARD_COPIES=1): memory::tests::card_ 4 passed, 0 failed; shadow::tests 8 passed, 0 failed (and default-off keeps existing behavior unchanged).

Review & Ecosystem Notes

  • Clearing stale[first..page] inline while holding stale.lock() inside card_uploads() in 185e36f9 cleanly closes the race where a concurrent CPU write between collecting upload regions and clearing stale flags could lose a dirty mark.
  • Opt-in DEFAULT VRAM + staging DMA works across all GPUs without requiring Resizable BAR and avoids holding per-copy page-bitmap locks across GPU fence waits; pairs naturally with #2120 (ReBAR read-only GPU_UPLOAD buffers) once #2705 skips buffers already placed in GPU_UPLOAD. Clean and ready to merge.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7172957180) Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and code review of `185e36f9` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC) - `cargo xtask policy`: **184 files ok**; `cargo clippy --locked -p victory-gpu --all-targets` (default & `--features diagnostics`): **0 warnings**. - **WARP (`VICTORY_D3D12_WARP=1`, `--features diagnostics --test-threads=1`):** **202 passed, 0 failed, 1 ignored** (all 4 `memory::tests::card_*` tests pass). - **NVIDIA GeForce RTX 5090 (`VICTORY_CARD_COPIES=1`):** `memory::tests::card_` **4 passed, 0 failed**; `shadow::tests` **8 passed, 0 failed** (and default-off keeps existing behavior unchanged). ### Review & Ecosystem Notes - Clearing `stale[first..page]` inline while holding `stale.lock()` inside `card_uploads()` in `185e36f9` cleanly closes the race where a concurrent CPU write between collecting upload regions and clearing stale flags could lose a dirty mark. - Opt-in `DEFAULT` VRAM + staging DMA works across all GPUs without requiring Resizable BAR and avoids holding per-copy page-bitmap locks across GPU fence waits; pairs naturally with #2120 (ReBAR read-only `GPU_UPLOAD` buffers) once #2705 skips buffers already placed in `GPU_UPLOAD`. Clean and ready to merge.
Author
Owner

@⁠MrEjecutor on GitHub · 2026-11-25 20:36 UTC · original

@⁠fuzeofficlal thank you for running it on the pinned toolchain, on WARP and on a 5090; that covers the two things I could not (rustc 1.98.1, and a card other than mine). On #2120: agreed, a copy whose buffer is already placed in GPU_UPLOAD memory gains nothing from a card side. Whichever of the two lands second should skip those; if #2120 lands first I'll add the check here.

Not tested: #2120 together with this.

AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.

**@⁠MrEjecutor** on GitHub · 2026-11-25 20:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7173932080) @⁠fuzeofficlal thank you for running it on the pinned toolchain, on WARP and on a 5090; that covers the two things I could not (rustc 1.98.1, and a card other than mine). On #2120: agreed, a copy whose buffer is already placed in `GPU_UPLOAD` memory gains nothing from a card side. Whichever of the two lands second should skip those; if #2120 lands first I'll add the check here. Not tested: #2120 together with this. AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:15 UTC · original · edited 2026-11-26 02:16 UTC

Automated triage for the maintainers.

Merge candidate (recommending a look, not an approval). Thanks for the rebase. This adds an opt-in (VICTORY_CARD_COPIES=1, exact match, off by default) DEFAULT-heap "card side" for title-buffer copies of at least 1 MB, with a 1 GB cap (reserve_card_bytes/CardBudget), a copy-up list before the title lists and a waited copy-down list before CPU copy-back (Host::copy_up_cards/copy_down_cards in host.rs). I read the paths that run with the switch off: Shadow::mark_stale is a no-op without a card side, the BITMAPS move in shadow.rs is behaviour-neutral, and defer_memory_bitmap/marked_card_pages only run when the switch is on. With it on, copy-up/down failures go through fail() rather than letting copy-back publish stale bytes, and stale pages are taken and cleared under one lock in card_uploads. Four GPU tests with stated negative controls, plus third-party measurements in the thread; it merges cleanly and CI check is passing.

It is large (≈925 lines across host.rs, memory.rs, shadow.rs, switch.rs); this reading covered the switch-off paths and the up/down ordering, not every page-arithmetic path under the switch.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7176139974) · edited 2026-11-26 02:16 UTC <!-- victory-triage v1 head=7dcc59543ea7b574336920103bb7b1da99dd6ef8 verdict=merge-candidate at=2026-11-26T02:16:10Z --> Automated triage for the maintainers. **Merge candidate** (recommending a look, not an approval). Thanks for the rebase. This adds an opt-in (`VICTORY_CARD_COPIES=1`, exact match, off by default) DEFAULT-heap "card side" for title-buffer copies of at least 1 MB, with a 1 GB cap (`reserve_card_bytes`/`CardBudget`), a copy-up list before the title lists and a waited copy-down list before CPU copy-back (`Host::copy_up_cards`/`copy_down_cards` in `host.rs`). I read the paths that run with the switch off: `Shadow::mark_stale` is a no-op without a card side, the `BITMAPS` move in `shadow.rs` is behaviour-neutral, and `defer_memory_bitmap`/`marked_card_pages` only run when the switch is on. With it on, copy-up/down failures go through `fail()` rather than letting copy-back publish stale bytes, and stale pages are taken and cleared under one lock in `card_uploads`. Four GPU tests with stated negative controls, plus third-party measurements in the thread; it merges cleanly and CI `check` is passing. It is large (≈925 lines across `host.rs`, `memory.rs`, `shadow.rs`, `switch.rs`); this reading covered the switch-off paths and the up/down ordering, not every page-arithmetic path under the switch. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠MrEjecutor on GitHub · 2026-11-25 22:34 UTC · original

Rebased onto main at f3578e3 (head now 7dcc595). What changed in the rebase:

  • shadow.rs: main split the refresh into update_tracked / update_untracked. The card-side stale marks moved with it: copy() marks what it writes (next to the new refreshed call), and the zeroed unmapped runs in update_tracked are marked too. Every other write into the staging buffer was already marked.
  • host.rs: only the log line and the imports conflicted; both kept.
  • One extra commit adapts the card-side page marks to the pooled bitmaps (cfc2344) and the NO_OWNER owner sentinel. Behaviour is the same as before the rebase.

Checked on an RTX 5060 Ti: the 4 card-copy GPU tests pass. The whole victory-gpu lib suite gives 225 passed, 2 failed. The same 2 fail on plain main at f3578e3 without these commits (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views), so they are not from this PR. Clippy's two fetch_update deprecation errors in object.rs and the rustfmt diff in victory-formats also come from main with a newer toolchain. Not tested: an in-game run after the rebase (the earlier A/B numbers in this PR are from before it).

AI use: the rebase, the conflict resolution and the checks above were done with Claude Code.

**@⁠MrEjecutor** on GitHub · 2026-11-25 22:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7176527758) Rebased onto `main` at f3578e3 (head now 7dcc595). What changed in the rebase: - `shadow.rs`: `main` split the refresh into `update_tracked` / `update_untracked`. The card-side stale marks moved with it: `copy()` marks what it writes (next to the new `refreshed` call), and the zeroed unmapped runs in `update_tracked` are marked too. Every other write into the staging buffer was already marked. - `host.rs`: only the log line and the imports conflicted; both kept. - One extra commit adapts the card-side page marks to the pooled bitmaps (cfc2344) and the `NO_OWNER` owner sentinel. Behaviour is the same as before the rebase. Checked on an RTX 5060 Ti: the 4 card-copy GPU tests pass. The whole `victory-gpu` lib suite gives 225 passed, 2 failed. The same 2 fail on plain `main` at f3578e3 without these commits (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`), so they are not from this PR. Clippy's two `fetch_update` deprecation errors in `object.rs` and the rustfmt diff in `victory-formats` also come from `main` with a newer toolchain. Not tested: an in-game run after the rebase (the earlier A/B numbers in this PR are from before it). AI use: the rebase, the conflict resolution and the checks above were done with Claude Code.
Author
Owner

@⁠moe-miau on GitHub · 2026-11-25 23:25 UTC · original

Per-pipeline data from an RTX 4070 SUPER (12 GB, driver 32.0.16.1742, Windows 11 26300, Ryzen 7 7700X), title 1.0.2.1, Series X profile, diag build, 6-minute runs with scripted Enter presses, VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1.

Tree: main f3578e3 + #2464 + #2098 + #2626 + #2628 + #2711 + #2851, with this PR (7dcc595) merged cleanly on top. Off = the same exe without VICTORY_CARD_COPIES; on = VICTORY_CARD_COPIES=1. The scenes in the two runs are not identical, so I compare each pipeline's median GPU time per command over the run, for the 89 pipelines timed in both:

pipeline off (ms/command) on (ms/command)
indirect [compute cfd83392ec9ae408] 518.1 5.8
indirect [compute 3592426e3e9142d8] 908.4 350.1
indirect [compute c519f7a7946e3702] 76.2 4.6
indirect [compute f22a76fcb967ee59] 62.2 6.1
indirect [compute ce30cb330ef34306] 145.9 105.2
indirect [compute c7feccae4e01e454] 95.1 67.3
median of all 89 ratio 1.00

So the passes that move whole buffers gain 10-90x. Most others are unchanged. The ray-march lighting passes (c7feccae, 8bbcbda6, 0184869d, ...) stay slow for an unrelated reason on this stack (their step-length 3D texture is all zeros, so each lane marches to its step cap). No device removal in either run. One run each.

AI-assisted (Claude Code). Runs done on my machine.

**@⁠moe-miau** on GitHub · 2026-11-25 23:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7177536033) Per-pipeline data from an RTX 4070 SUPER (12 GB, driver 32.0.16.1742, Windows 11 26300, Ryzen 7 7700X), title 1.0.2.1, Series X profile, diag build, 6-minute runs with scripted Enter presses, `VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1`. Tree: `main` `f3578e3` + #2464 + #2098 + #2626 + #2628 + #2711 + #2851, with this PR (`7dcc595`) merged cleanly on top. Off = the same exe without `VICTORY_CARD_COPIES`; on = `VICTORY_CARD_COPIES=1`. The scenes in the two runs are not identical, so I compare each pipeline's median GPU time per command over the run, for the 89 pipelines timed in both: | pipeline | off (ms/command) | on (ms/command) | |---|---:|---:| | `indirect [compute cfd83392ec9ae408]` | 518.1 | **5.8** | | `indirect [compute 3592426e3e9142d8]` | 908.4 | 350.1 | | `indirect [compute c519f7a7946e3702]` | 76.2 | **4.6** | | `indirect [compute f22a76fcb967ee59]` | 62.2 | **6.1** | | `indirect [compute ce30cb330ef34306]` | 145.9 | 105.2 | | `indirect [compute c7feccae4e01e454]` | 95.1 | 67.3 | | median of all 89 | | ratio 1.00 | So the passes that move whole buffers gain 10-90x. Most others are unchanged. The ray-march lighting passes (`c7feccae`, `8bbcbda6`, `0184869d`, ...) stay slow for an unrelated reason on this stack (their step-length 3D texture is all zeros, so each lane marches to its step cap). No device removal in either run. One run each. AI-assisted (Claude Code). Runs done on my machine.
Author
Owner

@⁠ntgata1-dotcom on GitHub · 2026-11-26 07:46 UTC · original

AMD RDNA4 under Wine: card copies off and on, in the title

Setup: RX 9070 XT (RDNA4), RADV / Mesa 26.3, Wine 11.22 with vkd3d-proton 3.1-83 from GE-Proton11-14. Diag builds of this PR merged onto main 63bcca4, with #2428 and the Linux-side changes listed below. Warm shader and pipeline cache, scripted input, the first mission's opening, 5-minute runs. The numbers are means over the 5-second frame lines with 1,000 draws or more (about 42 per run).

VICTORY_CARD_COPIES unset =1
ms per frame, median 455 470
ms per frame at 1,000–2,500 / 2,500–4,000 / 4,000+ draws 349 / 502 / 564 331 / 492 / 636
on the GPU 172 ms 168 ms
preparing (copies) / copying back 221 (112) / 66 ms 222 (115) / 70 ms
card copies up / down – 249 / 111 MB per frame

No fault, device loss or kernel message in either run. This is the same picture as your RTX 5060 Ti numbers: the GPU side moves a little and the frame doesn't, because preparing and copy-back run before and after each submission here too.

Both runs had the same local changes: queues on a worker thread (local, opt-in), #3071, and a wineserver that keeps memory views in a tree. Merged for Wine: #2913, #2919, #2723, #2977, #2703, #1722, #2101, #2249; and #2644 and #454, their switches on.

AI-assisted (Claude Code); numbers from my own runs.

**@⁠ntgata1-dotcom** on GitHub · 2026-11-26 07:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7185817777) **AMD RDNA4 under Wine: card copies off and on, in the title** **Setup:** RX 9070 XT (RDNA4), RADV / Mesa 26.3, Wine 11.22 with vkd3d-proton 3.1-83 from GE-Proton11-14. Diag builds of this PR merged onto `main` `63bcca4`, with #2428 and the Linux-side changes listed below. Warm shader and pipeline cache, scripted input, the first mission's opening, 5-minute runs. The numbers are means over the 5-second frame lines with 1,000 draws or more (about 42 per run). | | `VICTORY_CARD_COPIES` unset | `=1` | |---|---|---| | ms per frame, median | 455 | 470 | | ms per frame at 1,000–2,500 / 2,500–4,000 / 4,000+ draws | 349 / 502 / 564 | 331 / 492 / 636 | | on the GPU | 172 ms | 168 ms | | preparing (copies) / copying back | 221 (112) / 66 ms | 222 (115) / 70 ms | | card copies up / down | – | 249 / 111 MB per frame | No fault, device loss or kernel message in either run. This is the same picture as your RTX 5060 Ti numbers: the GPU side moves a little and the frame doesn't, because preparing and copy-back run before and after each submission here too. Both runs had the same local changes: queues on a worker thread (local, opt-in), #3071, and a wineserver that keeps memory views in a tree. Merged for Wine: #2913, #2919, #2723, #2977, #2703, #1722, #2101, #2249; and #2644 and #454, their switches on. AI-assisted (Claude Code); numbers from my own runs.
Author
Owner

@⁠MrEjecutor on GitHub · 2026-11-26 08:34 UTC · original

Thanks, that is a useful third card. Taken together for whoever reviews this:

  • RTX 5060 Ti (mine): GPU time per frame down with the switch on, frame time about the same, since preparing and copy-back run before and after each submission.
  • RTX 4070 SUPER (moe-miau, above): the passes that move whole buffers 10-90x faster per command; most other pipelines unchanged.
  • RX 9070 XT under Wine (yours): GPU time slightly down, frame time unchanged, no faults.

So the PR does what it claims on the GPU side on three vendors and stays off by default, but it does not make frames faster on its own while preparing and copy-back are serial with the submission. That limit is in the description; this confirms it on AMD too. No change planned to the PR from this; it stays rebased on main.

Not tested: overlapping preparing or copy-back with the GPU (a separate change).

AI use: this summary was written with Claude Code.

**@⁠MrEjecutor** on GitHub · 2026-11-26 08:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#issuecomment-7186761677) Thanks, that is a useful third card. Taken together for whoever reviews this: - RTX 5060 Ti (mine): GPU time per frame down with the switch on, frame time about the same, since preparing and copy-back run before and after each submission. - RTX 4070 SUPER (moe-miau, above): the passes that move whole buffers 10-90x faster per command; most other pipelines unchanged. - RX 9070 XT under Wine (yours): GPU time slightly down, frame time unchanged, no faults. So the PR does what it claims on the GPU side on three vendors and stays off by default, but it does not make frames faster on its own while preparing and copy-back are serial with the submission. That limit is in the description; this confirms it on AMD too. No change planned to the PR from this; it stays rebased on `main`. Not tested: overlapping preparing or copy-back with the GPU (a separate change). AI use: this summary was written with Claude Code.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 09:27 UTC · original · approved these changes

Reviewed 7dcc5954 across host.rs, memory.rs, shadow.rs, and switch.rs, and verified cleanly against current origin/main (63bcca43; git merge-tree --write-tree reports zero conflicts).

Lifecycle and synchronization checks look sound:

  • Shadow field drop order releases buffer before _budget returns bytes to CARD_ALLOCATED; arena slices stay single-sided; all staging-side mutations (copy(), unmapped zero-fills, copy_back_or_not, copy_back_marked, write_host) mark pages stale, and card_uploads() drains stale marks under a single lock.
  • Both shadow::marked_card_pages() and memory::marked_card_pages() read dirty bitmaps without clearing before copy_down_cards fences, leaving PooledBitmap alive in list.deferred.after until reset().
  • Copy-up/copy-down failures terminate via fail(...) so stale data cannot silently reach title lists or title memory.

Verified locally on Windows 11 (RTX 5090 + WARP + VICTORY_D3D12_DEBUG=1):

  • cargo clippy --workspace --all-targets [--all-features] -- -D warnings: clean; cargo xtask policy: 190 files ok.
  • Default (opt-in off): switch:: 4/4, shadow:: 10/10, and all 4 new memory::tests::card_* tests pass on RTX 5090, RTX 5090 + Debug Layer, and WARP + Debug Layer with zero D3D12 Debug Layer errors on the implicit COMMON transitions across the three ExecuteCommandLists calls.
  • With VICTORY_CARD_COPIES=1 (default 1 MiB threshold) + VICTORY_D3D12_DEBUG=1:
    • RTX 5090: bindless:: 3/3, draw::tests:: 20/20 (including root_views_reach_their_copy_and_read_zeros_past_it with a 4 MiB card-backed source and all 5 marked_subpage_uav_* tests), host::tests:: + descriptor::host::tests:: + pipeline::host::tests:: 30/31 (only the pre-existing NVIDIA 1M-cap dynamic_slots_are_held_until_released failure).
    • WARP (--features diagnostics, VICTORY_D3D12_WARP=1): bindless:: 3/3, draw::tests:: 20/20, host::tests:: + descriptor::host::tests:: + pipeline::host::tests:: 31/31.
  • Stress check with VICTORY_CARD_COPIES=1 VICTORY_CARD_COPIES_MIN_MB=0 VICTORY_D3D12_DEBUG=1 (forcing 64 KiB test shadows onto card sides): shadow:: 10/10, memory::tests:: 12/12 on WARP (including a_submission_that_missed_leaves_the_copies_at_once on both RTX 5090 and WARP), and all 5 marked_subpage_uav_* tests pass with zero Debug Layer issues.

Three minor non-blocking follow-ups worth noting:

  1. Empty groups fence gap under VICTORY_GPU_TIMING=1 (host.rs:1497-1567): when diagnostics timing() is active and runs is empty, groups is empty (vec![]), so copy_up_cards(&card_uploads) would submit commands.up without a subsequent fence signal/wait before card_uploads drops and before the next commands.up.begin() resets the allocator. Guarding copy_up_cards on !groups.is_empty() (or skipping card copies when runs.is_empty()) closes that edge case.
  2. Redundant live_cards() scans (host.rs:1508-1514, 1648, shadow.rs:829-831): has_cards() locks CARDS, upgrades every weak pointer into a Vec, and immediately drops it — running twice per submission even when VICTORY_CARD_COPIES is off, and twice back-to-back before copy_up_cards when on. Checking CARD_ALLOCATED.load(Ordering::Relaxed) != 0 in has_cards() (and calling card_uploads() directly when has_cards() is true without re-scanning) would make the default-off path lock-free and trim a scan per submission when enabled.
  3. Initial stale bitmap (shadow.rs:375): newly committed DEFAULT buffers without D3D12_HEAP_FLAG_CREATE_NOT_ZEROED are zero-initialized by D3D12 just like shared_buffer. Starting stale as vec![false; pages] (since copy(), unmapped zero-fills, merges, and write_host all call mark_stale) would avoid an initial full-buffer PCIe upload of untouched zero pages when a large heap gets its card side.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2705#pullrequestreview-6071539080) · **approved these changes** Reviewed `7dcc5954` across `host.rs`, `memory.rs`, `shadow.rs`, and `switch.rs`, and verified cleanly against current `origin/main` (`63bcca43`; `git merge-tree --write-tree` reports zero conflicts). Lifecycle and synchronization checks look sound: - `Shadow` field drop order releases `buffer` before `_budget` returns bytes to `CARD_ALLOCATED`; arena slices stay single-sided; all staging-side mutations (`copy()`, unmapped zero-fills, `copy_back_or_not`, `copy_back_marked`, `write_host`) mark pages stale, and `card_uploads()` drains stale marks under a single lock. - Both `shadow::marked_card_pages()` and `memory::marked_card_pages()` read dirty bitmaps without clearing before `copy_down_cards` fences, leaving `PooledBitmap` alive in `list.deferred.after` until `reset()`. - Copy-up/copy-down failures terminate via `fail(...)` so stale data cannot silently reach title lists or title memory. Verified locally on Windows 11 (RTX 5090 + WARP + `VICTORY_D3D12_DEBUG=1`): - `cargo clippy --workspace --all-targets [--all-features] -- -D warnings`: clean; `cargo xtask policy`: `190 files ok`. - Default (opt-in off): `switch::` 4/4, `shadow::` 10/10, and all 4 new `memory::tests::card_*` tests pass on RTX 5090, RTX 5090 + Debug Layer, and WARP + Debug Layer with zero D3D12 Debug Layer errors on the implicit `COMMON` transitions across the three `ExecuteCommandLists` calls. - With `VICTORY_CARD_COPIES=1` (default 1 MiB threshold) + `VICTORY_D3D12_DEBUG=1`: - RTX 5090: `bindless::` 3/3, `draw::tests::` 20/20 (including `root_views_reach_their_copy_and_read_zeros_past_it` with a 4 MiB card-backed source and all 5 `marked_subpage_uav_*` tests), `host::tests::` + `descriptor::host::tests::` + `pipeline::host::tests::` 30/31 (only the pre-existing NVIDIA 1M-cap `dynamic_slots_are_held_until_released` failure). - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`): `bindless::` 3/3, `draw::tests::` 20/20, `host::tests::` + `descriptor::host::tests::` + `pipeline::host::tests::` 31/31. - Stress check with `VICTORY_CARD_COPIES=1 VICTORY_CARD_COPIES_MIN_MB=0 VICTORY_D3D12_DEBUG=1` (forcing 64 KiB test shadows onto card sides): `shadow::` 10/10, `memory::tests::` 12/12 on WARP (including `a_submission_that_missed_leaves_the_copies_at_once` on both RTX 5090 and WARP), and all 5 `marked_subpage_uav_*` tests pass with zero Debug Layer issues. Three minor non-blocking follow-ups worth noting: 1. **Empty `groups` fence gap under `VICTORY_GPU_TIMING=1` (`host.rs:1497-1567`)**: when diagnostics `timing()` is active and `runs` is empty, `groups` is empty (`vec![]`), so `copy_up_cards(&card_uploads)` would submit `commands.up` without a subsequent fence signal/wait before `card_uploads` drops and before the next `commands.up.begin()` resets the allocator. Guarding `copy_up_cards` on `!groups.is_empty()` (or skipping card copies when `runs.is_empty()`) closes that edge case. 2. **Redundant `live_cards()` scans (`host.rs:1508-1514, 1648`, `shadow.rs:829-831`)**: `has_cards()` locks `CARDS`, upgrades every weak pointer into a `Vec`, and immediately drops it — running twice per submission even when `VICTORY_CARD_COPIES` is off, and twice back-to-back before `copy_up_cards` when on. Checking `CARD_ALLOCATED.load(Ordering::Relaxed) != 0` in `has_cards()` (and calling `card_uploads()` directly when `has_cards()` is true without re-scanning) would make the default-off path lock-free and trim a scan per submission when enabled. 3. **Initial `stale` bitmap (`shadow.rs:375`)**: newly committed `DEFAULT` buffers without `D3D12_HEAP_FLAG_CREATE_NOT_ZEROED` are zero-initialized by D3D12 just like `shared_buffer`. Starting `stale` as `vec![false; pages]` (since `copy()`, unmapped zero-fills, merges, and `write_host` all call `mark_stale`) would avoid an initial full-buffer PCIe upload of untouched zero pages when a large heap gets its card side. LGTM.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2705/head:github-bot/gh-2705'
git switch 'github-bot/gh-2705'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2705'
git switch 'github-bot/gh-2705'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2705'
git switch 'github-bot/gh-2705'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2705'
git switch 'main'
git merge --squash 'github-bot/gh-2705'
git switch 'main'
git merge --ff-only 'github-bot/gh-2705'
git switch 'main'
git merge 'github-bot/gh-2705'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2705
No description provided.