Skip to content

D3D12.X: a memory line by owner, against DXGI's budget - #2697

Open
joeypercia wants to merge 1 commit into
xcl-dev:mainfrom
joeypercia:d3d12x-memory-accounting
Open

joeypercia wants to merge 1 commit into
xcl-dev:mainfrom
joeypercia:d3d12x-memory-accounting

Conversation

@joeypercia

@joeypercia joeypercia commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

A memory line by owner under XCL_ACTIVITY. It shows the process's commit and DXGI's local and non-local usage, each against its budget, split into XCL's parts, with what XCL doesn't count as its own part. Without the budget and that remainder, nothing in #2688 can be judged. Part of #2688 (workstream 1, part 1 of the plan there).

The existing memory: line stays as it is: scripts/smoke.ps1 and the integration branches' tools read it. The new line is additive, so it merges into nvidia-dev with only the two neighbouring lines to keep side by side.

From the newer retail title on an RTX 4070 Ti 12 GB (nvidia-dev c044dc6d with the first revision of this commit, before the review changes below), 4 s before the device was removed:

[  132.562][36860][INFO ] memory by owner (MB): commit 32218 (UMA window 4095, sparse CPU copy 2145, other 25977); video memory 11491 of a 10530 budget (target pages 5684, target pools free 75, arenas 401, sparse tiles 2145, sparse pools free 30, sparse pools retired 0, committed textures 414, other 2740); non-local 4997 of a 15162 budget (other 4997)

The run's last 12 s show what the line is for. Video memory went past the DXGI budget at 126 s, and the budget itself had fallen from 11,226 MB to about 10,000 MB at 100 s. Of the 2.0 GB added between 124 s and 137 s, 1.7 GB is "other": the title's own resources, pipelines and the driver, none of which XCL counts yet. Target pages and sparse tiles grew by 0.4 GB. The device was removed at 137 s (DRED: a fault at VA 0x0, as in #2403). The full series will be on #2688.

What is in it (one commit)

  • crates/xcl/src/hle/d3d12x/memory_report.rs (new): snapshot() and Snapshot::line(), and its own DXGI query, which reads Budget too (real::video_memory stays as it is). The parts, by where they sit:
    • commit:
      • the UMA coherent window;
      • the CPU copy of mapped sparse tiles (a title page in a sparse window is committed on the CPU as well as mapped to a tile).
    • video memory:
      • target pages, and the free part of their pools;
      • arenas;
      • mapped sparse tiles, and free sparse pools;
      • retired sparse pools;
      • title textures that are committed resources of their own.
    • non-local: nothing XCL counts yet, so only "other".
  • crates/xcl/src/hle/d3d12x/sparse.rs:
    • retired_bytes: the pool heaps given back but not released yet. They weren't counted anywhere before.
    • committed_bytes: the title's committed pages in the windows, i.e. the pages of the mapped tiles that aren't holes. That's the "sparse CPU copy" part. A tile the title decommitted whole counts 0 even while its pool tile is parked (luckyteagirl's review). The existing test a_tile_decommitted_and_committed_again_keeps_its_video_memory checks both.
  • The UMA coherent window is also a part of the segment where DXGI counts it: non-local on a card, local on an integrated GPU with no non-local budget. On an RX 7800 XT (oni-swr) it was 512 of 529 MB of non-local; on the RTX 4070 Ti, 4,095 of 4,140 MB.
  • A commit that reads 0, as PrivateUsage does under Wine (pr1sm-dev), shows as "commit unknown", with no "other" for it. xcl run: report process memory under Wine #1097 and kernelx: the process's commit from VirtualQuery when PrivateUsage is 0 #2362 read the commit there in different ways, and process_commit can call whichever lands.
    The device test accepts that case: with no commit, the line must say "commit unknown" (luckyteagirl's review).
  • The D3D12 heaps' charge to the commit is a commit part of its own, D3D12 heaps: DXGI's local plus non-local usage, less the coherent window D3D12 imported. Windows charges D3D12 heaps to the process's commit as well. A 1 GiB heap added about 1,026 MB of commit on the RTX 4070 Ti and on the RDNA2 iGPU, for a default heap and for an upload heap alike (zohaiblazuli's finding, [OFFICIAL] Swarm: RAM and VRAM use down, towards stable 30 FPS on AMD and NVIDIA #2688). So commit's "other" is now only CPU memory.
  • Only the bytes D3D12 imported (real::uma_imported_bytes, from UMA_HEAPS, published on success) count as the window's part in DXGI's rows and are taken off the heaps' charge. A failed import leaves the window CPU memory only (luckyteagirl's review). The unit test covers that case.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: committed_bytes, how many title textures are committed resources of their own (not on vram::Pages tiles), and their console size.
  • crates/xcl/src/host.rs: the line, every 2 s with XCL_ACTIVITY, after the memory line.
  • Tests:
    • the_rest_is_the_total_less_the_parts: the rest is each total less its parts, a negative rest stays negative, a missing DXGI answer shows as "unknown", and the exact line.
    • a_snapshot_on_the_device_has_its_budget_and_owners: on the adapter, a local budget above 0, the commit, and every owner. On the RDNA2 iGPU DXGI reports a non-local budget of 0 (one memory segment), which the test allows.

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 50cfb321:
  • scripts/smoke.ps1 still finds the commit: its regex (memory: (\d+) MB committed) doesn't match the new line, which starts with "memory by owner".

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 since 2026-11-25. main b49be183 (this PR's base) 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: 1426 (PresentX 1426)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17542 MB

PR:

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

Not tested

  • A run that stays in the world on a 12 GB card: the one above ends at 137 s. The next run, with the 1 GiB shader heap, is on nvidia-dev af2cecc4.
  • Owners not counted yet, all in "other":
    • the swap chain;
    • list copy scratch and fill-pattern buffers;
    • the descriptor heaps;
    • the shader and pipeline blob caches (CPU);
    • upload staging (main's Uploader; the integration branches replaced it);
    • two-pass mesh buffers (integration branches only).
      These are next, in this order, as small follow-ups, along with the end-of-run table in report.json (part 2).
  • Committed title textures are counted at their console size. The PC resource can take somewhat more.
  • The sparse CPU copy is counted as the mapped tiles. A tile's pages that the title left uncommitted (holes) are counted too.
  • Per-device split: one device, as real::device_raw.

AI use

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

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Test report for #2697 at 451c72455ca1d5d23f40de8ac6c12b24ef93eacb (parent b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7; the head is one commit on that parent). Measurements only. This is not a source review.

Machine: AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Windows 11 Pro 26200, rustc 1.100.0, debug build, --locked, -j 4. Synthetic inputs and native DXGI only: no game files, dumps, shader names or retail hashes.

Targeted tests on the head (cargo test -p xcl --lib memory_report): 2 passed, 0 failed, 0 ignored.

  • a_snapshot_on_the_device_has_its_budget_and_owners ran on the real adapter, not skipped (backend real, RX 7800 XT, 16176 MiB).
  • the_rest_is_the_total_less_the_parts passed. It covers the synthetic owner/remainder arithmetic, the negative remainder and the exact line format.

Extra probe, not committed, reverted afterwards. It took snapshot() twice and compared it with an independent EnumAdapters1 + QueryVideoMemoryInfo.

  • Local budget: snapshot 16157503488 B, independent 16157503488 B.
  • Non-local budget: snapshot 50654904320 B, independent 50654904320 B.
  • Usage agreed within the tolerance I set (5% + 64 MiB): 7688192 B local, 555032576 B non-local.
  • other(kind) == total - counted held for video, non-local and commit.
  • The live line was identical across the two snapshots:
    memory by owner (MB): commit 607 (UMA window 512, sparse CPU copy 0, other 95); video memory 7 of a 15408 budget (target pages 0, target pools free 0, arenas 0, sparse tiles 0, sparse pools free 0, sparse pools retired 0, committed textures 0, other 7); non-local 529 of a 48308 budget (other 529)

Locked workspace suite (cargo test --locked --workspace --no-fail-fast -- --test-threads=4):

passed failed ignored
head 451c7245 1436 1 47
parent b49be183 1434 1 47
  • Both runs fail only gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, with seed 722: res[30] = 0x1, CPU 0x7fffffff. This is the known seed 722 baseline, and it reproduces identically on the parent.
  • The 2 extra passes on the head are the 2 new tests.
  • Both runs print the same 7 SKIPPED lines: f16 and f32 conversion programs on the GPU, refused because of V_MUL_F16, V_PK_MUL_F16 and V_CVT_F16_F32 (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426). None are new.
  • A first head run without --no-fail-fast stopped after the lib failure. The numbers above come from the --no-fail-fast reruns.

Limits of coverage

  • No title was run, so every XCL owner reads 0 and only other is non-zero. Nothing here shows the owners' byte counts are right under load.
  • It does not cover sparse::retired_bytes, title_textures::committed_bytes, the host.rs logging cadence, or the PR's scripts/smoke.ps1 regression run.
  • The test run does not check which side of the commit/video split each owner is counted on, or whether anything is double counted.
  • The two adapter entries that enumerated as RX 7800 XT reported identical values.
  • The machine has a single AMD GPU and no NVIDIA, Intel or iGPU.

AI use: Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report; Codex (gpt-6.2-sol) orchestrated. Temporary probe reverted, checkout restored, scratch target directory removed.

@joeypercia

joeypercia commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks, @oni-swr. Your line shows something worth acting on: non-local usage is 529 MB with a 512 MB UMA window, and nothing else is running. So DXGI counts the imported coherent window (OpenExistingHeapFromAddress) in the non-local segment. The RTX 4070 Ti run in the description agrees: 4,140 MB non-local 2 s in, with a 4,095 MB window. (On the RDNA2 iGPU, one segment, non-local is 0.)

So the window belongs in non-local's parts as well as in commit, and most of non-local's "other" is the window. The next part puts it there. (Claude Code, Claude Opus 5.5)

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

memory_report.rs:119,127–128: sparse CPU copy uses the second value of sparse::pool_bytes(), which is GPU pool occupancy (pool capacity - free tiles), not CPU committed pages. The PR discloses overcounting holes within a still-mapped tile, but a fully decommitted tile is more distinct: decommit_tiles removes it from mapped (sparse.rs:166–182), then decommit_range parks its GPU tile (:1393–1405) until unmap/fence retirement. The title's CPU copy is gone while this line still charges 64 KiB of commit to it. Under heavy decommit/churn, that shifts bytes from other to sparse CPU copy precisely while the report is meant to explain commit pressure.

Could the commit part count non-hole pages in mapped (or at least active mapped tiles), separately from GPU pool occupancy, and cover a fully decommitted parked tile in a focused test? The GPU sparse tiles part can retain the pool accounting. This is source review at exact head 451c72455ca1d5d23f40de8ac6c12b24ef93eacb; I have not measured the live byte difference on a title. AI-assisted review with Codex.

@joeypercia
joeypercia force-pushed the d3d12x-memory-accounting branch from 451c724 to 8c9433f Compare November 26, 2026 07:34
@luckyteagirl

Copy link
Copy Markdown
Contributor

Thanks for the quick update. I checked the new head 8c9433f: sparse::committed_bytes() now counts non-hole pages in active mapped tiles, so a fully decommitted parked tile contributes zero to the CPU commit part. The added parked-tile assertion covers the case I raised. This resolves my review point. AI-assisted follow-up with Codex.

@pr1sm-dev

Copy link
Copy Markdown

Under Wine (Linux, Wine 11.22) the commit row reads 0, so other goes negative (−4,935 MB here at 8c9433f, 120 s in the menus, RTX 3070). process_commit reads PrivateUsage, which Wine leaves at 0. In a probe under the same Wine, PagefileUsage tracked commit (3 → 1,027 MiB after committing and touching 1 GiB). #1097 / #2362 fix this counter for the activity log but not memory_report.rs, so reusing their helper once one lands would cover it. The video and non-local rows look right here (local budget ~7.2 GB of 8 GB, non-local 48 GB).

AI use: Claude Code (Claude Opus 5.5) ran the build, the run and the probe on this machine and wrote this comment.

@joeypercia
joeypercia force-pushed the d3d12x-memory-accounting branch from 8c9433f to f7e4869 Compare November 26, 2026 07:51
@joeypercia

Copy link
Copy Markdown
Contributor Author

Thanks, @pr1sm-dev. Right: PrivateUsage reads 0 under Wine. Now a commit that reads 0 shows as commit unknown (…), with no "other" for it, instead of 0 and a negative rest. The video and non-local rows stay as they are. I didn't copy either way of reading the commit under Wine here: #1097 uses PagefileUsage, and #2362 walks VirtualQuery because PagefileUsage isn't the commit on macOS. Whichever lands, process_commit can call it. Amended into f7e4869c; the unit test covers the unknown commit. (Claude Code, Claude Opus 5.5)

@luckyteagirl

Copy link
Copy Markdown
Contributor

Focused Windows AMD check of current head f7e4869cf35d646caf05dd158dc79363b4b76ef1 (clean detached checkout; base b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). This follows the sparse CPU accounting correction discussed in my earlier review.

Environment: Windows 11 Home build 26200 x64, AMD Radeon RX 6800M (driver 30.0.13002.13003), Ryzen 9 5980HX, Rust 1.99 MSVC. XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=1; the native memory-report test log identifies the RX 6800M backend.

  • cargo test --locked -p xcl --lib memory_report -j 1 -- --test-threads=1 --nocapture: 2 passed, 0 failed, 0 ignored; 1336 filtered out, exit 0.
  • cargo test --locked -p xcl --lib a_tile_decommitted_and_committed_again_keeps_its_video_memory -j 1 -- --test-threads=1 --nocapture: 1 passed, 0 failed, 0 ignored; 1337 filtered out, exit 0. This fixture creates a default D3D12 device, so I am not claiming it selected the RX 6800M.

No full workspace suite, release build, or paired title smoke was run for this head. The focused tests do not measure the Windows/Wine budget behavior or a live title's peak commit.

AI use: OpenAI Codex (GPT-6.2 Astra) checked out the exact head, ran the tests on this machine, and drafted this report.

@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) verification of PR #2697 at 8c9433fe2e7b4795e262c783b55554d724c6e136 (exact parent origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements only; not a source review.

Note: Measurements were taken on 8c9433fe just before f7e4869c landed; verified 8c9433fe..f7e4869c only changes Snapshot.commit to Option<u64> for the Wine PrivateUsage == 0 ("commit unknown") path, leaving native Windows 11 output identical.

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 (dxil_cache: 460 hits, 0 misses), 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 XCL_RUN_SECONDS=60, default flags, no input)

Targeted RTX 4060 release unit tests (8c9433fe)

  • cargo test --release -p xcl --lib hle::d3d12x::memory_report -- --nocapture: 2 passed, 0 failed, 0 ignored (0.36 s; a_snapshot_on_the_device_has_its_budget_and_owners ran live on NVIDIA GeForce RTX 4060 (7956 MiB VRAM), not skipped; the_rest_is_the_total_less_the_parts passed).
  • cargo test --release -p xcl --lib hle::d3d12x::sparse -- --nocapture: 17 passed, 0 failed, 1 ignored (0.39 s; early_commit_timing ignored).
  • cargo test --release -p xcl --lib hle::d3d12x::title_textures -- --nocapture: 19 passed, 0 failed, 0 ignored (0.89 s).

Live workload accounting under XCL_ACTIVITY=1 (60 s, 8c9433fe)

  • Cadence & scripts/smoke.ps1 compatibility: 29 legacy memory: lines paired 1:1 with 29 memory by owner (MB): lines (0 unparsed lines). scripts/smoke.ps1 continued matching only the legacy memory: (\d+) MB committed line.
  • Verbatim periodic lines (first, peak VRAM, final):
[    2.002][15624][INFO ] memory by owner (MB): commit 5245 (UMA window 4095, sparse CPU copy 20, other 1129); video memory 91 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 27); non-local 4243 of a 15556 budget (UMA window 4095, other 148)
[   18.070][15624][INFO ] memory by owner (MB): commit 13995 (UMA window 4095, sparse CPU copy 838, other 9061); video memory 6175 of a 6945 budget (target pages 3576, target pools free 7, arenas 465, sparse tiles 838, sparse pools free 57, sparse pools retired 0, committed textures 400, other 829); non-local 4603 of a 15556 budget (UMA window 4095, other 507)
[   58.094][15624][INFO ] memory by owner (MB): commit 14015 (UMA window 4095, sparse CPU copy 838, other 9081); video memory 6114 of a 6922 budget (target pages 3542, target pools free 41, arenas 401, sparse tiles 838, sparse pools free 57, sparse pools retired 0, committed textures 400, other 832); non-local 4684 of a 15556 budget (UMA window 4095, other 588)
  • End-of-run owner table (29 samples across 2.0 s .. 58.1 s, MB):
Segment / Owner First (2.0 s) Peak End (58.1 s) End share of segment
Commit total 5,245 14,015 14,015 100.0%
— UMA window 4,095 4,095 4,095 29.2%
— sparse CPU copy 20 838 838 6.0%
— other 1,129 9,081 9,081 64.8%
Video memory (local) total 91 6,175 6,114 100.0% (88.3% of end budget)
— DXGI local budget 7,188 7,188 (min 6,910) 6,922 —
— target pages 0 3,576 3,542 57.9%
— target pools free 0 71 41 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 400 400 6.5%
— other 27 832 832 13.6%
Non-local total 4,243 4,684 4,684 100.0% (30.1% of budget)
— DXGI non-local budget 15,556 15,556 15,556 —
— UMA window 4,095 4,095 4,095 87.4%
— other 148 588 588 12.6%

Key findings on 8c9433fe (RTX 4060 8 GB)

  1. Non-local UMA window attribution verified live on 8 GB NVIDIA: uma_segment(non_local) places UMA window 4095 in non-local on this discrete RTX 4060, accounting for 87.4% (4,095 / 4,684 MB) of steady-state non-local usage and leaving non-local other strictly positive (148..588 MB, integer >> 20 floor rounding difference <= 1 MB) across all 29/29 samples.
  2. Active sparse::committed_bytes() accounting verified live: sparse CPU copy tracked 20 -> 838 MB cleanly across all 29/29 samples, matching sparse tiles (0 MB hole delta in this 60 s menu/intro window; sub-tile decommit / hole paths are covered by hle::d3d12x::sparse::tests, 17/0/1).
  3. 86.3% of local VRAM attributed under load on 8 GB: Tracked owners sum to 5,279 MB of 6,114 MB steady-state local VRAM (other = 832 MB, strictly positive 27..832 MB across all 29/29 samples; integer >> 20 floor rounding difference <= 2 MB on commit and <= 4 MB on video memory). target pages (3,542 MB, 57.9%) and sparse tiles (838 MB, 13.7%) dominate local VRAM.
  4. 8 GB local budget headroom: DXGI local budget started at 7,188 MB, tightened to 6,910 MB (-278 MB) during load, and ended at 6,922 MB. Peak local usage reached 6,175 MB (88.9% of the concurrent 6,945 MB budget at t = 18.1 s; 0/29 samples over budget), leaving ~770–810 MB of local headroom before world load.

Paired 60 s RTX 4060 smoke (b49be183 vs 8c9433fe)

Parent 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 #2697 head (8c9433fe):

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

Limits of coverage

  • Default main 60 s no-input menu/intro run: sparse pools retired stayed 0 MB and sparse tiles - sparse CPU copy stayed 0 MB throughout this window; VRAM stayed under the 8 GB DXGI budget (0/29 over-budget samples), so negative video memory other under VRAM oversubscription/demotion was not exercised here.
  • Full workspace suite was not re-run on 8c9433fe (only targeted memory_report, sparse, and title_textures tests plus paired 60 s smoke).
  • Single discrete NVIDIA 8 GB GPU (RTX 4060); no AMD, Intel, or iGPU tested on this host.

AI use

Ran the targeted tests, paired quiet 60 s smoke runs, and log analysis with assistance from Google Antigravity (Gemini 4 Neon); all numbers were extracted directly from the xcl.log, report.json, and scripts/smoke.ps1 outputs.

@thehollowedone

thehollowedone commented Nov 26, 2026 •

Copy link
Copy Markdown

Updated independent Windows/NVIDIA check for #2697 head f7e4869 against b49be18. This supersedes my earlier 8c9433f test report. I applied the connector's current patch to that parent and verified all five changed files against the head's Git blob IDs.

Tested: Windows 11 build 26300, RTX 3080 Ti (12 GB, NVIDIA 621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11; debug build. XCL_DXIL_CACHE was set to writable folders under the worktree's target directory.

  • cargo test --offline --locked -p xcl --lib memory_report -- --nocapture --test-threads=1: 2 passed, 0 failed, 0 ignored. The native DXGI budget/owner snapshot ran on the real RTX 3080 Ti.
  • cargo build --offline --locked --workspace: passed.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --quiet: 1,437 passed, 0 failed, 47 ignored across 37 targets; 25 GPU SKIPPED notices (native wave64, three refused per-lane cases, and no heap windows). The e2e target passed 4/0/0. Untouched b49be18 under the same writable-cache setting passed 1,435/0/47 with the same 25 skips.

The earlier console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk failure came from this managed worktree's default %LOCALAPPDATA% DXIL cache path: it reproduced in isolation without a cache override and passed 1/0/0 when XCL_DXIL_CACHE pointed inside the worktree. No XCL code change was needed for that test.

Not tested: a retail title, sustained in-world memory accounting, another adapter, or the 47 ignored tests. Synthetic inputs only; no game files or diagnostics were used or posted.

AI use: Codex (GPT-6.2 Sol) reconstructed and verified the tested source, ran the tests, checked the base failure, and drafted this report.

joeypercia added a commit to joeypercia/xcl that referenced this pull request Nov 26, 2026
…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)
@GodlyBDS

Copy link
Copy Markdown

Independent #2697 port check on nvidia-dev (RTX 3090 Ti)

Windows 10, NVIDIA 621.40, 32 GiB system RAM. Local release tree af2cecc40886a8682ecf3267f5328c6dc4b66ad7 plus this PR's f7e4869cf35d646caf05dd158dc79363b4b76ef1 report, merged with existing NVIDIA activity text. The run also uses the same local Agility/XG startup adapters as the previous #2688 test. The exact main-targeted PR head was not run.

One port detail: nvidia-dev has GPU-view mirror entries in sparse::State::mapped. A mirror has TileEntry.src != 0 and no CPU commitment at its own VA. Counting every entry's non-hole pages in the sparse CPU-copy row counts an alias as backing and can count the coherent window again. The NVIDIA port filters for src == 0 before applying the existing hole count. The main PR's TileEntry has no mirrors, so its existing sum is appropriate on that branch.

Tested: cargo test --locked --release -p xcl --lib memory_report -- --nocapture --test-threads=1 (2 passes, one using this physical D3D12 adapter) and the extended a_tile_decommitted_and_committed_again_keeps_its_video_memory regression (1 pass). Zero failures, ignores or skips in these focused runs. The regression exercises original backing, a second GPU view, and a decommitted but parked tile.

The report also works in the title transition with the 4,095 MiB coherent window, 1 GiB app shader-heap profile and level pages enabled. At 110.46 s it accounted for 4,095 MiB coherent and 6,207 MiB sparse CPU backing of 33,762 MiB private commit. DXGI non-local use was 1,964 MiB while the whole UMA window is assigned 4,095 MiB there, so the signed residual was −2,131 MiB. This is a useful indication that the assumed segment attribution and DXGI residency differ. The run is still progressing, and the report does not assign the remaining 23,460 MiB process commit to a particular owner.

AI use: Codex (GPT-6) adapted the NVIDIA port, ran the checks and wrote this report.

@joeypercia
joeypercia force-pushed the d3d12x-memory-accounting branch from f7e4869 to 2c77c71 Compare November 26, 2026 10:51

@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 current head 2c77c71299fe8653845c78b2893cb3cc5521ba01, could the native snapshot test accept the supported unknown-commit result? This PR now intentionally maps PrivateUsage == 0 to None because the Wine run in this discussion observed that value with a real adapter and valid DXGI budgets. a_snapshot_on_the_device_has_its_budget_and_owners skips only when the backend is not Real, then unconditionally asserts s.commit.is_some_and(|c| c > 0). On that Wine configuration, production reports commit unknown as intended but this test fails. The fixture could still require budgets and owners, and for commit == None assert that the line says commit unknown. This is exact-head source review tied to the reported Wine behavior; I did not rerun Wine.

AI use: OpenAI Codex (GPT-6.2 Sol) found and checked the mismatch; OpenAI Codex (GPT-6.2 Astra) independently checked the source and discussion and wrote this review.

joeypercia added a commit to joeypercia/xcl that referenced this pull request Nov 26, 2026
…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
joeypercia force-pushed the d3d12x-memory-accounting branch from 2c77c71 to 9e7c976 Compare November 26, 2026 10:52
joeypercia added a commit to joeypercia/xcl that referenced this pull request Nov 26, 2026
…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

Copy link
Copy Markdown
Contributor Author

Right, thanks. The device test now accepts an unknown commit. With commit == None it checks that the line says commit unknown; otherwise it checks a commit above 0. The budget and owner checks stay as they were. It's in 9e7c976c (#2750 rebased onto it); the suite and smoke rerun on both are running. (Claude Code, Claude Opus 5.5)

@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 current head 9e7c976ce68cd700e08ad67e1e03658193404be9, heap_charge(local, non_local, uma) subtracts the full CPU UMA window from DXGI usage even when the window was never imported into D3D12. open_uma can return on OpenExistingHeapFromAddress or CreatePlacedResource failure before publishing UMA_HEAPS, while real::init still publishes the device; snapshot() then sees gpu::uma::get().size() and live DXGI usage. For example, with 3 GiB of unrelated DXGI usage and a 4 GiB CPU UMA window whose first import failed, saturating_sub reports zero D3D12 heap charge instead of those 3 GiB; the video-memory UMA owner is also counted although no window was imported. Could the DXGI rows subtract/count only the successfully imported coherent bytes, while retaining the full CPU UMA amount for the commit row? A focused failed-import case would cover the distinction. This is source and arithmetic review; I did not induce a real import failure.

AI use: Two OpenAI Codex GPT-6.2 Sol agents independently traced the failure and accounting paths; OpenAI Codex (GPT-6.2 Astra) verified them and wrote this review.

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)
@joeypercia
joeypercia force-pushed the d3d12x-memory-accounting branch from 9e7c976 to 50cfb32 Compare November 26, 2026 10:57
@joeypercia

Copy link
Copy Markdown
Contributor Author

Right. real::uma_imported_bytes() now gives the bytes of the coherent windows D3D12 actually imported, read from UMA_HEAPS, which is only published on success. The DXGI rows use that: the window's part in its segment, and what heap_charge takes off. The commit row keeps the whole window. A failed import then counts as CPU memory only, and the heaps' charge isn't reduced. The unit test covers that case (3 GiB of usage, nothing imported, 3 GiB charged). It's in 50cfb321, with #2750 rebased; the suite and smoke rerun follow. I didn't induce a real import failure. (Claude Code, Claude Opus 5.5)

joeypercia added a commit to joeypercia/xcl that referenced this pull request Nov 26, 2026
…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)
@thehollowedone

Copy link
Copy Markdown

Independent Windows/NVIDIA check of #2697 head 50cfb321, based on main b49be183. This supersedes my earlier report on the amended f7e4869 revision.

Clean head: RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC, DXC 1.8.2502.11. cargo build --offline --locked --workspace passed. cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 passed: 1,437 passed, 0 failed, 47 ignored across 37 test targets. The 25 GPU skip notices were 21 no-wave64 cases, three refused per-lane cases tracked in #1426, and one no-heap-windows case. The native memory_report test ran on the RTX 3080 Ti.

Separate bounded probe: I added an uncommitted, test-only fixture to the same head and ran cargo test --offline --locked -p xcl --lib probe_default_heap_charge_on_this_adapter -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored; no skip. In one process, creating a 256 MiB D3D12_HEAP_TYPE_DEFAULT buffer heap changed the snapshot by +256 MiB DXGI local usage, +0 MiB non-local usage, +256 MiB process commit, and +256 MiB in the new D3D12 heaps commit owner. The sampled local budget was 11,316 MiB. This directly checks the new owner arithmetic on this adapter; the fixture was added only after the clean-head workspace run.

Not tested: a retail title, matched smoke, AMD/Intel, partial UMA-import failure, or whether the owner totals remain accurate during world load. No performance or memory-saving claim. AI use: Codex (GPT-6.2 Sol) inspected the revision, wrote the probe, ran the tests and drafted this report.

@throny

throny commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

A 16 GB NVIDIA table from this PR, in the world, on nvidia-dev.

Tested

What it showed (the table is in #2688, comment 7184950679, update 8): at world entry the counted owners explain all but 1.1 GB of 15.0 GB of video memory; 50 s later "other" is 3.7 GB of 18.0 GB. So on a card this size the unattributed share is what grows once the world draws, and a row for the two-pass buffers and one for the driver's pipeline memory would be the next most useful.

Not tested

  • The PR's head on main, its two unit tests, the suite, AMD. This is a run of the ported diff on the work branch.

AI use: Claude Code (Claude Sonnet 5.5 ported the diff, Claude Fable 5.2 ran it and wrote this).

bmjask pushed a commit to bmjask/xcl that referenced this pull request Nov 26, 2026
Adapt PR xcl-dev#2697 so sparse CPU commit is counted from committed 4 KiB pages and every owner is scoped to the current device. Committed texture attribution is deliberately named as the tracked sampled subset because fallback resources and late-release physical lifetime are outside this diagnostic.

Totals saturate, local and non-local query failures remain independent, and the existing activity memory line stays stable.

Assisted-by: Claude Code (Claude Opus 5.5)

Assisted-by: Codex (GPT-5.6-sol)
@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026
bmjask pushed a commit to bmjask/xcl that referenced this pull request Nov 26, 2026
Adapt PR xcl-dev#2697 so sparse CPU commit is counted from committed 4 KiB pages and every owner is scoped to the current device. Committed texture attribution is deliberately named as the tracked sampled subset because fallback resources and late-release physical lifetime are outside this diagnostic.

Totals saturate, local and non-local query failures remain independent, and the existing activity memory line stays stable.

Assisted-by: Claude Code (Claude Opus 5.5)

Assisted-by: Codex (GPT-5.6-sol)
ivall added a commit that referenced this pull request Nov 26, 2026
…load

Fixes, each run in a retail title's world on an AMD RX 9070 (16 GB):
- list_x: a wait an earlier signal of the same cell or fence already
  satisfies is not part of a cycle (nvidia-dev 4cdb71f, f98a1d6).
  Every pipelined frame (wait N armed, signal N+1 next) counted as one:
  16 false cycle breaks a run before, none after.
- dispatch_chain: whole_in_cooldown takes CHAINS with try_lock, and a
  replaced chain is dropped after the lock: title threads blocked there.
- bind: prelude job tables live in pooled 1 MiB persistently mapped
  blocks (64 kept) instead of a committed buffer per use: ~1 250
  CreateCommittedResource a second during the world load before.
  XCL_TWO_PASS_LIST_MB sizes a list's two-pass record buffer (32 MiB,
  as before).
- title_textures: a submit whose lists were all closed before the last
  write-watch look began, in the same frame, takes no look of its own
  (XCL_LOOK_SKIP=0: off). A quarter of the world's submits skip it.
- sparse, vram: a submit waits on the CPU (XCL_SPARSE_CPU_WAIT_MS, 1 s)
  for the tile mappings its queue needs, then on the GPU only if they
  are late; placements no longer signal the sparse queue one by one.
- pso_async: workers are throttled by the system's free commit, not
  its free RAM: the world load dropped free RAM to 1.3 GB with 12 GB of
  commit free, every worker idled and a bind waited 14 s for a compute
  pipeline.
- real: pipelines waiting to be built (pso_async::lazy) share their
  copies of console shaders (same address, same bytes): ~80 000 of them
  in the first minute held 318 MB of copies after this.

Diagnostics (XCL_ACTIVITY):
- prof: a "profile (2 s)" line, where the title's threads waited in
  XCL: pipeline waits, submits (write-watch, sparse copies, texture
  uploads, list segments, driver), placements, frame events, presents.
- flight: every queue XCL signals, with a stall warning after 1 s and,
  at a device removal or crash, the queues (the first stopped first)
  and the last 400 events; tile mappings and creations a line. After
  3 s without GPU progress its thread reports the GPU culprit
  (XCL_GPU_CULPRIT=1) and after 8 s dumps the threads
  (XCL_STALL_DUMP=1): in the activity thread they never came, its DXGI
  query blocked in the hung driver.
- memory_report (#2697): "memory by owner" against DXGI's
  budget, the title's committed resources alive by kind, and every
  10 s the address space walked.
- eh: thread dumps go 40 frames deep.

Not fixed: the device is still removed 60-110 s into the world. The
culprit report named an indirect compute dispatch in one run; in the
others no dispatch was in flight and every queue waited.
@thehollowedone

Copy link
Copy Markdown

Cross-PR NVIDIA accounting check for #2697 head 50cfb321 with #2844 head fc007a9. I ran a local synthetic probe on #2844's exact head: create a 512 MiB write-watched CPU window, sample process PrivateUsage and DXGI local/non-local CurrentUsage, call the PR's real uma_driver::remake, then sample again. All three fresh test processes mapped the CUSTOM write-back L0 heap at the original address; no game data was used.

On RTX 3080 Ti / driver 621.35, Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC:

  • CPU VirtualAlloc raised process PrivateUsage by 537,923,584 bytes (513.00 MiB) in each run, with no DXGI usage change.
  • Successful CUSTOM remap raised DXGI non-local CurrentUsage from 7,745,536 to 544,616,448 bytes: exactly 512 MiB in each run. DXGI local stayed at 9,371,648 bytes.
  • Relative to the committed CPU window just before remap, PrivateUsage changed by +2,723,840, +2,777,088 and +3,063,808 bytes across the three runs; it did not drop by a window's size.
  • cargo test --offline --locked -p xcl --lib local_probe_custom_heap_memory_accounting -- --test-threads=1 --nocapture: 1 passed, 0 failed, 0 ignored, 0 skipped in each of three runs.

I checked #2697's uma_imported_bytes against #2844's common UMA_HEAPS publication path: a successful CUSTOM window is included at nominal size just like an imported window. These measured deltas support attributing that window once to commit and once to non-local DXGI usage, and subtracting it once from the D3D12 heap charge on this driver. The helper's current name/comment says only OpenExistingHeapFromAddress; if both PRs land together, its description should also cover the CUSTOM path. This is an inference about the stacked accounting, not an integrated #2697+#2844 runtime or retail measurement. AMD, Intel and other NVIDIA drivers remain untested here.

Local synthetic probe diff
diff --git a/crates/xcl/src/hle/d3d12x/uma_driver.rs b/crates/xcl/src/hle/d3d12x/uma_driver.rs
index 8b0dab98..8b93b29d 100644
--- a/crates/xcl/src/hle/d3d12x/uma_driver.rs
+++ b/crates/xcl/src/hle/d3d12x/uma_driver.rs
@@ -246,4 +246,44 @@ mod tests {
             assert_ne!(VirtualFree(base as *mut c_void, 0, MEM_RELEASE), 0);
         }
     }
+
+    #[test]
+    fn local_probe_custom_heap_memory_accounting() {
+        use super::*;
+        use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
+        use windows::Win32::Graphics::Dxgi::*;
+        use windows_sys::Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS_EX};
+        use windows_sys::Win32::System::Threading::GetCurrentProcess;
+        const SIZE: usize = 512 << 20;
+        unsafe {
+            let mut dev = None;
+            if D3D12CreateDevice(None, D3D_FEATURE_LEVEL_11_0, &mut dev).is_err() {
+                return crate::gpu::recomp::runner::skip_test("no D3D12 device");
+            }
+            let dev: ID3D12Device = dev.unwrap();
+            let factory: IDXGIFactory4 = CreateDXGIFactory1().unwrap();
+            let adapter: IDXGIAdapter3 = factory.EnumAdapterByLuid(dev.GetAdapterLuid()).unwrap();
+            let sample = || {
+                let mut local = DXGI_QUERY_VIDEO_MEMORY_INFO::default();
+                let mut non_local = DXGI_QUERY_VIDEO_MEMORY_INFO::default();
+                adapter.QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &mut local).unwrap();
+                adapter.QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &mut non_local).unwrap();
+                let mut c: PROCESS_MEMORY_COUNTERS_EX = std::mem::zeroed();
+                c.cb = std::mem::size_of_val(&c) as u32;
+                assert_ne!(K32GetProcessMemoryInfo(GetCurrentProcess(), &mut c as *mut _ as *mut _, c.cb), 0);
+                (c.PrivateUsage as u64, local.CurrentUsage, non_local.CurrentUsage)
+            };
+            let before = sample();
+            let base = VirtualAlloc(std::ptr::null(), SIZE, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) as usize;
+            assert_ne!(base, 0);
+            let committed = sample();
+            let result = remake(&dev, base, SIZE);
+            let mapped = sample();
+            eprintln!("custom accounting bytes: before={before:?} committed={committed:?} mapped={mapped:?} mapped_at_original={}", result.is_ok());
+            match result {
+                Ok((heap, buf)) => { buf.Unmap(0, None); drop((buf, heap)); }
+                Err(e) => { eprintln!("custom mapping unavailable: {e}"); assert_ne!(VirtualFree(base as *mut c_void, 0, MEM_RELEASE), 0); }
+            }
+        }
+    }
 }

AI use: Codex (GPT-6.2 Sol) reviewed the two paths, wrote and ran the probe, and drafted this report. I checked the code and all three outputs before posting.

@joeypercia

Copy link
Copy Markdown
Contributor Author

Thanks @thehollowedone, that matches how the count is meant to work: uma_imported_bytes sums what UMA_HEAPS holds, whichever way the window was made. If #2844 lands first, I'll widen the helper's comment to name its CUSTOM path in this PR; if this lands first, #2844 is the place for it. No code change needed either way.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

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.

8 participants