From 5c45a50daf03b9c21fa83d4e38134679aaf0344b Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 30 Aug 2018 15:24:47 +0200 Subject: [PATCH] [d3d11] Use D3D11CounterBuffer for UAV counters --- src/d3d11/d3d11_device.cpp | 33 +++++++++++++++++++++++++++++---- src/d3d11/d3d11_device.h | 6 +++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 73ed8f5d5..48610eeb4 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -113,16 +113,16 @@ namespace dxvk { throw DxvkError("D3D11Device: Failed to query adapter"); m_initializer = new D3D11Initializer(m_dxvkDevice); - m_uavCounters = new D3D11UavCounterAllocator(this); m_context = new D3D11ImmediateContext(this, m_dxvkDevice); m_d3d10Device = new D3D10Device(this, m_context); + + m_uavCounters = CreateUAVCounterBuffer(); } D3D11Device::~D3D11Device() { delete m_d3d10Device; delete m_context; - delete m_uavCounters; delete m_initializer; } @@ -1368,6 +1368,31 @@ 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(D3D11UavCounter), 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); + } + + HRESULT D3D11Device::CreateShaderModule( D3D11CommonShader* pShaderModule, const void* pShaderBytecode, @@ -1387,8 +1412,8 @@ namespace dxvk { return E_FAIL; } } - - + + HRESULT D3D11Device::GetFormatSupportFlags(DXGI_FORMAT Format, UINT* pFlags1, UINT* pFlags2) const { // Query some general information from DXGI, DXVK and Vulkan about the format const DXGI_VK_FORMAT_INFO fmtMapping = m_dxgiAdapter->LookupFormat(Format, DXGI_VK_FORMAT_MODE_ANY); diff --git a/src/d3d11/d3d11_device.h b/src/d3d11/d3d11_device.h index 2e6bc98df..817b3658d 100644 --- a/src/d3d11/d3d11_device.h +++ b/src/d3d11/d3d11_device.h @@ -13,6 +13,7 @@ #include "../util/com/com_private_data.h" +#include "d3d11_counter_buffer.h" #include "d3d11_initializer.h" #include "d3d11_interfaces.h" #include "d3d11_options.h" @@ -379,9 +380,10 @@ namespace dxvk { DxvkCsChunkPool m_csChunkPool; D3D11Initializer* m_initializer = nullptr; - D3D11UavCounterAllocator* m_uavCounters = nullptr; D3D11ImmediateContext* m_context = nullptr; D3D10Device* m_d3d10Device = nullptr; + + Rc m_uavCounters; D3D11StateObjectSet m_bsStateObjects; D3D11StateObjectSet m_dsStateObjects; @@ -389,6 +391,8 @@ namespace dxvk { D3D11StateObjectSet m_samplerObjects; D3D11ShaderModuleSet m_shaderModules; + Rc CreateUAVCounterBuffer(); + HRESULT CreateShaderModule( D3D11CommonShader* pShaderModule, const void* pShaderBytecode,