Branimir Karadžić 9 年之前
父節點
當前提交
afb7ec3d73
共有 3 個文件被更改,包括 39 次插入20 次删除
  1. 1 0
      src/glcontext_wgl.cpp
  2. 14 8
      src/renderer_d3d11.cpp
  3. 24 12
      src/renderer_d3d9.cpp

+ 1 - 0
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)

+ 14 - 8
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_needPresent)
+					{
+						m_ovr.flip();
+						m_ovr.swap(_hmd);
 
-					if (!m_ovr.isEnabled() )
+						if (!m_ovr.isEnabled() )
+						{
+							hr = m_swapChain->Present(syncInterval, 0);
+						}
+
+						m_needPresent = false;
+					}
+					else
 					{
-						hr = m_swapChain->Present(syncInterval, 0);
+						m_deviceCtx->Flush();
 					}
-
-					m_needPresent = false;
 				}
 
 				if (isLost(hr) )

+ 24 - 12
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();