Skip to content

D3D12.X: count and report what console code cannot reach in unified memory - #956

Closed
maximecmb wants to merge 1 commit into
xcl-dev:mainfrom
maximecmb:d3d12x-count-empty-buffer-views
Closed

maximecmb wants to merge 1 commit into
xcl-dev:mainfrom
maximecmb:d3d12x-count-empty-buffer-views

Conversation

@maximecmb

@maximecmb maximecmb commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #505. Diagnostics only: no behaviour change.

Once the coherent window is full, a console buffer XCL cannot place in unified memory becomes a plain PC resource, and every view of it gets an empty descriptor (num_records 0): a shader reads zeros there and its writes go nowhere. XCL counted these (NON_UMA_BUFFER_VIEWS) but never reported the count, and logged only the first one. So nobody can tell from a run whether the world load of the retail title creates thousands of them – which would fit the stop in #505 (the title stops submitting GPU work with no thread blocked in XCL, then its watchdog ends it) – or none.

In a hand-driven run of the retail title on main 077ce40 (RTX 5080): the coherent window was full (3998 / 4095 MB) from 43 s on; the world load started at ~44 s; the first #101 came at 59.5 s; presents and submits went to 0 at 62 s; the watchdog (+0x23cf683) at 90.4 s. 0 draws or dispatches skipped, 0 failed pipelines, 0 Wait64BitValueX timeouts, no title thread inside XCL or the driver at the crash. The single "buffer view … not in UMA" warning came at 14 s, and the log could say nothing more.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: OUTSIDE_UMA counts, by kind: buffer SRVs / UAVs / CBVs that get an empty V#, texture views XCL cannot shape (empty T#), console buffers that found no room in unified memory (coherent window and, where tried, sparse windows), committed console textures that found no room in the coherent window. The first of each kind is logged (its time shows when it starts). report.json gets them as d3d12.outside_uma (#[serde(default)], so older reports still read).
  • crates/xcl/src/host.rs: the XCL_ACTIVITY memory line (every 2 s) adds the coherent window's use and these counts, at its end (scripts/smoke.ps1 reads only its start). It reads unified memory through uma::current(), so reporting doesn't create it.
  • crates/xcl/src/gpu/uma.rs: current(), the title's graphics memory if it exists, without creating it (get() does), as @ettehn found; with a test that it's what get() made.
  • crates/xcl/src/hle/d3d12x/bind.rs: the "console code so far" line adds them too.
  • Tests in real.rs: each kind lands in its own field; a report without the field still reads.

Tested

  • NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug, DXC 1.9.2602.17
  • head 3261b74, rebased onto main 6efdabc
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 730 passed, 0 failed, 41 ignored
  • SKIPPED on this adapter (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware; no XCL_SAMPLE_* set

Regression run
main:

xcl-smoke v1
commit: 6efdabcdaac93ce5cc123a85e85deba5d49cb294
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1673 (PresentX 1673)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15184 MB

This PR:

xcl-smoke v1
commit: 3261b743ec8b256613b27978081f346f733bc7ee
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1674 (PresentX 1674)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14764 MB

Not tested

AI use

  • Claude Code, Claude Opus 5.5: read the run's log and report, wrote the change, the tests and this description, and ran the tests above.

🤖 Generated with Claude Code

@ettehn

ettehn commented Nov 24, 2026

Copy link
Copy Markdown

At ad2f675, the new two-second activity sampler in host.rs calls uma::get(), which initializes the global UMA on first access. In a fresh Windows test process I isolated that exact sampling expression: GLOBAL was unset before the sample, but afterward the sample reported 64 MiB used / 512 MiB coherent capacity and the allocator logged 12 GiB of sparse virtual address space. These are allocator/window figures, not physical VRAM consumption.

A local coherent_usage() accessor using GLOBAL.get().and_then(Option::as_ref) instead returned (0, 0) and left the global unset. After explicit initialization, the same accessor matched used() and size(). This keeps enabling XCL_ACTIVITY from bringing UMA up just to report its size. No retail files used.

Verification assisted by OpenAI Codex (GPT-6.2 Astra).

@maximecmb
maximecmb marked this pull request as ready for review November 24, 2026 09:51
@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@077ce40 (baseline 716 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
718 passed; 0 failed; 41 ignored   (exit 0)

Two more than the baseline. Note for the record: a first run of this patch, while the machine was also building another project, sat over 11 minutes in three title_textures tests and had to be stopped; with the box idle the same tree finishes in normal time and passes, so that was the environment, not the change.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

…emory

Once the coherent window is full, a console buffer XCL cannot place in
unified memory becomes a plain PC resource and its views get empty
descriptors: shaders read zeros there and their writes go nowhere. XCL
counted these views but never reported the count and logged only the
first, so a run could not show whether the retail title's world load
(#505) creates many of them.

Count, by kind: buffer SRVs / UAVs / CBVs with an empty V#, texture
views XCL cannot shape, console buffers and committed textures that
found no room in unified memory. The first of each kind is logged;
report.json gets them as d3d12.outside_uma, and the XCL_ACTIVITY memory
line and the "console code so far" line add them with the coherent
window's use. The activity line reads unified memory through the new
uma::current(), which does not create it (uma::get() would). No
behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maximecmb
maximecmb force-pushed the d3d12x-count-empty-buffer-views branch from ad2f675 to 3261b74 Compare November 24, 2026 10:24
@maximecmb
maximecmb marked this pull request as draft November 24, 2026 10:25
@maximecmb

Copy link
Copy Markdown
Contributor Author

@ettehn You're right, thank you. uma::get() is get_or_init, so the new activity line could create the title's graphics memory with default settings, in any process that hadn't made it yet. In a run the windows exist by 0.4 s and the first sample comes at 2 s, but nothing guaranteed that order.

Fixed in 3261b74 (squashed, rebased onto main 6efdabc):

  • gpu/uma.rs: uma::current(), GLOBAL.get().and_then(Option::as_ref), as you suggested. It doesn't create the memory.
  • host.rs: the activity line uses it. The other uma::get() calls this PR touches are main's own (the "console code so far" line, the report) and stay as they are.
  • A test that current() is what get() made. Whether it creates anything can't be checked in the shared test process, where other tests create the memory first; your isolated check covers that.

@dcastell1 thanks for the run. The head has changed since (above), and the regression run will be redone on it.

Tested on 3261b74: RTX 5080 (driver 617.42), Windows 11 26300, Rust 1.100.0 MSVC, debug. cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 730 passed, 0 failed, 41 ignored; SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

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

@maximecmb
maximecmb marked this pull request as ready for review November 24, 2026 10:30
@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head ad2f675 onto main 9aec53d, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 719 passed, 7 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows. unreachable-console-code counting tests green.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@thehollowedone

Copy link
Copy Markdown

A focused check on 3261b74 found that an intentional null CBV increments empty_cbv. D3D12 allows the view description pointer to be null. This can inflate the count or trigger the first warning before any real buffer falls outside unified memory.

Tested. Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug. A scratch test called dev_create_cbv_x on a registered console heap slot.

View PR head With the guard below
Address in unified memory +0 +0
Real native D3D12 buffer outside unified memory +1 +1
Null description pointer +1 +0

Changing the counter guard to if !in_uma && !desc.is_null() made the scratch test pass and preserved the descriptor words in all three cases. The two stock outside_uma_tests also passed. Both runs used cargo test --offline --locked -p xcl --lib <filter> -- --test-threads=1.

Not tested. How often a retail title creates null CBVs. The fixture checks descriptor creation and counters only.

AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch checks and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib real: 21 passed, 0 failed — includes outside_uma_tests::each_kind_lands_in_its_own_field and an_older_report_without_the_field_reads, covering the new unreachable-in-UMA counters and their report serialization.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@ettehn

ettehn commented Nov 24, 2026

Copy link
Copy Markdown

Confirmed the XCL_ACTIVITY fix on 3261b74 with the same isolated Windows regression probe. In a fresh test process, the sampler expression returned (0, 0) and left the UMA global unset. After explicit initialization, it returned the same used bytes and capacity as the initialized UMA object. One targeted test passed on Windows x64 (RTX 5070 Ti Laptop). OpenAI Codex (GPT-6.2 Sol) assisted with verification.

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.

6 participants