From c1642d46d17a82eaa7c1fffa455f87cefa51f961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 5 Mar 2016 22:55:50 -0800 Subject: [PATCH] D3D11: Check for GPU timer support. --- src/renderer_d3d11.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 1f73327d8..27f1681a0 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -599,6 +599,7 @@ namespace bgfx { namespace d3d11 , m_vsChanges(0) , m_fsChanges(0) , m_rtMsaa(false) + , m_timerQuerySupport(false) , m_ovrRtv(NULL) , m_ovrDsv(NULL) { @@ -1193,6 +1194,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); | BGFX_CAPS_OCCLUSION_QUERY ); + m_timerQuerySupport = m_featureLevel >= D3D_FEATURE_LEVEL_9_3; + if (m_featureLevel <= D3D_FEATURE_LEVEL_9_2) { g_caps.maxTextureSize = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION; @@ -2021,7 +2024,10 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { ovrPreReset(); - m_gpuTimer.preReset(); + if (m_timerQuerySupport) + { + m_gpuTimer.preReset(); + } m_occlusionQuery.preReset(); if (NULL == g_platformData.backBufferDS) @@ -2066,7 +2072,10 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_RELEASE(color, 0); } - m_gpuTimer.postReset(); + if (m_timerQuerySupport) + { + m_gpuTimer.postReset(); + } m_occlusionQuery.postReset(); ovrPostReset(); @@ -3434,6 +3443,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); FrameBufferHandle m_fbh; bool m_rtMsaa; + bool m_timerQuerySupport; OVR m_ovr; TextureD3D11 m_ovrRT; @@ -4726,7 +4736,10 @@ BX_PRAGMA_DIAGNOSTIC_POP(); int64_t elapsed = -bx::getHPCounter(); int64_t captureElapsed = 0; - m_gpuTimer.begin(); + if (m_timerQuerySupport) + { + m_gpuTimer.begin(); + } if (0 < _render->m_iboffset) { @@ -5636,15 +5649,18 @@ BX_PRAGMA_DIAGNOSTIC_POP(); static double maxGpuElapsed = 0.0f; double elapsedGpuMs = 0.0; - m_gpuTimer.end(); - - while (m_gpuTimer.get() ) + if (m_timerQuerySupport) { - double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); - elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; - maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; + m_gpuTimer.end(); + + while (m_gpuTimer.get() ) + { + double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); + elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; + maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; + } + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); } - maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); const int64_t timerFreq = bx::getHPFrequency();