Repository navigation
startup: reset the window presenter's allocator only after its fence is reached - #3196
Conversation
…eached The presenter waited at most two seconds for the frame's fence and then reset the command allocator anyway, which is invalid while the GPU still runs that frame. It now waits in one-second slices until the fence is reached or the device is removed (a slow wait is logged once), and a failed Signal, event arm or wait stops the presenter instead of reusing the allocator.
|
Review of |
|
Review of The ordering looks right on the success path.
AI-assisted. |
|
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 |
|
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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
There was a problem hiding this comment.
💡 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".
|
Merged current Verification (Windows Server 2025, D3D12 WARP, head @MasterDomino ready for review and merge when you have time. AI-assisted; commands listed were executed locally. |
pigalot
left a comment
There was a problem hiding this comment.
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:
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.- A frame that records nothing (
!drawn) closes the list without executing it and leavessubmittedas 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) setsfailed, andfailedis 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
signaledslice, re-arms and carries on; the re-arm branch inwait_for_submissionhandles that, andstartup_presenter_fencepins 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_warpand_hardware); timeout slice mapped tofailed(fails both). - binding, with the test's elapsed-time and completed-value checks also removed:
_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:
- 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; 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); - binding:
removed()always false; - binding: slice of
INFINITEinstead of 1000 ms.
Equivalent in the tests (1): the event && guard dropped (the test always passes a valid event).
Notes, none blocking:
- 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. - 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.
- Leyukaka's point 1 still stands at this head:
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. - 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 latercheck_devicecall instead of this one. - The call site in
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 Windows passed on 5fb93b04.
Approving 5fb93b04.
This reply was AI-assisted.
|
I have not merged this: the Codex thread on This reply was AI-assisted. |
|
@pigalot Resolved that review thread — ready to merge when you have a moment. AI-assisted. |
Leyukaka
left a comment
There was a problem hiding this comment.
Review of 5fb93b04 against main eab7180c, 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: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-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.
|
Re-reviewed at 5fb93b0 against main 77d1ba4 (by reading the code; no Windows build here). MUST
NIT Holding, not merging, until 1 is resolved. AI-assisted. |
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.