Skip to content

Commit

Permalink
feat: address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Oct 25, 2024
1 parent 51106f5 commit bcaa730
Showing 1 changed file with 10 additions and 50 deletions.
60 changes: 10 additions & 50 deletions Source/VK/SwapChainVK.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
// © 2021 NVIDIA Corporation

constexpr std::array<VkFormat, (size_t)SwapChainFormat::MAX_NUM> g_swapChainFormat = {
VK_FORMAT_R16G16B16A16_SFLOAT, // BT709_G10_16BIT
#ifdef __APPLE__
VK_FORMAT_B8G8R8A8_UNORM, // BT709_G22_8BIT
#else
VK_FORMAT_R8G8B8A8_UNORM, // BT709_G22_8BIT
#endif
VK_FORMAT_A2B10G10R10_UNORM_PACK32, // BT709_G22_10BIT
VK_FORMAT_A2B10G10R10_UNORM_PACK32, // BT2020_G2084_10BIT
};

constexpr std::array<VkColorSpaceKHR, (size_t)SwapChainFormat::MAX_NUM> g_colorSpace = {
VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT, // BT709_G10_16BIT
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, // BT709_G22_8BIT
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, // BT709_G22_10BIT
VK_COLOR_SPACE_HDR10_ST2084_EXT, // BT2020_G2084_10BIT
};

SwapChainVK::SwapChainVK(DeviceVK& device)
: m_Device(device)
, m_Textures(device.GetStdAllocator()) {
Expand Down Expand Up @@ -159,48 +141,26 @@ Result SwapChainVK::Create(const SwapChainDesc& swapChainDesc) {
RETURN_ON_FAILURE(&m_Device, result == VK_SUCCESS, GetReturnCode(result), "vkGetPhysicalDeviceSurfaceFormatsKHR returned %d", (int32_t)result);

auto priority_BT709_G22_16BIT = [](const VkSurfaceFormatKHR& surface) -> uint32_t {
nri::Format nriFormat = VKFormatToNRIFormat(surface.format);
const FormatProps& formatProps = GetFormatProps(nriFormat);
return ((formatProps.redBits == 16) << 0) |
((formatProps.greenBits == 16) << 1) |
((formatProps.blueBits == 16) << 2) |
((formatProps.alphaBits == 16) << 3) |
((!formatProps.isSrgb) << 4) |
((surface.colorSpace == VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT) << 4);
return ((surface.format == VK_FORMAT_R16G16B16A16_SFLOAT) << 0) |
((surface.colorSpace == VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT) << 1);
};

// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceSurfaceFormatsKHR.html
// there is always a corespodning UNORM and SRGB just need to consider UNORM
auto priority_BT709_G22_8BIT = [](const VkSurfaceFormatKHR& surface) -> uint32_t {
nri::Format nriFormat = VKFormatToNRIFormat(surface.format);
const FormatProps& formatProps = GetFormatProps(nriFormat);
return ((formatProps.redBits == 8) << 0) |
((formatProps.greenBits == 8) << 1) |
((formatProps.blueBits == 8) << 2) |
((formatProps.alphaBits == 8) << 3) |
((!formatProps.isSrgb) << 4) |
((surface.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) << 5);
return ((surface.format == VK_FORMAT_R8G8B8A8_UNORM || surface.format == VK_FORMAT_B8G8R8A8_UNORM) << 0) |
((surface.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) << 1);
};


auto priority_BT709_G22_10BIT = [](const VkSurfaceFormatKHR& surface) -> uint32_t {
nri::Format nriFormat = VKFormatToNRIFormat(surface.format);
const FormatProps& formatProps = GetFormatProps(nriFormat);
return ((formatProps.redBits == 10) << 0) |
((formatProps.greenBits == 10) << 1) |
((formatProps.blueBits == 10) << 2) |
((formatProps.alphaBits == 2) << 3) |
((!formatProps.isSrgb) << 4) |
((surface.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) << 4);
return ((surface.format == VK_FORMAT_A2B10G10R10_UNORM_PACK32) << 0) |
((surface.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) << 1);
};

auto priority_BT2020_G2084_10BIT = [](const VkSurfaceFormatKHR& surface) -> uint32_t {
nri::Format nriFormat = VKFormatToNRIFormat(surface.format);
const FormatProps& formatProps = GetFormatProps(nriFormat);
return ((formatProps.redBits == 10) << 0) |
((formatProps.greenBits == 10) << 1) |
((formatProps.blueBits == 10) << 2) |
((formatProps.alphaBits == 2) << 3) |
((!formatProps.isSrgb) << 4) |
((surface.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT) << 4);
return ((surface.format == VK_FORMAT_A2B10G10R10_UNORM_PACK32) << 0) |
((surface.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT) << 1);
};

switch(swapChainDesc.format) {
Expand Down

0 comments on commit bcaa730

Please sign in to comment.