Преглед изворни кода

D3D11: Check for GPU timer support.

Branimir Karadžić пре 9 година
родитељ
комит
c1642d46d1
1 измењених фајлова са 26 додато и 10 уклоњено
  1. 26 10
      src/renderer_d3d11.cpp

+ 26 - 10
src/renderer_d3d11.cpp

@@ -599,6 +599,7 @@ namespace bgfx { namespace d3d11
 			, m_vsChanges(0)
 			, m_vsChanges(0)
 			, m_fsChanges(0)
 			, m_fsChanges(0)
 			, m_rtMsaa(false)
 			, m_rtMsaa(false)
+			, m_timerQuerySupport(false)
 			, m_ovrRtv(NULL)
 			, m_ovrRtv(NULL)
 			, m_ovrDsv(NULL)
 			, m_ovrDsv(NULL)
 		{
 		{
@@ -1193,6 +1194,8 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 					| BGFX_CAPS_OCCLUSION_QUERY
 					| BGFX_CAPS_OCCLUSION_QUERY
 					);
 					);
 
 
+				m_timerQuerySupport = m_featureLevel >= D3D_FEATURE_LEVEL_9_3;
+
 				if (m_featureLevel <= D3D_FEATURE_LEVEL_9_2)
 				if (m_featureLevel <= D3D_FEATURE_LEVEL_9_2)
 				{
 				{
 					g_caps.maxTextureSize   = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
 					g_caps.maxTextureSize   = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
@@ -2021,7 +2024,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 		{
 		{
 			ovrPreReset();
 			ovrPreReset();
 
 
-			m_gpuTimer.preReset();
+			if (m_timerQuerySupport)
+			{
+				m_gpuTimer.preReset();
+			}
 			m_occlusionQuery.preReset();
 			m_occlusionQuery.preReset();
 
 
 			if (NULL == g_platformData.backBufferDS)
 			if (NULL == g_platformData.backBufferDS)
@@ -2066,7 +2072,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 				DX_RELEASE(color, 0);
 				DX_RELEASE(color, 0);
 			}
 			}
 
 
-			m_gpuTimer.postReset();
+			if (m_timerQuerySupport)
+			{
+				m_gpuTimer.postReset();
+			}
 			m_occlusionQuery.postReset();
 			m_occlusionQuery.postReset();
 
 
 			ovrPostReset();
 			ovrPostReset();
@@ -3434,6 +3443,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 
 
 		FrameBufferHandle m_fbh;
 		FrameBufferHandle m_fbh;
 		bool m_rtMsaa;
 		bool m_rtMsaa;
+		bool m_timerQuerySupport;
 
 
 		OVR m_ovr;
 		OVR m_ovr;
 		TextureD3D11 m_ovrRT;
 		TextureD3D11 m_ovrRT;
@@ -4726,7 +4736,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 		int64_t elapsed = -bx::getHPCounter();
 		int64_t elapsed = -bx::getHPCounter();
 		int64_t captureElapsed = 0;
 		int64_t captureElapsed = 0;
 
 
-		m_gpuTimer.begin();
+		if (m_timerQuerySupport)
+		{
+			m_gpuTimer.begin();
+		}
 
 
 		if (0 < _render->m_iboffset)
 		if (0 < _render->m_iboffset)
 		{
 		{
@@ -5636,15 +5649,18 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 		static double   maxGpuElapsed = 0.0f;
 		static double   maxGpuElapsed = 0.0f;
 		double elapsedGpuMs = 0.0;
 		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();
 		const int64_t timerFreq = bx::getHPFrequency();