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

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.
  • 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; and that the table keeps the last snapshot and the one with the most video memory.

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 on d485694b:

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: d485694b216101c2d684d3395cfb93679cd39e56
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1533 (PresentX 1533)
presents per 2 s (last 3): 59 60 58
device removals: 0
crashes: 0
peak commit: 17259 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.

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

Copy link
Copy Markdown

Independent verification of PR #2776 at d485694b216101c2d684d3395cfb93679cd39e56 (stacked on #2750 / #2697, cleanly mergeable with main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7) on an RTX 3090 24 GB.

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 (test suite) and release (60 s smoke run), DXC 1.9.2602.17 (21d28f72).
  • cargo build --workspace -j 8 and cargo build --release --workspace -j 8: ok (exit 0).
  • Targeted tests:
    • cargo test -p xcl --lib hle::d3d12x::memory_report::tests -- --nocapture --test-threads=1: 3 passed, 0 failed, 0 ignored (0.34 s), including the_table_keeps_the_last_snapshot_and_the_peak_of_video_memory.
    • cargo test -p xcl --lib hle::d3d12x::resource_census::tests -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored (0.31 s).
    • cargo test -p xcl --lib report::tests -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored (0.11 s).
  • Full workspace suite (cargo test --workspace -j 8 --no-fail-fast -- --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): test_title_draws_with_a_root_signature_under_the_debug_layer, test_title_runs_under_the_debug_layer_with_dred, uploads_start_from_each_subresources_state.
  • Live report.json verification from the 60 s scripts/smoke.ps1 run on RTX 3090 (XCL_ACTIVITY=1):
    • memory_by_owner.last (seconds: 58.0293664) matches the final [58.029] memory by owner (MB): log line (commit_mb: 13983, video_mb: 6125, video_budget_mb: 23554, non_local_mb: 4688, non_local_budget_mb: 15298, all 14 owner entries, and other_mb: { "commit": 2330, "non-local": 463, "video": 842 }).
    • memory_by_owner.peak_video (seconds: 34.0184304) retained the earliest snapshot that reached the 6125 MB local video-memory plateau:
      {
        "seconds": 34.0184304,
        "commit_mb": 13966,
        "video_mb": 6125,
        "video_budget_mb": 23554,
        "non_local_mb": 4637,
        "non_local_budget_mb": 15298,
        "parts": [
          ["UMA window", "commit", 4095],
          ["sparse CPU copy", "commit", 837],
          ["D3D12 heaps", "commit", 6667],
          ["target pages", "video", 3541],
          ["target pools free", "video", 42],
          ["arenas", "video", 401],
          ["sparse tiles", "video", 837],
          ["sparse pools free", "video", 58],
          ["sparse pools retired", "video", 0],
          ["committed textures", "video", 401],
          ["UMA window", "non-local", 4095],
          ["sparse staging", "non-local", 64],
          ["sparse zero buffer", "non-local", 1],
          ["upload staging", "non-local", 64]
        ],
        "other_mb": {
          "commit": 2364,
          "non-local": 412,
          "video": 842
        }
      }

Regression run

main (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 (d485694b216101c2d684d3395cfb93679cd39e56):

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

Not tested

  • AMD / Intel / integrated single-segment GPUs, native wave64, D3D12 debug-layer tests, Wine (commit_mb: null when PrivateUsage reads 0), and crash-handler report.json emission on a live title fault.

AI use

  • Antigravity (agy) with gemini-4-argon-high (audited by gemini-4-argon-medium) built the debug and release workspace, ran the targeted tests, full 37-target test suite, and 60 s smoke run, verified report.json against xcl.log, and drafted this report.

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.

2 participants