🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL confusion - VkImage as attachment & sampler

Started by
0 comments, last by Lewa 3 years, 1 month ago

I'm working on a deferred renderer in Vulkan and recently (after upgrading my Vulkan SDK from 1.2.135.0 to 1.2.176.1) i encountered an issue relating to depth-stencil attachments.

So the setup is simple: I have a VkImage with a depth/stencil format (VK_FORMAT_D32_SFLOAT_S8_UINT). I use a single VkImageView with the depth & stencil aspect bit set.

In my renderpass for rendering point lights i have to use the image as a depth-attachment (for depth-testing) as well as a sampler (for the shader to reconstruct position) while the stencil test is used to calculate the point-light volume (to reduce overdraw). The stencil part requires read/write access. (It's a basic deferred lighting/point light rendering setup)

The renderpass transitions the image to the VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL format, which according to the spec is exactly what i need (https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkImageLayout.html):

VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL specifies a layout for depth/stencil format images allowing read and write access to the stencil aspect as a stencil attachment, and read only access to the depth aspect as a depth attachment or in shaders as a sampled image, combined image/sampler, or input attachment. It is equivalent to VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL and VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL.

I also made sure to disable depth write (and only enable depth-testing) in the renderpass to comform to the spec.

This worked fine/without issues with the Vulkan SDK 1.2.135.0 (validation layers didn't throw any errors)

Now after i upgraded to the SDK 1.2.176.1 i recieve this error from the validation layer:

validation layer: Validation Error: [ VUID-vkCmdDrawIndexed-None-04584 ] Object 0: handle = 0xd50be8000000041b, type = VK_OBJECT_TYPE_DESCRIPTOR_SET; Object 1: handle = 0xbc1cf600000002b3, type = VK_OBJECT_TYPE_IMAGE_VIEW; Object 2: handle = 0x61b1840000000409, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xc406fcb7 | Descriptor set VkDescriptorSet 0xd50be8000000041b[] encountered the following validation error at vkCmdDrawIndexed() time: VkImageView 0xbc1cf600000002b3[] is used in Descriptor in binding #4 index 0 and VkFramebuffer 0x61b1840000000409[] attachment # 1. The Vulkan spec states: Image subresources used as attachments in the current render pass must not be accessed in any way other than as an attachment by this command, except for cases involving read-only access to depth/stencil attachments as described in the Render Pass chapter (https://vulkan.lunarg.com/doc/view/1.2.176.1/windows/1.2-extensions/vkspec.html#VUID-vkCmdDrawIndexed-None-04584)

Here is what the spec states: (https://vulkan.lunarg.com/doc/view/1.2.176.1/windows/1.2-extensions/vkspec.html#renderpass-attachment-nonattachment)

For depth/stencil attachments, each aspect can be used separately as attachments and non-attachments as long as the non-attachment accesses are also via an image subresource in either the VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL layout or the VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL layout, and the attachment resource uses whichever of those two layouts the image accesses do not.

I'm kind of confused with the spec here. I only have one VkImage (which can only be transitioned to one layout, in this case i chose VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL) which is then passed as a depth/stencil attachment and as a sampler (for the depth part) to the shader. But in the spec it makes it seem like the attachment and non-attachment (sampler) have to be in two different layouts simultaneously.

...can be used separately as attachments and non-attachments as long as the non-attachment accesses are also via an image subresource in either the VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL layout or the VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL layout, and the attachment resource uses whichever of those two layouts the image accesses do not.

Maybe i'm misunderstanding the spec (or even some fundamental conepts of vulkan) completely wrong but from what i can gather is that i somehow have to transition the sampler/non-attachment to VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL while having the actual depth-attachment in the VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL even though both of them are one and the same image?

What exactly am i getting wrong here? Is this a bug in the validation layers (given that it didn't throw any errors on the SDK ver. 1.2.135.0 ?)

This topic is closed to new replies.

Advertisement