From fc8606732ef9a30383aea362efdb38e8bd07e455 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 26 Sep 2024 09:13:03 +0200 Subject: [PATCH] [dxvk] Align allocation size to create global buffer --- src/dxvk/dxvk_memory.cpp | 6 ++++++ src/dxvk/dxvk_memory.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index c89627efe6a..b2bce1dfbed 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -279,6 +279,12 @@ namespace dxvk { const void* next) { auto vk = m_device->vkd(); + // If global buffers are enabled for this allocation, pad the allocation size + // to a multiple of the global buffer alignment. This can happen when we create + // a dedicated allocation for a large resource. + if (type.bufferUsage && !next) + size = align(size, GlobalBufferAlignment); + // Preemptively free some unused allocations to reduce memory waste freeEmptyChunksInHeap(*type.heap, size, high_resolution_clock::now()); diff --git a/src/dxvk/dxvk_memory.h b/src/dxvk/dxvk_memory.h index 4e55b4ed61c..59c45a8dad6 100644 --- a/src/dxvk/dxvk_memory.h +++ b/src/dxvk/dxvk_memory.h @@ -335,6 +335,10 @@ namespace dxvk { constexpr static VkDeviceSize MinChunkSize = 4ull << 20; constexpr static VkDeviceSize MaxChunkSize = 256ull << 20; + + // Assume an alignment of 256 bytes. This is enough to satisfy all + // buffer use cases, and matches our minimum allocation size. + constexpr static VkDeviceSize GlobalBufferAlignment = 256u; public: DxvkMemoryAllocator(DxvkDevice* device);