d3d12: fix placement run-cache invalidation on watch rearm and skip first-upload double digest #550

Closed
DrArroway wants to merge 1 commit from upstream-pr/550 into main
DrArroway commented 2026-11-29 21:40:54 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T21:40:54Z.


Summary

Follow-up fix for #495 (38894edc) resolving a stale watch-invalidation bug in check_sequential, a wasted double-digest pass on first mip upload, and the 4 tuxbox-d3d12 hardware placement unit-test failures on main (2d6dc338, also noted on #512 / #514 / #518):

  1. Preserve CELL_WRITTEN across Watch::rearm and skip the cached fast path when written (runtime/d3d12/src/device/placement/tracking.rs, guest_read.rs):
    • check_sequential previously called begin_check() (which calls watch.rearm(), clearing the WRITTEN bit) before checking self.watch_cacheable(), so a WRITTEN watch looked clean immediately afterward and kept reusing stale cached runs without reacquiring (section_watched_texture_caches_runs_and_invalidates_on_watch_or_mapping_change).
    • Watch::rearm now returns (reason, was_written) using CELL_WRITTEN, check_sequential gates its cached fast path with self.watch_cacheable(), and both prepare_parallel and check_sequential require !check.watch_written && self.watch_cacheable() (marking check.settled = true when prepare_parallel falls through to the uncached path).
  2. Skip speculative in-place digest_runs on first mip upload (runtime/d3d12/src/device/placement/guest_read.rs):
    • check_mips_speculative previously ran digest_runs even when previous[level] was None, counting two Step::Digest operations for a brand-new upload (check_chunk_collects_all_changes_and_merges_profile and check_chunk_runs_xmem_access_only_on_caller_thread measured 128 vs 64).
    • It now digests speculatively only when previous[level] is Some(prev) and copies directly before computing Digest::of(&bytes) once when previous[level] is None.
  3. Commit returned digests between check_chunk calls in test (runtime/d3d12/src/tests/device/placement/check_pool.rs):
    • check_chunk_reuses_cached_runs_and_retries_active_mapping_state now records returned change.digest values into contents.previous[change.level] after the initial and mutated check_chunk passes, matching upload::commit.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below (covered by the existing d3d12-placement regression control + the 4 fixed tuxbox-d3d12 hardware unit tests)
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: NVIDIA still needs to run them.

Commands & Results

  • tuxbox-d3d12 --lib under GE-Proton11-14 with vkd3d-proton (hardware adapter enabled):
    • RX 6900 XT (1002:73bf): 435 passed, 0 failed, 8 ignored (up from 431 passed / 4 failed on main 2d6dc338).
    • AMD Raphael iGPU (1002:164e): 435 passed, 0 failed, 8 ignored.
  • tuxbox.py check on RX 6900 XT (1002:73bf, Mesa RADV, GE-Proton11-14, 3d12a893):
    • Exit 0 — all 11 stages passed (Build the shader compiler, Python tests, Shader compiler tests, DXBC tests, XG layout tests, Storage codec tests, D3D12 Windows typecheck, Build, 126/126 Lanes + fixtures (lanes-benchmark PASS pci=1002:73bf submit_us=92.4 roundtrip_us=143.9 copy64k_us=128.6 frame_us=258.4 frame_p99_us=501.5 shader_pipeline_us=417.0 dxil_pipeline_us=234.8), 22/22 D3D12 regression controls including placement, 66/66 shader translator GPU checks).
  • tuxbox.py check on AMD Raphael iGPU (1002:164e, Mesa RADV, GE-Proton11-14, 3d12a893):
    • Exit 0 — all 11 stages passed (125/125 Lanes + fixtures (1 skipped; lanes-benchmark PASS pci=1002:164e submit_us=70.3 roundtrip_us=125.6 copy64k_us=90.3 frame_us=285.4 frame_p99_us=362.9 shader_pipeline_us=419.6 dxil_pipeline_us=247.7), 22/22 D3D12 regression controls, 66/66 shader translator GPU checks).
  • ProjectScarlett live runs (RX 6900 XT, RADV, GE-Proton11-14, offline):
    • On main (2d6dc338) + this fix (default section mode): ran 54.6 min (3279.6s, 93,278 total presents; placement resolve 70.8–302.0 ms / 5s across 555k–866k texture checks; unwatched=0/0.0MiB; ended on the pre-existing #389 host-page TCP fault).
    • Stacked locally with #501 (cbb6a2df, TUXBOX_XMEM_PRIVATE_VIEWS=1) + #389 (3ea19fe + #441 additions + walk_committed_run): ran 584.7s (15,653 total presents, 4–5 frames / 12 s in world; 0 GPUVM faults, 0 shadows (section=0/0.0MiB), placement resolve 49–136 ms / 5s, placement digest 168–472 ms / 5s, unwatched=0/0.0MiB).
<!-- greyfinch-sync:brcly/TuxBox:issue:5555412875 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/550). Originally posted by [DrArroway](https://github.com/DrArroway) on 2026-11-29T21:40:54Z. --- ## Summary Follow-up fix for #495 (`38894edc`) resolving a stale watch-invalidation bug in `check_sequential`, a wasted double-digest pass on first mip upload, and the 4 `tuxbox-d3d12` hardware placement unit-test failures on `main` (`2d6dc338`, also noted on #512 / #514 / #518): 1. **Preserve `CELL_WRITTEN` across `Watch::rearm` and skip the cached fast path when written (`runtime/d3d12/src/device/placement/tracking.rs`, `guest_read.rs`):** - `check_sequential` previously called `begin_check()` (which calls `watch.rearm()`, clearing the `WRITTEN` bit) *before* checking `self.watch_cacheable()`, so a `WRITTEN` watch looked clean immediately afterward and kept reusing stale cached runs without reacquiring (`section_watched_texture_caches_runs_and_invalidates_on_watch_or_mapping_change`). - `Watch::rearm` now returns `(reason, was_written)` using `CELL_WRITTEN`, `check_sequential` gates its cached fast path with `self.watch_cacheable()`, and both `prepare_parallel` and `check_sequential` require `!check.watch_written && self.watch_cacheable()` (marking `check.settled = true` when `prepare_parallel` falls through to the uncached path). 2. **Skip speculative in-place `digest_runs` on first mip upload (`runtime/d3d12/src/device/placement/guest_read.rs`):** - `check_mips_speculative` previously ran `digest_runs` even when `previous[level]` was `None`, counting two `Step::Digest` operations for a brand-new upload (`check_chunk_collects_all_changes_and_merges_profile` and `check_chunk_runs_xmem_access_only_on_caller_thread` measured 128 vs 64). - It now digests speculatively only when `previous[level]` is `Some(prev)` and copies directly before computing `Digest::of(&bytes)` once when `previous[level]` is `None`. 3. **Commit returned digests between `check_chunk` calls in test (`runtime/d3d12/src/tests/device/placement/check_pool.rs`):** - `check_chunk_reuses_cached_runs_and_retries_active_mapping_state` now records returned `change.digest` values into `contents.previous[change.level]` after the initial and mutated `check_chunk` passes, matching `upload::commit`. ## Tested - [x] The checks relevant to this change passed - [ ] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below *(covered by the existing `d3d12-placement` regression control + the 4 fixed `tuxbox-d3d12` hardware unit tests)* - [ ] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: **NVIDIA still needs to run them.** ### Commands & Results - **`tuxbox-d3d12 --lib` under GE-Proton11-14 with `vkd3d-proton` (hardware adapter enabled):** - **RX 6900 XT (`1002:73bf`):** **435 passed**, 0 failed, 8 ignored (up from 431 passed / 4 failed on `main` `2d6dc338`). - **AMD Raphael iGPU (`1002:164e`):** **435 passed**, 0 failed, 8 ignored. - **`tuxbox.py check` on RX 6900 XT (`1002:73bf`, Mesa RADV, GE-Proton11-14, `3d12a893`):** - Exit **0** — all 11 stages passed (`Build the shader compiler`, `Python tests`, `Shader compiler tests`, `DXBC tests`, `XG layout tests`, `Storage codec tests`, `D3D12 Windows typecheck`, `Build`, **126/126** Lanes + fixtures (`lanes-benchmark PASS pci=1002:73bf submit_us=92.4 roundtrip_us=143.9 copy64k_us=128.6 frame_us=258.4 frame_p99_us=501.5 shader_pipeline_us=417.0 dxil_pipeline_us=234.8`), **22/22** D3D12 regression controls including `placement`, **66/66** shader translator GPU checks). - **`tuxbox.py check` on AMD Raphael iGPU (`1002:164e`, Mesa RADV, GE-Proton11-14, `3d12a893`):** - Exit **0** — all 11 stages passed (**125/125** Lanes + fixtures (`1` skipped; `lanes-benchmark PASS pci=1002:164e submit_us=70.3 roundtrip_us=125.6 copy64k_us=90.3 frame_us=285.4 frame_p99_us=362.9 shader_pipeline_us=419.6 dxil_pipeline_us=247.7`), **22/22** D3D12 regression controls, **66/66** shader translator GPU checks). - **ProjectScarlett live runs (RX 6900 XT, RADV, GE-Proton11-14, offline):** - On `main` (`2d6dc338`) + this fix (default section mode): ran **54.6 min** (`3279.6s`, `93,278` total presents; `placement resolve` `70.8–302.0 ms / 5s` across `555k–866k` texture checks; `unwatched=0/0.0MiB`; ended on the pre-existing `#389` host-page `TCP` fault). - Stacked locally with `#501` (`cbb6a2df`, `TUXBOX_XMEM_PRIVATE_VIEWS=1`) + `#389` (`3ea19fe` + `#441` additions + `walk_committed_run`): ran **584.7s** (`15,653` total presents, `4–5 frames / 12 s` in world; `0` GPUVM faults, `0` shadows (`section=0/0.0MiB`), `placement resolve` `49–136 ms / 5s`, `placement digest` `168–472 ms / 5s`, `unwatched=0/0.0MiB`).
brcly commented 2026-11-29 22:13:32 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T22:13:32Z.


Merged as 038c478d on main (squashed into one commit). The full check passed on an RTX 4070 Ti SUPER and a Radeon 610M. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7263504625 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/550#issuecomment-7263504625). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T22:13:32Z. --- Merged as 038c478d on `main` (squashed into one commit). The full check passed on an RTX 4070 Ti SUPER and a Radeon 610M. Thanks!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!550
No description provided.