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

Manually merged
github merged 2 commits from gh-pr/1238/head into gh-pr/1238/base 2026-11-26 22:51:22 +00:00
Owner

@⁠R0Y00 on GitHub · 2026-11-24 04:56 UTC · original
R0Y00:codex/cpu-plane-refresh → main · +125 −3 · 5 files · 2 commits · merged 2026-11-24 05:26 UTC

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.

**@⁠R0Y00** on GitHub · 2026-11-24 04:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1238) `R0Y00:codex/cpu-plane-refresh` → `main` · +125 −3 · 5 files · 2 commits · merged 2026-11-24 05:26 UTC 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:51:20 +00:00
github manually merged commit 1aa7aed280 into gh-pr/1238/base 2026-11-26 22:51:22 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:03 UTC · original · reviewed

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.
**@⁠tedin7** on GitHub · 2026-11-24 05:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1238#pullrequestreview-6033963227) · **reviewed** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.