mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-21 14:24:18 +00:00
Descriptor set revamp (#2404)
* Descriptor set revamp * Fix tests * Fix examples * Add `DescriptorSet::update_unchecked` * Fix docs * Add `Debug` impls * Add `DescriptorSet::update_by_ref[_unchecked]` * Rename `UnsafeDescriptorSet` to `RawDescriptorSet` * Fix outdated docs for `DescriptorPool`
This commit is contained in:
parent
6b951709e5
commit
63a53f1b93
@ -47,7 +47,7 @@ use vulkano::{
|
||||
PrimaryCommandBufferAbstract, RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, Queue,
|
||||
@ -486,7 +486,7 @@ fn main() -> Result<(), impl Error> {
|
||||
let uniform_buffer_sets = uniform_buffers
|
||||
.iter()
|
||||
.map(|buffer| {
|
||||
PersistentDescriptorSet::new(
|
||||
DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
pipeline.layout().set_layouts()[0].clone(),
|
||||
[WriteDescriptorSet::buffer(0, buffer.clone())],
|
||||
@ -499,7 +499,7 @@ fn main() -> Result<(), impl Error> {
|
||||
// Create the descriptor sets for sampling the textures.
|
||||
let sampler = Sampler::new(device.clone(), SamplerCreateInfo::simple_repeat_linear()).unwrap();
|
||||
let sampler_sets = textures.map(|texture| {
|
||||
PersistentDescriptorSet::new(
|
||||
DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
pipeline.layout().set_layouts()[1].clone(),
|
||||
[
|
||||
|
@ -11,7 +11,7 @@ use vulkano::{
|
||||
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -184,7 +184,7 @@ fn main() {
|
||||
// If you want to run the pipeline on multiple different buffers, you need to create multiple
|
||||
// descriptor sets that each contain the buffer you want to run the shader on.
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::buffer(0, data_buffer.clone())],
|
||||
|
@ -6,7 +6,7 @@ use vulkano::{
|
||||
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::Queue,
|
||||
image::view::ImageView,
|
||||
@ -168,7 +168,7 @@ impl AmbientLightingSystem {
|
||||
};
|
||||
|
||||
let layout = self.pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let descriptor_set = PersistentDescriptorSet::new(
|
||||
let descriptor_set = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::image_view(0, color_input)],
|
||||
|
@ -7,7 +7,7 @@ use vulkano::{
|
||||
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::Queue,
|
||||
image::view::ImageView,
|
||||
@ -179,7 +179,7 @@ impl DirectionalLightingSystem {
|
||||
};
|
||||
|
||||
let layout = self.pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let descriptor_set = PersistentDescriptorSet::new(
|
||||
let descriptor_set = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -7,7 +7,7 @@ use vulkano::{
|
||||
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::Queue,
|
||||
image::view::ImageView,
|
||||
@ -191,7 +191,7 @@ impl PointLightingSystem {
|
||||
};
|
||||
|
||||
let layout = self.pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let descriptor_set = PersistentDescriptorSet::new(
|
||||
let descriptor_set = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -12,7 +12,7 @@ use vulkano::{
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, layout::DescriptorType, DescriptorBufferInfo,
|
||||
DescriptorSet, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -212,7 +212,7 @@ fn main() {
|
||||
.unwrap();
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -12,7 +12,7 @@ use vulkano::{
|
||||
CopyImageToBufferInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -224,7 +224,7 @@ fn main() {
|
||||
let view = ImageView::new_default(image.clone()).unwrap();
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::image_view(0, view)],
|
||||
|
@ -24,7 +24,7 @@ mod linux {
|
||||
CommandBufferUsage, RenderPassBeginInfo, SemaphoreSubmitInfo, SubmitInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, Queue,
|
||||
@ -278,7 +278,7 @@ mod linux {
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -7,7 +7,7 @@ use vulkano::{
|
||||
CopyImageInfo, ImageBlit, ImageCopy, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -380,7 +380,7 @@ fn main() -> Result<(), impl Error> {
|
||||
};
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -6,7 +6,7 @@ use vulkano::{
|
||||
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -328,7 +328,7 @@ fn main() -> Result<(), impl Error> {
|
||||
};
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -15,7 +15,7 @@ use vulkano::{
|
||||
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -349,7 +349,7 @@ fn main() -> Result<(), impl Error> {
|
||||
|
||||
// Use `image_view` instead of `image_view_sampler`, since the sampler is already in the
|
||||
// layout.
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::image_view(1, texture)],
|
||||
|
@ -25,7 +25,7 @@ use vulkano::{
|
||||
DrawIndirectCommand, RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -454,7 +454,7 @@ fn main() -> Result<(), impl Error> {
|
||||
|
||||
// Pass the two buffers to the compute shader.
|
||||
let layout = compute_pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let cs_desciptor_set = PersistentDescriptorSet::new(
|
||||
let cs_desciptor_set = DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -8,7 +8,7 @@ use vulkano::{
|
||||
PrimaryCommandBufferAbstract,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::Queue,
|
||||
image::view::ImageView,
|
||||
@ -138,7 +138,7 @@ impl FractalComputePipeline {
|
||||
let image_extent = image_view.image().extent();
|
||||
let pipeline_layout = self.pipeline.layout();
|
||||
let desc_layout = pipeline_layout.set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
desc_layout.clone(),
|
||||
[
|
||||
|
@ -6,7 +6,7 @@ use vulkano::{
|
||||
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::Queue,
|
||||
image::{
|
||||
@ -172,7 +172,7 @@ impl PixelsDrawPipeline {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_descriptor_set(&self, image: Arc<ImageView>) -> Arc<PersistentDescriptorSet> {
|
||||
fn create_descriptor_set(&self, image: Arc<ImageView>) -> Arc<DescriptorSet> {
|
||||
let layout = self.pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let sampler = Sampler::new(
|
||||
self.gfx_queue.device().clone(),
|
||||
@ -186,7 +186,7 @@ impl PixelsDrawPipeline {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
PersistentDescriptorSet::new(
|
||||
DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -9,7 +9,7 @@ use vulkano::{
|
||||
PrimaryAutoCommandBuffer,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::Queue,
|
||||
format::Format,
|
||||
@ -173,7 +173,7 @@ impl GameOfLifeComputePipeline {
|
||||
let image_extent = self.image.image().extent();
|
||||
let pipeline_layout = self.compute_life_pipeline.layout();
|
||||
let desc_layout = pipeline_layout.set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
desc_layout.clone(),
|
||||
[
|
||||
|
@ -7,7 +7,7 @@ use vulkano::{
|
||||
CommandBufferInheritanceInfo, CommandBufferUsage, SecondaryAutoCommandBuffer,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::Queue,
|
||||
image::{
|
||||
@ -168,7 +168,7 @@ impl PixelsDrawPipeline {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_image_sampler_nearest(&self, image: Arc<ImageView>) -> Arc<PersistentDescriptorSet> {
|
||||
fn create_image_sampler_nearest(&self, image: Arc<ImageView>) -> Arc<DescriptorSet> {
|
||||
let layout = self.pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let sampler = Sampler::new(
|
||||
self.gfx_queue.device().clone(),
|
||||
@ -182,7 +182,7 @@ impl PixelsDrawPipeline {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
PersistentDescriptorSet::new(
|
||||
DescriptorSet::new(
|
||||
self.descriptor_set_allocator.clone(),
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -10,7 +10,7 @@ use vulkano::{
|
||||
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -156,7 +156,7 @@ fn main() {
|
||||
.unwrap();
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::buffer(0, data_buffer.clone())],
|
||||
|
@ -6,8 +6,8 @@ use vulkano::{
|
||||
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, layout::DescriptorBindingFlags,
|
||||
PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, layout::DescriptorBindingFlags, DescriptorSet,
|
||||
WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, Features,
|
||||
@ -448,7 +448,7 @@ fn main() -> Result<(), impl Error> {
|
||||
};
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new_variable(
|
||||
let set = DescriptorSet::new_variable(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
2,
|
||||
|
@ -10,7 +10,7 @@ use vulkano::{
|
||||
CommandBufferUsage, CopyBufferInfoTyped,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -152,7 +152,7 @@ fn main() {
|
||||
.unwrap();
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::buffer(0, data_buffer.clone())],
|
||||
|
@ -9,7 +9,7 @@ use vulkano::{
|
||||
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -156,7 +156,7 @@ fn main() {
|
||||
.unwrap();
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::buffer(0, data_buffer.clone())],
|
||||
|
@ -23,7 +23,7 @@ use vulkano::{
|
||||
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, Queue,
|
||||
@ -184,7 +184,7 @@ fn main() {
|
||||
descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
) {
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::buffer(0, data_buffer)],
|
||||
|
@ -11,7 +11,7 @@ use vulkano::{
|
||||
CopyBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -432,7 +432,7 @@ fn main() -> Result<(), impl Error> {
|
||||
|
||||
// Create a new descriptor set for binding vertices as a storage buffer.
|
||||
use vulkano::pipeline::Pipeline; // Required to access the `layout` method of pipeline.
|
||||
let descriptor_set = PersistentDescriptorSet::new(
|
||||
let descriptor_set = DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
compute_pipeline
|
||||
.layout()
|
||||
|
@ -7,7 +7,7 @@ use vulkano::{
|
||||
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -157,7 +157,7 @@ fn main() {
|
||||
.unwrap();
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::buffer(0, data_buffer.clone())],
|
||||
|
@ -11,7 +11,7 @@ use vulkano::{
|
||||
RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, DeviceOwned,
|
||||
@ -341,7 +341,7 @@ fn main() -> Result<(), impl Error> {
|
||||
};
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
layout.clone(),
|
||||
[WriteDescriptorSet::buffer(0, uniform_buffer_subbuffer)],
|
||||
|
@ -6,7 +6,7 @@ use vulkano::{
|
||||
CopyBufferToImageInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{
|
||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
||||
@ -339,7 +339,7 @@ fn main() -> Result<(), impl Error> {
|
||||
};
|
||||
|
||||
let layout = pipeline.layout().set_layouts().get(0).unwrap();
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
descriptor_set_allocator,
|
||||
layout.clone(),
|
||||
[
|
||||
|
@ -39,7 +39,7 @@ use crate::{
|
||||
DeviceSize, Validated, ValidationError, VulkanError,
|
||||
};
|
||||
use ahash::HashMap;
|
||||
use parking_lot::Mutex;
|
||||
use parking_lot::{Mutex, RwLockReadGuard};
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
collections::hash_map::Entry,
|
||||
@ -1730,10 +1730,10 @@ pub(in crate::command_buffer) enum SetOrPush {
|
||||
}
|
||||
|
||||
impl SetOrPush {
|
||||
pub(in crate::command_buffer) fn resources(&self) -> &DescriptorSetResources {
|
||||
pub(in crate::command_buffer) fn resources(&self) -> SetOrPushResources<'_> {
|
||||
match self {
|
||||
Self::Set(set) => set.as_ref().0.resources(),
|
||||
Self::Push(resources) => resources,
|
||||
Self::Set(set) => SetOrPushResources::Set(set.as_ref().0.resources()),
|
||||
Self::Push(resources) => SetOrPushResources::Push(resources),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1746,6 +1746,22 @@ impl SetOrPush {
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::command_buffer) enum SetOrPushResources<'a> {
|
||||
Set(RwLockReadGuard<'a, DescriptorSetResources>),
|
||||
Push(&'a DescriptorSetResources),
|
||||
}
|
||||
|
||||
impl std::ops::Deref for SetOrPushResources<'_> {
|
||||
type Target = DescriptorSetResources;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
Self::Set(guard) => guard,
|
||||
Self::Push(r) => r,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub(in crate::command_buffer) struct StencilStateDynamic {
|
||||
pub(in crate::command_buffer) front: Option<u32>,
|
||||
|
@ -326,7 +326,7 @@ mod tests {
|
||||
DescriptorSetLayout, DescriptorSetLayoutBinding, DescriptorSetLayoutCreateInfo,
|
||||
DescriptorType,
|
||||
},
|
||||
PersistentDescriptorSet, WriteDescriptorSet,
|
||||
DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
device::{Device, DeviceCreateInfo, QueueCreateInfo},
|
||||
image::sampler::{Sampler, SamplerCreateInfo},
|
||||
@ -785,7 +785,7 @@ mod tests {
|
||||
Default::default(),
|
||||
));
|
||||
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
ds_allocator.clone(),
|
||||
set_layout.clone(),
|
||||
[WriteDescriptorSet::sampler(
|
||||
@ -856,8 +856,8 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let set = PersistentDescriptorSet::new(
|
||||
ds_allocator.clone(),
|
||||
let set = DescriptorSet::new(
|
||||
ds_allocator,
|
||||
set_layout,
|
||||
[WriteDescriptorSet::sampler(
|
||||
0,
|
||||
|
@ -582,7 +582,8 @@ where
|
||||
let dynamic_offsets = &dynamic_offsets_remaining[..split_index];
|
||||
dynamic_offsets_remaining = &dynamic_offsets_remaining[split_index..];
|
||||
|
||||
let elements = match set.resources().binding(binding_num) {
|
||||
let resources = set.resources();
|
||||
let elements = match resources.binding(binding_num) {
|
||||
Some(DescriptorBindingResources::Buffer(elements)) => elements.as_slice(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
@ -1279,28 +1279,29 @@ where
|
||||
{
|
||||
// Check sampler-image compatibility. Only done for separate samplers;
|
||||
// combined image samplers are checked when updating the descriptor set.
|
||||
|
||||
// If the image view isn't actually present in the resources, then just skip it.
|
||||
// It will be caught later by check_resources.
|
||||
let iter = desc_reqs.sampler_with_images.iter().filter_map(|id| {
|
||||
descriptor_set_state
|
||||
.descriptor_sets
|
||||
.get(&id.set)
|
||||
.and_then(|set| set.resources().binding(id.binding))
|
||||
.and_then(|res| match res {
|
||||
DescriptorBindingResources::ImageView(elements) => elements
|
||||
.get(id.index as usize)
|
||||
.and_then(|opt| opt.as_ref().map(|opt| (id, opt))),
|
||||
_ => None,
|
||||
})
|
||||
});
|
||||
|
||||
for (id, image_view_info) in iter {
|
||||
for id in &desc_reqs.sampler_with_images {
|
||||
let DescriptorIdentifier {
|
||||
set: iset_num,
|
||||
binding: ibinding_num,
|
||||
index: iindex,
|
||||
} = id;
|
||||
|
||||
// If the image view isn't actually present in the resources, then just
|
||||
// skip it. It will be caught later by check_resources.
|
||||
let Some(set) = descriptor_set_state.descriptor_sets.get(iset_num)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let resources = set.resources();
|
||||
let Some(DescriptorBindingResources::ImageView(elements)) =
|
||||
resources.binding(*ibinding_num)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let Some(Some(image_view_info)) = elements.get(*iindex as usize) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let DescriptorImageViewInfo {
|
||||
image_view,
|
||||
image_layout: _,
|
||||
|
@ -23,7 +23,7 @@
|
||||
//!
|
||||
//! ## Creating a descriptor set
|
||||
//!
|
||||
//! TODO: write example for: PersistentDescriptorSet::start(layout.clone()).add_buffer(data_buffer.clone())
|
||||
//! TODO: write
|
||||
//!
|
||||
//! ## Passing the descriptor set when drawing
|
||||
//!
|
||||
@ -31,9 +31,8 @@
|
||||
//!
|
||||
//! # When drawing
|
||||
//!
|
||||
//! When you call a function that adds a draw command to a command buffer, one of the parameters
|
||||
//! corresponds to the list of descriptor sets to use. Vulkano will check that what you passed is
|
||||
//! compatible with the layout of the pipeline.
|
||||
//! When you call a function that adds a draw command to a command buffer, vulkano will check that
|
||||
//! the descriptor sets you bound are compatible with the layout of the pipeline.
|
||||
//!
|
||||
//! TODO: talk about perfs of changing sets
|
||||
//!
|
||||
@ -41,59 +40,60 @@
|
||||
//!
|
||||
//! There are three concepts in Vulkan related to descriptor sets:
|
||||
//!
|
||||
//! - A `DescriptorSetLayout` is a Vulkan object that describes to the Vulkan implementation the
|
||||
//! - A `VkDescriptorSetLayout` is a Vulkan object that describes to the Vulkan implementation the
|
||||
//! layout of a future descriptor set. When you allocate a descriptor set, you have to pass an
|
||||
//! instance of this object. This is represented with the [`DescriptorSetLayout`] type in
|
||||
//! vulkano.
|
||||
//! - A `DescriptorPool` is a Vulkan object that holds the memory of descriptor sets and that can
|
||||
//! - A `VkDescriptorPool` is a Vulkan object that holds the memory of descriptor sets and that can
|
||||
//! be used to allocate and free individual descriptor sets. This is represented with the
|
||||
//! [`DescriptorPool`] type in vulkano.
|
||||
//! - A `DescriptorSet` contains the bindings to resources and is allocated from a pool. This is
|
||||
//! represented with the [`UnsafeDescriptorSet`] type in vulkano.
|
||||
//! - A `VkDescriptorSet` contains the bindings to resources and is allocated from a pool. This is
|
||||
//! represented with the [`RawDescriptorSet`] type in vulkano.
|
||||
//!
|
||||
//! In addition to this, vulkano defines the following:
|
||||
//!
|
||||
//! - The [`DescriptorSetAllocator`] trait can be implemented on types from which you can allocate
|
||||
//! and free descriptor sets. However it is different from Vulkan descriptor pools in the sense
|
||||
//! that an implementation of the [`DescriptorSetAllocator`] trait can manage multiple Vulkan
|
||||
//! that an implementation of the `DescriptorSetAllocator` trait can manage multiple Vulkan
|
||||
//! descriptor pools.
|
||||
//! - The [`StandardDescriptorSetAllocator`] type is a default implementation of the
|
||||
//! [`DescriptorSetAllocator`] trait.
|
||||
//! - The [`DescriptorSet`] trait is implemented on types that wrap around Vulkan descriptor sets in
|
||||
//! a safe way. A Vulkan descriptor set is inherently unsafe, so we need safe wrappers around
|
||||
//! them.
|
||||
//! - The [`DescriptorSetsCollection`] trait is implemented on collections of types that implement
|
||||
//! [`DescriptorSet`]. It is what you pass to the draw functions.
|
||||
//! - The [`DescriptorSet`] type wraps around an `RawDescriptorSet` a safe way. A Vulkan descriptor
|
||||
//! set is inherently unsafe, so we need safe wrappers around them.
|
||||
//! - The [`DescriptorSetsCollection`] trait is implemented on collections of descriptor sets. It
|
||||
//! is what you pass to the bind function.
|
||||
//!
|
||||
//! [`DescriptorPool`]: pool::DescriptorPool
|
||||
//! [`UnsafeDescriptorSet`]: sys::UnsafeDescriptorSet
|
||||
//! [`RawDescriptorSet`]: sys::RawDescriptorSet
|
||||
//! [`DescriptorSetAllocator`]: allocator::DescriptorSetAllocator
|
||||
//! [`StandardDescriptorSetAllocator`]: allocator::StandardDescriptorSetAllocator
|
||||
|
||||
pub(crate) use self::update::DescriptorWriteInfo;
|
||||
use self::{
|
||||
allocator::DescriptorSetAllocator,
|
||||
layout::DescriptorSetLayout,
|
||||
pool::{DescriptorPool, DescriptorPoolAlloc},
|
||||
sys::RawDescriptorSet,
|
||||
};
|
||||
pub use self::{
|
||||
collection::DescriptorSetsCollection,
|
||||
persistent::PersistentDescriptorSet,
|
||||
update::{
|
||||
CopyDescriptorSet, DescriptorBufferInfo, DescriptorImageViewInfo, WriteDescriptorSet,
|
||||
WriteDescriptorSetElements,
|
||||
},
|
||||
};
|
||||
use self::{
|
||||
layout::DescriptorSetLayout,
|
||||
pool::{DescriptorPool, DescriptorPoolAlloc},
|
||||
};
|
||||
use crate::{
|
||||
acceleration_structure::AccelerationStructure,
|
||||
buffer::view::BufferView,
|
||||
descriptor_set::layout::{
|
||||
DescriptorBindingFlags, DescriptorSetLayoutCreateFlags, DescriptorType,
|
||||
},
|
||||
device::DeviceOwned,
|
||||
device::{Device, DeviceOwned},
|
||||
image::{sampler::Sampler, ImageLayout},
|
||||
VulkanObject,
|
||||
Validated, ValidationError, VulkanError, VulkanObject,
|
||||
};
|
||||
use ahash::HashMap;
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::{
|
||||
hash::{Hash, Hasher},
|
||||
@ -103,67 +103,225 @@ use std::{
|
||||
pub mod allocator;
|
||||
mod collection;
|
||||
pub mod layout;
|
||||
pub mod persistent;
|
||||
pub mod pool;
|
||||
pub mod sys;
|
||||
mod update;
|
||||
|
||||
/// Trait for objects that contain a collection of resources that will be accessible by shaders.
|
||||
/// An object that contains a collection of resources that will be accessible by shaders.
|
||||
///
|
||||
/// Objects of this type can be passed when submitting a draw command.
|
||||
pub unsafe trait DescriptorSet:
|
||||
VulkanObject<Handle = ash::vk::DescriptorSet> + DeviceOwned + Send + Sync
|
||||
{
|
||||
/// Descriptor sets can be bound when recording a command buffer.
|
||||
#[derive(Debug)]
|
||||
pub struct DescriptorSet {
|
||||
inner: RawDescriptorSet,
|
||||
resources: RwLock<DescriptorSetResources>,
|
||||
}
|
||||
|
||||
impl DescriptorSet {
|
||||
/// Creates and returns a new descriptor set with a variable descriptor count of 0.
|
||||
pub fn new(
|
||||
allocator: Arc<dyn DescriptorSetAllocator>,
|
||||
layout: Arc<DescriptorSetLayout>,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) -> Result<Arc<DescriptorSet>, Validated<VulkanError>> {
|
||||
Self::new_variable(allocator, layout, 0, descriptor_writes, descriptor_copies)
|
||||
}
|
||||
|
||||
/// Creates and returns a new descriptor set with the requested variable descriptor count.
|
||||
pub fn new_variable(
|
||||
allocator: Arc<dyn DescriptorSetAllocator>,
|
||||
layout: Arc<DescriptorSetLayout>,
|
||||
variable_descriptor_count: u32,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) -> Result<Arc<DescriptorSet>, Validated<VulkanError>> {
|
||||
let mut set = DescriptorSet {
|
||||
inner: RawDescriptorSet::new(allocator, &layout, variable_descriptor_count)?,
|
||||
resources: RwLock::new(DescriptorSetResources::new(
|
||||
&layout,
|
||||
variable_descriptor_count,
|
||||
)),
|
||||
};
|
||||
|
||||
set.update(descriptor_writes, descriptor_copies)?;
|
||||
|
||||
Ok(Arc::new(set))
|
||||
}
|
||||
|
||||
/// Returns the allocation of the descriptor set.
|
||||
fn alloc(&self) -> &DescriptorPoolAlloc;
|
||||
#[inline]
|
||||
pub fn alloc(&self) -> &DescriptorPoolAlloc {
|
||||
&self.inner.alloc().inner
|
||||
}
|
||||
|
||||
/// Returns the descriptor pool that the descriptor set was allocated from.
|
||||
fn pool(&self) -> &DescriptorPool;
|
||||
#[inline]
|
||||
pub fn pool(&self) -> &DescriptorPool {
|
||||
self.inner.pool()
|
||||
}
|
||||
|
||||
/// Returns the layout of this descriptor set.
|
||||
#[inline]
|
||||
fn layout(&self) -> &Arc<DescriptorSetLayout> {
|
||||
pub fn layout(&self) -> &Arc<DescriptorSetLayout> {
|
||||
self.alloc().layout()
|
||||
}
|
||||
|
||||
/// Returns the variable descriptor count that this descriptor set was allocated with.
|
||||
#[inline]
|
||||
fn variable_descriptor_count(&self) -> u32 {
|
||||
pub fn variable_descriptor_count(&self) -> u32 {
|
||||
self.alloc().variable_descriptor_count()
|
||||
}
|
||||
|
||||
/// Creates a [`DescriptorSetWithOffsets`] with the given dynamic offsets.
|
||||
fn offsets(
|
||||
pub fn offsets(
|
||||
self: Arc<Self>,
|
||||
dynamic_offsets: impl IntoIterator<Item = u32>,
|
||||
) -> DescriptorSetWithOffsets
|
||||
where
|
||||
Self: Sized + 'static,
|
||||
{
|
||||
) -> DescriptorSetWithOffsets {
|
||||
DescriptorSetWithOffsets::new(self, dynamic_offsets)
|
||||
}
|
||||
|
||||
/// Returns the resources bound to this descriptor set.
|
||||
fn resources(&self) -> &DescriptorSetResources;
|
||||
}
|
||||
|
||||
impl PartialEq for dyn DescriptorSet {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.alloc() == other.alloc()
|
||||
pub fn resources(&self) -> RwLockReadGuard<'_, DescriptorSetResources> {
|
||||
self.resources.read()
|
||||
}
|
||||
|
||||
/// Updates the descriptor set with new values.
|
||||
pub fn update(
|
||||
&mut self,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) -> Result<(), Box<ValidationError>> {
|
||||
let descriptor_writes: SmallVec<[_; 8]> = descriptor_writes.into_iter().collect();
|
||||
let descriptor_copies: SmallVec<[_; 8]> = descriptor_copies.into_iter().collect();
|
||||
|
||||
self.inner
|
||||
.validate_update(&descriptor_writes, &descriptor_copies)?;
|
||||
|
||||
unsafe {
|
||||
Self::update_inner(
|
||||
&self.inner,
|
||||
self.resources.get_mut(),
|
||||
&descriptor_writes,
|
||||
&descriptor_copies,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
|
||||
pub unsafe fn update_unchecked(
|
||||
&mut self,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) {
|
||||
let descriptor_writes: SmallVec<[_; 8]> = descriptor_writes.into_iter().collect();
|
||||
let descriptor_copies: SmallVec<[_; 8]> = descriptor_copies.into_iter().collect();
|
||||
|
||||
Self::update_inner(
|
||||
&self.inner,
|
||||
self.resources.get_mut(),
|
||||
&descriptor_writes,
|
||||
&descriptor_copies,
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the descriptor set with new values.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - Host access to the descriptor set must be externally synchronized.
|
||||
pub unsafe fn update_by_ref(
|
||||
&self,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) -> Result<(), Box<ValidationError>> {
|
||||
let descriptor_writes: SmallVec<[_; 8]> = descriptor_writes.into_iter().collect();
|
||||
let descriptor_copies: SmallVec<[_; 8]> = descriptor_copies.into_iter().collect();
|
||||
|
||||
self.inner
|
||||
.validate_update(&descriptor_writes, &descriptor_copies)?;
|
||||
|
||||
Self::update_inner(
|
||||
&self.inner,
|
||||
&mut self.resources.write(),
|
||||
&descriptor_writes,
|
||||
&descriptor_copies,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
|
||||
pub unsafe fn update_by_ref_unchecked(
|
||||
&self,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) {
|
||||
let descriptor_writes: SmallVec<[_; 8]> = descriptor_writes.into_iter().collect();
|
||||
let descriptor_copies: SmallVec<[_; 8]> = descriptor_copies.into_iter().collect();
|
||||
|
||||
Self::update_inner(
|
||||
&self.inner,
|
||||
&mut self.resources.write(),
|
||||
&descriptor_writes,
|
||||
&descriptor_copies,
|
||||
);
|
||||
}
|
||||
|
||||
unsafe fn update_inner(
|
||||
inner: &RawDescriptorSet,
|
||||
resources: &mut DescriptorSetResources,
|
||||
descriptor_writes: &[WriteDescriptorSet],
|
||||
descriptor_copies: &[CopyDescriptorSet],
|
||||
) {
|
||||
inner.update_unchecked(descriptor_writes, descriptor_copies);
|
||||
|
||||
for write in descriptor_writes {
|
||||
resources.write(write, inner.layout());
|
||||
}
|
||||
|
||||
for copy in descriptor_copies {
|
||||
resources.copy(copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for dyn DescriptorSet {}
|
||||
unsafe impl VulkanObject for DescriptorSet {
|
||||
type Handle = ash::vk::DescriptorSet;
|
||||
|
||||
impl Hash for dyn DescriptorSet {
|
||||
#[inline]
|
||||
fn handle(&self) -> Self::Handle {
|
||||
self.inner.handle()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl DeviceOwned for DescriptorSet {
|
||||
#[inline]
|
||||
fn device(&self) -> &Arc<Device> {
|
||||
self.inner.device()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for DescriptorSet {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.inner == other.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for DescriptorSet {}
|
||||
|
||||
impl Hash for DescriptorSet {
|
||||
#[inline]
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.alloc().hash(state);
|
||||
self.inner.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
/// The resources that are bound to a descriptor set.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DescriptorSetResources {
|
||||
binding_resources: HashMap<u32, DescriptorBindingResources>,
|
||||
}
|
||||
@ -262,9 +420,8 @@ impl DescriptorSetResources {
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn copy(&mut self, copy: &CopyDescriptorSet) {
|
||||
let src = copy
|
||||
.src_set
|
||||
.resources()
|
||||
let resources = copy.src_set.resources();
|
||||
let src = resources
|
||||
.binding_resources
|
||||
.get(©.src_binding)
|
||||
.expect("descriptor copy has invalid src_binding number");
|
||||
@ -281,7 +438,7 @@ impl DescriptorSetResources {
|
||||
}
|
||||
|
||||
/// The resources that are bound to a single descriptor set binding.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum DescriptorBindingResources {
|
||||
None(Elements<()>),
|
||||
Buffer(Elements<DescriptorBufferInfo>),
|
||||
@ -471,13 +628,13 @@ impl DescriptorBindingResources {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DescriptorSetWithOffsets {
|
||||
descriptor_set: Arc<dyn DescriptorSet>,
|
||||
descriptor_set: Arc<DescriptorSet>,
|
||||
dynamic_offsets: SmallVec<[u32; 4]>,
|
||||
}
|
||||
|
||||
impl DescriptorSetWithOffsets {
|
||||
pub fn new(
|
||||
descriptor_set: Arc<dyn DescriptorSet>,
|
||||
descriptor_set: Arc<DescriptorSet>,
|
||||
dynamic_offsets: impl IntoIterator<Item = u32>,
|
||||
) -> Self {
|
||||
Self {
|
||||
@ -487,21 +644,19 @@ impl DescriptorSetWithOffsets {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_ref(&self) -> (&Arc<dyn DescriptorSet>, &[u32]) {
|
||||
pub fn as_ref(&self) -> (&Arc<DescriptorSet>, &[u32]) {
|
||||
(&self.descriptor_set, &self.dynamic_offsets)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_tuple(self) -> (Arc<dyn DescriptorSet>, impl ExactSizeIterator<Item = u32>) {
|
||||
pub fn into_tuple(self) -> (Arc<DescriptorSet>, impl ExactSizeIterator<Item = u32>) {
|
||||
(self.descriptor_set, self.dynamic_offsets.into_iter())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> From<Arc<S>> for DescriptorSetWithOffsets
|
||||
where
|
||||
S: DescriptorSet + 'static,
|
||||
{
|
||||
fn from(descriptor_set: Arc<S>) -> Self {
|
||||
impl From<Arc<DescriptorSet>> for DescriptorSetWithOffsets {
|
||||
#[inline]
|
||||
fn from(descriptor_set: Arc<DescriptorSet>) -> Self {
|
||||
DescriptorSetWithOffsets::new(descriptor_set, std::iter::empty())
|
||||
}
|
||||
}
|
||||
|
@ -1,151 +0,0 @@
|
||||
//! A simple, immutable descriptor set that is expected to be long-lived.
|
||||
//!
|
||||
//! Creating a persistent descriptor set allocates from a pool, and can't be modified once created.
|
||||
//! You are therefore encouraged to create them at initialization and not the during
|
||||
//! performance-critical paths.
|
||||
//!
|
||||
//! > **Note**: You can control of the pool that is used to create the descriptor set, if you wish
|
||||
//! > so. By creating a implementation of the `DescriptorPool` trait that doesn't perform any
|
||||
//! > actual allocation, you can skip this allocation and make it acceptable to use a persistent
|
||||
//! > descriptor set in performance-critical paths..
|
||||
//!
|
||||
//! # Examples
|
||||
//! TODO:
|
||||
|
||||
use super::{
|
||||
pool::{DescriptorPool, DescriptorPoolAlloc},
|
||||
sys::UnsafeDescriptorSet,
|
||||
CopyDescriptorSet,
|
||||
};
|
||||
use crate::{
|
||||
descriptor_set::{
|
||||
allocator::DescriptorSetAllocator, update::WriteDescriptorSet, DescriptorSet,
|
||||
DescriptorSetLayout, DescriptorSetResources,
|
||||
},
|
||||
device::{Device, DeviceOwned},
|
||||
Validated, ValidationError, VulkanError, VulkanObject,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
hash::{Hash, Hasher},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
/// A simple, immutable descriptor set that is expected to be long-lived.
|
||||
pub struct PersistentDescriptorSet {
|
||||
inner: UnsafeDescriptorSet,
|
||||
resources: DescriptorSetResources,
|
||||
}
|
||||
|
||||
impl PersistentDescriptorSet {
|
||||
/// Creates and returns a new descriptor set with a variable descriptor count of 0.
|
||||
///
|
||||
/// See `new_with_pool` for more.
|
||||
#[inline]
|
||||
pub fn new(
|
||||
allocator: Arc<dyn DescriptorSetAllocator>,
|
||||
layout: Arc<DescriptorSetLayout>,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) -> Result<Arc<PersistentDescriptorSet>, Validated<VulkanError>> {
|
||||
Self::new_variable(allocator, layout, 0, descriptor_writes, descriptor_copies)
|
||||
}
|
||||
|
||||
/// Creates and returns a new descriptor set with the requested variable descriptor count,
|
||||
/// allocating it from the provided pool.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - Panics if `layout` was created for push descriptors rather than descriptor sets.
|
||||
/// - Panics if `variable_descriptor_count` is too large for the given `layout`.
|
||||
pub fn new_variable(
|
||||
allocator: Arc<dyn DescriptorSetAllocator>,
|
||||
layout: Arc<DescriptorSetLayout>,
|
||||
variable_descriptor_count: u32,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) -> Result<Arc<PersistentDescriptorSet>, Validated<VulkanError>> {
|
||||
let mut set = PersistentDescriptorSet {
|
||||
inner: UnsafeDescriptorSet::new(allocator, &layout, variable_descriptor_count)?,
|
||||
resources: DescriptorSetResources::new(&layout, variable_descriptor_count),
|
||||
};
|
||||
|
||||
unsafe {
|
||||
set.update(descriptor_writes, descriptor_copies)?;
|
||||
}
|
||||
|
||||
Ok(Arc::new(set))
|
||||
}
|
||||
|
||||
unsafe fn update(
|
||||
&mut self,
|
||||
descriptor_writes: impl IntoIterator<Item = WriteDescriptorSet>,
|
||||
descriptor_copies: impl IntoIterator<Item = CopyDescriptorSet>,
|
||||
) -> Result<(), Box<ValidationError>> {
|
||||
let descriptor_writes: SmallVec<[_; 8]> = descriptor_writes.into_iter().collect();
|
||||
let descriptor_copies: SmallVec<[_; 8]> = descriptor_copies.into_iter().collect();
|
||||
|
||||
unsafe {
|
||||
self.inner.update(&descriptor_writes, &descriptor_copies)?;
|
||||
}
|
||||
|
||||
for write in descriptor_writes {
|
||||
self.resources.write(&write, self.inner.layout());
|
||||
}
|
||||
|
||||
for copy in descriptor_copies {
|
||||
self.resources.copy(©);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl DescriptorSet for PersistentDescriptorSet {
|
||||
#[inline]
|
||||
fn alloc(&self) -> &DescriptorPoolAlloc {
|
||||
&self.inner.alloc().inner
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pool(&self) -> &DescriptorPool {
|
||||
&self.inner.alloc().pool
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn resources(&self) -> &DescriptorSetResources {
|
||||
&self.resources
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl VulkanObject for PersistentDescriptorSet {
|
||||
type Handle = ash::vk::DescriptorSet;
|
||||
|
||||
#[inline]
|
||||
fn handle(&self) -> Self::Handle {
|
||||
self.inner.handle()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl DeviceOwned for PersistentDescriptorSet {
|
||||
#[inline]
|
||||
fn device(&self) -> &Arc<Device> {
|
||||
self.layout().device()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for PersistentDescriptorSet {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.inner == other.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for PersistentDescriptorSet {}
|
||||
|
||||
impl Hash for PersistentDescriptorSet {
|
||||
#[inline]
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.inner.hash(state);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
descriptor_set::{
|
||||
layout::{DescriptorSetLayout, DescriptorSetLayoutCreateFlags, DescriptorType},
|
||||
sys::UnsafeDescriptorSet,
|
||||
sys::RawDescriptorSet,
|
||||
},
|
||||
device::{Device, DeviceOwned, DeviceOwnedDebugWrapper},
|
||||
instance::InstanceOwnedDebugWrapper,
|
||||
@ -345,7 +345,7 @@ impl DescriptorPool {
|
||||
#[inline]
|
||||
pub unsafe fn free_descriptor_sets(
|
||||
&self,
|
||||
descriptor_sets: impl IntoIterator<Item = UnsafeDescriptorSet>,
|
||||
descriptor_sets: impl IntoIterator<Item = RawDescriptorSet>,
|
||||
) -> Result<(), Validated<VulkanError>> {
|
||||
self.validate_free_descriptor_sets()?;
|
||||
|
||||
@ -371,7 +371,7 @@ impl DescriptorPool {
|
||||
#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
|
||||
pub unsafe fn free_descriptor_sets_unchecked(
|
||||
&self,
|
||||
descriptor_sets: impl IntoIterator<Item = UnsafeDescriptorSet>,
|
||||
descriptor_sets: impl IntoIterator<Item = RawDescriptorSet>,
|
||||
) -> Result<(), VulkanError> {
|
||||
let sets: SmallVec<[_; 8]> = descriptor_sets.into_iter().map(|s| s.handle()).collect();
|
||||
if !sets.is_empty() {
|
||||
@ -440,7 +440,7 @@ unsafe impl DeviceOwned for DescriptorPool {
|
||||
|
||||
impl_id_counter!(DescriptorPool);
|
||||
|
||||
/// Parameters to create a new `UnsafeDescriptorPool`.
|
||||
/// Parameters to create a new `DescriptorPool`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DescriptorPoolCreateInfo {
|
||||
/// Additional properties of the descriptor pool.
|
||||
@ -598,7 +598,7 @@ vulkan_bitflags! {
|
||||
]), */
|
||||
}
|
||||
|
||||
/// Parameters to allocate a new `UnsafeDescriptorSet` from an `UnsafeDescriptorPool`.
|
||||
/// Parameters to allocate a new `DescriptorPoolAlloc` from a `DescriptorPool`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DescriptorSetAllocateInfo {
|
||||
/// The descriptor set layout to create the set for.
|
||||
|
@ -21,27 +21,27 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
/// Low-level descriptor set.
|
||||
/// A raw descriptor set corresponding directly to a `VkDescriptorSet`.
|
||||
///
|
||||
/// This descriptor set does not keep track of synchronization,
|
||||
/// nor does it store any information on what resources have been written to each descriptor.
|
||||
/// This descriptor set does not keep track of synchronization, nor does it store any information
|
||||
/// on what resources have been written to each descriptor.
|
||||
#[derive(Debug)]
|
||||
pub struct UnsafeDescriptorSet {
|
||||
pub struct RawDescriptorSet {
|
||||
allocation: ManuallyDrop<DescriptorSetAlloc>,
|
||||
allocator: Arc<dyn DescriptorSetAllocator>,
|
||||
}
|
||||
|
||||
impl UnsafeDescriptorSet {
|
||||
impl RawDescriptorSet {
|
||||
/// Allocates a new descriptor set and returns it.
|
||||
#[inline]
|
||||
pub fn new(
|
||||
allocator: Arc<dyn DescriptorSetAllocator>,
|
||||
layout: &Arc<DescriptorSetLayout>,
|
||||
variable_descriptor_count: u32,
|
||||
) -> Result<UnsafeDescriptorSet, Validated<VulkanError>> {
|
||||
) -> Result<RawDescriptorSet, Validated<VulkanError>> {
|
||||
let allocation = allocator.allocate(layout, variable_descriptor_count)?;
|
||||
|
||||
Ok(UnsafeDescriptorSet {
|
||||
Ok(RawDescriptorSet {
|
||||
allocation: ManuallyDrop::new(allocation),
|
||||
allocator,
|
||||
})
|
||||
@ -77,11 +77,12 @@ impl UnsafeDescriptorSet {
|
||||
///
|
||||
/// - The resources in `descriptor_writes` and `descriptor_copies` must be kept alive for as
|
||||
/// long as `self` is in use.
|
||||
/// - The descriptor set must not be in use by the device,
|
||||
/// or be recorded to a command buffer as part of a bind command.
|
||||
/// - The descriptor set must not be in use by the device, or be recorded to a command buffer
|
||||
/// as part of a bind command.
|
||||
/// - Host access to the descriptor set must be externally synchronized.
|
||||
#[inline]
|
||||
pub unsafe fn update(
|
||||
&mut self,
|
||||
&self,
|
||||
descriptor_writes: &[WriteDescriptorSet],
|
||||
descriptor_copies: &[CopyDescriptorSet],
|
||||
) -> Result<(), Box<ValidationError>> {
|
||||
@ -91,7 +92,7 @@ impl UnsafeDescriptorSet {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_update(
|
||||
pub(super) fn validate_update(
|
||||
&self,
|
||||
descriptor_writes: &[WriteDescriptorSet],
|
||||
descriptor_copies: &[CopyDescriptorSet],
|
||||
@ -112,7 +113,7 @@ impl UnsafeDescriptorSet {
|
||||
|
||||
#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
|
||||
pub unsafe fn update_unchecked(
|
||||
&mut self,
|
||||
&self,
|
||||
descriptor_writes: &[WriteDescriptorSet],
|
||||
descriptor_copies: &[CopyDescriptorSet],
|
||||
) {
|
||||
@ -206,7 +207,7 @@ impl UnsafeDescriptorSet {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for UnsafeDescriptorSet {
|
||||
impl Drop for RawDescriptorSet {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
let allocation = unsafe { ManuallyDrop::take(&mut self.allocation) };
|
||||
@ -214,7 +215,7 @@ impl Drop for UnsafeDescriptorSet {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl VulkanObject for UnsafeDescriptorSet {
|
||||
unsafe impl VulkanObject for RawDescriptorSet {
|
||||
type Handle = ash::vk::DescriptorSet;
|
||||
|
||||
#[inline]
|
||||
@ -223,23 +224,23 @@ unsafe impl VulkanObject for UnsafeDescriptorSet {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl DeviceOwned for UnsafeDescriptorSet {
|
||||
unsafe impl DeviceOwned for RawDescriptorSet {
|
||||
#[inline]
|
||||
fn device(&self) -> &Arc<Device> {
|
||||
self.allocation.inner.device()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for UnsafeDescriptorSet {
|
||||
impl PartialEq for RawDescriptorSet {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.allocation.inner == other.allocation.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for UnsafeDescriptorSet {}
|
||||
impl Eq for RawDescriptorSet {}
|
||||
|
||||
impl Hash for UnsafeDescriptorSet {
|
||||
impl Hash for RawDescriptorSet {
|
||||
#[inline]
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.allocation.inner.hash(state);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{
|
||||
layout::{DescriptorSetLayout, DescriptorType},
|
||||
sys::UnsafeDescriptorSet,
|
||||
sys::RawDescriptorSet,
|
||||
DescriptorSet,
|
||||
};
|
||||
use crate::{
|
||||
@ -1581,7 +1581,7 @@ pub struct CopyDescriptorSet {
|
||||
/// The source descriptor set to copy from.
|
||||
///
|
||||
/// There is no default value.
|
||||
pub src_set: Arc<dyn DescriptorSet>,
|
||||
pub src_set: Arc<DescriptorSet>,
|
||||
|
||||
/// The binding number in the source descriptor set to copy from.
|
||||
///
|
||||
@ -1612,7 +1612,7 @@ pub struct CopyDescriptorSet {
|
||||
impl CopyDescriptorSet {
|
||||
/// Returns a `CopyDescriptorSet` with the specified `src_set`.
|
||||
#[inline]
|
||||
pub fn new(src_set: Arc<dyn DescriptorSet>) -> Self {
|
||||
pub fn new(src_set: Arc<DescriptorSet>) -> Self {
|
||||
Self {
|
||||
src_set,
|
||||
src_binding: 0,
|
||||
@ -1624,10 +1624,7 @@ impl CopyDescriptorSet {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn validate(
|
||||
&self,
|
||||
dst_set: &UnsafeDescriptorSet,
|
||||
) -> Result<(), Box<ValidationError>> {
|
||||
pub(crate) fn validate(&self, dst_set: &RawDescriptorSet) -> Result<(), Box<ValidationError>> {
|
||||
let &Self {
|
||||
ref src_set,
|
||||
src_binding,
|
||||
|
@ -20,7 +20,7 @@
|
||||
//! DescriptorSetLayout, DescriptorSetLayoutBinding, DescriptorSetLayoutCreateInfo,
|
||||
//! DescriptorType,
|
||||
//! },
|
||||
//! PersistentDescriptorSet, WriteDescriptorSet,
|
||||
//! DescriptorSet, WriteDescriptorSet,
|
||||
//! },
|
||||
//! format::Format,
|
||||
//! image::{
|
||||
@ -99,7 +99,7 @@
|
||||
//! };
|
||||
//! let image_view = ImageView::new(image, create_info).unwrap();
|
||||
//!
|
||||
//! let descriptor_set = PersistentDescriptorSet::new(
|
||||
//! let descriptor_set = DescriptorSet::new(
|
||||
//! descriptor_set_allocator.clone(),
|
||||
//! descriptor_set_layout.clone(),
|
||||
//! [WriteDescriptorSet::image_view(0, image_view)],
|
||||
|
@ -448,7 +448,7 @@ mod tests {
|
||||
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
|
||||
},
|
||||
descriptor_set::{
|
||||
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||
allocator::StandardDescriptorSetAllocator, DescriptorSet, WriteDescriptorSet,
|
||||
},
|
||||
memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator},
|
||||
pipeline::{
|
||||
@ -544,7 +544,7 @@ mod tests {
|
||||
device.clone(),
|
||||
Default::default(),
|
||||
));
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
ds_allocator,
|
||||
pipeline.layout().set_layouts().get(0).unwrap().clone(),
|
||||
[WriteDescriptorSet::buffer(0, data_buffer.clone())],
|
||||
@ -688,7 +688,7 @@ mod tests {
|
||||
device.clone(),
|
||||
Default::default(),
|
||||
));
|
||||
let set = PersistentDescriptorSet::new(
|
||||
let set = DescriptorSet::new(
|
||||
ds_allocator,
|
||||
pipeline.layout().set_layouts().get(0).unwrap().clone(),
|
||||
[WriteDescriptorSet::buffer(0, data_buffer.clone())],
|
||||
|
Loading…
Reference in New Issue
Block a user