[d3d11] Use DxvkStagingBuffer in D3D11DeviceContext

This commit is contained in:
Philip Rebohle 2022-02-12 16:47:40 +01:00
parent 0bc19472e8
commit 80c5b61e26
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 7 additions and 37 deletions

View File

@ -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();
}

View File

@ -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<DxvkDevice> m_device;
Rc<DxvkDataBuffer> m_updateBuffer;
Rc<DxvkBuffer> m_stagingBuffer;
VkDeviceSize m_stagingOffset = 0ull;
DxvkStagingBuffer m_staging;
DxvkCsChunkFlags m_csFlags;
DxvkCsChunkRef m_csChunk;