Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would VkImageView format differ from the underlying VkImage format?

VkImageCreateInfo has the following member:

 VkFormat                   format;

And VkImageViewCreateInfo has the same member.

What I don't understand why you would ever have a different format in the VkImageView from the VkImage needed to create it.

I understand some formats are compatible with one another, but I don't know why you would use one of the alternate formats

like image 862
Krupip Avatar asked Nov 25 '25 02:11

Krupip


2 Answers

The canonical use case and primary original motivation (in D3D10, where this idea originated) is using a single image as either R8G8B8A8_UNORM or R8G8B8A8_SRGB -- either because it holds different content at different times, or because sometimes you want to operate in sRGB-space without linearization.

More generally, it's useful sometimes to have different "types" of content in an image object at different times -- this gives engines a limited form of memory aliasing, and was introduced to graphics APIs several years before full-featured memory aliasing was a thing.

like image 92
Jesse Hall Avatar answered Nov 27 '25 16:11

Jesse Hall


Like a lot of Vulkan, the API is designed to expose what the hardware can do. Memory layout (image) and the interpretation of that memory as data (image view) are different concepts in the hardware, and so the API exposes that. The API exposes it simply because that's how the hardware works and Vulkan is designed to be a thin abstraction; just because the API can do it doesn't mean you need to use it ;)

As you say, in most cases it's not really that useful ...

I think there are some cases where it could be more efficient, for example getting a compute shader to generate integer data for some types of image processing can be more energy efficient than either float computation or manually normalizing integer data to create unorm data. Using aliasing you the compute shader can directly write e.g. uint8 integers and a fragment shader can read the same data as unorm8 data

like image 44
solidpixel Avatar answered Nov 27 '25 17:11

solidpixel