summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Rodrigo Locatti2019-12-08 21:53:22 -0300
committerGravatar GitHub2019-12-08 21:53:22 -0300
commite54699565a3ba89ba429a25857856faad274fdb5 (patch)
treef6dfe9b93c4d0bfd749ae4fc6d9d5b308d32b83b
parentMerge pull request #3202 from lioncash/kernel-include (diff)
parentvk_swapchain: Add support for swapping sRGB (diff)
downloadyuzu-e54699565a3ba89ba429a25857856faad274fdb5.tar.gz
yuzu-e54699565a3ba89ba429a25857856faad274fdb5.tar.xz
yuzu-e54699565a3ba89ba429a25857856faad274fdb5.zip
Merge pull request #3199 from ReinUsesLisp/vk-swapchain
vk_swapchain: Add support for swapping sRGB
-rw-r--r--src/video_core/renderer_vulkan/vk_swapchain.cpp45
-rw-r--r--src/video_core/renderer_vulkan/vk_swapchain.h10
2 files changed, 31 insertions, 24 deletions
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp
index 08279e562..ebc68f030 100644
--- a/src/video_core/renderer_vulkan/vk_swapchain.cpp
+++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp
@@ -19,12 +19,18 @@
19namespace Vulkan { 19namespace Vulkan {
20 20
21namespace { 21namespace {
22vk::SurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector<vk::SurfaceFormatKHR>& formats) { 22
23vk::SurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector<vk::SurfaceFormatKHR>& formats,
24 bool srgb) {
23 if (formats.size() == 1 && formats[0].format == vk::Format::eUndefined) { 25 if (formats.size() == 1 && formats[0].format == vk::Format::eUndefined) {
24 return {vk::Format::eB8G8R8A8Unorm, vk::ColorSpaceKHR::eSrgbNonlinear}; 26 vk::SurfaceFormatKHR format;
27 format.format = vk::Format::eB8G8R8A8Unorm;
28 format.colorSpace = vk::ColorSpaceKHR::eSrgbNonlinear;
29 return format;
25 } 30 }
26 const auto& found = std::find_if(formats.begin(), formats.end(), [](const auto& format) { 31 const auto& found = std::find_if(formats.begin(), formats.end(), [srgb](const auto& format) {
27 return format.format == vk::Format::eB8G8R8A8Unorm && 32 const auto request_format = srgb ? vk::Format::eB8G8R8A8Srgb : vk::Format::eB8G8R8A8Unorm;
33 return format.format == request_format &&
28 format.colorSpace == vk::ColorSpaceKHR::eSrgbNonlinear; 34 format.colorSpace == vk::ColorSpaceKHR::eSrgbNonlinear;
29 }); 35 });
30 return found != formats.end() ? *found : formats[0]; 36 return found != formats.end() ? *found : formats[0];
@@ -51,28 +57,26 @@ vk::Extent2D ChooseSwapExtent(const vk::SurfaceCapabilitiesKHR& capabilities, u3
51 std::min(capabilities.maxImageExtent.height, extent.height)); 57 std::min(capabilities.maxImageExtent.height, extent.height));
52 return extent; 58 return extent;
53} 59}
54} // namespace 60
61} // Anonymous namespace
55 62
56VKSwapchain::VKSwapchain(vk::SurfaceKHR surface, const VKDevice& device) 63VKSwapchain::VKSwapchain(vk::SurfaceKHR surface, const VKDevice& device)
57 : surface{surface}, device{device} {} 64 : surface{surface}, device{device} {}
58 65
59VKSwapchain::~VKSwapchain() = default; 66VKSwapchain::~VKSwapchain() = default;
60 67
61void VKSwapchain::Create(u32 width, u32 height) { 68void VKSwapchain::Create(u32 width, u32 height, bool srgb) {
62 const auto dev = device.GetLogical();
63 const auto& dld = device.GetDispatchLoader(); 69 const auto& dld = device.GetDispatchLoader();
64 const auto physical_device = device.GetPhysical(); 70 const auto physical_device = device.GetPhysical();
65 71 const auto capabilities{physical_device.getSurfaceCapabilitiesKHR(surface, dld)};
66 const vk::SurfaceCapabilitiesKHR capabilities{
67 physical_device.getSurfaceCapabilitiesKHR(surface, dld)};
68 if (capabilities.maxImageExtent.width == 0 || capabilities.maxImageExtent.height == 0) { 72 if (capabilities.maxImageExtent.width == 0 || capabilities.maxImageExtent.height == 0) {
69 return; 73 return;
70 } 74 }
71 75
72 dev.waitIdle(dld); 76 device.GetLogical().waitIdle(dld);
73 Destroy(); 77 Destroy();
74 78
75 CreateSwapchain(capabilities, width, height); 79 CreateSwapchain(capabilities, width, height, srgb);
76 CreateSemaphores(); 80 CreateSemaphores();
77 CreateImageViews(); 81 CreateImageViews();
78 82
@@ -107,7 +111,7 @@ bool VKSwapchain::Present(vk::Semaphore render_semaphore, VKFence& fence) {
107 break; 111 break;
108 case vk::Result::eErrorOutOfDateKHR: 112 case vk::Result::eErrorOutOfDateKHR:
109 if (current_width > 0 && current_height > 0) { 113 if (current_width > 0 && current_height > 0) {
110 Create(current_width, current_height); 114 Create(current_width, current_height, current_srgb);
111 recreated = true; 115 recreated = true;
112 } 116 }
113 break; 117 break;
@@ -129,23 +133,19 @@ bool VKSwapchain::HasFramebufferChanged(const Layout::FramebufferLayout& framebu
129} 133}
130 134
131void VKSwapchain::CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities, u32 width, 135void VKSwapchain::CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities, u32 width,
132 u32 height) { 136 u32 height, bool srgb) {
133 const auto dev{device.GetLogical()};
134 const auto& dld{device.GetDispatchLoader()}; 137 const auto& dld{device.GetDispatchLoader()};
135 const auto physical_device{device.GetPhysical()}; 138 const auto physical_device{device.GetPhysical()};
139 const auto formats{physical_device.getSurfaceFormatsKHR(surface, dld)};
140 const auto present_modes{physical_device.getSurfacePresentModesKHR(surface, dld)};
136 141
137 const std::vector<vk::SurfaceFormatKHR> formats{ 142 const vk::SurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats, srgb)};
138 physical_device.getSurfaceFormatsKHR(surface, dld)};
139
140 const std::vector<vk::PresentModeKHR> present_modes{
141 physical_device.getSurfacePresentModesKHR(surface, dld)};
142
143 const vk::SurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats)};
144 const vk::PresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)}; 143 const vk::PresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)};
145 extent = ChooseSwapExtent(capabilities, width, height); 144 extent = ChooseSwapExtent(capabilities, width, height);
146 145
147 current_width = extent.width; 146 current_width = extent.width;
148 current_height = extent.height; 147 current_height = extent.height;
148 current_srgb = srgb;
149 149
150 u32 requested_image_count{capabilities.minImageCount + 1}; 150 u32 requested_image_count{capabilities.minImageCount + 1};
151 if (capabilities.maxImageCount > 0 && requested_image_count > capabilities.maxImageCount) { 151 if (capabilities.maxImageCount > 0 && requested_image_count > capabilities.maxImageCount) {
@@ -169,6 +169,7 @@ void VKSwapchain::CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities
169 swapchain_ci.imageSharingMode = vk::SharingMode::eExclusive; 169 swapchain_ci.imageSharingMode = vk::SharingMode::eExclusive;
170 } 170 }
171 171
172 const auto dev{device.GetLogical()};
172 swapchain = dev.createSwapchainKHRUnique(swapchain_ci, nullptr, dld); 173 swapchain = dev.createSwapchainKHRUnique(swapchain_ci, nullptr, dld);
173 174
174 images = dev.getSwapchainImagesKHR(*swapchain, dld); 175 images = dev.getSwapchainImagesKHR(*swapchain, dld);
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.h b/src/video_core/renderer_vulkan/vk_swapchain.h
index 2ad84f185..a1e7938d2 100644
--- a/src/video_core/renderer_vulkan/vk_swapchain.h
+++ b/src/video_core/renderer_vulkan/vk_swapchain.h
@@ -24,7 +24,7 @@ public:
24 ~VKSwapchain(); 24 ~VKSwapchain();
25 25
26 /// Creates (or recreates) the swapchain with a given size. 26 /// Creates (or recreates) the swapchain with a given size.
27 void Create(u32 width, u32 height); 27 void Create(u32 width, u32 height, bool srgb);
28 28
29 /// Acquires the next image in the swapchain, waits as needed. 29 /// Acquires the next image in the swapchain, waits as needed.
30 void AcquireNextImage(); 30 void AcquireNextImage();
@@ -60,8 +60,13 @@ public:
60 return image_format; 60 return image_format;
61 } 61 }
62 62
63 bool GetSrgbState() const {
64 return current_srgb;
65 }
66
63private: 67private:
64 void CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities, u32 width, u32 height); 68 void CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities, u32 width, u32 height,
69 bool srgb);
65 void CreateSemaphores(); 70 void CreateSemaphores();
66 void CreateImageViews(); 71 void CreateImageViews();
67 72
@@ -87,6 +92,7 @@ private:
87 92
88 u32 current_width{}; 93 u32 current_width{};
89 u32 current_height{}; 94 u32 current_height{};
95 bool current_srgb{};
90}; 96};
91 97
92} // namespace Vulkan 98} // namespace Vulkan