Perf/opt 01 card reserve #242

Open
El-Biiscuit wants to merge 12 commits from upstream-pr/242 into main
El-Biiscuit commented 2026-11-30 09:57:20 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by El-Biiscuit on 2026-11-30T09:57:20Z.


OPT-01: card reserve for title buffer copies (off by default)

Stacked on perf/card-room-pct (CARD-ROOM, c56fb6d). One commit, shadow: a card reserve for title buffer copies, off by default (VICTORY_CARD_RESERVE_MB).

Why

The room rule keeps a title buffer copy in the PC's memory whenever the card is past its line at the moment the copy is made. In this title the large shader-written buffers are made after the textures have filled the card (3.2 → 9.0 GB in 13 s before them in a diagnostic capture), so 8 of 9 stayed in PC memory at 80 %, and their shader writes were searched for on the CPU (about 700 MiB compared and 85 ms of snapshots per frame).

What

  • VICTORY_CARD_RESERVE_MB asks for a reserve; unset or 0 is the previous rule exactly. Default: off.
  • Capped at VICTORY_CARD_RESERVE_MAX_PCT of the card's current budget (10 unless set, 1 to 25).
  • A copy counts its card side plus the hashes of its "before" side. Placement: reserve first (while the card stays under its budget), then the room rule (VICTORY_CARD_ROOM_PCT), then PC memory, as before.
  • The texture queue (resource::room) leaves the unused part of the reserve free, so the order in which textures and buffers are made no longer decides.
  • Coherence paths are unchanged; card and PC copies use the same upload, compare and fetch steps.
  • Diagnostics: "on the card (from the reserve)" in the large-copy line; a 5 s line with the reserve, held bytes, copies placed and copies that found it short.

Tests

cargo test --profile diag -p victory-gpu -p victory-hle -p xtask --features victory-hle/diagnostics: victory-gpu 269, victory-hle 118, xtask 49 (perf-log message patterns included), all passing on this branch. New unit tests: cap, footprint, placement (reserve, short reserve, budget ceiling, off equals the old rule, 90 % case). Clippy clean on the validated build.

Measurements

One session, three runs of one diagnostics build, RX 6700 XT, Series X, --1080p-to-1440p, same save and path, fresh copies of the same state and shader cache, 60 s window marked by the player. Medians per frame (p95):

A: 80 % B: CARD-ROOM 90 % C: reserve 1024 MB
frame ms 265.5 (1627) 201.1 (267.8) 206.4 (226.7)
snapshots ms 85.1 2.1 2.1
CPU compare MiB 698.9 21.6 21.5
page faults 28,409 4,319 4,102
late.wait ms 30.1 70.8 74.5
VRAM % of budget 79.1 87.7 87.4
textures remade in window 692 MB 927 MB 944 MB
large copies on the card 1 of 9 9 of 9 9 of 9 (reserve)

Textures deferred by the VRAM budget: 0 in all runs. The reserve held 896 of 1,024 MB (109 copies); none found it short.

Limits of the comparison

  • C is not shown to be faster than B in median frame time. The difference (+2.6 % for C) is below run-to-run noise for one run per configuration; the p95 gap (−15 % for C) is from a single run too.
  • One run each, 10–11 frame-rate lines per window; the window starts differed (258, 202, 262 s after launch).
  • The measured build included GRAIN-0's diagnostics commits (af668d0, 90fdcb1), which earlier measurements found to have no measurable cost. This branch is the same change on c56fb6d without them, rebuilt and re-tested but not re-measured in game.
  • In this scene CARD-ROOM 90 % already places all 9 buffers. The reserve's benefit over B is structural (placement independent of creation order and of the texture threshold, bounded by the budget), not a demonstrated speed-up.
  • Reported by the player: in run C a boat showed its full texture. A single qualitative observation, not attributed to the change.
  • With copies on the card, late.wait more than doubles; this is the next item (OPT-02).
<!-- greyfinch-sync:DexNom/VIctory:issue:5562980086 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/242). Originally posted by [El-Biiscuit](https://github.com/El-Biiscuit) on 2026-11-30T09:57:20Z. --- ## OPT-01: card reserve for title buffer copies (off by default) Stacked on `perf/card-room-pct` (CARD-ROOM, `c56fb6d`). One commit, `shadow: a card reserve for title buffer copies, off by default (VICTORY_CARD_RESERVE_MB)`. ### Why The room rule keeps a title buffer copy in the PC's memory whenever the card is past its line at the moment the copy is made. In this title the large shader-written buffers are made after the textures have filled the card (3.2 → 9.0 GB in 13 s before them in a diagnostic capture), so 8 of 9 stayed in PC memory at 80 %, and their shader writes were searched for on the CPU (about 700 MiB compared and 85 ms of snapshots per frame). ### What - `VICTORY_CARD_RESERVE_MB` asks for a reserve; unset or 0 is the previous rule exactly. **Default: off.** - Capped at `VICTORY_CARD_RESERVE_MAX_PCT` of the card's current budget (10 unless set, 1 to 25). - A copy counts its card side plus the hashes of its "before" side. Placement: reserve first (while the card stays under its budget), then the room rule (`VICTORY_CARD_ROOM_PCT`), then PC memory, as before. - The texture queue (`resource::room`) leaves the unused part of the reserve free, so the order in which textures and buffers are made no longer decides. - Coherence paths are unchanged; card and PC copies use the same upload, compare and fetch steps. - Diagnostics: "on the card (from the reserve)" in the large-copy line; a 5 s line with the reserve, held bytes, copies placed and copies that found it short. ### Tests `cargo test --profile diag -p victory-gpu -p victory-hle -p xtask --features victory-hle/diagnostics`: victory-gpu 269, victory-hle 118, xtask 49 (perf-log message patterns included), all passing on this branch. New unit tests: cap, footprint, placement (reserve, short reserve, budget ceiling, off equals the old rule, 90 % case). Clippy clean on the validated build. ### Measurements One session, three runs of one diagnostics build, RX 6700 XT, Series X, `--1080p-to-1440p`, same save and path, fresh copies of the same state and shader cache, 60 s window marked by the player. Medians per frame (p95): | | A: 80 % | B: CARD-ROOM 90 % | C: reserve 1024 MB | | --- | ---: | ---: | ---: | | frame ms | 265.5 (1627) | 201.1 (267.8) | 206.4 (226.7) | | snapshots ms | 85.1 | 2.1 | 2.1 | | CPU compare MiB | 698.9 | 21.6 | 21.5 | | page faults | 28,409 | 4,319 | 4,102 | | late.wait ms | 30.1 | 70.8 | 74.5 | | VRAM % of budget | 79.1 | 87.7 | 87.4 | | textures remade in window | 692 MB | 927 MB | 944 MB | | large copies on the card | 1 of 9 | 9 of 9 | 9 of 9 (reserve) | Textures deferred by the VRAM budget: 0 in all runs. The reserve held 896 of 1,024 MB (109 copies); none found it short. ### Limits of the comparison - **C is not shown to be faster than B in median frame time.** The difference (+2.6 % for C) is below run-to-run noise for one run per configuration; the p95 gap (−15 % for C) is from a single run too. - One run each, 10–11 frame-rate lines per window; the window starts differed (258, 202, 262 s after launch). - The measured build included GRAIN-0's diagnostics commits (`af668d0`, `90fdcb1`), which earlier measurements found to have no measurable cost. This branch is the same change on `c56fb6d` without them, rebuilt and re-tested but not re-measured in game. - In this scene CARD-ROOM 90 % already places all 9 buffers. The reserve's benefit over B is structural (placement independent of creation order and of the texture threshold, bounded by the budget), not a demonstrated speed-up. - Reported by the player: in run C a boat showed its full texture. A single qualitative observation, not attributed to the change. - With copies on the card, `late.wait` more than doubles; this is the next item (OPT-02).
Zippp69 commented 2026-11-30 16:08:43 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Zippp69 on 2026-11-30T16:08:43Z.


Review of d44a0f8

Count reserve placements as VRAM. The runtime emits on the card (from the reserve), but LargeCopy::on_card() matches only on the card. I ran perf-log on two synthetic logs that differed only in the placement label. The reserve label produced one 174 MiB copy in PC memory, while the ordinary label produced one 174 MiB copy in VRAM. Recognize both VRAM labels and cover the reserve label in the summary test. parse.rs

The explicit texture budget and the first 2 GiB of tracked textures bypass the shared video-memory check. The texture queue does not hold back the reserve in those cases. Document those exceptions if the early returns are intentional. resource.rs

<!-- greyfinch-sync:DexNom/VIctory:comment:7284186757 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/242#issuecomment-7284186757). Originally posted by [Zippp69](https://github.com/Zippp69) on 2026-11-30T16:08:43Z. --- Review of `d44a0f8` **Count reserve placements as VRAM.** The runtime emits `on the card (from the reserve)`, but `LargeCopy::on_card()` matches only `on the card`. I ran `perf-log` on two synthetic logs that differed only in the placement label. The reserve label produced one 174 MiB copy in PC memory, while the ordinary label produced one 174 MiB copy in VRAM. Recognize both VRAM labels and cover the reserve label in the summary test. [parse.rs](https://github.com/DexNom/VIctory/blob/d44a0f8bcf3c13862b402e7c228bc58925b65249/xtask/src/perflog/parse.rs#L83-L87) The explicit texture budget and the first 2 GiB of tracked textures bypass the shared video-memory check. The texture queue does not hold back the reserve in those cases. Document those exceptions if the early returns are intentional. [resource.rs](https://github.com/DexNom/VIctory/blob/d44a0f8bcf3c13862b402e7c228bc58925b65249/crates/victory-gpu/src/resource.rs#L1453-L1475)
Zippp69 commented 2026-11-30 16:50:50 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Zippp69 on 2026-11-30T16:50:50Z.


Tested patch for the reserve classification. Follow-up to the perf-log review at d44a0f8. The classifier accepts both VRAM labels. The regression test changes the placement label in the synthetic run and verifies that the summary keeps 174 MiB in VRAM and 90 MiB in PC memory. The perflog suite returned 46 passed, 0 failed and 1 ignored.

In xtask/src/perflog/parse.rs:

    pub fn on_card(&self) -> bool {
        matches!(
            self.decision.as_str(),
            "on the card" | "on the card (from the reserve)"
        )
    }

In xtask/src/perflog/tests.rs:

#[test]
fn reserve_placements_are_counted_as_card_memory() {
    let log = synthetic(&Spec::default()).replacen(
        "MiB, on the card;",
        "MiB, on the card (from the reserve);",
        1,
    );
    let md = summary_of(&log, &Selection::default()).markdown(false, 8);
    assert!(
        md.contains("1 on the card (174 MiB), 1 kept in the PC's memory (90 MiB)"),
        "{md}"
    );
}
<!-- greyfinch-sync:DexNom/VIctory:comment:7285320813 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/242#issuecomment-7285320813). Originally posted by [Zippp69](https://github.com/Zippp69) on 2026-11-30T16:50:50Z. --- **Tested patch for the reserve classification.** Follow-up to [the perf-log review](https://github.com/DexNom/VIctory/pull/242#issuecomment-7284186757) at `d44a0f8`. The classifier accepts both VRAM labels. The regression test changes the placement label in the synthetic run and verifies that the summary keeps 174 MiB in VRAM and 90 MiB in PC memory. The `perflog` suite returned 46 passed, 0 failed and 1 ignored. In `xtask/src/perflog/parse.rs`: ```rust pub fn on_card(&self) -> bool { matches!( self.decision.as_str(), "on the card" | "on the card (from the reserve)" ) } ``` In `xtask/src/perflog/tests.rs`: ```rust #[test] fn reserve_placements_are_counted_as_card_memory() { let log = synthetic(&Spec::default()).replacen( "MiB, on the card;", "MiB, on the card (from the reserve);", 1, ); let md = summary_of(&log, &Selection::default()).markdown(false, 8); assert!( md.contains("1 on the card (174 MiB), 1 kept in the PC's memory (90 MiB)"), "{md}" ); } ```
El-Biiscuit commented 2026-12-01 14:44:15 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by El-Biiscuit on 2026-12-01T14:44:15Z.


Thanks @Zippp69 for both reviews and for the tested patch. Both points are addressed in a6eac73 (pushed to this branch):

1. Reserve placements count as card memory (xtask/src/perflog/parse.rs)

  • LargeCopy::on_card() now accepts both on the card and on the card (from the reserve). This is your fix; the commit message credits your review.
  • New regression test reserve_placements_are_counted_as_card_memory (xtask/src/perflog/tests.rs), adapted from your patch. It relabels the placement in the synthetic run, checks that the line still parses, and checks that the summary reports 1 on the card (174 MiB), 1 kept in the PC's memory (90 MiB).
  • cargo test -p xtask perflog: 46 passed, 0 failed, 1 ignored. The new test fails with the fix reverted and passes with it.

2. Texture-queue exceptions (crates/victory-gpu/src/resource.rs, room())

  • Confirmed in the source: an explicit VICTORY_TEXTURE_BUDGET_MB limit and the first FLOOR (2 GiB) of tracked textures both return before the shared video-memory check, so the reserve is not held back in those cases.
  • This is intentional. Both early returns predate this PR. The reserve only changes the budget-based branch, so the semantics of the explicit byte limit and of the always-admitted floor stay as they were. A user who sets an explicit texture limit chooses the copies' bytes directly.
  • This commit only adds a comment documenting the two exceptions. Behaviour is unchanged.

Performance

  • No new performance result. The measurements in the description still stand. The reserve run was not faster than the baseline in median frame time, so this PR still claims no frame-time gain.
<!-- greyfinch-sync:DexNom/VIctory:comment:7314744551 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/242#issuecomment-7314744551). Originally posted by [El-Biiscuit](https://github.com/El-Biiscuit) on 2026-12-01T14:44:15Z. --- Thanks @Zippp69 for both reviews and for the tested patch. Both points are addressed in a6eac73 (pushed to this branch): **1. Reserve placements count as card memory** (`xtask/src/perflog/parse.rs`) - `LargeCopy::on_card()` now accepts both `on the card` and `on the card (from the reserve)`. This is your fix; the commit message credits your review. - New regression test `reserve_placements_are_counted_as_card_memory` (`xtask/src/perflog/tests.rs`), adapted from your patch. It relabels the placement in the synthetic run, checks that the line still parses, and checks that the summary reports `1 on the card (174 MiB), 1 kept in the PC's memory (90 MiB)`. - `cargo test -p xtask perflog`: 46 passed, 0 failed, 1 ignored. The new test fails with the fix reverted and passes with it. **2. Texture-queue exceptions** (`crates/victory-gpu/src/resource.rs`, `room()`) - Confirmed in the source: an explicit `VICTORY_TEXTURE_BUDGET_MB` limit and the first `FLOOR` (2 GiB) of tracked textures both return before the shared video-memory check, so the reserve is not held back in those cases. - This is intentional. Both early returns predate this PR. The reserve only changes the budget-based branch, so the semantics of the explicit byte limit and of the always-admitted floor stay as they were. A user who sets an explicit texture limit chooses the copies' bytes directly. - This commit only adds a comment documenting the two exceptions. Behaviour is unchanged. **Performance** - No new performance result. The measurements in the description still stand. The reserve run was not faster than the baseline in median frame time, so this PR still claims no frame-time gain.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/242:upstream-pr/242'
git switch 'upstream-pr/242'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/242'
git switch 'upstream-pr/242'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/242'
git switch 'upstream-pr/242'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/242'
git switch 'main'
git merge --squash 'upstream-pr/242'
git switch 'main'
git merge --ff-only 'upstream-pr/242'
git switch 'main'
git merge 'upstream-pr/242'
git push origin 'main'
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
DexNom/VIctory!242
No description provided.