Skip to content

Commit

Permalink
[Vulkan] Fixed an issue with HDR color space deteciton
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Oct 22, 2023
1 parent 08eb6e0 commit 2439a16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion runtime/RHI/RHI_SwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Spartan
{
static const uint8_t max_buffer_count = 3;
static const RHI_Format format_sdr = RHI_Format::R8G8B8A8_Unorm;
static const RHI_Format format_hdr = RHI_Format::R10G10B10A2_Unorm;
static const RHI_Format format_hdr = RHI_Format::R16G16B16A16_Float;

class SP_CLASS RHI_SwapChain : public SpObject
{
Expand Down
12 changes: 8 additions & 4 deletions runtime/RHI/Vulkan/Vulkan_SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ namespace Spartan
{
namespace
{
static VkColorSpaceKHR get_color_space(bool is_hdr)
static VkColorSpaceKHR get_color_space(const RHI_Format format)
{
// VK_COLOR_SPACE_HDR10_ST2084_EXT represents the HDR10 color space with the ST.2084 (PQ)electro - optical transfer function.
// This is the most common HDR format used for HDR TVs and monitors.

// VK_COLOR_SPACE_SRGB_NONLINEAR_KHR represents the sRGB color space.
// VK_COLOR_SPACE_SRGB_NONLINEAR_KHR represents the sRGB color space
// This is the standard color space for the web and is supported by most modern displays.
// sRGB is a nonlinear color space, which means that the values stored in an image are not directly proportional to the perceived brightness of the colors.
// When displaying an image in sRGB, the values must be converted to linear space before they are displayed.

return is_hdr ? VK_COLOR_SPACE_HDR10_ST2084_EXT : VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
VkColorSpaceKHR color_space = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; // SDR
color_space = format == RHI_Format::R16G16B16A16_Float ? VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT : color_space; // HDR
color_space = format == RHI_Format::R10G10B10A2_Unorm ? VK_COLOR_SPACE_HDR10_ST2084_EXT : color_space; // HDR

return color_space;
}

static VkSurfaceCapabilitiesKHR get_surface_capabilities(const VkSurfaceKHR surface)
Expand Down Expand Up @@ -222,7 +226,7 @@ namespace Spartan
VkSurfaceCapabilitiesKHR capabilities = get_surface_capabilities(surface);

// Ensure that the surface supports the requested format and color space
VkColorSpaceKHR color_space = get_color_space(IsHdr());
VkColorSpaceKHR color_space = get_color_space(m_format);
SP_ASSERT_MSG(is_format_and_color_space_supported(surface, &m_format, color_space), "The surface doesn't support the requested format");

// Clamp size between the supported min and max
Expand Down

0 comments on commit 2439a16

Please sign in to comment.