Hi!
I’m posting here in hopes of getting clarification with regards to the usage of VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL
The spec states: (VkImageLayout(3)):
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 toVK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL
andVK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL
.
Which from my understanding makes the depth-aspect of a depth/stencil image read only (which in turn allows us to access it as a read-only attachment and/or a sampler to pass to a shader) while the stencil part remains in read/write mode for the attachment only. (Which is the exact usecase that is required for deferred rendering for example.)
Now the part that i don’t understand: (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 theVK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
layout, and the attachment resource uses whichever of those two layouts the image accesses do not.
Specifically i assumed that if you want to use a depth/stencil image as a depth read-only attachment AND at the same time as a sampler (to pass to the shader in the case of position reconstruction for deferred rendering) while having read/write access of the stencil aspect during the renderpass i would have to set both the attachment layout and descriptorimage layout to VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL
But the spec seems to suggest that if you (for example) set the layout of the descriptorimage to
VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL
(because you want to only read the depth) you HAVE to set the layout of the attachment to
VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
which doesn’t really make sense as the attachment layout states that the stencil aspect is then read only (which is not what we want to achieve.)
This was also implemented into the validation layers (at around 1.2.160?) in the descriptor_sets validation checks (which forces you to have those two different layouts in the descriptor and attachment):
//image layout is the layout of the descriptorimage.
if ((image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL &&
subpasses[att_index].layout ==
VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL) ||
(subpasses[att_index].layout ==
VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL &&
image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)) {
continue;
}
This issue was also mentioned on github:
Can someone clarify if this is an oversight or some limitation/ongoing issue with the spec?
/Edit: Just realised that i haven’t posted this in the correct sub-category on the forum. My bad. Will not happen again.