gpu/resource: pin aliased texture source while alias copy uses it #34
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/34"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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):
efs via etch_update only while
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().
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.
esource::tests::an_alias_source_is_held_after_the_title_releases_it.
Rig Specs Tested On
Run Settings & Profile
elease (and
elease --features diagnostics) @ $sha
Measurements & Verification
ear_black=0.0%, magenta=0.0%)
o_host_texture_errors=0)
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):passingReview Summary
Logic, concurrency invariants, and scoping look solid. This PR fixes a real use-after-free / stale-source race in
crate::resource::alias_ofby pinning the aliased source resource under theTARGETS_ATmutex before returning it.Verified Details
crates/victory-gpu/src/object.rs:add_ref_aliveusesAtomicU32::fetch_update(Ordering::AcqRel, Ordering::Acquire, ...)to incrementrefsonly whilen > 0, pairing cleanly withrelease_boxed'sAcqRel/Acquiredecrement-to-zero path.object::tests::add_ref_alive_increments_live_and_refuses_zerocovers the zero/live/zero transitions cleanly.crates/victory-gpu/src/resource.rs:alias_withexecutes the callback whileTARGETS_ATis still locked (before a concurrently droppingResourcecan finish removing itself and freeing itsBox<Resource>), soalias_ofsafely pins the source into an RAIIHeld(This)guard (or returnsNoneifrefsalready hit 0).Held::dropreleases viacrate::object::release_boxed::<Resource>(self.0).resource::hosted(3 sites),draw.rs(bake_sourcespath), andtexture/ahead.rs(claim) are updated tois_aliased, avoiding unnecessary refcount churn or dropping another resource's last reference while holding locks liker.host.made.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:readableandprepare_inputkeep theHeldguard alive acrosscrate::texture::alias(list, ..., source.get()).Minor Non-Blocking Note
object::add_ref_alive,n.saturating_add(1)would technically succeed atu32::MAXwithout increasing the count (checked_add(1)would refuse overflow), thoughu32::MAXconcurrent references to a single D3D12 resource is unreachable in practice and matchesadd_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).