1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-18 20:52:10 +01:00

[d3d11] Allocate counter buffer per UAV

Might slightly increase memory overhead, however this allows
the backend to execute UAV counter updates more efficiently.
This commit is contained in:
Philip Rebohle 2019-10-26 15:40:58 +02:00
parent 320e0de4a0
commit 191c9644af
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
4 changed files with 25 additions and 36 deletions

View File

@ -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<D3D11CounterBuffer> 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<VkDeviceSize>(
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<D3D11CounterBuffer> D3D11Device::CreateXFBCounterBuffer() {
DxvkBufferCreateInfo xfbCounterInfo;
xfbCounterInfo.size = 4096 * sizeof(D3D11SOCounter);

View File

@ -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<D3D11CounterBuffer> m_uavCounters;
Rc<D3D11CounterBuffer> m_xfbCounters;
Rc<D3D11CounterBuffer> m_predicates;
@ -472,7 +469,6 @@ namespace dxvk {
D3D11ShaderModuleSet m_shaderModules;
D3D11CommandListAllocator m_commandListAllocator;
Rc<D3D11CounterBuffer> CreateUAVCounterBuffer();
Rc<D3D11CounterBuffer> CreateXFBCounterBuffer();
Rc<D3D11CounterBuffer> CreatePredicateBuffer();

View File

@ -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<DxvkBuffer> D3D11UnorderedAccessView::CreateCounterBuffer() {
Rc<DxvkDevice> 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);
}
}

View File

@ -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<DxvkBufferView> m_bufferView;
Rc<DxvkImageView> m_imageView;
DxvkBufferSlice m_counterSlice;
Rc<DxvkBuffer> m_counterBuffer;
Rc<DxvkBuffer> CreateCounterBuffer();
};