Skip to content

Commit

Permalink
Fix incorrect aspects in barriers for depth+stencil images (vulkano-r…
Browse files Browse the repository at this point in the history
…s#2108)

* Fix incorrect aspects in barriers for depth+stencil images

* Account for first_use possibly being empty
  • Loading branch information
Rua authored and hakolao committed Feb 20, 2024
1 parent c0c50a6 commit bbb1c1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions vulkano/src/command_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ pub(crate) struct CommandBufferBufferUsage {

#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct CommandBufferBufferRangeUsage {
pub(crate) first_use: ResourceUseRef,
pub(crate) first_use: Option<ResourceUseRef>,
pub(crate) mutable: bool,
}

Expand All @@ -546,7 +546,7 @@ pub(crate) struct CommandBufferImageUsage {

#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct CommandBufferImageRangeUsage {
pub(crate) first_use: ResourceUseRef,
pub(crate) first_use: Option<ResourceUseRef>,
pub(crate) mutable: bool,
pub(crate) expected_layout: ImageLayout,
pub(crate) final_layout: ImageLayout,
Expand Down
19 changes: 16 additions & 3 deletions vulkano/src/command_buffer/synced/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
},
descriptor_set::{DescriptorSetResources, DescriptorSetWithOffsets},
device::{Device, DeviceOwned},
image::{sys::Image, ImageAccess, ImageLayout, ImageSubresourceRange},
image::{sys::Image, ImageAccess, ImageAspects, ImageLayout, ImageSubresourceRange},
pipeline::{
graphics::{
color_blend::LogicOp,
Expand Down Expand Up @@ -539,6 +539,19 @@ impl SyncCommandBufferBuilder {
subresource_range.mip_levels.start += inner.first_mipmap_level;
subresource_range.mip_levels.end += inner.first_mipmap_level;

// VUID-VkImageMemoryBarrier2-image-03320
if !self
.device()
.enabled_features()
.separate_depth_stencil_layouts
&& image
.format()
.aspects()
.contains(ImageAspects::DEPTH | ImageAspects::STENCIL)
{
subresource_range.aspects = ImageAspects::DEPTH | ImageAspects::STENCIL;
}

let range_map = self.images2.entry(inner.image.clone()).or_insert_with(|| {
[(
0..inner.image.range_size(),
Expand Down Expand Up @@ -816,7 +829,7 @@ impl SyncCommandBufferBuilder {
.into_iter()
.filter(|(_range, state)| !state.resource_uses.is_empty())
.map(|(range, state)| {
let first_use = state.resource_uses.into_iter().next().unwrap();
let first_use = state.resource_uses.into_iter().next();
(
range,
CommandBufferBufferRangeUsage {
Expand Down Expand Up @@ -845,7 +858,7 @@ impl SyncCommandBufferBuilder {
state.current_layout = state.final_layout;
}

let first_use = state.resource_uses.into_iter().next().unwrap();
let first_use = state.resource_uses.into_iter().next();
(
range,
CommandBufferImageRangeUsage {
Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/sync/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ pub enum FlushError {
/// Access to a resource has been denied.
ResourceAccessError {
error: AccessError,
use_ref: ResourceUseRef,
use_ref: Option<ResourceUseRef>,
},

/// The command buffer or one of the secondary command buffers it executes was created with the
Expand Down

0 comments on commit bbb1c1f

Please sign in to comment.