1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-04 16:24:29 +01:00

[d3d11] Improve flushing around deferred context submissions

This commit is contained in:
Philip Rebohle 2023-01-15 01:02:03 +01:00 committed by Philip Rebohle
parent 591e2df701
commit cf5adb8b12
3 changed files with 32 additions and 13 deletions

View File

@ -67,20 +67,20 @@ namespace dxvk {
}
uint64_t D3D11CommandList::EmitToCsThread(DxvkCsThread* CsThread) {
void D3D11CommandList::EmitToCsThread(
const D3D11ChunkDispatchProc& DispatchProc) {
uint64_t seq = 0;
for (const auto& query : m_queries)
query->DoDeferredEnd();
for (const auto& chunk : m_chunks)
seq = CsThread->dispatchChunk(DxvkCsChunkRef(chunk));
seq = DispatchProc(DxvkCsChunkRef(chunk));
for (const auto& resource : m_resources)
TrackResourceSequenceNumber(resource, seq);
MarkSubmitted();
return seq;
}

View File

@ -1,9 +1,13 @@
#pragma once
#include <functional>
#include "d3d11_context.h"
namespace dxvk {
using D3D11ChunkDispatchProc = std::function<uint64_t (DxvkCsChunkRef&&)>;
class D3D11CommandList : public D3D11DeviceChild<ID3D11CommandList> {
public:
@ -29,14 +33,18 @@ namespace dxvk {
void EmitToCommandList(
ID3D11CommandList* pCommandList);
uint64_t EmitToCsThread(
DxvkCsThread* CsThread);
void EmitToCsThread(
const D3D11ChunkDispatchProc& DispatchProc);
void TrackResourceUsage(
ID3D11Resource* pResource,
D3D11_RESOURCE_DIMENSION ResourceType,
UINT Subresource);
bool HasTrackedResources() const {
return !m_resources.empty();
}
private:
UINT const m_contextFlags;

View File

@ -237,18 +237,29 @@ namespace dxvk {
// number of pending draw calls is high enough.
ConsiderFlush(GpuFlushType::ImplicitWeakHint);
// Dispatch command list to the CS thread and
// restore the immediate context's state
uint64_t csSeqNum = commandList->EmitToCsThread(&m_csThread);
m_csSeqNum = std::max(m_csSeqNum, csSeqNum);
// Dispatch command list to the CS thread
commandList->EmitToCsThread([this] (DxvkCsChunkRef&& chunk) {
EmitCsChunk(std::move(chunk));
// Return the sequence number from before the flush since
// that is actually going to be needed for resource tracking
uint64_t csSeqNum = m_csSeqNum;
// Consider a flush after every chunk in case the app
// submits a very large command list or the GPU is idle
ConsiderFlush(GpuFlushType::ImplicitWeakHint);
return csSeqNum;
});
// If any resource tracking took place, flush with a strong hint
if (commandList->HasTrackedResources())
ConsiderFlush(GpuFlushType::ImplicitStrongHint);
// Restore the immediate context's state
if (RestoreContextState)
RestoreCommandListState();
else
ResetContextState();
// Flush again if the command list was sufficiently long
ConsiderFlush(GpuFlushType::ImplicitWeakHint);
}