startup: reset the window presenter's allocator only after its fence is reached #3196
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3196"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_windowsignalled 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_submissionover caller-supplied operations: returnsreachedonly 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,WaitForSingleObjectin 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 returnsreached, with no debug-layer error).Verification:
cmake -S . -B /tmp/up-presenter-fence-cfg -G Ninja -DDXC_EXECUTABLE=/bin/true-> configure OKx86_64-w64-mingw32-g++-posix -std=c++20 -fsyntax-only -Isrc tests/startup_presenter_fence.cpp-> OK9a41fd99788ad778cc62797c756bf60308168687:cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_presenter_fence, thenctest --preset dev -R '^startup_presenter_fence' --no-tests=error-> 3/3 passed/O2: same targets,ctest --preset release -R '^startup_presenter_fence' --no-tests=error-> 3/3 passedstartup_presenter_fence,_warpand_hardwareall fail (0/3 passed)d3d12_present.inlneeds 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.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T23:52:23Z.
Review of
9a41fd99(single commit):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_windownow waits for the presenter's own fence to reachsubmittedbeforeReset. The value it signals issubmitted + 1, on the queue that just executed, and it is stored only afterSignalsucceeds. On the first frame the fence starts at 0, so there is no wait. Two points:A removed device's fence value counts as "reached". In
wait_for_submission, the completion test isops.completed() >= submitted, andcompleted()returnsGetCompletedValue()as is. When the device is removed, that returnsUINT64_MAX, which passes the test.src/startup_stubs/fence_completion.halready treats that value as removal ("D3D12 returns UINT64_MAX on device removal, not successful completion"). Theremoved()check before it only catches a removal thatGetDeviceRemovedReason()already reports. Routing the comparison throughx2w_startup::fence_completion(ops.completed(), submitted)would make the helper agree with the rest of the tree. AFakecase withdone == UINT64_MAXanddead == falsewould 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.The test does not cover the change in
present_to_window.tests/startup_presenter_fence.cppincludespresenter_fence_win.hand driveswait_for_submission/wait_for_fence, but it never callspresent_to_window. If the wait beforeResetwere 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.
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 existingstartup_presenter_fence hardwaretest 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.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:These complement the existing WARP runs.
AI-assisted; commands listed were executed locally.
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.
9a41fd9ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
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
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".
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-28T10:53:49Z.
Code review location:
CMakeLists.txt; line 644The registration convention documented in
AGENTS.mdand its referencedtests/cmake/README.mdrequires new families'add_testandset_tests_propertiescalls to live intests/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 existingX2W_TEST_FRAGMENTSglob includes it automatically.AGENTS.md reference: AGENTS.md:L302-L302
Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T11:01:05Z.
Code review location:
CMakeLists.txt; line 644Valid, fixed. The two presenter registrations and the
foreachwith itsset_tests_propertiesnow live intests/cmake/startup_presenter_fence.cmake;CMakeLists.txtkeeps only the executable target and a pointer comment. Commit2313547fbonup-presenter-fence.Verification:
cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/trueconfigures (rc 0) and the threestartup_presenter_fence*tests are registered. aws-1 gate with WARP:x2w_pipe.py win2025 3196 --host aws-1 --regex startup_presenter_fence --forcedev 3/3 and release 3/3 passed.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T22:07:59Z.
Merged current
maininto this branch (merge commit, no force push, no conflicts); head is now5fb93b041. The registration finding was already fixed in2313547fb(the tests live intests/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.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-29T07:57:44Z.
Review: APPROVED
Independently reviewed
5fb93b04integrated overmain212d4b5f(treec70d77e0). The trial merge is clean andgit diff --checkis clean. The head's merge ofmain(5fb93b04) has an empty--remerge-diff.What I traced in
present_to_window:submittedstarts at 0 and the fence at 0, so the first frame does not wait.submittedadvances only afterSignalsucceeds, and the value signalled is on the queue that just executed the list.!drawn) closes the list without executing it and leavessubmittedas it was, so the next frame's wait and reset are still correct.Signal, arm, wait,Reset) setsfailed, andfailedis checked on entry, so the allocator is not touched again.signaledslice, re-arms and carries on; the re-arm branch inwait_for_submissionhandles that, andstartup_presenter_fencepins it.Built
d3d12_xs_shimandstartup_presenter_fenceindevandrelease, then ranctest --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. Onmain212d4b5fthe tests are not registered.Mutants (dev; each applied alone, rebuilt, then reverted):
Killed (10):
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).completed()reports the fence done after 1.5 s (fails_warpand_hardware); timeout slice mapped tofailed(fails both)._hardwarestill fails, so on the RTX 5090 the earlyResetitself is caught._warppasses with that pair of changes, so on WARP only the elapsed-time check tells the two apart.Survive (7), none blocking:
timeout; theSetEventOnCompletionresult ignored; the event never armed at all (the wait then finishes by polling at the next 1 s slice;_warptook 3.03 s instead of 2.64 s);removed()always false;INFINITEinstead of 1000 ms.Equivalent in the tests (1): the
event &&guard dropped (the test always passes a valid event).Notes, none blocking:
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.completed() >= submittedacceptsUINT64_MAX. I traced what follows: the pre-reset wait returnsreached, and nothing can still be executing on a removed device, so I do not see a wrong reset from it. Routing throughfence_completion()would still be the consistent form.check_device("window present", 0), so the "DEVICE REMOVED" line comes from a latercheck_devicecall instead of this one.d3d12_present.inlis not reached by any ctest, as the PR body says. A local title run of this head merged ontomain212d4b5fgoes 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 Windowspassed on5fb93b04.Approving
5fb93b04.This reply was AI-assisted.
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 at5fb93b04(the registrations are intests/cmake/startup_presenter_fence.cmake), so it only needs resolving.This reply was AI-assisted.
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.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T08:09:00Z.
Review: COMMENTED
Review of
5fb93b04againstmaineab7180c, by reading only (no build or run). Comment only.The wait before the allocator reset has no upper bound. At this head,
src/startup_stubs/d3d12_present.inl:177-187:and the loop in
presenter_fence.h:15-29isfor (;;)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 callsops.slow()and continues. Onmain,d3d12_present.inl:195isWaitForSingleObject(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, setsp.failedand returns without resetting the allocator, which keeps the guarantee this PR adds.The green
Build and test on Windowscheck does not build or run the new tests. On pull requests the job runscmake --build --preset prandctest --preset pr(.github/workflows/windows.yml:490,493). InCMakePresets.jsonateab7180c, theprbuild preset (:26-38) has a fixed"targets": [ "d3d12_sdk_check", "era_heap_check", "xmem_shim", ... ]list and theprtest preset (:46-53) has a"filter": { "include": { "name": "^(bcpack_all_formats(_golden_control)?|...|startup_present_readback|...)$" } }. Neither containsstartup_presenter_fence, and this PR does not changeCMakePresets.json. The tests first run in CI on the push tomain(ctest --preset dev ... -E '_hardware$',:498), which leaves out_hardware.Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T12:52:40Z.
Re-reviewed at
5fb93b041cagainst main77d1ba4d(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
present_to_windowgives up afterWaitForSingleObject(p.reached, 2000)and returns. At this head,wait_for_submissioninpresenter_fence.his afor (;;)loop that exits only onremoved,reached,arm_failedorwait_failed. A timed-out slice just loops again, and after 2 s it callsops.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-sideWaitthat 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--renderrun 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, setp.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() >= submittedalso acceptsUINT64_MAXfrom a removed device. That's harmless here, becauseremoved()is checked first, but usingfence_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). TheDEVICE REMOVEDline then comes from a later call.Holding, not merging, until 1 is resolved.
AI-assisted.