From 26ebc529456546b657064a646da59341a3f2ae7b Mon Sep 17 00:00:00 2001 From: Austin Johnson Date: Mon, 6 Dec 2021 13:59:58 -0600 Subject: [PATCH] reimplement generic implementations for BufferAccess, TypedBufferAccess, & ImageAccess (#1776) --- vulkano/src/buffer/traits.rs | 45 +++++++++++++++++++++++ vulkano/src/image/traits.rs | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/vulkano/src/buffer/traits.rs b/vulkano/src/buffer/traits.rs index e8fae8fd..1f92713b 100644 --- a/vulkano/src/buffer/traits.rs +++ b/vulkano/src/buffer/traits.rs @@ -14,6 +14,7 @@ use crate::device::Queue; use crate::memory::Content; use crate::sync::AccessError; use crate::DeviceSize; +use crate::SafeDeref; use crate::VulkanObject; use std::hash::Hash; use std::hash::Hasher; @@ -149,6 +150,42 @@ pub struct BufferInner<'a> { pub offset: DeviceSize, } +unsafe impl BufferAccess for T +where + T: SafeDeref + Send + Sync, + T::Target: BufferAccess, +{ + #[inline] + fn inner(&self) -> BufferInner { + (**self).inner() + } + + #[inline] + fn size(&self) -> DeviceSize { + (**self).size() + } + + #[inline] + fn conflict_key(&self) -> (u64, u64) { + (**self).conflict_key() + } + + #[inline] + fn try_gpu_lock(&self, exclusive_access: bool, queue: &Queue) -> Result<(), AccessError> { + (**self).try_gpu_lock(exclusive_access, queue) + } + + #[inline] + unsafe fn increase_gpu_lock(&self) { + (**self).increase_gpu_lock() + } + + #[inline] + unsafe fn unlock(&self) { + (**self).unlock() + } +} + /// Extension trait for `BufferAccess`. Indicates the type of the content of the buffer. pub unsafe trait TypedBufferAccess: BufferAccess { /// The type of the content. @@ -166,6 +203,14 @@ pub unsafe trait TypedBufferAccess: BufferAccess { } } +unsafe impl TypedBufferAccess for T +where + T: SafeDeref + Send + Sync, + T::Target: TypedBufferAccess, +{ + type Content = ::Content; +} + impl PartialEq for dyn BufferAccess { #[inline] fn eq(&self, other: &Self) -> bool { diff --git a/vulkano/src/image/traits.rs b/vulkano/src/image/traits.rs index 7f51ca5a..e467d29a 100644 --- a/vulkano/src/image/traits.rs +++ b/vulkano/src/image/traits.rs @@ -15,6 +15,7 @@ use crate::image::ImageDimensions; use crate::image::ImageLayout; use crate::image::SampleCount; use crate::sync::AccessError; +use crate::SafeDeref; use std::hash::Hash; use std::hash::Hasher; use std::sync::Arc; @@ -340,3 +341,72 @@ pub unsafe trait ImageContent

: ImageAccess { /// Checks whether pixels of type `P` match the format of the image. fn matches_format(&self) -> bool; } + +unsafe impl ImageAccess for T +where + T: SafeDeref + Send + Sync, + T::Target: ImageAccess, +{ + #[inline] + fn inner(&self) -> ImageInner { + (**self).inner() + } + + #[inline] + fn initial_layout_requirement(&self) -> ImageLayout { + (**self).initial_layout_requirement() + } + + #[inline] + fn final_layout_requirement(&self) -> ImageLayout { + (**self).final_layout_requirement() + } + + #[inline] + fn descriptor_layouts(&self) -> Option { + (**self).descriptor_layouts() + } + + #[inline] + fn conflict_key(&self) -> u64 { + (**self).conflict_key() + } + + #[inline] + fn try_gpu_lock( + &self, + exclusive_access: bool, + uninitialized_safe: bool, + expected_layout: ImageLayout, + ) -> Result<(), AccessError> { + (**self).try_gpu_lock(exclusive_access, uninitialized_safe, expected_layout) + } + + #[inline] + unsafe fn increase_gpu_lock(&self) { + (**self).increase_gpu_lock() + } + + #[inline] + unsafe fn unlock(&self, transitioned_layout: Option) { + (**self).unlock(transitioned_layout) + } + + #[inline] + unsafe fn layout_initialized(&self) { + (**self).layout_initialized(); + } + + #[inline] + fn is_layout_initialized(&self) -> bool { + (**self).is_layout_initialized() + } + + fn current_miplevels_access(&self) -> std::ops::Range { + (**self).current_miplevels_access() + } + + fn current_layer_levels_access(&self) -> std::ops::Range { + (**self).current_layer_levels_access() + } +} \ No newline at end of file