mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-03 22:24:13 +01:00
[dxvk] Fix some logic errors around sysmem chunk size
This commit is contained in:
parent
565ec7e0d3
commit
c1a25df468
@ -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;
|
||||||
@ -332,12 +335,12 @@ namespace dxvk {
|
|||||||
// Attempt to suballocate from existing chunks first
|
// Attempt to suballocate from existing chunks first
|
||||||
for (uint32_t i = 0; i < type->chunks.size() && !memory; i++)
|
for (uint32_t i = 0; i < type->chunks.size() && !memory; i++)
|
||||||
memory = type->chunks[i]->alloc(info.flags, size, align, hints);
|
memory = type->chunks[i]->alloc(info.flags, size, align, hints);
|
||||||
|
|
||||||
// If no existing chunk can accomodate the allocation, and if a dedicated
|
// If no existing chunk can accomodate the allocation, and if a dedicated
|
||||||
// allocation is not preferred, create a new chunk and suballocate from it
|
// allocation is not preferred, create a new chunk and suballocate from it
|
||||||
if (!memory && !wantsDedicatedAllocation) {
|
if (!memory && !wantsDedicatedAllocation) {
|
||||||
DxvkDeviceMemory devMem;
|
DxvkDeviceMemory devMem;
|
||||||
|
|
||||||
if (this->shouldFreeEmptyChunks(type->heap, chunkSize))
|
if (this->shouldFreeEmptyChunks(type->heap, chunkSize))
|
||||||
this->freeEmptyChunks(type->heap);
|
this->freeEmptyChunks(type->heap);
|
||||||
|
|
||||||
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user