Jump to content
  • Advertisement
GuyWithBeard

Typeless formats in Vulkan

This topic is 501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In D3D, if you want to render depth information to a texture and later use that texture as input to a shader you might create a texture with the format DXGI_FORMAT_R24G8_TYPELESS. You would then create two views to the texture, eg. one view with format DXGI_FORMAT_D24_UNORM_S8_UINT for rendering the depth and one SRV with format DXGI_FORMAT_R24_UNORM_X8_TYPELESS for sampling from the texture. How would one go about doing this in Vulkan since VkFormat does not seem to contain any typeless formats?

Share this post


Link to post
Share on other sites
Advertisement

I am surprised no-one seems to know this. Let me rephrase the question a bit.

In Vulkan, if you want to render to a texture and then later use it as a shader input, what format should you use in the texture itself, and which formats should you use in the descriptors/views? For the sake of argument, let's say the texture is R8G8B8A8.

Share this post


Link to post
Share on other sites

Oh, that's interesting. Still, it does not really answer my question.

One reason you might want a typeless format for a texture in DirectX is that you are planning to create two different views to the texture, each with their own formats, essentially "casting" the texture data into the type of the view you are currently using.

For example, if I have a depth buffer with the type VK_FORMAT_D24_UNORM_S8_UINT and I write the depth to it using a view of the same type, can I create a another view for SRV use with the format VK_FORMAT_B8G8R8A8_UNORM to that same texture, and then simply only use the RGB components? Or do I have to pass the original view to the shader?

I am only asking because AFAIK DX requires me to create two views with fully specified formats and the texture with a compatible typeless format and I would benefit from being able to do the same on Vulkan (except for the typeless part as that is not a thing on Vulkan).

Edited by GuyWithBeard
fixed a typo

Share this post


Link to post
Share on other sites

I apologize, you answered my question perfectly. I guess I just asked the wrong question.

To give you a bit of background, I have a common API that wraps, among others, DX12 and Vulkan and I am wondering how to render to a texture and later use it as an SRV in a way that works for both APIs.

Share this post


Link to post
Share on other sites
3 hours ago, GuyWithBeard said:

For example, if I have a depth buffer with the type VK_FORMAT_D24_UNORM_S8_UINT and I write the depth to it using a view of the same type, can I create a another view for SRV use with the format VK_FORMAT_B8G8R8A8_UNORM to that same texture, and the simply only use the RGB components? Or do I have to pass the original view to the shader?

 

You can't do that in D3D, because D24S8 and RGBA8 are from two different format "families" (e.g. DXGI_FORMAT_R24G8_TYPELESS / DXGI_FORMAT_R24_UNORM_X8_TYPELESS / DXGI_FORMAT_D24_UNORM_S8_UINT / etc are all the same "family").

In D3D, you use R24/X8 to tell an SRV that you'd like to read the depth channel in your shader, or X24/G8 to tell an SRV that you'd like to read the stencil channel in your shader, and D24/S8 when making a DSV just because that's what D3D makes you do.

I'm still learning Vulkan, but I think you achieve the same thing (telling the SRV which channel it will read from) via specifying VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT.

AFAIK, in vulkan/D3D12, it is certainly possible to alias a texture using a completely different format -- e.g. from D24S8 to RGBA8... However, it will be implementation defined whether this will work as you expect or not. It's highly likely that the GPU will use different memory addressing modes, compression modes, etc, etc, so the formats won't be bit-for-bit compatible like you would expect at first glance.

Share this post


Link to post
Share on other sites
2 minutes ago, Hodgman said:

You can't do that in D3D, because D24S8 and RGBA8 are from two different format "families"

I know, I just desperately tried to find some Vulkan formats that would equal the ones I originally used.

I guess I am just gonna have to try and see how it goes. As a fallback I can make it work like I am used to in DX11/12 and provide some custom logic to map the same view as an SRV on the Vulkan side.

Thanks for your insights, and please let me know if you figure it out as part of your own Vulkan work :)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!