GPU: card copies of title buffers keep their room from the textures picked by index (VICTORY_CARD_RESERVE=1) #723

Closed
github-bot wants to merge 1 commit from gh-pr/723/head into gh-pr/723/base
Owner

@⁠LeonardoS11 on GitHub · 2026-11-25 05:43 UTC · original
LeonardoS11:fix/card-reserve → main · +56 −2 · 2 files · 1 commits · closed without merging

What

Since 310c6eb the first room runs at about half the frame rate on an RTX 3080 Ti (12 GB): 540–660 ms a frame where c96b4f2 gave 270–330. This PR adds VICTORY_CARD_RESERVE=1 (off by default), which brings it back to 275–293 ms.

Why it got slower

  • A title buffer's copy in the card's memory is decided once, the first time the buffer is used (shadow.rs, card_for), and only while the card is under four fifths of its budget. It is not tried again.
  • Textures picked by index fill the card up to VICTORY_TEXTURE_ROOM_PERCENT (90).
  • With 310c6eb the textures get there first. Every big buffer used after that stays in the PC's memory for good, and what shaders write to it is looked for on the CPU.

The per-frame lines show it (plain 310c6eb, same scene, 300 s runs):

host copies in the card's memory shader writes looked for on the CPU ms a frame
c96b4f2 — 24 MB 300, 330
310c6eb 10 copies, 190 MB (one of the runs) 600–780 MB 539, 590, 658
310c6eb, VICTORY_TEXTURE_BUDGET_MB=6000 97 copies, 941 MB 24.5 MB 266
310c6eb, VICTORY_TEXTURE_ROOM_PERCENT=75 6 and 15 copies 618 and 784 MB 518, 551
310c6eb, VICTORY_REUPLOAD_WHEN_FULL=0 — — 408, 538
310c6eb + #676 20 copies, 366 MB 531 MB 499
this PR, VICTORY_CARD_RESERVE=1 94 and 96 copies, 932–936 MB 30 MB 293, 275
this PR, switch off 13 copies, 241 MB 602 MB 534

So a lower texture budget works around it, the percentage does not (the rest of what is on the card is already past four fifths), and neither VICTORY_REUPLOAD_WHEN_FULL=0 nor #676 changes it.

The change

With VICTORY_CARD_RESERVE=1:

  • resource::room counts as used the room of the card copies not made yet: what VICTORY_CARD_BUFFERS_MB allows, less the copies alive (about 1 GB with the defaults). Textures picked by index stop that much earlier.
  • card_for takes a copy while the card is under the textures' share instead of four fifths, since the reserve keeps that room for it.

The rule is a small pure function, under_share(budget, used, reserve, percent), with a unit test.

Why it is a switch, and what I would suggest

It is off by default because of three things I have not measured:

  1. If a title never uses big buffers adding up to the reserve, the unused part is held for good and textures lose up to about 1 GB of the card.
  2. On an 8 GB card that is a large part, and textures picked by index would wait longer.
  3. Copies may now take the card closer to the system's budget than four fifths.

On a 12 GB card it is a clear win, so on by default looks reasonable to me, perhaps with the reserve capped (a tenth of the budget, say) or dropped once the world has loaded. I leave that to you; a number from an 8 GB card would settle it.

Picture

I cannot show that the picture is unchanged, because the picture of 310c6eb is not stable here from launch to launch. Of 6 launches of plain 310c6eb with no switches, the first room's walls were missing in 1 and the chain-link mesh in the window in 1. The 3 launches of this PR's executable (two with the switch, one without) all had the walls missing, and so had the plain 310c6eb launches with the texture switches of the table, which ran in the same hour. So I see no difference that follows the switch, but 3 launches are too few to say so firmly.

Tested

  • Windows 11, RTX 3080 Ti 12 GB, 64 GB RAM, diag build with diagnostics, base 310c6eb.
  • cargo test --workspace: 511 passed, 0 failed, 9 ignored (on the GPU above). The new test is resource::tests::the_reserve_for_card_copies_counts_as_used.
  • In game: one checkpoint in the prologue (the room with the window onto the yard), 300 s a run, averages of the last 8 frame-rate lines; numbers in the table above. Two runs with the switch, one without on the same executable.

No title data in this PR: counts and times only.

🤖 Generated with Claude Code

**@⁠LeonardoS11** on GitHub · 2026-11-25 05:43 UTC · [original](https://github.com/fxceless/victory-fork/pull/723) `LeonardoS11:fix/card-reserve` → `main` · +56 −2 · 2 files · 1 commits · closed without merging ## What Since 310c6eb the first room runs at about half the frame rate on an RTX 3080 Ti (12 GB): 540–660 ms a frame where c96b4f2 gave 270–330. This PR adds `VICTORY_CARD_RESERVE=1` (off by default), which brings it back to 275–293 ms. ## Why it got slower - A title buffer's copy in the card's memory is decided once, the first time the buffer is used (`shadow.rs`, `card_for`), and only while the card is under four fifths of its budget. It is not tried again. - Textures picked by index fill the card up to `VICTORY_TEXTURE_ROOM_PERCENT` (90). - With 310c6eb the textures get there first. Every big buffer used after that stays in the PC's memory for good, and what shaders write to it is looked for on the CPU. The per-frame lines show it (plain 310c6eb, same scene, 300 s runs): | | host copies in the card's memory | shader writes looked for on the CPU | ms a frame | |---|---|---|---| | c96b4f2 | — | 24 MB | 300, 330 | | 310c6eb | 10 copies, 190 MB (one of the runs) | 600–780 MB | 539, 590, 658 | | 310c6eb, `VICTORY_TEXTURE_BUDGET_MB=6000` | 97 copies, 941 MB | 24.5 MB | 266 | | 310c6eb, `VICTORY_TEXTURE_ROOM_PERCENT=75` | 6 and 15 copies | 618 and 784 MB | 518, 551 | | 310c6eb, `VICTORY_REUPLOAD_WHEN_FULL=0` | — | — | 408, 538 | | 310c6eb + #676 | 20 copies, 366 MB | 531 MB | 499 | | **this PR, `VICTORY_CARD_RESERVE=1`** | **94 and 96 copies, 932–936 MB** | **30 MB** | **293, 275** | | this PR, switch off | 13 copies, 241 MB | 602 MB | 534 | So a lower texture budget works around it, the percentage does not (the rest of what is on the card is already past four fifths), and neither `VICTORY_REUPLOAD_WHEN_FULL=0` nor #676 changes it. ## The change With `VICTORY_CARD_RESERVE=1`: - `resource::room` counts as used the room of the card copies not made yet: what `VICTORY_CARD_BUFFERS_MB` allows, less the copies alive (about 1 GB with the defaults). Textures picked by index stop that much earlier. - `card_for` takes a copy while the card is under the textures' share instead of four fifths, since the reserve keeps that room for it. The rule is a small pure function, `under_share(budget, used, reserve, percent)`, with a unit test. ## Why it is a switch, and what I would suggest It is off by default because of three things I have not measured: 1. If a title never uses big buffers adding up to the reserve, the unused part is held for good and textures lose up to about 1 GB of the card. 2. On an 8 GB card that is a large part, and textures picked by index would wait longer. 3. Copies may now take the card closer to the system's budget than four fifths. On a 12 GB card it is a clear win, so on by default looks reasonable to me, perhaps with the reserve capped (a tenth of the budget, say) or dropped once the world has loaded. I leave that to you; a number from an 8 GB card would settle it. ## Picture I cannot show that the picture is unchanged, because the picture of 310c6eb is not stable here from launch to launch. Of 6 launches of plain 310c6eb with no switches, the first room's walls were missing in 1 and the chain-link mesh in the window in 1. The 3 launches of this PR's executable (two with the switch, one without) all had the walls missing, and so had the plain 310c6eb launches with the texture switches of the table, which ran in the same hour. So I see no difference that follows the switch, but 3 launches are too few to say so firmly. ## Tested - Windows 11, RTX 3080 Ti 12 GB, 64 GB RAM, `diag` build with `diagnostics`, base 310c6eb. - `cargo test --workspace`: 511 passed, 0 failed, 9 ignored (on the GPU above). The new test is `resource::tests::the_reserve_for_card_copies_counts_as_used`. - In game: one checkpoint in the prologue (the room with the window onto the yard), 300 s a run, averages of the last 8 frame-rate lines; numbers in the table above. Two runs with the switch, one without on the same executable. No title data in this PR: counts and times only. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A title buffer's card copy is made the first time the buffer is used, and
only while the card is under four fifths of its budget; it is not tried
again. Since textures picked by index are made earlier (310c6eb), they fill
the card to their share first, every big buffer used after that stays in
the PC's memory, and what shaders write to it is looked for on the CPU:
600-780 MB a frame against 24 with the copies on the card, and frames of
520-590 ms where they were 270.

With the switch the textures leave room for the copies not made yet (the
most VICTORY_CARD_BUFFERS_MB allows, less the copies alive), and a copy may
take the card up to the textures' share instead of four fifths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:46 +00:00
github-bot closed this pull request 2026-11-26 03:49:46 +00:00
Author
Owner

@⁠LeonardoS11 on GitHub · 2026-11-25 06:25 UTC · original

A correction to the "Picture" section above, after more launches: on this 12 GB card the switch does cost picture.

Counting the first room's walls at 295 s:

walls there
plain 310c6eb, no switches (slow: buffers off the card) 5 of 6 launches
reserve on (this PR's change; 2 launches of this branch, 8 of a branch of ours that has it on) 1 of 10
plain 310c6eb with VICTORY_TEXTURE_BUDGET_MB=6000 (fast without this PR) 0 of 1

So it is not this change in particular: whenever the big buffers get their copies on the card (about 940 MB) and the frame time halves, the walls' textures no longer fit ("textures picked by index: the card has no room for more; they wait"), and whenever the textures win, the buffers stay in the PC's memory and the frame time doubles. On 12 GB the two do not fit together as things are; the switch only chooses which side loses. c96b4f2 was on the fast side too, and had the walls missing in 2 of 3 launches here.

That makes the "known" line of 310c6eb the real lever for both — more than half of the texture memory on the card being held for levels the title has not loaded yet. I would keep this PR as an opt-in for now, not a default.

(Launches and screenshots by me on the RTX 3080 Ti above; counted and written with Claude Code.)

**@⁠LeonardoS11** on GitHub · 2026-11-25 06:25 UTC · [original](https://github.com/fxceless/victory-fork/pull/723#issuecomment-7154774695) A correction to the "Picture" section above, after more launches: on this 12 GB card the switch does cost picture. Counting the first room's walls at 295 s: | | walls there | |---|---| | plain 310c6eb, no switches (slow: buffers off the card) | 5 of 6 launches | | reserve on (this PR's change; 2 launches of this branch, 8 of a branch of ours that has it on) | 1 of 10 | | plain 310c6eb with `VICTORY_TEXTURE_BUDGET_MB=6000` (fast without this PR) | 0 of 1 | So it is not this change in particular: whenever the big buffers get their copies on the card (about 940 MB) and the frame time halves, the walls' textures no longer fit ("textures picked by index: the card has no room for more; they wait"), and whenever the textures win, the buffers stay in the PC's memory and the frame time doubles. On 12 GB the two do not fit together as things are; the switch only chooses which side loses. c96b4f2 was on the fast side too, and had the walls missing in 2 of 3 launches here. That makes the "known" line of 310c6eb the real lever for both — more than half of the texture memory on the card being held for levels the title has not loaded yet. I would keep this PR as an opt-in for now, not a default. (Launches and screenshots by me on the RTX 3080 Ti above; counted and written with Claude Code.)
Author
Owner

@⁠LeonardoS11 on GitHub · 2026-11-25 07:20 UTC · original

Closing: 8dd30ab brought the same thing as VICTORY_CARD_ROOM_FOR_BUFFERS=1, and with VICTORY_LEVELS_ON_DEMAND=1 the buffers and the walls' textures fit together on this 12 GB card, so the trade described above goes away. Numbers from the same scene on 8dd30ab are in #776. (Written with Claude Code.)

**@⁠LeonardoS11** on GitHub · 2026-11-25 07:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/723#issuecomment-7155750849) Closing: 8dd30ab brought the same thing as `VICTORY_CARD_ROOM_FOR_BUFFERS=1`, and with `VICTORY_LEVELS_ON_DEMAND=1` the buffers and the walls' textures fit together on this 12 GB card, so the trade described above goes away. Numbers from the same scene on 8dd30ab are in #776. (Written with Claude Code.)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.