mod binding;
mod layout;
mod sparse;
pub use self::{binding::*, layout::*, sparse::*};
pub use crate::{
backend::{DescriptorSet, WritableDescriptorSet},
queue::QueueId,
stage::PipelineStages,
};
use crate::{
accel::AccelerationStructure, backend::Device, buffer::BufferRange, encode::Encoder,
image::Layout, sampler::Sampler, sealed::Sealed, view::ImageView, BufferView, General,
OutOfMemory, ShaderReadOnlyOptimal, StaticLayout,
};
#[derive(Clone, Copy, Debug, thiserror::Error, PartialEq, Eq)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub enum DescriptorsAllocationError {
#[error(transparent)]
OutOfMemory {
#[from]
source: OutOfMemory,
},
#[error("Failed to allocate descriptors due to fragmentation")]
Fragmentation,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct DescriptorSetInfo {
pub layout: DescriptorSetLayout,
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct UpdateDescriptorSet<'a> {
pub set: &'a mut WritableDescriptorSet,
pub writes: &'a [DescriptorSetWrite<'a>],
pub copies: &'a [DescriptorSetCopy<'a>],
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct DescriptorSetWrite<'a> {
pub binding: u32,
pub element: u32,
pub descriptors: DescriptorSlice<'a>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct DescriptorSetCopy<'a> {
pub src: &'a DescriptorSet,
pub src_binding: u32,
pub src_element: u32,
pub dst_binding: u32,
pub dst_element: u32,
pub count: u32,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CombinedImageSampler {
pub view: ImageView,
pub layout: Layout,
pub sampler: Sampler,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum DescriptorSlice<'a> {
Sampler(&'a [Sampler]),
CombinedImageSampler(&'a [CombinedImageSampler]),
SampledImage(&'a [(ImageView, Layout)]),
StorageImage(&'a [(ImageView, Layout)]),
UniformTexelBuffer(&'a [BufferView]),
StorageTexelBuffer(&'a [BufferView]),
UniformBuffer(&'a [BufferRange]),
StorageBuffer(&'a [BufferRange]),
UniformBufferDynamic(&'a [BufferRange]),
StorageBufferDynamic(&'a [BufferRange]),
InputAttachment(&'a [(ImageView, Layout)]),
AccelerationStructure(&'a [AccelerationStructure]),
}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum DynamicFormat {}
pub trait ValidLayout<S>: StaticLayout {}
impl ValidLayout<Sampled> for ShaderReadOnlyOptimal {}
impl ValidLayout<Sampled> for General {}
impl ValidLayout<Storage> for General {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum DynamicLayout {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum DynamicOffset {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum StaticOffset {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum Uniform {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum Storage {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum Sampled {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum SamplerDescriptor {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum CombinedImageSamplerDescriptor {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub struct ImageDescriptor<S = Sampled, L = ShaderReadOnlyOptimal> {
pub storage: S,
pub layout: L,
}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub struct BufferDescriptor<S, O = StaticOffset> {
pub storage: S,
pub offset: O,
}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub struct TexelBufferDescriptor<S, F> {
pub storage: S,
pub format: F,
}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum InputAttachmentDescriptor {}
#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
pub enum AccelerationStructureDescriptor {}
#[doc(hidden)]
pub trait DescriptorKind: Sealed {
const TYPE: DescriptorType;
type Descriptor: std::hash::Hash + Eq;
fn descriptors(slice: &[Self::Descriptor]) -> DescriptorSlice<'_>;
}
impl Sealed for SamplerDescriptor {}
impl DescriptorKind for SamplerDescriptor {
const TYPE: DescriptorType = DescriptorType::Sampler;
type Descriptor = Sampler;
fn descriptors(slice: &[Sampler]) -> DescriptorSlice<'_> {
DescriptorSlice::Sampler(slice)
}
}
impl Sealed for CombinedImageSamplerDescriptor {}
impl DescriptorKind for CombinedImageSamplerDescriptor {
const TYPE: DescriptorType = DescriptorType::CombinedImageSampler;
type Descriptor = CombinedImageSampler;
fn descriptors(slice: &[CombinedImageSampler]) -> DescriptorSlice<'_> {
DescriptorSlice::CombinedImageSampler(slice)
}
}
impl<L> Sealed for ImageDescriptor<Sampled, L> {}
impl<L> DescriptorKind for ImageDescriptor<Sampled, L> {
const TYPE: DescriptorType = DescriptorType::SampledImage;
type Descriptor = (ImageView, Layout);
fn descriptors(slice: &[(ImageView, Layout)]) -> DescriptorSlice<'_> {
DescriptorSlice::SampledImage(slice)
}
}
impl<L> Sealed for ImageDescriptor<Storage, L> {}
impl<L> DescriptorKind for ImageDescriptor<Storage, L> {
const TYPE: DescriptorType = DescriptorType::StorageImage;
type Descriptor = (ImageView, Layout);
fn descriptors(slice: &[(ImageView, Layout)]) -> DescriptorSlice<'_> {
DescriptorSlice::StorageImage(slice)
}
}
impl Sealed for BufferDescriptor<Uniform> {}
impl DescriptorKind for BufferDescriptor<Uniform> {
const TYPE: DescriptorType = DescriptorType::UniformBuffer;
type Descriptor = BufferRange;
fn descriptors(slice: &[BufferRange]) -> DescriptorSlice<'_> {
DescriptorSlice::UniformBuffer(slice)
}
}
impl Sealed for BufferDescriptor<Storage> {}
impl DescriptorKind for BufferDescriptor<Storage> {
const TYPE: DescriptorType = DescriptorType::StorageBuffer;
type Descriptor = BufferRange;
fn descriptors(slice: &[BufferRange]) -> DescriptorSlice<'_> {
DescriptorSlice::StorageBuffer(slice)
}
}
impl Sealed for BufferDescriptor<Uniform, DynamicOffset> {}
impl DescriptorKind for BufferDescriptor<Uniform, DynamicOffset> {
const TYPE: DescriptorType = DescriptorType::UniformBufferDynamic;
type Descriptor = BufferRange;
fn descriptors(slice: &[BufferRange]) -> DescriptorSlice<'_> {
DescriptorSlice::UniformBufferDynamic(slice)
}
}
impl Sealed for BufferDescriptor<Storage, DynamicOffset> {}
impl DescriptorKind for BufferDescriptor<Storage, DynamicOffset> {
const TYPE: DescriptorType = DescriptorType::StorageBufferDynamic;
type Descriptor = BufferRange;
fn descriptors(slice: &[BufferRange]) -> DescriptorSlice<'_> {
DescriptorSlice::StorageBufferDynamic(slice)
}
}
impl<F> Sealed for TexelBufferDescriptor<Uniform, F> {}
impl<F> DescriptorKind for TexelBufferDescriptor<Uniform, F> {
const TYPE: DescriptorType = DescriptorType::UniformTexelBuffer;
type Descriptor = BufferView;
fn descriptors(slice: &[BufferView]) -> DescriptorSlice<'_> {
DescriptorSlice::UniformTexelBuffer(slice)
}
}
impl<F> Sealed for TexelBufferDescriptor<Storage, F> {}
impl<F> DescriptorKind for TexelBufferDescriptor<Storage, F> {
const TYPE: DescriptorType = DescriptorType::StorageTexelBuffer;
type Descriptor = BufferView;
fn descriptors(slice: &[BufferView]) -> DescriptorSlice<'_> {
DescriptorSlice::StorageTexelBuffer(slice)
}
}
impl Sealed for InputAttachmentDescriptor {}
impl DescriptorKind for InputAttachmentDescriptor {
const TYPE: DescriptorType = DescriptorType::InputAttachment;
type Descriptor = (ImageView, Layout);
fn descriptors(slice: &[(ImageView, Layout)]) -> DescriptorSlice<'_> {
DescriptorSlice::InputAttachment(slice)
}
}
impl Sealed for AccelerationStructureDescriptor {}
impl DescriptorKind for AccelerationStructureDescriptor {
const TYPE: DescriptorType = DescriptorType::AccelerationStructure;
type Descriptor = AccelerationStructure;
fn descriptors(slice: &[AccelerationStructure]) -> DescriptorSlice<'_> {
DescriptorSlice::AccelerationStructure(slice)
}
}
pub trait DescriptorsLayout {
type Instance;
fn raw(&self) -> &DescriptorSetLayout;
fn instance(&self) -> Self::Instance;
}
pub trait UpdatedDescriptors {
fn raw(&self) -> &DescriptorSet;
}
pub trait DescriptorsInstance<I: ?Sized> {
type Updated: UpdatedDescriptors;
fn update(
&mut self,
input: &I,
device: &Device,
encoder: &mut Encoder,
) -> Result<&Self::Updated, DescriptorsAllocationError>;
fn raw_layout(&self) -> &DescriptorSetLayout;
}
pub trait Descriptors {
type Layout;
type Instance: DescriptorsInstance<Self>;
fn layout(device: &Device) -> Result<Self::Layout, OutOfMemory>;
}
pub trait UpdatedPipelineDescriptors<P: ?Sized, const N: u32>: UpdatedDescriptors {}