8 GB card: 722c0e1 onward is 2-4x slower than f249fe0 and the time is not in any counter (starts at the eval/coolfox merge) #221

Open
opened 2026-11-26 12:04:47 +00:00 by github-bot · 12 comments
Owner

@⁠Key-rs on GitHub · 2026-11-26 11:58 UTC · original

On 8 GB VRAM (RTX 4060 Laptop) the tree from 722c0e1 onward is 2-4× slower than f249fe0 on the same scene, and the time does not show up in any counter. f249fe0 is the fastest this card has seen so far (5 fps at ~5,100 draws); I am reporting it because the regression starts exactly at the eval/coolfox merge.

The three points, same machine, same switches

Ryzen 7 8845H (8c/16t), RTX 4060 Laptop 8 GB, 31 GB RAM, Windows 11, driver 621.40. --profile diag --features diagnostics, scripts/play.ps1 -Safe plus VICTORY_THIN=1 for all of them, shaders and pipelines warmed for each, real key presses to reach the world:

tree switches frame fps draws
f249fe0 Safe + THIN 198-212 ms 5.0 5,065-5,292
722c0e1 Safe + THIN 680-1728 ms 1-2 2,864-7,164
722c0e1 + VICTORY_PLANES=0 419-540 ms 2-3 3,704-5,715
0dec5dc + VICTORY_OUTPUT=1920x1080 310-528 ms 2-3 4,791-5,926
0dec5dc + VICTORY_OUTPUT=1920x1080, after re-translating shaders and re-warming 2,981 pipelines 339-940 ms 1.1-2.9 2,528-4,567

I added lto = "thin" and codegen-units = 1 and built with -C target-cpu=native for all of them, so the comparison is like for like inside this machine (that alone was worth ~25 % here: 4 → 5 fps, 55 → 40 µs a draw).

Why this looks like a regression and not scene noise

Two things that should not happen together:

1. The parts I can account for get cheaper, the frame gets longer.

0dec5dc with 1080p output, a 539 ms frame:

539.6 ms/frame (138.2 preparing: copies 35.2 ms 73.4 MB, textures 4.9 ms 11.7 MB;
                0.0 on the GPU; 74.2 copying back 18.9 MB), 4567 draws/frame

That is 138 + 74 = 212 ms accounted for, and the GPU wait is 0.0 — so roughly 330 ms is somewhere no line reports. On f249fe0 the same kind of frame was 200 ms total with preparing at 160-190, i.e. the counters covered it.

2. The card is idle and the title has not submitted.

the card's clock per frame: nothing of ours queued 286.3 ms (the card about 26% busy),
  74.2 ms of that while the submitting thread was working,
  the rest while the title had not submitted; the submitting thread stood waiting for the card 0.0 ms

"the rest while the title had not submitted" is ~210 ms. The submitting thread is not waiting on the card (0.0 ms), so it is not a fence; the title's own threads are somewhere before submitting. On f249fe0 the same line read 55-99 ms queued and 62-76 % busy.

VICTORY_PLANES=0 recovers part of it (680 → 419 ms), so the two-plane compose is one contributor, but not the whole story: the remainder is still 2× slower than f249fe0.

Where I would bisect

The two commits that bracket the change:

11-26 02:05  Merge eval/coolfox: the AMD-safe parts of codec-d/cool_fox
             (two-plane compose for Series S, TablePlan, ...)
11-26 02:06  Two-plane compose on by default (VICTORY_PLANES=0 turns it off)

VICTORY_PLANES=0 exists and helps; I could not find a switch for the TablePlan half of that merge. If there is one (VICTORY_* for the plan or for the residency budgets), tell me and I will bisect it on this card — the same run takes 9 minutes.

On VICTORY_OUTPUT, which is a separate matter

It works, and the log says so:

resolution: patched site=0x224352b what="settings' output size applied"
resolution: patched site=0x247af25 what="back buffer pool's left-over check"

I just cannot see the gain on this build because the regression above eats far more than 1080p saves. Worth re-measuring after it is fixed: on an 8 GB card the back buffer is a real constraint (1526 MB budget, filled 863), so this switch should matter more here than on your 24 GB.

What I am running meanwhile

f249fe0 with the LTO profile, Safe + THIN, VICTORY_PORT_DESCRIPTORS=1 VICTORY_PORT_CONSTANTS=1: 5 fps, 198-212 ms, the state in the screenshot (prison yard, characters lit, fence and hair reading correctly). If it would help, I can run any commit you name through the same 9-minute harness and report the same three numbers.

**@⁠Key-rs** on GitHub · 2026-11-26 11:58 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221) On 8 GB VRAM (RTX 4060 Laptop) the tree from `722c0e1` onward is **2-4× slower than `f249fe0`** on the same scene, and the time does not show up in any counter. `f249fe0` is the fastest this card has seen so far (5 fps at ~5,100 draws); I am reporting it because the regression starts exactly at the `eval/coolfox` merge. ### The three points, same machine, same switches Ryzen 7 8845H (8c/16t), RTX 4060 Laptop 8 GB, 31 GB RAM, Windows 11, driver 621.40. `--profile diag --features diagnostics`, `scripts/play.ps1 -Safe` plus `VICTORY_THIN=1` for all of them, shaders and pipelines warmed for each, real key presses to reach the world: | tree | switches | frame | fps | draws | |---|---|---|---|---| | `f249fe0` | Safe + THIN | **198-212 ms** | **5.0** | 5,065-5,292 | | `722c0e1` | Safe + THIN | 680-1728 ms | 1-2 | 2,864-7,164 | | `722c0e1` | + `VICTORY_PLANES=0` | 419-540 ms | 2-3 | 3,704-5,715 | | `0dec5dc` | + `VICTORY_OUTPUT=1920x1080` | 310-528 ms | 2-3 | 4,791-5,926 | | `0dec5dc` | + `VICTORY_OUTPUT=1920x1080`, after re-translating shaders and re-warming 2,981 pipelines | 339-940 ms | 1.1-2.9 | 2,528-4,567 | I added `lto = "thin"` and `codegen-units = 1` and built with `-C target-cpu=native` for all of them, so the comparison is like for like inside this machine (that alone was worth ~25 % here: 4 → 5 fps, 55 → 40 µs a draw). ### Why this looks like a regression and not scene noise Two things that should not happen together: **1. The parts I can account for get cheaper, the frame gets longer.** `0dec5dc` with 1080p output, a 539 ms frame: ``` 539.6 ms/frame (138.2 preparing: copies 35.2 ms 73.4 MB, textures 4.9 ms 11.7 MB; 0.0 on the GPU; 74.2 copying back 18.9 MB), 4567 draws/frame ``` That is 138 + 74 = 212 ms accounted for, and the GPU wait is 0.0 — so roughly **330 ms is somewhere no line reports**. On `f249fe0` the same kind of frame was 200 ms total with `preparing` at 160-190, i.e. the counters covered it. **2. The card is idle and the title has not submitted.** ``` the card's clock per frame: nothing of ours queued 286.3 ms (the card about 26% busy), 74.2 ms of that while the submitting thread was working, the rest while the title had not submitted; the submitting thread stood waiting for the card 0.0 ms ``` "the rest while the title had not submitted" is ~210 ms. The submitting thread is not waiting on the card (0.0 ms), so it is not a fence; the title's own threads are somewhere before submitting. On `f249fe0` the same line read 55-99 ms queued and 62-76 % busy. `VICTORY_PLANES=0` recovers part of it (680 → 419 ms), so the two-plane compose is one contributor, but not the whole story: the remainder is still 2× slower than `f249fe0`. ### Where I would bisect The two commits that bracket the change: ``` 11-26 02:05 Merge eval/coolfox: the AMD-safe parts of codec-d/cool_fox (two-plane compose for Series S, TablePlan, ...) 11-26 02:06 Two-plane compose on by default (VICTORY_PLANES=0 turns it off) ``` `VICTORY_PLANES=0` exists and helps; I could not find a switch for the TablePlan half of that merge. If there is one (`VICTORY_*` for the plan or for the residency budgets), tell me and I will bisect it on this card — the same run takes 9 minutes. ### On `VICTORY_OUTPUT`, which is a separate matter It works, and the log says so: ``` resolution: patched site=0x224352b what="settings' output size applied" resolution: patched site=0x247af25 what="back buffer pool's left-over check" ``` I just cannot see the gain on this build because the regression above eats far more than 1080p saves. Worth re-measuring after it is fixed: on an 8 GB card the back buffer is a real constraint (`1526 MB budget, filled 863`), so this switch should matter more here than on your 24 GB. ### What I am running meanwhile `f249fe0` with the LTO profile, `Safe` + `THIN`, `VICTORY_PORT_DESCRIPTORS=1` `VICTORY_PORT_CONSTANTS=1`: 5 fps, 198-212 ms, the state in the screenshot (prison yard, characters lit, fence and hair reading correctly). If it would help, I can run any commit you name through the same 9-minute harness and report the same three numbers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:04:47 +00:00
Author
Owner

@⁠pr0vId3nce on GitHub · 2026-11-26 12:29 UTC · original

Bisected on an RTX 4080 16 GB (Ryzen 9 7900X, 32 GB RAM, Windows 11). The regression comes from PR #23 (b68e65e08, with its follow-up ce42cc74b), merged in 79fac1a. It is not the eval/coolfox merge: 79fac1a comes before that merge on main and is already slow.

Setup. diag builds, Series X profile, play.ps1's default set plus VICTORY_BURY_LAG=0 (#48 is not merged yet). The cell window in the first room, scripted Enter presses, warm shader caches.

tree ms/frame median heap-view pass: looking at slots / waited for at lists' close list calls, thread time per frame
0a43566 132 14 / 3 ms 360-420 ms
9c23e8d 132 10 / 2.5 ms —
79fac1a (the PR triage merge) 266 64 / 41 ms —
0dec5dc 268 67 / 61 ms 1,800-2,150 ms
0dec5dc, VICTORY_SYNC_IN_PLACE=0 275 50 / 31 ms 1,780 ms
0dec5dc, #24 (888bf1e) reverted 279 76 / 52 ms 1,860 ms
0dec5dc, #23 (b68e65e + ce42cc7) reverted 139 12 / 8 ms 314 ms

What changes. On this card the view heap has no raw twins (raw_twins=false). With #23, every untyped structured view whose start is on an element but not on 16 bytes gets a copy of its own bytes (shadow::exact). The log's buffer views off their copy's elements line shows it. Before: about 1 view asked a frame, 0.4 copies made, ~240 kept. After: ~2,800 asked a frame, 410-430 copies made a frame, 2,350-2,740 kept. The pass over the heap's views then takes 64-67 ms a frame instead of 10-14, and the list-call threads wait for it at every list's close. That is why the frame lines don't account for the time. The submitting thread waits only 25-41 ms a frame, and the card is idle about 160 ms a frame "while the title had not submitted". That matches what #221 describes.

What I did not check. #23 fixes raw reads of zero through such views on NVIDIA. My revert run had no captures. In this scene, 0a43566 (which never had #23) shows the cell, walls and character right. So a cheaper form of #23 seems better than a revert. Two possible forms, untested: keep each view's own-bytes copy across frames instead of making ~420 new ones a frame, or take the copy only for views whose shaders actually read them raw at that offset.

One run per row. Runs differ by about ±10 ms on this machine, which is small next to a 130 ms gap. The bisect points are first-parent merges of main. Inside 79fac1a only #23 was reverted.

No game files or images attached. The runs were driven and this was written AI-assisted (Claude Code).

**@⁠pr0vId3nce** on GitHub · 2026-11-26 12:29 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7192060968) Bisected on an **RTX 4080 16 GB** (Ryzen 9 7900X, 32 GB RAM, Windows 11). The regression comes from **PR #23** (`b68e65e08`, with its follow-up `ce42cc74b`), merged in `79fac1a`. It is not the eval/coolfox merge: `79fac1a` comes before that merge on main and is already slow. **Setup.** `diag` builds, Series X profile, `play.ps1`'s default set plus `VICTORY_BURY_LAG=0` (#48 is not merged yet). The cell window in the first room, scripted Enter presses, warm shader caches. | tree | ms/frame median | heap-view pass: looking at slots / waited for at lists' close | list calls, thread time per frame | |---|---:|---|---:| | `0a43566` | 132 | 14 / 3 ms | 360-420 ms | | `9c23e8d` | 132 | 10 / 2.5 ms | — | | `79fac1a` (the PR triage merge) | **266** | 64 / 41 ms | — | | `0dec5dc` | **268** | 67 / 61 ms | 1,800-2,150 ms | | `0dec5dc`, `VICTORY_SYNC_IN_PLACE=0` | 275 | 50 / 31 ms | 1,780 ms | | `0dec5dc`, #24 (`888bf1e`) reverted | 279 | 76 / 52 ms | 1,860 ms | | **`0dec5dc`, #23 (`b68e65e` + `ce42cc7`) reverted** | **139** | 12 / 8 ms | 314 ms | **What changes.** On this card the view heap has no raw twins (`raw_twins=false`). With #23, every untyped structured view whose start is on an element but not on 16 bytes gets a copy of its own bytes (`shadow::exact`). The log's `buffer views off their copy's elements` line shows it. Before: about 1 view asked a frame, 0.4 copies made, ~240 kept. After: **~2,800 asked a frame, 410-430 copies made a frame, 2,350-2,740 kept**. The pass over the heap's views then takes 64-67 ms a frame instead of 10-14, and the list-call threads wait for it at every list's close. That is why the frame lines don't account for the time. The submitting thread waits only 25-41 ms a frame, and the card is idle about 160 ms a frame "while the title had not submitted". That matches what #221 describes. **What I did not check.** #23 fixes raw reads of zero through such views on NVIDIA. My revert run had no captures. In this scene, `0a43566` (which never had #23) shows the cell, walls and character right. So a cheaper form of #23 seems better than a revert. Two possible forms, untested: keep each view's own-bytes copy across frames instead of making ~420 new ones a frame, or take the copy only for views whose shaders actually read them raw at that offset. One run per row. Runs differ by about ±10 ms on this machine, which is small next to a 130 ms gap. The bisect points are first-parent merges of main. Inside `79fac1a` only #23 was reverted. No game files or images attached. The runs were driven and this was written AI-assisted (Claude Code).
Author
Owner

@⁠Key-rs on GitHub · 2026-11-26 12:55 UTC · original

You are right that a revert is not the answer, and the numbers match what we see on an 8 GB card — thank you for finding it, that is a much better bisect than my guess at the cool_fox merge.

Our side, for the record (Ryzen 7 8845H, RTX 4060 Laptop 8 GB, 31 GB RAM, driver 621.40; --profile diag, play.ps1 -Safe + VICTORY_THIN=1, shaders and pipelines warmed per tree):

tree frame fps draws
249fe0 198-212 ms 5.0 5,065-5,292
722c0e1 680-1,728 ms 1-2 2,864-7,164
722c0e1 + VICTORY_PLANES=0 419-540 ms 2-3 3,704-5,715
␀dec5dc + VICTORY_OUTPUT=1920x1080 310-528 ms 2-3 4,791-5,926

So the same shape, and VICTORY_PLANES=0 buying only part of it is consistent with #23 rather than the compose merge: the compose switch removed ~260 ms of our 680, and the rest is the heap-view pass you describe.

The counter you name is in our captures too, and it is the one that made me file the report without knowing what it meant:

buffer views left null as the host would refuse them: 0 (358,381 copies made of views off their buffer's elements)

358 k cumulative in a few minutes of running, against the 0.4 a frame the tree had before #23. I had read that line as "views we work around", not "views we duplicate", which is why the frame accounting made no sense to me.

On the two cheaper forms you list, from someone who only watches from the outside: keeping each view's own-bytes copy across frames sounds like the better of the two for this title, because the set of views a frame asks about looks stable within a scene — our log shows the same 2.0 twin copies a frame into depth textures across minutes, so the identity of the interesting views is not what changes. The "only for views whose shaders read raw at that offset" form needs to know which shader reads which offset, which the translate step may already have (descriptor read only as data is a reason our translator refuses 195 shaders; the ones it accepts with raw reads must be recorded somewhere).

If it helps: I can run any candidate through the same 9-minute harness on the 4060 and report frame ms, draws, the iews off their buffer's elements count and the heap-view pass time, so you get a second card per attempt.

**@⁠Key-rs** on GitHub · 2026-11-26 12:55 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7192644641) You are right that a revert is not the answer, and the numbers match what we see on an 8 GB card — thank you for finding it, that is a much better bisect than my guess at the cool_fox merge. **Our side, for the record** (Ryzen 7 8845H, RTX 4060 Laptop 8 GB, 31 GB RAM, driver 621.40; --profile diag, play.ps1 -Safe + VICTORY_THIN=1, shaders and pipelines warmed per tree): | tree | frame | fps | draws | |---|---|---|---| | 249fe0 | 198-212 ms | 5.0 | 5,065-5,292 | | 722c0e1 | 680-1,728 ms | 1-2 | 2,864-7,164 | | 722c0e1 + VICTORY_PLANES=0 | 419-540 ms | 2-3 | 3,704-5,715 | | ␀dec5dc + VICTORY_OUTPUT=1920x1080 | 310-528 ms | 2-3 | 4,791-5,926 | So the same shape, and VICTORY_PLANES=0 buying only part of it is consistent with #23 rather than the compose merge: the compose switch removed ~260 ms of our 680, and the rest is the heap-view pass you describe. **The counter you name is in our captures too**, and it is the one that made me file the report without knowing what it meant: ` buffer views left null as the host would refuse them: 0 (358,381 copies made of views off their buffer's elements) ` 358 k cumulative in a few minutes of running, against the 0.4 a frame the tree had before #23. I had read that line as "views we work around", not "views we duplicate", which is why the frame accounting made no sense to me. **On the two cheaper forms you list**, from someone who only watches from the outside: keeping each view's own-bytes copy across frames sounds like the better of the two for this title, because the set of views a frame asks about looks stable within a scene — our log shows the same 2.0 twin copies a frame into depth textures across minutes, so the identity of the interesting views is not what changes. The "only for views whose shaders read raw at that offset" form needs to know which shader reads which offset, which the translate step may already have (descriptor read only as data is a reason our translator refuses 195 shaders; the ones it accepts with raw reads must be recorded somewhere). If it helps: I can run any candidate through the same 9-minute harness on the 4060 and report frame ms, draws, the iews off their buffer's elements count and the heap-view pass time, so you get a second card per attempt.
Author
Owner

@⁠Key-rs on GitHub · 2026-11-26 15:59 UTC · original

Second card, as promised, and the answer is not the one I hoped for: on 8 GB of VRAM the newest tree (c9c932c) is still slower than 249fe0, and the reason looks like memory, not code.

Same harness as before (Ryzen 7 8845H, RTX 4060 Laptop 8 GB, 31 GB RAM, driver 621.40, --profile diag, play.ps1 -Safe + VICTORY_THIN=1, shaders cached, 2,981 pipelines warmed, real key presses):

tree frame fps draws preparing copies copying back
** 249fe0** 198-212 ms 5.0 5,065-5,292 160-190 ms 27-47 ms ~19 MB
c9c932c (ports 5+6+7) 312-548 ms 2-3 5,101-5,146 158-178 ms 28-33 ms 38-40 MB, 80-85 ms

The two lines worth comparing at the same draw count (~5,100):

f249fe0: 3.0 fps, 331 ms → preparing 178.2, copies 33.2 ms 86.9 MB, copy-back 84.8 ms 39.6 MB

More precisely, the shape of the newest tree on this card:

  • preparing is fine — 158-178 ms, copies 28-33 ms, extures 3-4 ms. The ports do what they say: the fills and uploads are gone.
  • copying back doubles, 19 MB → 38-40 MB a frame, 80-85 ms.
  • ~85 ms is still not in any counter at the end (331 - 178 - 85).

38-40 MB a frame of copy-back, and a README that says 10.5 GB of VRAM, on a card with 8 GB, reads like the same memory story from the other side: with less room, more of what the ports keep resident has to come back through the host, and the saves the ports make are paid for in reads.

So on this card the ranking is: 249fe0 5 fps, c9c932c 3 fps, 722c0e1 1-2 fps. Two different limits pull in opposite directions: the newer trees want VRAM, and I do not have it.

What would help me test the ports properly: a switch that keeps the ports' residency small (the VICTORY_CARD_BUFFERS_MB/MIN_MB pair does that for card buffers; is there an equivalent for the constants heap and the descriptor mirroring from ports 1 and 2?). With that I could tell you whether ports 5/6/7 are a win when given 8 GB to live in, instead of measuring my card's shortage.

I am leaving the machine on 249fe0 + LTO, which is 5 fps / 198-212 ms here, and will re-run any commit you name the same way.

**@⁠Key-rs** on GitHub · 2026-11-26 15:59 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7197041392) Second card, as promised, and the answer is not the one I hoped for: **on 8 GB of VRAM the newest tree (c9c932c) is still slower than 249fe0, and the reason looks like memory, not code.** Same harness as before (Ryzen 7 8845H, RTX 4060 Laptop **8 GB**, 31 GB RAM, driver 621.40, --profile diag, play.ps1 -Safe + VICTORY_THIN=1, shaders cached, 2,981 pipelines warmed, real key presses): | tree | frame | fps | draws | preparing | copies | **copying back** | |---|---|---|---|---|---|---| | ** 249fe0** | **198-212 ms** | **5.0** | 5,065-5,292 | 160-190 ms | 27-47 ms | **~19 MB** | | c9c932c (ports 5+6+7) | 312-548 ms | 2-3 | 5,101-5,146 | 158-178 ms | 28-33 ms | **38-40 MB, 80-85 ms** | The two lines worth comparing at the same draw count (~5,100): ` f249fe0: 3.0 fps, 331 ms → preparing 178.2, copies 33.2 ms 86.9 MB, copy-back 84.8 ms 39.6 MB ` More precisely, the shape of the newest tree on this card: * **preparing is fine** — 158-178 ms, copies 28-33 ms, extures 3-4 ms. The ports do what they say: the fills and uploads are gone. * **copying back doubles**, 19 MB → 38-40 MB a frame, 80-85 ms. * **~85 ms is still not in any counter** at the end (331 - 178 - 85). 38-40 MB a frame of copy-back, and a README that says 10.5 GB of VRAM, on a card with 8 GB, reads like the same memory story from the other side: with less room, more of what the ports keep resident has to come back through the host, and the saves the ports make are paid for in reads. **So on this card the ranking is:** 249fe0 5 fps, c9c932c 3 fps, 722c0e1 1-2 fps. Two different limits pull in opposite directions: the newer trees want VRAM, and I do not have it. **What would help me test the ports properly**: a switch that keeps the ports' residency small (the VICTORY_CARD_BUFFERS_MB/MIN_MB pair does that for card buffers; is there an equivalent for the constants heap and the descriptor mirroring from ports 1 and 2?). With that I could tell you whether ports 5/6/7 are a win when given 8 GB to live in, instead of measuring my card's shortage. I am leaving the machine on 249fe0 + LTO, which is 5 fps / 198-212 ms here, and will re-run any commit you name the same way.
Author
Owner

@⁠pr0vId3nce on GitHub · 2026-11-26 18:39 UTC · original

A fix for this, as a patch on main 2de998014 (one commit, git am applies it). @⁠Key-rs, it would be good to see it on the 8 GB 4060 too.

It removes the NVIDIA slowdown from #23 and keeps #23's fix.

Cause. On a heap without raw twins, #23 gives every untyped structured view that starts off 16 bytes a copy of its own bytes (shadow::exact). The title's ring views move every frame. In the prologue on an RTX 4080 that is ~2,800 askings and ~410 new copies a frame, with ~2,500 kept, most of them held by lists. Two things made that expensive, both inside the global EXACT lock that every recording thread takes:

  1. A new buffer per copy. shared_buffer creates a committed resource, makes it resident and maps it. That took ~1.2 ms each, ~500 ms of thread time a frame.
  2. A full scan of the map at every miss once it held 256 copies. Each entry costs a driver call (references, an AddRef/Release pair), and almost nothing could be let go because lists hold the copies.

Change (one file, crates/victory-gpu/src/shadow.rs):

  • Pooled buffers. When a copy is let go and nothing else holds its buffer, the buffer is kept by size, still mapped, for the next copy of that size (at most 4,096 buffers and 128 MiB, smallest kept first). That is the condition under which they were dropped before. A copy made on a kept buffer starts with no page copied, so its first refresh writes all of it, and the bytes past its length are zeroed.
  • No buffer made under the lock. If another thread made the same copy meanwhile, that one is used.
  • Cheaper scans. The map is looked through for idle copies after 512 more copies instead of at every miss, with the cheap tests first. Copies let go are dropped after the lock is released.
  • Frame line. It now also says how many copies were made on a kept buffer, the pool's size, and the time spent waiting for the lock and making or taking buffers.

Measured on an RTX 4080 16 GB (Ryzen 9 7900X, 32 GB RAM, Windows 11). diag builds, Series X profile, play.ps1's default set plus VICTORY_BURY_LAG=0 (#48 is not merged yet), prologue checkpoint at the cell window, warm caches, median ms/frame of the 5-second frame lines:

build window ms/frame heap-view pass: looking / waited at lists' close list-call thread time copies made a frame (on a kept buffer)
c9c932c (main) 250-330 s 276 67 / 61 ms ~1,900 ms ~420 (—)
c9c932c with #23 reverted 250-330 s 140 11 / 0 ms 314 ms 0
this PR 250-450 s 142 12 / 0.7 ms 398 ms 412 (412)

Making copies takes 1.5 ms a frame of thread time instead of ~500. The lock is waited for ~6 ms a frame in all, across the recording threads. The first minutes after the world appears settle more slowly than with #23 reverted (150-165 ms until ~290 s, then 135-150). One run each. Runs differ by about ±10 ms on this machine.

#23's case still holds. On the RTX 4080 (no raw twins), views_off_their_elements_get_a_copy_of_their_bytes passes. It prints "the structured slot without a raw twin uses a view-relative copy". So do views_off_their_elements_are_told, a_structured_view_made_raw_passes_the_host_check and raw_twins_show_the_views_bytes. A new test, own_bytes_copies_held_stay_and_idle_ones_go, checks that copies a list holds survive the scans and idle ones still go. In the game the cell, character and yard draw as before. With raw twins (AMD) far fewer views take this path, so it runs much less often there. I have not run AMD.

Not in this PR. cargo clippy -p victory-gpu --all-targets -- -D warnings reports one error that is already on main (watch.rs:3626, unnecessary_mut_passed). Nothing else is reported.

Run on the user's machine and written AI-assisted (Claude Code). No game files attached.

Patch (crates/victory-gpu/src/shadow.rs)
From a81cef8af1afe7215a0947d4f9aec59fbee2446e Mon Sep 17 00:00:00 2001
From: pr0vId3nce <[email protected]>
Date: Thu, 26 Nov 2026 13:08:40 -0500
Subject: [PATCH] Own-bytes copies: pooled buffers, made outside the lock, idle
 ones looked for every 512 (#221)

PR #23 gives every untyped structured view that starts off 16 bytes a copy of its own bytes
(`shadow::exact`) where the heap has no raw twins (NVIDIA's 1,000,000-view heaps; with twins far
fewer views take this path). The title's ring views move every frame, so in the prologue on an
RTX 4080 that is ~2,800 askings and ~410 new copies a frame, with ~2,500 kept, most held by lists:

- a buffer made anew for each (committed, made resident, mapped) took ~1.2 ms of the recording
  thread, under the global lock every other recording thread waited for;
- each miss went through the whole map for idle copies, asking the driver's object for its
  reference count each time.

Now buffers of copies let go (no list holds the copy, nothing else holds the buffer: when they
were dropped before) are kept by size, mapped, for the next copies (at most 4,096 buffers and
128 MiB, the smallest kept first); a copy made on one starts with no page copied, so its first
refresh writes all of it, and the bytes past its length are zeroed. Buffers are made without the
lock; the map is looked through after 512 more copies, the cheap tests first. The frame line
gives copies made on a kept buffer, the pool's size, and the time waiting and making.

RTX 4080, prologue, Series X, play.ps1 + VICTORY_BURY_LAG=0, median ms/frame:
c9c932c 276; c9c932c with #23 reverted 140; with this 142 (250-450 s); heap-view pass 67 -> 12 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 crates/victory-gpu/src/shadow.rs | 181 ++++++++++++++++++++++++++++---
 1 file changed, 168 insertions(+), 13 deletions(-)

diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs
index 87eebbccc..e24a08be4 100644
--- a/crates/victory-gpu/src/shadow.rs
+++ b/crates/victory-gpu/src/shadow.rs
@@ -5618,8 +5618,13 @@ fn loose(address: u64, end: u64, unsized_ask: bool, any: bool) -> Option<Arc<Sha
 #[allow(clippy::type_complexity)]
 static EXACT: Mutex<(u64, BTreeMap<(u64, u64), (Arc<Shadow>, u64)>)> = Mutex::new((0, BTreeMap::new()));
 
-/// Since the last frame line: askings for such copies, and copies made.
-static EXACT_STATS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
+/// The number of such copies at which [`exact`] next looks for idle ones.
+static EXACT_TRIM_AT: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
+
+/// Since the last frame line: askings for such copies, copies made, and
+/// nanoseconds waiting for the lock and making copies, and copies made on a
+/// buffer of the pool.
+static EXACT_STATS: [AtomicU64; 5] = [const { AtomicU64::new(0) }; 5];
 
 /// A copy of the title memory `[address, address + len)` that starts at
 /// `address` itself: for a buffer view whose bytes do not start on an
@@ -5648,7 +5653,9 @@ pub(crate) fn exact(address: u64, len: u64) -> Option<Arc<Shadow>> {
         return None;
     }
     EXACT_STATS[0].fetch_add(1, Ordering::Relaxed);
+    let asked = std::time::Instant::now();
     let mut guard = EXACT.lock().unwrap_or_else(|e| e.into_inner());
+    EXACT_STATS[2].fetch_add(asked.elapsed().as_nanos() as u64, Ordering::Relaxed);
     let (tick, map) = &mut *guard;
     *tick += 1;
     let now = *tick;
@@ -5657,24 +5664,122 @@ pub(crate) fn exact(address: u64, len: u64) -> Option<Arc<Shadow>> {
         shadow.used.store(crate::host::moment(), Ordering::Relaxed);
         return Some(shadow.clone());
     }
-    if map.len() >= MANY {
+    // Copies let go here are dropped once the lock is let go.
+    let mut gone = Vec::new();
+    if map.len() >= EXACT_TRIM_AT.load(Ordering::Relaxed).max(MANY) {
         // Held by the map alone (no list), its buffer by the copy alone (no
-        // slot shows it), and not asked for lately.
-        map.retain(|_, (shadow, used)| {
-            Arc::strong_count(shadow) > 1 || crate::host::references(&shadow.buffer) > 1 || *used + LATELY > now
-        });
-    }
-    let (buffer, data) = host()?.shared_buffer(len.next_multiple_of(256))?;
-    crate::host::name(&buffer, || format!("title view {address:#x}+{len:#x}"));
+        // slot shows it), and not asked for lately. The cheap tests first:
+        // `references` is a call into the driver's object.
+        let idle: Vec<(u64, u64)> = map
+            .iter()
+            .filter(|(_, (shadow, used))| {
+                *used + LATELY <= now
+                    && Arc::strong_count(shadow) == 1
+                    && crate::host::references(&shadow.buffer) <= 1
+            })
+            .map(|(key, _)| *key)
+            .collect();
+        gone.extend(idle.iter().filter_map(|key| map.remove(key)));
+        // Looked through again after 512 more copies, not at every miss:
+        // where most copies are held by lists (ring views on a host with no
+        // raw twins, ~2,500 of them), a look at every miss went through all
+        // of them each time, under this lock.
+        EXACT_TRIM_AT.store(map.len() + 512, Ordering::Relaxed);
+    }
+    // The buffer is made without the lock: ~400 a frame on such a host,
+    // and every thread recording a list waited behind each one.
+    drop(guard);
+    let size = len.next_multiple_of(256);
+    let making = std::time::Instant::now();
+    keep_buffers(gone);
+    let reused = EXACT_POOL.lock().unwrap_or_else(|e| e.into_inner()).get_mut(&size).and_then(Vec::pop);
+    let (buffer, data) = match reused {
+        Some((buffer, data)) => {
+            EXACT_STATS[4].fetch_add(1, Ordering::Relaxed);
+            EXACT_POOL_BYTES.fetch_sub(size, Ordering::Relaxed);
+            let data = data as *mut u8;
+            // The bytes past the view, up to the 256-byte size, as on a
+            // buffer made anew: zeros (the copy's refreshes write the rest).
+            // SAFETY: the buffer is mapped and `size` bytes long; nothing
+            // else holds it.
+            unsafe { std::ptr::write_bytes(data.add(len as usize), 0, (size - len) as usize) };
+            #[cfg(feature = "diagnostics")]
+            crate::host::name(&buffer, || format!("title view {address:#x}+{len:#x}"));
+            (buffer, data)
+        }
+        None => {
+            let (buffer, data) = host()?.shared_buffer(size)?;
+            crate::host::name(&buffer, || format!("title view {address:#x}+{len:#x}"));
+            (buffer, data)
+        }
+    };
     // SAFETY: a live buffer.
     let gpu = unsafe { buffer.GetGPUVirtualAddress() };
     let shadow = Arc::new(Shadow::new(buffer, data, gpu, address, len));
+    EXACT_STATS[3].fetch_add(making.elapsed().as_nanos() as u64, Ordering::Relaxed);
+    let mut guard = EXACT.lock().unwrap_or_else(|e| e.into_inner());
+    let (tick, map) = &mut *guard;
+    if let Some((other, used)) = map.get_mut(&(address, len)) {
+        // Another thread made one meanwhile: that one is the view's.
+        *used = *tick;
+        return Some(other.clone());
+    }
     map.insert((address, len), (shadow.clone(), now));
     EXACT_STATS[1].fetch_add(1, Ordering::Relaxed);
     OWN_MADE.fetch_add(1, Ordering::Relaxed);
     Some(shadow)
 }
 
+/// Buffers of copies [`exact`] let go, by size, mapped still, for the next
+/// copies of that size. On a host with no raw twins the views of the
+/// title's rings move every frame: ~420 copies a frame are made and as many
+/// let go, and a buffer made anew (committed, made resident, mapped) took
+/// ~1.2 ms of a recording thread each.
+#[allow(clippy::type_complexity)]
+static EXACT_POOL: Mutex<BTreeMap<u64, Vec<(ID3D12Resource, usize)>>> = Mutex::new(BTreeMap::new());
+
+/// Buffers kept in [`EXACT_POOL`] at most.
+const EXACT_POOL_MOST: usize = 4096;
+
+/// Their bytes at most: a copy may be up to 64 MiB, and these stay mapped
+/// in the PC's memory.
+const EXACT_POOL_MOST_BYTES: u64 = 128 << 20;
+
+/// Bytes of the buffers in [`EXACT_POOL`].
+static EXACT_POOL_BYTES: AtomicU64 = AtomicU64::new(0);
+
+/// Keeps the buffers of copies let go that nothing else holds: no list
+/// (the copy was the map's alone) and no slot (the buffer was the copy's
+/// alone), which is when they were let go before. A copy made on one starts
+/// with no page copied, so its first refresh writes all of it.
+fn keep_buffers(gone: Vec<(Arc<Shadow>, u64)>) {
+    let mut kept = Vec::new();
+    for (shadow, _) in gone {
+        let Ok(shadow) = Arc::try_unwrap(shadow) else { continue };
+        let buffer = shadow.buffer.clone();
+        let data = shadow.data as usize;
+        let size = shadow.len.next_multiple_of(256);
+        drop(shadow);
+        if crate::host::references(&buffer) == 1 {
+            kept.push((size, buffer, data));
+        }
+    }
+    if kept.is_empty() {
+        return;
+    }
+    // The small ones first: past either limit the largest are let go.
+    kept.sort_unstable_by_key(|k| k.0);
+    let mut pool = EXACT_POOL.lock().unwrap_or_else(|e| e.into_inner());
+    let room = EXACT_POOL_MOST.saturating_sub(pool.values().map(Vec::len).sum());
+    for (size, buffer, data) in kept.into_iter().take(room) {
+        if EXACT_POOL_BYTES.load(Ordering::Relaxed) + size > EXACT_POOL_MOST_BYTES {
+            break;
+        }
+        EXACT_POOL_BYTES.fetch_add(size, Ordering::Relaxed);
+        pool.entry(size).or_default().push((buffer, data));
+    }
+}
+
 /// Copies of single views' bytes made since the start.
 pub(crate) static OWN_MADE: AtomicU64 = AtomicU64::new(0);
 
@@ -5682,16 +5787,23 @@ pub(crate) static OWN_MADE: AtomicU64 = AtomicU64::new(0);
 /// bytes ([`exact`]), per frame over `frames`, and the copies kept now.
 /// Nothing while there are none.
 pub(crate) fn exact_line(frames: f64) {
-    let [asked, made] = [0, 1].map(|i| EXACT_STATS[i].swap(0, Ordering::Relaxed));
+    let [asked, made, waited, making, reused] = [0, 1, 2, 3, 4].map(|i| EXACT_STATS[i].swap(0, Ordering::Relaxed));
     if asked == 0 {
         return;
     }
     let kept = EXACT.lock().unwrap_or_else(|e| e.into_inner()).1.len();
+    let pooled = EXACT_POOL.lock().unwrap_or_else(|e| e.into_inner()).values().map(Vec::len).sum::<usize>();
     tracing::info!(
         "buffer views off their copy's elements (they were refused and read zeros; VICTORY_VIEW_BYTES=0 refuses them again): \
-         {:.1} asked for per frame, {:.1} copies of their own bytes made per frame, {kept} kept",
+         {:.1} asked for per frame, {:.1} copies of their own bytes made per frame ({:.1} on a buffer let go), {kept} kept, \
+         {pooled} buffers ({:.1} MB) kept for reuse; {:.1} ms a frame waiting for their lock, {:.1} ms a frame between it and \
+         the next (dropping copies let go, the pool's lock, making or taking a buffer; all threads)",
         asked as f64 / frames,
-        made as f64 / frames
+        made as f64 / frames,
+        reused as f64 / frames,
+        EXACT_POOL_BYTES.load(Ordering::Relaxed) as f64 / f64::from(1 << 20),
+        waited as f64 / 1e6 / frames,
+        making as f64 / 1e6 / frames
     );
 }
 
@@ -5885,3 +5997,46 @@ pub(crate) fn near(va: u64) -> String {
     }
     text
 }
+
+#[cfg(test)]
+mod exact_tests {
+    use super::{EXACT, EXACT_POOL_BYTES, EXACT_POOL_MOST_BYTES, exact};
+
+    /// The copies of title memory at `[start, start + span)` that [`exact`] keeps.
+    fn kept(start: u64, span: u64) -> usize {
+        let guard = EXACT.lock().unwrap_or_else(|e| e.into_inner());
+        guard.1.range((start, 0)..(start + span, 0)).count()
+    }
+
+    /// Copies a list still holds stay however often the map is looked
+    /// through; idle ones go at a later look (no longer at every miss).
+    #[test]
+    fn own_bytes_copies_held_stay_and_idle_ones_go() {
+        if crate::host::host().is_none() {
+            return; // no host GPU here
+        }
+        let memory = vec![0u32; 1 << 16];
+        let start = (memory.as_ptr() as u64).next_multiple_of(4096);
+        let span = 64 * 1024;
+        // 300 views 4 bytes apart, each held as a list would hold it.
+        let held: Vec<_> = (0..300).map(|i| exact(start + 4 * i, 64).expect("a copy")).collect();
+        assert_eq!(kept(start, span), 300);
+        // Many more asked for and let go at once: the held ones stay.
+        for i in 300..2_000 {
+            drop(exact(start + 4 * i, 64));
+        }
+        assert!(held.iter().all(|h| std::sync::Arc::strong_count(h) > 1), "held copies are still the map's");
+        let before = kept(start, span);
+        drop(held);
+        // Once nobody holds them, they go at a later look.
+        for i in 2_000..6_000 {
+            drop(exact(start + 4 * i, 64));
+        }
+        let after = kept(start, span);
+        assert!(after < before, "idle copies are let go ({before} -> {after})");
+        assert!(kept(start, 4 * 300) < 300, "the 300 copies once held went");
+        let pooled = EXACT_POOL_BYTES.load(std::sync::atomic::Ordering::Relaxed);
+        assert!(pooled <= EXACT_POOL_MOST_BYTES, "buffers kept for reuse stay under the cap ({pooled})");
+        drop(memory);
+    }
+}
-- 
2.55.0.windows.3


**@⁠pr0vId3nce** on GitHub · 2026-11-26 18:39 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7200700579) A fix for this, as a patch on `main` 2de998014 (one commit, `git am` applies it). @⁠Key-rs, it would be good to see it on the 8 GB 4060 too. It removes the NVIDIA slowdown from #23 and keeps #23's fix. **Cause.** On a heap without raw twins, #23 gives every untyped structured view that starts off 16 bytes a copy of its own bytes (`shadow::exact`). The title's ring views move every frame. In the prologue on an RTX 4080 that is ~2,800 askings and ~410 new copies a frame, with ~2,500 kept, most of them held by lists. Two things made that expensive, both inside the global `EXACT` lock that every recording thread takes: 1. **A new buffer per copy.** `shared_buffer` creates a committed resource, makes it resident and maps it. That took ~1.2 ms each, ~500 ms of thread time a frame. 2. **A full scan of the map at every miss** once it held 256 copies. Each entry costs a driver call (`references`, an AddRef/Release pair), and almost nothing could be let go because lists hold the copies. **Change** (one file, `crates/victory-gpu/src/shadow.rs`): - **Pooled buffers.** When a copy is let go and nothing else holds its buffer, the buffer is kept by size, still mapped, for the next copy of that size (at most 4,096 buffers and 128 MiB, smallest kept first). That is the condition under which they were dropped before. A copy made on a kept buffer starts with no page copied, so its first refresh writes all of it, and the bytes past its length are zeroed. - **No buffer made under the lock.** If another thread made the same copy meanwhile, that one is used. - **Cheaper scans.** The map is looked through for idle copies after 512 more copies instead of at every miss, with the cheap tests first. Copies let go are dropped after the lock is released. - **Frame line.** It now also says how many copies were made on a kept buffer, the pool's size, and the time spent waiting for the lock and making or taking buffers. **Measured** on an RTX 4080 16 GB (Ryzen 9 7900X, 32 GB RAM, Windows 11). `diag` builds, Series X profile, `play.ps1`'s default set plus `VICTORY_BURY_LAG=0` (#48 is not merged yet), prologue checkpoint at the cell window, warm caches, median ms/frame of the 5-second frame lines: | build | window | ms/frame | heap-view pass: looking / waited at lists' close | list-call thread time | copies made a frame (on a kept buffer) | |---|---|---:|---|---:|---| | `c9c932c` (main) | 250-330 s | 276 | 67 / 61 ms | ~1,900 ms | ~420 (—) | | `c9c932c` with #23 reverted | 250-330 s | 140 | 11 / 0 ms | 314 ms | 0 | | **this PR** | 250-450 s | **142** | 12 / 0.7 ms | 398 ms | 412 (412) | Making copies takes 1.5 ms a frame of thread time instead of ~500. The lock is waited for ~6 ms a frame in all, across the recording threads. The first minutes after the world appears settle more slowly than with #23 reverted (150-165 ms until ~290 s, then 135-150). One run each. Runs differ by about ±10 ms on this machine. **#23's case still holds.** On the RTX 4080 (no raw twins), `views_off_their_elements_get_a_copy_of_their_bytes` passes. It prints "the structured slot without a raw twin uses a view-relative copy". So do `views_off_their_elements_are_told`, `a_structured_view_made_raw_passes_the_host_check` and `raw_twins_show_the_views_bytes`. A new test, `own_bytes_copies_held_stay_and_idle_ones_go`, checks that copies a list holds survive the scans and idle ones still go. In the game the cell, character and yard draw as before. With raw twins (AMD) far fewer views take this path, so it runs much less often there. I have not run AMD. **Not in this PR.** `cargo clippy -p victory-gpu --all-targets -- -D warnings` reports one error that is already on main (`watch.rs:3626`, `unnecessary_mut_passed`). Nothing else is reported. Run on the user's machine and written AI-assisted (Claude Code). No game files attached. <details><summary>Patch (crates/victory-gpu/src/shadow.rs)</summary> ```diff From a81cef8af1afe7215a0947d4f9aec59fbee2446e Mon Sep 17 00:00:00 2001 From: pr0vId3nce <148384071+[email protected]> Date: Thu, 26 Nov 2026 13:08:40 -0500 Subject: [PATCH] Own-bytes copies: pooled buffers, made outside the lock, idle ones looked for every 512 (#221) PR #23 gives every untyped structured view that starts off 16 bytes a copy of its own bytes (`shadow::exact`) where the heap has no raw twins (NVIDIA's 1,000,000-view heaps; with twins far fewer views take this path). The title's ring views move every frame, so in the prologue on an RTX 4080 that is ~2,800 askings and ~410 new copies a frame, with ~2,500 kept, most held by lists: - a buffer made anew for each (committed, made resident, mapped) took ~1.2 ms of the recording thread, under the global lock every other recording thread waited for; - each miss went through the whole map for idle copies, asking the driver's object for its reference count each time. Now buffers of copies let go (no list holds the copy, nothing else holds the buffer: when they were dropped before) are kept by size, mapped, for the next copies (at most 4,096 buffers and 128 MiB, the smallest kept first); a copy made on one starts with no page copied, so its first refresh writes all of it, and the bytes past its length are zeroed. Buffers are made without the lock; the map is looked through after 512 more copies, the cheap tests first. The frame line gives copies made on a kept buffer, the pool's size, and the time waiting and making. RTX 4080, prologue, Series X, play.ps1 + VICTORY_BURY_LAG=0, median ms/frame: c9c932c 276; c9c932c with #23 reverted 140; with this 142 (250-450 s); heap-view pass 67 -> 12 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- crates/victory-gpu/src/shadow.rs | 181 ++++++++++++++++++++++++++++--- 1 file changed, 168 insertions(+), 13 deletions(-) diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs index 87eebbccc..e24a08be4 100644 --- a/crates/victory-gpu/src/shadow.rs +++ b/crates/victory-gpu/src/shadow.rs @@ -5618,8 +5618,13 @@ fn loose(address: u64, end: u64, unsized_ask: bool, any: bool) -> Option<Arc<Sha #[allow(clippy::type_complexity)] static EXACT: Mutex<(u64, BTreeMap<(u64, u64), (Arc<Shadow>, u64)>)> = Mutex::new((0, BTreeMap::new())); -/// Since the last frame line: askings for such copies, and copies made. -static EXACT_STATS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; +/// The number of such copies at which [`exact`] next looks for idle ones. +static EXACT_TRIM_AT: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + +/// Since the last frame line: askings for such copies, copies made, and +/// nanoseconds waiting for the lock and making copies, and copies made on a +/// buffer of the pool. +static EXACT_STATS: [AtomicU64; 5] = [const { AtomicU64::new(0) }; 5]; /// A copy of the title memory `[address, address + len)` that starts at /// `address` itself: for a buffer view whose bytes do not start on an @@ -5648,7 +5653,9 @@ pub(crate) fn exact(address: u64, len: u64) -> Option<Arc<Shadow>> { return None; } EXACT_STATS[0].fetch_add(1, Ordering::Relaxed); + let asked = std::time::Instant::now(); let mut guard = EXACT.lock().unwrap_or_else(|e| e.into_inner()); + EXACT_STATS[2].fetch_add(asked.elapsed().as_nanos() as u64, Ordering::Relaxed); let (tick, map) = &mut *guard; *tick += 1; let now = *tick; @@ -5657,24 +5664,122 @@ pub(crate) fn exact(address: u64, len: u64) -> Option<Arc<Shadow>> { shadow.used.store(crate::host::moment(), Ordering::Relaxed); return Some(shadow.clone()); } - if map.len() >= MANY { + // Copies let go here are dropped once the lock is let go. + let mut gone = Vec::new(); + if map.len() >= EXACT_TRIM_AT.load(Ordering::Relaxed).max(MANY) { // Held by the map alone (no list), its buffer by the copy alone (no - // slot shows it), and not asked for lately. - map.retain(|_, (shadow, used)| { - Arc::strong_count(shadow) > 1 || crate::host::references(&shadow.buffer) > 1 || *used + LATELY > now - }); - } - let (buffer, data) = host()?.shared_buffer(len.next_multiple_of(256))?; - crate::host::name(&buffer, || format!("title view {address:#x}+{len:#x}")); + // slot shows it), and not asked for lately. The cheap tests first: + // `references` is a call into the driver's object. + let idle: Vec<(u64, u64)> = map + .iter() + .filter(|(_, (shadow, used))| { + *used + LATELY <= now + && Arc::strong_count(shadow) == 1 + && crate::host::references(&shadow.buffer) <= 1 + }) + .map(|(key, _)| *key) + .collect(); + gone.extend(idle.iter().filter_map(|key| map.remove(key))); + // Looked through again after 512 more copies, not at every miss: + // where most copies are held by lists (ring views on a host with no + // raw twins, ~2,500 of them), a look at every miss went through all + // of them each time, under this lock. + EXACT_TRIM_AT.store(map.len() + 512, Ordering::Relaxed); + } + // The buffer is made without the lock: ~400 a frame on such a host, + // and every thread recording a list waited behind each one. + drop(guard); + let size = len.next_multiple_of(256); + let making = std::time::Instant::now(); + keep_buffers(gone); + let reused = EXACT_POOL.lock().unwrap_or_else(|e| e.into_inner()).get_mut(&size).and_then(Vec::pop); + let (buffer, data) = match reused { + Some((buffer, data)) => { + EXACT_STATS[4].fetch_add(1, Ordering::Relaxed); + EXACT_POOL_BYTES.fetch_sub(size, Ordering::Relaxed); + let data = data as *mut u8; + // The bytes past the view, up to the 256-byte size, as on a + // buffer made anew: zeros (the copy's refreshes write the rest). + // SAFETY: the buffer is mapped and `size` bytes long; nothing + // else holds it. + unsafe { std::ptr::write_bytes(data.add(len as usize), 0, (size - len) as usize) }; + #[cfg(feature = "diagnostics")] + crate::host::name(&buffer, || format!("title view {address:#x}+{len:#x}")); + (buffer, data) + } + None => { + let (buffer, data) = host()?.shared_buffer(size)?; + crate::host::name(&buffer, || format!("title view {address:#x}+{len:#x}")); + (buffer, data) + } + }; // SAFETY: a live buffer. let gpu = unsafe { buffer.GetGPUVirtualAddress() }; let shadow = Arc::new(Shadow::new(buffer, data, gpu, address, len)); + EXACT_STATS[3].fetch_add(making.elapsed().as_nanos() as u64, Ordering::Relaxed); + let mut guard = EXACT.lock().unwrap_or_else(|e| e.into_inner()); + let (tick, map) = &mut *guard; + if let Some((other, used)) = map.get_mut(&(address, len)) { + // Another thread made one meanwhile: that one is the view's. + *used = *tick; + return Some(other.clone()); + } map.insert((address, len), (shadow.clone(), now)); EXACT_STATS[1].fetch_add(1, Ordering::Relaxed); OWN_MADE.fetch_add(1, Ordering::Relaxed); Some(shadow) } +/// Buffers of copies [`exact`] let go, by size, mapped still, for the next +/// copies of that size. On a host with no raw twins the views of the +/// title's rings move every frame: ~420 copies a frame are made and as many +/// let go, and a buffer made anew (committed, made resident, mapped) took +/// ~1.2 ms of a recording thread each. +#[allow(clippy::type_complexity)] +static EXACT_POOL: Mutex<BTreeMap<u64, Vec<(ID3D12Resource, usize)>>> = Mutex::new(BTreeMap::new()); + +/// Buffers kept in [`EXACT_POOL`] at most. +const EXACT_POOL_MOST: usize = 4096; + +/// Their bytes at most: a copy may be up to 64 MiB, and these stay mapped +/// in the PC's memory. +const EXACT_POOL_MOST_BYTES: u64 = 128 << 20; + +/// Bytes of the buffers in [`EXACT_POOL`]. +static EXACT_POOL_BYTES: AtomicU64 = AtomicU64::new(0); + +/// Keeps the buffers of copies let go that nothing else holds: no list +/// (the copy was the map's alone) and no slot (the buffer was the copy's +/// alone), which is when they were let go before. A copy made on one starts +/// with no page copied, so its first refresh writes all of it. +fn keep_buffers(gone: Vec<(Arc<Shadow>, u64)>) { + let mut kept = Vec::new(); + for (shadow, _) in gone { + let Ok(shadow) = Arc::try_unwrap(shadow) else { continue }; + let buffer = shadow.buffer.clone(); + let data = shadow.data as usize; + let size = shadow.len.next_multiple_of(256); + drop(shadow); + if crate::host::references(&buffer) == 1 { + kept.push((size, buffer, data)); + } + } + if kept.is_empty() { + return; + } + // The small ones first: past either limit the largest are let go. + kept.sort_unstable_by_key(|k| k.0); + let mut pool = EXACT_POOL.lock().unwrap_or_else(|e| e.into_inner()); + let room = EXACT_POOL_MOST.saturating_sub(pool.values().map(Vec::len).sum()); + for (size, buffer, data) in kept.into_iter().take(room) { + if EXACT_POOL_BYTES.load(Ordering::Relaxed) + size > EXACT_POOL_MOST_BYTES { + break; + } + EXACT_POOL_BYTES.fetch_add(size, Ordering::Relaxed); + pool.entry(size).or_default().push((buffer, data)); + } +} + /// Copies of single views' bytes made since the start. pub(crate) static OWN_MADE: AtomicU64 = AtomicU64::new(0); @@ -5682,16 +5787,23 @@ pub(crate) static OWN_MADE: AtomicU64 = AtomicU64::new(0); /// bytes ([`exact`]), per frame over `frames`, and the copies kept now. /// Nothing while there are none. pub(crate) fn exact_line(frames: f64) { - let [asked, made] = [0, 1].map(|i| EXACT_STATS[i].swap(0, Ordering::Relaxed)); + let [asked, made, waited, making, reused] = [0, 1, 2, 3, 4].map(|i| EXACT_STATS[i].swap(0, Ordering::Relaxed)); if asked == 0 { return; } let kept = EXACT.lock().unwrap_or_else(|e| e.into_inner()).1.len(); + let pooled = EXACT_POOL.lock().unwrap_or_else(|e| e.into_inner()).values().map(Vec::len).sum::<usize>(); tracing::info!( "buffer views off their copy's elements (they were refused and read zeros; VICTORY_VIEW_BYTES=0 refuses them again): \ - {:.1} asked for per frame, {:.1} copies of their own bytes made per frame, {kept} kept", + {:.1} asked for per frame, {:.1} copies of their own bytes made per frame ({:.1} on a buffer let go), {kept} kept, \ + {pooled} buffers ({:.1} MB) kept for reuse; {:.1} ms a frame waiting for their lock, {:.1} ms a frame between it and \ + the next (dropping copies let go, the pool's lock, making or taking a buffer; all threads)", asked as f64 / frames, - made as f64 / frames + made as f64 / frames, + reused as f64 / frames, + EXACT_POOL_BYTES.load(Ordering::Relaxed) as f64 / f64::from(1 << 20), + waited as f64 / 1e6 / frames, + making as f64 / 1e6 / frames ); } @@ -5885,3 +5997,46 @@ pub(crate) fn near(va: u64) -> String { } text } + +#[cfg(test)] +mod exact_tests { + use super::{EXACT, EXACT_POOL_BYTES, EXACT_POOL_MOST_BYTES, exact}; + + /// The copies of title memory at `[start, start + span)` that [`exact`] keeps. + fn kept(start: u64, span: u64) -> usize { + let guard = EXACT.lock().unwrap_or_else(|e| e.into_inner()); + guard.1.range((start, 0)..(start + span, 0)).count() + } + + /// Copies a list still holds stay however often the map is looked + /// through; idle ones go at a later look (no longer at every miss). + #[test] + fn own_bytes_copies_held_stay_and_idle_ones_go() { + if crate::host::host().is_none() { + return; // no host GPU here + } + let memory = vec![0u32; 1 << 16]; + let start = (memory.as_ptr() as u64).next_multiple_of(4096); + let span = 64 * 1024; + // 300 views 4 bytes apart, each held as a list would hold it. + let held: Vec<_> = (0..300).map(|i| exact(start + 4 * i, 64).expect("a copy")).collect(); + assert_eq!(kept(start, span), 300); + // Many more asked for and let go at once: the held ones stay. + for i in 300..2_000 { + drop(exact(start + 4 * i, 64)); + } + assert!(held.iter().all(|h| std::sync::Arc::strong_count(h) > 1), "held copies are still the map's"); + let before = kept(start, span); + drop(held); + // Once nobody holds them, they go at a later look. + for i in 2_000..6_000 { + drop(exact(start + 4 * i, 64)); + } + let after = kept(start, span); + assert!(after < before, "idle copies are let go ({before} -> {after})"); + assert!(kept(start, 4 * 300) < 300, "the 300 copies once held went"); + let pooled = EXACT_POOL_BYTES.load(std::sync::atomic::Ordering::Relaxed); + assert!(pooled <= EXACT_POOL_MOST_BYTES, "buffers kept for reuse stay under the cap ({pooled})"); + drop(memory); + } +} -- 2.55.0.windows.3 ``` </details>
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-26 20:15 UTC · original

An 8 GB data point for the pool, on an RTX 2070 SUPER 8 GB (Turing, driver 621.14; Ryzen 7 5800X, 32 GB RAM, Windows 11). Like the 4080, it has no raw twins here: the 2 x 2^21 heap is refused, so raw_twins=false.

Short version: with the pool, #23's copies cost about nothing here. Copies on (default) and copies off (VICTORY_VIEW_BYTES=0) are within noise of each other at the same draw count. Without the pool, on c9c932c, #23 cost about 87 ms a frame on this card.

Setup. diag build, Series X profile, play.ps1 defaults, warm caches (victory warm --used, 0 pipelines being made during the runs), standing still at the same spot in the world for about 3 minutes. The pool is your 67a50c6 and 835d4e8 from pr0vId3nce/VIctory-NVIDIA. It is not on plain main: it sits on a local branch of c9c932c with other merged upstream PRs and changes of my own that were switched off for these runs. Both runs below are the same build; only VICTORY_VIEW_BYTES differs. One run each.

The draw count on this build cycles by itself between about 3,300, 7,500 and 10,000 a frame even when standing still, and the frame time follows it. So I compare 5-second frame lines with about the same draw count:

~3,300 draws ~4,700 draws ms per 1,000 draws (median)
pool, copies on (default) 409 ms (8 lines) 635 ms (9 lines) 131
VICTORY_VIEW_BYTES=0 (copies off) 391 ms (12 lines) 651 ms (15 lines) 118

There are only a few lines per bin, so read differences of ±20 ms as noise.

The pool's frame line with copies on: 2,313 asked for a frame, 290 made, 289 of them on a kept buffer, 3,173 copies kept, 1,018 buffers (4.3 MB) in the pool, 1.4 ms a frame waiting for the lock and 5.5 ms making or taking buffers (all threads).

For comparison, before the pool on c9c932c (same card, same spot, steady ~3,740 draws a frame): default 318 ms median, VICTORY_VIEW_BYTES=0 231 ms, with ~180 copies made a frame.

I did not judge rendering in these runs, and I did not measure memory or VRAM separately.

I also tried a different approach on this card: no copies at all, with each view starting on the 16 bytes below and the shader adding the difference. It was slower than the pool (the shaders had to bind the per-slot table, which pulls in the heap-wide buffer pass) and caused visible glitches, so I've dropped it. The pool looks like the better fix.

Run on my machine and written with AI assistance (Claude Code). No game files attached.

**@⁠Jesper-Andersson** on GitHub · 2026-11-26 20:15 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7202467087) An 8 GB data point for the pool, on an RTX 2070 SUPER 8 GB (Turing, driver 621.14; Ryzen 7 5800X, 32 GB RAM, Windows 11). Like the 4080, it has no raw twins here: the 2 x 2^21 heap is refused, so `raw_twins=false`. **Short version:** with the pool, #23's copies cost about nothing here. Copies on (default) and copies off (`VICTORY_VIEW_BYTES=0`) are within noise of each other at the same draw count. Without the pool, on `c9c932c`, #23 cost about 87 ms a frame on this card. **Setup.** `diag` build, Series X profile, `play.ps1` defaults, warm caches (`victory warm --used`, 0 pipelines being made during the runs), standing still at the same spot in the world for about 3 minutes. The pool is your 67a50c6 and 835d4e8 from pr0vId3nce/VIctory-NVIDIA. It is not on plain `main`: it sits on a local branch of `c9c932c` with other merged upstream PRs and changes of my own that were switched off for these runs. Both runs below are the same build; only `VICTORY_VIEW_BYTES` differs. One run each. The draw count on this build cycles by itself between about 3,300, 7,500 and 10,000 a frame even when standing still, and the frame time follows it. So I compare 5-second frame lines with about the same draw count: | | ~3,300 draws | ~4,700 draws | ms per 1,000 draws (median) | |---|---:|---:|---:| | pool, copies on (default) | 409 ms (8 lines) | 635 ms (9 lines) | 131 | | `VICTORY_VIEW_BYTES=0` (copies off) | 391 ms (12 lines) | 651 ms (15 lines) | 118 | There are only a few lines per bin, so read differences of ±20 ms as noise. The pool's frame line with copies on: 2,313 asked for a frame, 290 made, 289 of them on a kept buffer, 3,173 copies kept, 1,018 buffers (4.3 MB) in the pool, 1.4 ms a frame waiting for the lock and 5.5 ms making or taking buffers (all threads). For comparison, before the pool on `c9c932c` (same card, same spot, steady ~3,740 draws a frame): default 318 ms median, `VICTORY_VIEW_BYTES=0` 231 ms, with ~180 copies made a frame. I did not judge rendering in these runs, and I did not measure memory or VRAM separately. I also tried a different approach on this card: no copies at all, with each view starting on the 16 bytes below and the shader adding the difference. It was slower than the pool (the shaders had to bind the per-slot table, which pulls in the heap-wide buffer pass) and caused visible glitches, so I've dropped it. The pool looks like the better fix. Run on my machine and written with AI assistance (Claude Code). No game files attached.
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-27 01:16 UTC · original

The pool on current main, same RTX 2070 SUPER 8 GB (driver 621.14; Ryzen 7 5800X, 32 GB RAM, Windows 11): pr0vId3nce's two commits (67a50c6, 835d4e8) still apply cleanly on 014d52d, and with them main's median frame falls from 288 to 121 ms here.

Setup: main 014d52d + #203 (DLSS), diag build, Series S + DLSS, play.ps1 settings plus VICTORY_CARD_BUFFERS_MIN_KB=64, CARD_BUFFERS_MB=1024, RESIDENCY=1, WIDE_MERGE=1, WINDOW_KB=1024, SUBMIT_FRAMES=2 and CARD_ROOM_FOR_TARGETS_MB=1280 (#407). The two builds differ only in the pool's two commits, both in shadow.rs. One run each, about two minutes in the world; the numbers are over the 5 s lines with at least 1,000 draws.

main main + pool
median frame 288 ms 121 ms
p90 529 ms 972 ms *
preparing, mean 71 ms 63 ms
draws a frame, mean 4,591 3,801

* The p90 isn't from the pool, as far as one more run shows: a third run, main + pool + a BC7 decoder fix (#412), had a median of 128 ms with p90 299 ms and longest 424 ms, at 4,851 draws a frame. The runs were in different spots, so the spikes are rough; the medians agree.

For scale: a local tree with this pool and about 50 other merged upstream PRs ran at 132 ms median with similar settings (its own launcher's, also Series S + DLSS), so on this card the pool is most of the gap between main and that tree.

Not checked: Series X, AMD, the pool without the card-buffer settings on 014d52d (my earlier numbers above were on c9c932c, Series X). With the card buffers at 1,024 MB the card went over its budget in 8 of 45 lines, which is #407's side, not the pool's.

There's no PR for the pool on this repo yet. @⁠pr0vId3nce, would you open one from your two commits? If you'd rather not, I can open one that ports them with your authorship.

This comment was written with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-11-27 01:16 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7207159722) The pool on current main, same RTX 2070 SUPER 8 GB (driver 621.14; Ryzen 7 5800X, 32 GB RAM, Windows 11): **pr0vId3nce's two commits (67a50c6, 835d4e8) still apply cleanly on `014d52d`, and with them main's median frame falls from 288 to 121 ms here.** Setup: main `014d52d` + #203 (DLSS), `diag` build, Series S + DLSS, `play.ps1` settings plus `VICTORY_CARD_BUFFERS_MIN_KB=64`, `CARD_BUFFERS_MB=1024`, `RESIDENCY=1`, `WIDE_MERGE=1`, `WINDOW_KB=1024`, `SUBMIT_FRAMES=2` and `CARD_ROOM_FOR_TARGETS_MB=1280` (#407). The two builds differ only in the pool's two commits, both in `shadow.rs`. One run each, about two minutes in the world; the numbers are over the 5 s lines with at least 1,000 draws. | | main | main + pool | |---|---|---| | median frame | 288 ms | **121 ms** | | p90 | 529 ms | 972 ms * | | preparing, mean | 71 ms | 63 ms | | draws a frame, mean | 4,591 | 3,801 | \* The p90 isn't from the pool, as far as one more run shows: a third run, main + pool + a BC7 decoder fix (#412), had a median of 128 ms with p90 299 ms and longest 424 ms, at 4,851 draws a frame. The runs were in different spots, so the spikes are rough; the medians agree. For scale: a local tree with this pool and about 50 other merged upstream PRs ran at 132 ms median with similar settings (its own launcher's, also Series S + DLSS), so on this card the pool is most of the gap between main and that tree. Not checked: Series X, AMD, the pool without the card-buffer settings on `014d52d` (my earlier numbers above were on `c9c932c`, Series X). With the card buffers at 1,024 MB the card went over its budget in 8 of 45 lines, which is #407's side, not the pool's. There's no PR for the pool on this repo yet. @⁠pr0vId3nce, would you open one from your two commits? If you'd rather not, I can open one that ports them with your authorship. This comment was written with AI assistance (Claude Code).
Author
Owner

@⁠Key-rs on GitHub · 2026-11-27 02:39 UTC · original

Same harness on the 8 GB card you asked for, and the pool does what you said on this one too.

Machine: Ryzen 7 8845H (8c/16t), RTX 4060 Laptop 8 GB, 31 GB RAM, Windows 11, driver 621.40. diag build, play.ps1 -Safe + VICTORY_THIN=1, shaders cached, 2,982 pipelines warmed, real key presses, 9-minute run.

I applied your patch on main = ␀14d52d (git am, clean, no conflicts) and built with lto = "thin" + codegen-units = 1 + -C target-cpu=native.

build (this machine) frame fps draws per draw
249fe0 (pre-port, my reference) 198-212 ms 5.0 5,065-5,292 40 µs
c9c932c (main, no pool) 338-358 ms 3.0 5,112-5,239 66 µs
␀14d52d + your pool 264-318 ms 3.6-4.0 6,470-8,278 41 µs

The draw count in the pool runs cycled up to 8,278 a frame on its own (the title decides), so I compare per draw: 66 µs → 41 µs, i.e. the whole regression and a little more, landing where 249fe0 was before ports 5/6/7 existed. That is the same result as your 142 vs 140 on the 4080, on a card with a third of the VRAM.

Frame line from the heaviest sample:

3.6 fps, 278.7 ms/frame (159.9 preparing: copies 37.4 ms 70.9 MB, textures 3.0 ms 3.1 MB; 87.4 on the GPU; 186.1 copying back 37.4 MB), 6,497 draws/frame

copying back is 173-188 ms for 37.5 MB in these scenes — that is my card's shortage showing (38 MB a frame against 249fe0's 19 MB at a third of the draws), not something the pool changed.

One thing to look at, and I cannot tell whether it is yours: in an interior (the cell block, camera behind the character) I see floating light patches beside a door and two ghosted rectangles low in the frame — the shape stale bytes would have. 249fe0 screenshots of the same place are not available to me to compare, and your notes say the light stand-in is approximate anyway, so it may be pre-existing. Worth a glance from someone who knows the scene: a kept buffer that starts with "no page copied" would show exactly this if the first refresh misses a range the shader later reads.

Rendering otherwise looks right: the jumpsuit lettering, the posters, the door glass and the sun through it.

**@⁠Key-rs** on GitHub · 2026-11-27 02:39 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7208321288) Same harness on the 8 GB card you asked for, and the pool does what you said on this one too. **Machine:** Ryzen 7 8845H (8c/16t), **RTX 4060 Laptop 8 GB**, 31 GB RAM, Windows 11, driver 621.40. diag build, play.ps1 -Safe + VICTORY_THIN=1, shaders cached, 2,982 pipelines warmed, real key presses, 9-minute run. I applied your patch on main = ␀14d52d (git am, clean, no conflicts) and built with lto = "thin" + codegen-units = 1 + -C target-cpu=native. | build (this machine) | frame | fps | draws | per draw | |---|---|---|---|---| | 249fe0 (pre-port, my reference) | 198-212 ms | 5.0 | 5,065-5,292 | **40 µs** | | c9c932c (main, no pool) | 338-358 ms | 3.0 | 5,112-5,239 | **66 µs** | | **␀14d52d + your pool** | **264-318 ms** | **3.6-4.0** | **6,470-8,278** | **41 µs** | The draw count in the pool runs cycled up to 8,278 a frame on its own (the title decides), so I compare per draw: **66 µs → 41 µs, i.e. the whole regression and a little more**, landing where 249fe0 was before ports 5/6/7 existed. That is the same result as your 142 vs 140 on the 4080, on a card with a third of the VRAM. Frame line from the heaviest sample: ` 3.6 fps, 278.7 ms/frame (159.9 preparing: copies 37.4 ms 70.9 MB, textures 3.0 ms 3.1 MB; 87.4 on the GPU; 186.1 copying back 37.4 MB), 6,497 draws/frame ` copying back is 173-188 ms for 37.5 MB in these scenes — that is my card's shortage showing (38 MB a frame against 249fe0's 19 MB at a third of the draws), not something the pool changed. **One thing to look at, and I cannot tell whether it is yours**: in an interior (the cell block, camera behind the character) I see **floating light patches beside a door and two ghosted rectangles low in the frame** — the shape stale bytes would have. 249fe0 screenshots of the same place are not available to me to compare, and your notes say the light stand-in is approximate anyway, so it may be pre-existing. Worth a glance from someone who knows the scene: a kept buffer that starts with "no page copied" would show exactly this if the first refresh misses a range the shader later reads. Rendering otherwise looks right: the jumpsuit lettering, the posters, the door glass and the sun through it.
Author
Owner

@⁠Key-rs on GitHub · 2026-11-27 03:03 UTC · original

Your pool patch does more than remove the regression on this card: with it, the renderer ports finally pay off on 8 GB, and this is now the fastest this machine has run.

Same harness (Ryzen 7 8845H, RTX 4060 Laptop 8 GB, 31 GB RAM, driver 621.40, diag build with lto = "thin", play.ps1 -Safe + VICTORY_THIN=1, warm caches, real key presses, 9-minute runs, one run per row):

build frame draws per draw fps
f249fe0 (my reference before ports 5/6/7) 198-212 ms 5,065-5,292 40 µs 5.0
c9c932c (main, no pool) 338-358 ms 5,112-5,239 68 µs 3.0
014d52d + your pool 264-318 ms 6,470-8,278 43 µs 3.6-4.0
+ VICTORY_OUTPUT=1920x1080, CARD_BUFFERS_MB=512, MIN_MB=1 321-341 ms 6,318 54 µs 2.9
+ the five port switches 133-140 ms 5,096-5,441 26 µs 7.1-7.5

The last row is VICTORY_PORT_CONSTANTS, PORT_DESCRIPTORS, PORT_CBV, PORT_GUARD and PORT_JOURNAL all on, with the output at 1080p and the card-buffer ceiling at 512 MB. Frame line at the best sample:

7.1 fps, 139.9 ms/frame (95.0 preparing: copies 19.0 ms 76.6 MB, textures 2.8 ms 6.6 MB;
                         6.1 on the GPU; 87.6 copying back 43.7 MB), 5,441 draws/frame

preparing fell from 160-220 ms to 95-110 ms and copies from 37-98 ms to 19-27 ms, against the same 76 MB of title memory — the ports doing what they say (no fills, no uploads, no slot scans) once the per-copy buffers stop being made anew every frame.

Two things about the ordering, because I had them backwards for a day:

  • The ports were net-negative here before the pool. c9c932c on this card was 3 fps against f249fe0's 5, and I said so in #221. Your patch changes the sign: the ports' savings only show once a copy stops costing 1.2 ms.
  • 1080p output alone did nothing (row 4 is slower per draw than row 3 on my runs, and the scenes differed, so read that as noise). It only helps in combination, where it holds copy-back at 43-50 MB instead of letting it grow with the 4K back buffer.

Rendering: the corridor and cell-block scenes look right — guard, inmate, gate, the painted floor, the poster wall. On the earlier pool-only run I thought I saw light patches beside a door and ghosted rectangles low in the frame; in these port runs I do not see them, so if it was a kept buffer it is not reproducing for me now. I will keep an eye on it and say if it comes back.

If it helps anyone else on a small card, this is the set I would write down:

VICTORY_OUTPUT=1920x1080
VICTORY_CARD_BUFFERS_MB=512   VICTORY_CARD_BUFFERS_MIN_MB=1
VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_DESCRIPTORS=1 VICTORY_PORT_CBV=1
VICTORY_PORT_GUARD=1 VICTORY_PORT_JOURNAL=1
VICTORY_THIN=1
**@⁠Key-rs** on GitHub · 2026-11-27 03:03 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7208663454) Your pool patch does more than remove the regression on this card: **with it, the renderer ports finally pay off on 8 GB**, and this is now the fastest this machine has run. Same harness (Ryzen 7 8845H, **RTX 4060 Laptop 8 GB**, 31 GB RAM, driver 621.40, `diag` build with `lto = "thin"`, `play.ps1 -Safe` + `VICTORY_THIN=1`, warm caches, real key presses, 9-minute runs, one run per row): | build | frame | draws | per draw | fps | |---|---|---|---|---| | `f249fe0` (my reference before ports 5/6/7) | 198-212 ms | 5,065-5,292 | **40 µs** | 5.0 | | `c9c932c` (main, no pool) | 338-358 ms | 5,112-5,239 | 68 µs | 3.0 | | `014d52d` + your pool | 264-318 ms | 6,470-8,278 | 43 µs | 3.6-4.0 | | + `VICTORY_OUTPUT=1920x1080`, `CARD_BUFFERS_MB=512`, `MIN_MB=1` | 321-341 ms | 6,318 | 54 µs | 2.9 | | **+ the five port switches** | **133-140 ms** | **5,096-5,441** | **26 µs** | **7.1-7.5** | The last row is `VICTORY_PORT_CONSTANTS`, `PORT_DESCRIPTORS`, `PORT_CBV`, `PORT_GUARD` and `PORT_JOURNAL` all on, with the output at 1080p and the card-buffer ceiling at 512 MB. Frame line at the best sample: ``` 7.1 fps, 139.9 ms/frame (95.0 preparing: copies 19.0 ms 76.6 MB, textures 2.8 ms 6.6 MB; 6.1 on the GPU; 87.6 copying back 43.7 MB), 5,441 draws/frame ``` `preparing` fell from 160-220 ms to 95-110 ms and `copies` from 37-98 ms to 19-27 ms, against the same 76 MB of title memory — the ports doing what they say (no fills, no uploads, no slot scans) **once the per-copy buffers stop being made anew every frame**. Two things about the ordering, because I had them backwards for a day: * **The ports were net-negative here before the pool.** `c9c932c` on this card was 3 fps against `f249fe0`'s 5, and I said so in #221. Your patch changes the sign: the ports' savings only show once a copy stops costing 1.2 ms. * **1080p output alone did nothing** (row 4 is slower per draw than row 3 on my runs, and the scenes differed, so read that as noise). It only helps in combination, where it holds copy-back at 43-50 MB instead of letting it grow with the 4K back buffer. **Rendering**: the corridor and cell-block scenes look right — guard, inmate, gate, the painted floor, the poster wall. On the earlier pool-only run I thought I saw light patches beside a door and ghosted rectangles low in the frame; in these port runs I do not see them, so if it was a kept buffer it is not reproducing for me now. I will keep an eye on it and say if it comes back. If it helps anyone else on a small card, this is the set I would write down: ``` VICTORY_OUTPUT=1920x1080 VICTORY_CARD_BUFFERS_MB=512 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_DESCRIPTORS=1 VICTORY_PORT_CBV=1 VICTORY_PORT_GUARD=1 VICTORY_PORT_JOURNAL=1 VICTORY_THIN=1 ```
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-27 03:28 UTC · original

The same set on an RTX 2070 SUPER 8 GB (Turing, driver 621.14; Ryzen 7 5800X, 32 GB; no raw twins here, so port 3 runs only its root-CBV half). This is a local branch (test 68b0055: main plus the pool, upstream #96 and about 50 merged PRs), not main. diag build, Series S + DLSS, warm caches, the same spot in the world, about 3 minutes each, one run each. Numbers are over the 5 s lines with at least 1,000 draws.

as is + VICTORY_OUTPUT=1920x1080, CARD_BUFFERS_MB=512, min 1 MB, PORT_CONSTANTS, PORT_DESCRIPTORS, PORT_CBV, PORT_GUARD, PORT_JOURNAL
median frame 154 ms 333 ms
p90 529 ms 775 ms
draws a frame 3,008 3,560
per draw 137 µs 174 µs
waiting on the GPU, mean 12 ms 54 ms

So on this card the set is slower, not faster. The CPU side is about the same with it (preparing 43 → 47 ms median, copies 22 → 23 ms), and the extra time is waiting on the card. That doesn't contradict your 4060 result: this branch already has async submit and two frames in flight, which may take the CPU savings the ports give on main. I haven't split the five switches yet, so I can't say which one costs the GPU time here.

This comment was written with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-11-27 03:28 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7209019615) The same set on an RTX 2070 SUPER 8 GB (Turing, driver 621.14; Ryzen 7 5800X, 32 GB; no raw twins here, so port 3 runs only its root-CBV half). This is a local branch (`test` 68b0055: main plus the pool, upstream #96 and about 50 merged PRs), not `main`. diag build, Series S + DLSS, warm caches, the same spot in the world, about 3 minutes each, one run each. Numbers are over the 5 s lines with at least 1,000 draws. | | as is | + `VICTORY_OUTPUT=1920x1080`, `CARD_BUFFERS_MB=512`, min 1 MB, `PORT_CONSTANTS`, `PORT_DESCRIPTORS`, `PORT_CBV`, `PORT_GUARD`, `PORT_JOURNAL` | |---|---|---| | median frame | 154 ms | 333 ms | | p90 | 529 ms | 775 ms | | draws a frame | 3,008 | 3,560 | | per draw | 137 µs | 174 µs | | waiting on the GPU, mean | 12 ms | 54 ms | So on this card the set is slower, not faster. The CPU side is about the same with it (preparing 43 → 47 ms median, copies 22 → 23 ms), and the extra time is waiting on the card. That doesn't contradict your 4060 result: this branch already has async submit and two frames in flight, which may take the CPU savings the ports give on `main`. I haven't split the five switches yet, so I can't say which one costs the GPU time here. This comment was written with AI assistance (Claude Code).
Author
Owner

@⁠Key-rs on GitHub · 2026-11-27 03:34 UTC · original

That result plus ours looks like it is the in-place reads, and specifically Resizable BAR, which Turing does not have.

Our numbers, for the contrast (RTX 4060 Laptop 8 GB, Ada, nvidia-smi -q reports BAR1 Memory Usage: Total 8192 MiB, i.e. ReBAR is on and the whole card memory is mappable):

build frame draws per draw waiting on the GPU
014d52d + pool, no ports 264-318 ms 6,470-8,278 43 µs 0-13 ms
+ the five switches at 1080p 133-140 ms 5,096-5,441 26 µs 0-6 ms
+ the same at 720p 128.7-129.9 ms 5,708-5,762 22.6 µs 0 GPU

So the same set that costs you 179 µs per draw and 54 ms waiting on the card is 22.6 µs per draw and no wait here, on the same 8 GB, on the same PORT_* set. The difference between the two machines is Ada+ReBAR against Turing without it, and the one switch that turns CPU savings into card time is the one that has the card read title memory where it lies:

  • VICTORY_PORT_CONSTANTS — "the title's 174 MB constants heap is read by the card where the title writes it: no uploads, no fills." With an 8 GB BAR that read is a local memory read. Without ReBAR, BAR1 is the classic 256 MiB window, so those reads go through whatever path the driver finds, and every shader that touches them waits. That is exactly the shape you measured: the CPU side flat (preparing 43 → 47 ms, copies 22 → 23 ms) and the extra time all "waiting on the card".
  • PORT_DESCRIPTORS, PORT_CBV, PORT_GUARD, PORT_JOURNAL also assume the card may look at title memory in place, so they may partly share the cost, but PORT_CONSTANTS is the one with 174 MB behind it.

One run would settle it on your box (3 minutes, same spot): keep the other four and set

VICTORY_PORT_CONSTANTS=0

If the frame comes back towards 154 ms, the set is fine on Turing minus that switch and the rest can stay; if it stays at 333 ms, split the next one (PORT_CBV is the other that reads raw bytes in place).

Two things I would put in a README for small or older cards either way:

# Ada and later, ReBAR on:     all five, 1080p or 720p
# Turing / no ReBAR:           leave VICTORY_PORT_CONSTANTS out

and, for anyone reading the counters: on our card the ports show up as preparing and copies falling (160-220 → 95-110 ms, 37-98 → 19-27 ms against the same 76 MB); if instead "waiting on the card" grows, the switch is being paid for on the GPU, and on an 8 GB card that is also where the copy-back is, so it compounds.

**@⁠Key-rs** on GitHub · 2026-11-27 03:34 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7209097403) That result plus ours looks like it is the in-place reads, and specifically **Resizable BAR**, which Turing does not have. Our numbers, for the contrast (RTX 4060 Laptop 8 GB, Ada, `nvidia-smi -q` reports **`BAR1 Memory Usage: Total 8192 MiB`**, i.e. ReBAR is on and the whole card memory is mappable): | build | frame | draws | per draw | waiting on the GPU | |---|---|---|---|---| | `014d52d` + pool, no ports | 264-318 ms | 6,470-8,278 | 43 µs | 0-13 ms | | + the five switches at 1080p | 133-140 ms | 5,096-5,441 | 26 µs | 0-6 ms | | + the same at 720p | **128.7-129.9 ms** | 5,708-5,762 | **22.6 µs** | 0 GPU | So the same set that costs you 179 µs per draw and 54 ms waiting on the card is 22.6 µs per draw and **no** wait here, on the same 8 GB, on the same `PORT_*` set. The difference between the two machines is Ada+ReBAR against Turing without it, and the one switch that turns CPU savings into card time is the one that has the card read title memory where it lies: * **`VICTORY_PORT_CONSTANTS`** — "the title's 174 MB constants heap is read by the card where the title writes it: no uploads, no fills." With an 8 GB BAR that read is a local memory read. Without ReBAR, BAR1 is the classic 256 MiB window, so those reads go through whatever path the driver finds, and every shader that touches them waits. That is exactly the shape you measured: the CPU side flat (preparing 43 → 47 ms, copies 22 → 23 ms) and the extra time all "waiting on the card". * `PORT_DESCRIPTORS`, `PORT_CBV`, `PORT_GUARD`, `PORT_JOURNAL` also assume the card may look at title memory in place, so they may partly share the cost, but `PORT_CONSTANTS` is the one with 174 MB behind it. **One run would settle it on your box** (3 minutes, same spot): keep the other four and set ``` VICTORY_PORT_CONSTANTS=0 ``` If the frame comes back towards 154 ms, the set is fine on Turing minus that switch and the rest can stay; if it stays at 333 ms, split the next one (`PORT_CBV` is the other that reads raw bytes in place). Two things I would put in a README for small or older cards either way: ``` # Ada and later, ReBAR on: all five, 1080p or 720p # Turing / no ReBAR: leave VICTORY_PORT_CONSTANTS out ``` and, for anyone reading the counters: on our card the ports show up as `preparing` and `copies` falling (160-220 → 95-110 ms, 37-98 → 19-27 ms against the same 76 MB); if instead "waiting on the card" grows, the switch is being paid for on the GPU, and on an 8 GB card that is also where the copy-back is, so it compounds.
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-27 04:21 UTC · original

I ran your split on the RTX 2070 SUPER (BAR1 is 256 MiB here, so no Resizable BAR, as you guessed). Same local branch (test 68b0055 + two switches that were off), diag build, Series S + DLSS, the same scripted route into the world, about 150 s there per run, one run per row. "Steady" is the median over the last 60 s (all at 4,400-4,600 draws a frame).

run steady median GPU wait, mean
as is (play.ps1 defaults: CARD_BUFFERS_MB=1024, CARD_BUFFERS_MIN_KB=64) 94 ms 9 ms
+ CARD_BUFFERS_MB=512, min 1 MB 139 ms 41 ms
+ those and VICTORY_OUTPUT=1920x1080 146 ms 60 ms
+ those and PORT_DESCRIPTORS, PORT_CBV, PORT_GUARD, PORT_JOURNAL (PORT_CONSTANTS=0) 163 ms 86 ms

So on this card PORT_CONSTANTS is not the cost: without it the set is still 163 ms. Most of the difference (45 of the 69 ms) comes from the card-buffer settings, not from the ports. With 512 MB and a 1 MB minimum, more of the title's buffers stay in the PC's memory, and without ReBAR the card reads them over PCIe, which shows up as waiting on the GPU. The four ports add about 17 ms on top here, and 1080p output adds a little. I didn't split the four ports.

For a Turing / no-ReBAR card I'd write down: keep the card buffers at 1,024 MB with the 64 KB minimum (they cost VRAM, and #407 is about leaving room for targets). The ports didn't pay off here either way.

This comment was written with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-11-27 04:21 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7209729343) I ran your split on the RTX 2070 SUPER (BAR1 is 256 MiB here, so no Resizable BAR, as you guessed). Same local branch (`test` 68b0055 + two switches that were off), diag build, Series S + DLSS, the same scripted route into the world, about 150 s there per run, one run per row. "Steady" is the median over the last 60 s (all at 4,400-4,600 draws a frame). | run | steady median | GPU wait, mean | |---|---|---| | as is (`play.ps1` defaults: `CARD_BUFFERS_MB=1024`, `CARD_BUFFERS_MIN_KB=64`) | 94 ms | 9 ms | | + `CARD_BUFFERS_MB=512`, min 1 MB | 139 ms | 41 ms | | + those and `VICTORY_OUTPUT=1920x1080` | 146 ms | 60 ms | | + those and `PORT_DESCRIPTORS`, `PORT_CBV`, `PORT_GUARD`, `PORT_JOURNAL` (`PORT_CONSTANTS=0`) | 163 ms | 86 ms | So on this card `PORT_CONSTANTS` is not the cost: without it the set is still 163 ms. Most of the difference (45 of the 69 ms) comes from the card-buffer settings, not from the ports. With 512 MB and a 1 MB minimum, more of the title's buffers stay in the PC's memory, and without ReBAR the card reads them over PCIe, which shows up as waiting on the GPU. The four ports add about 17 ms on top here, and 1080p output adds a little. I didn't split the four ports. For a Turing / no-ReBAR card I'd write down: keep the card buffers at 1,024 MB with the 64 KB minimum (they cost VRAM, and #407 is about leaving room for targets). The ports didn't pay off here either way. This comment was written with AI assistance (Claude Code).
Author
Owner

@⁠Key-rs on GitHub · 2026-11-27 05:33 UTC · original

Your split was right, and the half I had wrong was the card buffers, not the ports — same conclusion as yours, on Ada with ReBAR.

I re-ran my own set with your card-buffer settings (1,024 MB and the 64 KB minimum) instead of the 512 MB / 1 MB I had talked myself into, everything else the same (pool patch, five ports, 720p, -Safe + THIN). RTX 4060 Laptop 8 GB, BAR1 = 8192 MiB, driver 621.40, lto = "thin", warm caches, one run per row:

card buffers frame draws per draw preparing copies
512 MB, min 1 MB (my set) 128.7-129.9 ms 5,708-5,762 22.6 µs 103-107 ms 24-26 ms
1,024 MB, min 64 KB (yours) 114.6-128.2 ms 6,071-7,561 16-19 µs 58-61 ms 14-16 ms

So the direction of your finding holds here too, even with ReBAR: the smaller ceiling was costing me ~25 % per draw, and it showed up in preparing and copies (103 → 60 ms, 24 → 15 ms) rather than as GPU wait — on this card the difference is that the buffers stay resident instead of being replaced each frame.

copy-back went the other way and is worth noting: 39.5 MB / 67 ms → 24 MB / 92-102 ms. Fewer megabytes at a worse rate, and the frame is still shorter overall. On an 8 GB card that is the number to watch whenever the card-buffer ceiling moves.

What I would now write down for either kind of card, if it is useful for the README:

VICTORY_CARD_BUFFERS_MB=1024   VICTORY_CARD_BUFFERS_MIN_KB=64    # both cards
VICTORY_OUTPUT=1280x720 (or 1920x1080)                           # both
VICTORY_PORT_CONSTANTS=1  (with ReBAR)   -- without it, leave it out
VICTORY_PORT_DESCRIPTORS=1 VICTORY_PORT_CBV=1 VICTORY_PORT_GUARD=1 VICTORY_PORT_JOURNAL=1
VICTORY_THIN=1

which is 8 frames a second at 6,000-7,500 draws on the 4060, against 5 before the pool patch and 3 on plain main. Thank you for running the split — it saved me from shipping the 512 MB set as advice.

**@⁠Key-rs** on GitHub · 2026-11-27 05:33 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7210731630) Your split was right, and the half I had wrong was the card buffers, not the ports — same conclusion as yours, on Ada with ReBAR. I re-ran my own set with your card-buffer settings (1,024 MB and the 64 KB minimum) instead of the 512 MB / 1 MB I had talked myself into, everything else the same (pool patch, five ports, 720p, `-Safe` + `THIN`). RTX 4060 Laptop 8 GB, `BAR1 = 8192 MiB`, driver 621.40, `lto = "thin"`, warm caches, one run per row: | card buffers | frame | draws | per draw | preparing | copies | |---|---|---|---|---|---| | 512 MB, min 1 MB (my set) | 128.7-129.9 ms | 5,708-5,762 | 22.6 µs | 103-107 ms | 24-26 ms | | **1,024 MB, min 64 KB (yours)** | **114.6-128.2 ms** | **6,071-7,561** | **16-19 µs** | **58-61 ms** | **14-16 ms** | So the direction of your finding holds here too, even with ReBAR: the smaller ceiling was costing me **~25 % per draw**, and it showed up in `preparing` and `copies` (103 → 60 ms, 24 → 15 ms) rather than as GPU wait — on this card the difference is that the buffers stay resident instead of being replaced each frame. `copy-back` went the other way and is worth noting: **39.5 MB / 67 ms → 24 MB / 92-102 ms**. Fewer megabytes at a worse rate, and the frame is still shorter overall. On an 8 GB card that is the number to watch whenever the card-buffer ceiling moves. What I would now write down for either kind of card, if it is useful for the README: ``` VICTORY_CARD_BUFFERS_MB=1024 VICTORY_CARD_BUFFERS_MIN_KB=64 # both cards VICTORY_OUTPUT=1280x720 (or 1920x1080) # both VICTORY_PORT_CONSTANTS=1 (with ReBAR) -- without it, leave it out VICTORY_PORT_DESCRIPTORS=1 VICTORY_PORT_CBV=1 VICTORY_PORT_GUARD=1 VICTORY_PORT_JOURNAL=1 VICTORY_THIN=1 ``` which is 8 frames a second at 6,000-7,500 draws on the 4060, against 5 before the pool patch and 3 on plain `main`. Thank you for running the split — it saved me from shipping the 512 MB set as advice.
This discussion has been locked. Commenting is limited to contributors.
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/avatarmanz--VIctory-7900XTX#221
No description provided.