From 32cd85dc113c537ee5b8c1ad834717e8389b698d Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 22 Jun 2018 00:27:52 +0200 Subject: [PATCH] [dxvk] Discard slices from old physical buffers Improves effectiveness of an optimization that allows using dynamic buffer offsets for descriptor sets. --- src/dxvk/dxvk_buffer.cpp | 12 ++++++++---- src/dxvk/dxvk_buffer.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dxvk/dxvk_buffer.cpp b/src/dxvk/dxvk_buffer.cpp index 948c6004..32419265 100644 --- a/src/dxvk/dxvk_buffer.cpp +++ b/src/dxvk/dxvk_buffer.cpp @@ -42,11 +42,11 @@ namespace dxvk { // If there are still no slices available, create a new // physical buffer and add all slices to the free list. if (m_freeSlices.size() == 0) { - const Rc buffer - = this->allocPhysicalBuffer(m_physSliceCount); + std::unique_lock swapLock(m_swapMutex); + m_physBuffer = this->allocPhysicalBuffer(m_physSliceCount); for (uint32_t i = 0; i < m_physSliceCount; i++) { - m_freeSlices.push_back(buffer->slice( + m_freeSlices.push_back(m_physBuffer->slice( m_physSliceStride * i, m_physSliceLength)); } @@ -64,7 +64,11 @@ namespace dxvk { void DxvkBuffer::freePhysicalSlice(const DxvkPhysicalBufferSlice& slice) { // Add slice to a separate free list to reduce lock contention. std::unique_lock swapLock(m_swapMutex); - m_nextSlices.push_back(slice); + + // Discard slices allocated from other physical buffers. + // This may make descriptor set binding more efficient. + if (m_physBuffer->handle() == slice.handle()) + m_nextSlices.push_back(slice); } diff --git a/src/dxvk/dxvk_buffer.h b/src/dxvk/dxvk_buffer.h index 66b18739..e41a40dc 100644 --- a/src/dxvk/dxvk_buffer.h +++ b/src/dxvk/dxvk_buffer.h @@ -149,6 +149,8 @@ namespace dxvk { VkDeviceSize m_physSliceLength = 0; VkDeviceSize m_physSliceStride = 0; VkDeviceSize m_physSliceCount = 2; + + Rc m_physBuffer; Rc allocPhysicalBuffer( VkDeviceSize sliceCount) const;