From ca717eeb62a8583bd601e541daf64faad5d9b555 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 14 Apr 2019 16:27:15 +0200 Subject: [PATCH] [d3d11] Track query state correctly Not sure if any game actually needs this, but we should avoid sending bogus commands to the backend when the app sends bogus commands to us. --- src/d3d11/d3d11_query.cpp | 14 ++++++++++++++ src/d3d11/d3d11_query.h | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/d3d11/d3d11_query.cpp b/src/d3d11/d3d11_query.cpp index ccafb6207..85a8c9286 100644 --- a/src/d3d11/d3d11_query.cpp +++ b/src/d3d11/d3d11_query.cpp @@ -7,6 +7,7 @@ namespace dxvk { D3D11Device* device, const D3D11_QUERY_DESC& desc) : m_device(device), m_desc(desc), + m_state(D3D11_VK_QUERY_INITIAL), m_d3d10(this, device->GetD3D10Interface()) { Rc dxvkDevice = m_device->GetDXVKDevice(); @@ -171,6 +172,9 @@ 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: @@ -180,6 +184,8 @@ namespace dxvk { default: ctx->beginQuery(m_query); } + + m_state = D3D11_VK_QUERY_BEGUN; } @@ -197,11 +203,16 @@ namespace dxvk { break; default: + if (unlikely(m_state != D3D11_VK_QUERY_BEGUN)) + return; + ctx->endQuery(m_query); } if (m_predicate.defined()) ctx->writePredicate(m_predicate, m_query); + + m_state = D3D11_VK_QUERY_ENDED; } @@ -305,6 +316,9 @@ 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.defined())) { m_predicate = m_device->AllocPredicateSlice(); ctx->writePredicate(m_predicate, m_query); diff --git a/src/d3d11/d3d11_query.h b/src/d3d11/d3d11_query.h index 1e102cb4b..3b5b98f17 100644 --- a/src/d3d11/d3d11_query.h +++ b/src/d3d11/d3d11_query.h @@ -9,6 +9,12 @@ namespace dxvk { + enum D3D11_VK_QUERY_STATE : uint32_t { + D3D11_VK_QUERY_INITIAL, + D3D11_VK_QUERY_BEGUN, + D3D11_VK_QUERY_ENDED, + }; + class D3D11Query : public D3D11DeviceChild { public: @@ -49,6 +55,8 @@ namespace dxvk { D3D11Device* const m_device; D3D11_QUERY_DESC m_desc; + + D3D11_VK_QUERY_STATE m_state; Rc m_query = nullptr; Rc m_event = nullptr;