From 7d7cc1ceda4c6e2be7f950f0138fe2607059cdda Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 20 Jan 2018 22:52:18 +0100 Subject: [PATCH] [d3d11] Record commands into a CS chunk --- src/d3d11/d3d11_context.cpp | 8 ++++---- src/d3d11/d3d11_context.h | 9 +++++++-- src/d3d11/d3d11_context_imm.cpp | 36 ++++++++++++++++++++++++--------- src/d3d11/d3d11_context_imm.h | 6 +++++- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index adab2440..fd4b0a87 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -12,10 +12,10 @@ namespace dxvk { D3D11DeviceContext::D3D11DeviceContext( D3D11Device* parent, Rc device) - : m_parent(parent), - m_device(device) { - m_context = m_device->createContext(); - + : m_parent (parent), + m_device (device), + m_context (m_device->createContext()), + m_csChunk (new DxvkCsChunk()) { // Create default state objects. We won't ever return them // to the application, but we'll use them to apply state. Com defaultBlendState; diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 9c1301ac..02a30558 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -519,6 +519,7 @@ namespace dxvk { Rc m_device; Rc m_context; + Rc m_csChunk; Rc m_defaultSampler; Com m_defaultBlendState; @@ -567,10 +568,14 @@ namespace dxvk { template void EmitCs(Cmd&& command) { - // TODO push to CS chunk - command(m_context.ptr()); + if (!m_csChunk->push(command)) { + EmitCsChunk(); + m_csChunk->push(command); + } } + virtual void EmitCsChunk() = 0; + }; } diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index 99299ad4..1f359662 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -38,6 +38,8 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11ImmediateContext::Flush() { + EmitCsChunk(); + m_parent->FlushInitContext(); m_drawCount = 0; @@ -88,13 +90,11 @@ namespace dxvk { if (pMappedResource == nullptr) return S_FALSE; - DxvkPhysicalBufferSlice physicalSlice; - if (MapType == D3D11_MAP_WRITE_DISCARD) { // Allocate a new backing slice for the buffer and set // it as the 'new' mapped slice. This assumes that the // only way to invalidate a buffer is by mapping it. - physicalSlice = buffer->allocPhysicalSlice(); + auto physicalSlice = buffer->allocPhysicalSlice(); resource->GetBufferInfo()->mappedSlice = physicalSlice; EmitCs([ @@ -103,14 +103,10 @@ namespace dxvk { ] (DxvkContext* ctx) { ctx->invalidateBuffer(cBuffer, cPhysicalSlice); }); - } else if (MapType == D3D11_MAP_WRITE_NO_OVERWRITE) { - // Use map pointer from previous map operation. This - // way we don't have to synchronize with the CS thread. - physicalSlice = resource->GetBufferInfo()->mappedSlice; - } else { + } else if (MapType != D3D11_MAP_WRITE_NO_OVERWRITE) { // Synchronize with CS thread so that we know whether // the buffer is currently in use by the GPU or not - // TODO implement + SynchronizeCs(); if (buffer->isInUse()) { if (MapFlags & D3D11_MAP_FLAG_DO_NOT_WAIT) @@ -121,6 +117,12 @@ namespace dxvk { } } + // Use map pointer from previous map operation. This + // way we don't have to synchronize with the CS thread + // if the map mode is D3D11_MAP_WRITE_NO_OVERWRITE. + const DxvkPhysicalBufferSlice physicalSlice + = resource->GetBufferInfo()->mappedSlice; + pMappedResource->pData = physicalSlice.mapPtr(0); pMappedResource->RowPitch = physicalSlice.length(); pMappedResource->DepthPitch = physicalSlice.length(); @@ -243,4 +245,20 @@ namespace dxvk { m_device->waitForIdle(); } + + void D3D11ImmediateContext::SynchronizeCs() { + // Dispatch recorded commands first, + EmitCsChunk(); + + // TODO synchronize with CS thread + } + + + void D3D11ImmediateContext::EmitCsChunk() { + if (m_csChunk->commandCount() > 0) { + m_csChunk->executeAll(m_context.ptr()); + m_csChunk = new DxvkCsChunk(); + } + } + } \ No newline at end of file diff --git a/src/d3d11/d3d11_context_imm.h b/src/d3d11/d3d11_context_imm.h index 32d2d902..d0903fe7 100644 --- a/src/d3d11/d3d11_context_imm.h +++ b/src/d3d11/d3d11_context_imm.h @@ -42,10 +42,14 @@ namespace dxvk { ID3D11Resource* pResource, UINT Subresource) final; - void Synchronize(); private: + void Synchronize(); + void SynchronizeCs(); + + void EmitCsChunk(); + }; } \ No newline at end of file