Skip to content

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

Merged
Androtim merged 1 commit into
Androtim:mainfrom
RUIZ-Enrique-25002136:fix/texture-ahead-race-and-error
Dec 2, 2026
Merged

Androtim merged 1 commit into
Androtim:mainfrom
RUIZ-Enrique-25002136:fix/texture-ahead-race-and-error

Conversation

@RUIZ-Enrique-25002136

Copy link
Copy Markdown
Contributor

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)

@Androtim
Androtim merged commit b5467aa into Androtim:main Dec 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(gpu/texture/ahead): TOCTOU race in claim()/listed() and failed copy-queue batches still flip descriptors

2 participants