gpu/resource: pin aliased texture source while alias copy uses it #34

Merged
Androtim merged 1 commit from upstream-pr/34 into main 2026-11-28 18:44:31 +00:00
Androtim commented 2026-11-28 10:24:03 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-28T10:24:03Z.


Summary

Port rustno1-coder/VIctory-NVIDIA 74d6f24 (after xceless/victory-fork PR #1336 / 8fab6fb):

  • Add object::add_ref_alive (crates/victory-gpu/src/object.rs) to increment
    efs via etch_update only while
  • Add
    esource::Held + lias_with +
    esource::is_aliased (crates/victory-gpu/src/resource.rs) so lias_of() pins the aliased source resource while TARGETS_AT's lock is held and returns an RAII Held guard used by draw.rs::readable() and external.rs::prepare_input().
  • Update lookup-only callers in
    esource::hosted() (3 sites), draw.rs, and exture/ahead.rs to call is_aliased() so they never take/drop references to another resource mid-work.
  • Added unit tests object::tests::add_ref_alive_increments_live_and_refuses_zero and
    esource::tests::an_alias_source_is_held_after_the_title_releases_it.

Rig Specs Tested On

  • CPU: 13th Gen Intel(R) Core(TM) i7-13700F
  • GPU & VRAM: NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM)
  • System RAM: 32 GiB
  • OS & GPU Driver: Windows 11 Home (Build 26300) / Driver 32.0.16.2124

Run Settings & Profile

  • Build & Commit SHA:
    elease (and
    elease --features diagnostics) @ $sha
  • Console Profile & Internal Resolution / Scale: series-s (Quality scale .6666667, title output 960x540)
  • Ray Tracing: off
  • Upscaling: DLSS quality (Streamline 2.14.16)
  • Frame Generation: off
  • Launcher Command / Preset & Extra VICTORY_ Overrides:* erify-world.ps1 play.rs SETTINGS preset + VICTORY_CARD_ACCOUNTING=1, VICTORY_D3D12_DRED=light, VICTORY_SKIP_BINK=1 (pr34-alias-pin)
  • Scene / Area & Session Length: Mission-1 golden save (coastal world / balcony), 75s in-world after world entry (draws >= 500, 15 windows)

Measurements & Verification

  • Base FPS (without Frame Gen): median 11.2 fps (mean 9.86 fps, steady balcony 10.7–12.1 fps across final 10 windows) vs 8.9 fps baseline (+2.30 fps); rame-7758.png & rame-8814.png visually clean (luma=105.4, edge_energy=7.04,
    ear_black=0.0%, magenta=0.0%)
  • Frame-Gen FPS (if enabled): off
  • VRAM / RAM Usage: peak 5861 MB / min budget 6939 MB ( MB over budget; 5861 MB VRAM + 5434 MB shared in final copystat line), inal_waiting=1600 (vs 7121 baseline)
  • Crashes / DRED Resets: (crashes=0,
    o_host_texture_errors=0)
  • Automated Checks:
    • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy (sset policy: 294 files ok)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask (6 passed; 0 failed)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings (0 warnings)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features victory-gpu/diagnostics -- -D warnings (0 warnings)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1 (449 passed; 0 failed; 36 ignored, including dd_ref_alive_increments_live_and_refuses_zero)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --features diagnostics --lib an_alias_source_is_held_after_the_title_releases_it -- --test-threads=1 --nocapture (1 passed; 0 failed; 531 filtered out on RTX 4060 Ti)
    • cargo +1.98.1-x86_64-pc-windows-gnu build --release -p victory & --release --features diagnostics -p victory + objdump -p (0 non-system MinGW DLLs)
    • erify-world.ps1 (pr34-alias-pin, 75s): 11/11 verifier gates PASS
<!-- greyfinch-sync:Androtim/MiniVI:issue:5539158044 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/34). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-28T10:24:03Z. --- ## Summary Port rustno1-coder/VIctory-NVIDIA 74d6f24 (after xceless/victory-fork PR #1336 / 8fab6fb): - Add object::add_ref_alive (crates/victory-gpu/src/object.rs) to increment efs via etch_update only while > 0. - Add esource::Held + lias_with + esource::is_aliased (crates/victory-gpu/src/resource.rs) so lias_of() pins the aliased source resource while TARGETS_AT's lock is held and returns an RAII Held guard used by draw.rs::readable() and external.rs::prepare_input(). - Update lookup-only callers in esource::hosted() (3 sites), draw.rs, and exture/ahead.rs to call is_aliased() so they never take/drop references to another resource mid-work. - Added unit tests object::tests::add_ref_alive_increments_live_and_refuses_zero and esource::tests::an_alias_source_is_held_after_the_title_releases_it. ## Rig Specs Tested On - **CPU:** 13th Gen Intel(R) Core(TM) i7-13700F - **GPU & VRAM:** NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM) - **System RAM:** 32 GiB - **OS & GPU Driver:** Windows 11 Home (Build 26300) / Driver 32.0.16.2124 ## Run Settings & Profile - **Build & Commit SHA:** elease (and elease --features diagnostics) @ $sha - **Console Profile & Internal Resolution / Scale:** series-s (Quality scale .6666667, title output 960x540) - **Ray Tracing:** off - **Upscaling:** DLSS quality (Streamline 2.14.16) - **Frame Generation:** off - **Launcher Command / Preset & Extra VICTORY_* Overrides:** erify-world.ps1 play.rs SETTINGS preset + VICTORY_CARD_ACCOUNTING=1, VICTORY_D3D12_DRED=light, VICTORY_SKIP_BINK=1 (pr34-alias-pin) - **Scene / Area & Session Length:** Mission-1 golden save (coastal world / balcony), 75s in-world after world entry (draws >= 500, 15 windows) ## Measurements & Verification - **Base FPS (without Frame Gen):** median 11.2 fps (mean 9.86 fps, steady balcony 10.7–12.1 fps across final 10 windows) vs 8.9 fps baseline (+2.30 fps); rame-7758.png & rame-8814.png visually clean (luma=105.4, edge_energy=7.04, ear_black=0.0%, magenta=0.0%) - **Frame-Gen FPS (if enabled):** off - **VRAM / RAM Usage:** peak 5861 MB / min budget 6939 MB ( MB over budget; 5861 MB VRAM + 5434 MB shared in final copystat line), inal_waiting=1600 (vs 7121 baseline) - **Crashes / DRED Resets:** (crashes=0, o_host_texture_errors=0) - **Automated Checks:** - [x] cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy (sset policy: 294 files ok) - [x] cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask (6 passed; 0 failed) - [x] cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings (0 warnings) - [x] cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features victory-gpu/diagnostics -- -D warnings (0 warnings) - [x] cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1 (449 passed; 0 failed; 36 ignored, including dd_ref_alive_increments_live_and_refuses_zero) - [x] cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --features diagnostics --lib an_alias_source_is_held_after_the_title_releases_it -- --test-threads=1 --nocapture (1 passed; 0 failed; 531 filtered out on RTX 4060 Ti) - [x] cargo +1.98.1-x86_64-pc-windows-gnu build --release -p victory & --release --features diagnostics -p victory + objdump -p (0 non-system MinGW DLLs) - [x] erify-world.ps1 (pr34-alias-pin, 75s): **11/11 verifier gates PASS**
Androtim commented 2026-11-28 11:04:24 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-28T11:04:24Z.


Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Logic, concurrency invariants, and scoping look solid. This PR fixes a real use-after-free / stale-source race in crate::resource::alias_of by pinning the aliased source resource under the TARGETS_AT mutex before returning it.

Verified Details

  • crates/victory-gpu/src/object.rs:
    • add_ref_alive uses AtomicU32::fetch_update(Ordering::AcqRel, Ordering::Acquire, ...) to increment refs only while n > 0, pairing cleanly with release_boxed's AcqRel/Acquire decrement-to-zero path.
    • Unit test object::tests::add_ref_alive_increments_live_and_refuses_zero covers the zero/live/zero transitions cleanly.
  • crates/victory-gpu/src/resource.rs:
    • alias_with executes the callback while TARGETS_AT is still locked (before a concurrently dropping Resource can finish removing itself and freeing its Box<Resource>), so alias_of safely pins the source into an RAII Held(This) guard (or returns None if refs already hit 0).
    • Held::drop releases via crate::object::release_boxed::<Resource>(self.0).
    • Lookup-only callers in resource::hosted (3 sites), draw.rs (bake_sources path), and texture/ahead.rs (claim) are updated to is_aliased, avoiding unnecessary refcount churn or dropping another resource's last reference while holding locks like r.host.made.
    • Adds a host-backed test resource::tests::an_alias_source_is_held_after_the_title_releases_it (#[cfg(all(windows, feature = "diagnostics"))]).
  • crates/victory-gpu/src/draw.rs & crates/victory-gpu/src/external.rs:
    • readable and prepare_input keep the Held guard alive across crate::texture::alias(list, ..., source.get()).

Minor Non-Blocking Note

  • In object::add_ref_alive, n.saturating_add(1) would technically succeed at u32::MAX without increasing the count (checked_add(1) would refuse overflow), though u32::MAX concurrent references to a single D3D12 resource is unreachable in practice and matches add_ref's unchecked increment.

Next Step

CI is passing; since this touches D3D12 host resource lifecycle, alias-copy paths, and adds a D3D12-backed test (an_alias_source_is_held_after_the_title_releases_it), a local real-GPU test and smoke run is recommended before merging.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7238308904 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/34#issuecomment-7238308904). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-28T11:04:24Z. --- <!-- minivi-triage v1 head=d229732a39c60e879b4d3d5f0c6bdab681bc81f5 verdict=needs-gpu-test ci=passing at=2026-11-28T11:04:51Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic, concurrency invariants, and scoping look solid. This PR fixes a real use-after-free / stale-source race in `crate::resource::alias_of` by pinning the aliased source resource under the `TARGETS_AT` mutex before returning it. ### Verified Details - **`crates/victory-gpu/src/object.rs`**: - `add_ref_alive` uses `AtomicU32::fetch_update(Ordering::AcqRel, Ordering::Acquire, ...)` to increment `refs` only while `n > 0`, pairing cleanly with `release_boxed`'s `AcqRel`/`Acquire` decrement-to-zero path. - Unit test `object::tests::add_ref_alive_increments_live_and_refuses_zero` covers the zero/live/zero transitions cleanly. - **`crates/victory-gpu/src/resource.rs`**: - `alias_with` executes the callback while `TARGETS_AT` is still locked (before a concurrently dropping `Resource` can finish removing itself and freeing its `Box<Resource>`), so `alias_of` safely pins the source into an RAII `Held(This)` guard (or returns `None` if `refs` already hit 0). - `Held::drop` releases via `crate::object::release_boxed::<Resource>(self.0)`. - Lookup-only callers in `resource::hosted` (3 sites), `draw.rs` (`bake_sources` path), and `texture/ahead.rs` (`claim`) are updated to `is_aliased`, avoiding unnecessary refcount churn or dropping another resource's last reference while holding locks like `r.host.made`. - Adds a host-backed test `resource::tests::an_alias_source_is_held_after_the_title_releases_it` (`#[cfg(all(windows, feature = "diagnostics"))]`). - **`crates/victory-gpu/src/draw.rs` & `crates/victory-gpu/src/external.rs`**: - `readable` and `prepare_input` keep the `Held` guard alive across `crate::texture::alias(list, ..., source.get())`. ### Minor Non-Blocking Note - In `object::add_ref_alive`, `n.saturating_add(1)` would technically succeed at `u32::MAX` without increasing the count (`checked_add(1)` would refuse overflow), though `u32::MAX` concurrent references to a single D3D12 resource is unreachable in practice and matches `add_ref`'s unchecked increment. ### Next Step CI is passing; since this touches D3D12 host resource lifecycle, alias-copy paths, and adds a D3D12-backed test (`an_alias_source_is_held_after_the_title_releases_it`), a local real-GPU test and smoke run is recommended before merging. --- _Generated with Antigravity CLI (`agy`)._
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!34
No description provided.