fix(victory-gpu): honor blocking fence waits for null events #314

Merged
mauroalvare merged 4 commits from upstream-pr/314 into main 2026-11-27 19:38:44 +00:00
mauroalvare commented 2026-11-26 02:26:41 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-26T02:26:41Z.


Change

ID3D12Fence::SetEventOnCompletion(value, nullptr) returned E_NOTIMPL in Neptune when the value was still pending. A title thread could resume while the queue still held the work that would signal the fence.

Register a private Win32 event on the fence's existing waiter list and block until the signal satisfies that wait. Release the waiter lock before settling any submitted GPU work. The event remains signaled once the request is satisfied even if the fence is rewound. An already reached value returns immediately.

This is the victory-gpu fence path in the runtime launched by tools/lancer_victory.ps1. Microsoft documents the blocking behavior for a null event handle. D3D12 fence documentation

Reproduction and oracle

The regression queues one four-byte CopyBufferRegion behind an unsignaled gate fence, followed by a completion signal. A separate thread calls SetEventOnCompletion with a null event. The test checks whether it registered before opening the gate, captures the HRESULT and fence value at return, and reads back the copied word.

Revision Null-event wait GPU word after the copy
c4c93bdc413191a9dc909998d2d53080a3f0c880 Returned early with 0x80004001 and completion value 0 0x13579bdf after the test opens the gate for cleanup
f9fb590475db4931f10393d30fe5a4d7a16bfed9 Registered before the gate opened and returned S_OK at completion value 1 0x13579bdf

Both outcomes reproduced on an RTX 5070 Ti (driver 621.40) and on Microsoft WARP, using both VICTORY_LATE_WAIT=0 and the launcher relay path (VICTORY_LATE_WAIT=3, VICTORY_RELAY=2, VICTORY_RELAY_OWN_QUEUE=1). The focused tests had no skips on either adapter. The fixture builds the buffers and their contents itself.

Verification

Windows x64, Rust 1.98.1 MSVC. Commands from third_party/victory.

Command Result
cargo test --locked --offline -p victory-gpu --lib --features diagnostics fence::tests::null_event_waits_for_a_queued_gpu_copy -- --exact --nocapture --test-threads=1 1 passed per adapter/mode on the fix, 1 failed per adapter/mode on base with the test applied
cargo test --locked --offline -p victory-gpu --lib --features diagnostics fence::tests:: -- --nocapture --test-threads=1 2 passed
cargo test --locked --offline -p victory-gpu --lib --features diagnostics -- --test-threads=1 197 passed, 3 failed, 3 ignored
cargo test --locked --offline -p victory-loader --test load_probe 2 passed
cargo build --locked --offline --release -p victory Passed
cargo xtask policy 199 files OK

The three GPU suite failures also reproduce on this base with the same suite command. spans_say_the_next_start_and_the_lowest_level_viewed, warp_card_fetch_copies_flagged_pieces_to_their_slots, and warp_card_patch_writes_the_masked_bytes_and_no_others.

From the repository root, python -m pytest -rs passed 1,342 tests and skipped 323 requiring built runtime artifacts that were absent locally. python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools passed.

Prepared with AI assistance (OpenAI Codex).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5502887408 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/314). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-26T02:26:41Z. --- ## Change `ID3D12Fence::SetEventOnCompletion(value, nullptr)` returned `E_NOTIMPL` in Neptune when the value was still pending. A title thread could resume while the queue still held the work that would signal the fence. Register a private Win32 event on the fence's existing waiter list and block until the signal satisfies that wait. Release the waiter lock before settling any submitted GPU work. The event remains signaled once the request is satisfied even if the fence is rewound. An already reached value returns immediately. This is the `victory-gpu` fence path in the runtime launched by `tools/lancer_victory.ps1`. Microsoft documents the blocking behavior for a null event handle. [D3D12 fence documentation](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12fence-seteventoncompletion) ## Reproduction and oracle The regression queues one four-byte `CopyBufferRegion` behind an unsignaled gate fence, followed by a completion signal. A separate thread calls `SetEventOnCompletion` with a null event. The test checks whether it registered before opening the gate, captures the HRESULT and fence value at return, and reads back the copied word. | Revision | Null-event wait | GPU word after the copy | | --- | --- | --- | | `c4c93bdc413191a9dc909998d2d53080a3f0c880` | Returned early with `0x80004001` and completion value `0` | `0x13579bdf` after the test opens the gate for cleanup | | `f9fb590475db4931f10393d30fe5a4d7a16bfed9` | Registered before the gate opened and returned `S_OK` at completion value `1` | `0x13579bdf` | Both outcomes reproduced on an RTX 5070 Ti (driver 621.40) and on Microsoft WARP, using both `VICTORY_LATE_WAIT=0` and the launcher relay path (`VICTORY_LATE_WAIT=3`, `VICTORY_RELAY=2`, `VICTORY_RELAY_OWN_QUEUE=1`). The focused tests had no skips on either adapter. The fixture builds the buffers and their contents itself. ## Verification Windows x64, Rust 1.98.1 MSVC. Commands from `third_party/victory`. | Command | Result | | --- | --- | | `cargo test --locked --offline -p victory-gpu --lib --features diagnostics fence::tests::null_event_waits_for_a_queued_gpu_copy -- --exact --nocapture --test-threads=1` | 1 passed per adapter/mode on the fix, 1 failed per adapter/mode on base with the test applied | | `cargo test --locked --offline -p victory-gpu --lib --features diagnostics fence::tests:: -- --nocapture --test-threads=1` | 2 passed | | `cargo test --locked --offline -p victory-gpu --lib --features diagnostics -- --test-threads=1` | 197 passed, 3 failed, 3 ignored | | `cargo test --locked --offline -p victory-loader --test load_probe` | 2 passed | | `cargo build --locked --offline --release -p victory` | Passed | | `cargo xtask policy` | 199 files OK | The three GPU suite failures also reproduce on this base with the same suite command. `spans_say_the_next_start_and_the_lowest_level_viewed`, `warp_card_fetch_copies_flagged_pieces_to_their_slots`, and `warp_card_patch_writes_the_masked_bytes_and_no_others`. From the repository root, `python -m pytest -rs` passed 1,342 tests and skipped 323 requiring built runtime artifacts that were absent locally. `python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools` passed. Prepared with AI assistance (OpenAI Codex).
mauroalvare commented 2026-11-26 18:41:37 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-26T18:41:37Z.


Rebased and pushed the fence fix over main's merged-submission handling. The null-event path waits on a private event and still supports the opt-in fence-word wake path. GitHub now reports the PR as mergeable.

All six fence tests passed. The queued-copy regression also passed on the RTX 5070 Ti and WARP with late waits, relay, merged submissions, and fence-word wakeups enabled. The wait returned S_OK after the signal and the readback matched.

GitHub Actions for this revision.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7200747754 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/314#issuecomment-7200747754). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-26T18:41:37Z. --- Rebased and pushed the fence fix over main's merged-submission handling. The null-event path waits on a private event and still supports the opt-in fence-word wake path. GitHub now reports the PR as mergeable. All six fence tests passed. The queued-copy regression also passed on the RTX 5070 Ti and WARP with late waits, relay, merged submissions, and fence-word wakeups enabled. The wait returned `S_OK` after the signal and the readback matched. [GitHub Actions for this revision](https://github.com/LooperSalty/AnyXboxX/actions/runs/45877572648).
LooperSalty commented 2026-11-27 12:24:00 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T12:24:00Z.


Review: fence.rs:153-165 waits on WaitForSingleObject(handle, 10) with no deadline. A fence that never reaches its value hangs the title thread forever. Please keep a deadline (e.g. 30 s), then log a warning, unregister the waiter and return E_NOTIMPL, as the previous code did.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7218197025 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/314#issuecomment-7218197025). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T12:24:00Z. --- Review: fence.rs:153-165 waits on WaitForSingleObject(handle, 10) with no deadline. A fence that never reaches its value hangs the title thread forever. Please keep a deadline (e.g. 30 s), then log a warning, unregister the waiter and return E_NOTIMPL, as the previous code did.
mauroalvare commented 2026-11-27 17:57:29 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T17:57:29Z.


Updated in 850a42a:

  • Restored a 30 s deadline (NULL_EVENT_TIMEOUT) on the blocking null-event wait in fence.rs. On timeout it logs blocking fence wait timed out, unregisters the private waiter, closes the event handle, and returns E_NOTIMPL.
  • Added null_event_times_out_and_unregisters_waiter alongside null_event_waits_for_a_queued_gpu_copy.

Verified all 5 fence::tests and cargo xtask policy (285 files ok).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224966487 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/314#issuecomment-7224966487). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T17:57:29Z. --- Updated in `850a42a`: - Restored a 30 s deadline (`NULL_EVENT_TIMEOUT`) on the blocking null-event wait in `fence.rs`. On timeout it logs `blocking fence wait timed out`, unregisters the private waiter, closes the event handle, and returns `E_NOTIMPL`. - Added `null_event_times_out_and_unregisters_waiter` alongside `null_event_waits_for_a_queued_gpu_copy`. Verified all 5 `fence::tests` and `cargo xtask policy` (285 files ok).
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
LooperSalty/AnyXboxX!314
No description provided.