summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar Alexander Orzechowski2022-12-13 13:08:02 -0500
committerGravatar Alexander Orzechowski2022-12-13 13:23:35 -0500
commit3cc3176ad6549c412f2370f496f00f1f6849275c (patch)
tree33c90504a36af40b42080df1822e909a8399373f /src/video_core
parentrenderer_opengl: refactor context acquire (diff)
downloadyuzu-3cc3176ad6549c412f2370f496f00f1f6849275c.tar.gz
yuzu-3cc3176ad6549c412f2370f496f00f1f6849275c.tar.xz
yuzu-3cc3176ad6549c412f2370f496f00f1f6849275c.zip
video_core/vulkan: Explicity check swapchain size when deciding to recreate
Vulkan for whatever reason does not return VK_ERROR_OUT_OF_DATE_KHR when the swapchain is the wrong size. Explicity make sure the size is indeed up to date to workaround this.
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_vulkan/renderer_vulkan.cpp14
-rw-r--r--src/video_core/renderer_vulkan/vk_swapchain.cpp15
-rw-r--r--src/video_core/renderer_vulkan/vk_swapchain.h14
3 files changed, 28 insertions, 15 deletions
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp
index 18be54729..f502a7d09 100644
--- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp
+++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp
@@ -139,23 +139,25 @@ void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
139 RenderScreenshot(*framebuffer, use_accelerated); 139 RenderScreenshot(*framebuffer, use_accelerated);
140 140
141 bool has_been_recreated = false; 141 bool has_been_recreated = false;
142 const auto recreate_swapchain = [&] { 142 const auto recreate_swapchain = [&](u32 width, u32 height) {
143 if (!has_been_recreated) { 143 if (!has_been_recreated) {
144 has_been_recreated = true; 144 has_been_recreated = true;
145 scheduler.Finish(); 145 scheduler.Finish();
146 } 146 }
147 const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout(); 147 swapchain.Create(width, height, is_srgb);
148 swapchain.Create(layout.width, layout.height, is_srgb);
149 }; 148 };
150 if (swapchain.NeedsRecreation(is_srgb)) { 149
151 recreate_swapchain(); 150 const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout();
151 if (swapchain.NeedsRecreation(is_srgb) || swapchain.GetWidth() != layout.width ||
152 swapchain.GetHeight() != layout.height) {
153 recreate_swapchain(layout.width, layout.height);
152 } 154 }
153 bool is_outdated; 155 bool is_outdated;
154 do { 156 do {
155 swapchain.AcquireNextImage(); 157 swapchain.AcquireNextImage();
156 is_outdated = swapchain.IsOutDated(); 158 is_outdated = swapchain.IsOutDated();
157 if (is_outdated) { 159 if (is_outdated) {
158 recreate_swapchain(); 160 recreate_swapchain(layout.width, layout.height);
159 } 161 }
160 } while (is_outdated); 162 } while (is_outdated);
161 if (has_been_recreated) { 163 if (has_been_recreated) {
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp
index d7be417f5..b6810eef9 100644
--- a/src/video_core/renderer_vulkan/vk_swapchain.cpp
+++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp
@@ -67,17 +67,19 @@ VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, u32 wi
67 67
68} // Anonymous namespace 68} // Anonymous namespace
69 69
70Swapchain::Swapchain(VkSurfaceKHR surface_, const Device& device_, Scheduler& scheduler_, u32 width, 70Swapchain::Swapchain(VkSurfaceKHR surface_, const Device& device_, Scheduler& scheduler_,
71 u32 height, bool srgb) 71 u32 width_, u32 height_, bool srgb)
72 : surface{surface_}, device{device_}, scheduler{scheduler_} { 72 : surface{surface_}, device{device_}, scheduler{scheduler_} {
73 Create(width, height, srgb); 73 Create(width_, height_, srgb);
74} 74}
75 75
76Swapchain::~Swapchain() = default; 76Swapchain::~Swapchain() = default;
77 77
78void Swapchain::Create(u32 width, u32 height, bool srgb) { 78void Swapchain::Create(u32 width_, u32 height_, bool srgb) {
79 is_outdated = false; 79 is_outdated = false;
80 is_suboptimal = false; 80 is_suboptimal = false;
81 width = width_;
82 height = height_;
81 83
82 const auto physical_device = device.GetPhysical(); 84 const auto physical_device = device.GetPhysical();
83 const auto capabilities{physical_device.GetSurfaceCapabilitiesKHR(surface)}; 85 const auto capabilities{physical_device.GetSurfaceCapabilitiesKHR(surface)};
@@ -88,7 +90,7 @@ void Swapchain::Create(u32 width, u32 height, bool srgb) {
88 device.GetLogical().WaitIdle(); 90 device.GetLogical().WaitIdle();
89 Destroy(); 91 Destroy();
90 92
91 CreateSwapchain(capabilities, width, height, srgb); 93 CreateSwapchain(capabilities, srgb);
92 CreateSemaphores(); 94 CreateSemaphores();
93 CreateImageViews(); 95 CreateImageViews();
94 96
@@ -148,8 +150,7 @@ void Swapchain::Present(VkSemaphore render_semaphore) {
148 } 150 }
149} 151}
150 152
151void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, u32 width, u32 height, 153void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, bool srgb) {
152 bool srgb) {
153 const auto physical_device{device.GetPhysical()}; 154 const auto physical_device{device.GetPhysical()};
154 const auto formats{physical_device.GetSurfaceFormatsKHR(surface)}; 155 const auto formats{physical_device.GetSurfaceFormatsKHR(surface)};
155 const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)}; 156 const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)};
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.h b/src/video_core/renderer_vulkan/vk_swapchain.h
index 111b3902d..caf1ff32b 100644
--- a/src/video_core/renderer_vulkan/vk_swapchain.h
+++ b/src/video_core/renderer_vulkan/vk_swapchain.h
@@ -80,9 +80,16 @@ public:
80 return *present_semaphores[frame_index]; 80 return *present_semaphores[frame_index];
81 } 81 }
82 82
83 u32 GetWidth() const {
84 return width;
85 }
86
87 u32 GetHeight() const {
88 return height;
89 }
90
83private: 91private:
84 void CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, u32 width, u32 height, 92 void CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, bool srgb);
85 bool srgb);
86 void CreateSemaphores(); 93 void CreateSemaphores();
87 void CreateImageViews(); 94 void CreateImageViews();
88 95
@@ -105,6 +112,9 @@ private:
105 std::vector<u64> resource_ticks; 112 std::vector<u64> resource_ticks;
106 std::vector<vk::Semaphore> present_semaphores; 113 std::vector<vk::Semaphore> present_semaphores;
107 114
115 u32 width;
116 u32 height;
117
108 u32 image_index{}; 118 u32 image_index{};
109 u32 frame_index{}; 119 u32 frame_index{};
110 120