use std::error;
use std::fmt;
use std::sync::Arc;
use OomError;
use VulkanObject;
use buffer::BufferAccess;
use buffer::BufferViewRef;
use descriptor::descriptor::DescriptorDesc;
use descriptor::descriptor::DescriptorDescTy;
use descriptor::descriptor::DescriptorImageDesc;
use descriptor::descriptor::DescriptorImageDescArray;
use descriptor::descriptor::DescriptorImageDescDimensions;
use descriptor::descriptor::DescriptorType;
use descriptor::descriptor_set::DescriptorPool;
use descriptor::descriptor_set::DescriptorPoolAlloc;
use descriptor::descriptor_set::DescriptorSet;
use descriptor::descriptor_set::DescriptorSetDesc;
use descriptor::descriptor_set::DescriptorWrite;
use descriptor::descriptor_set::StdDescriptorPoolAlloc;
use descriptor::descriptor_set::UnsafeDescriptorSet;
use descriptor::descriptor_set::UnsafeDescriptorSetLayout;
use descriptor::pipeline_layout::PipelineLayoutAbstract;
use device::Device;
use device::DeviceOwned;
use format::Format;
use image::ImageViewAccess;
use sampler::Sampler;
pub struct PersistentDescriptorSet<L, R, P = StdDescriptorPoolAlloc> {
inner: P,
resources: R,
pipeline_layout: L,
set_id: usize,
layout: Arc<UnsafeDescriptorSetLayout>,
}
impl<L> PersistentDescriptorSet<L, ()> {
pub fn start(layout: L, set_id: usize) -> PersistentDescriptorSetBuilder<L, ()>
where L: PipelineLayoutAbstract
{
assert!(layout.num_sets() > set_id);
let cap = layout.num_bindings_in_set(set_id).unwrap_or(0);
PersistentDescriptorSetBuilder {
layout: layout,
set_id: set_id,
binding_id: 0,
writes: Vec::with_capacity(cap),
resources: (),
}
}
}
unsafe impl<L, R, P> DescriptorSet for PersistentDescriptorSet<L, R, P>
where L: PipelineLayoutAbstract,
P: DescriptorPoolAlloc,
R: PersistentDescriptorSetResources
{
#[inline]
fn inner(&self) -> &UnsafeDescriptorSet {
self.inner.inner()
}
#[inline]
fn num_buffers(&self) -> usize {
self.resources.num_buffers()
}
#[inline]
fn buffer(&self, index: usize) -> Option<(&dyn BufferAccess, u32)> {
self.resources.buffer(index)
}
#[inline]
fn num_images(&self) -> usize {
self.resources.num_images()
}
#[inline]
fn image(&self, index: usize) -> Option<(&dyn ImageViewAccess, u32)> {
self.resources.image(index)
}
}
unsafe impl<L, R, P> DescriptorSetDesc for PersistentDescriptorSet<L, R, P>
where L: PipelineLayoutAbstract
{
#[inline]
fn num_bindings(&self) -> usize {
self.pipeline_layout
.num_bindings_in_set(self.set_id)
.unwrap()
}
#[inline]
fn descriptor(&self, binding: usize) -> Option<DescriptorDesc> {
self.pipeline_layout.descriptor(self.set_id, binding)
}
}
unsafe impl<L, R, P> DeviceOwned for PersistentDescriptorSet<L, R, P>
where L: DeviceOwned
{
#[inline]
fn device(&self) -> &Arc<Device> {
self.layout.device()
}
}
pub struct PersistentDescriptorSetBuilder<L, R> {
layout: L,
set_id: usize,
binding_id: usize,
writes: Vec<DescriptorWrite>,
resources: R,
}
impl<L, R> PersistentDescriptorSetBuilder<L, R>
where L: PipelineLayoutAbstract
{
#[inline]
pub fn build(self)
-> Result<PersistentDescriptorSet<L, R, StdDescriptorPoolAlloc>,
PersistentDescriptorSetBuildError> {
let mut pool = Device::standard_descriptor_pool(self.layout.device());
self.build_with_pool(&mut pool)
}
pub fn build_with_pool<P>(
self, pool: &mut P)
-> Result<PersistentDescriptorSet<L, R, P::Alloc>, PersistentDescriptorSetBuildError>
where P: ?Sized + DescriptorPool
{
assert_eq!(self.layout.device().internal_object(),
pool.device().internal_object());
let expected_desc = self.layout.num_bindings_in_set(self.set_id).unwrap();
if expected_desc > self.binding_id {
return Err(PersistentDescriptorSetBuildError::MissingDescriptors {
expected: expected_desc as u32,
obtained: self.binding_id as u32,
});
}
debug_assert_eq!(expected_desc, self.binding_id);
let set_layout = self.layout
.descriptor_set_layout(self.set_id)
.expect("Unable to get the descriptor set layout")
.clone();
let set = unsafe {
let mut set = pool.alloc(&set_layout)?;
set.inner_mut()
.write(pool.device(), self.writes.into_iter());
set
};
Ok(PersistentDescriptorSet {
inner: set,
resources: self.resources,
pipeline_layout: self.layout,
set_id: self.set_id,
layout: set_layout,
})
}
#[inline]
pub fn enter_array(
self)
-> Result<PersistentDescriptorSetBuilderArray<L, R>, PersistentDescriptorSetError> {
let desc = match self.layout.descriptor(self.set_id, self.binding_id) {
Some(d) => d,
None => return Err(PersistentDescriptorSetError::EmptyExpected),
};
Ok(PersistentDescriptorSetBuilderArray {
builder: self,
desc,
array_element: 0,
})
}
#[inline]
pub fn add_empty(
mut self)
-> Result<PersistentDescriptorSetBuilder<L, R>, PersistentDescriptorSetError> {
match self.layout.descriptor(self.set_id, self.binding_id) {
None => (),
Some(desc) => return Err(PersistentDescriptorSetError::WrongDescriptorTy {
expected: desc.ty.ty().unwrap(),
}),
}
self.binding_id += 1;
Ok(self)
}
#[inline]
pub fn add_buffer<T>(self, buffer: T)
-> Result<PersistentDescriptorSetBuilder<L,
(R,
PersistentDescriptorSetBuf<T>)>,
PersistentDescriptorSetError>
where T: BufferAccess
{
self.enter_array()?.add_buffer(buffer)?.leave_array()
}
pub fn add_buffer_view<T>(self, view: T)
-> Result<PersistentDescriptorSetBuilder<L, (R, PersistentDescriptorSetBufView<T>)>, PersistentDescriptorSetError>
where T: BufferViewRef
{
self.enter_array()?.add_buffer_view(view)?.leave_array()
}
#[inline]
pub fn add_image<T>(self, image_view: T)
-> Result<PersistentDescriptorSetBuilder<L,
(R,
PersistentDescriptorSetImg<T>)>,
PersistentDescriptorSetError>
where T: ImageViewAccess
{
self.enter_array()?.add_image(image_view)?.leave_array()
}
#[inline]
pub fn add_sampled_image<T>(self, image_view: T, sampler: Arc<Sampler>)
-> Result<PersistentDescriptorSetBuilder<L, ((R, PersistentDescriptorSetImg<T>), PersistentDescriptorSetSampler)>, PersistentDescriptorSetError>
where T: ImageViewAccess
{
self.enter_array()?
.add_sampled_image(image_view, sampler)?
.leave_array()
}
#[inline]
pub fn add_sampler(self, sampler: Arc<Sampler>)
-> Result<PersistentDescriptorSetBuilder<L,
(R,
PersistentDescriptorSetSampler)>,
PersistentDescriptorSetError> {
self.enter_array()?.add_sampler(sampler)?.leave_array()
}
}
pub struct PersistentDescriptorSetBuilderArray<L, R> {
builder: PersistentDescriptorSetBuilder<L, R>,
array_element: usize,
desc: DescriptorDesc,
}
impl<L, R> PersistentDescriptorSetBuilderArray<L, R>
where L: PipelineLayoutAbstract
{
pub fn leave_array(
mut self)
-> Result<PersistentDescriptorSetBuilder<L, R>, PersistentDescriptorSetError> {
if self.desc.array_count > self.array_element as u32 {
return Err(PersistentDescriptorSetError::MissingArrayElements {
expected: self.desc.array_count,
obtained: self.array_element as u32,
});
}
debug_assert_eq!(self.desc.array_count, self.array_element as u32);
self.builder.binding_id += 1;
Ok(self.builder)
}
pub fn add_buffer<T>(mut self, buffer: T)
-> Result<PersistentDescriptorSetBuilderArray<L, (R, PersistentDescriptorSetBuf<T>)>, PersistentDescriptorSetError>
where T: BufferAccess
{
assert_eq!(self.builder.layout.device().internal_object(),
buffer.inner().buffer.device().internal_object());
if self.array_element as u32 >= self.desc.array_count {
return Err(PersistentDescriptorSetError::ArrayOutOfBounds);
}
self.builder.writes.push(match self.desc.ty {
DescriptorDescTy::Buffer(ref buffer_desc) => {
assert!(self.builder
.layout
.device()
.enabled_features()
.robust_buffer_access);
if buffer_desc.storage {
if !buffer.inner().buffer.usage_storage_buffer() {
return Err(PersistentDescriptorSetError::MissingBufferUsage(
MissingBufferUsage::StorageBuffer));
}
unsafe {
DescriptorWrite::storage_buffer(self.builder.binding_id as u32,
self.array_element as u32,
&buffer)
}
} else {
if !buffer.inner().buffer.usage_uniform_buffer() {
return Err(PersistentDescriptorSetError::MissingBufferUsage(
MissingBufferUsage::UniformBuffer));
}
unsafe {
DescriptorWrite::uniform_buffer(self.builder.binding_id as u32,
self.array_element as u32,
&buffer)
}
}
},
ref d => {
return Err(PersistentDescriptorSetError::WrongDescriptorTy {
expected: d.ty().unwrap(),
});
},
});
Ok(PersistentDescriptorSetBuilderArray {
builder: PersistentDescriptorSetBuilder {
layout: self.builder.layout,
set_id: self.builder.set_id,
binding_id: self.builder.binding_id,
writes: self.builder.writes,
resources: (self.builder.resources,
PersistentDescriptorSetBuf {
buffer: buffer,
descriptor_num: self.builder.binding_id as u32,
}),
},
desc: self.desc,
array_element: self.array_element + 1,
})
}
pub fn add_buffer_view<T>(mut self, view: T)
-> Result<PersistentDescriptorSetBuilderArray<L, (R, PersistentDescriptorSetBufView<T>)>, PersistentDescriptorSetError>
where T: BufferViewRef
{
assert_eq!(self.builder.layout.device().internal_object(),
view.view().device().internal_object());
if self.array_element as u32 >= self.desc.array_count {
return Err(PersistentDescriptorSetError::ArrayOutOfBounds);
}
self.builder.writes.push(match self.desc.ty {
DescriptorDescTy::TexelBuffer { storage, .. } => {
if storage {
if !view.view().storage_texel_buffer() {
return Err(PersistentDescriptorSetError::MissingBufferUsage(
MissingBufferUsage::StorageTexelBuffer));
}
DescriptorWrite::storage_texel_buffer(self.builder.binding_id as u32,
self.array_element as u32,
view.view())
} else {
if !view.view().uniform_texel_buffer() {
return Err(PersistentDescriptorSetError::MissingBufferUsage(
MissingBufferUsage::UniformTexelBuffer));
}
DescriptorWrite::uniform_texel_buffer(self.builder.binding_id as u32,
self.array_element as u32,
view.view())
}
},
ref d => {
return Err(PersistentDescriptorSetError::WrongDescriptorTy {
expected: d.ty().unwrap(),
});
},
});
Ok(PersistentDescriptorSetBuilderArray {
builder: PersistentDescriptorSetBuilder {
layout: self.builder.layout,
set_id: self.builder.set_id,
binding_id: self.builder.binding_id,
writes: self.builder.writes,
resources: (self.builder.resources,
PersistentDescriptorSetBufView {
view: view,
descriptor_num: self.builder.binding_id as u32,
}),
},
desc: self.desc,
array_element: self.array_element + 1,
})
}
pub fn add_image<T>(mut self, image_view: T)
-> Result<PersistentDescriptorSetBuilderArray<L, (R, PersistentDescriptorSetImg<T>)>, PersistentDescriptorSetError>
where T: ImageViewAccess
{
assert_eq!(self.builder.layout.device().internal_object(),
image_view.parent().inner().image.device().internal_object());
if self.array_element as u32 >= self.desc.array_count {
return Err(PersistentDescriptorSetError::ArrayOutOfBounds);
}
let desc = match self.builder
.layout
.descriptor(self.builder.set_id, self.builder.binding_id) {
Some(d) => d,
None => return Err(PersistentDescriptorSetError::EmptyExpected),
};
self.builder.writes.push(match desc.ty {
DescriptorDescTy::Image(ref desc) => {
image_match_desc(&image_view, &desc)?;
if desc.sampled {
DescriptorWrite::sampled_image(self.builder.binding_id as u32,
self.array_element as u32,
&image_view)
} else {
DescriptorWrite::storage_image(self.builder.binding_id as u32,
self.array_element as u32,
&image_view)
}
},
DescriptorDescTy::InputAttachment {
multisampled,
array_layers,
} => {
if !image_view.parent().inner().image.usage_input_attachment() {
return Err(PersistentDescriptorSetError::MissingImageUsage(
MissingImageUsage::InputAttachment));
}
if multisampled && image_view.samples() == 1 {
return Err(PersistentDescriptorSetError::ExpectedMultisampled);
} else if !multisampled && image_view.samples() != 1 {
return Err(PersistentDescriptorSetError::UnexpectedMultisampled);
}
let image_layers = image_view.dimensions().array_layers();
match array_layers {
DescriptorImageDescArray::NonArrayed => {
if image_layers != 1 {
return Err(PersistentDescriptorSetError::ArrayLayersMismatch {
expected: 1,
obtained: image_layers,
});
}
},
DescriptorImageDescArray::Arrayed { max_layers: Some(max_layers) } => {
if image_layers > max_layers {
return Err(PersistentDescriptorSetError::ArrayLayersMismatch {
expected: max_layers,
obtained: image_layers,
});
}
},
DescriptorImageDescArray::Arrayed { max_layers: None } => {},
};
DescriptorWrite::input_attachment(self.builder.binding_id as u32,
self.array_element as u32,
&image_view)
},
ty => {
return Err(PersistentDescriptorSetError::WrongDescriptorTy {
expected: ty.ty().unwrap(),
});
},
});
Ok(PersistentDescriptorSetBuilderArray {
builder: PersistentDescriptorSetBuilder {
layout: self.builder.layout,
set_id: self.builder.set_id,
binding_id: self.builder.binding_id,
writes: self.builder.writes,
resources: (self.builder.resources,
PersistentDescriptorSetImg {
image: image_view,
descriptor_num: self.builder.binding_id as u32,
}),
},
desc: self.desc,
array_element: self.array_element + 1,
})
}
pub fn add_sampled_image<T>(mut self, image_view: T, sampler: Arc<Sampler>)
-> Result<PersistentDescriptorSetBuilderArray<L, ((R, PersistentDescriptorSetImg<T>), PersistentDescriptorSetSampler)>, PersistentDescriptorSetError>
where T: ImageViewAccess
{
assert_eq!(self.builder.layout.device().internal_object(),
image_view.parent().inner().image.device().internal_object());
assert_eq!(self.builder.layout.device().internal_object(),
sampler.device().internal_object());
if self.array_element as u32 >= self.desc.array_count {
return Err(PersistentDescriptorSetError::ArrayOutOfBounds);
}
let desc = match self.builder
.layout
.descriptor(self.builder.set_id, self.builder.binding_id) {
Some(d) => d,
None => return Err(PersistentDescriptorSetError::EmptyExpected),
};
if !image_view.can_be_sampled(&sampler) {
return Err(PersistentDescriptorSetError::IncompatibleImageViewSampler);
}
self.builder.writes.push(match desc.ty {
DescriptorDescTy::CombinedImageSampler(ref desc) => {
image_match_desc(&image_view, &desc)?;
DescriptorWrite::combined_image_sampler(self.builder.binding_id as u32,
self.array_element as u32,
&sampler,
&image_view)
},
ty => {
return Err(PersistentDescriptorSetError::WrongDescriptorTy {
expected: ty.ty().unwrap(),
});
},
});
Ok(PersistentDescriptorSetBuilderArray {
builder: PersistentDescriptorSetBuilder {
layout: self.builder.layout,
set_id: self.builder.set_id,
binding_id: self.builder.binding_id,
writes: self.builder.writes,
resources: ((self.builder.resources,
PersistentDescriptorSetImg {
image: image_view,
descriptor_num: self.builder.binding_id as u32,
}),
PersistentDescriptorSetSampler { sampler: sampler }),
},
desc: self.desc,
array_element: self.array_element + 1,
})
}
pub fn add_sampler(mut self, sampler: Arc<Sampler>)
-> Result<PersistentDescriptorSetBuilderArray<L, (R, PersistentDescriptorSetSampler)>, PersistentDescriptorSetError>
{
assert_eq!(self.builder.layout.device().internal_object(),
sampler.device().internal_object());
if self.array_element as u32 >= self.desc.array_count {
return Err(PersistentDescriptorSetError::ArrayOutOfBounds);
}
let desc = match self.builder
.layout
.descriptor(self.builder.set_id, self.builder.binding_id) {
Some(d) => d,
None => return Err(PersistentDescriptorSetError::EmptyExpected),
};
self.builder.writes.push(match desc.ty {
DescriptorDescTy::Sampler => {
DescriptorWrite::sampler(self.builder.binding_id as u32,
self.array_element as u32,
&sampler)
},
ty => {
return Err(PersistentDescriptorSetError::WrongDescriptorTy {
expected: ty.ty().unwrap(),
});
},
});
Ok(PersistentDescriptorSetBuilderArray {
builder: PersistentDescriptorSetBuilder {
layout: self.builder.layout,
set_id: self.builder.set_id,
binding_id: self.builder.binding_id,
writes: self.builder.writes,
resources: (self.builder.resources,
PersistentDescriptorSetSampler { sampler: sampler }),
},
desc: self.desc,
array_element: self.array_element + 1,
})
}
}
fn image_match_desc<I>(image_view: &I, desc: &DescriptorImageDesc)
-> Result<(), PersistentDescriptorSetError>
where I: ?Sized + ImageViewAccess
{
if desc.sampled && !image_view.parent().inner().image.usage_sampled() {
return Err(PersistentDescriptorSetError::MissingImageUsage(
MissingImageUsage::Sampled));
} else if !desc.sampled && !image_view.parent().inner().image.usage_storage() {
return Err(PersistentDescriptorSetError::MissingImageUsage(
MissingImageUsage::Storage));
}
let image_view_ty = DescriptorImageDescDimensions::from_dimensions(image_view.dimensions());
if image_view_ty != desc.dimensions {
return Err(PersistentDescriptorSetError::ImageViewTypeMismatch {
expected: desc.dimensions,
obtained: image_view_ty,
});
}
if let Some(format) = desc.format {
if image_view.format() != format {
return Err(PersistentDescriptorSetError::ImageViewFormatMismatch {
expected: format,
obtained: image_view.format(),
});
}
}
if desc.multisampled && image_view.samples() == 1 {
return Err(PersistentDescriptorSetError::ExpectedMultisampled);
} else if !desc.multisampled && image_view.samples() != 1 {
return Err(PersistentDescriptorSetError::UnexpectedMultisampled);
}
let image_layers = image_view.dimensions().array_layers();
match desc.array_layers {
DescriptorImageDescArray::NonArrayed => {
if image_layers != 1 {
return Err(PersistentDescriptorSetError::ArrayLayersMismatch {
expected: 1,
obtained: image_layers,
});
}
},
DescriptorImageDescArray::Arrayed { max_layers: Some(max_layers) } => {
if image_layers > max_layers {
return Err(PersistentDescriptorSetError::ArrayLayersMismatch {
expected: max_layers,
obtained: image_layers,
});
}
},
DescriptorImageDescArray::Arrayed { max_layers: None } => {},
};
Ok(())
}
pub unsafe trait PersistentDescriptorSetResources {
fn num_buffers(&self) -> usize;
fn buffer(&self, index: usize) -> Option<(&dyn BufferAccess, u32)>;
fn num_images(&self) -> usize;
fn image(&self, index: usize) -> Option<(&dyn ImageViewAccess, u32)>;
}
unsafe impl PersistentDescriptorSetResources for () {
#[inline]
fn num_buffers(&self) -> usize {
0
}
#[inline]
fn buffer(&self, _: usize) -> Option<(&dyn BufferAccess, u32)> {
None
}
#[inline]
fn num_images(&self) -> usize {
0
}
#[inline]
fn image(&self, _: usize) -> Option<(&dyn ImageViewAccess, u32)> {
None
}
}
pub struct PersistentDescriptorSetBuf<B> {
buffer: B,
descriptor_num: u32,
}
unsafe impl<R, B> PersistentDescriptorSetResources for (R, PersistentDescriptorSetBuf<B>)
where R: PersistentDescriptorSetResources,
B: BufferAccess
{
#[inline]
fn num_buffers(&self) -> usize {
self.0.num_buffers() + 1
}
#[inline]
fn buffer(&self, index: usize) -> Option<(&dyn BufferAccess, u32)> {
if let Some(buf) = self.0.buffer(index) {
Some(buf)
} else if index == self.0.num_buffers() {
Some((&self.1.buffer, self.1.descriptor_num))
} else {
None
}
}
#[inline]
fn num_images(&self) -> usize {
self.0.num_images()
}
#[inline]
fn image(&self, index: usize) -> Option<(&dyn ImageViewAccess, u32)> {
self.0.image(index)
}
}
pub struct PersistentDescriptorSetBufView<V>
where V: BufferViewRef
{
view: V,
descriptor_num: u32,
}
unsafe impl<R, V> PersistentDescriptorSetResources for (R, PersistentDescriptorSetBufView<V>)
where R: PersistentDescriptorSetResources,
V: BufferViewRef
{
#[inline]
fn num_buffers(&self) -> usize {
self.0.num_buffers() + 1
}
#[inline]
fn buffer(&self, index: usize) -> Option<(&dyn BufferAccess, u32)> {
if let Some(buf) = self.0.buffer(index) {
Some(buf)
} else if index == self.0.num_buffers() {
Some((self.1.view.view().buffer(), self.1.descriptor_num))
} else {
None
}
}
#[inline]
fn num_images(&self) -> usize {
self.0.num_images()
}
#[inline]
fn image(&self, index: usize) -> Option<(&dyn ImageViewAccess, u32)> {
self.0.image(index)
}
}
pub struct PersistentDescriptorSetImg<I> {
image: I,
descriptor_num: u32,
}
unsafe impl<R, I> PersistentDescriptorSetResources for (R, PersistentDescriptorSetImg<I>)
where R: PersistentDescriptorSetResources,
I: ImageViewAccess
{
#[inline]
fn num_buffers(&self) -> usize {
self.0.num_buffers()
}
#[inline]
fn buffer(&self, index: usize) -> Option<(&dyn BufferAccess, u32)> {
self.0.buffer(index)
}
#[inline]
fn num_images(&self) -> usize {
self.0.num_images() + 1
}
#[inline]
fn image(&self, index: usize) -> Option<(&dyn ImageViewAccess, u32)> {
if let Some(img) = self.0.image(index) {
Some(img)
} else if index == self.0.num_images() {
Some((&self.1.image, self.1.descriptor_num))
} else {
None
}
}
}
pub struct PersistentDescriptorSetSampler {
sampler: Arc<Sampler>,
}
unsafe impl<R> PersistentDescriptorSetResources for (R, PersistentDescriptorSetSampler)
where R: PersistentDescriptorSetResources
{
#[inline]
fn num_buffers(&self) -> usize {
self.0.num_buffers()
}
#[inline]
fn buffer(&self, index: usize) -> Option<(&dyn BufferAccess, u32)> {
self.0.buffer(index)
}
#[inline]
fn num_images(&self) -> usize {
self.0.num_images()
}
#[inline]
fn image(&self, index: usize) -> Option<(&dyn ImageViewAccess, u32)> {
self.0.image(index)
}
}
#[derive(Debug, Clone)]
pub enum MissingBufferUsage {
StorageBuffer, UniformBuffer, StorageTexelBuffer, UniformTexelBuffer
}
#[derive(Debug, Clone)]
pub enum MissingImageUsage {
InputAttachment, Sampled, Storage
}
#[derive(Debug, Clone)]
pub enum PersistentDescriptorSetError {
WrongDescriptorTy {
expected: DescriptorType,
},
EmptyExpected,
ArrayOutOfBounds,
MissingArrayElements {
expected: u32,
obtained: u32,
},
IncompatibleImageViewSampler,
MissingBufferUsage(MissingBufferUsage),
MissingImageUsage(MissingImageUsage),
ExpectedMultisampled,
UnexpectedMultisampled,
ArrayLayersMismatch {
expected: u32,
obtained: u32,
},
ImageViewFormatMismatch {
expected: Format,
obtained: Format,
},
ImageViewTypeMismatch {
expected: DescriptorImageDescDimensions,
obtained: DescriptorImageDescDimensions,
},
}
impl error::Error for PersistentDescriptorSetError {
#[inline]
fn description(&self) -> &str {
match *self {
PersistentDescriptorSetError::WrongDescriptorTy { .. } => {
"expected one type of resource but got another"
},
PersistentDescriptorSetError::EmptyExpected => {
"expected an empty descriptor but got something"
},
PersistentDescriptorSetError::ArrayOutOfBounds => {
"tried to add too many elements to an array"
},
PersistentDescriptorSetError::MissingArrayElements { .. } => {
"didn't fill all the elements of an array before leaving"
},
PersistentDescriptorSetError::IncompatibleImageViewSampler => {
"the image view isn't compatible with the sampler"
},
PersistentDescriptorSetError::MissingBufferUsage { .. } => {
"the buffer is missing the correct usage"
},
PersistentDescriptorSetError::MissingImageUsage { .. } => {
"the image is missing the correct usage"
},
PersistentDescriptorSetError::ExpectedMultisampled => {
"expected a multisampled image, but got a single-sampled image"
},
PersistentDescriptorSetError::UnexpectedMultisampled => {
"expected a single-sampled image, but got a multisampled image"
},
PersistentDescriptorSetError::ArrayLayersMismatch { .. } => {
"the number of array layers of an image doesn't match what was expected"
},
PersistentDescriptorSetError::ImageViewFormatMismatch { .. } => {
"the format of an image view doesn't match what was expected"
},
PersistentDescriptorSetError::ImageViewTypeMismatch { .. } => {
"the type of an image view doesn't match what was expected"
},
}
}
}
impl fmt::Display for PersistentDescriptorSetError {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(fmt, "{}", error::Error::description(self))
}
}
#[derive(Debug, Clone)]
pub enum PersistentDescriptorSetBuildError {
OomError(OomError),
MissingDescriptors {
expected: u32,
obtained: u32,
},
}
impl error::Error for PersistentDescriptorSetBuildError {
#[inline]
fn description(&self) -> &str {
match *self {
PersistentDescriptorSetBuildError::MissingDescriptors { .. } => {
"didn't fill all the descriptors before building"
},
PersistentDescriptorSetBuildError::OomError(_) => {
"not enough memory available"
},
}
}
}
impl From<OomError> for PersistentDescriptorSetBuildError {
#[inline]
fn from(err: OomError) -> PersistentDescriptorSetBuildError {
PersistentDescriptorSetBuildError::OomError(err)
}
}
impl fmt::Display for PersistentDescriptorSetBuildError {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(fmt, "{}", error::Error::description(self))
}
}