Vulkan HDR Image present

Hello

I want to use Vulkan to Present the HDR Image on HDR display device,but I found the result is not correct.

the left side is vulkan result, the right side is a compared application result.


the SwapSurface Format used is:
availableFormat.format == VK_FORMAT_R16G16B16A16_SFLOAT && availableFormat.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT

the Image is pfm format, Use VK_FORMAT_R32G32B32_SFLOAT ImageFormat. the colour space is scrgb, the value is linear RGB.

createImage(texWidth, texHeight, VK_FORMAT_R32G32B32_SFLOAT, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, textureImage, textureImageMemory);

you can get a pfm file form here: PFM Format Documentation (pauldebevec.com)

the vertex shader is:

// filename is “shader_f.txt”   22_shader_ubo.vert
#version 450
layout(binding = 0) uniform UniformBufferObject {
    mat4 model;
    mat4 view;
    mat4 proj;
} ubo;

layout(location = 0) in vec2 inPosition;
layout(location = 1) in vec3 inColor;
layout(location = 2) in vec2 inTexCoord;

layout(location = 0) out vec3 fragColor;
layout(location = 1) out vec2 fragTexCoord;

void main() {
    gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
    fragColor = inColor;
    fragTexCoord = inTexCoord;
}

the fragment shader is:

// file name is “shader_f.txt”   22_shader_ubo.frag
#version 450

layout(binding = 0) uniform UniformBufferObject {
    mat4 model;
    mat4 view;
    mat4 proj;
} ubo;

layout(binding = 1) uniform sampler2D texSampler;

layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec2 fragTexCoord;

layout(location = 0) out vec4 outColor;

void main() {
    outColor = texture(texSampler, fragTexCoord);
}

the mian code is copy from here vulkan-tutorial.com/code/16_frames_in_flight.cpp

I want know how to let the render result become correct.Thanks.

1 Like

Have you seen this post: HDR in under 10 minutes ?

Thanks,I have tried it,but the result is not as expected.
I notice there is a error message while creating swapchain:

Validation Error: [ VUID-VkSwapchainCreateInfoKHR-imageColorSpace-parameter ] | MessageID = 0x7df43dca | vkCreateSwapchainKHR(): pCreateInfo->imageColorSpace (1000104008) requires the extensions VK_EXT_swapchain_colorspace. The Vulkan spec states: imageColorSpace must be a valid VkColorSpaceKHR value (Vulkan® 1.3.280 - A Specification (with all registered extensions))

I checked the deviceExtensions info, I found isn’t exist “VK_EXT_swapchain_colorspace”.
but SwapChainSupportDetails swapChainSupport context is:

+ [0] {format=VK_FORMAT_B8G8R8A8_UNORM (44) colorSpace=VK_COLOR_SPACE_SRGB_NONLINEAR_KHR (0) } VkSurfaceFormatKHR
+ [1] {format=VK_FORMAT_B8G8R8A8_SRGB (50) colorSpace=VK_COLOR_SPACE_SRGB_NONLINEAR_KHR (0) } VkSurfaceFormatKHR
+ [2] {format=VK_FORMAT_R8G8B8A8_UNORM (37) colorSpace=VK_COLOR_SPACE_SRGB_NONLINEAR_KHR (0) } VkSurfaceFormatKHR
+ [3] {format=VK_FORMAT_R8G8B8A8_SRGB (43) colorSpace=VK_COLOR_SPACE_SRGB_NONLINEAR_KHR (0) } VkSurfaceFormatKHR
+ [4] {format=VK_FORMAT_R16G16B16A16_SFLOAT (97) colorSpace=VK_COLOR_SPACE_HDR10_ST2084_EXT (1000104008) } VkSurfaceFormatKHR
+ [5] {format=VK_FORMAT_A2R10G10B10_UNORM_PACK32 (58) colorSpace=VK_COLOR_SPACE_HDR10_ST2084_EXT (1000104008) } VkSurfaceFormatKHR

I can not understand why the swapChainSupport format have VK_COLOR_SPACE_HDR10_ST2084_EXT but the “VK_EXT_swapchain_colorspace” is can’t find. Did I do something wrong? or how can make the format=VK_FORMAT_A2R10G10B10_UNORM_PACK32 (58) colorSpace=VK_COLOR_SPACE_HDR10_ST2084_EXT (1000104008) format swapchain created successfully?