1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-11 19:24:11 +01:00

[dxvk] Inline DxvkBuffer::allocSlice and DxvkBuffer::freeSlice

Seems to take some load off both the main rendering thread and the
cleanup thread in SotTR.
This commit is contained in:
Philip Rebohle 2019-02-04 10:01:29 +01:00
parent c451c9a95e
commit 01a7e06ad7
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 38 additions and 45 deletions

View File

@ -36,48 +36,6 @@ namespace dxvk {
} }
DxvkBufferSliceHandle DxvkBuffer::allocSlice() {
std::unique_lock<sync::Spinlock> freeLock(m_freeMutex);
// If no slices are available, swap the two free lists.
if (m_freeSlices.size() == 0) {
std::unique_lock<sync::Spinlock> swapLock(m_swapMutex);
std::swap(m_freeSlices, m_nextSlices);
}
// If there are still no slices available, create a new
// backing buffer and add all slices to the free list.
if (m_freeSlices.size() == 0) {
std::unique_lock<sync::Spinlock> swapLock(m_swapMutex);
DxvkBufferHandle handle = allocBuffer(m_physSliceCount);
for (uint32_t i = 0; i < m_physSliceCount; i++) {
DxvkBufferSliceHandle slice;
slice.handle = handle.buffer;
slice.offset = m_physSliceStride * i;
slice.length = m_physSliceLength;
slice.mapPtr = handle.memory.mapPtr(slice.offset);
m_freeSlices.push_back(slice);
}
m_buffers.push_back(std::move(handle));
m_physSliceCount *= 2;
}
// Take the first slice from the queue
DxvkBufferSliceHandle result = std::move(m_freeSlices.back());
m_freeSlices.pop_back();
return result;
}
void DxvkBuffer::freeSlice(const DxvkBufferSliceHandle& slice) {
// Add slice to a separate free list to reduce lock contention.
std::unique_lock<sync::Spinlock> swapLock(m_swapMutex);
m_nextSlices.push_back(slice);
}
DxvkBufferHandle DxvkBuffer::allocBuffer(VkDeviceSize sliceCount) const { DxvkBufferHandle DxvkBuffer::allocBuffer(VkDeviceSize sliceCount) const {
auto vkd = m_device->vkd(); auto vkd = m_device->vkd();

View File

@ -232,7 +232,39 @@ namespace dxvk {
* \brief Allocates new buffer slice * \brief Allocates new buffer slice
* \returns The new buffer slice * \returns The new buffer slice
*/ */
DxvkBufferSliceHandle allocSlice(); DxvkBufferSliceHandle allocSlice() {
std::unique_lock<sync::Spinlock> freeLock(m_freeMutex);
// If no slices are available, swap the two free lists.
if (unlikely(m_freeSlices.size() == 0)) {
std::unique_lock<sync::Spinlock> swapLock(m_swapMutex);
std::swap(m_freeSlices, m_nextSlices);
}
// If there are still no slices available, create a new
// backing buffer and add all slices to the free list.
if (unlikely(m_freeSlices.size() == 0)) {
std::unique_lock<sync::Spinlock> swapLock(m_swapMutex);
DxvkBufferHandle handle = allocBuffer(m_physSliceCount);
for (uint32_t i = 0; i < m_physSliceCount; i++) {
DxvkBufferSliceHandle slice;
slice.handle = handle.buffer;
slice.offset = m_physSliceStride * i;
slice.length = m_physSliceLength;
slice.mapPtr = handle.memory.mapPtr(slice.offset);
m_freeSlices.push_back(slice);
}
m_buffers.push_back(std::move(handle));
m_physSliceCount *= 2;
}
// Take the first slice from the queue
DxvkBufferSliceHandle result = m_freeSlices.back();
m_freeSlices.pop_back();
return result;
}
/** /**
* \brief Frees a buffer slice * \brief Frees a buffer slice
@ -242,8 +274,11 @@ namespace dxvk {
* the slice is no longer needed by the GPU. * the slice is no longer needed by the GPU.
* \param [in] slice The buffer slice to free * \param [in] slice The buffer slice to free
*/ */
void freeSlice( void freeSlice(const DxvkBufferSliceHandle& slice) {
const DxvkBufferSliceHandle& slice); // Add slice to a separate free list to reduce lock contention.
std::unique_lock<sync::Spinlock> swapLock(m_swapMutex);
m_nextSlices.push_back(slice);
}
private: private: