don't clone resources for ResourceMetadataProvider::Direct

This commit is contained in:
teoxoy 2024-07-02 15:06:34 +02:00 committed by Teodor Tanasoaia
parent 69b44c6a32
commit b8c5b2275e
5 changed files with 18 additions and 32 deletions

View File

@ -280,7 +280,7 @@ impl Global {
.trackers
.lock()
.buffers
.insert_single(resource, buffer_use);
.insert_single(&resource, buffer_use);
return (id, None);
};
@ -593,7 +593,7 @@ impl Global {
.trackers
.lock()
.textures
.insert_single(resource, hal::TextureUses::UNINITIALIZED);
.insert_single(&resource, hal::TextureUses::UNINITIALIZED);
return (id, None);
};
@ -666,7 +666,7 @@ impl Global {
.trackers
.lock()
.textures
.insert_single(resource, hal::TextureUses::UNINITIALIZED);
.insert_single(&resource, hal::TextureUses::UNINITIALIZED);
return (id, None);
};
@ -716,7 +716,7 @@ impl Global {
.trackers
.lock()
.buffers
.insert_single(buffer, hal::BufferUses::empty());
.insert_single(&buffer, hal::BufferUses::empty());
return (id, None);
};

View File

@ -244,7 +244,7 @@ impl Global {
let mut trackers = device.trackers.lock();
trackers
.textures
.insert_single(resource, hal::TextureUses::UNINITIALIZED);
.insert_single(&resource, hal::TextureUses::UNINITIALIZED);
}
if present.acquired_texture.is_some() {

View File

@ -5,7 +5,7 @@
* one subresource, they have no selector.
!*/
use std::{borrow::Cow, marker::PhantomData, sync::Arc};
use std::{marker::PhantomData, sync::Arc};
use super::{PendingTransition, ResourceTracker, TrackerIndex};
use crate::{
@ -171,9 +171,7 @@ impl<A: HalApi> BufferUsageScope<A> {
index as _,
index,
BufferStateProvider::Direct { state },
ResourceMetadataProvider::Direct {
resource: Cow::Borrowed(resource),
},
ResourceMetadataProvider::Direct { resource },
)?
};
}
@ -247,9 +245,7 @@ impl<A: HalApi> BufferUsageScope<A> {
index as _,
index,
BufferStateProvider::Direct { state: new_state },
ResourceMetadataProvider::Direct {
resource: Cow::Owned(buffer.clone()),
},
ResourceMetadataProvider::Direct { resource: buffer },
)?;
}
@ -387,7 +383,7 @@ impl<A: HalApi> BufferTracker<A> {
///
/// If the ID is higher than the length of internal vectors,
/// the vectors will be extended. A call to set_size is not needed.
pub fn insert_single(&mut self, resource: Arc<Buffer<A>>, state: BufferUses) {
pub fn insert_single(&mut self, resource: &Arc<Buffer<A>>, state: BufferUses) {
let index = resource.tracker_index().as_usize();
self.allow_index(index);
@ -408,9 +404,7 @@ impl<A: HalApi> BufferTracker<A> {
index,
BufferStateProvider::Direct { state },
None,
ResourceMetadataProvider::Direct {
resource: Cow::Owned(resource),
},
ResourceMetadataProvider::Direct { resource },
)
}
}
@ -441,9 +435,7 @@ impl<A: HalApi> BufferTracker<A> {
index,
BufferStateProvider::Direct { state },
None,
ResourceMetadataProvider::Direct {
resource: Cow::Owned(buffer.clone()),
},
ResourceMetadataProvider::Direct { resource: buffer },
&mut self.temp,
)
};

View File

@ -1,7 +1,7 @@
//! The `ResourceMetadata` type.
use bit_vec::BitVec;
use std::{borrow::Cow, mem, sync::Arc};
use std::{mem, sync::Arc};
use wgt::strict_assert;
/// A set of resources, holding a `Arc<T>` and epoch for each member.
@ -176,7 +176,7 @@ impl<T> ResourceMetadata<T> {
/// trackers can get new resource metadata from.
pub(super) enum ResourceMetadataProvider<'a, T> {
/// Comes directly from explicit values.
Direct { resource: Cow<'a, Arc<T>> },
Direct { resource: &'a Arc<T> },
/// Comes from another metadata tracker.
Indirect { metadata: &'a ResourceMetadata<T> },
}

View File

@ -40,7 +40,7 @@ use naga::FastHashMap;
use wgt::{strict_assert, strict_assert_eq};
use std::{borrow::Cow, iter, marker::PhantomData, ops::Range, sync::Arc, vec::Drain};
use std::{iter, marker::PhantomData, ops::Range, sync::Arc, vec::Drain};
/// Specifies a particular set of subresources in a texture.
#[derive(Clone, Debug, PartialEq, Eq)]
@ -382,9 +382,7 @@ impl<A: HalApi> TextureUsageScope<A> {
&mut self.metadata,
index,
TextureStateProvider::from_option(selector, new_state),
ResourceMetadataProvider::Direct {
resource: Cow::Borrowed(texture),
},
ResourceMetadataProvider::Direct { resource: texture },
)?
};
@ -537,7 +535,7 @@ impl<A: HalApi> TextureTracker<A> {
///
/// If the ID is higher than the length of internal vectors,
/// the vectors will be extended. A call to set_size is not needed.
pub fn insert_single(&mut self, resource: Arc<Texture<A>>, usage: TextureUses) {
pub fn insert_single(&mut self, resource: &Arc<Texture<A>>, usage: TextureUses) {
let index = resource.tracker_index().as_usize();
self.allow_index(index);
@ -559,9 +557,7 @@ impl<A: HalApi> TextureTracker<A> {
index,
TextureStateProvider::KnownSingle { state: usage },
None,
ResourceMetadataProvider::Direct {
resource: Cow::Owned(resource),
},
ResourceMetadataProvider::Direct { resource },
)
};
}
@ -597,9 +593,7 @@ impl<A: HalApi> TextureTracker<A> {
state: new_state,
},
None,
ResourceMetadataProvider::Direct {
resource: Cow::Owned(texture.clone()),
},
ResourceMetadataProvider::Direct { resource: texture },
&mut self.temp,
)
}