1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 10:54:16 +01:00

[d3d11] Track used queries in deferred contexts and command lists

This commit is contained in:
Philip Rebohle 2019-11-02 13:06:44 +01:00
parent 0671007437
commit 63dbca82e7
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
4 changed files with 101 additions and 6 deletions

View File

@ -49,12 +49,20 @@ namespace dxvk {
}
void D3D11CommandList::AddQuery(D3D11Query* pQuery) {
m_queries.emplace_back(pQuery);
}
void D3D11CommandList::EmitToCommandList(ID3D11CommandList* pCommandList) {
auto cmdList = static_cast<D3D11CommandList*>(pCommandList);
for (const auto& chunk : m_chunks)
cmdList->m_chunks.push_back(chunk);
for (const auto& query : m_queries)
cmdList->m_queries.push_back(query);
MarkSubmitted();
}

View File

@ -25,6 +25,9 @@ namespace dxvk {
void AddChunk(
DxvkCsChunkRef&& Chunk);
void AddQuery(
D3D11Query* pQuery);
void EmitToCommandList(
ID3D11CommandList* pCommandList);
@ -37,7 +40,8 @@ namespace dxvk {
D3D11Device* const m_device;
UINT const m_contextFlags;
std::vector<DxvkCsChunkRef> m_chunks;
std::vector<DxvkCsChunkRef> m_chunks;
std::vector<Com<D3D11Query, false>> m_queries;
std::atomic<bool> m_submitted = { false };
std::atomic<bool> m_warned = { false };

View File

@ -34,6 +34,63 @@ namespace dxvk {
}
void STDMETHODCALLTYPE D3D11DeferredContext::Begin(
ID3D11Asynchronous* pAsync) {
D3D10DeviceLock lock = LockContext();
if (unlikely(!pAsync))
return;
Com<D3D11Query, false> query(static_cast<D3D11Query*>(pAsync));
if (unlikely(!query->IsScoped()))
return;
auto entry = std::find(
m_queriesBegun.begin(),
m_queriesBegun.end(), query);
if (unlikely(entry != m_queriesBegun.end()))
return;
EmitCs([cQuery = query]
(DxvkContext* ctx) {
cQuery->Begin(ctx);
});
m_queriesBegun.push_back(std::move(query));
}
void STDMETHODCALLTYPE D3D11DeferredContext::End(
ID3D11Asynchronous* pAsync) {
D3D10DeviceLock lock = LockContext();
if (unlikely(!pAsync))
return;
Com<D3D11Query, false> query(static_cast<D3D11Query*>(pAsync));
if (query->IsScoped()) {
auto entry = std::find(
m_queriesBegun.begin(),
m_queriesBegun.end(), query);
if (unlikely(entry == m_queriesBegun.end()))
return;
m_queriesBegun.erase(entry);
}
m_commandList->AddQuery(query.ptr());
EmitCs([cQuery = std::move(query)]
(DxvkContext* ctx) {
cQuery->End(ctx);
});
}
void STDMETHODCALLTYPE D3D11DeferredContext::Flush() {
Logger::err("D3D11: Flush called on a deferred context");
}
@ -83,6 +140,7 @@ namespace dxvk {
ID3D11CommandList **ppCommandList) {
D3D10DeviceLock lock = LockContext();
FinalizeQueries();
FlushCsChunk();
if (ppCommandList != nullptr)
@ -309,6 +367,20 @@ namespace dxvk {
}
void D3D11DeferredContext::FinalizeQueries() {
for (auto& query : m_queriesBegun) {
m_commandList->AddQuery(query.ptr());
EmitCs([cQuery = std::move(query)]
(DxvkContext* ctx) {
cQuery->End(ctx);
});
}
m_queriesBegun.clear();
}
Com<D3D11CommandList> D3D11DeferredContext::CreateCommandList() {
return new D3D11CommandList(m_parent, m_contextFlags);
}

View File

@ -33,11 +33,17 @@ namespace dxvk {
UINT STDMETHODCALLTYPE GetContextFlags();
HRESULT STDMETHODCALLTYPE GetData(
ID3D11Asynchronous* pAsync,
void* pData,
UINT DataSize,
UINT GetDataFlags);
ID3D11Asynchronous* pAsync,
void* pData,
UINT DataSize,
UINT GetDataFlags);
void STDMETHODCALLTYPE Begin(
ID3D11Asynchronous* pAsync);
void STDMETHODCALLTYPE End(
ID3D11Asynchronous* pAsync);
void STDMETHODCALLTYPE Flush();
void STDMETHODCALLTYPE Flush1(
@ -87,6 +93,9 @@ namespace dxvk {
// number of mapped resources per command list.
std::vector<D3D11DeferredContextMapEntry> m_mappedResources;
// Begun and ended queries, will also be stored in command list
std::vector<Com<D3D11Query, false>> m_queriesBegun;
HRESULT MapBuffer(
ID3D11Resource* pResource,
D3D11_MAP MapType,
@ -100,6 +109,8 @@ namespace dxvk {
UINT MapFlags,
D3D11DeferredContextMapEntry* pMapEntry);
void FinalizeQueries();
Com<D3D11CommandList> CreateCommandList();
void EmitCsChunk(DxvkCsChunkRef&& chunk);