startup: reset the window presenter's allocator only after its fence is reached #3196

Merged
tedin7 merged 3 commits from upstream-pr/3196 into main 2026-11-30 19:35:41 +00:00
tedin7 commented 2026-11-27 21:25:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T21:25:48Z.


Part of #870

What this unblocks: a slow frame (a GPU frame longer than two seconds, common on WARP and on first-use shader compiles) no longer makes the window presenter reset a command allocator the GPU is still using.

present_to_window signalled its fence, waited at most 2000 ms, and on the next frame reset the command allocator whether or not the fence was reached. "ID3D12CommandAllocator::Reset" requires that no command list recorded with the allocator is still executing on the GPU; resetting earlier is a debug-layer error and can remove the device.

  • src/startup_stubs/presenter_fence.h: wait_for_submission over caller-supplied operations: returns reached only when the completed value reaches the submitted one; stops on device removal, a failed event arm or a failed wait; reports once when the wait passes two seconds.
  • src/startup_stubs/presenter_fence_win.h: the D3D12 binding (GetCompletedValue, SetEventOnCompletion, WaitForSingleObject in 1 s slices, GetDeviceRemovedReason).
  • d3d12_present.inl: the presenter waits before every allocator reset and after its Signal; a failed Signal, arm or wait, or a failed allocator/list reset, marks the presenter failed instead of reusing the allocator.

Tests:

  • startup_presenter_fence (pure decisions with a fake clock: ready, slow with one warning, removed before and during the wait, re-arm after a signalled slice, arm failure, wait failure).
  • startup_presenter_fence_warp / _hardware (debug layer: a real queue held behind a fence beyond two seconds; the allocator is reset only after the wait returns reached, with no debug-layer error).

Verification:

  • cmake -S . -B /tmp/up-presenter-fence-cfg -G Ninja -DDXC_EXECUTABLE=/bin/true -> configure OK
  • x86_64-w64-mingw32-g++-posix -std=c++20 -fsyntax-only -Isrc tests/startup_presenter_fence.cpp -> OK
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207, D3D12 WARP) at 9a41fd99788ad778cc62797c756bf60308168687:
    • dev: cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_presenter_fence, then ctest --preset dev -R '^startup_presenter_fence' --no-tests=error -> 3/3 passed
    • release /O2: same targets, ctest --preset release -R '^startup_presenter_fence' --no-tests=error -> 3/3 passed
  • Mutant (the wait helper gives up after two seconds and reports the fence reached), dev: startup_presenter_fence, _warp and _hardware all fail (0/3 passed)
  • Coverage note: the tests guard the wait helper and its D3D12 binding; the presenter call site in d3d12_present.inl needs a real window and is covered by review only.

Draft until an independent peer review and the Win2025 WARP gate pass.

Thanks to @Makto94 for the testing that found this.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5533286696 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:25:48Z. --- Part of #870 What this unblocks: a slow frame (a GPU frame longer than two seconds, common on WARP and on first-use shader compiles) no longer makes the window presenter reset a command allocator the GPU is still using. `present_to_window` signalled its fence, waited at most 2000 ms, and on the next frame reset the command allocator whether or not the fence was reached. "ID3D12CommandAllocator::Reset" requires that no command list recorded with the allocator is still executing on the GPU; resetting earlier is a debug-layer error and can remove the device. - `src/startup_stubs/presenter_fence.h`: `wait_for_submission` over caller-supplied operations: returns `reached` only when the completed value reaches the submitted one; stops on device removal, a failed event arm or a failed wait; reports once when the wait passes two seconds. - `src/startup_stubs/presenter_fence_win.h`: the D3D12 binding (`GetCompletedValue`, `SetEventOnCompletion`, `WaitForSingleObject` in 1 s slices, `GetDeviceRemovedReason`). - `d3d12_present.inl`: the presenter waits before every allocator reset and after its Signal; a failed Signal, arm or wait, or a failed allocator/list reset, marks the presenter failed instead of reusing the allocator. Tests: - `startup_presenter_fence` (pure decisions with a fake clock: ready, slow with one warning, removed before and during the wait, re-arm after a signalled slice, arm failure, wait failure). - `startup_presenter_fence_warp` / `_hardware` (debug layer: a real queue held behind a fence beyond two seconds; the allocator is reset only after the wait returns `reached`, with no debug-layer error). Verification: - `cmake -S . -B /tmp/up-presenter-fence-cfg -G Ninja -DDXC_EXECUTABLE=/bin/true` -> configure OK - `x86_64-w64-mingw32-g++-posix -std=c++20 -fsyntax-only -Isrc tests/startup_presenter_fence.cpp` -> OK - Windows Server 2025 (Build 26100, MSVC 14.44.35207, D3D12 WARP) at `9a41fd99788ad778cc62797c756bf60308168687`: - dev: `cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_presenter_fence`, then `ctest --preset dev -R '^startup_presenter_fence' --no-tests=error` -> 3/3 passed - release `/O2`: same targets, `ctest --preset release -R '^startup_presenter_fence' --no-tests=error` -> 3/3 passed - Mutant (the wait helper gives up after two seconds and reports the fence reached), dev: `startup_presenter_fence`, `_warp` and `_hardware` all fail (0/3 passed) - Coverage note: the tests guard the wait helper and its D3D12 binding; the presenter call site in `d3d12_present.inl` needs a real window and is covered by review only. Draft until an independent peer review and the Win2025 WARP gate pass. Thanks to @Makto94 for the testing that found this. AI-assisted; commands listed were executed locally.
KelboLive commented 2026-11-27 23:52:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T23:52:23Z.


Review of 9a41fd99 (single commit):

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7230472119 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7230472119). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T23:52:23Z. --- Review of `9a41fd99` (single commit):
Leyukaka commented 2026-11-28 01:02:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T01:02:41Z.


Review of 9a41fd99, diff only (no build or run on my side). Comment only.

The ordering looks right on the success path. present_to_window now waits for the presenter's own fence to reach submitted before Reset. The value it signals is submitted + 1, on the queue that just executed, and it is stored only after Signal succeeds. On the first frame the fence starts at 0, so there is no wait. Two points:

  1. A removed device's fence value counts as "reached". In wait_for_submission, the completion test is ops.completed() >= submitted, and completed() returns GetCompletedValue() as is. When the device is removed, that returns UINT64_MAX, which passes the test. src/startup_stubs/fence_completion.h already treats that value as removal ("D3D12 returns UINT64_MAX on device removal, not successful completion"). The removed() check before it only catches a removal that GetDeviceRemovedReason() already reports. Routing the comparison through x2w_startup::fence_completion(ops.completed(), submitted) would make the helper agree with the rest of the tree. A Fake case with done == UINT64_MAX and dead == false would pin it. The current fake sets both together. The window is small, a removal landing between the two calls, so this is a consistency point rather than a demonstrated failure.

  2. The test does not cover the change in present_to_window. tests/startup_presenter_fence.cpp includes presenter_fence_win.h and drives wait_for_submission / wait_for_fence, but it never calls present_to_window. If the wait before Reset were removed, it would still pass. The helper tests are useful as they are. This point is only about what they prove for the presenter.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7231378095 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7231378095). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-28T01:02:41Z. --- Review of `9a41fd99`, diff only (no build or run on my side). Comment only. The ordering looks right on the success path. `present_to_window` now waits for the presenter's own fence to reach `submitted` before `Reset`. The value it signals is `submitted + 1`, on the queue that just executed, and it is stored only after `Signal` succeeds. On the first frame the fence starts at 0, so there is no wait. Two points: 1. **A removed device's fence value counts as "reached".** In `wait_for_submission`, the completion test is `ops.completed() >= submitted`, and `completed()` returns `GetCompletedValue()` as is. When the device is removed, that returns `UINT64_MAX`, which passes the test. `src/startup_stubs/fence_completion.h` already treats that value as removal ("D3D12 returns UINT64_MAX on device removal, not successful completion"). The `removed()` check before it only catches a removal that `GetDeviceRemovedReason()` already reports. Routing the comparison through `x2w_startup::fence_completion(ops.completed(), submitted)` would make the helper agree with the rest of the tree. A `Fake` case with `done == UINT64_MAX` and `dead == false` would pin it. The current fake sets both together. The window is small, a removal landing between the two calls, so this is a consistency point rather than a demonstrated failure. 2. **The test does not cover the change in `present_to_window`.** `tests/startup_presenter_fence.cpp` includes `presenter_fence_win.h` and drives `wait_for_submission` / `wait_for_fence`, but it never calls `present_to_window`. If the wait before `Reset` were removed, it would still pass. The helper tests are useful as they are. This point is only about what they prove for the presenter. AI-assisted.
akimfomin commented 2026-11-28 01:22:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by akimfomin on 2026-11-28T01:22:38Z.


PortBridge found a related fence-lifetime fix in XCL #3062: XCL quarantines the old sparse allocator/list while this presenter waits for its own submitted fence. That makes the same lifetime condition useful without copying the different policy. On 9a41fd99, the test already covers a late fence and a bounded hardware gate. One independent check worth returning here is the existing startup_presenter_fence hardware test with the D3D12 debug layer on an idle Windows adapter. Report exit code, adapter/driver and debug error count. The two-second warning is informational; passing still requires completed fence plus a clean allocator reset.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7231621993 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7231621993). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-28T01:22:38Z. --- PortBridge found a related fence-lifetime fix in [XCL #3062](https://github.com/xcl-dev/xcl/pull/3062): XCL quarantines the old sparse allocator/list while this presenter waits for its own submitted fence. That makes the same lifetime condition useful without copying the different policy. On `9a41fd99`, the test already covers a late fence and a bounded hardware gate. One independent check worth returning here is the existing `startup_presenter_fence hardware` test with the D3D12 debug layer on an idle Windows adapter. Report exit code, adapter/driver and debug error count. The two-second warning is informational; passing still requires completed fence plus a clean allocator reset.
tedin7 commented 2026-11-28 10:49:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T10:49:16Z.


Real-GPU verification (NVIDIA RTX 3070 Ti, driver 32.0.16.2101, Windows 11):

Tested at 9a41fd9 (current head). dev preset, ctest run one test at a time:

  • ctest -R '^startup_presenter_fence': 100% tests passed, 0 tests failed out of 3.
  • ctest -R '^startup_presenter_fence_hardware$': 100% tests passed, 0 tests failed out of 1.
  • Mutant patch (timeout mutant) applied: 0% passed, 3 of 3 failed: startup_presenter_fence, startup_presenter_fence_warp, startup_presenter_fence_hardware.

These complement the existing WARP runs.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7238143563 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7238143563). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T10:49:16Z. --- Real-GPU verification (NVIDIA RTX 3070 Ti, driver 32.0.16.2101, Windows 11): Tested at 9a41fd9 (current head). dev preset, ctest run one test at a time: - ctest -R '^startup_presenter_fence': 100% tests passed, 0 tests failed out of 3. - ctest -R '^startup_presenter_fence_hardware$': 100% tests passed, 0 tests failed out of 1. - Mutant patch (timeout mutant) applied: 0% passed, 3 of 3 failed: startup_presenter_fence, startup_presenter_fence_warp, startup_presenter_fence_hardware. These complement the existing WARP runs. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot] commented 2026-11-28 10:49:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-28T10:49:33Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T10:53:51.285787Z 9a41fd9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7238146418 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7238146418). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:49:33Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"9a41fd99788ad778cc62797c756bf60308168687","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-28T10:53:51.285787Z">2026-11-28T10:53:51.285787Z</relative-time> | `9a41fd9` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot] commented 2026-11-28 10:53:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-28T10:53:49Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a41fd9978

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6097326737 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#pullrequestreview-6097326737). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:53:49Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `9a41fd9978` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot] commented 2026-11-28 10:53:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-28T10:53:49Z.

Code review location: CMakeLists.txt; line 644

@@ -636,6 +636,18 @@ foreach(adapter IN ITEMS hardware warp)
     add_test(NAME startup_null_views_${adapter} COMMAND startup_null_views_check ${adapter})
 endforeach()
 set_tests_properties(startup_null_views_hardware PROPERTIES SKIP_RETURN_CODE 77)
+# Presenter allocator reuse: pure decisions and a real queue held beyond two seconds.
+add_executable(startup_presenter_fence tests/startup_presenter_fence.cpp)
+target_include_directories(startup_presenter_fence PRIVATE src)
+target_compile_features(startup_presenter_fence PRIVATE cxx_std_17)
+target_link_libraries(startup_presenter_fence PRIVATE d3d12 dxgi)
+add_test(NAME startup_presenter_fence COMMAND startup_presenter_fence)

P1 Badge Move the presenter test registrations into a family fragment

The registration convention documented in AGENTS.md and its referenced tests/cmake/README.md requires new families' add_test and set_tests_properties calls to live in tests/cmake/<family>.cmake, leaving existing root registrations in place. Adding this family directly here recreates the shared-file merge-conflict hotspot that the fragments are intended to avoid. Move the new registrations and properties into a presenter-family fragment; the existing X2W_TEST_FRAGMENTS glob includes it automatically.

AGENTS.md reference: AGENTS.md:L302-L302

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726652616 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#discussion_r4726652616). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-28T10:53:49Z. **Code review location:** `CMakeLists.txt`; line 644 ~~~~diff @@ -636,6 +636,18 @@ foreach(adapter IN ITEMS hardware warp) add_test(NAME startup_null_views_${adapter} COMMAND startup_null_views_check ${adapter}) endforeach() set_tests_properties(startup_null_views_hardware PROPERTIES SKIP_RETURN_CODE 77) +# Presenter allocator reuse: pure decisions and a real queue held beyond two seconds. +add_executable(startup_presenter_fence tests/startup_presenter_fence.cpp) +target_include_directories(startup_presenter_fence PRIVATE src) +target_compile_features(startup_presenter_fence PRIVATE cxx_std_17) +target_link_libraries(startup_presenter_fence PRIVATE d3d12 dxgi) +add_test(NAME startup_presenter_fence COMMAND startup_presenter_fence) ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Move the presenter test registrations into a family fragment** The registration convention documented in `AGENTS.md` and its referenced `tests/cmake/README.md` requires new families' `add_test` and `set_tests_properties` calls to live in `tests/cmake/<family>.cmake`, leaving existing root registrations in place. Adding this family directly here recreates the shared-file merge-conflict hotspot that the fragments are intended to avoid. Move the new registrations and properties into a presenter-family fragment; the existing `X2W_TEST_FRAGMENTS` glob includes it automatically. AGENTS.md reference: [AGENTS.md:L302-L302](https://github.com/R0Y00/Xbox2Windows/blob/9a41fd99788ad778cc62797c756bf60308168687/AGENTS.md#L302-L302) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-28 11:01:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T11:01:05Z.

Code review location: CMakeLists.txt; line 644

@@ -636,6 +636,18 @@ foreach(adapter IN ITEMS hardware warp)
     add_test(NAME startup_null_views_${adapter} COMMAND startup_null_views_check ${adapter})
 endforeach()
 set_tests_properties(startup_null_views_hardware PROPERTIES SKIP_RETURN_CODE 77)
+# Presenter allocator reuse: pure decisions and a real queue held beyond two seconds.
+add_executable(startup_presenter_fence tests/startup_presenter_fence.cpp)
+target_include_directories(startup_presenter_fence PRIVATE src)
+target_compile_features(startup_presenter_fence PRIVATE cxx_std_17)
+target_link_libraries(startup_presenter_fence PRIVATE d3d12 dxgi)
+add_test(NAME startup_presenter_fence COMMAND startup_presenter_fence)

Valid, fixed. The two presenter registrations and the foreach with its set_tests_properties now live in tests/cmake/startup_presenter_fence.cmake; CMakeLists.txt keeps only the executable target and a pointer comment. Commit 2313547fb on up-presenter-fence.

Verification: cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true configures (rc 0) and the three startup_presenter_fence* tests are registered. aws-1 gate with WARP: x2w_pipe.py win2025 3196 --host aws-1 --regex startup_presenter_fence --force dev 3/3 and release 3/3 passed.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4726675306 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#discussion_r4726675306). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T11:01:05Z. **Code review location:** `CMakeLists.txt`; line 644 ~~~~diff @@ -636,6 +636,18 @@ foreach(adapter IN ITEMS hardware warp) add_test(NAME startup_null_views_${adapter} COMMAND startup_null_views_check ${adapter}) endforeach() set_tests_properties(startup_null_views_hardware PROPERTIES SKIP_RETURN_CODE 77) +# Presenter allocator reuse: pure decisions and a real queue held beyond two seconds. +add_executable(startup_presenter_fence tests/startup_presenter_fence.cpp) +target_include_directories(startup_presenter_fence PRIVATE src) +target_compile_features(startup_presenter_fence PRIVATE cxx_std_17) +target_link_libraries(startup_presenter_fence PRIVATE d3d12 dxgi) +add_test(NAME startup_presenter_fence COMMAND startup_presenter_fence) ~~~~ --- Valid, fixed. The two presenter registrations and the `foreach` with its `set_tests_properties` now live in `tests/cmake/startup_presenter_fence.cmake`; `CMakeLists.txt` keeps only the executable target and a pointer comment. Commit 2313547fb on `up-presenter-fence`. Verification: `cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true` configures (rc 0) and the three `startup_presenter_fence*` tests are registered. aws-1 gate with WARP: `x2w_pipe.py win2025 3196 --host aws-1 --regex startup_presenter_fence --force` dev 3/3 and release 3/3 passed. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-28 22:07:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T22:07:59Z.


Merged current main into this branch (merge commit, no force push, no conflicts); head is now 5fb93b041. The registration finding was already fixed in 2313547fb (the tests live in tests/cmake/startup_presenter_fence.cmake).

Verification (Windows Server 2025, D3D12 WARP, head 5fb93b041): x2w_pipe.py win2025 3196 --regex '^startup_presenter_fence' -> 3/3 passed.

@MasterDomino ready for review and merge when you have time.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7246518690 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7246518690). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T22:07:59Z. --- Merged current `main` into this branch (merge commit, no force push, no conflicts); head is now `5fb93b041`. The registration finding was already fixed in `2313547fb` (the tests live in `tests/cmake/startup_presenter_fence.cmake`). Verification (Windows Server 2025, D3D12 WARP, head `5fb93b041`): `x2w_pipe.py win2025 3196 --regex '^startup_presenter_fence'` -> 3/3 passed. @MasterDomino ready for review and merge when you have time. AI-assisted; commands listed were executed locally.
pigalot commented 2026-11-29 07:57:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-29T07:57:44Z.

Review: APPROVED


Independently reviewed 5fb93b04 integrated over main 212d4b5f (tree c70d77e0). The trial merge is clean and git diff --check is clean. The head's merge of main (5fb93b04) has an empty --remerge-diff.

What I traced in present_to_window:

  • submitted starts at 0 and the fence at 0, so the first frame does not wait.
  • submitted advances only after Signal succeeds, and the value signalled is on the queue that just executed the list.
  • A frame that records nothing (!drawn) closes the list without executing it and leaves submitted as it was, so the next frame's wait and reset are still correct.
  • Every path that leaves the allocator in an unknown state (failed Signal, arm, wait, Reset) sets failed, and failed is checked on entry, so the allocator is not touched again.
  • The event is auto-reset and can be left set when a wait returns through the completed-value check. The next wait then sees one early signaled slice, re-arms and carries on; the re-arm branch in wait_for_submission handles that, and startup_presenter_fence pins it.

Built d3d12_xs_shim and startup_presenter_fence in dev and release, then ran
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_presenter_fence(_warp)?$' and, on its own, -R '^startup_presenter_fence_hardware$':
3 passed in Debug and 3 passed in Release /O2, no skips. On main 212d4b5f the tests are not registered.

Mutants (dev; each applied alone, rebuilt, then reverted):

Killed (10):

  • helper: completed > submitted; removal check dropped; arm failure ignored; failed wait treated as a timeout (test times out); no re-arm after a signalled slice; warning not latched; give up after 2 s as reached (your mutant).
  • binding: completed() reports the fence done after 1.5 s (fails _warp and _hardware); timeout slice mapped to failed (fails both).
  • binding, with the test's elapsed-time and completed-value checks also removed: _hardware still fails, so on the RTX 5090 the early Reset itself is caught. _warp passes with that pair of changes, so on WARP only the elapsed-time check tells the two apart.

Survive (7), none blocking:

  • warning threshold 1000 ms or 2500 ms instead of 2000 (the fake clock steps 1001 ms and completes on the third slice);
  • binding: a signalled slice mapped to timeout; the SetEventOnCompletion result ignored; the event never armed at all (the wait then finishes by polling at the next 1 s slice; _warp took 3.03 s instead of 2.64 s);
  • binding: removed() always false;
  • binding: slice of INFINITE instead of 1000 ms.

Equivalent in the tests (1): the event && guard dropped (the test always passes a valid event).

Notes, none blocking:

  1. Your mutant fails all three tests through pure_checks(), which runs first in every mode, so it does not show that the device tests tell the behaviours apart. The binding mutant above does.
  2. The event path of the binding is not pinned: nothing checks that the wait returns when the event fires rather than at the next slice. A device case that releases the gate mid-slice and bounds the time to return would cover the three event survivors.
  3. Leyukaka's point 1 still stands at this head: completed() >= submitted accepts UINT64_MAX. I traced what follows: the pre-reset wait returns reached, and nothing can still be executing on a removed device, so I do not see a wrong reset from it. Routing through fence_completion() would still be the consistent form.
  4. On removal during the post-signal wait the function now returns before check_device("window present", 0), so the "DEVICE REMOVED" line comes from a later check_device call instead of this one.
  5. The call site in d3d12_present.inl is not reached by any ctest, as the PR body says. A local title run of this head merged onto main 212d4b5f goes through it: [pass] judgement: Judged no worse than the baseline. Confidence high.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and Microsoft WARP; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; D3D12 debug layer on.
CI: Build and test on Windows passed on 5fb93b04.

Approving 5fb93b04.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6101992758 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#pullrequestreview-6101992758). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-29T07:57:44Z. **Review:** APPROVED --- Independently reviewed `5fb93b04` integrated over `main` `212d4b5f` (tree `c70d77e0`). The trial merge is clean and `git diff --check` is clean. The head's merge of `main` (`5fb93b04`) has an empty `--remerge-diff`. What I traced in `present_to_window`: - `submitted` starts at 0 and the fence at 0, so the first frame does not wait. - `submitted` advances only after `Signal` succeeds, and the value signalled is on the queue that just executed the list. - A frame that records nothing (`!drawn`) closes the list without executing it and leaves `submitted` as it was, so the next frame's wait and reset are still correct. - Every path that leaves the allocator in an unknown state (failed `Signal`, arm, wait, `Reset`) sets `failed`, and `failed` is checked on entry, so the allocator is not touched again. - The event is auto-reset and can be left set when a wait returns through the completed-value check. The next wait then sees one early `signaled` slice, re-arms and carries on; the re-arm branch in `wait_for_submission` handles that, and `startup_presenter_fence` pins it. Built `d3d12_xs_shim` and `startup_presenter_fence` in `dev` and `release`, then ran `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_presenter_fence(_warp)?$'` and, on its own, `-R '^startup_presenter_fence_hardware$'`: 3 passed in Debug and 3 passed in Release `/O2`, no skips. On `main` `212d4b5f` the tests are not registered. Mutants (dev; each applied alone, rebuilt, then reverted): Killed (10): - helper: `completed > submitted`; removal check dropped; arm failure ignored; failed wait treated as a timeout (test times out); no re-arm after a signalled slice; warning not latched; give up after 2 s as reached (your mutant). - binding: `completed()` reports the fence done after 1.5 s (fails `_warp` and `_hardware`); timeout slice mapped to `failed` (fails both). - binding, with the test's elapsed-time and completed-value checks also removed: `_hardware` still fails, so on the RTX 5090 the early `Reset` itself is caught. `_warp` passes with that pair of changes, so on WARP only the elapsed-time check tells the two apart. Survive (7), none blocking: - warning threshold 1000 ms or 2500 ms instead of 2000 (the fake clock steps 1001 ms and completes on the third slice); - binding: a signalled slice mapped to `timeout`; the `SetEventOnCompletion` result ignored; the event never armed at all (the wait then finishes by polling at the next 1 s slice; `_warp` took 3.03 s instead of 2.64 s); - binding: `removed()` always false; - binding: slice of `INFINITE` instead of 1000 ms. Equivalent in the tests (1): the `event &&` guard dropped (the test always passes a valid event). Notes, none blocking: 1. Your mutant fails all three tests through `pure_checks()`, which runs first in every mode, so it does not show that the device tests tell the behaviours apart. The binding mutant above does. 2. The event path of the binding is not pinned: nothing checks that the wait returns when the event fires rather than at the next slice. A device case that releases the gate mid-slice and bounds the time to return would cover the three event survivors. 3. Leyukaka's point 1 still stands at this head: `completed() >= submitted` accepts `UINT64_MAX`. I traced what follows: the pre-reset wait returns `reached`, and nothing can still be executing on a removed device, so I do not see a wrong reset from it. Routing through `fence_completion()` would still be the consistent form. 4. On removal during the post-signal wait the function now returns before `check_device("window present", 0)`, so the "DEVICE REMOVED" line comes from a later `check_device` call instead of this one. 5. The call site in `d3d12_present.inl` is not reached by any ctest, as the PR body says. A local title run of this head merged onto `main` `212d4b5f` goes through it: `[pass] judgement: Judged no worse than the baseline. Confidence high.` Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and Microsoft WARP; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; D3D12 debug layer on. CI: `Build and test on Windows` passed on `5fb93b04`. Approving `5fb93b04`. This reply was AI-assisted.
pigalot commented 2026-11-29 07:58:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-29T07:58:05Z.


I have not merged this: the Codex thread on CMakeLists.txt (test registrations) is still open, and CONTRIBUTING asks for all review conversations to be resolved first. I checked that its request is met at 5fb93b04 (the registrations are in tests/cmake/startup_presenter_fence.cmake), so it only needs resolving.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7252800968 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7252800968). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-29T07:58:05Z. --- I have not merged this: the Codex thread on `CMakeLists.txt` (test registrations) is still open, and CONTRIBUTING asks for all review conversations to be resolved first. I checked that its request is met at `5fb93b04` (the registrations are in `tests/cmake/startup_presenter_fence.cmake`), so it only needs resolving. This reply was AI-assisted.
tedin7 commented 2026-11-29 08:03:24 +00:00 (Migrated from github.com)

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


@pigalot Resolved that review thread — ready to merge when you have a moment.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7252857129 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7252857129). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-29T08:03:24Z. --- @pigalot Resolved that review thread — ready to merge when you have a moment. AI-assisted.
Leyukaka commented 2026-11-29 08:09:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T08:09:00Z.

Review: COMMENTED


Review of 5fb93b04 against main eab7180c, by reading only (no build or run). Comment only.

  1. The wait before the allocator reset has no upper bound. At this head, src/startup_stubs/d3d12_present.inl:177-187:

    auto wait = [&] {
        return x2w_startup::wait_for_fence(p.fence, p.submitted, p.reached, device, [] {
    ...
    if (!wait()) {
        p.failed = true;
        return false;
    }
    if (FAILED(p.allocator->Reset()) || ...
    

    and the loop in presenter_fence.h:15-29 is for (;;) with four exits: removed, reached, arm_failed, wait_failed. A 1 s slice that times out (presenter_fence_win.h:19, WaitForSingleObject(event, 1000)) only goes round again; the two-second mark calls ops.slow() and continues. On main, d3d12_present.inl:195 is WaitForSingleObject(p.reached, 2000); and the function returned after that. So a frame whose fence never completes, on a device that never reports removal, now keeps the present thread in this loop for good, with one log line. Is that intended? An alternative is a bounded wait that logs, sets p.failed and returns without resetting the allocator, which keeps the guarantee this PR adds.

  2. The green Build and test on Windows check does not build or run the new tests. On pull requests the job runs cmake --build --preset pr and ctest --preset pr (.github/workflows/windows.yml:490,493). In CMakePresets.json at eab7180c, the pr build preset (:26-38) has a fixed "targets": [ "d3d12_sdk_check", "era_heap_check", "xmem_shim", ... ] list and the pr test preset (:46-53) has a "filter": { "include": { "name": "^(bcpack_all_formats(_golden_control)?|...|startup_present_readback|...)$" } }. Neither contains startup_presenter_fence, and this PR does not change CMakePresets.json. The tests first run in CI on the push to main (ctest --preset dev ... -E '_hardware$', :498), which leaves out _hardware.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6102025967 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#pullrequestreview-6102025967). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T08:09:00Z. **Review:** COMMENTED --- Review of `5fb93b04` against `main` `eab7180c`, by reading only (no build or run). Comment only. 1. **The wait before the allocator reset has no upper bound.** At this head, `src/startup_stubs/d3d12_present.inl:177-187`: ```cpp auto wait = [&] { return x2w_startup::wait_for_fence(p.fence, p.submitted, p.reached, device, [] { ... if (!wait()) { p.failed = true; return false; } if (FAILED(p.allocator->Reset()) || ... ``` and the loop in `presenter_fence.h:15-29` is `for (;;)` with four exits: `removed`, `reached`, `arm_failed`, `wait_failed`. A 1 s slice that times out (`presenter_fence_win.h:19`, `WaitForSingleObject(event, 1000)`) only goes round again; the two-second mark calls `ops.slow()` and continues. On `main`, `d3d12_present.inl:195` is `WaitForSingleObject(p.reached, 2000);` and the function returned after that. So a frame whose fence never completes, on a device that never reports removal, now keeps the present thread in this loop for good, with one log line. Is that intended? An alternative is a bounded wait that logs, sets `p.failed` and returns without resetting the allocator, which keeps the guarantee this PR adds. 2. **The green `Build and test on Windows` check does not build or run the new tests.** On pull requests the job runs `cmake --build --preset pr` and `ctest --preset pr` (`.github/workflows/windows.yml:490,493`). In `CMakePresets.json` at `eab7180c`, the `pr` build preset (`:26-38`) has a fixed `"targets": [ "d3d12_sdk_check", "era_heap_check", "xmem_shim", ... ]` list and the `pr` test preset (`:46-53`) has a `"filter": { "include": { "name": "^(bcpack_all_formats(_golden_control)?|...|startup_present_readback|...)$" } }`. Neither contains `startup_presenter_fence`, and this PR does not change `CMakePresets.json`. The tests first run in CI on the push to `main` (`ctest --preset dev ... -E '_hardware$'`, `:498`), which leaves out `_hardware`.
JohnConnorNPC commented 2026-11-29 12:52:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T12:52:40Z.


Re-reviewed at 5fb93b041c against main 77d1ba4d (by reading the code; no Windows build here). git merge-tree --write-tree origin/main <head> exits 0. CI: 3 success, 2 skipped. The WARP and RTX reports above cover ^startup_presenter_fence.

MUST

  1. The present call can now block for good on the default render path. On main, present_to_window gives up after WaitForSingleObject(p.reached, 2000) and returns. At this head, wait_for_submission in presenter_fence.h is a for (;;) loop that exits only on removed, reached, arm_failed or wait_failed. A timed-out slice just loops again, and after 2 s it calls ops.slow() once. The window presenter signals on the title's own queue (present_to_window(static_cast<ID3D12CommandQueue*>(self->own().real), ...)). So if that queue is stuck behind a GPU-side Wait that nothing signals, and the device is never removed, the title's present call (CommandQueue::slot32) never returns. On main the same case freezes the picture, but the title thread keeps running. Every --render run goes through this code, and no switch turns it off. This is the open question above about the unbounded wait. I'm grading it MUST because a hang is not a fail-closed result. The bounded wait proposed above (time out, set p.failed, skip the reset) keeps this PR's guarantee that no allocator is reset before its fence. Please also add a fixture case where the fence never completes, so that branch is tested.

NIT
2. ops.completed() >= submitted also accepts UINT64_MAX from a removed device. That's harmless here, because removed() is checked first, but using fence_completion() would match the rest of the file.
3. If the device is removed during the post-signal wait, the function returns before check_device("window present", 0). The DEVICE REMOVED line then comes from a later call.

Holding, not merging, until 1 is resolved.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7256127156 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3196#issuecomment-7256127156). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-29T12:52:40Z. --- Re-reviewed at 5fb93b041c70dea2c21ad259adcf6205d7f352a3 against main 77d1ba4d (by reading the code; no Windows build here). `git merge-tree --write-tree origin/main <head>` exits 0. CI: 3 success, 2 skipped. The WARP and RTX reports above cover `^startup_presenter_fence`. **MUST** 1. The present call can now block for good on the default render path. On main, `present_to_window` gives up after `WaitForSingleObject(p.reached, 2000)` and returns. At this head, `wait_for_submission` in `presenter_fence.h` is a `for (;;)` loop that exits only on `removed`, `reached`, `arm_failed` or `wait_failed`. A timed-out slice just loops again, and after 2 s it calls `ops.slow()` once. The window presenter signals on the title's own queue (`present_to_window(static_cast<ID3D12CommandQueue*>(self->own().real), ...)`). So if that queue is stuck behind a GPU-side `Wait` that nothing signals, and the device is never removed, the title's present call (`CommandQueue::slot32`) never returns. On main the same case freezes the picture, but the title thread keeps running. Every `--render` run goes through this code, and no switch turns it off. This is the open question above about the unbounded wait. I'm grading it MUST because a hang is not a fail-closed result. The bounded wait proposed above (time out, set `p.failed`, skip the reset) keeps this PR's guarantee that no allocator is reset before its fence. Please also add a fixture case where the fence never completes, so that branch is tested. **NIT** 2. `ops.completed() >= submitted` also accepts `UINT64_MAX` from a removed device. That's harmless here, because `removed()` is checked first, but using `fence_completion()` would match the rest of the file. 3. If the device is removed during the post-signal wait, the function returns before `check_device("window present", 0)`. The `DEVICE REMOVED` line then comes from a later call. Holding, not merging, until 1 is resolved. AI-assisted.
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!3196
No description provided.