Src\Dst flags combination for image layout transition TransferDstOptimal => DepthStencilReadOnlyOptimal

Hello
I’m trying to create a 1x1 depth image to use instead of a shadow map, when shadows are diasabled in my app.

Here are my steps:

  1. Create an Image of the same format as used for shadowmap (D32Sfloat).
  2. Create staging buffer with image data (single float).
  3. Change image layout Undefined => TransferDstOptimal.
  4. Copy data from buffer.
  5. Change image layout TransferDstOptimal => DepthStencilReadOnlyOptimal.

Problem is, I don’t know how to do TRANSFER_DST_OPTIMAL => DEPTH_STENCIL_READ_ONLY_OPTIMAL transition.
My transitions code is based on vulkan tutorial here: [Depth buffering - Vulkan Tutorial]
which doesn’t cover this case…

So could anybody pls. help me to find correct combination of src\dst access & src\dst stage flags for this transition?
I tried to use combinations for other transitions - my app just crashing, no messages from verification layers…

P.S.
Alternativly, if there is a way to create 1x1 depth image without layout transitions - I’m also all ears…

Well, found solution probably.

First, combination of flags that seems working is:

                flags.SourceAccessMask = Vulkan.AccessFlags.MemoryRead | Vulkan.AccessFlags.MemoryWrite;
                flags.DestinationAccessMask = Vulkan.AccessFlags.MemoryRead | Vulkan.AccessFlags.MemoryWrite;

                flags.SourceStage = Vulkan.PipelineStageFlags.AllCommands;
                flags.DestinationStage = Vulkan.PipelineStageFlags.AllCommands;

Second, found this in vulkan docs:

If srcQueueFamilyIndex and dstQueueFamilyIndex define a queue family ownership transfer or oldLayout and newLayout define an image layout transition, and oldLayout or newLayout is VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL then image must have been created with VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT

So image should be created with VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, despite you’re NOT going to use it as depth-stencil attachment…

You don’t have to use that usage if you’re not going to attach it to a render pass. But you do need the correct usage bits, the ones that fit the usage you intend to use it for. If you’re reading from it within a shader, then there are usage bits for that.

Usage flags I have at the moment are:

Vulkan.ImageUsageFlags.TransferDst | Vulkan.ImageUsageFlags.Sampled | Vulkan.ImageUsageFlags.DepthStencilAttachment

First layout transition Vulkan.ImageLayout.Undefined => Vulkan.ImageLayout.TransferDstOptimal - works regardless DepthStencilAttachment flag.

But then, after I copy buffer data to image, and trying to change layout Vulkan.ImageLayout.TransferDstOptimal => Vulkan.ImageLayout.DepthStencilReadOnlyOptimal without Vulkan.ImageUsageFlags.DepthStencilAttachment - it fails.

What “fails”? Vulkan doesn’t generally give out error messages. So, are you talking about a validation layer failure? If so, what’s the error message from the layer? If not, what exactly does “fails” mean?

Sorry, probably I should have provided more context…
So I’m using C# and VulkanSharp wrapper which I have forked and migrated to .NET 6.0.
I’m using VK_LAYER_KHRONOS_validation validation layer.
By “fails” I mean - I have an exception of type System.ExecutionEngineException with callstack looking like this:

--------------------------------
   at Vulkan.Interop.NativeMethods.vkCmdPipelineBarrier(IntPtr, Vulkan.PipelineStageFlags, Vulkan.PipelineStageFlags, Vulkan.DependencyFlags, UInt32, Vulkan.Interop.MemoryBarrier*, UInt32, Vulkan.Interop.BufferMemoryBarrier*, UInt32, Vulkan.Interop.ImageMemoryBarrier*)
--------------------------------
   at Vulkan.CommandBuffer.CmdPipelineBarrier(Vulkan.PipelineStageFlags, Vulkan.PipelineStageFlags, Vulkan.DependencyFlags, Vulkan.MemoryBarrier, Vulkan.BufferMemoryBarrier, Vulkan.ImageMemoryBarrier)
   at Ice.Graphics.VkSharp.ImageBuffer+<>c__DisplayClass55_0.<ChangeLayout>b__0(Vulkan.CommandBuffer)
   at Ice.Graphics.VkSharp.ApiCommandBuffer.ExecOnce(System.Action`1<Vulkan.CommandBuffer>)
   at Ice.Graphics.VkSharp.ImageBuffer.ChangeLayout(Vulkan.ImageLayout, Vulkan.ImageLayout, System.Nullable`1<Vulkan.ImageAspectFlags>)

Everything starts with Ice. - it’s mine abstraction layer code…
No other messages from system or validation layer.
And that happens quite often to me - lack of debug info I mean.

P.S.
Anyway, the problem is solved by adding VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT to image usage flags.
It’s really helpfull to try to explain the problem to another person. :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.