From 5cfb2763ae0bd7a7eff679fa19565690be1abeb7 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 12 Jan 2020 20:29:31 -0800 Subject: Added DurationQueryHelper class; fixed issue with disjoint query in D3D11 backend --- .../include/DisjointQueryPool.h | 1 + .../src/DeviceContextD3D11Impl.cpp | 2 ++ .../GraphicsEngineD3D11/src/QueryD3D11Impl.cpp | 26 +++++++++++++--------- .../GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/DisjointQueryPool.h b/Graphics/GraphicsEngineD3D11/include/DisjointQueryPool.h index 5de5cc2a..c9d259ab 100644 --- a/Graphics/GraphicsEngineD3D11/include/DisjointQueryPool.h +++ b/Graphics/GraphicsEngineD3D11/include/DisjointQueryPool.h @@ -42,6 +42,7 @@ public: { DisjointQueryPool& Pool; CComPtr pd3d11Query; + bool IsEnded = false; DisjointQueryWrapper(DisjointQueryPool& _Pool, CComPtr&& _pd3d11Query) : diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 8009c9b0..d963c7b1 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -1152,6 +1152,7 @@ void DeviceContextD3D11Impl::FinishFrame() if (m_ActiveDisjointQuery) { m_pd3d11DeviceContext->End(m_ActiveDisjointQuery->pd3d11Query); + m_ActiveDisjointQuery->IsEnded = true; m_ActiveDisjointQuery.reset(); } } @@ -1838,6 +1839,7 @@ void DeviceContextD3D11Impl::EndQuery(IQuery* pQuery) m_ActiveDisjointQuery = m_DisjointQueryPool.GetDisjointQuery(m_pDevice->GetD3D11Device()); // Disjoint timestamp queries should only be invoked once per frame or less. m_pd3d11DeviceContext->Begin(m_ActiveDisjointQuery->pd3d11Query); + m_ActiveDisjointQuery->IsEnded = false; } pQueryD3D11Impl->SetDisjointQuery(m_ActiveDisjointQuery); } diff --git a/Graphics/GraphicsEngineD3D11/src/QueryD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/QueryD3D11Impl.cpp index a6335b13..751810de 100644 --- a/Graphics/GraphicsEngineD3D11/src/QueryD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/QueryD3D11Impl.cpp @@ -119,20 +119,24 @@ bool QueryD3D11Impl::GetData(void* pData, Uint32 DataSize, bool AutoInvalidate) VERIFY_EXPR(m_DisjointQuery); - UINT64 Counter = 0; - DataReady = pd3d11Ctx->GetData(m_pd3d11Query, &Counter, sizeof(Counter), 0) == S_OK; - - if (DataReady && pData != nullptr) + DataReady = m_DisjointQuery->IsEnded; + if (DataReady) { - D3D11_QUERY_DATA_TIMESTAMP_DISJOINT DisjointQueryData; - DataReady = pd3d11Ctx->GetData(m_DisjointQuery->pd3d11Query, &DisjointQueryData, sizeof(DisjointQueryData), 0) == S_OK; + UINT64 Counter = 0; + DataReady = pd3d11Ctx->GetData(m_pd3d11Query, &Counter, sizeof(Counter), 0) == S_OK; - if (DataReady) + if (DataReady && pData != nullptr) { - auto& QueryData = *reinterpret_cast(pData); - QueryData.Counter = Counter; - // The timestamp returned by ID3D11DeviceContext::GetData for a timestamp query is only reliable if Disjoint is FALSE. - QueryData.Frequency = DisjointQueryData.Disjoint ? 0 : DisjointQueryData.Frequency; + D3D11_QUERY_DATA_TIMESTAMP_DISJOINT DisjointQueryData; + DataReady = pd3d11Ctx->GetData(m_DisjointQuery->pd3d11Query, &DisjointQueryData, sizeof(DisjointQueryData), 0) == S_OK; + + if (DataReady) + { + auto& QueryData = *reinterpret_cast(pData); + QueryData.Counter = Counter; + // The timestamp returned by ID3D11DeviceContext::GetData for a timestamp query is only reliable if Disjoint is FALSE. + QueryData.Frequency = DisjointQueryData.Disjoint ? 0 : DisjointQueryData.Frequency; + } } } } diff --git a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp index 94497ca0..537064e5 100644 --- a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp @@ -133,6 +133,7 @@ void SwapChainD3D11Impl::Present(Uint32 SyncInterval) if (m_SwapChainDesc.IsPrimary) { + pImmediateCtxD3D11->FinishFrame(); // Clear the state caches to release all outstanding objects // that are only kept alive by references in the cache // It is better to do this before calling Present() as D3D11 -- cgit v1.2.3