use buffer::BufferAccess;
use format::ClearValue;
use format::Format;
use format::PossibleDepthFormatDesc;
use format::PossibleDepthStencilFormatDesc;
use format::PossibleFloatFormatDesc;
use format::PossibleSintFormatDesc;
use format::PossibleStencilFormatDesc;
use format::PossibleUintFormatDesc;
use format::PossibleCompressedFormatDesc;
use image::Dimensions;
use image::ImageDimensions;
use image::ImageLayout;
use image::sys::UnsafeImage;
use image::sys::UnsafeImageView;
use sampler::Sampler;
use sync::AccessError;
use SafeDeref;
pub unsafe trait ImageAccess {
fn inner(&self) -> ImageInner;
#[inline]
fn format(&self) -> Format {
self.inner().image.format()
}
#[inline]
fn has_color(&self) -> bool {
let format = self.format();
format.is_float() || format.is_uint() || format.is_sint() || format.is_compressed()
}
#[inline]
fn has_depth(&self) -> bool {
let format = self.format();
format.is_depth() || format.is_depth_stencil()
}
#[inline]
fn has_stencil(&self) -> bool {
let format = self.format();
format.is_stencil() || format.is_depth_stencil()
}
#[inline]
fn mipmap_levels(&self) -> u32 {
self.inner().image.mipmap_levels()
}
#[inline]
fn samples(&self) -> u32 {
self.inner().image.samples()
}
#[inline]
fn dimensions(&self) -> ImageDimensions {
self.inner().image.dimensions()
}
#[inline]
fn supports_blit_source(&self) -> bool {
self.inner().image.supports_blit_source()
}
#[inline]
fn supports_blit_destination(&self) -> bool {
self.inner().image.supports_blit_destination()
}
unsafe fn layout_initialized(&self) {}
fn is_layout_initialized(&self) -> bool {false}
unsafe fn preinitialized_layout(&self) -> bool {
self.inner().image.preinitialized_layout()
}
fn initial_layout_requirement(&self) -> ImageLayout;
fn final_layout_requirement(&self) -> ImageLayout;
#[inline]
unsafe fn forced_undefined_initial_layout(self, preinitialized: bool)
-> ImageAccessFromUndefinedLayout<Self>
where Self: Sized
{
ImageAccessFromUndefinedLayout {
image: self,
preinitialized: preinitialized,
}
}
fn conflicts_buffer(&self, other: &dyn BufferAccess) -> bool;
fn conflicts_image(&self, other: &dyn ImageAccess) -> bool;
fn conflict_key(&self) -> u64;
fn try_gpu_lock(&self, exclusive_access: bool, expected_layout: ImageLayout)
-> Result<(), AccessError>;
unsafe fn increase_gpu_lock(&self);
unsafe fn unlock(&self, transitioned_layout: Option<ImageLayout>);
}
#[derive(Copy, Clone, Debug)]
pub struct ImageInner<'a> {
pub image: &'a UnsafeImage,
pub first_layer: usize,
pub num_layers: usize,
pub first_mipmap_level: usize,
pub num_mipmap_levels: usize,
}
unsafe impl<T> ImageAccess for T
where T: SafeDeref,
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 conflicts_buffer(&self, other: &dyn BufferAccess) -> bool {
(**self).conflicts_buffer(other)
}
#[inline]
fn conflicts_image(&self, other: &dyn ImageAccess) -> bool {
(**self).conflicts_image(other)
}
#[inline]
fn conflict_key(&self) -> u64 {
(**self).conflict_key()
}
#[inline]
fn try_gpu_lock(&self, exclusive_access: bool, expected_layout: ImageLayout)
-> Result<(), AccessError> {
(**self).try_gpu_lock(exclusive_access, 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()
}
}
#[derive(Debug, Copy, Clone)]
pub struct ImageAccessFromUndefinedLayout<I> {
image: I,
preinitialized: bool,
}
unsafe impl<I> ImageAccess for ImageAccessFromUndefinedLayout<I>
where I: ImageAccess
{
#[inline]
fn inner(&self) -> ImageInner {
self.image.inner()
}
#[inline]
fn initial_layout_requirement(&self) -> ImageLayout {
if self.preinitialized {
ImageLayout::Preinitialized
} else {
ImageLayout::Undefined
}
}
#[inline]
fn final_layout_requirement(&self) -> ImageLayout {
self.image.final_layout_requirement()
}
#[inline]
fn conflicts_buffer(&self, other: &dyn BufferAccess) -> bool {
self.image.conflicts_buffer(other)
}
#[inline]
fn conflicts_image(&self, other: &dyn ImageAccess) -> bool {
self.image.conflicts_image(other)
}
#[inline]
fn conflict_key(&self) -> u64 {
self.image.conflict_key()
}
#[inline]
fn try_gpu_lock(&self, exclusive_access: bool, expected_layout: ImageLayout)
-> Result<(), AccessError> {
self.image.try_gpu_lock(exclusive_access, expected_layout)
}
#[inline]
unsafe fn increase_gpu_lock(&self) {
self.image.increase_gpu_lock()
}
#[inline]
unsafe fn unlock(&self, new_layout: Option<ImageLayout>) {
self.image.unlock(new_layout)
}
}
pub unsafe trait ImageClearValue<T>: ImageAccess {
fn decode(&self, T) -> Option<ClearValue>;
}
pub unsafe trait ImageContent<P>: ImageAccess {
fn matches_format(&self) -> bool;
}
pub unsafe trait ImageViewAccess {
fn parent(&self) -> &dyn ImageAccess;
fn dimensions(&self) -> Dimensions;
fn inner(&self) -> &UnsafeImageView;
#[inline]
fn format(&self) -> Format {
self.inner().format()
}
#[inline]
fn samples(&self) -> u32 {
self.parent().samples()
}
fn descriptor_set_storage_image_layout(&self) -> ImageLayout;
fn descriptor_set_combined_image_sampler_layout(&self) -> ImageLayout;
fn descriptor_set_sampled_image_layout(&self) -> ImageLayout;
fn descriptor_set_input_attachment_layout(&self) -> ImageLayout;
fn identity_swizzle(&self) -> bool;
fn can_be_sampled(&self, _sampler: &Sampler) -> bool {
true
}
}
unsafe impl<T> ImageViewAccess for T
where T: SafeDeref,
T::Target: ImageViewAccess
{
#[inline]
fn parent(&self) -> &dyn ImageAccess {
(**self).parent()
}
#[inline]
fn inner(&self) -> &UnsafeImageView {
(**self).inner()
}
#[inline]
fn dimensions(&self) -> Dimensions {
(**self).dimensions()
}
#[inline]
fn descriptor_set_storage_image_layout(&self) -> ImageLayout {
(**self).descriptor_set_storage_image_layout()
}
#[inline]
fn descriptor_set_combined_image_sampler_layout(&self) -> ImageLayout {
(**self).descriptor_set_combined_image_sampler_layout()
}
#[inline]
fn descriptor_set_sampled_image_layout(&self) -> ImageLayout {
(**self).descriptor_set_sampled_image_layout()
}
#[inline]
fn descriptor_set_input_attachment_layout(&self) -> ImageLayout {
(**self).descriptor_set_input_attachment_layout()
}
#[inline]
fn identity_swizzle(&self) -> bool {
(**self).identity_swizzle()
}
#[inline]
fn can_be_sampled(&self, sampler: &Sampler) -> bool {
(**self).can_be_sampled(sampler)
}
}
pub unsafe trait AttachmentImageView: ImageViewAccess {
fn accept(&self, initial_layout: ImageLayout, final_layout: ImageLayout) -> bool;
}