gpu: add off-by-default memory attribution report #270

Open
github-bot wants to merge 11 commits from github-bot/gh-270 into rx9070xt AGit
Owner

@⁠Adika713 on GitHub · 2026-11-26 15:27 UTC · original
Adika713:feat/mem-counters → rx9070xt · +646 −68 · 9 files · 11 commits · open

## What and why
Adds an off-by-default memory attribution report so low-memory runs can see which host/GPU-memory categories dominate before changing allocation behavior.

What is in it

  • crates/victory-gpu/src/memstat.rs: victory_gpu::memory_report() formatting existing counters into a single line. Off by default.
  • crates/victory-gpu/src/lib.rs: exports memstat and memory_report.
  • crates/victory-gpu/src/host.rs + resource.rs: report-only retired queue attribution (queued entries, best-effort retired resource bytes, Any entries), decremented when bury() drops them.
  • crates/victory-gpu/src/host.rs + memstat.rs: report-only deferred upload retention (live deferred upload buffer count/bytes), deferred kept host-object count, and scratch/prelude allocator attribution (spare count/bytes, pool/lazy-prelude flags, chunk sizes).
  • crates/victory-gpu/src/texture.rs + memstat.rs: report-only staging stats accessor (staging_stats) and staging state scan (dirty/never-uploaded/clean).
  • crates/victory-gpu/src/shadow.rs + memstat.rs: report-only card copy/before/window/mapped byte attribution and active snapshot/before-twin scan.
  • crates/victory-gpu/src/memstat.rs: includes existing tiles::STATS when nonzero (report-only).

Tested

  • Hardware: Windows 11, AMD Radeon RX 6950 XT (16337 MB), Ryzen 5 3600, 32 GB RAM. Not target RX 7900 XTX / i9-12900K / 64 GB hardware.
  • Commands (F: temp/target):
    • $env:TEMP='F:\VIctory-Belobug-AMD\_agent_tmp\tmp'; $env:TMP=$env:TEMP; $env:CARGO_TARGET_DIR='F:\VIctory-Belobug-AMD\_agent_tmp\target-split-mem'; cargo test --locked -p victory-gpu --lib memstat -- --test-threads=1
  • Result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 361 filtered out.

Not tested

  • No game run. No world-entry/FPS/visual/stability claim.
  • Report is not wired into a runtime log timer by this PR; it is a callable diagnostic.

AI use

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @⁠Adika713.

**@⁠Adika713** on GitHub · 2026-11-26 15:27 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/270) `Adika713:feat/mem-counters` → `rx9070xt` · +646 −68 · 9 files · 11 commits · open ## What and why Adds an off-by-default memory attribution report so low-memory runs can see which host/GPU-memory categories dominate before changing allocation behavior. ## What is in it - `crates/victory-gpu/src/memstat.rs`: `victory_gpu::memory_report()` formatting existing counters into a single line. Off by default. - `crates/victory-gpu/src/lib.rs`: exports `memstat` and `memory_report`. - `crates/victory-gpu/src/host.rs` + `resource.rs`: report-only retired queue attribution (queued entries, best-effort retired resource bytes, Any entries), decremented when `bury()` drops them. - `crates/victory-gpu/src/host.rs` + `memstat.rs`: report-only deferred upload retention (live deferred upload buffer count/bytes), deferred kept host-object count, and scratch/prelude allocator attribution (spare count/bytes, pool/lazy-prelude flags, chunk sizes). - `crates/victory-gpu/src/texture.rs` + `memstat.rs`: report-only staging stats accessor (`staging_stats`) and staging state scan (dirty/never-uploaded/clean). - `crates/victory-gpu/src/shadow.rs` + `memstat.rs`: report-only card copy/before/window/mapped byte attribution and active snapshot/before-twin scan. - `crates/victory-gpu/src/memstat.rs`: includes existing `tiles::STATS` when nonzero (report-only). ## Tested - Hardware: Windows 11, AMD Radeon RX 6950 XT (16337 MB), Ryzen 5 3600, 32 GB RAM. Not target RX 7900 XTX / i9-12900K / 64 GB hardware. - Commands (F: temp/target): - `$env:TEMP='F:\VIctory-Belobug-AMD\_agent_tmp\tmp'; $env:TMP=$env:TEMP; $env:CARGO_TARGET_DIR='F:\VIctory-Belobug-AMD\_agent_tmp\target-split-mem'; cargo test --locked -p victory-gpu --lib memstat -- --test-threads=1` - Result: `ok. 2 passed; 0 failed; 0 ignored; 0 measured; 361 filtered out`. ## Not tested - No game run. No world-entry/FPS/visual/stability claim. - Report is not wired into a runtime log timer by this PR; it is a callable diagnostic. ## AI use Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @⁠Adika713.
Add victory_gpu::memory_report() that formats existing host list/scratch, shadow, staging, texture, made-buffer and video-memory counters into one attribution line. The report is off by default and does not change allocation behavior.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:31:47 +00:00
Track retired queue entry count, best-effort retired resource bytes, and Any entry count in report-only atomics. Expose them in memory_report() and add test coverage. No allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Track live deferred upload buffer count/bytes with report-only atomics and expose them in memory_report(). No allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Add texture::staging_stats() as a report-only accessor and use it from memory_report so staging counts are available without diagnostics-only memory(). No allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Expose report-only card copy/before/window/mapped byte counters through shadow::card_memory_stats() and include them in memory_report(). No allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Track report-only deferred kept host-object count and expose it in memory_report(). No allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Expose existing tiles::STATS counters in memory_report when nonzero. Report-only; no allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Add report-only snapshot_active_stats() scanning live shadow copies for host snapshot buffers and card before-twin resources; expose in memory_report(). No allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Add report-only staging_state_stats() scan (dirty/never-uploaded/clean) and expose in memory_report(). No allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Add report-only scratch_stats() for spare chunk count/bytes, pool/lazy-prelude flags, and chunk sizes; expose in memory_report(). No allocation behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 22:44 UTC · original

Checked by reading the code on rx9070xt cd8dfc0 (the PR base; head aa9eb8b); I did not build or run it.

  • retired_resource_bytes (resource.rs:195-199 on the head) casts the host ID3D12Resource pointer to This and calls resource(this). resource() (resource.rs:2760 on cd8dfc0) is an unchecked cast to the crate's title Resource struct (resource.rs:1144). Its SAFETY note says it is only called from resource methods.
  • The only caller of retire_resource passes a host resource: the old resource of a descriptor slot (keep, descriptor/host.rs:2907-2926 on cd8dfc0). So every queued retire_resource call, and the bury of each such entry, reads the driver's COM object as a Resource and runs footprint() on whatever sits at the desc offset. Bury lag defaults to 16 or 64 (host.rs:609-615), so retire_resource always queues and this runs on every call during play, whether or not the report is used. From reading: the byte counts are garbage. The run in #147 that used this PR (about 25 minutes) reports no fault, so the likely effect is wrong numbers rather than a crash.
  • The byte count is computed again at bury (host.rs:513 on the head) and not stored with the entry. If the two reads differ, RETIRED_STATS[1].fetch_sub wraps.
  • Safer options: GetDesc() on the host resource, storing the size in the queue entry, or dropping the resource-bytes figure.
  • Rebase: applying 81ebb7b..aa9eb8b onto cd8dfc0 conflicts in host.rs only. cd8dfc0 split the retired queue into 16 parts (RETIRED, host.rs:81; retired(); bury loops for part in &RETIRED). The retire, retire_resource and bury hunks (host.rs:577-632) have to be redone for that.
  • lib.rs:69-71 (head): pub mod memstat; is inserted after #[cfg(windows)]. The cfg now applies to memstat, and mod memory loses it. pub use memstat::report as memory_report (lib.rs:111) is not gated, so on a non-Windows target it names a module that does not exist. CI is Windows-only and would not catch this.
  • CI has not run on this head: the workflow run shows "action_required".
  • Clippy already fails on cd8dfc0 for unrelated reasons (#315, fixed on a-publier by #330). On a base where it passes, the default job (no diagnostics, -D warnings) would likely fail on this PR:
    • made (memstat.rs:14) is only used inside the diagnostics block.
    • staging_stats (the old cfg-gated memory(), renamed), staging_state_stats, card_memory_stats and snapshot_active_stats are not gated on diagnostics, but only diagnostics code calls them. They are dead code in the default build.
    • Possible further hits: alive.get(0) (get_first, memstat.rs:23) and retired_resource_bytes(&res), where res is already a reference (needless_borrow, host.rs:513 on the head).
  • footprint_size is inserted between footprint's doc comment and fn footprint (resource.rs:186-202 on the head). That doc now documents footprint_size.
  • snapshot_active_stats (shadow.rs:2854 on the head) calls CARDED.retain under the lock. It prunes entries, so it is not purely report-only as described.
  • Encoding: all 6 files start with a UTF-8 BOM (5 gained one; memstat.rs is new). En dashes in comments became mojibake (5 lines in shadow.rs, 1 in resource.rs). Several files end in runs of blank lines.
  • Overlap: copystat::log_memory (copystat.rs:808 on cd8dfc0, diagnostics only) already logs ALIVE, LISTS, MADE, HOST_TEXTURES, shadow and staging memory, and video memory. As the description says, nothing calls memory_report. Adding only the new counters to that log line would avoid a second report.

Not checked: build, clippy, tests, any game run.

**@⁠adrianmjim** on GitHub · 2026-11-26 22:44 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/270#issuecomment-7204945180) Checked by reading the code on rx9070xt cd8dfc0 (the PR base; head aa9eb8b); I did not build or run it. - `retired_resource_bytes` (resource.rs:195-199 on the head) casts the host `ID3D12Resource` pointer to `This` and calls `resource(this)`. `resource()` (resource.rs:2760 on cd8dfc0) is an unchecked cast to the crate's title `Resource` struct (resource.rs:1144). Its SAFETY note says it is only called from resource methods. - The only caller of `retire_resource` passes a host resource: the old resource of a descriptor slot (`keep`, descriptor/host.rs:2907-2926 on cd8dfc0). So every queued `retire_resource` call, and the bury of each such entry, reads the driver's COM object as a `Resource` and runs `footprint()` on whatever sits at the `desc` offset. Bury lag defaults to 16 or 64 (host.rs:609-615), so `retire_resource` always queues and this runs on every call during play, whether or not the report is used. From reading: the byte counts are garbage. The run in #147 that used this PR (about 25 minutes) reports no fault, so the likely effect is wrong numbers rather than a crash. - The byte count is computed again at bury (host.rs:513 on the head) and not stored with the entry. If the two reads differ, `RETIRED_STATS[1].fetch_sub` wraps. - Safer options: `GetDesc()` on the host resource, storing the size in the queue entry, or dropping the resource-bytes figure. - Rebase: applying 81ebb7b..aa9eb8b onto cd8dfc0 conflicts in host.rs only. cd8dfc0 split the retired queue into 16 parts (`RETIRED`, host.rs:81; `retired()`; `bury` loops `for part in &RETIRED`). The retire, retire_resource and bury hunks (host.rs:577-632) have to be redone for that. - lib.rs:69-71 (head): `pub mod memstat;` is inserted after `#[cfg(windows)]`. The cfg now applies to `memstat`, and `mod memory` loses it. `pub use memstat::report as memory_report` (lib.rs:111) is not gated, so on a non-Windows target it names a module that does not exist. CI is Windows-only and would not catch this. - CI has not run on this head: the workflow run shows "action_required". - Clippy already fails on cd8dfc0 for unrelated reasons (#315, fixed on a-publier by #330). On a base where it passes, the default job (no `diagnostics`, `-D warnings`) would likely fail on this PR: - `made` (memstat.rs:14) is only used inside the `diagnostics` block. - `staging_stats` (the old cfg-gated `memory()`, renamed), `staging_state_stats`, `card_memory_stats` and `snapshot_active_stats` are not gated on `diagnostics`, but only diagnostics code calls them. They are dead code in the default build. - Possible further hits: `alive.get(0)` (get_first, memstat.rs:23) and `retired_resource_bytes(&res)`, where `res` is already a reference (needless_borrow, host.rs:513 on the head). - `footprint_size` is inserted between `footprint`'s doc comment and `fn footprint` (resource.rs:186-202 on the head). That doc now documents `footprint_size`. - `snapshot_active_stats` (shadow.rs:2854 on the head) calls `CARDED.retain` under the lock. It prunes entries, so it is not purely report-only as described. - Encoding: all 6 files start with a UTF-8 BOM (5 gained one; memstat.rs is new). En dashes in comments became mojibake (5 lines in shadow.rs, 1 in resource.rs). Several files end in runs of blank lines. - Overlap: `copystat::log_memory` (copystat.rs:808 on cd8dfc0, diagnostics only) already logs ALIVE, LISTS, MADE, HOST_TEXTURES, shadow and staging memory, and video memory. As the description says, nothing calls `memory_report`. Adding only the new counters to that log line would avoid a second report. Not checked: build, clippy, tests, any game run.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/ambient.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/pipeline/make.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/270/head:github-bot/gh-270'
git switch 'github-bot/gh-270'

Merge

Merge the changes and update on Forgejo.
git switch 'rx9070xt'
git merge --no-ff 'github-bot/gh-270'
git switch 'github-bot/gh-270'
git rebase 'rx9070xt'
git switch 'rx9070xt'
git merge --ff-only 'github-bot/gh-270'
git switch 'github-bot/gh-270'
git rebase 'rx9070xt'
git switch 'rx9070xt'
git merge --no-ff 'github-bot/gh-270'
git switch 'rx9070xt'
git merge --squash 'github-bot/gh-270'
git switch 'rx9070xt'
git merge --ff-only 'github-bot/gh-270'
git switch 'rx9070xt'
git merge 'github-bot/gh-270'
git push origin 'rx9070xt'
This discussion has been locked. Commenting is limited to contributors.
No description provided.