From c8ad5a45120ad244ee6ec0f8de0fa725158054b7 Mon Sep 17 00:00:00 2001 From: Rua Date: Fri, 25 Aug 2023 21:15:23 +0200 Subject: [PATCH] Fix erroneous used range for buffers in descriptor sets (#2303) * Fix erroneous used range for buffers in descriptor sets * Fix mistake resulting from an error in the spec that was just fixed --- vulkano/src/command_buffer/auto/builder.rs | 17 +++++++++++++++-- vulkano/src/command_buffer/auto/mod.rs | 2 +- vulkano/src/command_buffer/commands/pipeline.rs | 16 ++++------------ vulkano/src/sync/pipeline.rs | 3 +-- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/vulkano/src/command_buffer/auto/builder.rs b/vulkano/src/command_buffer/auto/builder.rs index c7b44561..19492cd9 100644 --- a/vulkano/src/command_buffer/auto/builder.rs +++ b/vulkano/src/command_buffer/auto/builder.rs @@ -680,6 +680,9 @@ impl AutoSyncState { ref range, memory_access, } => { + debug_assert!(range.start <= range.end); + debug_assert!(range.end <= buffer.size()); + if let Some(previous_use_ref) = self.find_buffer_conflict( self.command_index, buffer, @@ -704,6 +707,16 @@ impl AutoSyncState { start_layout, end_layout, } => { + debug_assert!(image.format().aspects().contains(subresource_range.aspects)); + debug_assert!( + subresource_range.mip_levels.start <= subresource_range.mip_levels.end + ); + debug_assert!(subresource_range.mip_levels.end <= image.mip_levels()); + debug_assert!( + subresource_range.array_layers.start <= subresource_range.array_layers.end + ); + debug_assert!(subresource_range.array_layers.end <= image.array_layers()); + debug_assert!(memory_access.contains_write() || start_layout == end_layout); debug_assert!(end_layout != ImageLayout::Undefined); debug_assert!(end_layout != ImageLayout::Preinitialized); @@ -1267,7 +1280,7 @@ struct UnsolvableResourceConflict { } // State of a resource during the building of the command buffer. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] struct BufferState { // Lists every use of the resource. resource_uses: Vec, @@ -1281,7 +1294,7 @@ struct BufferState { } // State of a resource during the building of the command buffer. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] struct ImageState { // Lists every use of the resource. resource_uses: Vec, diff --git a/vulkano/src/command_buffer/auto/mod.rs b/vulkano/src/command_buffer/auto/mod.rs index e62777c4..d7058bd7 100644 --- a/vulkano/src/command_buffer/auto/mod.rs +++ b/vulkano/src/command_buffer/auto/mod.rs @@ -281,7 +281,7 @@ impl From for ResourceUseRef2 { } /// Type of resource whose state is to be tracked. -#[derive(Clone)] +#[derive(Clone, Debug)] pub(super) enum Resource { Buffer { buffer: Subbuffer<[u8]>, diff --git a/vulkano/src/command_buffer/commands/pipeline.rs b/vulkano/src/command_buffer/commands/pipeline.rs index 721c1eba..18bfd750 100644 --- a/vulkano/src/command_buffer/commands/pipeline.rs +++ b/vulkano/src/command_buffer/commands/pipeline.rs @@ -2503,14 +2503,14 @@ where let (use_ref, memory_access) = use_iter(index as u32); let mut range = range.clone(); - range.start += buffer.offset() + dynamic_offset; - range.end += buffer.offset() + dynamic_offset; + range.start += dynamic_offset; + range.end += dynamic_offset; used_resources.push(( use_ref, Resource::Buffer { buffer: buffer.clone(), - range: range.clone(), + range, memory_access, }, )); @@ -2523,10 +2523,6 @@ where let (use_ref, memory_access) = use_iter(index as u32); - let mut range = range.clone(); - range.start += buffer.offset(); - range.end += buffer.offset(); - used_resources.push(( use_ref, Resource::Buffer { @@ -2545,15 +2541,11 @@ where let buffer = buffer_view.buffer(); let (use_ref, memory_access) = use_iter(index as u32); - let mut range = buffer_view.range(); - range.start += buffer.offset(); - range.end += buffer.offset(); - used_resources.push(( use_ref, Resource::Buffer { buffer: buffer.clone(), - range: range.clone(), + range: buffer_view.range().clone(), memory_access, }, )); diff --git a/vulkano/src/sync/pipeline.rs b/vulkano/src/sync/pipeline.rs index e017774e..73269fc7 100644 --- a/vulkano/src/sync/pipeline.rs +++ b/vulkano/src/sync/pipeline.rs @@ -601,8 +601,7 @@ vulkan_bitflags! { pub(crate) fn expand(mut self) -> Self { if self.intersects(AccessFlags::SHADER_READ) { self -= AccessFlags::SHADER_READ; - self |= AccessFlags::UNIFORM_READ - | AccessFlags::SHADER_SAMPLED_READ + self |= AccessFlags::SHADER_SAMPLED_READ | AccessFlags::SHADER_STORAGE_READ | AccessFlags::SHADER_BINDING_TABLE_READ; }