Просмотр исходного кода

D3D12: Fixed command allocator leak.

Branimir Karadžić 10 лет назад
Родитель
Сommit
cfb8e8a13a
2 измененных файлов с 12 добавлено и 3 удалено
  1. 8 1
      src/renderer_d3d12.cpp
  2. 4 2
      src/renderer_d3d12.h

+ 8 - 1
src/renderer_d3d12.cpp

@@ -1243,7 +1243,7 @@ namespace bgfx { namespace d3d12
 
 		void preReset()
 		{
-			finish();
+			finishAll();
 
 			for (uint32_t ii = 0, num = m_scd.BufferCount; ii < num; ++ii)
 			{
@@ -2191,6 +2191,13 @@ data.NumQualityLevels = 0;
 			m_commandList = NULL;
 		}
 
+		void finishAll()
+		{
+			uint64_t fence = m_cmd.kick();
+			m_cmd.finish(fence, true);
+			m_commandList = NULL;
+		}
+
 		void* m_d3d12dll;
 		void* m_dxgidll;
 

+ 4 - 2
src/renderer_d3d12.h

@@ -366,6 +366,7 @@ namespace bgfx { namespace d3d12
 			}
 
 			CommandList& commandList = m_commandList[m_control.m_current];
+			DX_CHECK(commandList.m_commandAllocator->Reset() );
 			DX_CHECK(commandList.m_commandList->Reset(commandList.m_commandAllocator, NULL) );
 			return commandList.m_commandList;
 		}
@@ -388,7 +389,7 @@ namespace bgfx { namespace d3d12
 			return fence;
 		}
 
-		void finish(uint64_t _waitFence = UINT64_MAX)
+		void finish(uint64_t _waitFence = UINT64_MAX, bool _finishAll = false)
 		{
 			while (0 < m_control.available() )
 			{
@@ -401,7 +402,8 @@ namespace bgfx { namespace d3d12
 
 				m_control.consume(1);
 
-				if (_waitFence <= m_completedFence)
+				if (!_finishAll
+				&&  _waitFence <= m_completedFence)
 				{
 					return;
 				}