GPU: confirm the host fence before copying results back #2897
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2899"
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 Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T23:25:05Z.
Change
The synchronous host submission path uses a shared auto-reset event. A previous notification can wake a later wait while that submission's fence value is still pending. The old path also continued on an event-registration error or a failed Win32 wait. The work that copies GPU data back to guest memory relies on confirmed completion.
Check the completed value after the event wakes. Continue waiting on the registered event if an earlier signal woke it. If registration or the native wait fails, poll the fence at 1 ms intervals. A failed queue signal or the device-removed value goes through the submission failure path before copy-back. This is the standalone fence change suggested in the closing note on #2158.
Verification
The WARP test gives a private D3D12 queue a fence signal behind a closed gate and supplies an already-signalled auto-reset event. On
842b0cb76f8f5fa9289bd779783c51ec24d75302, the test extracts the existing wait without changing its decision. It returned the still-pending value0in six runs. Withfde6a92694cd5b61891e17ca4100a526384a6e4f, the same test stays blocked and sees1after the gate opens in all six runs.Full native WARP GPU suite passed with 247 tests and one ignored under each D3D12 debug setting, and again with GPU timing enabled. Strict GPU Clippy in both configurations and asset policy passed. The paired test uses synthetic data and exercises the early wake. Device removal was not induced.
Coordination · Win32 event wait · D3D12 fence completion
Please retain the Git author if cherry-picking the fix or test. If folding this change into another commit, please retain
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:35:07Z.
Review: COMMENTED
Robust fence handling: SetEventOnCompletion failure or a non-WAIT_OBJECT_0 wake now falls back to polling GetCompletedValue rather than hanging or proceeding early — and the loop re-checks the actual submitted value, so a stale event signal can't pass the wait. Copy-back correctness preserved. LGTM.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:37:10Z.
Review: COMMENTED
Verified head
fde6a926cleanly merged ontoorigin/main(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP +VICTORY_D3D12_DEBUG=1).Code & Safety Review
Signalerror rather than proceeding to copy-back closes a real data-race window, and confirmingGetCompletedValue() >= valueinwait_for_fence_valuebeforeStep::GpuWrite/copy_back_marks/defer_afterensures spurious or stale auto-reset event wakeups cannot allow premature reads.Host::executeserializesself.eventunderself.submitted; onDXGI_ERROR_DEVICE_REMOVED, D3D12 guaranteesGetCompletedValue()returnsu64::MAX(>= *submitted), so the loop exits immediately into theremoveddiagnostic path instead of hanging.Local Verification (
VICTORY_D3D12_DEBUG=1)host::tests31/32 (including newsubmission_wait_confirms_fence_after_an_early_event; the 1 failure is the pre-existingdynamic_slots_are_held_until_releasedNVIDIA 1M view cap baseline),draw::tests20/20,queue::tests5/5,hold::tests10/10.host::tests32/32,draw::tests20/20,queue::tests5/5,hold::tests10/10.cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics) &cargo xtask policy(191 files ok): clean.Looks clean and ready to merge.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:31:08Z.
Automated triage for the maintainers.
Merge candidate. The synchronous wait in
Host::submit(host.rs) becomeswait_for_fence_value, which re-checksGetCompletedValueafter every wake, falls back to 1 ms polling if event registration or the wait fails, and stops on the device-removed value; a failedSignalgoes throughfailbefore any copy-back. This closes a real gap on main, where a failedSetEventOnCompletionlet copy-back run before the GPU finished. The WARP test with a gated queue checks that the wait does not return early.CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:47:58Z.
Review: APPROVED
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):wait_for_fence_valueconfirmsfence.GetCompletedValue() >= valuein a loop (falling back to polling ifSetEventOnCompletionorWaitForSingleObjectfails), preventing premature result read-backs after spurious/early event wakes while preserving device-removed handling.cargo test -p victory-gpu submission_wait_confirms_fence_after_an_early_event -- --test-threads=1(RTX 5090 & WARP): 1 passed, 0 failed on both.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-28T14:18:32Z.
Verified the completion invariant on a physical RTX 4060 Laptop GPU (8 GiB), Linux 6.17 / Wine 11, NVIDIA 590.48.1, diagnostic-relaxed vkd3d-proton 3.2.0 build 2576c0b4adfae4a+. This is a dirty local integration based on
3ed7d725f6, NOT an exact-head test of this PR.The VIctory-NVIDIA fork's
e205498cbackground-wait correction prompted a review of our synchronous path, which still ignored failed/premature event wakes. Your standalonefde6a92694addresses that path without importing the fork's renderer.A local ignored diagnostic regression exercises actual Host::execute (not only an extracted wait helper): close an empty native list, gate the native queue with a private CPU-signalled fence, pre-signal the existing auto-reset completion event, and execute from another thread. Release the private gate after a bounded 200 ms observation; require that execute has not already returned.
Before the port: 0/1 FAIL, early=Ok(()), completion before release=0. After porting your wait/Signal/removal handling while preserving our pending-submission observer: 1/1 PASS, early=Err(Timeout), before=0, after=1. Fresh intended-worktree builds 7.41/7.44 s; tests 0.65/0.85 s. The final fixture retains the empty list until completion; the initial failing fixture dropped its worker-owned list early and logged deferred native allocator release. That lifetime cleanup changed between legs, not the pre-release return assertion. An earlier fixture compilation error was our missing move capture, not a PR defect.
Command on both legs: VICTORY_LAB_SUBMISSIONS=1 VICTORY_WARP=0 DXVK_CONFIG='dxgi.hideNvidiaGpu = False' cargo test --locked --target x86_64-pc-windows-msvc -p victory-gpu --features diagnostics --lib lab_submission_does_not_retire_on_a_stale_event -- --ignored --nocapture --test-threads=1, through our guarded Wine wrapper. Actual adapter required, no WARP fallback or host skip. Scope 9 GiB/512 MiB; all global safety limits unchanged. Passing run GPU peak214 MiB, minimum available RAM10715 MiB.
Local evidence directories: verify-mixed-stale-event-control-fixed-fixture-20261128T141631Z/ and verify-mixed-pr2899-stale-event-20261128T141720Z/ (console and resource manifests). Adaptation credit: andrewpozdnakov7-jpg [email protected].
Limits: empty native work, no title shaders, no induced device removal/failed event-registration test, no native Windows debug-layer certification. This prevents premature copy-back/retirement; it does NOT establish a fix for our separate Xid109 CTX SWITCH TIMEOUT. In the saved title trace all 8,882 completed submissions reached their fence values; submission8,883 remained pending when the driver timed out. No new title run was performed.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.