Skip to content

D3D12.X: XCL_WINDOW_STATS logs each memory window's traffic - #3627

Open
Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:d3d12x/window-stats
Open

Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:d3d12x/window-stats

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

(Edited: head bdec29f9f takes the second reviews: XCL_WINDOW_STATS uses the UMA region only once it exists, 0 is off, and an address range counts as outside when it runs past its run of adjacent windows of one kind (a root view, whose size is not known, is placed by its start). On main 38ad22d.)

An address the title gives the GPU outside every memory window is no GPU memory, and nothing said so (#3565: with 4 windows the title's GPU views lay outside them). With XCL_WINDOW_STATS=<seconds>, every that many seconds XCL logs a line for each memory window and one for the addresses given to the GPU outside every window, by path; the first 8 of each path are logged with what lies there. Off by default; then each counter is one load. Nothing is remapped.

What is in it

  • hle/d3d12x/window_stats.rs (new): per window its kind, range, bytes with memory on the GPU, and since the line before the bytes uploaded, the pages the write watch found written, the bytes read back and the GPU-view tiles filled; per view_want::Path the addresses outside every window, the first 8 placed (a GPU view of the title's memory, a graphics reservation, plain memory, nothing committed). Relaxed atomics, a logging thread started from host.rs.
  • Counted where the work already happens: sparse.rs (uploads, copy back, view tiles filled; mapped_by_window), title_textures.rs (pages the write watch found), view_want.rs and bind.rs (addresses outside every view window, root views).
  • README.md: the switch.

Tested

  • At bdec29f9f: Under Wine on Mesa's CPU Vulkan driver, release, 1 run: window_stats 5 passed, 0 failed; cargo test --lib -- window_stats file_reads write_log shader_mem console_heap eh:: at the top of the stack (D3D12.X: XCL_SHADER_MEM_STATS writes a placement table per allocation #3642, f1ae90ebb): 62 passed, 0 failed. zero_seconds_is_off and the outside-range case of traffic_adds_to_its_window_and_addresses_in_one_are_not_outside failed without the fix.
  • RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, debug, at the top of this stack (D3D12.X: XCL_SHADER_MEM_STATS writes a placement table per allocation #3642, head 5653fd69, with an earlier version of this PR's commit, before the second review's fixes): cargo test --workspace -- --test-threads=4, 2,931 passed, 0 failed, 51 ignored, 1 run; 28 SKIPPED lines (wave64 tests: no wave64 on this card; heap-window tests without XCL_HEAP_WINDOWS=1; no D3D12 debug layer). The stack's GPU tests (gpu_mem_stats_*, the writer and geometry-pass tests) ran and passed.
  • RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, Rust 1.98.0, x86_64-pc-windows-gnu, release. Tests under Wine on Mesa's CPU Vulkan driver (no card: the card was running a title).
  • cargo check -p xcl --release --target x86_64-pc-windows-gnu, with and without --tests: no errors, no new warnings.
  • cargo test -p xcl --release --target x86_64-pc-windows-gnu --lib -- --test-threads=8 window_stats view_want hle::d3d12x::bind sparse title_textures gpu::uma: 361 passed, 0 failed, 2 ignored; 3 GPU tests printed SKIPPED: no GPU. The new tests place addresses in the 16- and 4-window layouts and check the lines.
  • In title runs on our development tree, with XCL_SHADER_MEM_STATS (stacked after this), its lines and placement table showed a 1.34 GB GPU heap in a coherent window (system memory) that shaders read far more than the CPU wrote it; kernelx: XCL_COHERENT_HEAPS=sparse-wc puts write-combined GPU heaps in video memory #3619 moves that heap to video memory.

Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by scripts/smoke.ps1, the same retail title for 60 s each.

main:

xcl-smoke v1
commit: 5eaadb54c14e0fc29597b2a1689d7dbd83491303
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1575 (PresentX 1575)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15670 MB

this PR's head:

xcl-smoke v1
commit: 4b7c148bc2b8c66a896e24b4cf91efe8bac092fa
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15240 MB

Not tested

  • AMD, the switch on in a run from this branch (the runs were on our development tree, which carries other changes).

AI use

  • Claude Code, Claude Opus 5.5: wrote the change, its tests and this description, ported it to main and made the title runs.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Review (head 9a0ac0a, diff read, not a merge-check; draft, checks red):

  • "KB up" counts uploads that never happen. window_stats::uploaded(runs) is called when upload_dirty_with_timeout starts (sparse.rs ~4559), before the !uploads_ordered return, before the XCL_SPARSE_LAZY starved runs are dropped (~4593), and before the Wait / RetryRequired returns (~4580, ~4612, ~4630, ~4665). A run that gets Wait is scanned and sent again later (continue 'prepare ~5541, retry_journal ~7997), so the same bytes are counted twice and the per-window upload figure this PR exists to supply is too high under upload pressure. Counting what goes into a submitted batch (submit_upload / staged) avoids it.
  • "KB read back" counts skipped pages too. copy_back (~4252) counts the whole len on entry, while the loop below leaves out LAZY tiles, holes and tiles whose gen changed.
  • The counters have no test. The new tests cover place() and the line formatting; nothing checks which slot count, given, uploaded or written add to, that given ignores an address inside a window, or that log / mapped_by_window add up per window.
  • Regression run missing. Regression run has no xcl-smoke blocks (the reason PR description is red), and Tested is a filtered --lib run under Wine.

Fine: off by default, each hook is one OnceLock load when off, and want_view / want_root_views return the same results as before; place() is right for the 4- and 16-window layouts; the sparse lock is taken through lock_state / holding like the module's other readers.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

Thanks. Fixed at 4e2d288: KB up counts the copies of a submitted upload (submit_upload, after the submit succeeds), KB read back counts what copy_back lands, and two tests cover the counters' slots, given inside a window, and the per-window lines and mapped sums. #3628 is rebased onto it (bc55ba1fe) with no other change.

AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply.

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 4e2d288, since 9a0ac0a, diff read, not a merge-check; draft):

  • "KB up" counts uploads that never happen: fixed. submit_upload (sparse.rs ~4762) counts staged only when submit_dirty_batch returns Ok, so copies dropped by a Wait / RetryRequired return or by the starved-run drop are not counted.
  • "KB read back" counts skipped pages too: fixed. copy_back (~4267) counts each page inside the branch that lands it.
  • The counters have no test: fixed. traffic_adds_to_its_window_and_addresses_in_one_are_not_outside (window_stats.rs ~255) and mapped_bytes_add_up_per_window_without_lazy_tiles (sparse.rs ~11345) cover the slot choice, given_in, lines and by_window.
  • Regression run missing: partly fixed. Both xcl-smoke blocks are in (1665 vs 1620 frames, peak commit 111 %), and PR description passes; Tested is still a filtered --lib run under Wine, not the whole suite on a GPU.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Royalflamejlh
Royalflamejlh marked this pull request as ready for review December 2, 2026 04:10
@Decodere

Decodere commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 1c8b551
head: 4e2d288
merge: clean (fast-forward onto base, commit 4e2d288, git diff --check clean)
build: cargo build --workspace ok; cargo build --release -p xcl ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture (43 targets): 2914 passed, 0 failed, 51 ignored (+5 new tests vs main baseline). All 5 new unit tests passed with 0 skips: hle::d3d12x::sparse::tests::mapped_bytes_add_up_per_window_without_lazy_tiles and all 4 hle::d3d12x::window_stats::tests (an_address_is_placed_in_its_window_or_none, a_view_address_with_four_windows_is_in_no_window, traffic_adds_to_its_window_and_addresses_in_one_are_not_outside, the_lines_name_the_window_and_the_paths_outside). 28 SKIPPED lines (host environment only: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode required)).
review: Read the full merged diff (+367/-7 across README.md, host.rs, and 6 files in crates/xcl/src/hle/d3d12x/). Adds opt-in XCL_WINDOW_STATS=<seconds> (parsed with .max(1) into a OnceLock<Option<u64>>, off by default so no background thread spawns and every hook short-circuits in one branch). Counts per-window uploads, written pages, readbacks, and filled view tiles using relaxed AtomicU64 counters plus out-of-window GPU addresses by view_want::Path (logging the first 8 per path with region classification). In sparse.rs, iterating staged.iter() before submit_dirty_batch and calling staged.clear() unconditionally after recording window_stats::uploaded(staged) on Ok preserves cleanup without early-return leaks, and by_window excludes LAZY tiles cleanly under lock_state(). The 5 new unit tests verify 16-window and 4-window placement, traffic/outside deltas, line formatting, and lazy-tile exclusion. No scope creep, lock-order issues, or UB.
performance: Paired 60 s retail smoke (title: 29640639): default (unset) 1654 frames (+13.1% vs 1c8b551 baseline 1462 frames), 14630 MB peak commit (-8.8% vs 16043 MB), 0 removals, 0 crashes; opt-in XCL_WINDOW_STATS=10 1655 frames, 14604 MB peak commit, 0 removals, 0 crashes (live xcl.log confirmed startup banner, 10 s periodic lines for windows 0..3 and outside-every-window traffic, plus views by address outside-window entries).

Default (XCL_WINDOW_STATS unset):

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

Opt-in (XCL_WINDOW_STATS=10):

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

verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
@github-actions github-actions Bot removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 4b7c148, since 4e2d288, diff read, not a merge-check; checks red):

  • Earlier points: unchanged. git range-diff shows the own commit identical to the previous one; this push only rebases the stack onto the current main.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of 2580976a, since 4b7c148b (code reading only, not a merge-check; PR description red) · 1 medium

In short: This push reworks the PR's own commit:

  • XCL_WINDOW_STATS=0 now turns the stats off;
  • the stats read the UMA region only once it exists (uma::existing());
  • a range whose end runs past its window now counts as "outside every window".

The new end check also counts ranges that are inside the memory windows: ranges that cross between two adjacent sparse or view windows, and root views near a window's end, checked against an assumed 64 KiB. The smoke blocks name 4b7c148b, and the whole-suite GPU run predates this push (PR description is red).

Medium

  1. Ranges that cross between windows of the same region count as "outside every window".

    • given_in (window_stats.rs ~111) treats a range as inside only when its first and last byte fall in the same 4 GiB window index.
    • The sparse windows are one reservation, and a title's reservation can run across them (uma.rs ~440: "one contiguous range of 11.5 GiB"). GPU views can cross view windows too. A view or copy crossing a 4 GiB line inside a title reservation is then logged as "only its start does, in window 0".
    • want_root_views (bind.rs ~1615) passes ROOT_VIEW_BYTES (64 KiB), an assumed size, so every root view in the last 64 KiB before a 4 GiB line, or of the coherent window's committed bytes, is flagged the same way.
    • These false counts land in the number this PR exists to report (Memory: with the default 4 UMA windows the retail game's world renders black on the Series S profile; XCL_UMA_WINDOWS=16 draws it #3565).

    Fix: accept an end in the same run of adjacent windows of one kind, and check only the start of root views. Add a test with a range that crosses from window 0 into window 1.

Checked and fine
  • Earlier finding fixed: "KB up" counted uploads that never happen. It is now counted only when submit_dirty_batch returns Ok (sparse.rs ~4765).
  • Earlier finding fixed: "KB read back" counted skipped pages. It is now counted inside the branch that lands the page (~4270).
  • Earlier finding fixed: the counters had no test. Now traffic_adds_to_its_window_and_addresses_in_one_are_not_outside and mapped_bytes_add_up_per_window_without_lazy_tiles.
  • every returns None for 0 and for text that is not a number (zero_seconds_is_off).
  • on() and log() use uma::existing(), so the stats never create the UMA region.
  • The coherent-window case in the new test is right: a 2-byte range at end - 1 is counted, one at end - 2 is not.
  • given still returns early for address 0, and the end arithmetic cannot overflow.
  • Off by default; each hook costs one OnceLock load when off.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

An address the title gives the GPU outside every memory window is no GPU
memory, and nothing said so: with 4 windows the title's GPU views lay
outside them and the world's mesh programs read empty meshlet lists
(xcl-dev#3565). With XCL_WINDOW_STATS=<seconds>, every that many seconds:

- a line for each window: kind, range, bytes with memory on the GPU
  (tiles of a sparse or view window, the committed bytes of a coherent
  one), and since the line before the bytes uploaded into it, the pages
  the write watch found written, the bytes read back and the GPU-view
  tiles filled;
- a line with the addresses given outside every window, by
  view_want::Path, and the pages written outside them.

The first 8 addresses of each path outside every window are logged with
their size and what lies there (a GPU view of the title's memory, a
graphics reservation, plain memory, nothing committed). The counters are
relaxed atomics where the uploads, read-backs, write-watch looks, mirror
fills and view_want asks already happen; off, each is one load. Nothing
is remapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

Right: the sparse windows hold one contiguous title reservation, and root views pass an assumed 64 KiB. Fixed at bdec29f9. A range is inside when its last byte lies in its start's window or in the windows of the same kind that run on from it without a gap (in_run, window_stats.rs). A root view is placed by its start alone. The test now has a range from window 0 into window 1 (inside), from sparse window 2 into the coherent window and past the last view window (both outside), and a 64 KiB root view at the coherent window's last byte (inside). It failed without the fix, 1 run under Wine.

AI use: Claude Code (Claude Opus 5.5) made the changes and wrote this reply.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of bdec29f9, since 2580976a (code reading only, not a merge-check; PR description red) · no new findings

In short: This push fixes the window-crossing count from my last review. A range now counts as inside when its last byte lies in the same window or in the adjacent windows of the same kind that run on from it (in_run, window_stats.rs). A root view, whose size is not known, is placed by its start only. The test covers ranges crossing 0→1, 2→3 and past the last window. The smoke blocks name 4b7c148b (PR description is red).

Checked and fine
  • Earlier finding fixed: ranges crossing between windows of the same region counted as outside. in_run accepts last in windows k..=end when every window in between has the same kind and is full-size (u.window(j).1 == WINDOW), so a reservation spanning sparse or view windows counts as inside.
  • Earlier finding fixed: root views near a window's end were checked against an assumed 64 KiB. Path::RootView now uses last = va.
  • The new test cases: a CBV crossing from sparse window 0 into 1 is not counted. One at the coherent window's end, one crossing 2→3 and one past window 10 are counted (3 constant buffer views in the expected line). A 64 KiB root view at the coherent end is not counted.
  • The earlier fixes (uploads and readbacks counted only when they happen, the counter tests, XCL_WINDOW_STATS=0, uma::existing()) are unchanged.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants