Card copies without a CPU mirror until shaders write them (VICTORY_CARD_NO_MIRROR=1, off by default) #4861

Closed
github-bot wants to merge 2 commits from github-bot/gh-4860 into main AGit
Owner

@⁠mcozcan on GitHub · 2026-12-01 11:54 UTC · original
mcozcan:card-no-mirror → main · +416 −11 · 3 files · 2 commits · closed without merging

Refs #4463

What it changes

Every title buffer with a copy in the card's memory is held three times: the title's own pages, the copy's CPU mirror (Card::staging, which Shadow::data points into) and the card's side. The mirror is the copy's full size in the PC's memory. It does two jobs:

  1. What the title wrote goes up from it (Shadow::copy → send::take).
  2. It is the "before" that the card's bytes are compared with to find what shaders wrote (safecopy::merge via card_merge, land_card). The card keeps only a 16-byte hash per 64 KiB piece.

A copy that no shader was ever declared to write needs only the first job, and title memory can do that itself. The aim is RAM and commit: for those copies, the PC's memory holds the bytes once instead of twice.

With VICTORY_CARD_NO_MIRROR=1 (off by default):

  • Only address space. A new card copy's mirror is reserved (MEM_RESERVE), not committed, so it costs neither RAM nor commit (LazyMirror). The copy's pointer stays the same; nothing reads or writes the pages while they are missing.
  • The refresh only marks. The changed runs are marked to go up; nothing is copied into the mirror (Shadow::copy).
  • The sends read title memory. Missing pages read as zeros, through copy_mapped as the refresh does. The reads run on the wide pool (send::copy_from_title), so the work does not move onto the submitting thread. The bytes are copied once (title → submission memory) instead of twice (title → mirror → submission memory).
  • The mirror is made when it is first needed. The first time shaders are declared to write the copy, it is committed, filled from title memory, and the whole copy is marked to go up from it (Shadow::ensure_mirror). The first time means any of the eight written sites, writing, placed_copy, keep_stores, card_make_before, take or take_landed. The card then holds what the mirror holds before any submission that writes it runs, and the copy goes on as today.
  • Placed copies. Before a placed copy (Step::Placed) writes title memory, copies over its destination that have no mirror get one, filled with the bytes from before. Draws ahead of the copy in the list keep seeing those bytes (the order place.rs keeps).
  • Landing and merge paths (card_merge, card_merge_relay, land_card) leave a copy without a mirror out and warn once (... on a copy without a mirror, left out (please report)). They should never meet one, because declaring shader writes makes the mirror first.
  • Out of commit. If the PC's commit is used up when a mirror must be made, the run ends with a clear message (host::fail). The copy could not be landed without it.
  • Where it stays off. It is off with VICTORY_SEND_OWN=0, VICTORY_UPCOPY_CHECK=1 or VICTORY_SEND_CHANGED=1, which read every copy's mirror. Arenas by address (by_address, changes_only) and windows promoted later (card_late_windows) keep their mirrors.

VICTORY_MIRROR_STATS=1 (counting only, and also on with VICTORY_CARD_NO_MIRROR=1) adds one line to the frame-rate lines:

  • the mirrors now, by whether shaders were declared to write the copy, with copies of 128 MiB and more apart;
  • the mirrors left out, and those made later;
  • per frame, the ranges newly declared written and the title pages written under ranges in flight.

The last two size a possible next step: dropping the mirrors of written copies too, with copy-on-write of the pages the title writes under a flight. That is not in this PR.

How much it saves depends on how much of the carded memory shaders never write, and nothing in the repository splits that yet; the new line does. For scale, the mirrors are as large as the carded copies:

  • 592 MB in one run (shadow.rs comment);
  • 925 MB in 57 copies on an RTX 5080;
  • up to 2 GiB of buffers plus 1 GiB of windows at the default caps;
  • far more under victory play, whose VICTORY_CARD_ALL=1 gives every copy a second side.

How it was tested

  • GPU and profile: not run in the game yet. I will run it on my RTX 5070 12 GB (Ryzen 5 9600X, 32 GB RAM) this evening and post the results here. Until then it is a draft.
  • Before / After: none yet. What I will compare, same route, 10-15 minutes each:
    • VICTORY_MIRROR_STATS=1 alone against VICTORY_MIRROR_STATS=1 VICTORY_CARD_NO_MIRROR=1;
    • commit and RAM in use (Task Manager), frame times, and the picture (faces, hair, missing models);
    • the line's "left out now ... MB" and "given one later";
    • any "please report" warning.
  • Testers welcome, especially on 8 and 16 GB cards and with victory play. The two runs above, with the CPU mirrors of card copies line and commit from each, would show what it saves and whether anything breaks.
  • For shader changes: none.
  • cargo test: the new title_pieces_cover_every_byte_once_in_order (the split of the sends across the pool) passes, run on Linux in a crate of its own. Built on Windows: the same change (with other opt-in work on top) passed both clippy steps of this repository's CI workflow in my own repository (run), since CI here waits for approval; that run was stopped before its test step.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:

    • #2215 (RT arena edits staged without a permanent second CPU mirror: the same idea for the arenas by address, which this leaves alone);
    • #4842 and #4276 (VICTORY_CARD_CPU_FILE: the mirrors in files instead of the page file; this drops them where they are not needed);
    • #4751 (windows share one copy in tiles);
    • #4818 (first-touch copies outside write locks; touches shadow.rs);
    • #4580 (snapshots of private CPU mirrors).

    None removes the mirror of card copies.

**@⁠mcozcan** on GitHub · 2026-12-01 11:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4860) `mcozcan:card-no-mirror` → `main` · +416 −11 · 3 files · 2 commits · closed without merging Refs #4463 ## What it changes Every title buffer with a copy in the card's memory is held three times: the title's own pages, the copy's CPU mirror (`Card::staging`, which `Shadow::data` points into) and the card's side. The mirror is the copy's full size in the PC's memory. It does two jobs: 1. What the title wrote goes up from it (`Shadow::copy` → `send::take`). 2. It is the "before" that the card's bytes are compared with to find what shaders wrote (`safecopy::merge` via `card_merge`, `land_card`). The card keeps only a 16-byte hash per 64 KiB piece. A copy that no shader was ever declared to write needs only the first job, and title memory can do that itself. **The aim is RAM and commit:** for those copies, the PC's memory holds the bytes once instead of twice. With `VICTORY_CARD_NO_MIRROR=1` (off by default): - **Only address space.** A new card copy's mirror is reserved (`MEM_RESERVE`), not committed, so it costs neither RAM nor commit (`LazyMirror`). The copy's pointer stays the same; nothing reads or writes the pages while they are missing. - **The refresh only marks.** The changed runs are marked to go up; nothing is copied into the mirror (`Shadow::copy`). - **The sends read title memory.** Missing pages read as zeros, through `copy_mapped` as the refresh does. The reads run on the wide pool (`send::copy_from_title`), so the work does not move onto the submitting thread. The bytes are copied once (title → submission memory) instead of twice (title → mirror → submission memory). - **The mirror is made when it is first needed.** The first time shaders are declared to write the copy, it is committed, filled from title memory, and the whole copy is marked to go up from it (`Shadow::ensure_mirror`). The first time means any of the eight `written` sites, `writing`, `placed_copy`, `keep_stores`, `card_make_before`, `take` or `take_landed`. The card then holds what the mirror holds before any submission that writes it runs, and the copy goes on as today. - **Placed copies.** Before a placed copy (`Step::Placed`) writes title memory, copies over its destination that have no mirror get one, filled with the bytes from before. Draws ahead of the copy in the list keep seeing those bytes (the order `place.rs` keeps). - **Landing and merge paths** (`card_merge`, `card_merge_relay`, `land_card`) leave a copy without a mirror out and warn once (`... on a copy without a mirror, left out (please report)`). They should never meet one, because declaring shader writes makes the mirror first. - **Out of commit.** If the PC's commit is used up when a mirror must be made, the run ends with a clear message (`host::fail`). The copy could not be landed without it. - **Where it stays off.** It is off with `VICTORY_SEND_OWN=0`, `VICTORY_UPCOPY_CHECK=1` or `VICTORY_SEND_CHANGED=1`, which read every copy's mirror. Arenas by address (`by_address`, `changes_only`) and windows promoted later (`card_late_windows`) keep their mirrors. `VICTORY_MIRROR_STATS=1` (counting only, and also on with `VICTORY_CARD_NO_MIRROR=1`) adds one line to the frame-rate lines: - the mirrors now, by whether shaders were declared to write the copy, with copies of 128 MiB and more apart; - the mirrors left out, and those made later; - per frame, the ranges newly declared written and the title pages written under ranges in flight. The last two size a possible next step: dropping the mirrors of written copies too, with copy-on-write of the pages the title writes under a flight. That is not in this PR. How much it saves depends on how much of the carded memory shaders never write, and nothing in the repository splits that yet; the new line does. For scale, the mirrors are as large as the carded copies: - 592 MB in one run (`shadow.rs` comment); - 925 MB in 57 copies on an RTX 5080; - up to 2 GiB of buffers plus 1 GiB of windows at the default caps; - far more under `victory play`, whose `VICTORY_CARD_ALL=1` gives every copy a second side. ## How it was tested - GPU and profile: **not run in the game yet.** I will run it on my RTX 5070 12 GB (Ryzen 5 9600X, 32 GB RAM) this evening and post the results here. Until then it is a draft. - Before / After: none yet. What I will compare, same route, 10-15 minutes each: - `VICTORY_MIRROR_STATS=1` alone against `VICTORY_MIRROR_STATS=1 VICTORY_CARD_NO_MIRROR=1`; - commit and RAM in use (Task Manager), frame times, and the picture (faces, hair, missing models); - the line's "left out now ... MB" and "given one later"; - any "please report" warning. - **Testers welcome**, especially on 8 and 16 GB cards and with `victory play`. The two runs above, with the `CPU mirrors of card copies` line and commit from each, would show what it saves and whether anything breaks. - For shader changes: none. - `cargo test`: the new `title_pieces_cover_every_byte_once_in_order` (the split of the sends across the pool) passes, run on Linux in a crate of its own. Built on Windows: the same change (with other opt-in work on top) passed both clippy steps of this repository's CI workflow in my own repository ([run](https://github.com/mcozcan/PortMC-VI/actions/runs/46645239870)), since CI here waits for approval; that run was stopped before its test step. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: - #2215 (RT arena edits staged without a permanent second CPU mirror: the same idea for the arenas by address, which this leaves alone); - #4842 and #4276 (`VICTORY_CARD_CPU_FILE`: the mirrors in files instead of the page file; this drops them where they are not needed); - #4751 (windows share one copy in tiles); - #4818 (first-touch copies outside write locks; touches `shadow.rs`); - #4580 (snapshots of private CPU mirrors). None removes the mirror of card copies.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 11:59:00 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:30 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4860#issuecomment-7321055480) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
github-bot closed this pull request 2026-12-01 18:36:23 +00:00

Pull request closed

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/trustno1-coder--VIctory-NVIDIA!4861
No description provided.