GS: Don't show GPU OSD when timing init fails

This commit is contained in:
Connor McLaughlin 2022-05-18 00:24:17 +10:00 committed by refractionpcsx2
parent 1f5d2c49fc
commit fa3bd58b7f
14 changed files with 52 additions and 35 deletions

View File

@ -634,8 +634,14 @@ namespace Vulkan
vkGetDeviceQueue(m_device, m_present_queue_family_index, 0, &m_present_queue); 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); m_gpu_timing_supported = (m_device_properties.limits.timestampComputeAndGraphics != 0 &&
DevCon.WriteLn("GPU timing is %s", m_gpu_timing_supported ? "supported" : "not supported"); 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<u32>(m_device_properties.limits.timestampComputeAndGraphics),
queue_family_properties[m_graphics_queue_family_index].timestampValidBits,
m_device_properties.limits.timestampPeriod);
ProcessDeviceExtensions(); ProcessDeviceExtensions();
return true; return true;
@ -845,6 +851,7 @@ namespace Vulkan
if (res != VK_SUCCESS) if (res != VK_SUCCESS)
{ {
LOG_VULKAN_ERROR(res, "vkCreateQueryPool failed: "); LOG_VULKAN_ERROR(res, "vkCreateQueryPool failed: ");
m_gpu_timing_supported = false;
return false; return false;
} }
} }
@ -959,9 +966,10 @@ namespace Vulkan
return time; return time;
} }
void Context::SetEnableGPUTiming(bool enabled) bool Context::SetEnableGPUTiming(bool enabled)
{ {
m_gpu_timing_enabled = enabled && m_gpu_timing_supported; m_gpu_timing_enabled = enabled && m_gpu_timing_supported;
return (enabled == m_gpu_timing_enabled);
} }
void Context::WaitForCommandBufferCompletion(u32 index) 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 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) if (timestamps[0] > 0)
{ {
const u64 ns_diff = (timestamps[1] - timestamps[0]) * static_cast<u64>(m_device_properties.limits.timestampPeriod); const double ns_diff = (timestamps[1] - timestamps[0]) * static_cast<double>(m_device_properties.limits.timestampPeriod);
m_accumulated_gpu_time += static_cast<double>(ns_diff) / 1000000.0; m_accumulated_gpu_time += ns_diff / 1000000.0;
} }
} }
else else

View File

@ -221,7 +221,7 @@ namespace Vulkan
void WaitForGPUIdle(); void WaitForGPUIdle();
float GetAndResetAccumulatedGPUTime(); float GetAndResetAccumulatedGPUTime();
void SetEnableGPUTiming(bool enabled); bool SetEnableGPUTiming(bool enabled);
private: private:
Context(VkInstance instance, VkPhysicalDevice physical_device); Context(VkInstance instance, VkPhysicalDevice physical_device);

View File

@ -47,7 +47,6 @@
#include "QtUtils.h" #include "QtUtils.h"
EmuThread* g_emu_thread = nullptr; EmuThread* g_emu_thread = nullptr;
WindowInfo g_gs_window_info;
static std::unique_ptr<HostDisplay> s_host_display; static std::unique_ptr<HostDisplay> s_host_display;
@ -678,8 +677,6 @@ HostDisplay* EmuThread::acquireHostDisplay(HostDisplay::RenderAPI api)
return nullptr; 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.WriteLn(Color_StrongGreen, "%s Graphics Driver Info:", HostDisplay::RenderAPIToString(s_host_display->GetRenderAPI()));
Console.Indent().WriteLn(s_host_display->GetDriverInfo()); Console.Indent().WriteLn(s_host_display->GetDriverInfo());
@ -696,8 +693,6 @@ void EmuThread::releaseHostDisplay()
s_host_display->DestroyRenderDevice(); s_host_display->DestroyRenderDevice();
} }
g_gs_window_info = WindowInfo();
emit onDestroyDisplayRequested(); emit onDestroyDisplayRequested();
s_host_display.reset(); s_host_display.reset();

View File

@ -757,7 +757,7 @@ void D3D11HostDisplay::EndPresent()
KickTimestampQuery(); KickTimestampQuery();
} }
void D3D11HostDisplay::CreateTimestampQueries() bool D3D11HostDisplay::CreateTimestampQueries()
{ {
for (u32 i = 0; i < NUM_TIMESTAMP_QUERIES; i++) for (u32 i = 0; i < NUM_TIMESTAMP_QUERIES; i++)
{ {
@ -768,12 +768,13 @@ void D3D11HostDisplay::CreateTimestampQueries()
if (FAILED(hr)) if (FAILED(hr))
{ {
m_timestamp_queries = {}; m_timestamp_queries = {};
return; return false;
} }
} }
} }
KickTimestampQuery(); KickTimestampQuery();
return true;
} }
void D3D11HostDisplay::DestroyTimestampQueries() void D3D11HostDisplay::DestroyTimestampQueries()
@ -835,7 +836,7 @@ void D3D11HostDisplay::PopTimestampQuery()
void D3D11HostDisplay::KickTimestampQuery() void D3D11HostDisplay::KickTimestampQuery()
{ {
if (m_timestamp_query_started) if (m_timestamp_query_started || !m_timestamp_queries[0][0])
return; return;
m_context->Begin(m_timestamp_queries[m_write_timestamp_query][0].Get()); m_context->Begin(m_timestamp_queries[m_write_timestamp_query][0].Get());
@ -843,16 +844,21 @@ void D3D11HostDisplay::KickTimestampQuery()
m_timestamp_query_started = true; m_timestamp_query_started = true;
} }
void D3D11HostDisplay::SetGPUTimingEnabled(bool enabled) bool D3D11HostDisplay::SetGPUTimingEnabled(bool enabled)
{ {
if (m_gpu_timing_enabled == enabled) if (m_gpu_timing_enabled == enabled)
return; return true;
m_gpu_timing_enabled = enabled; m_gpu_timing_enabled = enabled;
if (m_gpu_timing_enabled) if (m_gpu_timing_enabled)
CreateTimestampQueries(); {
return CreateTimestampQueries();
}
else else
{
DestroyTimestampQueries(); DestroyTimestampQueries();
return true;
}
} }
float D3D11HostDisplay::GetAndResetAccumulatedGPUTime() float D3D11HostDisplay::GetAndResetAccumulatedGPUTime()

View File

@ -69,7 +69,7 @@ public:
bool BeginPresent(bool frame_skip) override; bool BeginPresent(bool frame_skip) override;
void EndPresent() override; void EndPresent() override;
void SetGPUTimingEnabled(bool enabled) override; bool SetGPUTimingEnabled(bool enabled) override;
float GetAndResetAccumulatedGPUTime() override; float GetAndResetAccumulatedGPUTime() override;
static AdapterAndModeList StaticGetAdapterAndModeList(); static AdapterAndModeList StaticGetAdapterAndModeList();
@ -87,7 +87,7 @@ protected:
bool CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode); bool CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode);
bool CreateSwapChainRTV(); bool CreateSwapChainRTV();
void CreateTimestampQueries(); bool CreateTimestampQueries();
void DestroyTimestampQueries(); void DestroyTimestampQueries();
void PopTimestampQuery(); void PopTimestampQuery();
void KickTimestampQuery(); void KickTimestampQuery();

View File

@ -645,9 +645,10 @@ void D3D12HostDisplay::EndPresent()
m_swap_chain->Present(static_cast<UINT>(vsync), 0); m_swap_chain->Present(static_cast<UINT>(vsync), 0);
} }
void D3D12HostDisplay::SetGPUTimingEnabled(bool enabled) bool D3D12HostDisplay::SetGPUTimingEnabled(bool enabled)
{ {
g_d3d12_context->SetEnableGPUTiming(enabled); g_d3d12_context->SetEnableGPUTiming(enabled);
return true;
} }
float D3D12HostDisplay::GetAndResetAccumulatedGPUTime() float D3D12HostDisplay::GetAndResetAccumulatedGPUTime()

View File

@ -75,7 +75,7 @@ public:
bool BeginPresent(bool frame_skip) override; bool BeginPresent(bool frame_skip) override;
void EndPresent() override; void EndPresent() override;
void SetGPUTimingEnabled(bool enabled) override; bool SetGPUTimingEnabled(bool enabled) override;
float GetAndResetAccumulatedGPUTime() override; float GetAndResetAccumulatedGPUTime() override;
static AdapterAndModeList StaticGetAdapterAndModeList(); static AdapterAndModeList StaticGetAdapterAndModeList();

View File

@ -481,18 +481,21 @@ void OpenGLHostDisplay::KickTimestampQuery()
m_timestamp_query_started = true; 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) 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; m_gpu_timing_enabled = enabled;
if (m_gpu_timing_enabled) if (m_gpu_timing_enabled)
CreateTimestampQueries(); CreateTimestampQueries();
else else
DestroyTimestampQueries(); DestroyTimestampQueries();
return true;
} }
float OpenGLHostDisplay::GetAndResetAccumulatedGPUTime() float OpenGLHostDisplay::GetAndResetAccumulatedGPUTime()

View File

@ -62,7 +62,7 @@ public:
bool BeginPresent(bool frame_skip) override; bool BeginPresent(bool frame_skip) override;
void EndPresent() override; void EndPresent() override;
void SetGPUTimingEnabled(bool enabled) override; bool SetGPUTimingEnabled(bool enabled) override;
float GetAndResetAccumulatedGPUTime() override; float GetAndResetAccumulatedGPUTime() override;
protected: protected:

View File

@ -419,9 +419,9 @@ void VulkanHostDisplay::EndPresent()
g_vulkan_context->MoveToNextCommandBuffer(); 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() float VulkanHostDisplay::GetAndResetAccumulatedGPUTime()

View File

@ -51,7 +51,7 @@ public:
bool BeginPresent(bool frame_skip) override; bool BeginPresent(bool frame_skip) override;
void EndPresent() override; void EndPresent() override;
void SetGPUTimingEnabled(bool enabled) override; bool SetGPUTimingEnabled(bool enabled) override;
float GetAndResetAccumulatedGPUTime() override; float GetAndResetAccumulatedGPUTime() override;
static AdapterAndModeList StaticGetAdapterAndModeList(const WindowInfo* wi); static AdapterAndModeList StaticGetAdapterAndModeList(const WindowInfo* wi);

View File

@ -281,10 +281,10 @@ static bool DoGSOpen(GSRendererType renderer, u8* basemem)
return false; return false;
} }
g_gs_renderer->SetRegsMem(basemem);
display->SetVSync(EmuConfig.GetEffectiveVsyncMode()); display->SetVSync(EmuConfig.GetEffectiveVsyncMode());
display->SetGPUTimingEnabled(GSConfig.OsdShowGPU); GSConfig.OsdShowGPU = EmuConfig.GS.OsdShowGPU && display->SetGPUTimingEnabled(true);
g_gs_renderer->SetRegsMem(basemem);
return true; return true;
} }
@ -861,7 +861,10 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config)
if (GSConfig.OsdShowGPU != old_config.OsdShowGPU) if (GSConfig.OsdShowGPU != old_config.OsdShowGPU)
{ {
if (HostDisplay* display = Host::GetHostDisplay(); display) if (HostDisplay* display = Host::GetHostDisplay(); display)
display->SetGPUTimingEnabled(GSConfig.OsdShowGPU); {
if (!display->SetGPUTimingEnabled(GSConfig.OsdShowGPU))
GSConfig.OsdShowGPU = false;
}
} }
} }

View File

@ -65,8 +65,9 @@ bool HostDisplay::GetHostRefreshRate(float* refresh_rate)
return WindowInfo::QueryRefreshRateForWindow(m_window_info, 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() float HostDisplay::GetAndResetAccumulatedGPUTime()

View File

@ -136,7 +136,7 @@ public:
virtual bool GetHostRefreshRate(float* refresh_rate); virtual bool GetHostRefreshRate(float* refresh_rate);
/// Enables/disables GPU frame timing. /// 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. /// Returns the amount of GPU time utilized since the last time this method was called.
virtual float GetAndResetAccumulatedGPUTime(); virtual float GetAndResetAccumulatedGPUTime();