Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add remaining ext_descriptor_indexing flags #2358

Merged
merged 5 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
315 changes: 297 additions & 18 deletions vulkano/src/descriptor_set/layout.rs

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion vulkano/src/descriptor_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ pub use self::{
WriteDescriptorSetElements,
},
};
use self::{layout::DescriptorSetLayout, pool::DescriptorPoolAlloc};
use self::{
layout::DescriptorSetLayout,
pool::{DescriptorPool, DescriptorPoolAlloc},
};
use crate::{
acceleration_structure::AccelerationStructure,
buffer::view::BufferView,
Expand Down Expand Up @@ -122,6 +125,9 @@ pub unsafe trait DescriptorSet:
/// Returns the allocation of the descriptor set.
fn alloc(&self) -> &DescriptorPoolAlloc;

/// Returns the descriptor pool that the descriptor set was allocated from.
fn pool(&self) -> &DescriptorPool;

/// Returns the layout of this descriptor set.
#[inline]
fn layout(&self) -> &Arc<DescriptorSetLayout> {
Expand Down
10 changes: 9 additions & 1 deletion vulkano/src/descriptor_set/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
//! # Examples
//! TODO:
use super::{pool::DescriptorPoolAlloc, sys::UnsafeDescriptorSet, CopyDescriptorSet};
use super::{
pool::{DescriptorPool, DescriptorPoolAlloc},
sys::UnsafeDescriptorSet,
CopyDescriptorSet,
};
use crate::{
descriptor_set::{
allocator::{DescriptorSetAlloc, DescriptorSetAllocator, StandardDescriptorSetAlloc},
Expand Down Expand Up @@ -126,6 +130,10 @@ where
self.inner.alloc().inner()
}

fn pool(&self) -> &DescriptorPool {
self.inner.alloc().pool()
}

fn resources(&self) -> &DescriptorSetResources {
&self.resources
}
Expand Down
38 changes: 35 additions & 3 deletions vulkano/src/descriptor_set/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,33 @@ impl DescriptorPool {
for (index, info) in allocate_infos.iter().enumerate() {
info.validate(self.device())
.map_err(|err| err.add_context(format!("allocate_infos[{}]", index)))?;

let &DescriptorSetAllocateInfo {
ref layout,
variable_descriptor_count: _,
_ne: _,
} = info;

if layout
.flags()
.intersects(DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL)
&& !self
.flags
.intersects(DescriptorPoolCreateFlags::UPDATE_AFTER_BIND)
{
return Err(Box::new(ValidationError {
problem: format!(
"`allocate_infos[{}].layout.flags()` contains \
`DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL`, but \
`self.flags` does not contain \
`DescriptorPoolCreateFlags::UPDATE_AFTER_BIND`",
index
)
.into(),
vuids: &["VUID-VkDescriptorSetAllocateInfo-pSetLayouts-03044"],
..Default::default()
}));
}
}

Ok(())
Expand Down Expand Up @@ -558,13 +585,18 @@ vulkan_bitflags! {
/// destroy the whole pool at once.
FREE_DESCRIPTOR_SET = FREE_DESCRIPTOR_SET,

/* TODO: enable
// TODO: document
/// The pool can allocate descriptor sets with a layout whose flags include
/// [`DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL`].
///
/// A pool created with this flag can still allocate descriptor sets without the flag.
/// However, descriptor copy operations are only allowed between pools of the same type;
/// it is not possible to copy between a descriptor set whose pool has `UPDATE_AFTER_BIND`,
/// and a descriptor set whose pool does not have this flag.
UPDATE_AFTER_BIND = UPDATE_AFTER_BIND
RequiresOneOf([
RequiresAllOf([APIVersion(V1_2)]),
RequiresAllOf([DeviceExtension(ext_descriptor_indexing)]),
]), */
]),

/* TODO: enable
// TODO: document
Expand Down
9 changes: 8 additions & 1 deletion vulkano/src/descriptor_set/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use super::{
allocator::{DescriptorSetAlloc, DescriptorSetAllocator, StandardDescriptorSetAlloc},
pool::DescriptorPool,
CopyDescriptorSet,
};
use crate::{
Expand Down Expand Up @@ -60,6 +61,12 @@ where
&self.alloc
}

/// Returns the descriptor pool that the descriptor set was allocated from.
#[inline]
pub fn pool(&self) -> &DescriptorPool {
self.alloc.pool()
}

/// Returns the layout of this descriptor set.
#[inline]
pub fn layout(&self) -> &Arc<DescriptorSetLayout> {
Expand Down Expand Up @@ -104,7 +111,7 @@ where
}

for (index, copy) in descriptor_copies.iter().enumerate() {
copy.validate(self.layout(), self.variable_descriptor_count())
copy.validate(self)
.map_err(|err| err.add_context(format!("descriptor_copies[{}]", index)))?;
}

Expand Down
89 changes: 81 additions & 8 deletions vulkano/src/descriptor_set/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
// according to those terms.

use super::{
allocator::DescriptorSetAlloc,
layout::{DescriptorSetLayout, DescriptorType},
sys::UnsafeDescriptorSet,
DescriptorSet,
};
use crate::{
acceleration_structure::{AccelerationStructure, AccelerationStructureType},
buffer::{view::BufferView, BufferUsage, Subbuffer},
descriptor_set::layout::{DescriptorBindingFlags, DescriptorSetLayoutCreateFlags},
descriptor_set::{
layout::{DescriptorBindingFlags, DescriptorSetLayoutCreateFlags},
pool::DescriptorPoolCreateFlags,
},
device::DeviceOwned,
image::{
sampler::Sampler,
Expand Down Expand Up @@ -1629,11 +1634,13 @@ impl CopyDescriptorSet {
}
}

pub(crate) fn validate(
pub(crate) fn validate<P>(
&self,
dst_set_layout: &DescriptorSetLayout,
dst_set_variable_descriptor_count: u32,
) -> Result<(), Box<ValidationError>> {
dst_set: &UnsafeDescriptorSet<P>,
) -> Result<(), Box<ValidationError>>
where
P: DescriptorSetAlloc,
{
let &Self {
ref src_set,
src_binding,
Expand All @@ -1645,7 +1652,73 @@ impl CopyDescriptorSet {
} = self;

// VUID-VkCopyDescriptorSet-commonparent
assert_eq!(src_set.device(), dst_set_layout.device());
assert_eq!(src_set.device(), dst_set.device());

match (
src_set
.layout()
.flags()
.intersects(DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL),
dst_set
.layout()
.flags()
.intersects(DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL),
) {
(true, false) => {
return Err(Box::new(ValidationError {
problem: "`src_set.layout().flags()` contains \
`DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL`, but \
`dst_set.layout().flags()` does not also contain it"
.into(),
vuids: &["VUID-VkCopyDescriptorSet-srcSet-01918"],
..Default::default()
}));
}
(false, true) => {
return Err(Box::new(ValidationError {
problem: "`src_set.layout().flags()` does not contain \
`DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL`, but \
`dst_set.layout().flags()` does contain it"
.into(),
vuids: &["VUID-VkCopyDescriptorSet-srcSet-04885"],
..Default::default()
}));
}
_ => (),
}

match (
src_set
.pool()
.flags()
.intersects(DescriptorPoolCreateFlags::UPDATE_AFTER_BIND),
dst_set
.pool()
.flags()
.intersects(DescriptorPoolCreateFlags::UPDATE_AFTER_BIND),
) {
(true, false) => {
return Err(Box::new(ValidationError {
problem: "`src_set.pool().flags()` contains \
`DescriptorPoolCreateFlags::UPDATE_AFTER_BIND`, but \
`dst_set.pool().flags()` does not also contain it"
.into(),
vuids: &["VUID-VkCopyDescriptorSet-srcSet-01920"],
..Default::default()
}));
}
(false, true) => {
return Err(Box::new(ValidationError {
problem: "`src_set.pool().flags()` does not contain \
`DescriptorPoolCreateFlags::UPDATE_AFTER_BIND`, but \
`dst_set.pool().flags()` does contain it"
.into(),
vuids: &["VUID-VkCopyDescriptorSet-srcSet-04887"],
..Default::default()
}));
}
_ => (),
}

let src_layout_binding = match src_set.layout().bindings().get(&src_binding) {
Some(layout_binding) => layout_binding,
Expand Down Expand Up @@ -1679,7 +1752,7 @@ impl CopyDescriptorSet {
}));
}

let dst_layout_binding = match dst_set_layout.bindings().get(&dst_binding) {
let dst_layout_binding = match dst_set.layout().bindings().get(&dst_binding) {
Some(layout_binding) => layout_binding,
None => {
return Err(Box::new(ValidationError {
Expand All @@ -1696,7 +1769,7 @@ impl CopyDescriptorSet {
.binding_flags
.intersects(DescriptorBindingFlags::VARIABLE_DESCRIPTOR_COUNT)
{
dst_set_variable_descriptor_count
dst_set.variable_descriptor_count()
} else {
dst_layout_binding.descriptor_count
};
Expand Down
Loading
Loading