2

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.

bishopp
  • 113
  • 8
  • Did You create a separate descriptor for the image view with the stencil aspect? – Ekzuzy Aug 15 '18 at 13:47
  • Yes. I created a separate descriptor for the stencil texture. – bishopp Aug 16 '18 at 09:46
  • Then we need more info or, even better, access to Your code to be able to say anything more. – Ekzuzy Aug 16 '18 at 13:39
  • What kind of information would be useful? This is part of a bigger engine, so it might be difficult to extract relevant information. Do I need to use a specific sampler type? Or is there a way to select the stencil component from the depth/stencil image? Even with the stencil aspect set, I still can get the depth values from the texture. So I assume there is something wrong with the way I access the texture. – bishopp Aug 16 '18 at 14:42
  • For depth and stencil images, You cannot sample both at the same time. You need two separate image views: one for depth and one for stencil aspect. So You also need a descriptor set with two separate descriptors. As far as I know they cannot use samplers (so You cannot use combined image samplers for that). I'm not sure if You can use sampled image for that or only storage images. So to know what may the problem for You, provide at least Your shader and descriptor setting code. – Ekzuzy Aug 16 '18 at 15:50
  • And are You sure that Your hardware supports sampling/reading the stencil data from an image with that format? As far as I can see, the spec doesn't require any stencil format to be readable in shaders. – Ekzuzy Aug 16 '18 at 15:58
  • I see the update but I'm not sure how did You do this previously, how are doing this now and what exactly have You changed so it started working? Such comprehensive information could be helpful for reader. – Ekzuzy Sep 20 '18 at 19:27
  • You should post the last update as the answer – Makogan Nov 03 '20 at 20:13

0 Answers0