vk_swapchain: Prefer linear swapchain format when presenting sRGB images
Fixes broken sRGB when presenting from a secondary GPU.
This commit is contained in:
parent
3843995ceb
commit
3c65c8580f
|
@ -356,7 +356,7 @@ void VKBlitScreen::CreateDescriptorPool() {
|
||||||
void VKBlitScreen::CreateRenderPass() {
|
void VKBlitScreen::CreateRenderPass() {
|
||||||
const VkAttachmentDescription color_attachment{
|
const VkAttachmentDescription color_attachment{
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.format = swapchain.GetImageFormat(),
|
.format = swapchain.GetImageViewFormat(),
|
||||||
.samples = VK_SAMPLE_COUNT_1_BIT,
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
||||||
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
||||||
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
||||||
|
|
|
@ -20,16 +20,15 @@ namespace Vulkan {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats, bool srgb) {
|
VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats) {
|
||||||
if (formats.size() == 1 && formats[0].format == VK_FORMAT_UNDEFINED) {
|
if (formats.size() == 1 && formats[0].format == VK_FORMAT_UNDEFINED) {
|
||||||
VkSurfaceFormatKHR format;
|
VkSurfaceFormatKHR format;
|
||||||
format.format = VK_FORMAT_B8G8R8A8_UNORM;
|
format.format = VK_FORMAT_B8G8R8A8_UNORM;
|
||||||
format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
const auto& found = std::find_if(formats.begin(), formats.end(), [srgb](const auto& format) {
|
const auto& found = std::find_if(formats.begin(), formats.end(), [](const auto& format) {
|
||||||
const auto request_format = srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM;
|
return format.format == VK_FORMAT_B8G8R8A8_UNORM &&
|
||||||
return format.format == request_format &&
|
|
||||||
format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||||
});
|
});
|
||||||
return found != formats.end() ? *found : formats[0];
|
return found != formats.end() ? *found : formats[0];
|
||||||
|
@ -145,7 +144,7 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities,
|
||||||
const auto formats{physical_device.GetSurfaceFormatsKHR(surface)};
|
const auto formats{physical_device.GetSurfaceFormatsKHR(surface)};
|
||||||
const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)};
|
const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)};
|
||||||
|
|
||||||
const VkSurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats, srgb)};
|
const VkSurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats)};
|
||||||
const VkPresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)};
|
const VkPresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)};
|
||||||
|
|
||||||
u32 requested_image_count{capabilities.minImageCount + 1};
|
u32 requested_image_count{capabilities.minImageCount + 1};
|
||||||
|
@ -191,7 +190,7 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities,
|
||||||
|
|
||||||
images = swapchain.GetImages();
|
images = swapchain.GetImages();
|
||||||
image_count = static_cast<u32>(images.size());
|
image_count = static_cast<u32>(images.size());
|
||||||
image_format = surface_format.format;
|
image_view_format = srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VKSwapchain::CreateSemaphores() {
|
void VKSwapchain::CreateSemaphores() {
|
||||||
|
@ -207,7 +206,7 @@ void VKSwapchain::CreateImageViews() {
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.image = {},
|
.image = {},
|
||||||
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
||||||
.format = image_format,
|
.format = image_view_format,
|
||||||
.components =
|
.components =
|
||||||
{
|
{
|
||||||
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
|
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
|
|
|
@ -68,8 +68,8 @@ public:
|
||||||
return *image_views[index];
|
return *image_views[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
VkFormat GetImageFormat() const {
|
VkFormat GetImageViewFormat() const {
|
||||||
return image_format;
|
return image_view_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -96,7 +96,7 @@ private:
|
||||||
u32 image_index{};
|
u32 image_index{};
|
||||||
u32 frame_index{};
|
u32 frame_index{};
|
||||||
|
|
||||||
VkFormat image_format{};
|
VkFormat image_view_format{};
|
||||||
VkExtent2D extent{};
|
VkExtent2D extent{};
|
||||||
|
|
||||||
bool current_srgb{};
|
bool current_srgb{};
|
||||||
|
|
Reference in New Issue