From 5ecfbd84256d0554bcf4da4670a7ee7e0aee2b31 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 17 Oct 2018 17:19:07 +0200 Subject: [PATCH] [d3d11] Do not use QueryInterface to get query pointers We're not going to implement counters anyway, so this is unnecessary overhead. --- src/d3d11/d3d11_context.cpp | 42 +++++++++++++-------------------- src/d3d11/d3d11_context_imm.cpp | 20 +++++----------- 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index b691e2046..621bb7fe7 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -226,18 +226,13 @@ namespace dxvk { if (!pAsync) return; - Com query; - - if (SUCCEEDED(pAsync->QueryInterface(__uuidof(ID3D11Query), reinterpret_cast(&query)))) { - Com queryPtr = static_cast(query.ptr()); + Com queryPtr = static_cast(pAsync); - if (queryPtr->HasBeginEnabled()) { - const uint32_t revision = queryPtr->Reset(); - - EmitCs([revision, queryPtr] (DxvkContext* ctx) { - queryPtr->Begin(ctx, revision); - }); - } + if (queryPtr->HasBeginEnabled()) { + uint32_t revision = queryPtr->Reset(); + EmitCs([revision, queryPtr] (DxvkContext* ctx) { + queryPtr->Begin(ctx, revision); + }); } } @@ -246,22 +241,17 @@ namespace dxvk { if (!pAsync) return; - Com query; + Com queryPtr = static_cast(pAsync); - if (SUCCEEDED(pAsync->QueryInterface(__uuidof(ID3D11Query), reinterpret_cast(&query)))) { - Com queryPtr = static_cast(query.ptr()); - - if (queryPtr->HasBeginEnabled()) { - EmitCs([queryPtr] (DxvkContext* ctx) { - queryPtr->End(ctx); - }); - } else { - const uint32_t revision = queryPtr->Reset(); - - EmitCs([revision, queryPtr] (DxvkContext* ctx) { - queryPtr->Signal(ctx, revision); - }); - } + if (queryPtr->HasBeginEnabled()) { + EmitCs([queryPtr] (DxvkContext* ctx) { + queryPtr->End(ctx); + }); + } else { + uint32_t revision = queryPtr->Reset(); + EmitCs([revision, queryPtr] (DxvkContext* ctx) { + queryPtr->Signal(ctx, revision); + }); } } diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index 2782a4941..a09042f74 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -53,12 +53,15 @@ namespace dxvk { void* pData, UINT DataSize, UINT GetDataFlags) { + if (!pAsync) + return E_INVALIDARG; + // Make sure that we can safely write to the memory // location pointed to by pData if it is specified. if (DataSize == 0) pData = nullptr; - if (pData != nullptr && pAsync->GetDataSize() != DataSize) { + if (pData && pAsync->GetDataSize() != DataSize) { Logger::err(str::format( "D3D11: GetData: Data size mismatch", "\n Expected: ", pAsync->GetDataSize(), @@ -66,25 +69,14 @@ namespace dxvk { return E_INVALIDARG; } - // Default error return for unsupported interfaces - HRESULT hr = E_INVALIDARG; - - // This method can handle various incompatible interfaces, - // so we have to find out what we are actually dealing with - Com query; - - if (SUCCEEDED(pAsync->QueryInterface(__uuidof(ID3D11Query), reinterpret_cast(&query)))) - hr = static_cast(query.ptr())->GetData(pData, GetDataFlags); + // Get query status directly from the query object + HRESULT hr = static_cast(pAsync)->GetData(pData, GetDataFlags); // If we're likely going to spin on the asynchronous object, // flush the context so that we're keeping the GPU busy if (hr == S_FALSE) FlushImplicit(); - // The requested interface is not supported - if (FAILED(hr)) - Logger::err("D3D11: GetData: Unsupported Async type"); - return hr; }