GPU: pin the texture a placed view aliases while the copy uses it #1336
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!1336
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1336"
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?
@CwWwWwW on GitHub · 2026-11-26 16:14 UTC · original
CwWwWwW:fix/alias-source-held→main· +63 −5 · 2 files · 1 commits · merged 2026-11-26 18:05 UTCProblem
crate::resource::alias_of(called from the draw's placed-view preparation) takesTARGETS_AT's lock, looks up the title target texture that lies in the placed view's memory, validates it, and returns the bare pointer. The lock is dropped on return; the caller then passes the pointer totexture::alias, which dereferences it -host_resource(source)locks the resource'shost.made, then the host copy is used in copies and barriers.The only thing that made the lookup safe is
Resource::dropremoving theTARGETS_ATentry under the same lock before freeing. Once the lock is released that protection is gone: a title that releases the target texture between the lookup and the copy (recording threads release textures once their last use is recorded; the same texture can be recreated at the same address) makes the copy read a freedBox<Resource>- heap use-after-free, or a silent copy from the next texture allocated there.The fork already has the exact idiom for title-object pointers crossing a thread:
resource::holdreturns aHeldguard that pins the object withobject::add_ref_aliveand releases it on drop.alias_ofwas the one lookup that returned a naked pointer.Change
alias_ofnow returnsOption<Held>: underTARGETS_AT's lock, after the same checks, it pins the found texture withcrate::object::add_ref_aliveand returns the existingHeldguard. If the texture's last reference is already being released, it returnsNone(safe: the draw falls back to the title-memory upload, which is what the alias copy replaces).Heldgainsget() -> This.draw.rsholds the guard acrosstexture::alias(list, placed, source.get()); it drops right after the copy is recorded.alias_after_title_upload_copies_the_gpu_atlastest uses the held API.Tests
an_alias_source_is_held_after_the_title_releases_it: releases the title's reference to the alias source, then checks the source is still in the texture table andhost_resourcestill returns its copy; dropping the held handle frees it. Without the pin the source is freed by the release, so the following copy would read freed memory.cargo test -p victory-gpu --lib --locked: 217 passed, 0 failed, 6 ignored (default build; the new test is diagnostics-gated like the existing alias test).VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics resource:: -- --test-threads=1: 11 passed, 0 failed (the alias tests run on the WARP device).cargo clippy -p victory-gpu --all-targets --locked -- -D warningsand--all-features: clean.Notes
(CI note: the
checkjob on main is currently red on the asset-policy violation; #1322 fixes that, after which this can be rebased.)