Shaders: bound synthetic test fence waits and retain unfinished submissions #3413

Open
github-bot wants to merge 1 commit from github-bot/gh-3413 into main AGit
Owner

@⁠carlosmegino on GitHub · 2026-11-26 23:08 UTC · original
carlosmegino:codex/shader-dispatch-fence-timeout → main · +249 −26 · 1 files · 1 commits · open

A synthetic shader test whose GPU submission never finishes currently spins indefinitely; a removed fence can also report u64::MAX and be mistaken for success before readback. This adds a shared, cumulative 30-second fence wait to the test host's draw and dispatch paths.

Follow-up to @⁠fuzeofficlal's non-blocking suggestion on #3180. Based on main 63bcca43c6a00a758510398fa43096ce7e4f7df0; head 60771e1f65f6ff3df086435dbf8e635ced92a8de. #3180 is unchanged.

Behavior and resource lifetime

  • Device-removal errors and u64::MAX are rejected before the fence value can count as completion. Readback is reached only after a successful wait.
  • One Instant is created outside the polling loop. Its elapsed time accumulates across polls and yields; the deadline is not restarted. The limit covers the fence wait after Signal, not blocking inside a D3D12 API call.
  • Fence creation and the command-list cast happen before submission. After submission, a signal/wait error (or unwinding) retains the queue, allocator, command list, fence, descriptor heaps, upload/output/readback resources, root signature and PSO references until process exit. This deliberately trades failure-path memory reclamation for safety; no completion is assumed.
  • On success, objects are released normally after completion. This branch creates fresh command objects per call and has no allocator/list reset or reusable-object pool.
  • Changes are confined to #[cfg(test)] helpers, call sites and regressions in crates/victory-shader/src/emit/host.rs. Runtime adapter initialization, shader translation and #3180's Wave64 fixtures are untouched.

Relationship to #1734

Reviewed #1734 at 7d6cff93e0804f983f389686744fc304213853fd. Both PRs touch the draw/dispatch wait sites, so integration needs manual conflict resolution.

#1734 targets performance: event-based waiting and reuse of command objects. Its 100 ms waits allow periodic device-status checks, but do not impose a total deadline. This PR targets robustness: a total deadline, explicit removed-fence detection, and lifetime protection when completion cannot be established. It keeps the existing yield-based polling and makes no performance claim.

When combining them, the pooled fence's expected timeline value must replace this branch's one-shot value of 1. A submitted batch that times out or fails must be quarantined from the pool without resetting or destroying it; retain its command objects, event and per-dispatch resources until completion is proven or the process exits. Simply clearing Reused::recording, calling Reset, or assigning *reused = None would not preserve this guarantee for potentially active work. Pre-submission recording failures are a separate case, since that recording has not reached the GPU. The cached event must also remain valid while its fence registration can still signal it.

This PR is independently based on main, not a combined implementation of #1734. No combined-tree execution is claimed.

Existing validation

Reused the recorded evidence for this commit; no redundant test reruns for the publication review:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed.
  • cargo xtask policy: 191 files OK, using this worktree's own maintenance build.
  • cargo test -p victory-shader --locked --lib emit::host::tests:: -- --test-threads=1: 6 passed. Five new deterministic regressions cover success, the exact timeout boundary, removed-fence/device-status cases, and release/retention of submission objects; the existing concurrent WARP draw test also passes.
  • cargo test -p victory-shader --locked --lib emit::memory_tests::root_views_read_their_copy_and_zeros_past_it -- --test-threads=1: 1 passed, exercising dispatch readback.
  • git diff --check: passed. The full workspace test suite was not rerun for this change.

Timeout/removal regressions inject status queries and a clock. They do not deliberately hang a GPU or remove a real device.

Pre-existing formatting differences

cargo fmt --all -- --check was run and fails on existing formatting in main (including victory-formats/src/texture.rs), so this is not claimed as a green check. The modified file was also compared with rustfmt output against the original main version: the same four existing formatting regions remain, with no new differences. They concern the GS bytecode pointer expression, the format alternatives and buffer patterns in view_strides, and the TypedUav match arm. New/changed code is rustfmt-formatted; unrelated formatting is preserved to keep the diff scoped.

**@⁠carlosmegino** on GitHub · 2026-11-26 23:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/3413) `carlosmegino:codex/shader-dispatch-fence-timeout` → `main` · +249 −26 · 1 files · 1 commits · open A synthetic shader test whose GPU submission never finishes currently spins indefinitely; a removed fence can also report `u64::MAX` and be mistaken for success before readback. This adds a shared, cumulative 30-second fence wait to the test host's `draw` and `dispatch` paths. Follow-up to [@⁠fuzeofficlal's non-blocking suggestion on #3180](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3180). Based on main `63bcca43c6a00a758510398fa43096ce7e4f7df0`; head `60771e1f65f6ff3df086435dbf8e635ced92a8de`. #3180 is unchanged. ## Behavior and resource lifetime - Device-removal errors and `u64::MAX` are rejected before the fence value can count as completion. Readback is reached only after a successful wait. - One `Instant` is created outside the polling loop. Its elapsed time accumulates across polls and yields; the deadline is not restarted. The limit covers the fence wait after `Signal`, not blocking inside a D3D12 API call. - Fence creation and the command-list cast happen before submission. After submission, a signal/wait error (or unwinding) retains the queue, allocator, command list, fence, descriptor heaps, upload/output/readback resources, root signature and PSO references until process exit. This deliberately trades failure-path memory reclamation for safety; no completion is assumed. - On success, objects are released normally after completion. This branch creates fresh command objects per call and has no allocator/list reset or reusable-object pool. - Changes are confined to `#[cfg(test)]` helpers, call sites and regressions in `crates/victory-shader/src/emit/host.rs`. Runtime adapter initialization, shader translation and #3180's Wave64 fixtures are untouched. ## Relationship to #1734 Reviewed #1734 at `7d6cff93e0804f983f389686744fc304213853fd`. Both PRs touch the draw/dispatch wait sites, so integration needs manual conflict resolution. #1734 targets **performance**: event-based waiting and reuse of command objects. Its 100 ms waits allow periodic device-status checks, but do not impose a total deadline. This PR targets **robustness**: a total deadline, explicit removed-fence detection, and lifetime protection when completion cannot be established. It keeps the existing yield-based polling and makes no performance claim. When combining them, the pooled fence's expected timeline value must replace this branch's one-shot value of 1. A submitted batch that times out or fails must be quarantined from the pool without resetting or destroying it; retain its command objects, event and per-dispatch resources until completion is proven or the process exits. Simply clearing `Reused::recording`, calling `Reset`, or assigning `*reused = None` would not preserve this guarantee for potentially active work. Pre-submission recording failures are a separate case, since that recording has not reached the GPU. The cached event must also remain valid while its fence registration can still signal it. This PR is independently based on main, not a combined implementation of #1734. No combined-tree execution is claimed. ## Existing validation Reused the recorded evidence for this commit; no redundant test reruns for the publication review: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed. - `cargo xtask policy`: 191 files OK, using this worktree's own maintenance build. - `cargo test -p victory-shader --locked --lib emit::host::tests:: -- --test-threads=1`: 6 passed. Five new deterministic regressions cover success, the exact timeout boundary, removed-fence/device-status cases, and release/retention of submission objects; the existing concurrent WARP draw test also passes. - `cargo test -p victory-shader --locked --lib emit::memory_tests::root_views_read_their_copy_and_zeros_past_it -- --test-threads=1`: 1 passed, exercising dispatch readback. - `git diff --check`: passed. The full workspace test suite was not rerun for this change. Timeout/removal regressions inject status queries and a clock. They do not deliberately hang a GPU or remove a real device. ## Pre-existing formatting differences `cargo fmt --all -- --check` was run and fails on existing formatting in main (including `victory-formats/src/texture.rs`), so this is not claimed as a green check. The modified file was also compared with rustfmt output against the original main version: the same four existing formatting regions remain, with no new differences. They concern the GS bytecode pointer expression, the format alternatives and buffer patterns in `view_strides`, and the `TypedUav` match arm. New/changed code is rustfmt-formatted; unrelated formatting is preserved to keep the diff scoped.
Follow up on @fuzeofficlal's non-blocking suggestion in Marvisak/VIctory#3180: https://github.com/Marvisak/VIctory/pull/3180#pullrequestreview-6081236830

Share a 30-second fence wait between draw and dispatch, reject u64::MAX as device removal, and retain submitted resources on signal or wait failure. Use synthetic clocks and status queries to test timeout, removal, and resource lifetime without hanging a GPU.

Related: #1734 proposes event waits and command-object reuse; this change adds a total deadline and error-path lifetime protection on main without the performance refactor.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:06:59 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 23:22 UTC · original · reviewed

This overlaps #3143 (Mdemets, still open: "bound the test host fence waits so a wedged device fails instead of hanging"), which changes the same file (crates/victory-shader/src/emit/host.rs) for the same reason. The description doesn't mention it. Worth linking it and agreeing with Mdemets which one goes forward, or what this adds on top (the cumulative deadline and the u64::MAX / device-removed check), so the maintainer doesn't get two versions of the same fix.

**@⁠AurumCarlos** on GitHub · 2026-11-26 23:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/3413#pullrequestreview-6081431864) · **reviewed** This overlaps #3143 (Mdemets, still open: "bound the test host fence waits so a wedged device fails instead of hanging"), which changes the same file (`crates/victory-shader/src/emit/host.rs`) for the same reason. The description doesn't mention it. Worth linking it and agreeing with Mdemets which one goes forward, or what this adds on top (the cumulative deadline and the `u64::MAX` / device-removed check), so the maintainer doesn't get two versions of the same fix.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 23:26 UTC · original · approved these changes

LGTM! Verified locally with cargo xtask policy, cargo clippy --locked -p victory-shader --all-targets -- -D warnings, cargo clippy --locked -p victory-shader --all-features -- -D warnings, and VICTORY_D3D12_DEBUG=1 runs of emit::host:: (6/6 passed) and emit::valu_tests:: (35/35 passed) on both RTX 5090 (VICTORY_WARP=0) and WARP (VICTORY_WARP=1) with no formatting issues on the PR's changed lines.

  • wait_for_fence (crates/victory-shader/src/emit/host.rs:68-100) checks GetDeviceRemovedReason and completed == u64::MAX before treating completed >= 1 as completion and bounds waits with FENCE_TIMEOUT (30s).
  • retain_until_complete / submit_and_wait (host.rs:107-154, 1328, 2074) cleanly retain the queue, allocator, command list, fence, readback buffers, heaps, UAVs, root signature, and PSO across both draw and dispatch failure/unwind paths while releasing them normally on completion.

(Minor non-blocking note for a follow-up: the existing fuses_fmad probe at host.rs:801 outside #[cfg(test)] still submits before creating its fence and polls without a timeout or u64::MAX check, and Signal errors could optionally query GetDeviceRemovedReason.)

**@⁠fuzeofficlal** on GitHub · 2026-11-26 23:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/3413#pullrequestreview-6081447823) · **approved these changes** LGTM! Verified locally with `cargo xtask policy`, `cargo clippy --locked -p victory-shader --all-targets -- -D warnings`, `cargo clippy --locked -p victory-shader --all-features -- -D warnings`, and `VICTORY_D3D12_DEBUG=1` runs of `emit::host::` (6/6 passed) and `emit::valu_tests::` (35/35 passed) on both RTX 5090 (`VICTORY_WARP=0`) and WARP (`VICTORY_WARP=1`) with no formatting issues on the PR's changed lines. - `wait_for_fence` (`crates/victory-shader/src/emit/host.rs:68-100`) checks `GetDeviceRemovedReason` and `completed == u64::MAX` before treating `completed >= 1` as completion and bounds waits with `FENCE_TIMEOUT` (30s). - `retain_until_complete` / `submit_and_wait` (`host.rs:107-154, 1328, 2074`) cleanly retain the queue, allocator, command list, fence, readback buffers, heaps, UAVs, root signature, and PSO across both `draw` and `dispatch` failure/unwind paths while releasing them normally on completion. *(Minor non-blocking note for a follow-up: the existing `fuses_fmad` probe at `host.rs:801` outside `#[cfg(test)]` still submits before creating its fence and polls without a timeout or `u64::MAX` check, and `Signal` errors could optionally query `GetDeviceRemovedReason`.)*
Author
Owner

@⁠carlosmegino on GitHub · 2026-11-26 23:42 UTC · original

Thanks for highlighting #3143. I've reviewed both implementations and agree that we should consolidate the work rather than maintain competing fixes.

Following fuzeofficlal's approval, #3413 now has independent hardware and WARP validation for device-removal detection, cumulative timeouts and submission resource lifetime protection.

@⁠Mdemets, I'm happy to collaborate on a combined implementation that preserves your configurable timeout, polling interval and coverage of all three submission paths, together with the safety guarantees and regression tests from #3413.

I've also noted @⁠steven-seagull27's existing removal-sentinel/elapsed-time correction and shared-queue integration on #3143. We should account for that work, and the event/object-reuse proposals, when choosing a single integration path.

Let me know which approach you prefer.

**@⁠carlosmegino** on GitHub · 2026-11-26 23:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/3413#issuecomment-7205780672) Thanks for highlighting #3143. I've reviewed both implementations and agree that we should consolidate the work rather than maintain competing fixes. Following fuzeofficlal's approval, #3413 now has independent hardware and WARP validation for device-removal detection, cumulative timeouts and submission resource lifetime protection. @⁠Mdemets, I'm happy to collaborate on a combined implementation that preserves your configurable timeout, polling interval and coverage of all three submission paths, together with the safety guarantees and regression tests from #3413. I've also noted @⁠steven-seagull27's existing removal-sentinel/elapsed-time correction and shared-queue integration on #3143. We should account for that work, and the event/object-reuse proposals, when choosing a single integration path. Let me know which approach you prefer.
Author
Owner

@⁠carlosmegino on GitHub · 2026-11-26 23:42 UTC · original

Thanks again for the thorough review and independent validation.

I agree that fuses_fmad deserves the same fence completion and resource lifetime guarantees. I'll coordinate with Mdemets regarding #3143 before extending the implementation, so we avoid further duplication.

Recorded follow-up work, pending that consolidation:

  • Extend the agreed helper to fuses_fmad: create the fence before submission, use a cumulative bounded wait, reject device removal/u64::MAX before completion, and protect potentially active submission resources on failure.
  • Improve Signal failure diagnostics by also querying GetDeviceRemovedReason, while preserving the original Signal error and resource-retention behavior.

These are deferred follow-ups; no additional implementation is being opened in parallel.

**@⁠carlosmegino** on GitHub · 2026-11-26 23:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/3413#issuecomment-7205780899) Thanks again for the thorough review and independent validation. I agree that fuses_fmad deserves the same fence completion and resource lifetime guarantees. I'll coordinate with Mdemets regarding #3143 before extending the implementation, so we avoid further duplication. Recorded follow-up work, pending that consolidation: - [ ] Extend the agreed helper to fuses_fmad: create the fence before submission, use a cumulative bounded wait, reject device removal/u64::MAX before completion, and protect potentially active submission resources on failure. - [ ] Improve Signal failure diagnostics by also querying GetDeviceRemovedReason, while preserving the original Signal error and resource-retention behavior. These are deferred follow-ups; no additional implementation is being opened in parallel.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-27 01:27 UTC · original · approved these changes

LGTM — verified on Windows (RTX 5090 + WARP):

  • cargo test -p victory-shader --lib emit::host::tests:: passed (6/6, including all 5 new fence-timeout and submission-retention tests)
  • cargo test -p victory-shader --lib emit::crosslane_tests:: passed (5/5) on RTX 5090 and under VICTORY_WARP=1
  • cargo clippy -p victory-shader --all-targets -- -D warnings and --all-features --all-targets -- -D warnings both passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

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

**@⁠Dukestar69** on GitHub · 2026-11-27 01:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3413#pullrequestreview-6082274707) · **approved these changes** LGTM — verified on Windows (RTX 5090 + WARP): - `cargo test -p victory-shader --lib emit::host::tests::` passed (6/6, including all 5 new fence-timeout and submission-retention tests) - `cargo test -p victory-shader --lib emit::crosslane_tests::` passed (5/5) on RTX 5090 and under `VICTORY_WARP=1` - `cargo clippy -p victory-shader --all-targets -- -D warnings` and `--all-features --all-targets -- -D warnings` both passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3413/head:github-bot/gh-3413'
git switch 'github-bot/gh-3413'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3413'
git switch 'github-bot/gh-3413'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3413'
git switch 'github-bot/gh-3413'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3413'
git switch 'main'
git merge --squash 'github-bot/gh-3413'
git switch 'main'
git merge --ff-only 'github-bot/gh-3413'
git switch 'main'
git merge 'github-bot/gh-3413'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3413
No description provided.