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

[dxvk] Fix some logic errors around sysmem chunk size

This commit is contained in:
Philip Rebohle 2024-09-11 15:21:03 +02:00
parent 565ec7e0d3
commit c1a25df468

View File

@ -313,7 +313,10 @@ namespace dxvk {
VkDeviceSize align, VkDeviceSize align,
const DxvkMemoryProperties& info, const DxvkMemoryProperties& info,
DxvkMemoryFlags hints) { DxvkMemoryFlags hints) {
VkDeviceSize chunkSize = pickChunkSize(type->memTypeId, size, hints); constexpr VkDeviceSize DedicatedAllocationThreshold = 3;
VkDeviceSize chunkSize = pickChunkSize(type->memTypeId,
DedicatedAllocationThreshold * size, hints);
DxvkMemory memory; DxvkMemory memory;
@ -323,7 +326,7 @@ namespace dxvk {
// Prefer a dedicated allocation for very large resources in order to // Prefer a dedicated allocation for very large resources in order to
// reduce fragmentation if a large number of those resources are in use // reduce fragmentation if a large number of those resources are in use
bool wantsDedicatedAllocation = 3 * size >= chunkSize; bool wantsDedicatedAllocation = DedicatedAllocationThreshold * size > chunkSize;
// Try to reuse existing memory as much as possible in case the heap is nearly full // Try to reuse existing memory as much as possible in case the heap is nearly full
bool heapBudgedExceeded = 5 * type->heap->stats.memoryUsed + size > 4 * type->heap->properties.size; bool heapBudgedExceeded = 5 * type->heap->stats.memoryUsed + size > 4 * type->heap->properties.size;
@ -497,7 +500,7 @@ namespace dxvk {
VkDeviceSize chunkSize = m_memTypes[memTypeId].chunkSize; VkDeviceSize chunkSize = m_memTypes[memTypeId].chunkSize;
while (chunkSize < requiredSize) while (chunkSize < requiredSize && chunkSize < MaxChunkSize)
chunkSize <<= 1u; chunkSize <<= 1u;
if (hints.test(DxvkMemoryFlag::Small)) if (hints.test(DxvkMemoryFlag::Small))
@ -525,9 +528,8 @@ namespace dxvk {
// Don't bump chunk size if we reached the maximum or if // Don't bump chunk size if we reached the maximum or if
// we already were unable to allocate a full chunk. // we already were unable to allocate a full chunk.
if (chunkSize < MaxChunkSize && chunkSize <= allocatedSize if (chunkSize <= allocatedSize && chunkSize <= m_memTypes[memTypeId].heap->stats.memoryAllocated)
&& chunkSize <= m_memTypes[memTypeId].heap->stats.memoryAllocated) m_memTypes[memTypeId].chunkSize = pickChunkSize(memTypeId, chunkSize * 2, DxvkMemoryFlags());
m_memTypes[memTypeId].chunkSize <<= 1u;
} }