From 0924bb469c86b9b25b05809d34194ad12d00cd02 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 2 Nov 2019 13:24:36 +0100 Subject: [PATCH] [d3d11] Move query state tracking to immediate context implementation --- src/d3d11/d3d11_cmdlist.cpp | 3 +++ src/d3d11/d3d11_context_imm.cpp | 5 ++++- src/d3d11/d3d11_query.cpp | 30 +++++++++++++++++------------- src/d3d11/d3d11_query.h | 9 +++++++++ 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/d3d11/d3d11_cmdlist.cpp b/src/d3d11/d3d11_cmdlist.cpp index 87863fbb7..d59d9b572 100644 --- a/src/d3d11/d3d11_cmdlist.cpp +++ b/src/d3d11/d3d11_cmdlist.cpp @@ -68,6 +68,9 @@ namespace dxvk { void D3D11CommandList::EmitToCsThread(DxvkCsThread* CsThread) { + for (const auto& query : m_queries) + query->DoDeferredEnd(); + for (const auto& chunk : m_chunks) CsThread->dispatchChunk(DxvkCsChunkRef(chunk)); diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index d55f97c6c..afd6a7c77 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -110,7 +110,7 @@ namespace dxvk { Com query(static_cast(pAsync)); - if (unlikely(!query->IsScoped())) + if (unlikely(!query->DoBegin())) return; EmitCs([cQuery = std::move(query)] @@ -128,6 +128,9 @@ namespace dxvk { Com query(static_cast(pAsync)); + if (unlikely(!query->DoEnd())) + return; + if (unlikely(query->IsEvent())) { query->NotifyEnd(); query->IsStalling() diff --git a/src/d3d11/d3d11_query.cpp b/src/d3d11/d3d11_query.cpp index 554be1445..b434a1c7b 100644 --- a/src/d3d11/d3d11_query.cpp +++ b/src/d3d11/d3d11_query.cpp @@ -182,9 +182,6 @@ namespace dxvk { void D3D11Query::Begin(DxvkContext* ctx) { - if (unlikely(m_state == D3D11_VK_QUERY_BEGUN)) - return; - switch (m_desc.Query) { case D3D11_QUERY_EVENT: case D3D11_QUERY_TIMESTAMP: @@ -197,8 +194,6 @@ namespace dxvk { default: ctx->beginQuery(m_query[0]); } - - m_state = D3D11_VK_QUERY_BEGUN; } @@ -214,19 +209,31 @@ namespace dxvk { break; default: - if (unlikely(m_state != D3D11_VK_QUERY_BEGUN)) - return; - ctx->endQuery(m_query[0]); } if (unlikely(m_predicate != nullptr)) ctx->writePredicate(DxvkBufferSlice(m_predicate), m_query[0]); - - m_state = D3D11_VK_QUERY_ENDED; } + bool STDMETHODCALLTYPE D3D11Query::DoBegin() { + if (!IsScoped() || m_state == D3D11_VK_QUERY_BEGUN) + return false; + + m_state = D3D11_VK_QUERY_BEGUN; + return true; + } + + bool STDMETHODCALLTYPE D3D11Query::DoEnd() { + if (IsScoped() && m_state != D3D11_VK_QUERY_BEGUN) + return false; + + m_state = D3D11_VK_QUERY_ENDED; + return true; + } + + HRESULT STDMETHODCALLTYPE D3D11Query::GetData( void* pData, UINT GetDataFlags) { @@ -327,9 +334,6 @@ namespace dxvk { if (unlikely(m_desc.Query != D3D11_QUERY_OCCLUSION_PREDICATE)) return DxvkBufferSlice(); - if (unlikely(m_state != D3D11_VK_QUERY_ENDED)) - return DxvkBufferSlice(); - if (unlikely(m_predicate != nullptr)) { m_predicate = CreatePredicateBuffer(); ctx->writePredicate(DxvkBufferSlice(m_predicate), m_query[0]); diff --git a/src/d3d11/d3d11_query.h b/src/d3d11/d3d11_query.h index 369d40168..c70cd837a 100644 --- a/src/d3d11/d3d11_query.h +++ b/src/d3d11/d3d11_query.h @@ -43,12 +43,21 @@ namespace dxvk { void End(DxvkContext* ctx); + bool STDMETHODCALLTYPE DoBegin(); + + bool STDMETHODCALLTYPE DoEnd(); + HRESULT STDMETHODCALLTYPE GetData( void* pData, UINT GetDataFlags); DxvkBufferSlice GetPredicate(DxvkContext* ctx); + void DoDeferredEnd() { + m_state = D3D11_VK_QUERY_ENDED; + m_resetCtr += 1; + } + bool IsScoped() const { return m_desc.Query != D3D11_QUERY_EVENT && m_desc.Query != D3D11_QUERY_TIMESTAMP;