From afb7ec3d734aac5e38eda0a96fba563415d3ae8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 15 Nov 2016 16:57:28 -0800 Subject: [PATCH] Cleanup. --- src/glcontext_wgl.cpp | 1 + src/renderer_d3d11.cpp | 24 +++++++++++++++--------- src/renderer_d3d9.cpp | 36 ++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/glcontext_wgl.cpp b/src/glcontext_wgl.cpp index eafee4f94..ca7195ea0 100644 --- a/src/glcontext_wgl.cpp +++ b/src/glcontext_wgl.cpp @@ -318,6 +318,7 @@ namespace bgfx { namespace gl void GlContext::destroySwapChain(SwapChainGL* _swapChain) { BX_DELETE(g_allocator, _swapChain); + wglMakeCurrent(m_hdc, m_context); } void GlContext::swap(SwapChainGL* _swapChain) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index e8439f4b0..672cadbc1 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -2261,18 +2261,24 @@ BX_PRAGMA_DIAGNOSTIC_POP(); hr = m_frameBuffers[m_windows[ii].idx].present(syncInterval); } - if (SUCCEEDED(hr) - && m_needPresent) + if (SUCCEEDED(hr) ) { - m_ovr.flip(); - m_ovr.swap(_hmd); - - if (!m_ovr.isEnabled() ) + if (m_needPresent) { - hr = m_swapChain->Present(syncInterval, 0); - } + m_ovr.flip(); + m_ovr.swap(_hmd); - m_needPresent = false; + if (!m_ovr.isEnabled() ) + { + hr = m_swapChain->Present(syncInterval, 0); + } + + m_needPresent = false; + } + else + { + m_deviceCtx->Flush(); + } } if (isLost(hr) ) diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index e24e54a7a..80663ad47 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -275,6 +275,18 @@ namespace bgfx { namespace d3d9 static PFN_D3DPERF_BEGIN_EVENT D3DPERF_BeginEvent; static PFN_D3DPERF_END_EVENT D3DPERF_EndEvent; + inline bool isLost(HRESULT _hr) + { + return false + || _hr == D3DERR_DEVICELOST + || _hr == D3DERR_DRIVERINTERNALERROR +#if !defined(D3D_DISABLE_9EX) + || _hr == D3DERR_DEVICEHUNG + || _hr == D3DERR_DEVICEREMOVED +#endif // !defined(D3D_DISABLE_9EX) + ; + } + struct RendererContextD3D9 : public RendererContextI { RendererContextD3D9() @@ -1413,15 +1425,10 @@ namespace bgfx { namespace d3d9 postReset(); } - static bool isLost(HRESULT _hr) + void flush() { - return D3DERR_DEVICELOST == _hr - || D3DERR_DRIVERINTERNALERROR == _hr -#if !defined(D3D_DISABLE_9EX) - || D3DERR_DEVICEHUNG == _hr - || D3DERR_DEVICEREMOVED == _hr -#endif // !defined(D3D_DISABLE_9EX) - ; + m_flushQuery->Issue(D3DISSUE_END); + m_flushQuery->GetData(NULL, 0, D3DGETDATA_FLUSH); } void flip(HMD& /*_hmd*/) BX_OVERRIDE @@ -1443,6 +1450,10 @@ namespace bgfx { namespace d3d9 hr = m_swapChain->Present(NULL, NULL, (HWND)g_platformData.nwh, NULL, 0); m_needPresent = false; } + else + { + flush(); + } } else { @@ -3465,8 +3476,10 @@ namespace bgfx { namespace d3d9 Frame& frame = m_frame[m_control.m_read]; uint64_t timeEnd; - HRESULT hr = frame.m_end->GetData(&timeEnd, sizeof(timeEnd), 0); - if (S_OK == hr) + const bool flush = BX_COUNTOF(m_frame)-1 == m_control.available(); + HRESULT hr = frame.m_end->GetData(&timeEnd, sizeof(timeEnd), flush ? D3DGETDATA_FLUSH : 0); + if (S_OK == hr + || isLost(hr) ) { m_control.consume(1); @@ -4194,8 +4207,7 @@ namespace bgfx { namespace d3d9 { if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) { - m_flushQuery->Issue(D3DISSUE_END); - m_flushQuery->GetData(NULL, 0, D3DGETDATA_FLUSH); + flush(); } captureElapsed = -bx::getHPCounter();