diff --git a/common/Vulkan/Context.cpp b/common/Vulkan/Context.cpp index 3e4eba2db7..f6c6a41741 100644 --- a/common/Vulkan/Context.cpp +++ b/common/Vulkan/Context.cpp @@ -634,8 +634,14 @@ namespace Vulkan vkGetDeviceQueue(m_device, m_present_queue_family_index, 0, &m_present_queue); } - m_gpu_timing_supported = (queue_family_properties[m_graphics_queue_family_index].timestampValidBits > 0); - DevCon.WriteLn("GPU timing is %s", m_gpu_timing_supported ? "supported" : "not supported"); + m_gpu_timing_supported = (m_device_properties.limits.timestampComputeAndGraphics != 0 && + queue_family_properties[m_graphics_queue_family_index].timestampValidBits > 0 && + m_device_properties.limits.timestampPeriod > 0); + DevCon.WriteLn("GPU timing is %s (TS=%u TS valid bits=%u, TS period=%f)", + m_gpu_timing_supported ? "supported" : "not supported", + static_cast(m_device_properties.limits.timestampComputeAndGraphics), + queue_family_properties[m_graphics_queue_family_index].timestampValidBits, + m_device_properties.limits.timestampPeriod); ProcessDeviceExtensions(); return true; @@ -845,6 +851,7 @@ namespace Vulkan if (res != VK_SUCCESS) { LOG_VULKAN_ERROR(res, "vkCreateQueryPool failed: "); + m_gpu_timing_supported = false; return false; } } @@ -959,9 +966,10 @@ namespace Vulkan return time; } - void Context::SetEnableGPUTiming(bool enabled) + bool Context::SetEnableGPUTiming(bool enabled) { m_gpu_timing_enabled = enabled && m_gpu_timing_supported; + return (enabled == m_gpu_timing_enabled); } void Context::WaitForCommandBufferCompletion(u32 index) @@ -1199,8 +1207,8 @@ namespace Vulkan // if we didn't write the timestamp at the start of the cmdbuffer (just enabled timing), the first TS will be zero if (timestamps[0] > 0) { - const u64 ns_diff = (timestamps[1] - timestamps[0]) * static_cast(m_device_properties.limits.timestampPeriod); - m_accumulated_gpu_time += static_cast(ns_diff) / 1000000.0; + const double ns_diff = (timestamps[1] - timestamps[0]) * static_cast(m_device_properties.limits.timestampPeriod); + m_accumulated_gpu_time += ns_diff / 1000000.0; } } else diff --git a/common/Vulkan/Context.h b/common/Vulkan/Context.h index 75adc9df69..0483e89ab0 100644 --- a/common/Vulkan/Context.h +++ b/common/Vulkan/Context.h @@ -221,7 +221,7 @@ namespace Vulkan void WaitForGPUIdle(); float GetAndResetAccumulatedGPUTime(); - void SetEnableGPUTiming(bool enabled); + bool SetEnableGPUTiming(bool enabled); private: Context(VkInstance instance, VkPhysicalDevice physical_device); diff --git a/pcsx2-qt/EmuThread.cpp b/pcsx2-qt/EmuThread.cpp index b204908233..250639696c 100644 --- a/pcsx2-qt/EmuThread.cpp +++ b/pcsx2-qt/EmuThread.cpp @@ -47,7 +47,6 @@ #include "QtUtils.h" EmuThread* g_emu_thread = nullptr; -WindowInfo g_gs_window_info; static std::unique_ptr s_host_display; @@ -678,8 +677,6 @@ HostDisplay* EmuThread::acquireHostDisplay(HostDisplay::RenderAPI api) return nullptr; } - g_gs_window_info = s_host_display->GetWindowInfo(); - Console.WriteLn(Color_StrongGreen, "%s Graphics Driver Info:", HostDisplay::RenderAPIToString(s_host_display->GetRenderAPI())); Console.Indent().WriteLn(s_host_display->GetDriverInfo()); @@ -696,8 +693,6 @@ void EmuThread::releaseHostDisplay() s_host_display->DestroyRenderDevice(); } - g_gs_window_info = WindowInfo(); - emit onDestroyDisplayRequested(); s_host_display.reset(); diff --git a/pcsx2/Frontend/D3D11HostDisplay.cpp b/pcsx2/Frontend/D3D11HostDisplay.cpp index 7fa2cf5faf..d62a97cfa8 100644 --- a/pcsx2/Frontend/D3D11HostDisplay.cpp +++ b/pcsx2/Frontend/D3D11HostDisplay.cpp @@ -757,7 +757,7 @@ void D3D11HostDisplay::EndPresent() KickTimestampQuery(); } -void D3D11HostDisplay::CreateTimestampQueries() +bool D3D11HostDisplay::CreateTimestampQueries() { for (u32 i = 0; i < NUM_TIMESTAMP_QUERIES; i++) { @@ -768,12 +768,13 @@ void D3D11HostDisplay::CreateTimestampQueries() if (FAILED(hr)) { m_timestamp_queries = {}; - return; + return false; } } } KickTimestampQuery(); + return true; } void D3D11HostDisplay::DestroyTimestampQueries() @@ -835,7 +836,7 @@ void D3D11HostDisplay::PopTimestampQuery() void D3D11HostDisplay::KickTimestampQuery() { - if (m_timestamp_query_started) + if (m_timestamp_query_started || !m_timestamp_queries[0][0]) return; m_context->Begin(m_timestamp_queries[m_write_timestamp_query][0].Get()); @@ -843,16 +844,21 @@ void D3D11HostDisplay::KickTimestampQuery() m_timestamp_query_started = true; } -void D3D11HostDisplay::SetGPUTimingEnabled(bool enabled) +bool D3D11HostDisplay::SetGPUTimingEnabled(bool enabled) { if (m_gpu_timing_enabled == enabled) - return; + return true; m_gpu_timing_enabled = enabled; if (m_gpu_timing_enabled) - CreateTimestampQueries(); + { + return CreateTimestampQueries(); + } else + { DestroyTimestampQueries(); + return true; + } } float D3D11HostDisplay::GetAndResetAccumulatedGPUTime() diff --git a/pcsx2/Frontend/D3D11HostDisplay.h b/pcsx2/Frontend/D3D11HostDisplay.h index 3806bc6957..b16461901f 100644 --- a/pcsx2/Frontend/D3D11HostDisplay.h +++ b/pcsx2/Frontend/D3D11HostDisplay.h @@ -69,7 +69,7 @@ public: bool BeginPresent(bool frame_skip) override; void EndPresent() override; - void SetGPUTimingEnabled(bool enabled) override; + bool SetGPUTimingEnabled(bool enabled) override; float GetAndResetAccumulatedGPUTime() override; static AdapterAndModeList StaticGetAdapterAndModeList(); @@ -87,7 +87,7 @@ protected: bool CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode); bool CreateSwapChainRTV(); - void CreateTimestampQueries(); + bool CreateTimestampQueries(); void DestroyTimestampQueries(); void PopTimestampQuery(); void KickTimestampQuery(); diff --git a/pcsx2/Frontend/D3D12HostDisplay.cpp b/pcsx2/Frontend/D3D12HostDisplay.cpp index 7aef99871d..c1e591c0af 100644 --- a/pcsx2/Frontend/D3D12HostDisplay.cpp +++ b/pcsx2/Frontend/D3D12HostDisplay.cpp @@ -645,9 +645,10 @@ void D3D12HostDisplay::EndPresent() m_swap_chain->Present(static_cast(vsync), 0); } -void D3D12HostDisplay::SetGPUTimingEnabled(bool enabled) +bool D3D12HostDisplay::SetGPUTimingEnabled(bool enabled) { g_d3d12_context->SetEnableGPUTiming(enabled); + return true; } float D3D12HostDisplay::GetAndResetAccumulatedGPUTime() diff --git a/pcsx2/Frontend/D3D12HostDisplay.h b/pcsx2/Frontend/D3D12HostDisplay.h index 18857a1519..777fd6d05f 100644 --- a/pcsx2/Frontend/D3D12HostDisplay.h +++ b/pcsx2/Frontend/D3D12HostDisplay.h @@ -75,7 +75,7 @@ public: bool BeginPresent(bool frame_skip) override; void EndPresent() override; - void SetGPUTimingEnabled(bool enabled) override; + bool SetGPUTimingEnabled(bool enabled) override; float GetAndResetAccumulatedGPUTime() override; static AdapterAndModeList StaticGetAdapterAndModeList(); diff --git a/pcsx2/Frontend/OpenGLHostDisplay.cpp b/pcsx2/Frontend/OpenGLHostDisplay.cpp index 0bb262d7fb..27e4d26062 100644 --- a/pcsx2/Frontend/OpenGLHostDisplay.cpp +++ b/pcsx2/Frontend/OpenGLHostDisplay.cpp @@ -481,18 +481,21 @@ void OpenGLHostDisplay::KickTimestampQuery() m_timestamp_query_started = true; } -void OpenGLHostDisplay::SetGPUTimingEnabled(bool enabled) +bool OpenGLHostDisplay::SetGPUTimingEnabled(bool enabled) { - enabled &= (!m_gl_context->IsGLES() || GLAD_GL_EXT_disjoint_timer_query); - if (m_gpu_timing_enabled == enabled) - return; + return true; + + if (enabled && m_gl_context->IsGLES() && !GLAD_GL_EXT_disjoint_timer_query) + return false; m_gpu_timing_enabled = enabled; if (m_gpu_timing_enabled) CreateTimestampQueries(); else DestroyTimestampQueries(); + + return true; } float OpenGLHostDisplay::GetAndResetAccumulatedGPUTime() diff --git a/pcsx2/Frontend/OpenGLHostDisplay.h b/pcsx2/Frontend/OpenGLHostDisplay.h index 4f9e5184cb..26e4ccde9f 100644 --- a/pcsx2/Frontend/OpenGLHostDisplay.h +++ b/pcsx2/Frontend/OpenGLHostDisplay.h @@ -62,7 +62,7 @@ public: bool BeginPresent(bool frame_skip) override; void EndPresent() override; - void SetGPUTimingEnabled(bool enabled) override; + bool SetGPUTimingEnabled(bool enabled) override; float GetAndResetAccumulatedGPUTime() override; protected: diff --git a/pcsx2/Frontend/VulkanHostDisplay.cpp b/pcsx2/Frontend/VulkanHostDisplay.cpp index feb8db0834..370f315442 100644 --- a/pcsx2/Frontend/VulkanHostDisplay.cpp +++ b/pcsx2/Frontend/VulkanHostDisplay.cpp @@ -419,9 +419,9 @@ void VulkanHostDisplay::EndPresent() g_vulkan_context->MoveToNextCommandBuffer(); } -void VulkanHostDisplay::SetGPUTimingEnabled(bool enabled) +bool VulkanHostDisplay::SetGPUTimingEnabled(bool enabled) { - g_vulkan_context->SetEnableGPUTiming(enabled); + return g_vulkan_context->SetEnableGPUTiming(enabled); } float VulkanHostDisplay::GetAndResetAccumulatedGPUTime() diff --git a/pcsx2/Frontend/VulkanHostDisplay.h b/pcsx2/Frontend/VulkanHostDisplay.h index da297398b2..8e2bed555e 100644 --- a/pcsx2/Frontend/VulkanHostDisplay.h +++ b/pcsx2/Frontend/VulkanHostDisplay.h @@ -51,7 +51,7 @@ public: bool BeginPresent(bool frame_skip) override; void EndPresent() override; - void SetGPUTimingEnabled(bool enabled) override; + bool SetGPUTimingEnabled(bool enabled) override; float GetAndResetAccumulatedGPUTime() override; static AdapterAndModeList StaticGetAdapterAndModeList(const WindowInfo* wi); diff --git a/pcsx2/GS/GS.cpp b/pcsx2/GS/GS.cpp index 2436607ced..ed46f04eda 100644 --- a/pcsx2/GS/GS.cpp +++ b/pcsx2/GS/GS.cpp @@ -281,10 +281,10 @@ static bool DoGSOpen(GSRendererType renderer, u8* basemem) return false; } - g_gs_renderer->SetRegsMem(basemem); - display->SetVSync(EmuConfig.GetEffectiveVsyncMode()); - display->SetGPUTimingEnabled(GSConfig.OsdShowGPU); + GSConfig.OsdShowGPU = EmuConfig.GS.OsdShowGPU && display->SetGPUTimingEnabled(true); + + g_gs_renderer->SetRegsMem(basemem); return true; } @@ -861,7 +861,10 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config) if (GSConfig.OsdShowGPU != old_config.OsdShowGPU) { if (HostDisplay* display = Host::GetHostDisplay(); display) - display->SetGPUTimingEnabled(GSConfig.OsdShowGPU); + { + if (!display->SetGPUTimingEnabled(GSConfig.OsdShowGPU)) + GSConfig.OsdShowGPU = false; + } } } diff --git a/pcsx2/HostDisplay.cpp b/pcsx2/HostDisplay.cpp index 53434785ca..10dcf21e52 100644 --- a/pcsx2/HostDisplay.cpp +++ b/pcsx2/HostDisplay.cpp @@ -65,8 +65,9 @@ bool HostDisplay::GetHostRefreshRate(float* refresh_rate) return WindowInfo::QueryRefreshRateForWindow(m_window_info, refresh_rate); } -void HostDisplay::SetGPUTimingEnabled(bool enabled) +bool HostDisplay::SetGPUTimingEnabled(bool enabled) { + return false; } float HostDisplay::GetAndResetAccumulatedGPUTime() diff --git a/pcsx2/HostDisplay.h b/pcsx2/HostDisplay.h index 4c031f0fe2..7a82875165 100644 --- a/pcsx2/HostDisplay.h +++ b/pcsx2/HostDisplay.h @@ -136,7 +136,7 @@ public: virtual bool GetHostRefreshRate(float* refresh_rate); /// Enables/disables GPU frame timing. - virtual void SetGPUTimingEnabled(bool enabled); + virtual bool SetGPUTimingEnabled(bool enabled); /// Returns the amount of GPU time utilized since the last time this method was called. virtual float GetAndResetAccumulatedGPUTime();