GeneralSettings: Update vsync after settings close (#401)

This commit is contained in:
goeiecool9999 2022-10-31 17:54:26 +01:00 committed by GitHub
parent f41f7b63e8
commit c3182aedd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 29 deletions

View File

@ -352,14 +352,19 @@ void OpenGLRenderer::NotifyLatteCommandProcessorIdle()
glFlush(); glFlush();
} }
void OpenGLRenderer::EnableVSync(int state) void OpenGLRenderer::UpdateVSyncState()
{
int configValue = GetConfig().vsync.GetValue();
if(m_activeVSyncState != configValue)
{ {
#if BOOST_OS_WINDOWS #if BOOST_OS_WINDOWS
if(wglSwapIntervalEXT) if(wglSwapIntervalEXT)
wglSwapIntervalEXT(state); // 1 = enabled, 0 = disabled wglSwapIntervalEXT(configValue); // 1 = enabled, 0 = disabled
#else #else
cemuLog_log(LogType::Force, "OpenGL vsync not implemented"); cemuLog_log(LogType::Force, "OpenGL vsync not implemented");
#endif #endif
m_activeVSyncState = configValue;
}
} }
bool IsRunningInWine(); bool IsRunningInWine();
@ -438,6 +443,7 @@ void OpenGLRenderer::EnableDebugMode()
void OpenGLRenderer::SwapBuffers(bool swapTV, bool swapDRC) void OpenGLRenderer::SwapBuffers(bool swapTV, bool swapDRC)
{ {
GLCanvas_SwapBuffers(swapTV, swapDRC); GLCanvas_SwapBuffers(swapTV, swapDRC);
UpdateVSyncState();
if (swapTV) if (swapTV)
cleanupAfterFrame(); cleanupAfterFrame();

View File

@ -30,7 +30,7 @@ public:
void Flush(bool waitIdle = false) override; void Flush(bool waitIdle = false) override;
void NotifyLatteCommandProcessorIdle() override; void NotifyLatteCommandProcessorIdle() override;
void EnableVSync(int state) override; void UpdateVSyncState();
void EnableDebugMode() override; void EnableDebugMode() override;
void SwapBuffers(bool swapTV = true, bool swapDRC = true) override; void SwapBuffers(bool swapTV = true, bool swapDRC = true) override;
@ -168,6 +168,7 @@ private:
GLuint m_defaultFramebufferId; GLuint m_defaultFramebufferId;
GLuint m_pipeline = 0; GLuint m_pipeline = 0;
int m_activeVSyncState{};
bool m_isPadViewContext{}; bool m_isPadViewContext{};
// rendertarget viewport // rendertarget viewport

View File

@ -58,7 +58,6 @@ public:
virtual bool GetVRAMInfo(int& usageInMB, int& totalInMB) const; virtual bool GetVRAMInfo(int& usageInMB, int& totalInMB) const;
virtual void EnableDebugMode() {} virtual void EnableDebugMode() {}
virtual void EnableVSync(int state) = 0;
virtual void ClearColorbuffer(bool padView) = 0; virtual void ClearColorbuffer(bool padView) = 0;
virtual void DrawEmptyFrame(bool mainWindow) = 0; virtual void DrawEmptyFrame(bool mainWindow) = 0;

View File

@ -1382,22 +1382,22 @@ VkSurfaceFormatKHR VulkanRenderer::ChooseSwapSurfaceFormat(const std::vector<VkS
VkPresentModeKHR VulkanRenderer::ChooseSwapPresentMode(const std::vector<VkPresentModeKHR>& modes) VkPresentModeKHR VulkanRenderer::ChooseSwapPresentMode(const std::vector<VkPresentModeKHR>& modes)
{ {
m_vsync_state = (VSync)GetConfig().vsync.GetValue(); const auto vsyncState = (VSync)GetConfig().vsync.GetValue();
if (m_vsync_state == VSync::MAILBOX) if (vsyncState == VSync::MAILBOX)
{ {
if (std::find(modes.cbegin(), modes.cend(), VK_PRESENT_MODE_MAILBOX_KHR) != modes.cend()) if (std::find(modes.cbegin(), modes.cend(), VK_PRESENT_MODE_MAILBOX_KHR) != modes.cend())
return VK_PRESENT_MODE_MAILBOX_KHR; return VK_PRESENT_MODE_MAILBOX_KHR;
forceLog_printf("Vulkan: Can't find mailbox present mode"); forceLog_printf("Vulkan: Can't find mailbox present mode");
} }
else if (m_vsync_state == VSync::Immediate) else if (vsyncState == VSync::Immediate)
{ {
if (std::find(modes.cbegin(), modes.cend(), VK_PRESENT_MODE_IMMEDIATE_KHR) != modes.cend()) if (std::find(modes.cbegin(), modes.cend(), VK_PRESENT_MODE_IMMEDIATE_KHR) != modes.cend())
return VK_PRESENT_MODE_IMMEDIATE_KHR; return VK_PRESENT_MODE_IMMEDIATE_KHR;
forceLog_printf("Vulkan: Can't find immediate present mode"); forceLog_printf("Vulkan: Can't find immediate present mode");
} }
else if (m_vsync_state == VSync::SYNC_AND_LIMIT) else if (vsyncState == VSync::SYNC_AND_LIMIT)
{ {
LatteTiming_EnableHostDrivenVSync(); LatteTiming_EnableHostDrivenVSync();
// use immediate mode if available, other wise fall back to // use immediate mode if available, other wise fall back to
@ -1991,19 +1991,6 @@ void VulkanRenderer::QueryAvailableFormats()
} }
} }
void VulkanRenderer::EnableVSync(int state)
{
if (m_vsync_state == (VSync)state)
return;
m_vsync_state = (VSync)state;
// recreate spawn chains (vsync state is checked from config in ChooseSwapPresentMode)
RecreateSwapchain(true);
if (m_padSwapchainInfo)
RecreateSwapchain(false);
}
bool VulkanRenderer::ImguiBegin(bool mainWindow) bool VulkanRenderer::ImguiBegin(bool mainWindow)
{ {
if (!Renderer::ImguiBegin(mainWindow)) if (!Renderer::ImguiBegin(mainWindow))
@ -2962,6 +2949,16 @@ void VulkanRenderer::RecreateSwapchain(bool main_window)
ImguiInit(); ImguiInit();
} }
void VulkanRenderer::UpdateVSyncState(bool main_window)
{
auto& swapInfo = main_window ? *m_mainSwapchainInfo : *m_padSwapchainInfo;
const auto configValue = (VSync)GetConfig().vsync.GetValue();
if(swapInfo.m_activeVSyncState != configValue){
RecreateSwapchain(main_window);
swapInfo.m_activeVSyncState = configValue;
}
}
void VulkanRenderer::SwapBuffer(bool main_window) void VulkanRenderer::SwapBuffer(bool main_window)
{ {
auto& swapInfo = main_window ? *m_mainSwapchainInfo : *m_padSwapchainInfo; auto& swapInfo = main_window ? *m_mainSwapchainInfo : *m_padSwapchainInfo;
@ -2999,6 +2996,8 @@ void VulkanRenderer::SwapBuffer(bool main_window)
} }
} }
UpdateVSyncState(main_window);
auto& swapinfo = main_window ? *m_mainSwapchainInfo : *m_padSwapchainInfo; auto& swapinfo = main_window ? *m_mainSwapchainInfo : *m_padSwapchainInfo;
AcquireNextSwapchainImage(main_window); AcquireNextSwapchainImage(main_window);

View File

@ -195,8 +195,6 @@ public:
void QueryMemoryInfo(); void QueryMemoryInfo();
void QueryAvailableFormats(); void QueryAvailableFormats();
void EnableVSync(int state) override;
#if BOOST_OS_WINDOWS #if BOOST_OS_WINDOWS
static VkSurfaceKHR CreateWinSurface(VkInstance instance, HWND hwindow); static VkSurfaceKHR CreateWinSurface(VkInstance instance, HWND hwindow);
#endif #endif
@ -466,6 +464,7 @@ private:
VkExtent2D swapchainExtend{}; VkExtent2D swapchainExtend{};
uint32 swapchainImageIndex = (uint32)-1; uint32 swapchainImageIndex = (uint32)-1;
uint32 m_acquireIndex = 0; // increases with every successful vkAcquireNextImageKHR uint32 m_acquireIndex = 0; // increases with every successful vkAcquireNextImageKHR
VSync m_activeVSyncState = VSync::Immediate;
struct AcquireInfo struct AcquireInfo
{ {
@ -557,8 +556,8 @@ private:
static bool CheckDeviceExtensionSupport(const VkPhysicalDevice device, FeatureControl& info); static bool CheckDeviceExtensionSupport(const VkPhysicalDevice device, FeatureControl& info);
static std::vector<const char*> CheckInstanceExtensionSupport(FeatureControl& info); static std::vector<const char*> CheckInstanceExtensionSupport(FeatureControl& info);
void UpdateVSyncState(bool main_window);
void SwapBuffer(bool main_window); void SwapBuffer(bool main_window);
VSync m_vsync_state = VSync::Immediate;
struct SwapChainSupportDetails struct SwapChainSupportDetails
{ {

View File

@ -1334,8 +1334,9 @@ void GeneralSettings2::HandleGraphicsApiSelection()
m_vsync->AppendString(_("Off")); m_vsync->AppendString(_("Off"));
m_vsync->AppendString(_("Double buffering")); m_vsync->AppendString(_("Double buffering"));
m_vsync->AppendString(_("Triple buffering")); m_vsync->AppendString(_("Triple buffering"));
#if BOOST_OS_WINDOWS
m_vsync->AppendString(_("Match emulated display (Experimental)")); m_vsync->AppendString(_("Match emulated display (Experimental)"));
#endif
m_vsync->Select(selection); m_vsync->Select(selection);