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.

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 on 44a7e6fe:

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, 1 GiB) installed on this machine. 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: 1587 (PresentX 1587)
presents per 2 s (last 3): 60 58 48
device removals: 0
crashes: 0
peak commit: 15772 MB

PR:

xcl-smoke v1
commit: 44a7e6fe3431b16e26e8f199d958f86648a6bc2c
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1492 (PresentX 1492)
presents per 2 s (last 3): 27 52 49
device removals: 0
crashes: 0
peak commit: 17450 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

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.

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)
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.

3 participants