Bug 1912019 - Undo the gpu-descriptor crate override. r=ErichDonGubler,supply-chain-reviewers

WebRender depends on allocator-api2 now.

Differential Revision: https://phabricator.services.mozilla.com/D221967
This commit is contained in:
Nicolas Silva
2024-09-18 10:17:27 +00:00
parent 9b20807e14
commit 855acf5cc9
14 changed files with 839 additions and 832 deletions

View File

@@ -100,11 +100,6 @@ git = "https://github.com/servo/unicode-bidi"
rev = "ca612daf1c08c53abe07327cb3e6ef6e0a760f0c"
replace-with = "vendored-sources"
[source."git+https://github.com/zakarumych/gpu-descriptor?rev=7b71a4e47c81903ad75e2c53deb5ab1310f6ff4d"]
git = "https://github.com/zakarumych/gpu-descriptor"
rev = "7b71a4e47c81903ad75e2c53deb5ab1310f6ff4d"
replace-with = "vendored-sources"
# Take advantage of the fact that cargo will treat lines starting with #
# as comments to add preprocessing directives. This file can thus by copied

7
Cargo.lock generated
View File

@@ -2579,7 +2579,8 @@ dependencies = [
[[package]]
name = "gpu-descriptor"
version = "0.3.0"
source = "git+https://github.com/zakarumych/gpu-descriptor?rev=7b71a4e47c81903ad75e2c53deb5ab1310f6ff4d#7b71a4e47c81903ad75e2c53deb5ab1310f6ff4d"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c08c1f623a8d0b722b8b99f821eb0ba672a1618f0d3b16ddbee1cedd2dd8557"
dependencies = [
"bitflags 2.6.0",
"gpu-descriptor-types",
@@ -2589,7 +2590,8 @@ dependencies = [
[[package]]
name = "gpu-descriptor-types"
version = "0.2.0"
source = "git+https://github.com/zakarumych/gpu-descriptor?rev=7b71a4e47c81903ad75e2c53deb5ab1310f6ff4d#7b71a4e47c81903ad75e2c53deb5ab1310f6ff4d"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdf242682df893b86f33a73828fb09ca4b2d3bb6cc95249707fc684d27484b91"
dependencies = [
"bitflags 2.6.0",
]
@@ -2651,6 +2653,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
dependencies = [
"ahash",
"allocator-api2",
]
[[package]]

View File

@@ -219,8 +219,4 @@ tabs = { git = "https://github.com/mozilla/application-services", rev = "5af28e1
viaduct = { git = "https://github.com/mozilla/application-services", rev = "5af28e120fd636135d50894cf16a74e21dc63045" }
webext-storage = { git = "https://github.com/mozilla/application-services", rev = "5af28e120fd636135d50894cf16a74e21dc63045" }
# Patch `gpu-descriptor` 0.3.0 to remove unnecessary `allocator-api2` dep.:
# Still waiting for the now-merged <https://github.com/zakarumych/gpu-descriptor/pull/40> to be released.
gpu-descriptor = { git = "https://github.com/zakarumych/gpu-descriptor", rev = "7b71a4e47c81903ad75e2c53deb5ab1310f6ff4d" }
allocator-api2 = { path = "third_party/rust/allocator-api2" }

View File

@@ -72,12 +72,6 @@ notes = "The dependencies on tokio-reactor and tokio-threadpools are just a hack
criteria = "safe-to-run"
notes = "Used for fuzzing."
[policy.gpu-descriptor]
audit-as-crates-io = true
[policy.gpu-descriptor-types]
audit-as-crates-io = true
[policy.http3server]
criteria = "safe-to-run"
notes = "Used for testing."

View File

@@ -1 +1 @@
{"files":{"Cargo.toml":"6ec655b687fc0d5a93c589b6b1e243d0b8c01b70212682b6ce1e2ee888d13361","src/device.rs":"0f9957fee64c4db767a2abb2e88d34ebbf48ed6062121e081e0116e14190b4fa","src/lib.rs":"0ca3f2a281ba43466fb4d29c05b35c9059806d6114cd929b85afc0c41ea9d3ac","src/types.rs":"d38b838827edf226f6bc82e8f0718d90d6e2376d027c118a6d397260996a12bd"},"package":null}
{"files":{"Cargo.toml":"54164c8c1352852cce6f2330030365868815deb9bd717b8d493071790cd72d7b","src/device.rs":"2420d9126f4a0908721917428e7ec4c126cda2768c079fae4f630dd81d5bf721","src/lib.rs":"bcf06593c390a3999f300333f63ae69542613157d316b3246faf69eded07d896","src/types.rs":"8a9d9e9aa4ec4605b765a4b4845c27a30d338f9bc73274ae2b466112a33919f8"},"package":"fdf242682df893b86f33a73828fb09ca4b2d3bb6cc95249707fc684d27484b91"}

View File

@@ -14,15 +14,9 @@ edition = "2018"
name = "gpu-descriptor-types"
version = "0.2.0"
authors = ["Zakarum <zakarumych@ya.ru>"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Core types of gpu-descriptor crate"
homepage = "https://github.com/zakarumych/gpu-descriptor"
documentation = "https://docs.rs/gpu-descriptor-types"
readme = false
keywords = [
"gpu",
"vulkan",
@@ -32,10 +26,6 @@ keywords = [
license = "MIT OR Apache-2.0"
repository = "https://github.com/zakarumych/gpu-descriptor"
[lib]
name = "gpu_descriptor_types"
path = "src/lib.rs"
[dependencies.bitflags]
version = "2.4"
default-features = false

View File

@@ -1,75 +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> {
/// 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>);
}
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>);
}

View File

@@ -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::*};

View File

@@ -1,53 +1,53 @@
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
}
}
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
}
}

View File

@@ -1 +1 @@
{"files":{"Cargo.toml":"f05bb02b22a730a3ba7fded8afa84c5d31c60531d51604d2051ab8c4fd9265fb","src/allocator.rs":"38d173f9b6ca608dee9a7898b6e2ad7e75d199284c99291da0112e4b6e908409","src/lib.rs":"6fb74a08ad9975e561f4fca7bd391f0cbd96a7cab79b17df7d979021099b50f9"},"package":null}
{"files":{"Cargo.toml":"f879e82bc2f03b8c7fb6053d0582bf7e70a89525c63ba41b99092b9128c8cf9e","README.md":"23283d5bdd4ef362cc5f848b03f58e0ad2354d4fbcfc477032c5db2cb0b6d9db","src/allocator.rs":"d7456bb290565722ade6d9997283c3b23ddc970baf796bbe87bdff0bfff7a6f9","src/lib.rs":"86d91995ea56d2ccf12974cb28f02028d096e00acbe417b1acdaa0d7133ae9f2"},"package":"9c08c1f623a8d0b722b8b99f821eb0ba672a1618f0d3b16ddbee1cedd2dd8557"}

View File

@@ -14,15 +14,10 @@ edition = "2018"
name = "gpu-descriptor"
version = "0.3.0"
authors = ["Zakarum <zakarumych@ya.ru>"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Implementation agnostic descriptor allocator for Vulkan like APIs"
homepage = "https://github.com/zakarumych/gpu-descriptor"
documentation = "https://docs.rs/gpu-descriptor"
readme = "../README.md"
readme = "README.md"
keywords = [
"gpu",
"vulkan",
@@ -31,25 +26,15 @@ keywords = [
license = "MIT OR Apache-2.0"
repository = "https://github.com/zakarumych/gpu-descriptor"
[lib]
name = "gpu_descriptor"
path = "src/lib.rs"
[dependencies.bitflags]
version = "2.4"
default-features = false
[dependencies.gpu-descriptor-types]
version = "0.2"
path = "../types"
[dependencies.hashbrown]
version = "0.14"
features = [
"ahash",
"raw",
]
default-features = false
[dependencies.serde]
version = "1.0"

View File

@@ -0,0 +1,44 @@
# gpu-descriptor
[![crates](https://img.shields.io/crates/v/gpu-descriptor.svg?style=for-the-badge&label=gpu-descriptor)](https://crates.io/crates/gpu-descriptor)
[![docs](https://img.shields.io/badge/docs.rs-gpu--descriptor-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white)](https://docs.rs/gpu-descriptor)
[![actions](https://img.shields.io/github/workflow/status/zakarumych/gpu-descriptor/badge/master?style=for-the-badge)](https://github.com/zakarumych/gpu-descriptor/actions?query=workflow%3ARust)
[![MIT/Apache](https://img.shields.io/badge/license-MIT%2FApache-blue.svg?style=for-the-badge)](COPYING)
![loc](https://img.shields.io/tokei/lines/github/zakarumych/gpu-descriptor?style=for-the-badge)
Library for Vulkan-like APIs to allocated descriptor sets
from descriptor pools fast, with least overhead and zero fragmentation.
Straightforward usage:
```rust
use gpu_descriptor::DescriptorAllocator;
let mut allocator = DescriptorAllocator::new(max_update_after_bind_descriptors_in_all_pools); // Limit as dictated by API for selected hardware
let result = allocator.allocate(
device, // Implementation of `gpu_descriptor::DescriptorDevice`. Comes from plugins.
layout, // Descriptor set layout recognized by device's type.
flags, // Flags specified when layout was created.
layout_descriptor_count, // Descriptors count in the layout.
count, // count of sets to allocated.
);
```
## License
Licensed under either of
* Apache License, Version 2.0, ([license/APACHE](license/APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([license/MIT](license/MIT) or http://opensource.org/licenses/MIT)
at your option.
## Contributions
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
## Support me on Patreon
[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dzakarum%26type%3Dpatrons&style=for-the-badge)](https://patreon.com/zakarum)

File diff suppressed because it is too large Load Diff

View File

@@ -1,35 +1,35 @@
//!
//! Library for Vulkan-like APIs to allocated descriptor sets
//! from descriptor pools fast, with least overhead and zero fragmentation.
//!
//! Straightforward usage:
//! ```ignore
//! use gpu_descriptor::DescriptorAllocator;
//!
//! let mut allocator = DescriptorAllocator::new(max_update_after_bind_descriptors_in_all_pools); // Limit as dictated by API for selected hardware
//!
//! let result = allocator.allocate(
//! device, // Implementation of `gpu_descriptor::DescriptorDevice`. Comes from plugins.
//! layout, // Descriptor set layout recognized by device's type.
//! flags, // Flags specified when layout was created.
//! layout_descriptor_count, // Descriptors count in the layout.
//! count, // count of sets to allocated.
//! );
//! ```
//!
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications
)]
extern crate alloc;
mod allocator;
pub use {crate::allocator::*, gpu_descriptor_types::*};
//!
//! Library for Vulkan-like APIs to allocated descriptor sets
//! from descriptor pools fast, with least overhead and zero fragmentation.
//!
//! Straightforward usage:
//! ```ignore
//! use gpu_descriptor::DescriptorAllocator;
//!
//! let mut allocator = DescriptorAllocator::new(max_update_after_bind_descriptors_in_all_pools); // Limit as dictated by API for selected hardware
//!
//! let result = allocator.allocate(
//! device, // Implementation of `gpu_descriptor::DescriptorDevice`. Comes from plugins.
//! layout, // Descriptor set layout recognized by device's type.
//! flags, // Flags specified when layout was created.
//! layout_descriptor_count, // Descriptors count in the layout.
//! count, // count of sets to allocated.
//! );
//! ```
//!
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications
)]
extern crate alloc;
mod allocator;
pub use {crate::allocator::*, gpu_descriptor_types::*};