fix(gpu/uav_pool): reversed STARTED/QUEUED load order in retire_uavs can recycle in-flight UAV buffers #316

Closed
opened 2026-12-02 09:14:10 +00:00 by RUIZ-Enrique-25002136 · 1 comment
RUIZ-Enrique-25002136 commented 2026-12-02 09:14:10 +00:00 (Migrated from github.com)
Contributor

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


Summary

uav_pool::retire_uavs reads STARTED before crate::queue::queued(), which is the opposite order of host::retire / host::retire_resource and races with queue::behind incrementing STARTED before decrementing QUEUED. As a result, still-in-flight scratch UAV buffers can be under-counted and immediately recycled into UAV_SPARE.

Evidence (file:line & Code Proof)

  • crates/victory-gpu/src/host/uav_pool.rs:139-143 (uav_pool::retire_uavs):
    pub(super) fn retire_uavs(buffers: Vec<(ID3D12Resource, u64)>) {
        let started = STARTED.load(Ordering::Acquire) + crate::queue::queued();
        let finished = FINISHED.load(Ordering::Acquire);
        retire_uavs_at(buffers, started, finished);
    }
    
  • Submit-worker ordering (crates/victory-gpu/src/queue/behind.rs:696-712):
    The submit worker increments STARTED (inside host.execute_late / host.execute_parts) before calling QUEUED.fetch_sub(..., Relaxed).
  • Reference correct ordering (crates/victory-gpu/src/host.rs:820-821, 833-834):
    retire and retire_resource explicitly load queued() before STARTED.load(Ordering::Acquire).
  • Race interleaving:
    1. STARTED = 10, QUEUED = 1, FINISHED = 10.
    2. retire_uavs evaluates the left operand of +: reads STARTED == 10.
    3. victory-submit executes submission #11 (STARTED -> 11, GPU work in flight) and decrements QUEUED -> 0.
    4. retire_uavs reads queued() == 0, computes started = 10 <= finished, and immediately returns the buffers to UAV_SPARE via give_uavs (bypassing RETIRED_UAVS). Even when started > finished, started is under-counted by 1 (or 1 + parts.len() for Job::Joined), allowing drain_retired_uavs to release buffers before submission #11 finishes.

Impact

Device-local scratch UAV buffers still referenced by an active GPU submission can be immediately handed out by take_uav to another command list, causing GPU data corruption, D3D12 resource-state hazards, or device removal (TDR).

AI-Ready Fix Specification

  1. In crates/victory-gpu/src/host/uav_pool.rs (retire_uavs), load let queued = crate::queue::queued(); before STARTED.load(Ordering::Acquire) and compute let started = STARTED.load(Ordering::Acquire) + queued;.
  2. In crates/victory-gpu/src/queue/behind.rs (where QUEUED is decremented and read via queued()), upgrade QUEUED memory ordering from Relaxed to Release on fetch_sub and Acquire on load (matching STARTED synchronization) so neither the compiler nor CPU can reorder the pair.
  3. Add a unit test in uav_pool (if pure-logic retire_uavs_at / atomic ordering helper is testable) and run cargo clippy --workspace --all-targets --locked -- -D warnings on Windows CI.
<!-- greyfinch-sync:Androtim/MiniVI:issue:6741193251 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/issues/316). Originally posted by [RUIZ-Enrique-25002136](https://github.com/RUIZ-Enrique-25002136) on 2026-12-02T09:14:10Z. --- ## Summary `uav_pool::retire_uavs` reads `STARTED` **before** `crate::queue::queued()`, which is the opposite order of `host::retire` / `host::retire_resource` and races with `queue::behind` incrementing `STARTED` before decrementing `QUEUED`. As a result, still-in-flight scratch UAV buffers can be under-counted and immediately recycled into `UAV_SPARE`. ## Evidence (`file:line` & Code Proof) - **`crates/victory-gpu/src/host/uav_pool.rs:139-143` (`uav_pool::retire_uavs`):** ```rust pub(super) fn retire_uavs(buffers: Vec<(ID3D12Resource, u64)>) { let started = STARTED.load(Ordering::Acquire) + crate::queue::queued(); let finished = FINISHED.load(Ordering::Acquire); retire_uavs_at(buffers, started, finished); } ``` - **Submit-worker ordering (`crates/victory-gpu/src/queue/behind.rs:696-712`):** The submit worker increments `STARTED` (inside `host.execute_late` / `host.execute_parts`) **before** calling `QUEUED.fetch_sub(..., Relaxed)`. - **Reference correct ordering (`crates/victory-gpu/src/host.rs:820-821, 833-834`):** `retire` and `retire_resource` explicitly load `queued()` **before** `STARTED.load(Ordering::Acquire)`. - **Race interleaving:** 1. `STARTED = 10`, `QUEUED = 1`, `FINISHED = 10`. 2. `retire_uavs` evaluates the left operand of `+`: reads `STARTED == 10`. 3. `victory-submit` executes submission #11 (`STARTED` -> `11`, GPU work in flight) and decrements `QUEUED` -> `0`. 4. `retire_uavs` reads `queued() == 0`, computes `started = 10 <= finished`, and immediately returns the buffers to `UAV_SPARE` via `give_uavs` (bypassing `RETIRED_UAVS`). Even when `started > finished`, `started` is under-counted by `1` (or `1 + parts.len()` for `Job::Joined`), allowing `drain_retired_uavs` to release buffers before submission #11 finishes. ## Impact Device-local scratch UAV buffers still referenced by an active GPU submission can be immediately handed out by `take_uav` to another command list, causing GPU data corruption, D3D12 resource-state hazards, or device removal (TDR). ## AI-Ready Fix Specification 1. In `crates/victory-gpu/src/host/uav_pool.rs` (`retire_uavs`), load `let queued = crate::queue::queued();` **before** `STARTED.load(Ordering::Acquire)` and compute `let started = STARTED.load(Ordering::Acquire) + queued;`. 2. In `crates/victory-gpu/src/queue/behind.rs` (where `QUEUED` is decremented and read via `queued()`), upgrade `QUEUED` memory ordering from `Relaxed` to `Release` on `fetch_sub` and `Acquire` on `load` (matching `STARTED` synchronization) so neither the compiler nor CPU can reorder the pair. 3. Add a unit test in `uav_pool` (if pure-logic `retire_uavs_at` / atomic ordering helper is testable) and run `cargo clippy --workspace --all-targets --locked -- -D warnings` on Windows CI.
github-actions[bot] commented 2026-12-02 09:14:21 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Androtim/MiniVI. Originally posted by github-actions[bot] on 2026-12-02T09:14:21Z.


Please attach both logs from the run that went wrong so we can investigate without guessing. Paste %LOCALAPPDATA% into the File Explorer address bar to find them:

  1. Play log in %LOCALAPPDATA%\victory\logs\: the newest .log from that run (the console prints its path at startup on the Log: ... line).
  2. Crash log: %LOCALAPPDATA%\victory\data\<TitleId>\crashes.log, and if present, the newest .crash.log in %LOCALAPPDATA%\victory\data\<TitleId>\temp\.

Please also include:

  • GPU & VRAM, Windows version (10 or 11)
  • MiniVI preset / launcher flags (play-minivi.ps1 preset, DLSS/FG/RT, custom VICTORY_* vars) and commit SHA

(Clean-room policy: please only attach text logs/screenshots — do not upload copyrighted game files or executables.)

<!-- greyfinch-sync:Androtim/MiniVI:comment:7340585958 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/issues/316#issuecomment-7340585958). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-02T09:14:21Z. --- Please attach both logs from the run that went wrong so we can investigate without guessing. Paste `%LOCALAPPDATA%` into the File Explorer address bar to find them: 1. **Play log** in `%LOCALAPPDATA%\victory\logs\`: the newest `.log` from that run (the console prints its path at startup on the `Log: ...` line). 2. **Crash log**: `%LOCALAPPDATA%\victory\data\<TitleId>\crashes.log`, and if present, the newest `.crash.log` in `%LOCALAPPDATA%\victory\data\<TitleId>\temp\`. Please also include: - **GPU & VRAM**, **Windows version** (10 or 11) - **MiniVI preset / launcher flags** (`play-minivi.ps1` preset, DLSS/FG/RT, custom `VICTORY_*` vars) and **commit SHA** *(Clean-room policy: please only attach text logs/screenshots — do not upload copyrighted game files or executables.)*
Sign in to join this conversation.
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#316
No description provided.