runtime: preserve CPU fence signal rewinds #3281
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3281
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3279"
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?
@wish131400 on GitHub · 2026-11-28 05:08 UTC · original
wish131400:runtime/fence-observed-values→main· +517 −4 · 5 files · 7 commits · openCPU
ID3D12Fence::Signalcan rewind a fence. The previous atomic maximum left both the shim method and completion address at 9 after a CPU sequence9 -> 2 -> 0 -> 7. Publishing the observed value without serialization then allowed two CPU callers to publish out of order: A captures 1, B publishes 2, A publishes its stale 1.Serialize desktop Signal, GetCompletedValue and publication with a lock on each fence. Keep slot 8 and the slot 12 completion-address reads lock-free.
fence_reacheduses the same writer lock but retains its existing atomic-maximum queue semantics.This branch incorporates the serialization commits from #3352, preserving their author history, and resolves the CMake preset conflict against main
44a3ad5aa9c679cc039b8cb8275738dd6e4405d2. The controlled regression goes beyond the 128-pair barrier stress check: a test-only hook pauses A after the desktop observation and before publication, acknowledges B immediately before the writer lock, allows B 250 ms, then releases A without requiring B to complete first. Fixed behavior must finish at desktop/method/address2/2/2. The isolated test DLL can bypass the writer lock as a negative control, which succeeds only when the exact stale2/1/1outcome and all scheduling handshakes are observed. Each wait is bounded. The production DLL has no scheduling export or unlocked mode.Both fence executables and all three WARP cases are included in the PR build/test preset. Historical sequential results in the experiment notes are now distinguished from the new concurrent measurements.
Validation on Windows 10 Pro build 19045, MSVC 19.43.34810, D3D12 debug layer enabled, tests run serially:
ed554820bed30737fba887ee991611b8fd761e92; final documentation revision77b41d55. Debug was also rebuilt/rechecked at that final head.startup_queue_wait_warp.2/2/2. Negative control on both: B completed during the pause; desktop/method/address2/1/1.9, 2, 0, 7and 128-pair stress checks passed in both production and controlled fixtures.dumpbin /exportsconfirmed the scheduling hook is absent from the production DLL and present only in the isolated test DLL.ctest --preset pr --show-only=json-v1without an extra filter confirmed all three WARP cases are selected.python -B tests/docs_links_check.py,python -B tests/bidi_controls_check.pyandgit diff --checkpassed.Reproduction:
Refs #3282. Queue rewinds and delayed higher-target callbacks still need their own completion-order mechanism. The optional
--queue-rewinddiagnostic was repeated on WARP Release: desktop 3, method/address 7, expected diagnostic failure (exit 1), excluded from the passing count. A failed native Signal was not induced; the HRESULT guard remains code-reviewed. These fixtures do not establish full startup or frame rate. All inputs are source-built; no game or SDK assets are included.CI for
77b41d55completed: run 46369026117.startup_triage_run_check.py, reporting the missingan output UAV interval exceeds the D3D12 buffer view element limitallowlist entry.I reproduced the identical triage failure from the unmodified main base
44a3ad5a, using the test, tool and source inputs extracted directly from that commit. None of those files differ in this PR. Existing #3548 and #3561 already fix that exact upstream failure; #3544 also includes it. This PR does not duplicate those unrelated fixes. The Windows /O2 CI job is not selected for ordinary PR runs; Release coverage above was run locally.@R0Y00 on GitHub · 2026-11-28 05:24 UTC · original · requested changes
Independent Release check on
a5a92ea1:ctest --preset release --no-tests=error -V -R '^startup_(fence_values_(warp|hardware)|queue_wait_warp)$'passed 3/3. The 9 → 2 → 0 → 7 sequence matched the desktop fence, method and completion address on inbox WARP and RTX 4060 Laptop with the debug layer enabled.The new publication breaks ordering with two CPU callers, even with no queue and with increasing values. If A's
Signal(1)succeeds and A reads 1, A can pause beforeInterlockedExchange64. B'sSignal(2)can then complete and publish 2, after which A publishes its stale 1. The native value stays 2, while the method and completion word can stay at 1 indefinitely. The previous atomic max avoided this regression for increasing CPU signals. This is a source-derived interleaving, separate from the queued rewind tracked in #3282.Please serialize the native CPU signal and publication on each fence, or otherwise prevent stale CPU observations from overwriting newer ones. Add a controlled two-caller regression alongside the existing sequential rewind fixture. The queue follow-up can remain separate.
@JohnConnorNPC on GitHub · 2026-11-28 08:17 UTC · original
Thanks for the clear write-up and the sequential fixture. Could you address R0Y00's requested change before this merges? The head
a5a92ea1is the commit that review covered, so it isn't in yet. Here is what I measured on that head:fence_signalexchanges inGetCompletedValue()with no per-fence lock:awk '/^HRESULT __stdcall fence_signal/,/^}/' src/startup_stubs/d3d12_xs_device.cpp | grep -cE 'Lock|mutex|SRW'→0, andWrapperOwnhas no lock member either. Take this order: A signals 1 and reads 1, B signals 2 and publishes 2, then A's exchange writes 1. A step model of that schedule givesnative=2 word=1on this head andnative=2 word=2with main'sfence_reachedmaximum.signal_fence(entry.fence, entry.value), reached fromqueue_workerinsrc/startup_stubs/xcrdapi.cpp). Two queues sharing a fence, or one queue plus a CPU thread, take the same path. I found this in the source and did not trigger it.Signal,GetCompletedValueand the publish for each fence, or otherwise stop an older observation from replacing a newer one. Please also add the controlled two-caller regression next to the 9→2→0→7 loop, as requested.ctest --preset pruses an include list, and the Windows job log has0lines matchingstartup_fence_values(100% tests passed out of 70). Addingstartup_fence_values_warpto that list is the maintainers' call.SUCCEEDED(hr)guard. On the sequential fixture, publishingvalueinstead of the desktop reading also gives the same results. After the fix, update the doc's sentence "this patch adds no live desktop read or lock" and the body's "does not establish concurrent producer ordering", because main's maximum handled the two-caller case.The trial merge into current main is clean (
git merge-tree --write-tree origin/main a5a92ea1→ rc 0), andtests/docs_links_check.pypasses on the merged tree. I did not build or run anything on Windows.This comment was AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-29 13:05 UTC · original
I compared this head with #3352.
git merge-base --is-ancestor a5a92ea1 ac685174is true: #3352 carries this commit unchanged and adds the per-fence lock that R0Y00's review asked for, plus theprpreset entry. So #3352 supersedes this PR, and review can continue there. Closing this one once #3352 lands is the maintainers' call.This head still merges cleanly into main
af1cab5c(git merge-tree --write-treerc 0). On its own, though, it would bring in the two-caller stale-word case that #3352 fixes.MUST
None new. The head is still
a5a92ea1, so the two-caller point in my earlier comment still applies.SHOULD / NIT
None new.
AI-assisted.
@wish131400 on GitHub · 2026-11-30 06:49 UTC · original · edited 2026-11-30 06:57 UTC
Addressed the CPU publication ordering request at
77b41d55(implementationed554820). I incorporated #3352's per-fence writer serialization with its author history, resolved the current-main preset conflict, and added the controlled interleaving requested here and in Leyukaka's review. Slot 8 remains lock-free, as suggested in the review of #3352.The test pauses A after capturing desktop value 1 and before its exchange, starts B at value 2, acknowledges B before its lock attempt, gives B a bounded interval, then releases A without waiting for B first. With the lock: B waits, final desktop/method/address =
2/2/2. The separate test DLL's unlocked negative control reproducibly gives2/1/1and only passes when that exact stale outcome and the scheduling handshakes are observed. Production exports no test hook.Debug and Release each passed 7/7 checks, zero skips, serially on WARP and RTX 4070 Ti SUPER, with the debug layer enabled. This includes the controlled and negative-control cases on both adapters, the existing sequential/stress checks, and
startup_queue_wait_warp. The PR preset selects all three WARP cases. Documentation links, bidi checks andgit diff --checkpassed; the experiment notes now separate the old sequential run from these new measurements. The queued-rewind diagnostic still fails as expected and remains tracked by #3282.The PR description contains the commands and environment. Please re-review this revision for the requested CPU ordering fix and controlled regression.
CI for
77b41d55completed: run 46369026117.startup_triage_run_check.py, reporting the missingan output UAV interval exceeds the D3D12 buffer view element limitallowlist entry.I reproduced the identical triage failure from the unmodified main base
44a3ad5a, using the test, tool and source inputs extracted directly from that commit. None of those files differ in this PR. Existing #3548 and #3561 already fix that exact upstream failure; #3544 also includes it. This PR does not duplicate those unrelated fixes. The Windows /O2 CI job is not selected for ordinary PR runs; Release coverage above was run locally.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.