From 191c9644af94371871712ed091d33a111de02e3e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 26 Oct 2019 15:40:58 +0200 Subject: [PATCH] [d3d11] Allocate counter buffer per UAV Might slightly increase memory overhead, however this allows the backend to execute UAV counter updates more efficiently. --- src/d3d11/d3d11_device.cpp | 26 -------------------------- src/d3d11/d3d11_device.h | 4 ---- src/d3d11/d3d11_view_uav.cpp | 23 +++++++++++++++++++---- src/d3d11/d3d11_view_uav.h | 8 ++++++-- 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index aadbe1187..2083a8a72 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -45,7 +45,6 @@ namespace dxvk { m_context = new D3D11ImmediateContext(this, m_dxvkDevice); m_d3d10Device = new D3D10Device(this, m_context); - m_uavCounters = CreateUAVCounterBuffer(); m_xfbCounters = CreateXFBCounterBuffer(); m_predicates = CreatePredicateBuffer(); } @@ -1970,31 +1969,6 @@ namespace dxvk { } - Rc D3D11Device::CreateUAVCounterBuffer() { - // UAV counters are going to be used as raw storage buffers, so - // we need to align them to the minimum SSBO offset alignment - const auto& devInfo = m_dxvkAdapter->deviceProperties(); - - VkDeviceSize uavCounterSliceLength = align( - sizeof(uint32_t), devInfo.limits.minStorageBufferOffsetAlignment); - - DxvkBufferCreateInfo uavCounterInfo; - uavCounterInfo.size = 4096 * uavCounterSliceLength; - uavCounterInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT - | VK_BUFFER_USAGE_TRANSFER_SRC_BIT - | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - uavCounterInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT - | GetEnabledShaderStages(); - uavCounterInfo.access = VK_ACCESS_TRANSFER_READ_BIT - | VK_ACCESS_TRANSFER_WRITE_BIT - | VK_ACCESS_SHADER_READ_BIT - | VK_ACCESS_SHADER_WRITE_BIT; - - return new D3D11CounterBuffer(m_dxvkDevice, - uavCounterInfo, uavCounterSliceLength); - } - - Rc D3D11Device::CreateXFBCounterBuffer() { DxvkBufferCreateInfo xfbCounterInfo; xfbCounterInfo.size = 4096 * sizeof(D3D11SOCounter); diff --git a/src/d3d11/d3d11_device.h b/src/d3d11/d3d11_device.h index c17f2ab82..8d24e2a0a 100644 --- a/src/d3d11/d3d11_device.h +++ b/src/d3d11/d3d11_device.h @@ -425,11 +425,9 @@ namespace dxvk { return m_d3d10Device; } - DxvkBufferSlice AllocUavCounterSlice() { return m_uavCounters->AllocSlice(); } DxvkBufferSlice AllocXfbCounterSlice() { return m_xfbCounters->AllocSlice(); } DxvkBufferSlice AllocPredicateSlice () { return m_predicates ->AllocSlice(); } - void FreeUavCounterSlice(const DxvkBufferSlice& Slice) { m_uavCounters->FreeSlice(Slice); } void FreeXfbCounterSlice(const DxvkBufferSlice& Slice) { m_xfbCounters->FreeSlice(Slice); } void FreePredicateSlice (const DxvkBufferSlice& Slice) { m_predicates ->FreeSlice(Slice); } @@ -461,7 +459,6 @@ namespace dxvk { D3D11ImmediateContext* m_context = nullptr; D3D10Device* m_d3d10Device = nullptr; - Rc m_uavCounters; Rc m_xfbCounters; Rc m_predicates; @@ -472,7 +469,6 @@ namespace dxvk { D3D11ShaderModuleSet m_shaderModules; D3D11CommandListAllocator m_commandListAllocator; - Rc CreateUAVCounterBuffer(); Rc CreateXFBCounterBuffer(); Rc CreatePredicateBuffer(); diff --git a/src/d3d11/d3d11_view_uav.cpp b/src/d3d11/d3d11_view_uav.cpp index 123d1e3b1..f392b5f48 100644 --- a/src/d3d11/d3d11_view_uav.cpp +++ b/src/d3d11/d3d11_view_uav.cpp @@ -43,7 +43,7 @@ namespace dxvk { } if (pDesc->Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER)) - m_counterSlice = pDevice->AllocUavCounterSlice(); + m_counterBuffer = CreateCounterBuffer(); // Populate view info struct m_info.Buffer.Offset = viewInfo.rangeOffset; @@ -123,9 +123,6 @@ namespace dxvk { D3D11UnorderedAccessView::~D3D11UnorderedAccessView() { ResourceReleasePrivate(m_resource); - - if (m_counterSlice.defined()) - m_device->FreeUavCounterSlice(m_counterSlice); } @@ -420,5 +417,23 @@ namespace dxvk { return S_OK; } + + + Rc D3D11UnorderedAccessView::CreateCounterBuffer() { + Rc device = m_device->GetDXVKDevice(); + + DxvkBufferCreateInfo info; + info.size = sizeof(uint32_t); + info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT + | VK_BUFFER_USAGE_TRANSFER_DST_BIT + | VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + info.stages = VK_PIPELINE_STAGE_TRANSFER_BIT + | device->getShaderPipelineStages(); + info.access = VK_ACCESS_TRANSFER_WRITE_BIT + | VK_ACCESS_TRANSFER_READ_BIT + | VK_ACCESS_SHADER_WRITE_BIT + | VK_ACCESS_SHADER_READ_BIT; + return device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + } } diff --git a/src/d3d11/d3d11_view_uav.h b/src/d3d11/d3d11_view_uav.h index bd2532e88..c54c35650 100644 --- a/src/d3d11/d3d11_view_uav.h +++ b/src/d3d11/d3d11_view_uav.h @@ -60,7 +60,9 @@ namespace dxvk { } DxvkBufferSlice GetCounterSlice() const { - return m_counterSlice; + return m_counterBuffer != nullptr + ? DxvkBufferSlice(m_counterBuffer) + : DxvkBufferSlice(); } static HRESULT GetDescFromResource( @@ -82,7 +84,9 @@ namespace dxvk { D3D11_VK_VIEW_INFO m_info; Rc m_bufferView; Rc m_imageView; - DxvkBufferSlice m_counterSlice; + Rc m_counterBuffer; + + Rc CreateCounterBuffer(); };