summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2023-06-23 18:08:23 +0200
committerGitHub <noreply@github.com>2023-06-23 18:08:23 +0200
commit02909bd1a560673a2d205bc95f5257436d194fad (patch)
treef7462671e50770652fae79371645027867d8d560 /Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp
parent5bf3d55d3864274814efc883fb54e464ae406cf0 (diff)
parentdaddf4cd9cf7c45820f5cadd1539c6a6b366cfbc (diff)
Merge pull request #11850 from Filoppi/post_process_fixes
Video: implement color correction to match the Wii/GC NTSC/PAL color spaces (and gamma)
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp')
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp55
1 files changed, 47 insertions, 8 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp b/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp
index 5e76adf788..48102df64d 100644
--- a/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp
@@ -154,7 +154,7 @@ bool SwapChain::SelectSurfaceFormat()
&format_count, surface_formats.data());
ASSERT(res == VK_SUCCESS);
- // If there is a single undefined surface format, the device doesn't care, so we'll just use RGBA
+ // If there is a single undefined surface format, the device doesn't care, so we'll just use RGBA8
if (surface_formats[0].format == VK_FORMAT_UNDEFINED)
{
m_surface_format.format = VK_FORMAT_R8G8B8A8_UNORM;
@@ -162,22 +162,61 @@ bool SwapChain::SelectSurfaceFormat()
return true;
}
- // Try to find a suitable format.
+ const VkSurfaceFormatKHR* surface_format_RGBA8 = nullptr;
+ const VkSurfaceFormatKHR* surface_format_BGRA8 = nullptr;
+ const VkSurfaceFormatKHR* surface_format_RGB10_A2 = nullptr;
+ const VkSurfaceFormatKHR* surface_format_RGBA16F_scRGB = nullptr;
+
+ // Try to find all suitable formats.
for (const VkSurfaceFormatKHR& surface_format : surface_formats)
{
- // Some drivers seem to return a SRGB format here (Intel Mesa).
- // This results in gamma correction when presenting to the screen, which we don't want.
- // Use a linear format instead, if this is the case.
+ // Some drivers seem to return a RGBA8 SRGB format here (Intel Mesa).
+ // Some other drivers return both a RGBA8 SRGB and UNORM formats (Nvidia).
+ // This results in gamma correction when presenting to the screen, which we don't want,
+ // because we already apply gamma ourselves, and we might not use sRGB gamma.
+ // Force using a linear format instead, if this is the case.
VkFormat format = VKTexture::GetLinearFormat(surface_format.format);
if (format == VK_FORMAT_R8G8B8A8_UNORM)
- m_texture_format = AbstractTextureFormat::RGBA8;
+ surface_format_RGBA8 = &surface_format;
else if (format == VK_FORMAT_B8G8R8A8_UNORM)
- m_texture_format = AbstractTextureFormat::BGRA8;
+ surface_format_BGRA8 = &surface_format;
+ else if (format == VK_FORMAT_A2B10G10R10_UNORM_PACK32 &&
+ surface_format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
+ surface_format_RGB10_A2 = &surface_format;
+ else if (format == VK_FORMAT_R16G16B16A16_SFLOAT &&
+ surface_format.colorSpace == VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT)
+ surface_format_RGBA16F_scRGB = &surface_format;
else
continue;
+ }
+
+ const VkSurfaceFormatKHR* surface_format = nullptr;
+
+ // Pick the best format.
+ // "g_ActiveConfig" might not have been been updated yet.
+ if (g_Config.bHDR && surface_format_RGBA16F_scRGB)
+ surface_format = surface_format_RGBA16F_scRGB;
+ else if (surface_format_RGB10_A2)
+ surface_format = surface_format_RGB10_A2;
+ else if (surface_format_RGBA8)
+ surface_format = surface_format_RGBA8;
+ else if (surface_format_BGRA8)
+ surface_format = surface_format_BGRA8;
+
+ if (surface_format)
+ {
+ const VkFormat format = VKTexture::GetLinearFormat(surface_format->format);
+ if (format == VK_FORMAT_R8G8B8A8_UNORM)
+ m_texture_format = AbstractTextureFormat::RGBA8;
+ else if (format == VK_FORMAT_B8G8R8A8_UNORM)
+ m_texture_format = AbstractTextureFormat::BGRA8;
+ else if (format == VK_FORMAT_A2B10G10R10_UNORM_PACK32)
+ m_texture_format = AbstractTextureFormat::RGB10_A2;
+ else if (format == VK_FORMAT_R16G16B16A16_SFLOAT)
+ m_texture_format = AbstractTextureFormat::RGBA16F;
m_surface_format.format = format;
- m_surface_format.colorSpace = surface_format.colorSpace;
+ m_surface_format.colorSpace = surface_format->colorSpace;
return true;
}