From 34cdba1df5c40163368ce0ef25a8a2502bd10cf0 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 21 Jun 2019 16:28:46 +0200 Subject: [PATCH] [dxvk] Add method to explicitly release staging buffer memory --- src/dxvk/dxvk_context.cpp | 5 +++++ src/dxvk/dxvk_context.h | 9 +++++++++ src/dxvk/dxvk_staging.cpp | 9 +++++++++ src/dxvk/dxvk_staging.h | 8 ++++++++ 4 files changed, 31 insertions(+) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 6618611d..35d2cf14 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -2284,6 +2284,11 @@ namespace dxvk { void DxvkContext::writeTimestamp(const Rc& query) { m_queryManager.writeTimestamp(m_cmd, query); } + + + void DxvkContext::trimStagingBuffers() { + m_staging.trim(); + } void DxvkContext::clearImageViewFb( diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index 49aa48bb..041de51b 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -954,6 +954,15 @@ namespace dxvk { void writeTimestamp( const Rc& query); + /** + * \brief Trims staging buffers + * + * Releases staging buffer resources. Calling + * this may be useful if data updates on a + * given context are rare. + */ + void trimStagingBuffers(); + private: const Rc m_device; diff --git a/src/dxvk/dxvk_staging.cpp b/src/dxvk/dxvk_staging.cpp index 1c089228..dd2a1fd2 100644 --- a/src/dxvk/dxvk_staging.cpp +++ b/src/dxvk/dxvk_staging.cpp @@ -46,6 +46,15 @@ namespace dxvk { } + void DxvkStagingDataAlloc::trim() { + m_buffer = nullptr; + m_offset = 0; + + while (!m_buffers.empty()) + m_buffers.pop(); + } + + Rc DxvkStagingDataAlloc::createBuffer(VkDeviceSize size) { DxvkBufferCreateInfo info; info.size = size; diff --git a/src/dxvk/dxvk_staging.h b/src/dxvk/dxvk_staging.h index 8bff39cb..b4156c38 100644 --- a/src/dxvk/dxvk_staging.h +++ b/src/dxvk/dxvk_staging.h @@ -33,6 +33,14 @@ namespace dxvk { */ DxvkBufferSlice alloc(VkDeviceSize align, VkDeviceSize size); + /** + * \brief Deletes all staging buffers + * + * Destroys allocated buffers and + * releases all buffer memory. + */ + void trim(); + private: Rc m_device;