Skip to content

GPU: report retained snapshot, texture scratch and upload memory - #602

Open
lucaseddd wants to merge 1 commit into
Marvisak:mainfrom
lucaseddd:gpu/retained-copy-memory-471
Open

lucaseddd wants to merge 1 commit into
Marvisak:mainfrom
lucaseddd:gpu/retained-copy-memory-471

Conversation

@lucaseddd

@lucaseddd lucaseddd commented Nov 24, 2026 •

Copy link
Copy Markdown

When world loading approaches the system commit limit (#471), the process-wide number cannot show which retained GPU bridge allocations are growing. This adds a diagnostic line with three byte counters: idle shadow snapshots, live texture upload staging allocations, and retained CPU texture-read capacity.

The counters are independent of GPU vendor and VRAM size. Upload allocations are tracked once by allocation lifetime through weak references, so a diagnostic reference cannot keep an allocation alive. The sampler skips a busy sample and runs only with diagnostics enabled. The counters distinguish these components from overall private or system commit and do not change allocation policy.

Validated against main at 940d32f on Windows 10 x64:

  • cargo check --locked -p victory-gpu --features diagnostics
  • cargo check --locked -p victory-gpu
  • cargo xtask policy (182 files)

An earlier offline diagnostics run on an RTX 3060 Laptop collected 59 samples during loading. The last sample reported 53.5 MiB in texture uploads, 8 KiB of CPU read capacity, zero idle snapshots and about 11.9 GiB of process private memory. That run ended before a world frame, so it does not establish the cause of #471.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 4367d6c on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed), and cargo check -p victory-gpu --features diagnostics is clean on this branch.

  • try_lock everywhere is the right choice for a diagnostics sample: it never stalls the submission path, and a busy sample is skipped rather than reported as zero. It is gated on diagnostics, so release builds are unchanged.
  • Interaction with #472: that PR removes Last::read (one shared SCRATCH buffer replaces the per-texture vectors). On a branch with #472 merged, this PR merges without a textual conflict but no longer compiles: error[E0609]: no field read on type MutexGuard<'_, texture::Last> at texture.rs:82. If #472 lands first, the "texture read capacity" figure becomes SCRATCH's capacity, a single number rather than a sum. That is also exactly what #472 set out to measure.

Approving the change on current main. I have not merged it into our fork, which already has #472.

AI-assisted (Claude Code).

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32029.2010, Rust 1.98.1), cleanly merged onto main (ffe310e):

  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: PASS
  • cargo clippy -p victory-gpu --all-targets --features diagnostics --locked -- -D warnings: PASS
  • cargo test -p victory-gpu --locked: 50 passed, 0 failed, 1 ignored
  • cargo test -p victory-gpu --features diagnostics --locked: 53 passed, 0 failed, 1 ignored

Diff review (copystat.rs, shadow.rs, texture.rs): clean, minimal, and properly gated behind #[cfg(feature = diagnostics)]. Using try_lock() on POOL, STAGING, and each staging.last avoids blocking render/upload work and eliminates any lock-order deadlock risk when sampling retained memory.

AI-assisted; synthetic tests only, no game files.

@lucaseddd

Copy link
Copy Markdown
Author

Thanks both for verifying this on NVIDIA and AMD. The #472 interaction is useful to have recorded. #472 is still open, so the diagnostics remain based on the current layout. If #472 lands first, the texture-read sample will need to read the single SCRATCH capacity while retaining the non-blocking sample behavior.

@lucaseddd

Copy link
Copy Markdown
Author

Could a maintainer merge this into main if the diagnostics meet the request in #471? The counters are ready on current main. If #472 is scheduled to land first, please let me know here so I can adapt the texture-read counter to the shared scratch buffer.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC, NVIDIA RTX 5090):

  • cargo test -p victory-gpu --features diagnostics: 53 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-gpu --features diagnostics --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean, lightweight diagnostic addition reporting retained shadow buffer and texture staging memory in copystat. Approving.

AI-assisted (Gemini 4 Neon).

@lucaseddd

Copy link
Copy Markdown
Author

Thanks @DenRakEiw for testing the diagnostics configuration and running Clippy and the policy check. The #471 follow-up also confirms the counters can be sampled alongside #484.

@Capi360

Capi360 commented Nov 24, 2026

Copy link
Copy Markdown

Additional Windows startup measurement with the retained-copy counters.

This corroborates the earlier loading-screen result on a 3060: the measured retained copy buffers explain only a small portion of the startup memory use. These samples do not cover the world or resources outside the counters. The diagnostics build, three watch tests, and asset policy check passed. AI-assisted.

@lucaseddd

Copy link
Copy Markdown
Author

Updated the branch to main at 70564ae (head 380dab2). Texture uploads now belong to individual host textures, so the sampler tracks each staging allocation once through a weak reference. It counts allocations that remain live through an in-flight owner and skips busy samples without waiting. The upstream watch-lock and snapshot-rate lines remain present. Windows checks with and without diagnostics passed, and cargo xtask policy passed for 174 files.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@aycow

aycow commented Nov 24, 2026 •

Copy link
Copy Markdown

@Capi360 I reviewed your shared-read scratch measurement at 8d67d8e and the original implementation in 39eba9d. An isolated current-main version on 70564ae passed the tracked refresh and live alias shader controls on AMD and WARP. Across six generated 512² and two 1024² textures, the retained CPU input capacity was 14 MiB with per-texture storage and 4 MiB with a shared buffer. The GPU-visible uploads retained their independent contents. I’m keeping the branch local while we choose the contribution route. Would you prefer to carry the current-main scratch port separately from your retained-copy counters, or have me send the isolated patch for your review?

For the GPU-HOST-MEMORY and FIND-2 claims, a matched current-main loading and world capture would help identify what still consumes memory and whether fallback hashing is material. If your authorized setup can collect it, please share aggregate process private bytes, system commit/headroom, adapter budget/usage, snapshot and texture capacity, and the existing texture refresh totals for watched, hashed and changed bytes by the same frame window. Aggregate measurements are sufficient. The old startup measurement is useful provenance.

AI-assisted using Codex.

The attribution composition also exposed an exact-view accounting error. A 456-byte view backed by a native buffer of width 512 was charged as 65,536 bytes. The current diagnostics package charges 512 and includes live exact-view overlap until its owner releases it. AMD and WARP reproduced the expected capacity and lifetime after correction. The package preserves #602's allocation-lifetime counters and #484's process counters. Resource width remains a separate quantity from driver allocation and residency.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown

@Capi360 The validated patch is available as shared texture read scratch on your #602 head. This combines exact 380dab2 with the isolated scratch change and retains your nonblocking upload attribution. It credits your earlier implementation and the #1076 scratch work. AMD and WARP passed tracked refresh, decommit zero-fill, and the placed-alias shader test. Six 512² and two 1024² inputs required 4 MiB of shared CPU scratch instead of 14 MiB of per-texture capacity. The GPU uploads remained independent.

@Calvix2k If you can collect a matched run on the same authorized Windows 10 Series X and Agility/#1798 setup as your #175 report, the two revisions are attribution-only 1eab79c and attribution with shared scratch dac1953. Use the same cache, title profile, and recorded system commit headroom. With VICTORY_MEMORY_STATS=1, please share aggregate process private bytes, system commit and limit, DXGI budget and use, and shadow, snapshot, staging and scratch capacity over the same pre-failure window around frame 128. We can compare a world window if both runs reach it. No files or dumps are needed. Prior report

AI-assisted using Codex.

@Calvix2k

Copy link
Copy Markdown
Contributor

@aycow Matched run, revision A = 1eab79c + Agility #175 + #1798 (diag build, VICTORY_MEMORY_STATS=1). Same authorized setup as the #175 report: Windows 10 22H2 19045, Ryzen 7 5800X, RX 7800 XT (driver 32.0.32029.2010), 32 GB, D3D12Core 1.620.2, same cache/data dirs, title �99f876b…. Bytes are decimal.

Series X (--console series-x), pre-failure window — the run ends with Windows commit limit reached while committing 65536 bytes at frame ~130, title breakpoint +0x2474680:

frame s private working set system commit / limit GPU local use / budget GPU non-local shadow (peak) cached shadows native textures (bytes/used) staging (upload/read)
0 0 5,183,528,960 520,433,664 34,314,129,408 / 42,327,384,064 7,839,744 / 16,156,999,680 21,307,392 0 0 0 0
44 3 8,221,978,624 3,792,379,904 44,052,516,864 / 47,178,948,608 553,291,776 / 16,156,999,680 1,572,569,088 212,740,608 22 (212,512,448 guest / 207,357,952 unique) 32 (266,731,520 / 143,982,592) 0 / 0
130 6 10,350,305,280 4,443,979,776 45,900,623,872 / 47,676,006,400 2,163,216,384 / 16,156,999,680 1,991,835,648 631,981,824 locked (None) 791 (1,522,597,888 / 144,637,952) 4 / 4,096

Snapshot, list scratch and list upload were 0 in every sample; idle_snapshot_bytes 0. At the failure the system had ~1.8 GB of commit left, and Victory's own retained pools (shadow 0.63 GB, native textures 1.52 GB capacity / 0.14 GB used, staging ~4 KB) are small next to the process's 10.35 GB private. So the Series X failure here is the OS commit limit (C: pagefile cannot grow: 5.4 GB free), not one of the tracked pools.

Series S, same revision, 20 samples over 57 s (last sample, frame 1655):
private 10,385,784,832; working set 5,490,969,664; commit 43,484,344,320 / 46,939,488,256; GPU local 3,272,552,448 / 16,156,999,680; GPU non-local 2,663,211,008; shadow 1,266,756,864 peak; cached shadows 4,102 (1,064,812,494 guest / 913,442,886 unique); native textures 1,522,597,888 capacity (last line not sampled, texture count moves); texture upload 43,628,192; texture read 43,421,696; snapshots/scratch/upload 0.

Revision B = dac1953 is building now; I will post the same two windows for it next. No files or dumps.

@Calvix2k

Copy link
Copy Markdown
Contributor

@aycow Matched run, revision B = dac1953 (attribution + shared scratch) + Agility #175 + #1798. Same machine, cache, data dirs, title and diagnostic profile as the revision A table above. Bytes are decimal.

Series X (--console series-x) — same end: XMem … mapping physical pages failed … os error 1455 at frame ~142, then the title breakpoint +0x2474680:

frame s private working set system commit / limit GPU local use / budget GPU non-local shadow (peak) cached shadows native textures (bytes/used) staging (upload/read)
0 0 5,183,528,960* 520,433,664* 34,314,129,408 / 42,327,384,064* 7,839,744 / 16,156,999,680* 21,307,392* 0* 0* 0* 0*
52 3 8,180,658,176 3,802,439,680 43,425,431,552 / 46,911,041,536 556,699,648 / 16,156,999,680 1,572,569,088 212,740,608 22 (212,512,448 / 207,357,952) 33 (270,008,320 / 143,982,592) 0 / 0
142 6 10,388,692,992 4,498,919,424 45,563,432,960 / 47,720,468,480 2,163,216,384 / 16,156,999,680 2,082,611,200 722,683,648 locked (None) 791 (1,522,597,888 / 144,637,952) 4 / 4,096

*frame-0 line is the same startup sample in both revisions; I marked it with the A values because the run prints identical numbers there.

Snapshot, list scratch and list upload were 0 in every sample. As with A, the tracked pools are small at the failure (shadow 0.72 GB, native 1.52 GB capacity / 0.14 GB used) and the last 64 KiB fails against the OS commit limit.

Series S, revision B, 20 samples over 57 s (last sample, frame 1660):
private 10,194,096,128; working set 4,983,078,912; commit 42,840,850,432 / 46,809,739,264; GPU local 3,221,667,840 / 16,156,999,680; GPU non-local 2,593,333,248; shadow 1,240,577,280 peak; cached shadows 4,068 (1,039,297,790 guest / 896,878,266 unique); native textures 1,522,597,888 capacity / 144,637,952 used; texture upload 4; texture read 4,096; snapshots/scratch/upload 0.

The one visible A→B difference in this boot window is the texture read/upload attribution: revision A's Series S sample showed texture upload 43,628,192 and texture read 43,421,696, while B shows 4 and 4,096 with the same frame count and window length. If that matches your expectation for shared scratch, the matched pair is here; if not, I can repeat both with a fixed frame window (VICTORY_CAPTURE_FRAMES-style stop at frame 1600) to remove the timing difference.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate.

This adds a diagnostics-only retained copy memory line to copystat::log. It reports three numbers: idle shadow snapshot capacity (shadow::idle_snapshot_bytes, from POOL), texture upload chunks plus large upload buffers (texture::cached_staging_bytes, from CHUNKS and BUFFERS), and idle per-thread read scratch. copystat is already gated on diagnostics, and so is every new counter. The sampler uses try_lock and skips a busy sample rather than blocking. RETAINED_SCRATCH stays balanced: it is added when a buffer is put back in Scratch::drop, and subtracted on take, on replacement and on thread exit (Drop for ScratchCache). Allocation behaviour does not change.

One note: the PR description still mentions tracking uploads through weak references. This head no longer does that, so please update the description.

CI (check) passes on this head.


Generated by Claude Code

aycow added a commit to aycow/VIctory that referenced this pull request Nov 25, 2026
@aycow

aycow commented Nov 25, 2026

Copy link
Copy Markdown

@lucaseddd I updated the existing #602 scratch handoff to ccfb029 while retaining your changes. Both strict GPU Clippy configurations, policy and 144 active diagnostics tests passed. The separate attribution build passed the focused synthetic checks on AMD, NVIDIA and WARP with full GPU-based validation. The 8-texture fixture retained 4 MiB of CPU detile scratch versus 14 MiB before sharing and kept its GPU uploads independent. Could you use this scratch change in #602, or would #472 be the better place for it?

@Calvix2k Thanks for the previous matched title runs. The Series S GPU upload gauge moved along with CPU scratch, so that sample cannot isolate the private-commit effect. If you have an authorized test slot, could you compare the current-main counter baseline and shared-scratch build? Use a diagnostics build with VICTORY_MEMORY_STATS=1, the same adapter, title mode and cache state, and matching elapsed-time windows or frame tokens. Aggregate process private commit, system commit and limit, CPU texture-read capacity, GPU texture-upload capacity, and any failure time/code are sufficient. Measurement steps

@lucaseddd

Copy link
Copy Markdown
Author

I'd keep shared detile scratch in #472. #602 can stay focused on counting what the bridge retains, including live GPU uploads. Keeping the allocation change separate also lets us compare private and system commit at matched frame tokens without treating a change in GPU upload retention as a CPU scratch savings. The synthetic result gives #472 a concrete regression target: shared CPU scratch with independent GPU uploads.

@Calvix2k

Copy link
Copy Markdown
Contributor

@aycow Matched A/B on current main 4118f33 (plus only the Agility opt-in so Windows 10 draws), diagnostics build, VICTORY_MEMORY_STATS=1, --console series-s, same cache/data, title �99f876b…, adapter RX 7800 XT. Both runs: 20 samples, 0–57 s, 1644 / 1645 frames — the windows match. Bytes are decimal.

elapsed s A �e7e05c2 private A commit B �19a7ed4 private B commit
0 3,506,622,464 18,446,934,016 3,507,929,088 18,441,555,968
3 7,165,833,216 26,426,138,624 8,659,329,024 27,687,784,448
6 9,010,962,432 28,270,546,944 9,056,886,784 28,071,776,256
9 11,303,440,384 30,827,282,432 11,565,088,768 30,804,180,992
12 11,232,890,880 30,787,145,728 12,827,410,432 32,063,221,760
21 12,523,184,128 31,995,695,104 12,278,067,200 31,668,269,056
30 11,978,571,776 31,203,397,632 12,374,081,536 31,599,362,048
45 11,671,576,576 30,731,046,912 12,463,386,624 31,693,275,136
51 11,652,075,520 30,701,252,608 12,625,420,288 31,891,566,592
54 12,397,813,760 31,432,290,304 12,458,295,296 31,618,867,200
57 12,338,548,736 31,368,818,688 12,646,326,272 31,800,045,568

Shadow, snapshots, scratch and the texture gauges are identical at every matched sample: shadow 1,238,711,808 peak, snapshot 0, list scratch/upload 0, texture upload 4 B, texture read 4,096 B, cached shadows 4,329 (1,037,401,102 guest / 893,261,254 unique).

So in this window shared scratch shows no private-commit benefit (B is ~0.2–0.3 GB higher late, within run-to-run noise). The caveat is the window itself: on main with --console series-s this machine never submits world draws (the black-UI issue #1854), so texture reads never start and the scratch pool is not exercised; the gauges stay at their boot values. A window with active texture reads — or your synthetic fixture — is the fair place to see the 14 MiB → 4 MiB capacity change. If you want, I can rerun the pair with --console series-x and stop both at the same frame, but that profile dies at the commit limit around frame 130 here, before the world either.

zhaibingye added a commit to zhaibingye/VIctory that referenced this pull request Nov 25, 2026
Adapt lucaseddd's Marvisak#602 (380dab2) to the fork's shared
texture read scratch. Count staging lifetimes without a weak registry,
and sample idle snapshots and scratch independently without blocking.
These are component byte counts, not process commit or GPU residency.

Verified resource-accounting ownership and MSVC test compilation with
both default and all features.
@lucaseddd lucaseddd changed the title GPU diagnostics: report retained copy memory GPU: report retained snapshot, texture scratch and upload memory Nov 25, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@lucaseddd
lucaseddd force-pushed the gpu/retained-copy-memory-471 branch from f23624b to 663dc83 Compare November 25, 2026 16:16
@lucaseddd

Copy link
Copy Markdown
Author

Rebased onto 67e8ae1 and pushed 663dc83. GitHub now reports the PR as mergeable.

The rebase accounts for the current ownership of texture memory: upload chunks are counted once, the separate pool includes its free and in-use buffers, and idle per-thread read capacity is removed when the buffer is taken or its thread exits. The upstream ordering of host writes is preserved.

Both strict workspace Clippy configurations and the repository policy check passed. On this Windows host, the three reproducible GPU test failures and the shader test failures were also present on the unmodified base. The two additional timing-sensitive tests seen in the parallel workspace run passed when rerun individually on both the base and this PR. The hosted Windows CI is running on the new head.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and RTX 5090 + WARP verification at head 663dc8371f15 merged cleanly onto main (63bcca43c6a0):

  • Feature-gating & accounting audit (shadow.rs:899-903, texture.rs:725-733, 917-924):
    • idle_snapshot_bytes, cached_staging_bytes, RETAINED_SCRATCH, and Drop for ScratchCache stay strictly under #[cfg(feature = "diagnostics")] (default builds retain only zero-overhead ScratchCache(Cell<Vec<u8>>)).
    • Byte accounting across Scratch::take (fetch_sub), Scratch::drop (fetch_add -> replace -> fetch_sub), and thread-exit ScratchCache::drop (fetch_sub) balances exactly without underflow, and try_lock().ok()? ensures diagnostic logging never blocks active uploads/copy-backs.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy -p victory-gpu --all-targets -- -D warnings (default + --features diagnostics): 0 warnings
    • copystat:: shadow:: texture::: 12/12 passed on both RTX 5090 and WARP (--features diagnostics).

LGTM.

Steenax6 added a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
…d at every check (the opening video no longer cycles through old frames)

The opening video decodes into a ring of three plane sets in view memory,
which the title writes through another view: the guards never see a write
to them, and the hash that finds the change was taken on the texture's
eighth-frame turn only (HASH_EVERY). A set's use and its turn lined up
about every 24 frames, so two presented frames in three showed video from
up to two seconds before.

Now a texture whose hash finds it changed while its guard saw no write is
hashed at every check from then on, and a guarded texture's first three
checks hash it whatever the turn, so such a texture is found at its second
use (its memory moves from run to run; it cannot be known by address).
Textures that do not change cost three hashes more each, once. The log's
texture line counts the textures found so.

Source: fxceless/victory-fork pull request Marvisak#701 (on an RTX 5070: the planes
uploaded every frame of the video, 12.7 MB and about 4 ms of refresh a
frame; 0 of 318 frames out of order, none doubled). Of the cluster it is
the one that holds: Marvisak#602 hashes again only while the hash keeps finding a
change, which a ring of three defeats (each set is unchanged for two checks
out of three); Marvisak#489 covers linear one-layer R8 textures only; Marvisak#509/Marvisak#456 are
the same as a timed "hot" window. Without a switch: a fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants