Warm tip: This article is reproduced from serverfault.com, please click

What is vulkan color space?

发布于 2020-12-10 20:21:39

During creation of vulkan swapchain i've stuck at imageColorSpace and imageFormat parameters in VkSwapchainCreateInfoKHR. I do understand that imageFormat is how actual pixel is encoded and stored in memory and if it color isn't linear then vulkan converts it to such during sampling and writing operations in shaders. My hardware supports only VK_COLOR_SPACE_SRGB_NONLINEAR_KHR which i suppose means that color in swapchain image should be stored in a non-linear fashion but VK_FORMAT_B8G8R8A8_SRGB results in gamma 0.44 corected colors, while VK_FORMAT_B8G8R8A8_UNORM works fine. How imageFormat relates to imageColorSpace and what does imageColorSpace specify?

Questioner
E1Hephaestus
Viewed
0
krOoze 2020-12-11 06:39:00

Vulkan is colorspace agnostic. Though at some point before the bits are converted to photons, the colorspace must become known. That's why it is asked for in the swapchain creation.

imageFormat specifies what the image format is (same as it does in vkCreateImage()). imageColorSpace is how the swapchain\display interprets the values when the image is presented.

So if you have UNORM, that means unspecified color space, and they are good ol' raw bits. Or rather it means that you are in charge of the color space (if the image even stores color, and not something else entirely). If you use VK_COLOR_SPACE_SRGB_NONLINEAR_KHR with *_UNORM, it means the swapchain takes your bits and it is gonna assume it is already SRGB when presented. If it is *_SRGB, then that is no different for the swapchain itself, but what happens is that the created VkImages are *_SRGB format, which means when you use them then the color is being linearized for you (same as would happen if you created a non-swapchain VkImage).