From 080aa1a989a849d5c579e9902fb1101ddfd98a00 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 17 Feb 2022 15:30:56 +0100 Subject: [PATCH] [dxvk] Add initBuffer method --- src/dxvk/dxvk_context.cpp | 19 +++++++++++++++++-- src/dxvk/dxvk_context.h | 12 +++++++++++- src/dxvk/dxvk_unbound.cpp | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 73b801c3c..9b1c15968 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -1505,6 +1505,22 @@ namespace dxvk { } + void DxvkContext::initBuffer( + const Rc& buffer) { + auto slice = buffer->getSliceHandle(); + + m_cmd->cmdFillBuffer(DxvkCmdBuffer::InitBuffer, + slice.handle, slice.offset, + dxvk::align(slice.length, 4), 0); + + m_initBarriers.accessBuffer(slice, + VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, + buffer->info().stages, + buffer->info().access); + } + + void DxvkContext::initImage( const Rc& image, const VkImageSubresourceRange& subresources, @@ -5234,8 +5250,7 @@ namespace dxvk { m_zeroBuffer = m_device->createBuffer(bufInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - clearBuffer(m_zeroBuffer, 0, bufInfo.size, 0); - m_execBarriers.recordCommands(m_cmd); + this->initBuffer(m_zeroBuffer); return m_zeroBuffer; } diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index b52143abe..1d029689a 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -638,7 +638,17 @@ namespace dxvk { void generateMipmaps( const Rc& imageView, VkFilter filter); - + + /** + * \brief Initializes a buffer + * + * Clears the given buffer to zero. Only safe to call + * if the buffer is not currently in use by the GPU. + * \param [in] buffer Buffer to clear + */ + void initBuffer( + const Rc& buffer); + /** * \brief Initializes an image * diff --git a/src/dxvk/dxvk_unbound.cpp b/src/dxvk/dxvk_unbound.cpp index eeb3f9b0b..852672418 100644 --- a/src/dxvk/dxvk_unbound.cpp +++ b/src/dxvk/dxvk_unbound.cpp @@ -179,7 +179,7 @@ namespace dxvk { void DxvkUnboundResources::clearBuffer( const Rc& ctx, const Rc& buffer) { - ctx->clearBuffer(buffer, 0, buffer->info().size, 0); + ctx->initBuffer(buffer); }