summaryrefslogtreecommitdiffstats
path: root/third_party/rust/gpu-descriptor-types
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/gpu-descriptor-types')
-rw-r--r--third_party/rust/gpu-descriptor-types/.cargo-checksum.json2
-rw-r--r--third_party/rust/gpu-descriptor-types/Cargo.toml23
-rw-r--r--third_party/rust/gpu-descriptor-types/src/device.rs128
-rw-r--r--third_party/rust/gpu-descriptor-types/src/lib.rs12
-rw-r--r--third_party/rust/gpu-descriptor-types/src/types.rs86
5 files changed, 149 insertions, 102 deletions
diff --git a/third_party/rust/gpu-descriptor-types/.cargo-checksum.json b/third_party/rust/gpu-descriptor-types/.cargo-checksum.json
index ff289fd42a..9a414739ec 100644
--- a/third_party/rust/gpu-descriptor-types/.cargo-checksum.json
+++ b/third_party/rust/gpu-descriptor-types/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"5e3f9842253279ef626cd67111b942c5ef8d011efb39cc00b8f3469f8b4bede9","src/device.rs":"ecb6aaefd8af7ac51eed42a01ebbe7a98f44f62ea3b8d193e11a6889d4cd01bb","src/lib.rs":"bcf06593c390a3999f300333f63ae69542613157d316b3246faf69eded07d896","src/types.rs":"65f8e4006280713668f96279ce96c2d21fc75b5fb0fe4240dc650dfe71f92b27"},"package":"363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126"} \ No newline at end of file
+{"files":{"Cargo.toml":"54164c8c1352852cce6f2330030365868815deb9bd717b8d493071790cd72d7b","src/device.rs":"0f9957fee64c4db767a2abb2e88d34ebbf48ed6062121e081e0116e14190b4fa","src/lib.rs":"0ca3f2a281ba43466fb4d29c05b35c9059806d6114cd929b85afc0c41ea9d3ac","src/types.rs":"d38b838827edf226f6bc82e8f0718d90d6e2376d027c118a6d397260996a12bd"},"package":null} \ No newline at end of file
diff --git a/third_party/rust/gpu-descriptor-types/Cargo.toml b/third_party/rust/gpu-descriptor-types/Cargo.toml
index 18871bb18b..f63ba9b7b6 100644
--- a/third_party/rust/gpu-descriptor-types/Cargo.toml
+++ b/third_party/rust/gpu-descriptor-types/Cargo.toml
@@ -3,24 +3,29 @@
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g., crates.io) dependencies
+# to registry (e.g., crates.io) dependencies.
#
-# If you believe there's an error in this file please file an
-# issue against the rust-lang/cargo repository. If you're
-# editing this file be aware that the upstream Cargo.toml
-# will likely look very different (and much more reasonable)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "gpu-descriptor-types"
-version = "0.1.1"
+version = "0.2.0"
authors = ["Zakarum <zakarumych@ya.ru>"]
description = "Core types of gpu-descriptor crate"
homepage = "https://github.com/zakarumych/gpu-descriptor"
-documentation = "https://docs.rs/gpu-descriptor-types/0.1.0"
-keywords = ["gpu", "vulkan", "allocation", "no-std"]
+documentation = "https://docs.rs/gpu-descriptor-types"
+keywords = [
+ "gpu",
+ "vulkan",
+ "allocation",
+ "no-std",
+]
license = "MIT OR Apache-2.0"
repository = "https://github.com/zakarumych/gpu-descriptor"
+
[dependencies.bitflags]
-version = "1.2"
+version = "2.4"
default-features = false
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
+ }
+}