Diagnostics: host buffers alive now, by heap #3869

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

@⁠Trillazill on GitHub · 2026-11-30 09:51 UTC · original
Trillazill:diag/alive-host-buffers → main · +255 −3 · 5 files · 2 commits · closed without merging

What this adds

A diagnostics-only line, every five seconds with the memory lines:

host buffers alive now (made by the host's own makers): upload N MB, write-back upload N MB, shared N MB, read-back N MB, mapped card N MB, card N MB; in the PC's memory N MB of the N MB of it the card uses (...)

The memory line already says how many upload, shared and card buffers were made since the start (host::MADE), and the textures line how much of the PC's memory the card uses. Neither says what holds that memory now. That is the open question in most of the RAM reports (#1915, #2146, #2293, #3295, #3646, #3813).

alive.rs counts each buffer the host's makers give out when it is made, and uncounts it when the runtime destroys it. A small COM object rides on the resource as private data, and the resource releases it last. This is the same mechanism book.rs uses, but without the book, which is only kept with DRED or the slot check. Hooks sit next to the existing book::made calls in upload_buffer, writeback_upload_buffer, shared_buffer_own and uav_buffer_now, plus mapped_card_buffer and the pooled read-back maker. Everything is under feature = "diagnostics"; release builds are unchanged.

What it showed

RTX 4080, 32 GB RAM, Series X, default switches, a few minutes into the world:

process private 33.1–33.4 GB
PC memory the card uses 8.5–9.6 GB
of it, counted by this line 7.4–8.6 GB
shared buffers 953–1,115 alive, 6.4–7.4 GB
upload buffers 0.9–1.0 GB
card buffers (the card's own memory) 4.0–4.1 GB

The shared buffers are the host copies of title memory: 1,064 windows outside buffers came to 6,496 MB at the same moment. Windows that go to the card keep their shared buffer as the CPU side (CardCpu::Shared): 402 of them (2.4 GB) held both. The 6,496 MB of windows lay over 4,922 MB of title memory.

Also measured in the same session:

  • Texture room at 75 % instead of 90 %: the card had 1.3 GB free instead of being at its budget, and the PC memory it used stayed at 7.8–9.4 GB (33.4 → 32.2–34.1 GB private). This is not textures pushed out of a full card.
  • VICTORY_LIST_LAZY=1: at the menu it saved 20 MB (10,525 → 10,505 MB; host lists 686 → 673). Host lists are not where the memory goes.

Tests

  • New: alive::tests::the_line_sums_what_lies_in_the_pcs_memory.
  • cargo test -p victory-gpu --features diagnostics --lib -- alive:: copystat::: 9 pass.
  • cargo test -p victory-gpu --no-fail-fast (without diagnostics, which compiles none of this): 919 pass, 3 fail.
    • shader_cache::tests::every_switch_of_the_translator_is_in_the_key fails on 41adb551 too.
    • host::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue and host::menu::tests::a_change_is_saved_at_once_however_the_game_was_started pass alone (three times out of three).
  • Clippy (-p victory-gpu --lib --tests, with and without --features diagnostics): nothing in the lines this change adds or touches.
  • cargo xtask policy --staged: ok (4 files).

No game data, logs or other files from the title are in this change.

🤖 Generated with Claude Code

**@⁠Trillazill** on GitHub · 2026-11-30 09:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3869) `Trillazill:diag/alive-host-buffers` → `main` · +255 −3 · 5 files · 2 commits · closed without merging ## What this adds A diagnostics-only line, every five seconds with the memory lines: ``` host buffers alive now (made by the host's own makers): upload N MB, write-back upload N MB, shared N MB, read-back N MB, mapped card N MB, card N MB; in the PC's memory N MB of the N MB of it the card uses (...) ``` The memory line already says how many upload, shared and card buffers were **made** since the start (`host::MADE`), and the textures line how much of the PC's memory the card uses. Neither says what holds that memory **now**. That is the open question in most of the RAM reports (#1915, #2146, #2293, #3295, #3646, #3813). `alive.rs` counts each buffer the host's makers give out when it is made, and uncounts it when the runtime destroys it. A small COM object rides on the resource as private data, and the resource releases it last. This is the same mechanism `book.rs` uses, but without the book, which is only kept with DRED or the slot check. Hooks sit next to the existing `book::made` calls in `upload_buffer`, `writeback_upload_buffer`, `shared_buffer_own` and `uav_buffer_now`, plus `mapped_card_buffer` and the pooled read-back maker. Everything is under `feature = "diagnostics"`; release builds are unchanged. ## What it showed RTX 4080, 32 GB RAM, Series X, default switches, a few minutes into the world: | | | |---|---| | process private | 33.1–33.4 GB | | PC memory the card uses | 8.5–9.6 GB | | of it, counted by this line | 7.4–8.6 GB | | **shared buffers** | **953–1,115 alive, 6.4–7.4 GB** | | upload buffers | 0.9–1.0 GB | | card buffers (the card's own memory) | 4.0–4.1 GB | The shared buffers are the host copies of title memory: 1,064 windows outside buffers came to 6,496 MB at the same moment. Windows that go to the card keep their shared buffer as the CPU side (`CardCpu::Shared`): 402 of them (2.4 GB) held both. The 6,496 MB of windows lay over 4,922 MB of title memory. Also measured in the same session: - **Texture room at 75 % instead of 90 %:** the card had 1.3 GB free instead of being at its budget, and the PC memory it used stayed at 7.8–9.4 GB (33.4 → 32.2–34.1 GB private). This is not textures pushed out of a full card. - **`VICTORY_LIST_LAZY=1`:** at the menu it saved 20 MB (10,525 → 10,505 MB; host lists 686 → 673). Host lists are not where the memory goes. ## Tests - New: `alive::tests::the_line_sums_what_lies_in_the_pcs_memory`. - `cargo test -p victory-gpu --features diagnostics --lib -- alive:: copystat::`: 9 pass. - `cargo test -p victory-gpu --no-fail-fast` (without diagnostics, which compiles none of this): 919 pass, 3 fail. - `shader_cache::tests::every_switch_of_the_translator_is_in_the_key` fails on 41adb551 too. - `host::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue` and `host::menu::tests::a_change_is_saved_at_once_however_the_game_was_started` pass alone (three times out of three). - Clippy (`-p victory-gpu --lib --tests`, with and without `--features diagnostics`): nothing in the lines this change adds or touches. - `cargo xtask policy --staged`: ok (4 files). No game data, logs or other files from the title are in this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The memory line says how many upload, shared and card buffers were made
since the start, and the textures line how much of the PC's memory the
card uses, but not what holds that memory now. alive.rs counts each
buffer the host's makers give out while it lives (a COM object of ours
on it as private data, released when the runtime destroys it, as
book.rs is told), and copystat logs them by heap every five seconds.

In one run the card used 8.5-9.6 GB of the PC's memory and 6.4-7.4 GB
of it were shared buffers: the host copies of title memory (#3646).

Diagnostics builds only.

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

@⁠tyr0nsur on GitHub · 2026-11-30 10:06 UTC · original

I reproduced a gap in the live buffer census at 7a0efe3 with VICTORY_BUFFER_POOL=1. Small Host::upload_buffer and Host::shared_buffer_now allocations can return from pool::cpu_buffer before the committed-buffer hooks run. The resulting 64 MiB upload/shared heaps are missing from the census even while they stay cached. Staging blocks already use the large committed upload path, so they need no extra entry.

The follow-up tracks each backing heap once from successful creation to final D3D12 release. It shows tracked CPU backing and DXGI non-local usage as independent figures because the census includes requested buffer widths and full heap capacities. An unavailable DXGI query is reported as such.

On an RTX 4060, the regression fixture found a live 64 MiB upload heap with zero bytes reported before the fix. With the patch, two placed buffers shared one 64 MiB heap in each pool. The census read 64 MiB with the buffers live, 64 MiB with the heap cached, and 0 MiB after reclaim. The committed-buffer counters stayed flat, and the same check passed on WARP. The focused diagnostics suite passed 38 tests. No title needed.

Follow-up commit against this PR

**@⁠tyr0nsur** on GitHub · 2026-11-30 10:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3869#issuecomment-7275141308) I reproduced a gap in the live buffer census at `7a0efe3` with `VICTORY_BUFFER_POOL=1`. Small `Host::upload_buffer` and `Host::shared_buffer_now` allocations can return from `pool::cpu_buffer` before the committed-buffer hooks run. The resulting 64 MiB upload/shared heaps are missing from the census even while they stay cached. Staging blocks already use the large committed upload path, so they need no extra entry. The follow-up tracks each backing heap once from successful creation to final D3D12 release. It shows tracked CPU backing and DXGI non-local usage as independent figures because the census includes requested buffer widths and full heap capacities. An unavailable DXGI query is reported as such. On an RTX 4060, the regression fixture found a live 64 MiB upload heap with zero bytes reported before the fix. With the patch, two placed buffers shared one 64 MiB heap in each pool. The census read 64 MiB with the buffers live, 64 MiB with the heap cached, and 0 MiB after reclaim. The committed-buffer counters stayed flat, and the same check passed on WARP. The focused diagnostics suite passed 38 tests. No title needed. [Follow-up commit against this PR](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/ef6f0c9042d082ecdc97f63c7b721ca85692f509)
Report each upload and shared pool block for its full D3D12 lifetime, including idle capacity. Show the tracked CPU bytes and DXGI non-local usage independently.
Author
Owner

@⁠Trillazill on GitHub · 2026-11-30 10:36 UTC · original

Good find, thanks. I'd missed that pooled buffers come back from pool::cpu_buffer before the committed-buffer hooks. I cherry-picked ef6f0c9 (now aec09f4, authorship kept). Counting each 64 MiB backing heap once, for its whole D3D12 lifetime, is the right unit. Splitting "CPU backing tracked" from DXGI non-local usage, and printing "unavailable" when the query fails, reads better than my single sum.

With --features diagnostics, alive::, copystat:: and pool::tests::cpu_pool_heaps_are_counted_until_released pass here (10, RTX 4080). Clippy reports nothing in alive.rs, pool.rs or copystat.rs.

My in-game numbers in the description were taken with VICTORY_BUFFER_POOL unset, so the pool's heaps weren't part of them.

**@⁠Trillazill** on GitHub · 2026-11-30 10:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3869#issuecomment-7275835242) Good find, thanks. I'd missed that pooled buffers come back from `pool::cpu_buffer` before the committed-buffer hooks. I cherry-picked ef6f0c9 (now `aec09f4`, authorship kept). Counting each 64 MiB backing heap once, for its whole D3D12 lifetime, is the right unit. Splitting "CPU backing tracked" from DXGI non-local usage, and printing "unavailable" when the query fails, reads better than my single sum. With `--features diagnostics`, `alive::`, `copystat::` and `pool::tests::cpu_pool_heaps_are_counted_until_released` pass here (10, RTX 4080). Clippy reports nothing in `alive.rs`, `pool.rs` or `copystat.rs`. My in-game numbers in the description were taken with `VICTORY_BUFFER_POOL` unset, so the pool's heaps weren't part of them.
github-bot changed title from Diagnostics: host buffers alive now, by heap (what holds the PC's memory the card uses) to Diagnostics: host buffers alive now, by heap 2026-12-01 06:26:18 +00:00
github-bot force-pushed github-bot/gh-3869 from aec09f4f5f to d3fe025577 2026-12-01 06:26:19 +00:00 Compare
Author
Owner

@⁠Trillazill on GitHub · 2026-12-01 06:21 UTC · original

Rebased onto main 5fabb46e. Conflict in host.rs: main unwraps the upload buffer earlier; the hook moved next to book::made. Tests on the rebased branch: cargo test -p victory-gpu --lib --features diagnostics -- alive:: copystat:: pool::tests::cpu_pool 10 pass; cargo clippy -p victory-gpu --lib --tests --features diagnostics no errors.

**@⁠Trillazill** on GitHub · 2026-12-01 06:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3869#issuecomment-7302783585) Rebased onto main 5fabb46e. Conflict in `host.rs`: main unwraps the upload buffer earlier; the hook moved next to `book::made`. Tests on the rebased branch: `cargo test -p victory-gpu --lib --features diagnostics -- alive:: copystat:: pool::tests::cpu_pool` 10 pass; `cargo clippy -p victory-gpu --lib --tests --features diagnostics` no errors.
github-bot closed this pull request 2026-12-01 18:51:05 +00:00
Author
Owner

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

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

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

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3869
No description provided.