This commit is contained in:
Branimir Karadžić 2016-11-15 16:57:28 -08:00
parent a96372cd69
commit afb7ec3d73
3 changed files with 40 additions and 21 deletions

View File

@ -318,6 +318,7 @@ namespace bgfx { namespace gl
void GlContext::destroySwapChain(SwapChainGL* _swapChain) void GlContext::destroySwapChain(SwapChainGL* _swapChain)
{ {
BX_DELETE(g_allocator, _swapChain); BX_DELETE(g_allocator, _swapChain);
wglMakeCurrent(m_hdc, m_context);
} }
void GlContext::swap(SwapChainGL* _swapChain) void GlContext::swap(SwapChainGL* _swapChain)

View File

@ -2261,8 +2261,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
hr = m_frameBuffers[m_windows[ii].idx].present(syncInterval); hr = m_frameBuffers[m_windows[ii].idx].present(syncInterval);
} }
if (SUCCEEDED(hr) if (SUCCEEDED(hr) )
&& m_needPresent) {
if (m_needPresent)
{ {
m_ovr.flip(); m_ovr.flip();
m_ovr.swap(_hmd); m_ovr.swap(_hmd);
@ -2274,6 +2275,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
m_needPresent = false; m_needPresent = false;
} }
else
{
m_deviceCtx->Flush();
}
}
if (isLost(hr) ) if (isLost(hr) )
{ {

View File

@ -275,6 +275,18 @@ namespace bgfx { namespace d3d9
static PFN_D3DPERF_BEGIN_EVENT D3DPERF_BeginEvent; static PFN_D3DPERF_BEGIN_EVENT D3DPERF_BeginEvent;
static PFN_D3DPERF_END_EVENT D3DPERF_EndEvent; 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 struct RendererContextD3D9 : public RendererContextI
{ {
RendererContextD3D9() RendererContextD3D9()
@ -1413,15 +1425,10 @@ namespace bgfx { namespace d3d9
postReset(); postReset();
} }
static bool isLost(HRESULT _hr) void flush()
{ {
return D3DERR_DEVICELOST == _hr m_flushQuery->Issue(D3DISSUE_END);
|| D3DERR_DRIVERINTERNALERROR == _hr m_flushQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
#if !defined(D3D_DISABLE_9EX)
|| D3DERR_DEVICEHUNG == _hr
|| D3DERR_DEVICEREMOVED == _hr
#endif // !defined(D3D_DISABLE_9EX)
;
} }
void flip(HMD& /*_hmd*/) BX_OVERRIDE 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); hr = m_swapChain->Present(NULL, NULL, (HWND)g_platformData.nwh, NULL, 0);
m_needPresent = false; m_needPresent = false;
} }
else
{
flush();
}
} }
else else
{ {
@ -3465,8 +3476,10 @@ namespace bgfx { namespace d3d9
Frame& frame = m_frame[m_control.m_read]; Frame& frame = m_frame[m_control.m_read];
uint64_t timeEnd; uint64_t timeEnd;
HRESULT hr = frame.m_end->GetData(&timeEnd, sizeof(timeEnd), 0); const bool flush = BX_COUNTOF(m_frame)-1 == m_control.available();
if (S_OK == hr) HRESULT hr = frame.m_end->GetData(&timeEnd, sizeof(timeEnd), flush ? D3DGETDATA_FLUSH : 0);
if (S_OK == hr
|| isLost(hr) )
{ {
m_control.consume(1); m_control.consume(1);
@ -4194,8 +4207,7 @@ namespace bgfx { namespace d3d9
{ {
if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) )
{ {
m_flushQuery->Issue(D3DISSUE_END); flush();
m_flushQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
} }
captureElapsed = -bx::getHPCounter(); captureElapsed = -bx::getHPCounter();