From 80c5b61e267956bc2e29cea1ccc1d84f5b5ddaa8 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 12 Feb 2022 16:47:40 +0100 Subject: [PATCH] [d3d11] Use DxvkStagingBuffer in D3D11DeviceContext --- src/d3d11/d3d11_context.cpp | 38 +++---------------------------------- src/d3d11/d3d11_context.h | 6 ++++-- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index cc470eee..044ab4b7 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -19,6 +19,7 @@ namespace dxvk { m_annotation(this), m_multithread(this, false), m_device (Device), + m_staging (Device, StagingBufferSize), m_csFlags (CsFlags), m_csChunk (AllocCsChunk()), m_cmdData (nullptr) { @@ -4421,45 +4422,12 @@ namespace dxvk { DxvkBufferSlice D3D11DeviceContext::AllocStagingBuffer( VkDeviceSize Size) { - constexpr VkDeviceSize StagingBufferSize = 4 * 1024 * 1024; - - DxvkBufferCreateInfo info; - info.size = Size; - info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT - | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT - | VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; - info.stages = VK_PIPELINE_STAGE_TRANSFER_BIT - | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT - | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; - info.access = VK_ACCESS_TRANSFER_READ_BIT - | VK_ACCESS_SHADER_READ_BIT; - - // Create a dedicated buffer for large allocations - VkDeviceSize alignedSize = align(Size, 256); - - if (alignedSize >= StagingBufferSize) { - return DxvkBufferSlice(m_device->createBuffer(info, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)); - } - - // Otherwise, try to suballocate from an existing buffer - if (m_stagingOffset + alignedSize > StagingBufferSize || m_stagingBuffer == nullptr) { - info.size = StagingBufferSize; - - m_stagingBuffer = m_device->createBuffer(info, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - m_stagingOffset = 0; - } - - DxvkBufferSlice slice(m_stagingBuffer, m_stagingOffset, Size); - m_stagingOffset += alignedSize; - return slice; + return m_staging.alloc(256, Size); } void D3D11DeviceContext::ResetStagingBuffer() { - m_stagingBuffer = nullptr; - m_stagingOffset = 0; + m_staging.reset(); } diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 48b84427..c63e60e4 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -3,6 +3,7 @@ #include "../dxvk/dxvk_adapter.h" #include "../dxvk/dxvk_cs.h" #include "../dxvk/dxvk_device.h" +#include "../dxvk/dxvk_staging.h" #include "../d3d10/d3d10_multithread.h" @@ -21,6 +22,8 @@ namespace dxvk { friend class D3D11DeviceContextExt; // Needed in order to call EmitCs for pushing markers friend class D3D11UserDefinedAnnotation; + + constexpr static VkDeviceSize StagingBufferSize = 4ull << 20; public: D3D11DeviceContext( @@ -696,8 +699,7 @@ namespace dxvk { Rc m_device; Rc m_updateBuffer; - Rc m_stagingBuffer; - VkDeviceSize m_stagingOffset = 0ull; + DxvkStagingBuffer m_staging; DxvkCsChunkFlags m_csFlags; DxvkCsChunkRef m_csChunk;