change return type of ResourceMetadataProvider.get to &Arc<T>

This commit is contained in:
teoxoy 2024-06-20 13:39:13 +02:00 committed by Teodor Tanasoaia
parent 26eceabe86
commit 123a59ae7b
3 changed files with 14 additions and 15 deletions

View File

@ -748,8 +748,8 @@ unsafe fn insert<A: HalApi>(
} }
*current_states.get_unchecked_mut(index) = new_end_state; *current_states.get_unchecked_mut(index) = new_end_state;
let resource = metadata_provider.get_own(index); let resource = metadata_provider.get(index);
resource_metadata.insert(index, resource); resource_metadata.insert(index, resource.clone());
} }
} }
@ -768,7 +768,7 @@ unsafe fn merge<A: HalApi>(
if invalid_resource_state(merged_state) { if invalid_resource_state(merged_state) {
return Err(UsageConflict::from_buffer( return Err(UsageConflict::from_buffer(
unsafe { metadata_provider.get_own(index).info.id() }, unsafe { metadata_provider.get(index).info.id() },
*current_state, *current_state,
new_state, new_state,
)); ));

View File

@ -182,21 +182,20 @@ pub(super) enum ResourceMetadataProvider<'a, T: Resource> {
Indirect { metadata: &'a ResourceMetadata<T> }, Indirect { metadata: &'a ResourceMetadata<T> },
} }
impl<T: Resource> ResourceMetadataProvider<'_, T> { impl<T: Resource> ResourceMetadataProvider<'_, T> {
/// Get the epoch and an owned refcount from this. /// Get a reference to the resource from this.
/// ///
/// # Safety /// # Safety
/// ///
/// - The index must be in bounds of the metadata tracker if this uses an indirect source. /// - The index must be in bounds of the metadata tracker if this uses an indirect source.
/// - info must be Some if this uses a Resource source.
#[inline(always)] #[inline(always)]
pub(super) unsafe fn get_own(self, index: usize) -> Arc<T> { pub(super) unsafe fn get(&self, index: usize) -> &Arc<T> {
match self { match self {
ResourceMetadataProvider::Direct { resource } => resource.into_owned(), ResourceMetadataProvider::Direct { resource } => resource,
ResourceMetadataProvider::Indirect { metadata } => { ResourceMetadataProvider::Indirect { metadata } => {
metadata.tracker_assert_in_bounds(index); metadata.tracker_assert_in_bounds(index);
{ {
let resource = unsafe { metadata.resources.get_unchecked(index) }; let resource = unsafe { metadata.resources.get_unchecked(index) }.as_ref();
unsafe { resource.clone().unwrap_unchecked() } unsafe { resource.unwrap_unchecked() }
} }
} }
} }

View File

@ -1064,8 +1064,8 @@ unsafe fn insert<A: HalApi>(
} }
unsafe { unsafe {
let resource = metadata_provider.get_own(index); let resource = metadata_provider.get(index);
resource_metadata.insert(index, resource); resource_metadata.insert(index, resource.clone());
} }
} }
@ -1096,7 +1096,7 @@ unsafe fn merge<A: HalApi>(
if invalid_resource_state(merged_state) { if invalid_resource_state(merged_state) {
return Err(UsageConflict::from_texture( return Err(UsageConflict::from_texture(
unsafe { metadata_provider.get_own(index).info.id() }, unsafe { metadata_provider.get(index).info.id() },
texture_selector.clone(), texture_selector.clone(),
*current_simple, *current_simple,
new_simple, new_simple,
@ -1123,7 +1123,7 @@ unsafe fn merge<A: HalApi>(
if invalid_resource_state(merged_state) { if invalid_resource_state(merged_state) {
return Err(UsageConflict::from_texture( return Err(UsageConflict::from_texture(
unsafe { metadata_provider.get_own(index).info.id() }, unsafe { metadata_provider.get(index).info.id() },
selector, selector,
*current_simple, *current_simple,
new_state, new_state,
@ -1164,7 +1164,7 @@ unsafe fn merge<A: HalApi>(
if invalid_resource_state(merged_state) { if invalid_resource_state(merged_state) {
return Err(UsageConflict::from_texture( return Err(UsageConflict::from_texture(
unsafe { metadata_provider.get_own(index).info.id() }, unsafe { metadata_provider.get(index).info.id() },
TextureSelector { TextureSelector {
mips: mip_id..mip_id + 1, mips: mip_id..mip_id + 1,
layers: layers.clone(), layers: layers.clone(),
@ -1205,7 +1205,7 @@ unsafe fn merge<A: HalApi>(
if invalid_resource_state(merged_state) { if invalid_resource_state(merged_state) {
return Err(UsageConflict::from_texture( return Err(UsageConflict::from_texture(
unsafe { metadata_provider.get_own(index).info.id() }, unsafe { metadata_provider.get(index).info.id() },
TextureSelector { TextureSelector {
mips: mip_id..mip_id + 1, mips: mip_id..mip_id + 1,
layers: layers.clone(), layers: layers.clone(),