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 -- --test-threads=4 on head 4714ed9b (after bmjask's third review): 3007 passed, 0 failed, 52 ignored, 25 SKIPPED lines.

  • 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).
  • Switch-on cost at 412e11e9 (review point 2): a 900 s warm world run with XCL_UNWATCHED_RECHECK=1 (run 492, XCL_RESIDENCY_PRIORITY=1): 3.00 presents/s from 240 s, no device removal, no crash (main on this machine: 3.0-3.2).

Regression run

main 817eb1fc9:

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

this PR's head:

xcl-smoke v1
commit: 4714ed9bb4f9074f7795d9b5d8117f297212cdd7
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1582)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 17266 MB

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

@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
Collaborator

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
@Pipodi

Pipodi commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

merge-check claim withdrawn
head: c928379

Withdrawn: this PR is labelled needs:amd-test and we have no AMD hardware. Sorry for the noise; the slot is free.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of c9283790: 2 finding(s) (1 high, 1 medium), most severe first.

  1. High crates/xcl/src/hle/d3d12x/title_textures.rs:2360: first_stage(true) starts kept entries past all milestones, so a kept texture is first rechecked 16 + stagger (16-31) frames after upload instead of at the 4- and 12-frame milestones it had before. (inline)
  2. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:2533: The new gpu_written && steady_keeps arm neither checks nor prunes the entry, so a GPU-written kept entry stays in STREAM_RECHECK for good with base_frame frozen, collected as due and looked up in TEXTURES every frame. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

@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.

@stijn-boer

stijn-boer commented Dec 2, 2026 •

Copy link
Copy Markdown

merge-check
base: 5eaadb5
head: c928379
verdict: not yet: the workspace suite and retail smoke ended early on both builds. The changed GPU_UPLOAD path remains unverified.

Windows / AMD RDNA4 (native D3D12) — workspace suite and retail smoke on c928379

Clean merge onto main at 5eaadb54 (merge commit db004a531a1a10e335aae3e1541b97092365c789). git diff --check was clean.

Setup

  • AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 7 5700X, Windows 10 21H2 build 19044.6332
  • Rust 1.100.0, debug builds, Agility SDK 1.620.2 with matching d3d12SDKLayers.dll, DXC 1.9.2609.5

Tested

cargo build --workspace passed on both builds. cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output exited 101 on both.

Build Passed Failed Ignored SKIPPED notices
main 335 3 23 0
Merged PR 335 3 23 0

Counts are partial because two test processes aborted on each build.

  • Tests that failed on the PR and passed on main — none observed in the comparable results.
  • Test added by the PR — steady_rechecks_follow_the_milestones_and_keep_to_the_frame_budget passed in isolation.
  • Debug-layer coverage — both debug-layer E2E tests, including DRED, and uploads_start_from_each_subresources_state passed on both builds.
Shared failures and process aborts
  • fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_3, and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs reported failures on both builds.
  • The library and gpu_compute_e2e test processes exited with 0xc0000409 on both builds.

Retail smoke

Ran scripts/smoke.ps1 -Game <local folder> -Seconds 60 -Xcl <debug binary> with XCL_UMA_DRIVER=mixed for title hash 2c508222.

Build Exit Frames logged Device removals logged Peak commit
main 0xc0000409 None 0 1320 MB
Merged PR, XCL_UNWATCHED_RECHECK=0 0xc0000409 None 0 1320 MB
Merged PR, XCL_UNWATCHED_RECHECK=1 0xc0000409 None 0 1320 MB

Diff review

The isolated test covers scheduling and hashing. With the switch enabled, the initial whole-texture fingerprint runs before the periodic recheck budget applies. Neither merged smoke run logged recheck activity.

Not tested

Tests after the aborts and retail frame performance remain unverified. The smoke runs did not verify mixed GPU_UPLOAD re-upload or its performance.

AI use

Codex (GPT-6) ran the builds and tests, reviewed the diff, compared the results with main, and drafted this report.

@ClosetPie107

Copy link
Copy Markdown

Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on c928379

Merged onto main 5eaadb54 (clean merge) and compared with main run twice on the same machine.

Setup

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS (kernel 7.3.7)
  • Wine 11.23 (system), stock vkd3d-proton v3.1-83-gcae8353ed and DXVK dxgi.dll from GE-Proton11-16, DXC 1.9.2609.5
  • Debug build, cross-compiled for x86_64-pc-windows-msvc with cargo-xwin; test binaries run under Wine

Tested: cargo xwin test --workspace --target x86_64-pc-windows-msvc --no-fail-fast -- --test-threads=4 --skip <31 tests>

passed failed ignored
main 5eaadb54 2769 177 52
this PR merged 2770 177 52
  • Tests that fail with this PR and pass on main: none.
  • Tests this PR adds: 1 of 1 pass (steady_rechecks_follow_the_milestones_and_keep_to_the_frame_budget).
About the failures on main and the 31 skipped tests (same for every PR in this batch)
  • Most of main's 177 failures under Wine come from Linux (Wine + vkd3d-proton): a retail game reaches what main reaches on Windows; the obstacle is replaced vtables — proposal: proxies #175: once a test has set up the real device, vkd3d-proton refuses the command allocators XCL adopts (d3d12_command_list_Reset: Invalid command allocator), and later tests get E_INVALIDARG (0x80070057). Running vkd3d-proton master with its vtable check taken out, hle::d3d12x::sparse::tests goes from 106 passed / 38 failed to 144 / 0.
  • The 31 skipped tests make vkd3d-proton's dxil-spirv call std::terminate() (Cannot reliably convert LLVM pointer type, we cannot differentiate between Function and Private), which kills the whole test binary. They are the split-wave64, dispatch-chain and bridged-mask GPU tests, gpu_compute_mode_dispatch_abi, gpu_compute_thread_limits_leave_the_lanes_past_them_out, the two gpu_mesh_mode_* tests, and console_wave64_compute_through_the_pso_hook_dispatch_and_read_back, plus serialize_root_signature_strips_console_flags_and_preserves_pc_flags, whose null descriptor vkd3d-proton dereferences. The dxil-spirv ones crash the same way with vkd3d-proton master (f8c1cae8, dxil-spirv 93ab44c5).
  • main was run twice: same counts, same failure set. SKIPPED lines (same as main): no heap windows (2), no D3D12 debug layer (2-3), driver cache control not implemented in vkd3d-proton (1).

Not tested: Windows, NVIDIA, a retail title / scripts/smoke.ps1, a review of the diff. This is a test report, not a merge-check.

AI use: omp (Claude Opus 5.5) merged, built and ran the suites on this machine, compared the results with main, and drafted this report. The user asked for it to be posted.

@throny
throny force-pushed the unwatched-texture-recheck branch from c928379 to 412e11e Compare December 2, 2026 18:55
@throny

throny commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

@Foniass thanks for the review; everything is in 412e11e9 (rebased on main 817eb1fc):

  1. No read at seed time any more. A kept texture starts as Whole::Unknown. Its first whole hash is taken by the first budgeted check (8 MiB / 64 textures a frame), and until then the three slices are compared as on main. A hash taken by a check stays the baseline for the upload it queues, because it was read before that upload. The reads are still synchronous GPU copies, at most 64 a frame; the README says so now.
  2. Switch-on cost, measured at this head: a 900 s warm world run with XCL_UNWATCHED_RECHECK=1 gave 3.00 presents/s, no device removal, no crash (main on this machine: 3.0–3.2).
  3. Wiring tests: seed_stream_recheck_keeping(.., keeps) and keeps_whole(..) take the switch as an argument. The new test steady_recheck_keeps_small_unwatched_textures_past_the_milestones runs the real seed and recheck path. It covers no read at seed, the early milestones, survival past 400 frames, an 8 MiB texture retiring, a rewrite outside the slices being re-queued, and the download re-seed.
  4. Kept textures keep the 4/12/40/120/400 milestones; the 16-frame stagger applies only after the last one.
  5. The dead arm is gone. A download that clears gpu_written re-seeds the texture from the bytes it wrote, with nothing read.
  6. The README is rewritten: budget, first-check timing, ~N/64-frame period above ~1024 kept textures, synchronous reads, measured cost.

Known limits, now in the commit message: a write outside the three slices before a texture's first whole hash is missed, and so is a CPU write, made while the texture was GPU-written, to a subresource a later download didn't cover (main never re-checks those at all).

@stijn-boer the whole suite runs through at this head on an RTX 4080 (3006 passed, 0 failed), and both smoke runs finish (blocks in the description). If it still ends early on your machine, could you post the last lines of the log? Then I can see whether it's this PR.

Could you both re-check 412e11e9? An AMD check would help too (gpu:both).

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

@github-actions github-actions Bot removed 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

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 412e11e9: 4 finding(s) (1 high, 3 medium), most severe first.

  1. High crates/xcl/src/hle/d3d12x/title_textures.rs:2489: A kept texture is seeded as Whole::Unknown and gets its first whole hash only at a later check, after the upload has already read it. (inline)
  2. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:2597: steady_waiting removes deferred kept entries from check entirely and orders by base_frame, so milestone and Unknown checks of freshly uploaded kept textures wait behind steady polls of older ones and get no slice comparison meanwhile. (inline)
  3. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:4209: reseed_downloaded doesn't check entry.cpu_backed, so GPU-owned placements (from register_gpu_owned) that get downloaded are put under the recheck. (inline)
  4. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:4207: publish_download drops the TEXTURES lock before reseed_downloaded inserts into STREAM_RECHECK, so a concurrent forget or register on the same raw resource pointer can run in between and the stale entry gets inserted afterwards. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

@github-actions github-actions Bot added the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Dec 2, 2026
@throny
throny force-pushed the unwatched-texture-recheck branch from 412e11e to 7783f9b Compare December 2, 2026 21:30
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 2, 2026
@throny

throny commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. All four were real; they are fixed in 7783f9b6, which is amended into the PR's single commit. The commit message and README now describe the new behaviour.

  1. High: a write between the upload's read and the first whole hash was never uploaded. Fixed. The upload already keeps a hash of each page it read (Known, written by Hashes::note in fill). The first whole check of a Whole::Unknown entry now compares the texture's pages with those hashes in the same read, through texture_upload::differs_from_sent (texture_upload.rs:137) and whole_check (title_textures.rs:2418). A difference queues the texture, and the hash taken there becomes the baseline of that upload (title_textures.rs:2593, differs just below line 2648). The texture is not read again at seed time. One case is left: a page the upload read only in part, where row reads of a linear texture end inside a page, has no hash. A write there is still caught only if it falls in the slices. The commit message says so. Tests: bytes_are_compared_with_what_the_last_upload_read (texture_upload.rs:963), and a new part of steady_recheck_keeps_small_unwatched_textures_past_the_milestones (title_textures.rs:7042) that writes outside the slices after the upload's read and expects the texture to be queued. That part fails without the fix.

  2. Medium: deferred checks of fresh kept textures waited behind steady polls, with no slice comparison. Fixed. steady_waiting now sorts checks still at their milestones ahead of the steady polls (title_textures.rs:2392). A deferred check that is at a milestone (at_milestone, line 2405) is still made by its slices, as with the switch off (lines 2615 and 2648). A change there queues the texture and resets its whole hash to Unknown, because the old hash is not a baseline for the upload that follows. A match advances the stage. A deferred steady poll still just waits. Test: the ordering and at_milestone cases added to steady_rechecks_follow_the_milestones_and_keep_to_the_frame_budget (line 6866).

  3. Medium: reseed_downloaded put GPU-owned placements under the recheck. Fixed. reseed_downloaded now takes the entry and does nothing for one that is not cpu_backed or is paged (title_textures.rs:2539). The test re-seeds the texture with cpu_backed false, then with cpu_backed true but not kept, and expects no recheck entry in either case.

  4. Medium: lock gap in publish_download. Fixed. The re-seed now runs while TEXTURES is held, right after download_current checks the entry's generation and address (title_textures.rs:4240). A texture that is released or registered at the same address cannot come in between. If a concurrent forget removes the recheck entry before the insert, the leftover entry has no texture behind it, and the next recheck prunes it as on main. A register at that address removes it first. No code path locks TEXTURES while it holds STREAM_RECHECK, so the new lock order (TEXTURES first, then STREAM_RECHECK) cannot deadlock. This race is not covered by a test.

Tested on an RTX 4080 (debug build) with cargo build --workspace (ok) and cargo test -p xcl --lib title_textures: 67 passed, 0 failed, 1 ignored. cargo test -p xcl --lib texture_upload: 11 passed, 1 failed. The failure is an_upload_reads_pages_kept_apart, which also fails at 412e11e9 without these changes on this machine. It is not related to this PR. The whole suite was not run.

Pushed as 7783f9b6. The whole suite passes there (see the description), and the smoke blocks are updated. @bmjask could you re-check?

AI use: Claude Code (Claude Opus 5.5).

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 7783f9b6: 3 finding(s) (2 high, 1 medium), most severe first.

Re-review at 7783f9b6. From the 412e11e9 review, the stuck PENDING on GPU-owned textures and the reseed race on reused addresses weren't flagged again. The baseline-after-upload gap is narrowed by differs_from_sent but still open in the case below, and milestone checks can still be starved under sustained streaming. Two new items.

  1. High crates/xcl/src/hle/d3d12x/title_textures.rs:2676: The first whole-hash check of a Whole::Unknown entry still takes the current memory as its baseline, and its only guard against writes made after the upload read the texture is differs_from_sent, which returns false whenever the uplo.... (inline)
  2. High crates/xcl/src/hle/d3d12x/title_textures.rs:2525: On a whole upload, seed_stream_recheck keeps an existing Whole::Hash(h) even when the check that took h didn't trigger this upload, so the baseline can be arbitrarily old: from a check 16+ frames ago, a reseed_downloaded, or the me.... (inline)
  3. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:2556: see below.

On lines outside the diff:

  1. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:2556: LAST_RECHECK_FRAME.swap only stops two calls for the same frame. Since the recheck can now do up to 64 GPU readbacks one after another (each waiting up to 5 s on a fence), passes for frames F and F+1 from two submitting threads can overlap, and both write the same STREAM_RECHECK entries from stale seen snapshots. If thread A is still reading for frame F when B starts F+1, both snapshot entry X and both run st.stage += 1, so X skips a milestone. Or one pass writes whole: Hash(cur_old) over an entry that seed_stream_recheck/reseed_downloaded refreshed in between, replacing the fresh baseline with one read before the upload. Holding a recheck-in-progress flag (or re-validating each entry's generation before writing) would prevent the overlap.

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

@stijn-boer

Copy link
Copy Markdown

merge-check
base: 5ad98ad
head: 7783f9b
verdict: not yet: the focused checks passed and all smoke runs completed. The workspace library aborted on both builds and this host exposed no GPU_UPLOAD heaps for the mixed-UMA test.

Windows / AMD RDNA4 — unwatched texture recheck redo with #3707 and #3455

Both builds include #3707 at 912ff558e932264511f386eb8b7e97cbf7cf46e2 and #3455 at 1895d9e8ea3c64f7e91f4a0211f2a7aacff5c525. The combined baseline is cfdacf961cf9cced7aba34f4f11e6219ce55df2d, measured in the prior #3613 retest. The PR merged cleanly onto it at def66c5d589a6df50b1298156e9dee73bf6242c1, with a clean git diff --check and its own Cargo target directory.

Setup

AMD Radeon RX 9060 XT (32.0.32029.2010), Ryzen 7 5700X, Windows 10 21H2 build 19044.6332, Rust 1.100.0 debug, Agility SDK 1.620.2 with matching debug layer, DXC 1.9.2609.5.

Tested

cargo build --workspace passed. cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output recorded the following partial counts.

Build Passed Failed Ignored SKIPPED notices
main + #3707 + #3455 1585 9 47 2
Same base + #3617 1585 9 47 2

Both workspace commands exited 101. The library exited 0x80004005 on both builds. Both logged the same failures in fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_3, gpu_smem_flat_descriptor_windows_and_limits, f32_programs_on_the_gpu, gpu_f32_compares_with_nan, gpu_float_compares_random, gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends, and two failures of two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs. The two skip notices were for disabled heap windows. Both debug-layer E2E checks and the texture-state check passed.

Three focused checks passed, with 0 failed, 0 ignored, and 0 skip notices using --test-threads=1 --show-output --nocapture. They cover comparison against the last upload, the check budget, and rechecks beyond the initial milestones.

Retail smoke

Ran scripts/smoke.ps1 -Game <local folder> -Seconds 60 -Xcl <debug binary> with XCL_UMA_DRIVER=mixed and a fresh data root for title hash 2c508222. The baseline row is from the prior run under the same setup.

Build Exit Frames Peak commit Device removals / crashes
main + #3707 + #3455 0x0 1050 15709 MB 0 / 0
Same base + #3617, switch unset, AMD default UMA 0x0 1338 11505 MB 0 / 0
Same base + #3617, switch 1, AMD default UMA 0x0 1227 15856 MB 0 / 0
Same base + #3617, switch unset, mixed:0:128 0x0 1152 16012 MB 0 / 0
Same base + #3617, switch 1, mixed:0:128 0x0 1341 11050 MB 0 / 0

The baseline and the first pair used XCL_UMA_DRIVER=mixed without ranges, which selected AMD default UMA. The second pair explicitly requested XCL_UMA_DRIVER=mixed:0:128. Both logs for that pair reported that the adapter exposed no GPU_UPLOAD heaps and used a CUSTOM heap instead. The switch-on runs logged zero XCL_UNWATCHED_RECHECK events, so the frame and commit differences do not establish an effect from the recheck path.

Not tested

Remaining workspace tests after the abort, mixed GPU_UPLOAD re-upload and its startup and frame costs, and repeated performance pairs.

AI use

Codex (GPT-6) merged and built the PR, ran the tests and smoke test, compared the results with the combined baseline, and drafted this report.

@github-actions github-actions Bot removed the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Dec 2, 2026
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 keeps the milestones, is then
not retired but checked every 16 frames, and is compared by a hash of all of
it. Every read of all of a texture is a check under the frame's budget of
8 MiB and 64 textures (checks at their milestones first, then the longest
unchecked); nothing is read when a texture is seeded. Its first check, at the
first frame after its upload with room for it, takes the whole hash and also
compares each page with the hash the upload kept of what it read there
(texture_upload::differs_from_sent), so a write between the upload's read and
that check is caught; a page the upload kept no hash of (read only in part,
or nothing kept) counts as changed, and the texture goes up once more. A check
that waits for room is made by the slices at a milestone, as with the switch
off. A check that finds a change keeps its hash as the baseline of the whole
upload it queues, since it was taken before that upload read the texture; any
other whole upload starts from no whole hash. A pass leaves an entry that
changed after it read the texture (seeded meanwhile, or written by another
thread's pass) as it is. Entries that pass the last milestone together are
staggered over the 16-frame period. A texture that becomes GPU-written is
still removed by publish_submission_effects; a download that hands a
CPU-backed one back to the CPU seeds it again from the bytes it wrote, while
the texture table is held. Limit: a CPU write is not caught that was made while the texture was GPU-written, to a
subresource a later download did not cover: the download's re-seed takes the
title's bytes there as the baseline (main never checks such a texture
again). 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 an earlier version (seed-time whole hash, no budget, no stagger).

Part of xcl-dev#1049

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny
throny force-pushed the unwatched-texture-recheck branch from 7783f9b to 4714ed9 Compare December 3, 2026 01:29
@throny

throny commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the third round. All three points hold; they are fixed in the PR's commit (amended, now 4714ed9bb; not pushed yet when this was written).

1. High: first whole check of a Whole::Unknown entry takes current memory as its baseline. Fixed. texture_upload::differs_from_sent now answers "may differ": a page the upload kept no hash of (read only in part, or nothing kept because unknown()/forget() ran or forgotten moved during fill) counts as changed (crates/xcl/src/hle/d3d12x/texture_upload.rs:138-149). Such a first check queues one more whole upload, and the hash it took becomes that upload's baseline (point 2), so this does not loop: the next check compares whole hashes and no longer relies on page hashes. The cost is one extra whole upload (at most 4 MiB) after an upload whose page hashes are incomplete. Tests: bytes_are_compared_with_what_the_last_upload_read now expects "may differ" for no hashes and for a zero-hash page. steady_recheck_keeps_small_unwatched_textures_past_the_milestones (title_textures.rs:7091) checks that after forget the first check queues the texture, that the upload that follows makes the hash its baseline, and that the next check finds nothing.

2. High: seed_stream_recheck keeps an old Whole::Hash on an upload no check queued. Fixed. A new Whole::Queued(h) (title_textures.rs:2331-2334) is what a check that finds a change leaves (:2687-2691). Only that hash carries over into the upload's seed (:2532-2535). Any other whole upload starts from Unknown, which also covers a moved e.src. A check that finds no change turns Queued into Hash (:2699). The test reproduces your A-B-A case (:7108): the title writes, an upload it did not queue reads that, then the title writes the old bytes back. The entry is Unknown after the seed, and the first check queues the texture.

3. Medium: overlapping passes write from stale snapshots. Fixed with the re-validation you suggested. When a pass records its results, it skips an entry that no longer equals the snapshot it read (title_textures.rs:2658-2662). That covers a seed or reseed in between and a pass of another thread's frame. The test (:7120) uses a test-only hook that runs between a pass's reads and its write-back (AFTER_RECHECK_READS, :2340-2344, :2651). It replaces the entry the way a concurrent seed would, and checks that the pass leaves it as it is and queues nothing.

Tests (Windows, debug, RTX 4080): cargo test -p xcl --lib d3d12x::title_textures gave 67 passed, 0 failed, 1 ignored. cargo test -p xcl --lib d3d12x::texture_upload gave 10 passed, 0 failed, 0 ignored. There were no SKIPPED notices. The whole suite was not rerun for this amend.

On @stijn-boer's "not yet" (merge check on 7783f9b6), the part that concerns this PR:

  • The abort with 0x80004005 and the 9 failures are the same tests with the same counts on both builds (1585 / 9 / 47 each). They come from the base, not this PR.
  • That no XCL_UNWATCHED_RECHECK line was logged is expected on that host. The switch acts only on textures in a GPU_UPLOAD segment of XCL_UMA_DRIVER=mixed, the range without write watch. Without ranges, mixed picked AMD's default UMA. With mixed:0:128 the adapter had no GPU_UPLOAD heaps (the log says so; Resizable BAR is probably off), so the window is one CUSTOM heap and nothing is in the unwatched range. On that host the runs count as a regression check with the switch on and off, not as coverage of the recheck. A run that covers it needs an adapter that exposes GPU_UPLOAD heaps.

Each round has found new points so far. Would the remaining ones block the merge, or can they be follow-ups once this round is in?

Pushed as 4714ed9b. The whole suite passes there (3007 passed, 0 failed), and the smoke block in the description is updated.

AI use: Claude Code (Claude Opus 5.5).

@Foniass

Foniass commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 078358a
head: 4714ed9
merge: clean
build: ok
tests: 3009 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 1 medium, 3 nits (below)
performance: 60 s smoke run: 1669 → 1679 frames (100 % of main), peak commit 17577 → 18035 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 234 s there, 0 device removals, 0 crashes, 2.9 presents/s; run with XCL_SKIP_CS=95cc13288a27a96e (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)
verdict: not yet: PR description is red; otherwise no blocking finding, the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5


In short: The PR adds XCL_UNWATCHED_RECHECK=1 (off by default): small textures in unwatched memory are hashed whole every 16 frames after the usual milestones, and the push to 4714ed9 reworks how a check picks its baseline. Reading the code at this head shows the three medium findings from the 7783f9b review are fixed, and the new paths have unit tests (no page hashes, the queued baseline, a pass racing a seed); the default path is unchanged. Nothing blocks merging; the main open point is that the switch-on cost was measured before this push, and the push adds a second whole upload for many kept textures.

Medium

  1. Switch-on cost not re-measured at the head, now with a second upload per kept texture. The cost run (900 s, 3.00 presents/s) is from 412e11e, the A/B from e125eda8, and the test counts and smoke blocks from 7783f9b. This head adds a path that costs more: differs_from_sent (texture_upload.rs ~137) now counts a page with no hash as changed. An upload keeps no hash for a page it read only in part (Hashes::note ~608), which covers linear textures read in row chunks that end inside a page, small mips whose block rows are under 4 KiB, and pages in padding between levels. So the first check after most outside whole uploads of such a texture queues it once more. That is one extra whole upload per upload, not a loop, because the queued upload takes the check's hash as its baseline. Re-run the switch-on world run at 4714ed9 with the XCL_UNWATCHED_RECHECK "goes up again" count logged, and update the cost and count lines in the description.

Nit

  1. A write undone between a check and the upload it queued is missed. seed_stream_recheck_keeping (title_textures.rs ~2525) turns Queued(h) into Hash(h) without comparing against the upload's page hashes. If the title writes B after the check hashed A, the upload reads B, and the title then writes A back, the next check sees A == h and the PC texture keeps B. The window is only from the check to the upload it queued, so this is much narrower than the earlier A-B-A case. Comparing the first check after a queued upload with differs_from_sent too, as the Unknown path does, would close it. Otherwise, name the limit in the commit message.
  2. Description and commit message out of date at this head. The description describes the earlier version: "What is in it" does not mention differs_from_sent, the Queued baseline, the second upload when an upload kept no page hashes, or the pass-overlap guard, and it lists only one of the two new tests. The commit message has one unwrapped line of about 110 characters ("Limit: a CPU write is not caught ..."). Three README lines run well past the file's usual width.
  3. Conflicts with open D3D12.X: streamed textures read through their pages are rechecked there #3725. D3D12.X: streamed textures read through their pages are rechecked there #3725 (streamed textures read through their pages are rechecked there) changes the same seed and recheck code and builds StreamRecheck entries without the new whole field. git merge-tree shows a content conflict in title_textures.rs, so whichever PR merges second needs a rebase and a look at how paged entries get a Whole state.
Checked and fine
  • Earlier finding fixed: First whole hash trusts an upload that kept no page hashes. differs_from_sent now returns true when the hash count does not match or a page hash is 0. The new test case (forget, then check) queues the texture once and does not queue it again after the upload.
  • Earlier finding fixed: A kept baseline can predate the upload it stands for. Only a Queued(h) hash, set by the check that queued the upload, is carried into the upload's seed; any other whole upload starts from Unknown. The test with a write and a write-back covers it.
  • Earlier finding fixed: Two recheck passes can overlap. They still can, but a pass now writes only entries equal to the snapshot it read (get_mut(..).filter(st == seen) ~2655), so a seed, a re-seed or another pass in between wins. A test-only hook tests this. Double queueing is still stopped by e.pending.
  • A recheck-queued upload is whole (Due.whole = e.pending ~2146), so Queued always becomes Hash at its seed and a check-queued texture cannot keep re-queueing
  • The switch-off path is unchanged: Whole::No entries keep the old milestone, slice and retire logic, and the existing tests only add the new field to their expected values. No assertion was removed or weakened.
  • Runtime code is under 300 lines (most of the 601 added lines are tests), one logical change, merges cleanly into current origin/main
How this was tested
  • Merged onto main 078358a0, then cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4.
  • The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar).
  • scripts/smoke.ps1: 60 s of a retail title on main 078358a0 and on this merge; presents per 2 s at the end: 60 60 60.
  • Title run: the release build of this merge launched the retail title with XCL_RUN_SECONDS=300 and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, GameInput: XCL_PRESS_BASE=frame counts scripted presses from the first frame #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.

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 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants