From 8fe180b3b2a179eb71d937ac65d12beb70b78a50 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 16 Apr 2019 08:19:27 -0700 Subject: Added validation to texture uploader dtors; updated pending operations counting in TextureUploaderD3D11 --- Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp | 18 +++++++++++++++++- Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp | 9 +++++++++ Graphics/GraphicsTools/src/TextureUploaderGL.cpp | 9 +++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsTools') diff --git a/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp b/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp index 162823d7..3d21df48 100644 --- a/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp +++ b/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp @@ -183,6 +183,15 @@ TextureUploaderD3D11::TextureUploaderD3D11(IReferenceCounters *pRefCounters, IRe TextureUploaderD3D11::~TextureUploaderD3D11() { + auto Stats = TextureUploaderD3D11::GetStats(); + if (Stats.NumPendingOperations != 0) + { + LOG_WARNING_MESSAGE("TextureUploaderD3D11::~TextureUploaderD3D11(): there ", (Stats.NumPendingOperations > 1 ? "are " : "is "), + Stats.NumPendingOperations, (Stats.NumPendingOperations > 1 ? " pending operations" : " pending operation"), + " in the queue. If other threads wait for ", (Stats.NumPendingOperations > 1 ? "these operations" : "this operation"), + ", they may deadlock."); + } + for (auto BuffQueueIt : m_pInternalData->m_UploadBufferCache) { if (BuffQueueIt.second.size()) @@ -338,7 +347,14 @@ TextureUploaderStats TextureUploaderD3D11::GetStats() { TextureUploaderStats Stats; std::lock_guard QueueLock(m_pInternalData->m_PendingOperationsMtx); - Stats.NumPendingOperations = static_cast(m_pInternalData->m_PendingOperations.size()); + for (auto &OperationInfo : m_pInternalData->m_PendingOperations) + { + // Do not count MapAndCache operations as they are performed as part of the + // buffer recycling. + if (OperationInfo.operation == InternalData::PendingBufferOperation::Map || + OperationInfo.operation == InternalData::PendingBufferOperation::Copy) + ++Stats.NumPendingOperations; + } return Stats; } diff --git a/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp b/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp index 2888a65d..775c9523 100644 --- a/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp +++ b/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp @@ -266,6 +266,15 @@ TextureUploaderD3D12_Vk::TextureUploaderD3D12_Vk(IReferenceCounters* pRefCounter TextureUploaderD3D12_Vk::~TextureUploaderD3D12_Vk() { + auto NumPendingOperations = m_pInternalData->GetNumPendingOperations(); + if (NumPendingOperations != 0) + { + LOG_WARNING_MESSAGE("TextureUploaderD3D12_Vk::~TextureUploaderD3D12_Vk(): there ", (NumPendingOperations > 1 ? "are " : "is "), + NumPendingOperations, (NumPendingOperations > 1 ? " pending operations" : " pending operation"), + " in the queue. If other threads wait for ", (NumPendingOperations > 1 ? "these operations" : "this operation"), + ", they may deadlock."); + + } } void TextureUploaderD3D12_Vk::RenderThreadUpdate(IDeviceContext* pContext) diff --git a/Graphics/GraphicsTools/src/TextureUploaderGL.cpp b/Graphics/GraphicsTools/src/TextureUploaderGL.cpp index 4171a822..2ba1301c 100644 --- a/Graphics/GraphicsTools/src/TextureUploaderGL.cpp +++ b/Graphics/GraphicsTools/src/TextureUploaderGL.cpp @@ -152,6 +152,15 @@ TextureUploaderGL::TextureUploaderGL(IReferenceCounters *pRefCounters, IRenderDe TextureUploaderGL::~TextureUploaderGL() { + auto Stats = TextureUploaderGL::GetStats(); + if (Stats.NumPendingOperations != 0) + { + LOG_WARNING_MESSAGE("TextureUploaderGL::~TextureUploaderGL(): there ", (Stats.NumPendingOperations > 1 ? "are " : "is "), + Stats.NumPendingOperations, (Stats.NumPendingOperations > 1 ? " pending operations" : " pending operation"), + " in the queue. If other threads wait for ", (Stats.NumPendingOperations > 1 ? "these operations" : "this operation"), + ", they may deadlock."); + } + for (auto BuffQueueIt : m_pInternalData->m_UploadBufferCache) { if (BuffQueueIt.second.size()) -- cgit v1.2.3