Skip to content

D3D12.X: report.json keeps the memory by owner at its peak and at the end - #2776

Open
joeypercia wants to merge 3 commits into
xcl-dev:mainfrom
joeypercia:d3d12x-memory-table
Open

joeypercia wants to merge 3 commits into
xcl-dev:mainfrom
joeypercia:d3d12x-memory-table

Conversation

@joeypercia

@joeypercia joeypercia commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2750 (itself on #2697); only the top commit belongs here.

report.json gets the memory table workstream 1 of #2688 asked for: the snapshot by owner where video memory in use was highest, and the last one of the run, in MB. Runs can be compared from their reports instead of their logs. Part of #2688 (workstream 1, part 2 of the plan there).

What is in it (one commit)

  • crates/xcl/src/hle/d3d12x/memory_report.rs:
    • Record is a snapshot as the report keeps it, with owned strings so the report can be read back: the second of the run, commit, video and non-local usage with their budgets, XCL's parts as (owner, memory, MB), and the rest of each total.
    • Table holds last and peak_video. note keeps them, and table() hands them to the report. The peak is chosen on DXGI's CurrentUsage in bytes (kept beside it, not written to the report), not on the MB, and a known reading ranks above an unknown one.
  • crates/xcl/src/host.rs: the XCL_ACTIVITY thread takes one snapshot every 2 s. It logs that snapshot's line, as before, and now also notes it.
  • crates/xcl/src/report.rs: memory_by_owner (with #[serde(default)]: older reports still read). The report copies what was kept and makes no DXGI call, because a crash report can be written from any thread. Without XCL_ACTIVITY the table is empty.
  • Test the_table_keeps_the_last_snapshot_and_the_peak_of_video_memory: a record's totals, budgets, parts and rests in MB; a JSON round trip; that the table keeps the last snapshot and the one with the most video memory; that of two readings within one MB it keeps the higher one in bytes, with its own parts; and that a known reading under 1 MB ranks above an earlier unknown one. The last two fail on a ranking by MB.

The newer retail title on an RTX 4070 Ti 12 GB (nvidia-dev af2cecc4 with this stack, 1 GiB shader heap). The run ended in a device removal at 282 s, and the table was in the report all the same. peak_video:

{
  "seconds": 279.7938144,
  "commit_mb": 35641,
  "video_mb": 14438,
  "video_budget_mb": 10534,
  "non_local_mb": 5743,
  "non_local_budget_mb": 15162,
  "parts": [
    [
      "UMA window",
      "commit",
      4095
    ],
    [
      "sparse CPU copy",
      "commit",
      2538
    ],
    [
      "D3D12 heaps",
      "commit",
      16085
    ],
    [
      "target pages",
      "video",
      6859
    ],
    [
      "target pools free",
      "video",
      116
    ],
    [
      "arenas",
      "video",
      401
    ],
    [
      "sparse tiles",
      "video",
      2581
    ],
    [
      "sparse pools free",
      "video",
      170
    ],
    [
      "sparse pools retired",
      "video",
      0
    ],
    [
      "committed textures",
      "video",
      415
    ],
    [
      "UMA window",
      "non-local",
      4095
    ],
    [
      "dispatch chain scratch",
      "video",
      391
    ],
    [
      "sparse readback",
      "non-local",
      16
    ],
    [
      "sparse staging",
      "non-local",
      64
    ],
    [
      "sparse zero buffer",
      "non-local",
      1
    ]
  ],
  "other_mb": {
    "commit": 12921,
    "non-local": 1566,
    "video": 3500
  }
}

(UMA window appears twice: once in commit, as CPU memory, and once in non-local, where DXGI counts the imported window.)

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, 1 GiB) installed on this machine. main b49be183 (the base of the stack) 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: c5d9342194c00aef2ca68cab84940e2b3d2f445d
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1557 (PresentX 1557)
presents per 2 s (last 3): 60 59 60
device removals: 0
crashes: 0
peak commit: 17397 MB

Not tested

  • A report written by a crash handler while the activity thread held the table's lock. table() uses try_lock and gives an empty table then, rather than waiting.
  • Runs without XCL_ACTIVITY: no table, by design (a snapshot costs a DXGI query).
  • AMD in a title, and the suite on RDNA2 at this head.

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.

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)
@MatyEjsr

MatyEjsr commented Nov 26, 2026 •

Copy link
Copy Markdown

Updated independent verification of PR #2776 at c5d9342194c00aef2ca68cab84940e2b3d2f445d (superseding the earlier d485694b report) on an RTX 3090 24 GB.

Review follow-up & branch status

  • Verified both peak-ranking fixes in c5d93421 (crates/xcl/src/hle/d3d12x/memory_report.rs): Table keeps #[serde(skip)] peak_video_bytes: Option<u64>, note() compares raw DXGI CurrentUsage bytes (ranking known readings above None), the_table_keeps_the_last_snapshot_and_the_peak_of_video_memory covers both sub-MiB tie-breaking and < 1 MiB vs None, and live report.json omits peak_video_bytes.
  • Cleanly mergeable with current origin/main (8b957bec, merge-base b49be183); no duplicate PRs in the queue (stacked on D3D12.X: count the resources XCL makes for itself, by where it makes them #2750 -> D3D12.X: a memory line by owner, against DXGI's budget #2697; not superseded on origin/nvidia-dev af2cecc4, though the stack conflicts with origin/nvidia-dev in mod.rs/sparse.rs).

Tested

  • Environment: Windows 11 Pro for Workstations 10.0.26200 (Build 26200, Developer Mode enabled), AMD Ryzen 7 7800X3D, 31.4 GB RAM, NVIDIA GeForce RTX 3090 (24322 MiB VRAM, driver 617.42 / 32.0.16.1742, wave32), rustc 1.100.0 (0ef1bc386 2026-11-09) (x86_64-pc-windows-msvc), debug (builds + test suite) and release (build + 60 s smoke), DXC 1.9.2602.17 (21d28f72).
  • cargo build --workspace -j 8 and cargo build --release --workspace -j 8: ok (exit 0).
  • Targeted tests (--nocapture --test-threads=1):
    • cargo test -p xcl --lib hle::d3d12x::memory_report::tests -- --nocapture --test-threads=1: 3 passed, 0 failed, 0 ignored (0.33s).
    • cargo test -p xcl --lib hle::d3d12x::resource_census::tests -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored (0.30s).
    • cargo test -p xcl --lib report::tests -- --nocapture --test-threads=1: 4 passed, 0 failed, 0 ignored (0.40s; matches 3 in memory_report::tests + 1 in report::tests).
  • Full workspace suite (cargo test --workspace -j 8 --no-fail-fast -- --nocapture --test-threads=8): 1439 passed, 0 failed, 47 ignored across 37 targets.
  • SKIPPED checks on this host (28 total, not counted as GPU coverage):
    • no wave64 (21): gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole, 4 in gpu::recomp::lower::tests, 14 wave64 cases in gpu::recomp::lower_dxil::tests, and 2 in gpu::recomp::tests (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware).
    • per-lane form: refused (3 sub-cases in gpu::recomp::lower_dxil::tests): f16_programs_on_the_gpu (f16 arithmetic, wave32; f16 packed, wave32) and f32_programs_on_the_gpu (f32 conversions, wave32).
    • no heap windows (1): heap_window_out_of_memory_falls_back_to_the_switch_form (default env).
    • no D3D12 debug layer / no d3d12SDKLayers.dll (3): the title under the debug layer (dred: false), the title under the debug layer (dred: true), uploads_start_from_each_subresources_state.
  • Live report.json verification from the 60 s scripts/smoke.ps1 run (XCL_ACTIVITY=1, 29 memory by owner (MB): samples):
    • peak_video_bytes is absent from serialized report.json.
    • memory_by_owner.last (seconds: 58.1652405) matches the final [58.165] log line on every field (commit_mb: 13962, video_mb: 6126, video_budget_mb: 23554, non_local_mb: 4654, non_local_budget_mb: 15298, all 14 parts tuples, and other_mb: { "commit": 2343, "non-local": 461, "video": 842 }).
    • memory_by_owner.peak_video (seconds: 34.1536177) matches the peak [34.154] log line on every field (commit_mb: 13949, video_mb: 6189, video_budget_mb: 23554, non_local_mb: 4578, non_local_budget_mb: 15298, all 14 parts tuples, and other_mb: { "commit": 2343, "non-local": 385, "video": 841 }).

Regression run

main (merge-base b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3090
title: c1cc91a4
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: 14104 MB

PR (c5d9342194c00aef2ca68cab84940e2b3d2f445d):

xcl-smoke v1
commit: c5d9342194c00aef2ca68cab84940e2b3d2f445d
gpu: NVIDIA GeForce RTX 3090
title: c1cc91a4
seconds: 60
exit: 0x0
frames shown: 1560 (PresentX 1560)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13963 MB

(102.8% of main frames, 99.0% of main peak commit; 0 device removals, 0 crashes.)

Not tested

  • AMD / Intel / integrated single-segment GPUs, native wave64, D3D12 debug-layer tests, Wine (commit_mb: null when PrivateUsage reads 0), default XCL_ACTIVITY=0 omission, and crash-handler report.json lock-contention fallback (try_lock).

AI use

  • Antigravity (agy) with gemini-pro-orchestrator-argon (audited by gemini-pro-orchestrator-argon) checked out c5d9342194c00aef2ca68cab84940e2b3d2f445d, built debug and release workspaces, ran targeted tests, the 37-target workspace suite, and the 60 s smoke test, verified report.json <-> xcl.log parity, and drafted/audited this report.

@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2776 at d485694b216101c2d684d3395cfb93679cd39e56 (stacked on PR #2750 44a7e6fe -> PR #2697 50cfb321; 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 (d485694b)

  • cargo test --release -p xcl --lib hle::d3d12x::memory_report:: -- --nocapture: 3 passed, 0 failed, 0 ignored (0.38 s, 0 skipped, exit 0), covering the_table_keeps_the_last_snapshot_and_the_peak_of_video_memory, the_rest_is_the_total_less_the_parts, and live RTX 4060 a_snapshot_on_the_device_has_its_budget_and_owners.
  • cargo test --release -p xcl --lib hle::d3d12x::resource_census:: -- --nocapture: 1 passed, 0 failed, 0 ignored (0.36 s, live RTX 4060, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib report:: -- --nocapture: 4 passed, 0 failed, 0 ignored (0.37 s, report::tests::a_crash_is_kept_while_another_thread_writes_the_report + 3 memory_report::tests, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib hle::d3d12x::sparse:: -- --test-threads=4: 17 passed, 0 failed, 1 ignored (0.40 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.90 s, 0 skipped, exit 0).

Live 8 GB RTX 4060 report.json memory_by_owner verification (60 s, d485694b)

  • 1:1 report.json <-> xcl.log parity across 29 snapshots: report.json serialized both memory_by_owner.peak_video (t = 18.037 s) and memory_by_owner.last (t = 58.062 s), matching the peak-VRAM and final memory by owner (MB): log lines on every single field (commit_mb, video_mb, video_budget_mb, non_local_mb, non_local_budget_mb, all 14 parts tuples, and all 3 other_mb values):
Field peak_video (18.037 s) last (58.062 s)
commit_mb (UMA / sparse CPU / D3D12 heaps / other) 13,961 (4095 / 838 / 6647 / 2379) 13,970 (4095 / 838 / 6670 / 2365)
video_mb / video_budget_mb 6,176 / 6,958 (88.8% of budget) 6,116 / 6,958 (87.9% of budget)
— target pages / target pools free / arenas 3543 / 40 / 465 3540 / 43 / 401
— sparse tiles / pools free / pools retired 838 / 57 / 0 838 / 57 / 0
— committed textures / video other 402 / 829 402 / 832
non_local_mb / non_local_budget_mb 4,566 / 15,556 (29.4%) 4,650 / 15,556 (29.9%)
— UMA / sparse staging / zero buf / upload staging / other 4095 / 64 / 1 / 32 / 373 4095 / 64 / 1 / 32 / 457
  • Quiet 60 s retail smoke ran cleanly (exit: 0x0, 1603 frames shown, 60 60 60 steady-state presents per 2 s, 0 device removals, 0 crashes, 13971 MB peak commit vs origin/main b49be183's 14018 MB / 1518 frames).

Paired 60 s RTX 4060 smoke (b49be183 vs d485694b)

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 #2776 head (d485694b):

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

Limits of coverage

  • Full workspace test suite was not re-run on d485694b (only targeted memory_report::, resource_census::, report::, sparse::, and title_textures:: release tests plus paired quiet 60 s smoke).
  • Verified with XCL_ACTIVITY=1 on a discrete 8 GB NVIDIA GPU (RTX 4060) on native Windows 11; default XCL_ACTIVITY=0 omission behavior, crash-time report writes, and UMA/iGPU systems were not exercised in this smoke.

AI use

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

@Prime1997 Prime1997 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please rank peak samples by raw DXGI bytes. The top commit selects peak_video after rounding CurrentUsage to MiB. Sample 104,857,600 bytes, then 104,858,623 bytes with a different owner breakdown. Both display as 100 MiB, so the report can keep the earlier breakdown even though the second usage is higher. An unknown reading can similarly mask a later known reading below 1 MiB.

Keep an optional raw-byte value for selection, rank a known sample above unknown, and retain the existing MiB output. Please add both cases to the peak-selection test; distinct whole-MiB fixtures cannot detect this. The issue is in this top commit. Hosted Windows results and the reported hardware checks are useful, but there was no independent NVIDIA execution here because the stack conflicts with af2cecc4.

AI use: Codex (GPT-6) reviewed the pinned changes and verified the reported evidence. Optional temporary Discord for coordinating contributor work, testing, and comparing results.

… 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)
@joeypercia

Copy link
Copy Markdown
Contributor Author

Thanks, both cases were real: note compared video_mb after the shift to MB, and unwrap_or(0) put an unknown reading level with a known one under 1 MB.

Fixed in c5d93421 (squashed into the top commit). Table keeps the peak's CurrentUsage in bytes beside it (#[serde(skip)], so the report's MB output is unchanged), and note replaces the peak when Option<u64> bytes are greater, which ranks a known reading above an unknown one. The test now has both of your cases: 100 MiB then 100 MiB + 1,023 B with a different commit (the second is kept, with its own breakdown), and an unknown reading, then 512 KiB, then unknown again (the 512 KiB one is kept). With the old ranking put back, the test fails at the first of them (it keeps the 10 s sample).

Reran on the new head, RTX 4070 Ti: cargo test --workspace --no-fail-fast -- --test-threads=4 1439 passed, 0 failed, 47 ignored, and a new smoke block in the description (1557 frames, no removal, peak commit 17,397 MB). RDNA2 was not rerun at this head.

AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and wrote this reply.

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the memory-report table test at c5d93421 on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib the_table_keeps_the_last_snapshot_and_the_peak_of_video_memory -- --test-threads=1
1 passed; 0 failed; 0 ignored; 0 measured; 1339 filtered out      (exit 0)

The test passes: it covers the JSON round trip, keeping the last snapshot and the peak by video bytes, and the byte-level tie-break that would fail if the ranking were done in MB. This is a CPU-side report-serialization test; the report copies what was noted and makes no DXGI call. The thread has RTX 5090 + Radeon iGPU and RTX 4060 reports, but no 5070 Ti; this adds a Blackwell desktop datapoint on driver 32.0.16.2124 with DXC 1.9.2609.5.

Not tested: a real XCL_ACTIVITY run producing the table, a paired 60 s smoke run, the full workspace suite, release profile, AMD and Intel GPUs, native wave64 hosts, Wine, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

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.

5 participants