Shaders: bound the test host fence waits so a wedged device fails instead of hanging #3141

Open
Mdemets wants to merge 1 commit from upstream-pr/3143 into main
Mdemets commented 2026-11-26 10:10:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Mdemets on 2026-11-26T10:10:16Z.


Three command-recording paths in the test host spin on GetCompletedValue() with yield_now() and no deadline. A device that neither signals the fence nor reports itself removed wedges the test binary forever — the same shape as the world hang in #71 (a submission that never finishes and ends in a TDR), just observed from the suite instead of a title run.

What changes

  • one wait_for_fence helper, poll every 2 ms, returns the device-removed reason exactly as the old loops did;
  • after 120 s without a signal it returns a named error saying no fence signal arrived and the device is not removed;
  • VICTORY_WAIT_SECS raises the deadline for a deliberately long run;
  • all three call sites now share it, so behaviour cannot drift between them.

Verification

cargo check -p victory-shader --lib clean on 63bcca4.

From the test fleet's branch (c5eb934), where it stopped a wedged A5000 from hanging the suite for the rest of the night.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6624314314 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3143). Originally posted by [Mdemets](https://github.com/Mdemets) on 2026-11-26T10:10:16Z. --- Three command-recording paths in the test host spin on `GetCompletedValue()` with `yield_now()` and no deadline. A device that neither signals the fence nor reports itself removed wedges the test binary forever — the same shape as the world hang in #71 (a submission that never finishes and ends in a TDR), just observed from the suite instead of a title run. ## What changes - one `wait_for_fence` helper, poll every 2 ms, returns the device-removed reason exactly as the old loops did; - after **120 s** without a signal it returns a named error saying no fence signal arrived and the device is not removed; - `VICTORY_WAIT_SECS` raises the deadline for a deliberately long run; - all three call sites now share it, so behaviour cannot drift between them. ## Verification `cargo check -p victory-shader --lib` clean on `63bcca4`. From the test fleet's branch (`c5eb934`), where it stopped a wedged A5000 from hanging the suite for the rest of the night.
Dukestar69 commented 2026-11-26 11:03:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T10:29:30Z.

Review: APPROVED


Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-shader --lib emit::host:: -- --test-threads=1: passed (parallel_warp_pipelines_and_draws).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly bounds test-host fence waits so a wedged device fails fast with an error instead of hanging CI/test runs.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6072451063 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3143#pullrequestreview-6072451063). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:29:30Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib emit::host:: -- --test-threads=1`: passed (`parallel_warp_pipelines_and_draws`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly bounds test-host fence waits so a wedged device fails fast with an error instead of hanging CI/test runs. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
steven-seagull27 commented 2026-11-26 11:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T10:32:52Z.


@Mdemets I tested the new wait helper on native Windows with an RTX 5080 (621.40) and built-in WARP. With a one-second deadline, both adapters accepted an immediate queue signal and a delayed fence signal. A healthy unsignaled fence returned the named timeout after 1,000–1,002 ms. Each case ran twice per adapter in a fresh process.

I found one case where the helper returns success before readback should proceed. In a separate process with no GPU work queued I called ID3D12Device5::RemoveDevice on the test process’s device. On both adapters the fence returned UINT64_MAX and the removal reason was 0x887A0005 (DXGI_ERROR_DEVICE_REMOVED), yet wait_for_fence returned Ok(()) on all four runs at 8cd3a449. The current >= 1 check accepts the removal value before reading the removal reason. D3D12 fence return values

The attached change checks the removal reason after reading the fence and rejects the sentinel. All four removal runs returned an error with the patch. Healthy signals and timeouts still behaved as expected. I also switched the deadline comparison to elapsed time. With the largest accepted u64 timeout, the original helper panicked adding the duration to Instant even on an already completed fence. The same fence returned immediately with the patch. The included regression creates private fences on a healthy device. Fix and regression test

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3143-fence-completion
git cherry-pick fe4446a418985c18a4f4913f96eddb8ce80c7b39
cargo test --locked -p victory-shader --lib emit::host::tests::fence_wait_rejects_the_removed_value -- --exact --nocapture

I also tested this with the latest shared-queue revision, 076c0e7e on #3093. The two PRs conflict at all three readback waits. The optional merge keeps one signal on the shared queue and uses the bounded wait for the requested fence value. Both adapters passed immediate and delayed signals, a wait for value 2 starting at 1, timeout, device removal, and the maximum timeout override. The hardware shared-queue test and existing WARP draw test also passed twice each. Tested integration branch

AI-assisted patch and tests using synthetic D3D12 work on Windows.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189510604 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3143#issuecomment-7189510604). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T10:32:52Z. --- @Mdemets I tested the new wait helper on native Windows with an RTX 5080 (621.40) and built-in WARP. With a one-second deadline, both adapters accepted an immediate queue signal and a delayed fence signal. A healthy unsignaled fence returned the named timeout after 1,000–1,002 ms. Each case ran twice per adapter in a fresh process. I found one case where the helper returns success before readback should proceed. In a separate process with no GPU work queued I called `ID3D12Device5::RemoveDevice` on the test process’s device. On both adapters the fence returned `UINT64_MAX` and the removal reason was `0x887A0005` (`DXGI_ERROR_DEVICE_REMOVED`), yet `wait_for_fence` returned `Ok(())` on all four runs at `8cd3a449`. The current `>= 1` check accepts the removal value before reading the removal reason. [D3D12 fence return values](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12fence-getcompletedvalue) The attached change checks the removal reason after reading the fence and rejects the sentinel. All four removal runs returned an error with the patch. Healthy signals and timeouts still behaved as expected. I also switched the deadline comparison to elapsed time. With the largest accepted `u64` timeout, the original helper panicked adding the duration to `Instant` even on an already completed fence. The same fence returned immediately with the patch. The included regression creates private fences on a healthy device. [Fix and regression test](https://github.com/steven-seagull27/VIctory/commit/fe4446a418985c18a4f4913f96eddb8ce80c7b39) ```powershell git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3143-fence-completion git cherry-pick fe4446a418985c18a4f4913f96eddb8ce80c7b39 cargo test --locked -p victory-shader --lib emit::host::tests::fence_wait_rejects_the_removed_value -- --exact --nocapture ``` I also tested this with the latest shared-queue revision, `076c0e7e` on #3093. The two PRs conflict at all three readback waits. The optional merge keeps one signal on the shared queue and uses the bounded wait for the requested fence value. Both adapters passed immediate and delayed signals, a wait for value 2 starting at 1, timeout, device removal, and the maximum timeout override. The hardware shared-queue test and existing WARP draw test also passed twice each. [Tested integration branch](https://github.com/steven-seagull27/VIctory/commit/e34cf3fe002d4c065091f702a32b0e6dce61ef78) AI-assisted patch and tests using synthetic D3D12 work on Windows.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3143:upstream-pr/3143'
git switch 'upstream-pr/3143'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3143'
git switch 'upstream-pr/3143'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3143'
git switch 'upstream-pr/3143'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3143'
git switch 'main'
git merge --squash 'upstream-pr/3143'
git switch 'main'
git merge --ff-only 'upstream-pr/3143'
git switch 'main'
git merge 'upstream-pr/3143'
git push origin 'main'
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
Marvisak/VIctory!3141
No description provided.