From 09f507c284f1e71345152fc1846a13db6a5ede85 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 26 Oct 2019 15:46:40 +0200 Subject: [PATCH] [d3d11] Allocate xfb counter buffer per buffer Same idea as with UAV counters, allows for more efficient updates. --- src/d3d11/d3d11_buffer.cpp | 26 +++++++++++++++++++++++--- src/d3d11/d3d11_buffer.h | 8 ++++++-- src/d3d11/d3d11_device.cpp | 22 ---------------------- src/d3d11/d3d11_device.h | 4 ---- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index 5fe8621f6..2738345b9 100644 --- a/src/d3d11/d3d11_buffer.cpp +++ b/src/d3d11/d3d11_buffer.cpp @@ -76,13 +76,12 @@ namespace dxvk { // For Stream Output buffers we need a counter if (pDesc->BindFlags & D3D11_BIND_STREAM_OUTPUT) - m_soCounter = m_device->AllocXfbCounterSlice(); + m_soCounter = CreateSoCounterBuffer(); } D3D11Buffer::~D3D11Buffer() { - if (m_soCounter.defined()) - m_device->FreeXfbCounterSlice(m_soCounter); + } @@ -255,6 +254,27 @@ namespace dxvk { return memoryFlags; } + + + Rc D3D11Buffer::CreateSoCounterBuffer() { + Rc device = m_device->GetDXVKDevice(); + + DxvkBufferCreateInfo info; + info.size = sizeof(D3D11SOCounter); + info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT + | VK_BUFFER_USAGE_TRANSFER_SRC_BIT + | VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT + | VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT; + info.stages = VK_PIPELINE_STAGE_TRANSFER_BIT + | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT + | VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT; + info.access = VK_ACCESS_TRANSFER_READ_BIT + | VK_ACCESS_TRANSFER_WRITE_BIT + | VK_ACCESS_INDIRECT_COMMAND_READ_BIT + | VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT + | VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT; + return device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + } D3D11Buffer* GetCommonBuffer(ID3D11Resource* pResource) { diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index 99d96cba6..f19e410bb 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -92,7 +92,9 @@ namespace dxvk { } DxvkBufferSlice GetSOCounter() { - return m_soCounter; + return m_soCounter != nullptr + ? DxvkBufferSlice(m_soCounter) + : DxvkBufferSlice(); } DxvkBufferSliceHandle AllocSlice() { @@ -127,7 +129,7 @@ namespace dxvk { const D3D11_BUFFER_DESC m_desc; Rc m_buffer; - DxvkBufferSlice m_soCounter; + Rc m_soCounter; DxvkBufferSliceHandle m_mapped; D3D11DXGIResource m_resource; @@ -139,6 +141,8 @@ namespace dxvk { VkMemoryPropertyFlags GetMemoryFlags() const; + Rc CreateSoCounterBuffer(); + }; diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 2083a8a72..c02883af1 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_xfbCounters = CreateXFBCounterBuffer(); m_predicates = CreatePredicateBuffer(); } @@ -1969,27 +1968,6 @@ namespace dxvk { } - Rc D3D11Device::CreateXFBCounterBuffer() { - DxvkBufferCreateInfo xfbCounterInfo; - xfbCounterInfo.size = 4096 * sizeof(D3D11SOCounter); - xfbCounterInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT - | VK_BUFFER_USAGE_TRANSFER_SRC_BIT - | VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT - | VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT; - xfbCounterInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT - | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT - | VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT; - xfbCounterInfo.access = VK_ACCESS_TRANSFER_READ_BIT - | VK_ACCESS_TRANSFER_WRITE_BIT - | VK_ACCESS_INDIRECT_COMMAND_READ_BIT - | VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT - | VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT; - - return new D3D11CounterBuffer(m_dxvkDevice, - xfbCounterInfo, sizeof(D3D11SOCounter)); - } - - Rc D3D11Device::CreatePredicateBuffer() { DxvkBufferCreateInfo predCounterInfo; predCounterInfo.size = 4096 * sizeof(uint32_t); diff --git a/src/d3d11/d3d11_device.h b/src/d3d11/d3d11_device.h index 8d24e2a0a..80808f2ea 100644 --- a/src/d3d11/d3d11_device.h +++ b/src/d3d11/d3d11_device.h @@ -425,10 +425,8 @@ namespace dxvk { return m_d3d10Device; } - DxvkBufferSlice AllocXfbCounterSlice() { return m_xfbCounters->AllocSlice(); } DxvkBufferSlice AllocPredicateSlice () { return m_predicates ->AllocSlice(); } - void FreeXfbCounterSlice(const DxvkBufferSlice& Slice) { m_xfbCounters->FreeSlice(Slice); } void FreePredicateSlice (const DxvkBufferSlice& Slice) { m_predicates ->FreeSlice(Slice); } static bool CheckFeatureLevelSupport( @@ -459,7 +457,6 @@ namespace dxvk { D3D11ImmediateContext* m_context = nullptr; D3D10Device* m_d3d10Device = nullptr; - Rc m_xfbCounters; Rc m_predicates; D3D11StateObjectSet m_bsStateObjects; @@ -469,7 +466,6 @@ namespace dxvk { D3D11ShaderModuleSet m_shaderModules; D3D11CommandListAllocator m_commandListAllocator; - Rc CreateXFBCounterBuffer(); Rc CreatePredicateBuffer(); HRESULT CreateShaderModule(