[Noob] Difference between UNORM and SRGB

Hi, I’m a hobbyist, so I’m not that knowledgeable in to graphics programming.
Still I’ve been doing the few Vulkan tutorials out there, and reading how to do stuff.
But I come across this again and again…all tutorials assume that your graphics hardware support the VK_FORMAT_R8G8B8A8_SRGB flag but when asking vulkan for the supported formats I get VK_FORMAT_B8G8R8A8_UNORM for the 8bit formats.

So I was wondering what is the difference between UNORM and SRGB.

I found this in Vulkan Spec:

VK_FORMAT_R8G8B8A8_SRGB specifies a four-component, 32-bit unsigned normalized format that has an 8-bit R component stored with sRGB nonlinear encoding in byte 0, an 8-bit G component stored with sRGB nonlinear encoding in byte 1, an 8-bit B component stored with sRGB nonlinear encoding in byte 2, and an 8-bit A component in byte 3.

VK_FORMAT_B8G8R8A8_UNORM specifies a four-component, 32-bit unsigned normalized format that has an 8-bit B component in byte 0, an 8-bit G component in byte 1, an 8-bit R component in byte 2, and an 8-bit A component in byte 3.

There seems to be a difference in format features as well:

All image formats are assumed to be in a linear colorspace. SRGB is a specific, non-linear colorspace, so that becomes part of the image format. In terms of the actual storage, SRGB is stored the same way as UNORM. But when it gets read from a texture, then a conversion from sRGB to a linear colorspace will take place for the texels being read. When writing to sRGB images, you can also tell the system to do a linear-to-sRGB conversion for the values being written to the framebuffer.

Ah I see…so SRGB and UNORM are almost identical ,except UNORM having
some extra features.
That link reminded me that should start reading the specification as well.

I was curious , because I have a Radeon RX 570, not modern card but not old either…so I was wondering if not having an SRGB is a handicap.
Also since most tutorials use SRGB as the preferred format, setting the hardware checks for SRGB always gave me a null. Now I’ll know that I have to set it up to also look for the UNORM.

@Alfonse_Reinheart I was wondering…since there is a conversion to SRGB when using UNORM. Does that conversion take up processing power or it’s really insignificant?

It’s SRGB that has the extra features. UNORM is linear and is accessed directly; SRGB is stored non-linearly and is converted to linear upon access.

Your card definitely allows sRGB images. You are doing something wrong when you’re querying for this capability.

well my initial assumption is that I’m doing something wrong.
I query for the available formats with:
vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device,surface)

and for .format I get:

VK_FORMAT_B8G8R8A8_UNORM = 44
VK_FORMAT_B8G8R8A8_SRGB = 50
VK_FORMAT_A2R10G10B10_UNORM_PACK32 = 58
VK_FORMAT_R16G16B16A16_SFLOAT = 97

and for .colorSpace I get:

VK_COLOR_SPACE_SRGB_NONLINEAR_KHR = 0
VK_COLOR_SPACE_BT709_NONLINEAR_EXT = 1000104006

this is my actual print to the console:

format: `44` in colorspace: `0`
format: `50` in colorspace: `0`
format: `58` in colorspace: `0`
format: `97` in colorspace: `0`
format: `44` in colorspace: `1000104006`
format: `50` in colorspace: `1000104006`
format: `58` in colorspace: `1000104006`
format: `97` in colorspace: `1000104006`

so I usually go with the first format 44 - 0

Those are the formats for swapchain images, not for general image usage. In fact, that kinda changes pretty much the entire discussion.

Swapchain images have certain behavior. While the Vulkan image format defines how Vulkan will work with the image, the colorspace will define how the display system will work with it.

So if you choose UNORM, 0, what you’ll get is an image that Vulkan will render to without performing sRGB colorspace conversion. So the data you write will be unmodified. However, because the swapchain colorspace is in fact sRGB, the display system will assume that the color data is in the sRGB colorspace and behave accordingly.

So you’re rendering to the sRGB colorspace, whether you like it or not. Unless you explicitly never want to access the image with colorspace conversion, it’s best to make the format agree with the colorspace.

3 Likes

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.