Skip to content

D3D12.X: keep re-checking small textures in the unwatched upload range - #3617

Open
throny wants to merge 1 commit into
xcl-dev:mainfrom
throny:unwatched-texture-recheck
Open

throny wants to merge 1 commit into
xcl-dev:mainfrom
throny:unwatched-texture-recheck

Conversation

@throny

@throny throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Control-hint glyphs lose letters with XCL_UMA_DRIVER=mixed ("B g / K b g" instead of "Bewegen / Kamera bewegen"). Title textures are copies that XCL re-uploads when a write watch reports a change; the GPU_UPLOAD range of the mixed driver has no write watch, so a texture there is uploaded when it is made and after that only by the stream recheck. That recheck fingerprints three 16 KiB slices at five milestones (4 to 400 frames after the upload) and then drops the texture for good, so a small texture the CPU rewrites later, or outside the slices, is never uploaded again. This adds a switch, XCL_UNWATCHED_RECHECK=1 (off by default), that keeps such textures under a whole-texture check.

Part of #1049 (not shown that the six textures it re-uploads are the glyph atlas itself; the text came out complete in the one run with the switch on).

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: with the switch, a texture of up to 4 MiB in the committed window that is not fully write-watched stays in the stream recheck after the milestones, is hashed whole every 16 frames (read through with_title_bytes), under a frame budget of 8 MiB and 64 textures (longest unchecked first, the first always made); an entry with no baseline yet is hashed under the same budget; entries seeded in one frame are staggered over the 16-frame period by a hash of the resource. A change queues a whole upload as before. A texture that becomes GPU-written is still removed by publish_submission_effects, as before (the switch does not change that). Watched memory, paged textures, textures over 4 MiB and the switch off are unchanged. Unit test steady_rechecks_follow_the_milestones_and_keep_to_the_frame_budget (budget, count cap, stagger).
  • README.md: one line for the switch.

Tested

  • RTX 4080 (NVIDIA), Windows 11 Pro, Rust stable-x86_64-pc-windows-msvc, debug.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 2905 passed, 0 failed, 51 ignored (sum of all test result lines), exit 0, on head c9283790.
  • The in-world A/B below (402 vs 404) was made on the pre-review commit e125eda8, before the frame count cap, the stagger and the baseline budget; it was not repeated on c9283790.
  • 25 SKIPPED lines: 22 no wave64 (RTX 4080 has no wave64), 2 no heap windows (heap_window_out_of_memory_falls_back_to_the_switch_form, bind::tests::two_pass_binds_set_the_shared_view_heap), 1 shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache: Developer Mode required).
  • A/B on the retail title (same build with and without the switch, XCL_UMA_DRIVER=mixed, 900 s, hint phase, near-white pixels in the left quarter of each 960x540 frame):
    • run 402, switch off: 355 px, hint text "B g / K b g" (letters missing), 3.10 presents/s from 240 s
    • run 404, switch on: 582 px, hint text complete, 3.07 presents/s from 240 s
    • the recheck's share of the submit cost stays at 0.00-0.20 ms per submit (switch off: 0.00-0.24).

Regression run

main (f07e426d):

xcl-smoke v1
commit: f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 120
exit: 0x0
frames shown: 3400 (PresentX 3400)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 19407 MB

this PR's head (c9283790):

xcl-smoke v1
commit: c92837900097f1495fe83b3ccb774eae151dbab8
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 120
exit: 0x0
frames shown: 3469 (PresentX 3469)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19442 MB

The smoke run does not set the switch (it is off by default), so it only shows that the default path is unchanged.

Not tested

  • n = 1 per side for the text comparison (runs 402 vs 404). The letters could also be a timing effect; more pairs are needed.
  • One more run with the switch on (run 403) lost the device at +95 s, before the hint phase: 0x887a0006, Aftermath page fault "Read by Graphics, BC7 128x1024, not placed". Plain main's run 344 lost the device the same way at +90 s, so it is probably the known loss at the world load, but 1 of 2 switch runs ended that way and 0 of 1 without.
  • Textures over 4 MiB in the unwatched range keep only the five milestones; with many small textures there a change can wait several cycles of the frame budget.
  • AMD (RDNA4 / RDNA2), Series S layout, wave64 GPUs, the other UMA driver modes with the switch on.

AI use

  • Claude Code (Claude Fable 5.2) found the cause and wrote the fix; Claude Sonnet 5.5 prepared the branch and ran the tests; Claude Opus 5.5 coordinated.

🤖 Generated with Claude Code

Title textures are copies: XCL reads the title's bytes, detiles them and
uploads them into its own PC texture, and learns of changes by write watch.
The GPU_UPLOAD range of XCL_UMA_DRIVER=mixed has no write watch, so a texture
there is uploaded when it is made and after that only by the stream recheck,
which fingerprints three 16 KiB slices at 5 milestones (4 to 400 frames) and
then drops the texture for good. A small texture the CPU rewrites later than
that, or outside the slices, is never uploaded again; with the mixed driver
the control-hint glyphs lost letters (xcl-dev#1049).

XCL_UNWATCHED_RECHECK=1 (off unless given): a texture of up to 4 MiB in a
committed window that is not fully write-watched is not retired; it is hashed
whole every 16 frames for as long as it lives. A frame reads at most 8 MiB and
64 textures (longest unchecked first), and an entry with no baseline yet is
hashed under the same budget. Entries seeded in one frame are staggered over
the 16-frame period by a hash of the resource, so they do not all come due
together. A change queues a whole upload as before. A texture that becomes
GPU-written is still removed by publish_submission_effects, as before.
Everything else is unchanged.

Measured on an RTX 4080, mixed driver, same build, 900 s, hint phase, near-white
pixels in the left quarter of the frame: run 402 (switch off) 355 px, hint text
"B g / K b g"; run 404 (switch on) 582 px, text complete. Presents/s from 240 s:
3.10 vs 3.07. Run 403 (switch on) lost the device at +95 s with the same page
fault as plain main's run 344, before the hint phase. n = 1 per side. These
runs were on the commit before the frame count cap and the stagger.

Part of xcl-dev#1049

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: f07e426
head: c928379
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+153/-11). With XCL_UNWATCHED_RECHECK=1, a title texture of up to 4 MiB in a committed window that isn't fully write-watched stays in the stream recheck after the milestones and is hashed whole every 16 frames under a per-frame budget; with the switch off nothing changes. Findings: (1) The whole hash at seed time has no cap and is a GPU round trip. In seed_stream_recheck (title_textures.rs ~2468-2478), every whole upload of a kept texture calls stream_fingerprint(.., true) -> with_title_bytes, which in the GPU_UPLOAD range goes to read_vram_bytes (uma_driver.rs ~658-687): a CopyBufferRegion, a signal, a fence wait with a 5 s timeout and a new len-sized Vec, one texture at a time, on the submit path before upload_all. This applies to every new upload and every re-upload the check itself triggers; the 8 MiB / 64-texture budget only covers the recheck side, so a frame that creates thousands of small textures (world load) gets thousands of synchronous readbacks, and even the budgeted recheck can make up to 64 serial round trips a frame. The description and README ("at most 8 MiB and 64 textures read a frame") leave this out. (2) The switch-on cost isn't measured at the head commit. The description's A/B was made on e125eda8, before the cap, the stagger and the baseline budget; both of its smoke blocks run with the switch off, and one of its two switch-on runs lost the device at +95 s. The switch-on smoke below is 60 s on NVIDIA and doesn't cover world load. (3) The tests don't exercise the wiring. steady_recheck() is read once through a OnceLock, so no test runs seed_stream_recheck or recheck_streamed_unwatched_at with the switch on: nothing shows a kept entry surviving past the 400-frame milestone, a rewrite after the last milestone being re-queued, or the 4 MiB limit. The new test covers only the helpers (recheck_interval, steady_waiting, steady_base, stream_fingerprint, including a byte changed outside the slices). (4) Kept textures lose the early milestones. first_stage(true) plus steady_base put the first check 16-31 frames after the upload (later when over budget) instead of 4 / 12 / 40, so streaming writes landing shortly after a small texture is made are caught later with the switch on than without it. (5) A match arm that is effectively dead and can't clean up. Some(e) if e.gpu_written && steady_keeps(..) => {} (~2533) is in practice never reached, since publish_submission_effects removes the entry; if it were, the entry would never be pruned and would stay due every frame under the TEXTURES lock. Keeping the plain prune would be simpler. Related: a kept texture whose gpu_written is later cleared by a download (~4117) isn't re-seeded until its next whole upload, so "for as long as they live" overstates the coverage. (6) README is imprecise: besides the seed-time reads in (1), the first check is 16-31 frames, and with more than about 1024 kept textures the 64-check cap stretches the period to about N/64 frames, with every waiting entry sorted and looked up under TEXTURES each frame. Fine: the baseline is the hash at the last whole upload (re-seeded before upload_all; partial uploads keep it); a detected change re-uploads through the existing pending path at the next submit with main's ordering, and pending entries are skipped, so nothing uploads twice; forget, register and retire_range drop entries, and the committed window is never decommitted, so reading a freed texture can't fault; steady_waiting checks the oldest first, so nothing starves; with the switch off, steady_keeps returns early, no new locks are taken, and the milestones and retirement are as on main.
performance: 60 s smoke of a retail title, main f07e426 vs this merge (c928379): 1672 -> 1683 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17352 -> 17229 MB, 0 device removals, 0 crashes. With XCL_UMA_DRIVER=mixed XCL_UNWATCHED_RECHECK=1: 1673 frames, peak commit 17700 MB, 0 device removals, 0 crashes, and the log shows the new check running; a 60 s run doesn't reach world load, where finding 1 would cost most.
verdict: not yet: with the switch on, every whole upload of a kept texture does a synchronous GPU readback outside the per-frame budget (finding 1), so the cost at world load is unmeasured and the description's "at most 8 MiB and 64 textures read a frame" doesn't hold; and no test runs the new path with the switch on (finding 3). With the switch off nothing changes, the suite passes, and both smoke runs are clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

Stability follow-up on the switch (pre-review build of this change, RTX 4080, 900 s each, same save and inputs, no draws skipped): runs 405 and 407 with XCL_UNWATCHED_RECHECK=1 3.05 and 3.07 presents/s, run 406 without it 2.97; no device removal or crash in any of the three. So with run 403 that is 1 loss in 4 runs with the switch and the same fault plain main showed once — not tied to the switch as far as these runs go.

AI use: Claude Code (Claude Opus 5.5).

@vasanex

vasanex commented Dec 2, 2026

Copy link
Copy Markdown

merge-check claim
head: c928379

@vasanex

vasanex commented Dec 2, 2026

Copy link
Copy Markdown

merge-check
base: 1c8b551
head: c928379
merge: clean (merged tree 8cc07b4e, git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same set as on the base; failing: none. Base alone, same machine: 2909 passed, 0 failed, 51 ignored. The new test steady_rechecks_follow_the_milestones_and_keep_to_the_frame_budget passes.
review: whole diff read (title_textures.rs, README.md), in the merge result. No blocking finding. With the switch off nothing changes: steady_keeps is false everywhere, so every entry starts at stage 0, is fingerprinted by the three slices and is removed after the last milestone as on main; an entry past the milestones (now due every 16 frames instead of never) cannot exist without the switch. With the switch on: the whole-texture read goes through with_title_bytes, which reads a GPU_UPLOAD segment from the GPU's copy and the committed window in place (never decommitted), so the read cannot fault; a frame's steady checks are capped at 8 MiB and 64 textures, oldest first, and one that waits stays due; an unchanged kept entry is rescheduled from the current frame, a changed one restarts with the stagger. Smaller points: (1) the unit test covers the helpers (interval, budget, stagger, whole hash); that recheck_streamed_unwatched_at keeps an entry past the milestones and queues the upload is not tested; (2) a kept texture that is GPU-written and still listed is neither checked nor pruned and stays due every frame (a map lookup a frame; the comment says publish_submission_effects removes it); (3) as the description says, the text comparison is n = 1 per side and was made on a commit before the budget and stagger. Duplicates: none open; #3537 (same author, closed draft) was the earlier form.
performance: off by default: one OnceLock read per seeded texture and per due check, reasoned, not measured. With the switch on, up to 8 MiB hashed per frame on the submitting thread; the description measured 0.00-0.20 ms per submit on an RTX 4080. No title run in this check.
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0, debug / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.

@github-actions github-actions Bot added checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 2, 2026
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 checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants