gpu: add off-by-default memory attribution report #270
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!270
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-270"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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: exportsmemstatandmemory_report.crates/victory-gpu/src/host.rs+resource.rs: report-only retired queue attribution (queued entries, best-effort retired resource bytes, Any entries), decremented whenbury()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 existingtiles::STATSwhen nonzero (report-only).Tested
$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=1ok. 2 passed; 0 failed; 0 ignored; 0 measured; 361 filtered out.Not tested
AI use
Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
@adrianmjim on GitHub · 2026-11-26 22:44 UTC · original
Checked by reading the code on rx9070xt
cd8dfc0(the PR base; headaa9eb8b); I did not build or run it.retired_resource_bytes(resource.rs:195-199 on the head) casts the hostID3D12Resourcepointer toThisand callsresource(this).resource()(resource.rs:2760 oncd8dfc0) is an unchecked cast to the crate's titleResourcestruct (resource.rs:1144). Its SAFETY note says it is only called from resource methods.retire_resourcepasses a host resource: the old resource of a descriptor slot (keep, descriptor/host.rs:2907-2926 oncd8dfc0). So every queuedretire_resourcecall, and the bury of each such entry, reads the driver's COM object as aResourceand runsfootprint()on whatever sits at thedescoffset. Bury lag defaults to 16 or 64 (host.rs:609-615), soretire_resourcealways 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.RETIRED_STATS[1].fetch_subwraps.GetDesc()on the host resource, storing the size in the queue entry, or dropping the resource-bytes figure.cd8dfc0conflicts in host.rs only.cd8dfc0split the retired queue into 16 parts (RETIRED, host.rs:81;retired();buryloopsfor part in &RETIRED). The retire, retire_resource and bury hunks (host.rs:577-632) have to be redone for that.pub mod memstat;is inserted after#[cfg(windows)]. The cfg now applies tomemstat, andmod memoryloses 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.cd8dfc0for unrelated reasons (#315, fixed on a-publier by #330). On a base where it passes, the default job (nodiagnostics,-D warnings) would likely fail on this PR:made(memstat.rs:14) is only used inside thediagnosticsblock.staging_stats(the old cfg-gatedmemory(), renamed),staging_state_stats,card_memory_statsandsnapshot_active_statsare not gated ondiagnostics, but only diagnostics code calls them. They are dead code in the default build.alive.get(0)(get_first, memstat.rs:23) andretired_resource_bytes(&res), whereresis already a reference (needless_borrow, host.rs:513 on the head).footprint_sizeis inserted betweenfootprint's doc comment andfn footprint(resource.rs:186-202 on the head). That doc now documentsfootprint_size.snapshot_active_stats(shadow.rs:2854 on the head) callsCARDED.retainunder the lock. It prunes entries, so it is not purely report-only as described.copystat::log_memory(copystat.rs:808 oncd8dfc0, diagnostics only) already logs ALIVE, LISTS, MADE, HOST_TEXTURES, shadow and staging memory, and video memory. As the description says, nothing callsmemory_report. Adding only the new counters to that log line would avoid a second report.Not checked: build, clippy, tests, any game run.
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.Merge
Merge the changes and update on Forgejo.