use buffer::BufferAccess;
use device::Queue;
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 image::Dimensions;
use image::ImageDimensions;
use image::ImageLayout;
use image::sys::UnsafeImage;
use image::sys::UnsafeImageView;
use sampler::Sampler;
use sync::AccessError;
use SafeDeref;
use VulkanObject;
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()
}
#[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()
}
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, self_first_layer: u32, self_num_layers: u32,
self_first_mipmap: u32, self_num_mipmaps: u32, other: &BufferAccess,
other_offset: usize, other_size: usize)
-> bool {
false
}
fn conflicts_image(&self, self_first_layer: u32, self_num_layers: u32,
self_first_mipmap: u32, self_num_mipmaps: u32, other: &ImageAccess,
other_first_layer: u32, other_num_layers: u32, other_first_mipmap: u32,
other_num_mipmaps: u32)
-> bool {
if self.inner().image.internal_object() != other.inner().image.internal_object() {
return false;
}
true
}
fn conflict_key(&self, first_layer: u32, num_layers: u32, first_mipmap: u32, num_mipmaps: u32)
-> u64;
#[inline]
fn conflicts_buffer_all(&self, other: &BufferAccess) -> bool {
self.conflicts_buffer(0,
self.dimensions().array_layers(),
0,
self.mipmap_levels(),
other,
0,
other.size())
}
#[inline]
fn conflicts_image_all(&self, other: &ImageAccess) -> bool {
self.conflicts_image(0,
self.dimensions().array_layers(),
0,
self.mipmap_levels(),
other,
0,
other.dimensions().array_layers(),
0,
other.mipmap_levels())
}
#[inline]
fn conflict_key_all(&self) -> u64 {
self.conflict_key(0, self.dimensions().array_layers(), 0, self.mipmap_levels())
}
fn try_gpu_lock(&self, exclusive_access: bool, queue: &Queue) -> Result<(), AccessError>;
unsafe fn increase_gpu_lock(&self);
unsafe fn unlock(&self);
}
#[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 conflict_key(&self, first_layer: u32, num_layers: u32, first_mipmap: u32, num_mipmaps: u32)
-> u64 {
(**self).conflict_key(first_layer, num_layers, first_mipmap, num_mipmaps)
}
#[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()
}
}
#[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 conflict_key(&self, first_layer: u32, num_layers: u32, first_mipmap: u32, num_mipmaps: u32)
-> u64 {
self.image
.conflict_key(first_layer, num_layers, first_mipmap, num_mipmaps)
}
#[inline]
fn try_gpu_lock(&self, exclusive_access: bool, queue: &Queue) -> Result<(), AccessError> {
self.image.try_gpu_lock(exclusive_access, queue)
}
#[inline]
unsafe fn increase_gpu_lock(&self) {
self.image.increase_gpu_lock()
}
#[inline]
unsafe fn unlock(&self) {
self.image.unlock()
}
}
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) -> &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) -> &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;
}