Skip to content

Commit

Permalink
Fix erroneous used range for buffers in descriptor sets (#2303)
Browse files Browse the repository at this point in the history
* Fix erroneous used range for buffers in descriptor sets

* Fix mistake resulting from an error in the spec that was just fixed
  • Loading branch information
Rua authored Aug 25, 2023
1 parent 49a8f66 commit c8ad5a4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
17 changes: 15 additions & 2 deletions vulkano/src/command_buffer/auto/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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<ResourceUseRef>,
Expand All @@ -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<ResourceUseRef>,
Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/command_buffer/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl From<ResourceInCommand> for ResourceUseRef2 {
}

/// Type of resource whose state is to be tracked.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub(super) enum Resource {
Buffer {
buffer: Subbuffer<[u8]>,
Expand Down
16 changes: 4 additions & 12 deletions vulkano/src/command_buffer/commands/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
));
Expand All @@ -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 {
Expand All @@ -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,
},
));
Expand Down
3 changes: 1 addition & 2 deletions vulkano/src/sync/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c8ad5a4

Please # to comment.