| 3601 | } |
| 3602 | |
| 3603 | static void TestPool_MinBlockCount() |
| 3604 | { |
| 3605 | #if defined(VMA_DEBUG_MARGIN) && VMA_DEBUG_MARGIN > 0 |
| 3606 | return; |
| 3607 | #endif |
| 3608 | |
| 3609 | wprintf(L"Test Pool MinBlockCount\n"); |
| 3610 | VkResult res; |
| 3611 | |
| 3612 | static const VkDeviceSize ALLOC_SIZE = 512ull * 1024; |
| 3613 | static const VkDeviceSize BLOCK_SIZE = ALLOC_SIZE * 2; // Each block can fit 2 allocations. |
| 3614 | |
| 3615 | VmaAllocationCreateInfo allocCreateInfo = {}; |
| 3616 | allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST; |
| 3617 | |
| 3618 | VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; |
| 3619 | bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 3620 | bufCreateInfo.size = ALLOC_SIZE; |
| 3621 | |
| 3622 | VmaPoolCreateInfo poolCreateInfo = {}; |
| 3623 | poolCreateInfo.blockSize = BLOCK_SIZE; |
| 3624 | poolCreateInfo.minBlockCount = 2; // At least 2 blocks always present. |
| 3625 | res = vmaFindMemoryTypeIndexForBufferInfo(g_hAllocator, &bufCreateInfo, &allocCreateInfo, &poolCreateInfo.memoryTypeIndex); |
| 3626 | TEST(res == VK_SUCCESS); |
| 3627 | |
| 3628 | VmaPool pool = VK_NULL_HANDLE; |
| 3629 | res = vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool); |
| 3630 | TEST(res == VK_SUCCESS && pool != VK_NULL_HANDLE); |
| 3631 | |
| 3632 | // Check that there are 2 blocks preallocated as requested. |
| 3633 | VmaDetailedStatistics begPoolStats = {}; |
| 3634 | vmaCalculatePoolStatistics(g_hAllocator, pool, &begPoolStats); |
| 3635 | TEST(begPoolStats.statistics.blockCount == 2 && |
| 3636 | begPoolStats.statistics.allocationCount == 0 && |
| 3637 | begPoolStats.statistics.blockBytes == BLOCK_SIZE * 2); |
| 3638 | |
| 3639 | // Allocate 5 buffers to create 3 blocks. |
| 3640 | static const uint32_t BUF_COUNT = 5; |
| 3641 | allocCreateInfo.pool = pool; |
| 3642 | std::vector<AllocInfo> allocs(BUF_COUNT); |
| 3643 | for(uint32_t i = 0; i < BUF_COUNT; ++i) |
| 3644 | { |
| 3645 | res = vmaCreateBuffer(g_hAllocator, &bufCreateInfo, &allocCreateInfo, &allocs[i].m_Buffer, &allocs[i].m_Allocation, nullptr); |
| 3646 | TEST(res == VK_SUCCESS && allocs[i].m_Buffer != VK_NULL_HANDLE && allocs[i].m_Allocation != VK_NULL_HANDLE); |
| 3647 | } |
| 3648 | |
| 3649 | // Check that there are really 3 blocks. |
| 3650 | VmaDetailedStatistics poolStats2 = {}; |
| 3651 | vmaCalculatePoolStatistics(g_hAllocator, pool, &poolStats2); |
| 3652 | TEST(poolStats2.statistics.blockCount == 3 && |
| 3653 | poolStats2.statistics.allocationCount == BUF_COUNT && |
| 3654 | poolStats2.statistics.blockBytes == BLOCK_SIZE * 3); |
| 3655 | |
| 3656 | // Free two first allocations to make one block empty. |
| 3657 | allocs[0].Destroy(); |
| 3658 | allocs[1].Destroy(); |
| 3659 | |
| 3660 | // Check that there are still 3 blocks due to hysteresis. |
no test coverage detected