fix(gpu/texture/ahead): close claim/listed TOCTOU window and handle copy-queue failures (#317) #336

Merged
RUIZ-Enrique-25002136 merged 1 commit from upstream-pr/336 into main 2026-12-02 13:34:26 +00:00
RUIZ-Enrique-25002136 commented 2026-12-02 13:20:10 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by RUIZ-Enrique-25002136 on 2026-12-02T13:20:10Z.


Summary

Fixes both concurrency and copy-queue error-handling bugs in crates/victory-gpu/src/texture/ahead.rs tracked in #317.

Fixes #317

Changes

  1. Close claim() / listed() TOCTOU window:
    • Changed ON_THEIR_WAY entries from (u64, Arc<Job>) to (u64, Option<Arc<Job>>) where None reserves a copy.serial slot atomically under the ON_THEIR_WAY lock alongside the NONE -> PENDING CAS.
    • Added RAII PendingGuard so if staging() returns None, fails filtering, or unwinds, copy.ahead is reverted to LISTED, the reservation is removed, IN_FLIGHT is updated, and LANDED.notify_all() wakes any waiters.
    • Added wait_known() so concurrent claim() calls encountering PENDING wait on LANDED until the reservation resolves to Some(job) (Taken::Known) or clears (None), while listed() waits on LANDED for both None reservations and published Some(job) entries.
  2. Prevent failed copy-queue batches from flipping descriptors or resetting in-flight allocators:
    • Replaced Job::then's Option<Vec<...>> with Then::{Pending, Done, Failed} so late job.then(...) calls on a failed Taken::Known job also never fire.
    • Updated finish(jobs, ok): when ok == false, leaves staging.uploaded = false and staging.dirty = true, sets copy.ahead = LISTED, decrements BYTES, transitions job.then to Then::Failed without running callbacks, removes jobs from ON_THEIR_WAY, notifies LANDED, and skips flip_now().
    • Tracked Worker::allocator_in_flight across ExecuteCommandLists -> Signal -> SetEventOnCompletion; if a failure happens after ExecuteCommandLists, retires the old allocator via crate::host::retire and replaces it with a fresh CreateCommandAllocator before any subsequent Reset().
  3. Unit tests:
    • Added failed_finish_reverts_state_and_suppresses_callbacks and wait_known_waits_for_pending_reservation_to_clear.

Rig Specs Tested On

  • CPU: Linux workstation (x86_64)
  • GPU & VRAM: N/A (Windows-only victory-gpu crate; full clippy & tests verified on GitHub Actions windows-latest CI)
  • System RAM: N/A
  • OS & GPU Driver: Linux (x86_64) — Windows x86_64-pc-windows-msvc CI verifies compilation, clippy, and unit tests

Run Settings & Profile

  • Build & Commit SHA: rebased on origin/main (b0842d9)
  • Console Profile & Internal Resolution / Scale: N/A
  • Ray Tracing: N/A
  • Upscaling: N/A
  • Frame Generation: N/A
  • Launcher Command / Preset & Extra VICTORY_* Overrides: N/A
  • Scene / Area & Session Length: N/A

Measurements & Verification

  • Base FPS (without Frame Gen): N/A
  • Frame-Gen FPS (if enabled): N/A
  • VRAM / RAM Usage: N/A
  • Crashes / DRED Resets: N/A
  • Automated Checks:
    • cargo clippy --workspace --all-targets --locked -- -D warnings (verified on GitHub Actions windows-latest CI)
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (verified on GitHub Actions windows-latest CI)
    • cargo test --locked -p xtask -> 8 passed, 0 failed
    • cargo xtask policy -> asset policy: 324 files ok
    • cargo test -p victory-gpu --locked -- --test-threads=1 (verified on GitHub Actions windows-latest CI)
<!-- greyfinch-sync:Androtim/MiniVI:issue:5607245004 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/336). Originally posted by [RUIZ-Enrique-25002136](https://github.com/RUIZ-Enrique-25002136) on 2026-12-02T13:20:10Z. --- ## Summary Fixes both concurrency and copy-queue error-handling bugs in `crates/victory-gpu/src/texture/ahead.rs` tracked in #317. Fixes #317 ### Changes 1. **Close `claim()` / `listed()` TOCTOU window:** - Changed `ON_THEIR_WAY` entries from `(u64, Arc<Job>)` to `(u64, Option<Arc<Job>>)` where `None` reserves a `copy.serial` slot atomically under the `ON_THEIR_WAY` lock alongside the `NONE -> PENDING` CAS. - Added RAII `PendingGuard` so if `staging()` returns `None`, fails filtering, or unwinds, `copy.ahead` is reverted to `LISTED`, the reservation is removed, `IN_FLIGHT` is updated, and `LANDED.notify_all()` wakes any waiters. - Added `wait_known()` so concurrent `claim()` calls encountering `PENDING` wait on `LANDED` until the reservation resolves to `Some(job)` (`Taken::Known`) or clears (`None`), while `listed()` waits on `LANDED` for both `None` reservations and published `Some(job)` entries. 2. **Prevent failed copy-queue batches from flipping descriptors or resetting in-flight allocators:** - Replaced `Job::then`'s `Option<Vec<...>>` with `Then::{Pending, Done, Failed}` so late `job.then(...)` calls on a failed `Taken::Known` job also never fire. - Updated `finish(jobs, ok)`: when `ok == false`, leaves `staging.uploaded = false` and `staging.dirty = true`, sets `copy.ahead = LISTED`, decrements `BYTES`, transitions `job.then` to `Then::Failed` without running callbacks, removes jobs from `ON_THEIR_WAY`, notifies `LANDED`, and skips `flip_now()`. - Tracked `Worker::allocator_in_flight` across `ExecuteCommandLists` -> `Signal` -> `SetEventOnCompletion`; if a failure happens after `ExecuteCommandLists`, retires the old allocator via `crate::host::retire` and replaces it with a fresh `CreateCommandAllocator` before any subsequent `Reset()`. 3. **Unit tests:** - Added `failed_finish_reverts_state_and_suppresses_callbacks` and `wait_known_waits_for_pending_reservation_to_clear`. ## Rig Specs Tested On - **CPU:** Linux workstation (`x86_64`) - **GPU & VRAM:** N/A (Windows-only `victory-gpu` crate; full clippy & tests verified on GitHub Actions `windows-latest` CI) - **System RAM:** N/A - **OS & GPU Driver:** Linux (`x86_64`) — Windows `x86_64-pc-windows-msvc` CI verifies compilation, clippy, and unit tests ## Run Settings & Profile - **Build & Commit SHA:** rebased on `origin/main` (`b0842d9`) - **Console Profile & Internal Resolution / Scale:** N/A - **Ray Tracing:** N/A - **Upscaling:** N/A - **Frame Generation:** N/A - **Launcher Command / Preset & Extra `VICTORY_*` Overrides:** N/A - **Scene / Area & Session Length:** N/A ## Measurements & Verification - **Base FPS (without Frame Gen):** N/A - **Frame-Gen FPS (if enabled):** N/A - **VRAM / RAM Usage:** N/A - **Crashes / DRED Resets:** N/A - **Automated Checks:** - [ ] `cargo clippy --workspace --all-targets --locked -- -D warnings` (verified on GitHub Actions `windows-latest` CI) - [ ] `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` (verified on GitHub Actions `windows-latest` CI) - [x] `cargo test --locked -p xtask` -> 8 passed, 0 failed - [x] `cargo xtask policy` -> `asset policy: 324 files ok` - [ ] `cargo test -p victory-gpu --locked -- --test-threads=1` (verified on GitHub Actions `windows-latest` CI)
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
Androtim/MiniVI!336
No description provided.