From db3df4e55f80c137ea6187250957eb92c2291627 Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:53:38 +0200 Subject: [PATCH] Restore old initial/final layout requirement bahavior (#2288) --- vulkano/src/image/sys.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/vulkano/src/image/sys.rs b/vulkano/src/image/sys.rs index ef8dd03508..775f75d9bc 100644 --- a/vulkano/src/image/sys.rs +++ b/vulkano/src/image/sys.rs @@ -1156,10 +1156,34 @@ impl RawImage { return Err((VulkanError::from(err), self, allocations.into_iter())); } + let usage = self + .usage + .difference(ImageUsage::TRANSFER_SRC | ImageUsage::TRANSFER_DST); + + let layout = if usage.intersects(ImageUsage::SAMPLED | ImageUsage::INPUT_ATTACHMENT) + && usage + .difference(ImageUsage::SAMPLED | ImageUsage::INPUT_ATTACHMENT) + .is_empty() + { + ImageLayout::ShaderReadOnlyOptimal + } else if usage.intersects(ImageUsage::COLOR_ATTACHMENT) + && usage.difference(ImageUsage::COLOR_ATTACHMENT).is_empty() + { + ImageLayout::ColorAttachmentOptimal + } else if usage.intersects(ImageUsage::DEPTH_STENCIL_ATTACHMENT) + && usage + .difference(ImageUsage::DEPTH_STENCIL_ATTACHMENT) + .is_empty() + { + ImageLayout::DepthStencilAttachmentOptimal + } else { + ImageLayout::General + }; + Ok(Image::from_raw( self, ImageMemory::Normal(allocations), - ImageLayout::General, + layout, )) }