fix(gpu): pin the texture a placed view aliases while the copy uses it
alias_of returned the bare pointer of the aliased texture after TARGETS_AT's lock was gone, and texture::alias then used it; the title can drop its last reference in between (use-after-free, or a copy from the next texture at the same address). alias_of now takes a reference under the lock (object::add_ref_alive) and returns a Held guard that the two copying callers (draw.rs readable, external.rs prepare_input) keep until the alias copy is recorded; a texture already being released is not returned. This tree has three lookup-only callers (draw.rs bake sources, texture/ahead.rs, resource.rs host-copy levels). They now call is_aliased, the same lookup without a pin, so none of them takes and drops a reference (and so none can end up freeing the texture inside its own work). No switch: a lifetime fix with no other behaviour change. The original test comes along (diagnostics builds with a host GPU only). Original author: CwWwWwW (fxceless/victory-fork pull request #1336, f8fab6fb). Ported by hand from CuteBooty/victory-8gb; Held and add_ref_alive follow fxceless/victory-fork d4a528ba, which this tree does not have. Co-Authored-By: Claude Fable 5.2 <[email protected]> (cherry picked from commit 6665ad8bd2147e58aed9362e41718aa385643102)
This commit is contained in:
1 parent
8e9f11d618
commit
74d6f2408b
5 files changed
+100
-7
No files matched your search
@@ -2736,7 +2736,7 @@ impl State {
|
||||
// copies that texture's texels into it on the host, no upload.
|
||||
// (Lighting tables read as R9G9B9E5: 6 to 13 sources a run were
|
||||
// counted as failed for want of an upload.)
|
||||
if crate::resource::alias_of(resource).is_some() {
|
||||
if crate::resource::is_aliased(resource) {
|
||||
readable(list, ResourceType::Srv, &view);
|
||||
n[if shown { 2 } else { 5 }] += 1;
|
||||
if !shown {
|
||||
@@ -5671,7 +5671,7 @@ fn readable(list: &HostList, kind: ResourceType, view: &View) {
|
||||
// a texture the host writes: that texture's texels, copied on
|
||||
// the host (title memory does not have them).
|
||||
let aliased = crate::resource::alias_of(*resource as This)
|
||||
.is_some_and(|source| crate::texture::alias(list, *resource as This, source));
|
||||
.is_some_and(|source| crate::texture::alias(list, *resource as This, source.get()));
|
||||
if !aliased
|
||||
&& let Some(t) = crate::resource::host_copy(*resource as This)
|
||||
&& t.flags() & 0x7 == 0
|
||||
|
||||
Reference in new issue
Block a user