startup: keep fallback GDI off the swap-chain presenter #1235

Merged
R0Y00 merged 1 commit from upstream-pr/1242 into main 2026-11-24 05:17:08 +00:00
R0Y00 commented 2026-11-24 05:01:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T05:01:48Z.


Refs #870 and #874.

The swap chain and diagnostic GDI overlay use separate HWNDs. The fallback enumerated all visible, unowned top-level windows of the process, so z-order or closing the guest window could send a diagnostic background fill to the swap-chain presenter. Exclude the presenter class and query a currently visible, unowned guest window at draw time.

Tested commit ac4bd0cc in MSVC Release on Windows build 26200. Built the runtime DLL. The source-built Win32 regression created the presenter, guest, hidden and owned windows, then changed stacking order and destroyed the guest. The overlay selected the guest in both z-orders, and found no target with only the presenter and ineligible windows present. One test passed, zero skips. No title-side inputs required.

cmake --build out/bin --target d3d12_xs_shim startup_overlay_window
ctest --test-dir out/bin --no-tests=error -R '^startup_overlay_window$' -V

This reproduces a fallback-window selection error. Confirming whether a reported periodic dark frame uses that fallback needs a corresponding surface/Present trace.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575000900 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1242). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T05:01:48Z. --- Refs #870 and #874. The swap chain and diagnostic GDI overlay use separate HWNDs. The fallback enumerated all visible, unowned top-level windows of the process, so z-order or closing the guest window could send a diagnostic background fill to the swap-chain presenter. Exclude the presenter class and query a currently visible, unowned guest window at draw time. Tested commit `ac4bd0cc` in MSVC Release on Windows build 26200. Built the runtime DLL. The source-built Win32 regression created the presenter, guest, hidden and owned windows, then changed stacking order and destroyed the guest. The overlay selected the guest in both z-orders, and found no target with only the presenter and ineligible windows present. One test passed, zero skips. No title-side inputs required. ```powershell cmake --build out/bin --target d3d12_xs_shim startup_overlay_window ctest --test-dir out/bin --no-tests=error -R '^startup_overlay_window$' -V ``` This reproduces a fallback-window selection error. Confirming whether a reported periodic dark frame uses that fallback needs a corresponding surface/Present trace.
tedin7 commented 2026-11-24 05:07:45 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed PR #1242 at commit ac4bd0cc (ac4bd0cc0d3621496d9fcbd8d0437b61253f9743).

Findings

  • Presenter exclusion & stale cache removal (src/startup_stubs/overlay_window.h, src/startup_stubs/d3d12_xs_device.cpp, src/startup_stubs/d3d12_present.inl): Sharing x2w_startup::presenter_class (L"X2WOutputWindow") and querying EnumWindows at draw time fixes both the presenter-selection bug and stale static HWND caching across z-order changes or guest window destruction.
  • Edge cases:
    • draw_overlay still has a benign TOCTOU window between overlay_window() returning an HWND and GetDC/FillRect if the guest window is destroyed concurrently on another thread (GetDC returning nullptr is guarded; subsequent GDI calls fail harmlessly).
    • CMakeLists.txt inserts startup_overlay_window's add_executable/target_*/add_test block between add_executable(startup_dump_fence_check ...) and startup_dump_fence_check's target_* calls (lines 8–16); functionally valid in CMake, just slightly interleaved.
  • Compliance & Docs: AGENTS.md title-neutrality is preserved across code, tests, and docs/startup-runtime.md.

Verification (Linux host)

Windows MSVC build and Win32 test startup_overlay_window were not run locally on this Linux environment.

Commands run on ac4bd0cc:

  • git diff --check $(git merge-base origin/main HEAD)..HEAD -> exit 0 (clean)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py -> passed (Self-test passed. Checked 16 Markdown files and 280 links., 0 fail, 0 skip)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py -> passed (Self-test passed. Checked 1050 tracked source, script and build/CI files: no bidirectional controls., 0 fail, 0 skip)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py -> passed (form coverage checks passed, 0 fail, 0 skip)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034009250 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1242#pullrequestreview-6034009250). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:07:45Z. **Review:** COMMENTED --- Reviewed PR #1242 at commit `ac4bd0cc` (`ac4bd0cc0d3621496d9fcbd8d0437b61253f9743`). ### Findings - **Presenter exclusion & stale cache removal (`src/startup_stubs/overlay_window.h`, `src/startup_stubs/d3d12_xs_device.cpp`, `src/startup_stubs/d3d12_present.inl`)**: Sharing `x2w_startup::presenter_class` (`L"X2WOutputWindow"`) and querying `EnumWindows` at draw time fixes both the presenter-selection bug and stale `static HWND` caching across z-order changes or guest window destruction. - **Edge cases**: - `draw_overlay` still has a benign TOCTOU window between `overlay_window()` returning an `HWND` and `GetDC`/`FillRect` if the guest window is destroyed concurrently on another thread (`GetDC` returning `nullptr` is guarded; subsequent GDI calls fail harmlessly). - `CMakeLists.txt` inserts `startup_overlay_window`'s `add_executable`/`target_*`/`add_test` block between `add_executable(startup_dump_fence_check ...)` and `startup_dump_fence_check`'s `target_*` calls (lines 8–16); functionally valid in CMake, just slightly interleaved. - **Compliance & Docs**: `AGENTS.md` title-neutrality is preserved across code, tests, and `docs/startup-runtime.md`. ### Verification (Linux host) Windows MSVC build and Win32 test `startup_overlay_window` were **not** run locally on this Linux environment. Commands run on `ac4bd0cc`: - `git diff --check $(git merge-base origin/main HEAD)..HEAD` -> exit 0 (clean) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py` -> passed (`Self-test passed. Checked 16 Markdown files and 280 links.`, 0 fail, 0 skip) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py` -> passed (`Self-test passed. Checked 1050 tracked source, script and build/CI files: no bidirectional controls.`, 0 fail, 0 skip) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py` -> passed (`form coverage checks passed`, 0 fail, 0 skip)
upstream-sync closed this pull request 2026-11-24 06:47:13 +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!1235
No description provided.