diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 08a505d4..e8a04fb3 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -11,11 +11,8 @@ namespace dxvk { D3D11DeviceContext::D3D11DeviceContext( - D3D11Device* pParent, - const Rc& Device) - : D3D11DeviceChild(pParent), - m_device (Device), - m_staging (Device, StagingBufferSize) { + D3D11Device* pParent) + : D3D11DeviceChild(pParent) { } @@ -48,39 +45,6 @@ namespace dxvk { } - DxvkDataSlice D3D11DeviceContext::AllocUpdateBufferSlice(size_t Size) { - constexpr size_t UpdateBufferSize = 1 * 1024 * 1024; - - if (Size >= UpdateBufferSize) { - Rc buffer = new DxvkDataBuffer(Size); - return buffer->alloc(Size); - } else { - if (m_updateBuffer == nullptr) - m_updateBuffer = new DxvkDataBuffer(UpdateBufferSize); - - DxvkDataSlice slice = m_updateBuffer->alloc(Size); - - if (slice.ptr() == nullptr) { - m_updateBuffer = new DxvkDataBuffer(UpdateBufferSize); - slice = m_updateBuffer->alloc(Size); - } - - return slice; - } - } - - - DxvkBufferSlice D3D11DeviceContext::AllocStagingBuffer( - VkDeviceSize Size) { - return m_staging.alloc(256, Size); - } - - - void D3D11DeviceContext::ResetStagingBuffer() { - m_staging.reset(); - } - - void D3D11DeviceContext::InitDefaultPrimitiveTopology( DxvkInputAssemblyState* pIaState) { pIaState->primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM; diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index a67b225a..edf6f877 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -19,41 +19,20 @@ namespace dxvk { class D3D11Device; class D3D11DeviceContext : public D3D11DeviceChild { - template - friend class D3D11DeviceContextExt; - // Needed in order to call EmitCs for pushing markers - template - friend class D3D11UserDefinedAnnotation; - constexpr static VkDeviceSize StagingBufferSize = 4ull << 20; public: D3D11DeviceContext( - D3D11Device* pParent, - const Rc& Device); + D3D11Device* pParent); ~D3D11DeviceContext(); protected: - Rc m_device; - Rc m_updateBuffer; - - DxvkStagingBuffer m_staging; - - D3D11ContextState m_state; - VkClearValue ConvertColorValue( const FLOAT Color[4], const DxvkFormatInfo* pFormatInfo); - DxvkDataSlice AllocUpdateBufferSlice(size_t Size); - - DxvkBufferSlice AllocStagingBuffer( - VkDeviceSize Size); - - void ResetStagingBuffer(); - static void InitDefaultPrimitiveTopology( DxvkInputAssemblyState* pIaState); diff --git a/src/d3d11/d3d11_context_common.cpp b/src/d3d11/d3d11_context_common.cpp index 72461628..e6ae7410 100644 --- a/src/d3d11/d3d11_context_common.cpp +++ b/src/d3d11/d3d11_context_common.cpp @@ -9,10 +9,12 @@ namespace dxvk { D3D11Device* pParent, const Rc& Device, DxvkCsChunkFlags CsFlags) - : D3D11DeviceContext(pParent, Device), + : D3D11DeviceContext(pParent), m_contextExt(GetTypedContext()), m_annotation(GetTypedContext(), Device), m_multithread(this, false), + m_device (Device), + m_staging (Device, StagingBufferSize), m_csFlags (CsFlags), m_csChunk (AllocCsChunk()), m_cmdData (nullptr) { @@ -2987,7 +2989,37 @@ namespace dxvk { DxvkCsChunkRef D3D11CommonContext::AllocCsChunk() { return m_parent->AllocCsChunk(m_csFlags); } - + + + template + DxvkDataSlice D3D11CommonContext::AllocUpdateBufferSlice(size_t Size) { + constexpr size_t UpdateBufferSize = 1 * 1024 * 1024; + + if (Size >= UpdateBufferSize) { + Rc buffer = new DxvkDataBuffer(Size); + return buffer->alloc(Size); + } else { + if (m_updateBuffer == nullptr) + m_updateBuffer = new DxvkDataBuffer(UpdateBufferSize); + + DxvkDataSlice slice = m_updateBuffer->alloc(Size); + + if (slice.ptr() == nullptr) { + m_updateBuffer = new DxvkDataBuffer(UpdateBufferSize); + slice = m_updateBuffer->alloc(Size); + } + + return slice; + } + } + + + template + DxvkBufferSlice D3D11CommonContext::AllocStagingBuffer( + VkDeviceSize Size) { + return m_staging.alloc(256, Size); + } + template void D3D11CommonContext::ApplyInputLayout() { @@ -3890,6 +3922,12 @@ namespace dxvk { } + template + void D3D11CommonContext::ResetStagingBuffer() { + m_staging.reset(); + } + + template void D3D11CommonContext::ResetState() { EmitCs([] (DxvkContext* ctx) { diff --git a/src/d3d11/d3d11_context_common.h b/src/d3d11/d3d11_context_common.h index be33d595..1e8e9830 100644 --- a/src/d3d11/d3d11_context_common.h +++ b/src/d3d11/d3d11_context_common.h @@ -58,6 +58,8 @@ namespace dxvk { template friend class D3D11DeviceContextExt; template friend class D3D11UserDefinedAnnotation; + + constexpr static VkDeviceSize StagingBufferSize = 4ull << 20; public: D3D11CommonContext( @@ -748,12 +750,24 @@ namespace dxvk { D3D11UserDefinedAnnotation m_annotation; D3D10Multithread m_multithread; + Rc m_device; + + D3D11ContextState m_state; + + DxvkStagingBuffer m_staging; + Rc m_updateBuffer; + DxvkCsChunkFlags m_csFlags; DxvkCsChunkRef m_csChunk; D3D11CmdData* m_cmdData; DxvkCsChunkRef AllocCsChunk(); + DxvkDataSlice AllocUpdateBufferSlice(size_t Size); + + DxvkBufferSlice AllocStagingBuffer( + VkDeviceSize Size); + void ApplyInputLayout(); void ApplyPrimitiveTopology(); @@ -871,6 +885,8 @@ namespace dxvk { UINT NumSamplers, ID3D11SamplerState** ppSamplers); + void ResetStagingBuffer(); + void ResetState(); template