diff options
Diffstat (limited to 'third_party/rust/gpu-descriptor-types/src')
-rw-r--r-- | third_party/rust/gpu-descriptor-types/src/device.rs | 128 | ||||
-rw-r--r-- | third_party/rust/gpu-descriptor-types/src/lib.rs | 12 | ||||
-rw-r--r-- | third_party/rust/gpu-descriptor-types/src/types.rs | 86 |
3 files changed, 134 insertions, 92 deletions
diff --git a/third_party/rust/gpu-descriptor-types/src/device.rs b/third_party/rust/gpu-descriptor-types/src/device.rs index b10511f863..a73a58a79c 100644 --- a/third_party/rust/gpu-descriptor-types/src/device.rs +++ b/third_party/rust/gpu-descriptor-types/src/device.rs @@ -1,53 +1,75 @@ -use crate::types::{DescriptorPoolCreateFlags, DescriptorTotalCount};
-
-/// Memory exhausted error.
-#[derive(Debug)]
-pub enum CreatePoolError {
- /// Device memory exhausted.
- OutOfDeviceMemory,
-
- /// Host memory exhausted.
- OutOfHostMemory,
-
- /// A descriptor pool creation has failed due to fragmentation.
- Fragmentation,
-}
-
-/// Memory exhausted error.
-#[derive(Debug)]
-pub enum DeviceAllocationError {
- /// Device memory exhausted.
- OutOfDeviceMemory,
-
- /// Host memory exhausted.
- OutOfHostMemory,
-
- /// Failed to allocate memory from pool.
- OutOfPoolMemory,
-
- /// Pool allocation failed due to fragmentation of pool's memory.
- FragmentedPool,
-}
-
-/// Abstract device that can create pools of type `P` and allocate sets `S` with layout `L`.
-pub trait DescriptorDevice<L, P, S> {
- unsafe fn create_descriptor_pool(
- &self,
- descriptor_count: &DescriptorTotalCount,
- max_sets: u32,
- flags: DescriptorPoolCreateFlags,
- ) -> Result<P, CreatePoolError>;
-
- unsafe fn destroy_descriptor_pool(&self, pool: P);
-
- unsafe fn alloc_descriptor_sets<'a>(
- &self,
- pool: &mut P,
- layouts: impl ExactSizeIterator<Item = &'a L>,
- sets: &mut impl Extend<S>,
- ) -> Result<(), DeviceAllocationError>
- where
- L: 'a;
-
- unsafe fn dealloc_descriptor_sets<'a>(&self, pool: &mut P, sets: impl Iterator<Item = S>);
-}
+use crate::types::{DescriptorPoolCreateFlags, DescriptorTotalCount}; + +/// Memory exhausted error. +#[derive(Debug)] +pub enum CreatePoolError { + /// Device memory exhausted. + OutOfDeviceMemory, + + /// Host memory exhausted. + OutOfHostMemory, + + /// A descriptor pool creation has failed due to fragmentation. + Fragmentation, +} + +/// Memory exhausted error. +#[derive(Debug)] +pub enum DeviceAllocationError { + /// Device memory exhausted. + OutOfDeviceMemory, + + /// Host memory exhausted. + OutOfHostMemory, + + /// Failed to allocate memory from pool. + OutOfPoolMemory, + + /// Pool allocation failed due to fragmentation of pool's memory. + FragmentedPool, +} + +/// Abstract device that can create pools of type `P` and allocate sets `S` with layout `L`. +pub trait DescriptorDevice<L, P, S> { + /// Creates a new descriptor pool. + /// + /// # Safety + /// + /// Actually safe. + /// TODO: Remove `unsafe` with next breaking change. + unsafe fn create_descriptor_pool( + &self, + descriptor_count: &DescriptorTotalCount, + max_sets: u32, + flags: DescriptorPoolCreateFlags, + ) -> Result<P, CreatePoolError>; + + /// Destroys descriptor pool. + /// + /// # Safety + /// + /// Pool must be created from this device. + /// All descriptor sets allocated from this pool become invalid. + unsafe fn destroy_descriptor_pool(&self, pool: P); + + /// Allocates descriptor sets. + /// + /// # Safety + /// + /// Pool must be created from this device. + unsafe fn alloc_descriptor_sets<'a>( + &self, + pool: &mut P, + layouts: impl ExactSizeIterator<Item = &'a L>, + sets: &mut impl Extend<S>, + ) -> Result<(), DeviceAllocationError> + where + L: 'a; + + /// Deallocates descriptor sets. + /// + /// # Safety + /// + /// Sets must be allocated from specified pool and not deallocated before. + unsafe fn dealloc_descriptor_sets(&self, pool: &mut P, sets: impl Iterator<Item = S>); +} diff --git a/third_party/rust/gpu-descriptor-types/src/lib.rs b/third_party/rust/gpu-descriptor-types/src/lib.rs index 37c0d861c6..2af448c654 100644 --- a/third_party/rust/gpu-descriptor-types/src/lib.rs +++ b/third_party/rust/gpu-descriptor-types/src/lib.rs @@ -1,6 +1,6 @@ -#![no_std]
-
-mod device;
-mod types;
-
-pub use self::{device::*, types::*};
+#![no_std] + +mod device; +mod types; + +pub use self::{device::*, types::*}; diff --git a/third_party/rust/gpu-descriptor-types/src/types.rs b/third_party/rust/gpu-descriptor-types/src/types.rs index f65ffc74ae..73b28dcea5 100644 --- a/third_party/rust/gpu-descriptor-types/src/types.rs +++ b/third_party/rust/gpu-descriptor-types/src/types.rs @@ -1,33 +1,53 @@ -bitflags::bitflags! {
- /// Flags to augment descriptor pool creation.
- ///
- /// Match corresponding bits in Vulkan.
- pub struct DescriptorPoolCreateFlags: u32 {
- /// Allows freeing individial sets.
- const FREE_DESCRIPTOR_SET = 0x1;
-
- /// Allows allocating sets with layout created with matching backend-specific flag.
- const UPDATE_AFTER_BIND = 0x2;
- }
-}
-
-/// Number of descriptors of each type.
-///
-/// For `InlineUniformBlock` this value is number of bytes instead.
-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
-pub struct DescriptorTotalCount {
- pub sampler: u32,
- pub combined_image_sampler: u32,
- pub sampled_image: u32,
- pub storage_image: u32,
- pub uniform_texel_buffer: u32,
- pub storage_texel_buffer: u32,
- pub uniform_buffer: u32,
- pub storage_buffer: u32,
- pub uniform_buffer_dynamic: u32,
- pub storage_buffer_dynamic: u32,
- pub input_attachment: u32,
- pub acceleration_structure: u32,
- pub inline_uniform_block_bytes: u32,
- pub inline_uniform_block_bindings: u32,
-}
+bitflags::bitflags! { + /// Flags to augment descriptor pool creation. + /// + /// Match corresponding bits in Vulkan. + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] + pub struct DescriptorPoolCreateFlags: u32 { + /// Allows freeing individual sets. + const FREE_DESCRIPTOR_SET = 0x1; + + /// Allows allocating sets with layout created with matching backend-specific flag. + const UPDATE_AFTER_BIND = 0x2; + } +} + +/// Number of descriptors of each type. +/// +/// For `InlineUniformBlock` this value is number of bytes instead. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +pub struct DescriptorTotalCount { + pub sampler: u32, + pub combined_image_sampler: u32, + pub sampled_image: u32, + pub storage_image: u32, + pub uniform_texel_buffer: u32, + pub storage_texel_buffer: u32, + pub uniform_buffer: u32, + pub storage_buffer: u32, + pub uniform_buffer_dynamic: u32, + pub storage_buffer_dynamic: u32, + pub input_attachment: u32, + pub acceleration_structure: u32, + pub inline_uniform_block_bytes: u32, + pub inline_uniform_block_bindings: u32, +} + +impl DescriptorTotalCount { + pub fn total(&self) -> u32 { + self.sampler + + self.combined_image_sampler + + self.sampled_image + + self.storage_image + + self.uniform_texel_buffer + + self.storage_texel_buffer + + self.uniform_buffer + + self.storage_buffer + + self.uniform_buffer_dynamic + + self.storage_buffer_dynamic + + self.input_attachment + + self.acceleration_structure + + self.inline_uniform_block_bytes + + self.inline_uniform_block_bindings + } +} |