Skip to content

D3D12.X: count the resources XCL makes for itself, by where it makes them - #2750

Open
joeypercia wants to merge 2 commits into
xcl-dev:mainfrom
joeypercia:d3d12x-memory-census
Open

joeypercia wants to merge 2 commits into
xcl-dev:mainfrom
joeypercia:d3d12x-memory-census

Conversation

@joeypercia

@joeypercia joeypercia commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2697; only the top commit belongs here.

Renamed after review (@throny on #2688): the row target pages is now placed texture pages, and target pools free is now placed texture pools free. It is vram::page_bytes().0, the pages of every placed texture on the shared 64 KiB pages, not only render targets. Log lines and JSON quoted below are from before the rename and keep the old names; the quantity is the same.

Counts the D3D12 resources XCL makes for itself, by the place it makes them: how many are alive, how many were made, and their bytes. #2697's memory line then shows each place as a part, and a line of its own lists the counts. Growth that follows the title's submits shows up as one place whose count keeps climbing. That's what @GreemSC's measurements on #2688 needed to tell XCL's own buffers apart from the title's. Part of #2688 (workstream 1, part 2 of the plan there).

What is in it (one commit)

  • crates/xcl/src/hle/d3d12x/resource_census.rs (new):
    • track(res, site) counts a resource XCL made and gives it a small COM object (IUnknown, a hand-made vtable as in null.rs) as private data (SetPrivateDataInterface).
    • D3D12 releases private data when it destroys the resource, and that release takes the resource off its place's count. So nothing has to be remembered at each place that lets one go, and a resource still referenced elsewhere stays counted.
    • Bytes come from GetResourceAllocationInfo. A resource in an upload or readback heap is in system memory, and memory_report::census_kind puts it where D3D12.X: a memory line by owner, against DXGI's budget #2697 puts the coherent window: non-local on a card, local on an integrated GPU with one segment (luckyteagirl's review). Everything else counts as video memory.
    • tracked(Option<ID3D12Resource>, site) wraps a creation's result.
  • The eleven places XCL makes committed resources at run time, each wrapped with tracked:
    • list_x.rs: copy scratch, fill pattern, timestamp readback, predication;
    • bind.rs: ExecuteIndirect argument order;
    • present.rs: frame dump readback;
    • real/dispatch_chain.rs: dispatch chain scratch;
    • sparse.rs: staging, zero buffer, readback;
    • gpu/texture.rs: upload staging.
  • memory_report.rs: each place's bytes are a part of the line by owner, so they come out of "other". census_line() gives memory: XCL's own resources (alive): <place> <alive> of <made> made, <MB> MB; …, logged after it under XCL_ACTIVITY.
  • Test a_tracked_resource_counts_until_it_is_destroyed:
    • two default-heap buffers and an upload buffer count at their places, with their bytes and kinds;
    • a clone keeps one alive and counted;
    • when the last reference goes, it leaves the count and made stays.
      Without the private data (SetPrivateDataInterface left out) it fails at its first count.

Tested

  • NVIDIA GeForce RTX 4070 Ti (driver 621.40), and the AMD Radeon iGPU of a Ryzen 7 7800X3D (RDNA2) with XCL_ADAPTER=Radeon. Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.8.2502.11. Debug builds for the tests, release for the runs.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4:

Regression run

RTX 4070 Ti (driver 621.40), release builds, 60 s each, scripts/smoke.ps1 -Game <folder> -Title retail-title on the newer retail title, with the same settings. Both ran with the NVIDIA shader-heap profile (#2590, 2 GiB) installed on this machine, one after the other. main b49be183 (the base of #2697 and of this) and this PR's head (no uncommitted changes):

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 963 (PresentX 963)
presents per 2 s (last 3): 60 59 50
device removals: 0
crashes: 0
peak commit: 20335 MB

PR:

xcl-smoke v1
commit: d08648bc1e7eb655a94b961e8727221955fecce0
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1213 (PresentX 1214)
presents per 2 s (last 3): 60 60 56
device removals: 0
crashes: 0
peak commit: 20099 MB

Not tested

  • The counts in a title run that reaches the world. The commit is in my next nvidia-dev run; the lines will go on [OFFICIAL] Swarm: RAM and VRAM use down, towards stable 30 FPS on AMD and NVIDIA #2688.
  • Resources XCL makes by other means than the eleven places: placed resources on its heaps (vram, sparse pools: already parts of the line), and the title's own resources (not XCL's to count).
  • Bytes of a resource D3D12 can't size (GetResourceAllocationInfo returning UINT64_MAX) count as 0.

AI use

  • Claude Code with Claude Opus 5.5 wrote the code, the test and this description, and ran the tests and the runs on the hardware above.

@luckyteagirl luckyteagirl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On 51f3149, resource_census::track classifies every UPLOAD/READBACK resource as NonLocal from heap.Type alone. That is wrong for an integrated UMA adapter: Microsoft maps L0 to DXGI LOCAL on UMA, and UPLOAD and READBACK both use L0 there. The new snapshot subtracts these bytes from non_local.usage, so on an integrated GPU it overstates the local other remainder and can report a negative or nonexistent non-local remainder. The new GPU test hardcodes UPLOAD as NonLocal, encoding the same assumption. XCL's existing uma_segment helper already treats an absent non-local segment differently.

Could classification use the resource device's architecture (and the chosen memory pool for custom heaps), so L0 counts as local on UMA and non-local on discrete? Please cover both architectures in a small classifier test and make the GPU assertion follow the actual adapter. This is exact-head source review using the D3D12 memory-pool contract; I did not run the new census test on both adapter types.

@joeypercia

Copy link
Copy Markdown
Contributor Author

Thanks, right. A census part in an upload or readback heap now goes where #2697 already puts the coherent window. On an adapter with a non-local budget it's non-local; on an integrated GPU, which has one segment, it's local (memory_report::census_kind). The unit test checks both, plus a video-memory part staying in video memory. It's in ed8707c8; the suite and smoke rerun follow. (Claude Code, Claude Opus 5.5)

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA test of #2750 head ed8707c, stacked on #2697 f7e4869. I reran after the author's UMA attribution update; earlier results on 51f3149 are not used for this report.

Windows 11 build 26300, RTX 3080 Ti (12 GB, NVIDIA driver 621.35), rustc 1.99.1 MSVC. A clean exact-head checkout was used.

  • cargo build --offline --locked --workspace: passed.
  • cargo test --offline --locked -p xcl --lib memory_report -- --nocapture --test-threads=1: 2 passed, 0 failed, 0 ignored. The native snapshot test selected the real RTX 3080 Ti.
  • cargo test --offline --locked -p xcl --lib resource_census -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored. The lifetime test selected the real RTX 3080 Ti and covered creation, a cloned reference, and final release.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --quiet: 1,438 passed, 0 failed, 47 ignored across 37 test executables. The output also printed 25 GPU SKIPPED notices; those paths are not counted as GPU coverage.

Not tested here: an integrated/UMA adapter, a paired retail smoke run, world-load memory growth, or FPS impact. The tests establish the current head's behavior on this discrete adapter; they do not resolve the frame/commit difference in the author's 60-second smoke blocks.

AI use: Codex (GPT-6.2 Sol) ran the tests and drafted this report.

@luckyteagirl

Copy link
Copy Markdown
Contributor

I reran the resource-census and memory-report tests at clean head fc3a1ef986c44e22cf744d358eb49b2a9ddd076d, after the D3D12 heap commit-accounting update.

Tested

Windows 11 Home build 26200, Ryzen 9 5980HX, AMD driver 30.0.13002.13003, Rust 1.99.0 MSVC, debug test profile. Separate test processes used XCL_REQUIRE_GPU=1 and the explicit XCL_ADAPTER names below.

cargo test --locked -p xcl --lib -j 1 hle::d3d12x::resource_census::tests -- --test-threads=1 --nocapture
cargo test --locked -p xcl --lib -j 1 hle::d3d12x::memory_report::tests -- --test-threads=1 --nocapture
Actual D3D12 backend from each log Resource census Memory report
AMD Radeon RX 6800M, 11,987 MiB 1 passed, 1,338 filtered 2 passed, 1,337 filtered
AMD Radeon(TM) Graphics, 496 MiB 1 passed, 1,338 filtered 2 passed, 1,337 filtered

All four commands exited 0, with 0 failures, 0 ignored, and no skip markers. The census fixture checks resource lifetime. The report tests cover synthetic segment and heap-charge cases plus whether a live snapshot includes budgets and expected owners.

Not tested

No title, full workspace suite, or measured per-heap process commit delta. The tests do not establish the accuracy of every runtime memory attribution.

AI use

OpenAI Codex (GPT-6.2 Sol) ran the tests, checked the exact revision and backend logs, and drafted this report.

@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2750 at 44a7e6fe3431b16e26e8f199d958f86648a6bc2c (stacked on PR #2697 50cfb321be8277482566d31f7a29f97c3f2ef4e7; merge-base origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.

Setup

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200
  • Toolchain / caches: rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)
  • Workload: Retail workload title: 29640639 via scripts/smoke.ps1 -Seconds 60 (XCL_NETWORK=0 XCL_ACTIVITY=1, default flags, no input)

Targeted RTX 4060 release unit tests (44a7e6fe)

  • cargo test --release -p xcl --lib hle::d3d12x::resource_census:: -- --nocapture: 1 passed, 0 failed, 0 ignored (0.38 s, a_tracked_resource_counts_until_it_is_destroyed ran live on RTX 4060, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib hle::d3d12x::memory_report:: -- --nocapture: 2 passed, 0 failed, 0 ignored (0.37 s, a_snapshot_on_the_device_has_its_budget_and_owners ran live on RTX 4060, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib hle::d3d12x::sparse:: -- --test-threads=4: 17 passed, 0 failed, 1 ignored (0.35 s, early_commit_timing ignored, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib hle::d3d12x::title_textures:: -- --test-threads=4: 19 passed, 0 failed, 0 ignored (0.79 s, 0 skipped, exit 0).

Live 8 GB RTX 4060 accounting under XCL_ACTIVITY=1 (60 s, 44a7e6fe)

  • Cadence & scripts/smoke.ps1 compatibility: 29 legacy memory: <N> MB committed by the process lines, 29 memory by owner (MB): lines (0/29 negative other values), and 28 memory: XCL's own resources (alive): census lines (starting at 4.0 s). scripts/smoke.ps1 parsed peak commit: 13980 MB cleanly.
  • Verbatim periodic memory by owner (MB): lines (first, peak VRAM, final):
[    2.004][13204][INFO ] memory by owner (MB): commit 5108 (UMA window 4095, sparse CPU copy 20, D3D12 heaps 122, other 870); video memory 78 of a 7188 budget (target pages 0, target pools free 0, arenas 0, sparse tiles 20, sparse pools free 44, sparse pools retired 0, committed textures 0, other 14); non-local 4139 of a 15556 budget (UMA window 4095, other 43)
[   19.174][13204][INFO ] memory by owner (MB): commit 13962 (UMA window 4095, sparse CPU copy 838, D3D12 heaps 6653, other 2374); video memory 6176 of a 6959 budget (target pages 3575, target pools free 8, arenas 465, sparse tiles 838, sparse pools free 57, sparse pools retired 0, committed textures 402, other 829); non-local 4572 of a 15556 budget (UMA window 4095, sparse staging 64, sparse zero buffer 1, upload staging 32, other 379)
[   59.200][13204][INFO ] memory by owner (MB): commit 13979 (UMA window 4095, sparse CPU copy 838, D3D12 heaps 6670, other 2375); video memory 6116 of a 6959 budget (target pages 3540, target pools free 43, arenas 401, sparse tiles 838, sparse pools free 57, sparse pools retired 0, committed textures 402, other 832); non-local 4650 of a 15556 budget (UMA window 4095, sparse staging 64, sparse zero buffer 1, upload staging 32, other 457)
  • Verbatim XCL's own resources (alive): census lines (first & final):
[    4.005][13204][INFO ] memory: XCL's own resources (alive): sparse staging 1 of 1 made, 64 MB; sparse zero buffer 1 of 1 made, 1 MB; upload staging 1 of 2 made, 8 MB
[   59.200][13204][INFO ] memory: XCL's own resources (alive): sparse staging 1 of 1 made, 64 MB; sparse zero buffer 1 of 1 made, 1 MB; upload staging 1 of 3 made, 32 MB
  • End-of-run owner breakdown (29 samples across 2.0 s .. 59.2 s, MB):
Segment / Owner First (2.0 s) Peak End (59.2 s) End share of segment
Commit total 5,108 13,980 13,979 100.0%
— UMA window 4,095 4,095 4,095 29.3%
— sparse CPU copy 20 838 838 6.0%
— D3D12 heaps 122 6,670 6,670 47.7%
— other 870 2,418 2,375 17.0%
Video memory (local) total 78 6,176 6,116 100.0% (87.9% of end budget)
— DXGI local budget 7,188 7,188 (min 6,959) 6,959 —
— target pages 0 3,575 3,540 57.9%
— target pools free 0 71 43 0.7%
— arenas 0 465 401 6.6%
— sparse tiles 20 838 838 13.7%
— sparse pools free 44 58 57 0.9%
— sparse pools retired 0 0 0 0.0%
— committed textures 0 402 402 6.6%
— other 14 832 832 13.6%
Non-local total 4,139 4,650 4,650 100.0% (29.9% of budget)
— DXGI non-local budget 15,556 15,556 15,556 —
— UMA window 4,095 4,095 4,095 88.1%
— sparse staging 0 64 64 1.4%
— sparse zero buffer 0 1 1 0.0%
— upload staging 0 32 32 0.7%
— other 43 457 457 9.8%

Key findings on 44a7e6fe (RTX 4060 8 GB)

  1. Commit other cut from 64.8% to 17.0%: Adding D3D12 heaps (6,670 MB, 47.7% of commit) brings attributed process commit to 83.0% (11,603 / 13,979 MB, integer >> 20 rounding diff 1..2 MB across all 29 samples; compare 9,081 MB / 64.8% unattributed other on PR D3D12.X: a memory line by owner, against DXGI's budget #2697 8c9433fe on the same host/title).
  2. Non-local attribution rises to 90.2%: resource_census breaks out sparse staging (64 MB), upload staging (32 MB), and sparse zero buffer (1 MB) cleanly alongside UMA window (4,095 MB), matching the XCL's own resources (alive): census line (1 of 3 made, 32 MB for upload staging) 1:1 and keeping non-local other strictly positive (43..457 MB, rounding diff 1 MB across all 29 samples).
  3. Local VRAM accounting stays consistent: 86.3% attributed (5,281 / 6,116 MB, other = 832 MB, rounding diff 0..4 MB), peak 6,176 / 6,959 MB (88.7% of concurrent DXGI local budget, 0/29 over-budget samples).

Paired 60 s RTX 4060 smoke (b49be183 vs 44a7e6fe)

Merge-base origin/main (b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB

PR #2750 head (44a7e6fe):

xcl-smoke v1
commit: 44a7e6fe3431b16e26e8f199d958f86648a6bc2c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1579 (PresentX 1579)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13980 MB

Limits of coverage

  • Full workspace test suite was not re-run on 44a7e6fe (only targeted resource_census::, memory_report::, sparse::, and title_textures:: release tests plus paired quiet 60 s smoke).
  • Discrete NVIDIA 8 GB GPU (RTX 4060) only — UMA / L0=LOCAL iGPU classification (census_kind when non_local is absent/zero) and VRAM oversubscription were not exercised on this host.
  • Default 60 s no-input menu/intro run: only sparse staging, sparse zero buffer, and upload staging appeared in XCL's own resources (alive):; other census categories (dispatch_chain scratch, compositor targets, readback/copy staging) stayed 0 in this window.

AI use

Ran the targeted release unit tests, paired quiet 60 s smoke runs, and log aggregation with assistance from Google Antigravity (Gemini 4 Neon); all numbers and verbatim lines were extracted directly from cargo test, xcl.log, and scripts/smoke.ps1 outputs.

@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026
joeypercia added a commit to joeypercia/xcl that referenced this pull request Nov 26, 2026
… end

The XCL_ACTIVITY line by owner was only in the log, so comparing runs
meant reading logs (xcl-dev#2688, workstream 1: an end-of-run table).

The activity thread keeps each snapshot it logs (memory_report::note):
the last one, and the one where video memory in use was highest.
report.json gets them as memory_by_owner (MB: totals, budgets, XCL's
parts and the rest of each total, with the second of the run). The
report takes what was kept and makes no DXGI call, which a crash report
may make from any thread. Without XCL_ACTIVITY there is no table.

Part of xcl-dev#2688. Stacked on xcl-dev#2750.

Assisted-by: Claude Code (Claude Opus 5.5)
What the video memory in use is made of could not be told from the
XCL_ACTIVITY memory line: it gives no budget, and three of XCL's owners
(xcl-dev#2688, workstream 1).

memory_report::snapshot() takes the process's commit, and DXGI's local
and non-local usage with their budgets, and XCL's parts of each:
- commit: the UMA coherent window, and the CPU copy of mapped sparse
  tiles (a title page in a sparse window is committed on the CPU too);
- video memory: target pages and the free part of their pools, arenas,
  mapped sparse tiles, free sparse pools, retired sparse pools (counted
  now: sparse::retired_bytes), and title textures that are committed
  resources of their own (title_textures::committed_bytes, console size).
What each total holds besides them is its own part, "other".

XCL_ACTIVITY logs it as a line of its own after the memory line, which
stays as it was (scripts/smoke.ps1 and the integration branches' tools
read it).

Part of xcl-dev#2688.

Assisted-by: Claude Code (Claude Opus 5.5)
…them

XCL's buffers sized per list or per submit (copy scratch, fill patterns,
readbacks, upload staging, ...) were not in the memory line, so memory
that grows with the title's submits could not be told apart from the
title's own (xcl-dev#2688, workstream 1).

resource_census::track gives a resource XCL made a small COM object as
private data; D3D12 releases it with the resource, which takes it off
its place's count. The eleven places XCL makes committed resources at
run time are tracked. Each place's bytes are a part of the memory line,
and a line of its own gives how many of each are alive and made.

Part of xcl-dev#2688. Stacked on xcl-dev#2697.

Assisted-by: Claude Code (Claude Opus 5.5)
joeypercia added a commit to joeypercia/xcl that referenced this pull request Nov 26, 2026
… end

The XCL_ACTIVITY line by owner was only in the log, so comparing runs
meant reading logs (xcl-dev#2688, workstream 1: an end-of-run table).

The activity thread keeps each snapshot it logs (memory_report::note):
the last one, and the one where video memory in use was highest.
report.json gets them as memory_by_owner (MB: totals, budgets, XCL's
parts and the rest of each total, with the second of the run). The
report takes what was kept and makes no DXGI call, which a crash report
may make from any thread. Without XCL_ACTIVITY there is no table.

Part of xcl-dev#2688. Stacked on xcl-dev#2750.

Assisted-by: Claude Code (Claude Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants