Skip to content

D3D12.X: a full write-watch buffer goes on after its last page - #347

Merged
theaustinayers merged 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/write-watch-resume
Nov 24, 2026
Merged

theaustinayers merged 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/write-watch-resume

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

refresh_once looks for CPU writes before each of the title's submits. When its 16,384-entry GetWriteWatch buffer came back full, it asked again from the start of the range. The pages already reported had been reset, but every call walked them again, so a look over many written pages cost more than one pass. take_written now continues after the last page reported.

Related:

What is in it

  • title_textures::take_written: one range's look, each call starting after the last page the previous one reported. The pages found, their order and the reset are the same as before.
  • Test written_pages_past_a_full_buffer_are_all_found_once: a 64-entry buffer over 1,000 write-watched pages, with 857 pages written, then 128 (exactly two buffers full). Each page is found once and in order, and a second look finds none. When the line that moves past the reported pages is replaced with break (stop at a full buffer), the test fails.
  • Timing from a standalone synthetic program (no XCL code). It runs the same GetWriteWatch(WRITE_WATCH_FLAG_RESET) sequence with a 16,384-entry buffer on committed, resident, write-watched memory. Medians of 5–15 looks, Ryzen 9 9950X:
watched pages written from the start (before) after the last page (this PR)
256 MiB all 1.38 ms (5 calls) 1.15 ms (4 calls)
1 GiB 1 in 16 1.28 ms 0.82 ms
1 GiB all 13.5 ms (17 calls) 9.7 ms (16 calls)
4 GiB 1 in 16 12.4 ms 7.9 ms
4 GiB all 105 ms (65 calls) 47 ms (64 calls)
4 GiB none / 1 in 256 1.78 / 2.09 ms 1.75 / 2.06 ms (one call either way)

The difference appears only once a look needs more than one call, i.e. more than 16,384 written pages (64 MiB).

Tested

  • RTX 5070 Ti (NVIDIA 610.74), Ryzen 9 9950X, Windows 11 26200; rustc 1.99.0; debug build.
  • cargo test --workspace -- --test-threads=4:
    • this PR (d6cbfcd on 85bdf21): 666 passed, 0 failed, 41 ignored over 16 test binaries (lib: 626 / 0 / 21). Two GPU tests print SKIPPED (no wave64 on this GPU): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
    • main 85bdf21, the control: 665 passed, 0 failed, 41 ignored (lib: 625 / 0 / 21), the same two SKIPPED. The one test more is this PR's.
  • Independent run by @nullmarsh (D3D12.X: a full write-watch buffer goes on after its last page #347 (comment)): AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32029.2010), Ryzen 7 5800X3D, Windows 11 26200, Rust 1.100.0, debug, d6cbfcd merged onto main a6f5f7a. scripts/test.ps1: 677 passed, 0 failed, 41 ignored, no SKIPPED GPU tests.
  • Independent run by @throny (D3D12.X: a full write-watch buffer goes on after its last page #347 (comment)): RTX 4080 (driver 610.88), i9-12900K, Windows 11 26300, Rust 1.100.0, debug, d6cbfcd merged onto main a6f5f7a. cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored (lib 637 / 0 / 21), the two no-wave64 skips. With the advance replaced by break, the new test fails on its first case (857 pages written).
  • Earlier smoke runs by @CuteBooty, RTX 3070 (NVIDIA 617.14), release, on main 85bdf21 and this head: 910 and 912 frames, no crash or device removal (D3D12.X: a full write-watch buffer goes on after its last page #347 (comment)).

Regression run

Our own runs, one after the other on the machine under Tested (RTX 5070 Ti), release builds, no uncommitted changes.

main:

xcl-smoke v1
commit: 0e946cfc68244edee1fba6e0425371f687a05ccd
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1481 (PresentX 1481)
presents per 2 s (last 3): 49 59 60
device removals: 0
crashes: 0
peak commit: 14741 MB

PR:

xcl-smoke v1
commit: d6cbfcd31c1da1edbf6513211e103755f7d8de6f
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1491 (PresentX 1492)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14542 MB

Not tested

  • How many pages a title's look finds: the timing is synthetic, and the smoke runs above do not measure it.
  • The clean-scan cost per GiB, the Open item's main part, which this PR does not change.
  • AMD, Wine.

AI use

  • Claude Code (Claude Opus 5.5): measured the cost, wrote the change, the test and this description.

🤖 Generated with Claude Code

refresh_once asked GetWriteWatch again from the range's start whenever its
16,384-entry buffer came back full. The pages already reported had been reset,
but each call walked them again. A range with many written pages therefore
cost more than one pass: 4 GiB with every page written took 105 ms a look,
and 47 ms when each call starts after the last page reported.

take_written does the look for one range and continues from there.

Test: written_pages_past_a_full_buffer_are_all_found_once. A 64-entry buffer
over 1,000 pages, with 857 and 128 pages written: each page is found once, in
order, and the look resets them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ghost

ghost commented Nov 24, 2026

Copy link
Copy Markdown

AMD run: d6cbfcd merged onto main a6f5f7a (clean merge): pass.

Tested

  • AMD Radeon RX 9060 XT (RDNA4), driver 32.0.32029.2010; Ryzen 7 5800X3D; Windows 11 Pro 26200; Rust 1.100.0; DXC 1.9.2602.17; debug build.
  • .\scripts\test.ps1: 677 passed, 0 failed, 41 ignored; no SKIPPED GPU tests.
  • cargo test -p xcl --lib written_pages: written_pages_past_a_full_buffer_are_all_found_once passes.

Not tested

  • No run without the fix: the test is in title_textures.rs with it.
  • A title; Wine.

AI use

  • Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs; I checked it before posting.

@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

NVIDIA run with the negative control the AMD report above lists under Not tested: d6cbfcd merged onto main a6f5f7a (clean merge, merge commit dacaa0a): pass.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored (lib: 637 / 0 / 21, written_pages_past_a_full_buffer_are_all_found_once ok)
  • SKIPPED on this adapter: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)
  • Negative control: with the line at = buf[n - 1] as usize + *page as usize; replaced by break; (stop at a full buffer, as the description says), cargo test -p xcl --lib written_pages_past_a_full_buffer fails on the first case (857 pages written).

Reviewed (read the whole diff)

  • The loop ends on a failed call, an empty or partly filled buffer, or at reaching end (a buffer that fills exactly on the last page), so it cannot spin. Going on after buf[n - 1] relies on GetWriteWatch reporting addresses in ascending order; the test's ordered comparison shows that on this Windows build.

Not tested

  • The timings (no timing run here), no regression run (scripts/smoke.ps1) on a title, no XCL_SAMPLE_* game-data tests, release build.

AI use

  • Claude Code (Claude Fable 5.2) ran the build, the tests and the control, read the diff and wrote this report. The runs above are real, on the hardware named.

@srcamarda

Copy link
Copy Markdown
Contributor

The write-watch look measured past the menus on a retail title, for the HANDOFF Open item this PR names ("costs in proportion to their size at every submit … pending measurement past the menus"). This is a measurement of main, not a run of this PR.

Setup: main a6f5f7a, release; RX 7800 XT (RDNA3, driver 32.0.32029.2010), Ryzen 5 5600G, 32 GB; Windows 11 Pro 26300; XCL_NETWORK=0 XCL_ACTIVITY=1, menus walked with XCL_PRESS_A_AT / XCL_PRESS_AT. To get the cost per 2 s rather than at power-of-two submit counts, a local line next to the activity line printed the change in sparse::WATCH (µs in refresh_once's GetWriteWatch loop, and dirty pages) every 2 s. That line is not part of any PR. The runs stop when free system commit falls under 3 GB (here at ~20.8 GB of XCL process commit, ~15 s into world loading).

Per 2 s, one run (the cumulative sparse windows timing lines of four other runs agree: 1.38–1.45 ms a submit from 28 s on):

phase fps submits/s write-watch per submit share of wall time dirty pages per 2 s
intro movie 3.5–4 ~22 ~1.0 ms ~2 % ~23 000
menus and the loading screen 30 150 1.27–1.32 ms ~19 % ~575
world loading (first ~15 s) 1–11 5–74 1.4 → 2.5 ms 1–17 % 7 000 → 102 000

Example lines from the 30 fps loading screen, and from world loading:

fps 30.0  submits/s 150.0  ww 383 ms (19.1% wall)  1.28 ms/submit  dirty    572
fps 11.0  submits/s  69.5  ww 346 ms (17.3% wall)  2.49 ms/submit  dirty 102086

What it shows

  • On the menus and the loading screen the look costs ~1.3 ms a submit, ~19 % of wall time at 150 submits a second, while the CPU writes almost nothing (~290 pages a second). So it is the clean look: the cost grows with what is watched, not with what is written.
  • The per-submit cost rises from 0.25 ms at the start to ~1.4 ms over the first two minutes, while the title creates the textures kept in step, then stays flat.
  • In world loading it rises further, to 2.5 ms a submit, as the written pages go to ~50 000 a second. The frame rate there is held down by the loading itself, so the share of wall time varies.
  • At ~4 submits a frame it is ~5 ms of each 33 ms frame on the menus. The title stays at 30 fps there, so it costs no frames yet, but it is CPU time on the submit path.
  • In these runs the 16 384-entry buffer does not fill on the menus (~1 dirty page per submit). So this PR's change would not show there; it may in world loading. I did not run this PR.

Not tested: this PR's head; further into world loading than ~15 s (the commit limit on this machine); NVIDIA.

AI use: Claude Code with Claude Opus 5.5 ran the builds and runs, the local instrumentation and the analysis, and wrote this report. The runs are from my machine.

@CuteBooty

Copy link
Copy Markdown

Regression run on a retail title for d6cbfcd, which the description lists as pending: pass (no device removal, no crash, frames and peak commit level with main).

Tested

  • RTX 3070 8 GB (32-lane waves), NVIDIA 617.14; Ryzen 5 3600, 32 GB; Windows 11 Pro 26200; rustc 1.100.0 MSVC; release build.
  • scripts\smoke.ps1 -Game <folder> -Seconds 60 on the PR's head as it is and on main 85bdf21, the commit it is based on, each built from a clean checkout of its commit.
  • Each build ran twice back to back and the blocks are the second runs. The first runs: 528 frames (main) and 848 frames (PR), also with no device removal or crash.
  • Video memory at 60 s, from XCL's memory: line: 6310 MB local / 4619 MB non-local (main), 6311 MB local / 4619 MB non-local (PR).

main:

xcl-smoke v1
commit: 85bdf2193e7a793d568485b35f9cae5e8159bc39
gpu: NVIDIA GeForce RTX 3070
title: game
seconds: 60
exit: 0x0
frames shown: 910 (PresentX 911)
presents per 2 s (last 3): 40 40 40
device removals: 0
crashes: 0
peak commit: 14790 MB

PR:

xcl-smoke v1
commit: d6cbfcd31c1da1edbf6513211e103755f7d8de6f
gpu: NVIDIA GeForce RTX 3070
title: game
seconds: 60
exit: 0x0
frames shown: 912 (PresentX 912)
presents per 2 s (last 3): 40 41 40
device removals: 0
crashes: 0
peak commit: 14799 MB

Not tested

  • The test suite on this head (others have posted it), anything past the first 60 s, and whether the title writes more pages between two looks than one GetWriteWatch call reports (the case this changes).

AI use: Claude Code with Claude Fable 5.2 made the runs with me present and wrote this comment.

@theaustinayers
theaustinayers merged commit f4ce27c into xcl-dev:main Nov 24, 2026
6 of 8 checks passed
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 24, 2026
…, xcl-dev#490, xcl-dev#347)

The fork keeps its own pso_async (short waits, all compute pipelines built ahead); xcl-dev#690 upstream is its used-pipelines part.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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