From ffb0104f60cd4152f84fe0cd5e1d9f51b82683c3 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 15 Apr 2019 22:47:22 -0700 Subject: Added ITextureUploader::GetStats method --- Graphics/GraphicsTools/include/TextureUploader.h | 23 ++++++++++++---- .../GraphicsTools/include/TextureUploaderD3D11.h | 2 ++ .../include/TextureUploaderD3D12_Vk.h | 2 ++ Graphics/GraphicsTools/include/TextureUploaderGL.h | 2 ++ .../GraphicsTools/src/TextureUploaderD3D11.cpp | 8 ++++++ .../GraphicsTools/src/TextureUploaderD3D12_Vk.cpp | 32 +++++++++++++++++----- Graphics/GraphicsTools/src/TextureUploaderGL.cpp | 8 ++++++ 7 files changed, 65 insertions(+), 12 deletions(-) (limited to 'Graphics/GraphicsTools') diff --git a/Graphics/GraphicsTools/include/TextureUploader.h b/Graphics/GraphicsTools/include/TextureUploader.h index 8066e0ca..dbc4383f 100644 --- a/Graphics/GraphicsTools/include/TextureUploader.h +++ b/Graphics/GraphicsTools/include/TextureUploader.h @@ -59,14 +59,27 @@ namespace Diligent }; + struct TextureUploaderStats + { + Uint32 NumPendingOperations = 0; + }; + class ITextureUploader : public IObject { public: - virtual void RenderThreadUpdate(IDeviceContext *pContext) = 0; - virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc, bool IsRenderThread, IUploadBuffer **ppBuffer) = 0; - virtual void ScheduleGPUCopy(ITexture *pDstTexture, Uint32 ArraySlice, Uint32 MipLevel, IUploadBuffer *pUploadBuffer) = 0; - virtual void RecycleBuffer(IUploadBuffer *pUploadBuffer) = 0; + virtual void RenderThreadUpdate(IDeviceContext* pContext) = 0; + + virtual void AllocateUploadBuffer(const UploadBufferDesc& Desc, + bool IsRenderThread, + IUploadBuffer** ppBuffer) = 0; + virtual void ScheduleGPUCopy(ITexture* pDstTexture, + Uint32 ArraySlice, + Uint32 MipLevel, + IUploadBuffer* pUploadBuffer) = 0; + virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer) = 0; + + virtual TextureUploaderStats GetStats() = 0; }; - void CreateTextureUploader(IRenderDevice *pDevice, const TextureUploaderDesc& Desc, ITextureUploader **ppUploader); + void CreateTextureUploader(IRenderDevice* pDevice, const TextureUploaderDesc& Desc, ITextureUploader** ppUploader); } diff --git a/Graphics/GraphicsTools/include/TextureUploaderD3D11.h b/Graphics/GraphicsTools/include/TextureUploaderD3D11.h index f6cec59d..a1274df5 100644 --- a/Graphics/GraphicsTools/include/TextureUploaderD3D11.h +++ b/Graphics/GraphicsTools/include/TextureUploaderD3D11.h @@ -45,6 +45,8 @@ namespace Diligent IUploadBuffer* pUploadBuffer)override final; virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer)override final; + virtual TextureUploaderStats GetStats()override final; + private: struct InternalData; std::unique_ptr m_pInternalData; diff --git a/Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h b/Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h index 585d0f37..6b8bc7e3 100644 --- a/Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h +++ b/Graphics/GraphicsTools/include/TextureUploaderD3D12_Vk.h @@ -45,6 +45,8 @@ namespace Diligent IUploadBuffer* pUploadBuffer)override final; virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer)override final; + virtual TextureUploaderStats GetStats()override final; + private: struct InternalData; std::unique_ptr m_pInternalData; diff --git a/Graphics/GraphicsTools/include/TextureUploaderGL.h b/Graphics/GraphicsTools/include/TextureUploaderGL.h index fd9d77e4..d8182d22 100644 --- a/Graphics/GraphicsTools/include/TextureUploaderGL.h +++ b/Graphics/GraphicsTools/include/TextureUploaderGL.h @@ -45,6 +45,8 @@ namespace Diligent IUploadBuffer* pUploadBuffer)override final; virtual void RecycleBuffer(IUploadBuffer* pUploadBuffer)override final; + virtual TextureUploaderStats GetStats()override final; + private: struct InternalData; std::unique_ptr m_pInternalData; diff --git a/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp b/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp index 17fffc39..162823d7 100644 --- a/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp +++ b/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp @@ -334,4 +334,12 @@ void TextureUploaderD3D11::RecycleBuffer(IUploadBuffer *pUploadBuffer) m_pInternalData->EnqueMap(pUploadBufferD3D11, InternalData::PendingBufferOperation::MapAndCache); } +TextureUploaderStats TextureUploaderD3D11::GetStats() +{ + TextureUploaderStats Stats; + std::lock_guard QueueLock(m_pInternalData->m_PendingOperationsMtx); + Stats.NumPendingOperations = static_cast(m_pInternalData->m_PendingOperations.size()); + return Stats; +} + } // namespace Diligent diff --git a/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp b/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp index b2c6e5e1..2888a65d 100644 --- a/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp +++ b/Graphics/GraphicsTools/src/TextureUploaderD3D12_Vk.cpp @@ -239,6 +239,12 @@ struct TextureUploaderD3D12_Vk::InternalData Deque.emplace_back(pUploadTexture); } + Uint32 GetNumPendingOperations() + { + std::lock_guard QueueLock(m_PendingOperationsMtx); + return static_cast(m_PendingOperations.size()); + } + private: std::mutex m_PendingOperationsMtx; std::vector m_PendingOperations; @@ -267,6 +273,7 @@ void TextureUploaderD3D12_Vk::RenderThreadUpdate(IDeviceContext* pContext) auto& InWorkOperations = m_pInternalData->SwapMapQueues(); if (!InWorkOperations.empty()) { + Uint32 NumCopyOperations = 0; for (auto& OperationInfo : InWorkOperations) { auto& pUploadTex = OperationInfo.pUploadTexture; @@ -295,19 +302,23 @@ void TextureUploaderD3D12_Vk::RenderThreadUpdate(IDeviceContext* pContext) CopyInfo.DstSlice = OperationInfo.DstSlice; CopyInfo.DstMipLevel = OperationInfo.DstMip; pContext->CopyTexture(CopyInfo); + ++NumCopyOperations; } break; } } - // The buffer may be recycled immediately after the copy scheduled is signaled, - // so we must signal the fence first. - auto SignaledFenceValue = m_pInternalData->SignalFence(pContext); - - for (auto& OperationInfo : InWorkOperations) + if (NumCopyOperations > 0) { - if (OperationInfo.operation == InternalData::PendingBufferOperation::Copy) - OperationInfo.pUploadTexture->SignalCopyScheduled(SignaledFenceValue); + // The buffer may be recycled immediately after the copy scheduled is signaled, + // so we must signal the fence first. + auto SignaledFenceValue = m_pInternalData->SignalFence(pContext); + + for (auto& OperationInfo : InWorkOperations) + { + if (OperationInfo.operation == InternalData::PendingBufferOperation::Copy) + OperationInfo.pUploadTexture->SignalCopyScheduled(SignaledFenceValue); + } } InWorkOperations.clear(); @@ -362,4 +373,11 @@ void TextureUploaderD3D12_Vk::RecycleBuffer(IUploadBuffer* pUploadBuffer) m_pInternalData->RecycleUploadTexture(pUploadTexture); } +TextureUploaderStats TextureUploaderD3D12_Vk::GetStats() +{ + TextureUploaderStats Stats; + Stats.NumPendingOperations = static_cast(m_pInternalData->GetNumPendingOperations()); + return Stats; +} + } // namespace Diligent diff --git a/Graphics/GraphicsTools/src/TextureUploaderGL.cpp b/Graphics/GraphicsTools/src/TextureUploaderGL.cpp index ff568f94..4171a822 100644 --- a/Graphics/GraphicsTools/src/TextureUploaderGL.cpp +++ b/Graphics/GraphicsTools/src/TextureUploaderGL.cpp @@ -278,4 +278,12 @@ void TextureUploaderGL::RecycleBuffer(IUploadBuffer *pUploadBuffer) Deque.emplace_back( pUploadBufferGL ); } +TextureUploaderStats TextureUploaderGL::GetStats() +{ + TextureUploaderStats Stats; + std::lock_guard QueueLock(m_pInternalData->m_PendingOperationsMtx); + Stats.NumPendingOperations = static_cast(m_pInternalData->m_PendingOperations.size()); + return Stats; +} + } // namespace Diligent -- cgit v1.2.3