reimplement generic implementations for BufferAccess, TypedBufferAccess, & ImageAccess (#1776)

This commit is contained in:
Austin Johnson 2021-12-06 13:59:58 -06:00 committed by GitHub
parent b5034907fa
commit 26ebc52945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 115 additions and 0 deletions

View File

@ -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<T> 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<T> TypedBufferAccess for T
where
T: SafeDeref + Send + Sync,
T::Target: TypedBufferAccess,
{
type Content = <T::Target as TypedBufferAccess>::Content;
}
impl PartialEq for dyn BufferAccess {
#[inline]
fn eq(&self, other: &Self) -> bool {

View File

@ -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<P>: ImageAccess {
/// Checks whether pixels of type `P` match the format of the image.
fn matches_format(&self) -> bool;
}
unsafe impl<T> 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<ImageDescriptorLayouts> {
(**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<ImageLayout>) {
(**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<u32> {
(**self).current_miplevels_access()
}
fn current_layer_levels_access(&self) -> std::ops::Range<u32> {
(**self).current_layer_levels_access()
}
}