startup: refresh directly written R8 planes on frame reuse #1231

Merged
R0Y00 merged 2 commits from upstream-pr/1238 into main 2026-11-24 05:26:08 +00:00
R0Y00 commented 2026-11-24 04:56:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T04:56:49Z.


Refs #870, #874. This supplies the runtime texture side of CPU-written image refresh. #1110 covers updates to buffer SRVs.

The startup wrapper checked directly written image data every 15 presented frames. Reusing one of three CPU-backed images between those checks could display old pixels while the desktop continued presenting. Recheck single-slice, single-mip R8_UNORM textures of up to 32 MiB on the first bind of each new frame. The existing content hash avoids a copy when bytes match. Explicit write notifications still take precedence.

Built commit 0f496ab6 in Release under Windows build 26200. NVIDIA GeForce RTX 4060 Laptop driver 32.0.16.1656 and Microsoft WARP 10.0.26100.9818 each passed the same six-image test. The debug layer was off. Both read back 306/306 current R8 pixels. With the reused planes intentionally left stale, exactly 153/306 pixels differed, all matching their original buffer contents. Zero skips.

cmake --build out/bin-plane --target startup_plane_refresh d3d12_xs_shim
ctest --test-dir out/bin-plane --no-tests=error -R '^startup_plane_refresh_' -V

The fixture uses source-built CPU images, the uploader's refresh decision and the desktop footprint copy on each backend. Decoded, uploaded and presented frame counts from a whole-program run remain a separate end-to-end measurement.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6574940485 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1238). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T04:56:49Z. --- Refs #870, #874. This supplies the runtime texture side of CPU-written image refresh. #1110 covers updates to buffer SRVs. The startup wrapper checked directly written image data every 15 presented frames. Reusing one of three CPU-backed images between those checks could display old pixels while the desktop continued presenting. Recheck single-slice, single-mip R8_UNORM textures of up to 32 MiB on the first bind of each new frame. The existing content hash avoids a copy when bytes match. Explicit write notifications still take precedence. Built commit `0f496ab6` in Release under Windows build 26200. NVIDIA GeForce RTX 4060 Laptop driver 32.0.16.1656 and Microsoft WARP 10.0.26100.9818 each passed the same six-image test. The debug layer was off. Both read back 306/306 current R8 pixels. With the reused planes intentionally left stale, exactly 153/306 pixels differed, all matching their original buffer contents. Zero skips. ```powershell cmake --build out/bin-plane --target startup_plane_refresh d3d12_xs_shim ctest --test-dir out/bin-plane --no-tests=error -R '^startup_plane_refresh_' -V ``` The fixture uses source-built CPU images, the uploader's refresh decision and the desktop footprint copy on each backend. Decoded, uploaded and presented frame counts from a whole-program run remain a separate end-to-end measurement.
tedin7 commented 2026-11-24 05:03:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:03:57Z.

Review: COMMENTED


Reviewed commit 0f496ab6 (Linux host; Windows build and startup_plane_refresh_{warp,hardware} were not executed locally).

Code & Edge-Case Audit

  • src/startup_stubs/slice_footprints.h (recheck_cpu_texture) & src/startup_stubs/d3d12_draw.inl (upload_texture):
    • Restricts per-frame recheck (elapsed >= 1) to DXGI_FORMAT_R8_UNORM, MipLevels == 1, DepthOrArraySize == 1, and total <= 32 MiB; other formats retain the 15-frame interval.
    • elapsed uses unsigned subtraction (static_cast<UINT>(frame_number) - static_cast<UINT>(state.checked_frame)), avoiding signed overflow on LONG wraparound.
    • state.checked_frame = frame_number is updated before the hash == state.hash early return, so an unchanged plane is not re-hashed multiple times within the same frame, and explicit XG write notifications (announced) still bypass the interval check.
    • Minor note: recheck_cpu_texture checks desc.DepthOrArraySize == 1 directly (while upload_texture normalizes 0 to 1 in slices), and MipLevels == 0 (full mip chain) is excluded; both are safe/conservative.
  • tests/startup_plane_refresh.cpp & docs/experiments.md:
    • Title-neutral (AGENTS.md compliant). The test validates recheck_cpu_texture boundary cases (elapsed 0 vs 1, 32 MiB + 1, R8G8B8A8_UNORM at 14 vs 15) and the 6-frame / 3-texture rotation pattern, though upload_texture itself is not exercised directly by this test.

Checks Run (Linux / Python)

  • git diff --check origin/main...HEAD: pass (0 issues)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: pass (16 Markdown files, 280 links)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: pass (1049 files)
  • Windows build and ctest -R '^startup_plane_refresh_': not run locally.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033963227 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1238#pullrequestreview-6033963227). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:03:57Z. **Review:** COMMENTED --- Reviewed commit `0f496ab6` (Linux host; Windows build and `startup_plane_refresh_{warp,hardware}` were not executed locally). ### Code & Edge-Case Audit - `src/startup_stubs/slice_footprints.h` (`recheck_cpu_texture`) & `src/startup_stubs/d3d12_draw.inl` (`upload_texture`): - Restricts per-frame recheck (`elapsed >= 1`) to `DXGI_FORMAT_R8_UNORM`, `MipLevels == 1`, `DepthOrArraySize == 1`, and `total <= 32 MiB`; other formats retain the 15-frame interval. - `elapsed` uses unsigned subtraction (`static_cast<UINT>(frame_number) - static_cast<UINT>(state.checked_frame)`), avoiding signed overflow on `LONG` wraparound. - `state.checked_frame = frame_number` is updated before the `hash == state.hash` early return, so an unchanged plane is not re-hashed multiple times within the same frame, and explicit XG write notifications (`announced`) still bypass the interval check. - Minor note: `recheck_cpu_texture` checks `desc.DepthOrArraySize == 1` directly (while `upload_texture` normalizes `0` to `1` in `slices`), and `MipLevels == 0` (full mip chain) is excluded; both are safe/conservative. - `tests/startup_plane_refresh.cpp` & `docs/experiments.md`: - Title-neutral (`AGENTS.md` compliant). The test validates `recheck_cpu_texture` boundary cases (elapsed 0 vs 1, `32 MiB + 1`, `R8G8B8A8_UNORM` at 14 vs 15) and the 6-frame / 3-texture rotation pattern, though `upload_texture` itself is not exercised directly by this test. ### Checks Run (Linux / Python) - `git diff --check origin/main...HEAD`: pass (0 issues) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: pass (16 Markdown files, 280 links) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: pass (1049 files) - Windows build and `ctest -R '^startup_plane_refresh_'`: not run locally.
upstream-sync closed this pull request 2026-11-24 06:47:10 +00:00
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
R0Y00/Xbox2Windows!1231
No description provided.