I have a combined depth/stencil image with the VK_FORMAT_D32_SFLOAT_S8_UINT
format. I am trying to create 2 image views for it, so that I can use them to sample the depth and the stencil values in a shader. I set the image aspect flags to VK_IMAGE_ASPECT_DEPTH_BIT
and VK_IMAGE_ASPECT_STENCIL_BIT
respectively when the views are created, but I can only sample the depth texture successfully. The stencil image view is created fine but I can't even see it bound in the shader (at least that's what RenderDoc is saying). Also there are no errors or messages from the validation layers.
Is there any specific configuration for the buffer and stencil view that I need to use or any other things to consider in order to set the stencil texture view and sample it?
UPDATE: The issue with the stencil texture not being set was caused by an error in my code. I can now see it bound in RenderDoc and toggle between the depth and stencil components (they have the right content). So now the question is, how do I sample the stencil component of a combined depth/stencil image, because I can only get the stencil clear color when I sample it?
UPDATE: I eventually managed to get this working by using a buffer with the VK_FORMAT_D32_SFLOAT_S8_UINT format and a view that has the VK_IMAGE_ASPECT_STENCIL_BIT aspect. Also, in the shader, I used a usampler2DMS sampler and texelFetch to read the stencil value (as I'm using multisampling). texelFetch will return a uint4 value and the stencil value can be accessed from the red channel.