@@ -3863,13 +3863,15 @@ static void TestBudget()
38633863
38643864 uint32_t memTypeIndex = UINT32_MAX;
38653865
3866- static const VkDeviceSize BUF_SIZE = 0x10000 ;
3867- static const uint32_t BUF_COUNT = 32 ;
3866+ static const VkDeviceSize BUF_SIZE = 100ull * 1024 * 1024 ;
3867+ static const uint32_t BUF_COUNT = 4 ;
38683868
38693869 for (uint32_t testIndex = 0 ; testIndex < 2 ; ++testIndex)
38703870 {
3871- VmaBudget budgetBeg = {};
3872- vmaGetBudget (g_hAllocator, &budgetBeg);
3871+ vmaSetCurrentFrameIndex (g_hAllocator, ++g_FrameIndex);
3872+
3873+ VmaBudget budgetBeg[VK_MAX_MEMORY_HEAPS] = {};
3874+ vmaGetBudget (g_hAllocator, budgetBeg);
38733875
38743876 VkBufferCreateInfo bufInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
38753877 bufInfo.size = BUF_SIZE;
@@ -3902,36 +3904,85 @@ static void TestBudget()
39023904 }
39033905 }
39043906
3905- VmaBudget budgetWithBufs = {};
3906- vmaGetBudget (g_hAllocator, & budgetWithBufs);
3907+ VmaBudget budgetWithBufs[VK_MAX_MEMORY_HEAPS] = {};
3908+ vmaGetBudget (g_hAllocator, budgetWithBufs);
39073909
39083910 // DESTROY BUFFERS
39093911 for (size_t bufIndex = BUF_COUNT; bufIndex--; )
39103912 {
39113913 vmaDestroyBuffer (g_hAllocator, bufInfos[bufIndex].Buffer , bufInfos[bufIndex].Allocation );
39123914 }
39133915
3914- VmaBudget budgetEnd = {};
3915- vmaGetBudget (g_hAllocator, & budgetEnd);
3916+ VmaBudget budgetEnd[VK_MAX_MEMORY_HEAPS] = {};
3917+ vmaGetBudget (g_hAllocator, budgetEnd);
39163918
39173919 // CHECK
39183920 for (uint32_t i = 0 ; i < VK_MAX_MEMORY_HEAPS; ++i)
39193921 {
3920- TEST (budgetEnd. allocationBytes [i] <= budgetEnd. blockBytes [i]);
3922+ TEST (budgetEnd[i]. allocationBytes <= budgetEnd[i]. blockBytes );
39213923 if (i == heapIndex)
39223924 {
3923- TEST (budgetEnd.allocationBytes [i] == budgetBeg.allocationBytes [i]);
3924- TEST (budgetWithBufs.allocationBytes [i] == budgetBeg.allocationBytes [i] + BUF_SIZE * BUF_COUNT);
3925- TEST (budgetWithBufs.blockBytes [i] >= budgetEnd.blockBytes [i]);
3925+ TEST (budgetEnd[i].allocationBytes == budgetBeg[i].allocationBytes );
3926+ TEST (budgetWithBufs[i].allocationBytes == budgetBeg[i].allocationBytes + BUF_SIZE * BUF_COUNT);
3927+ TEST (budgetWithBufs[i].blockBytes >= budgetEnd[i].blockBytes );
3928+ }
3929+ else
3930+ {
3931+ TEST (budgetEnd[i].allocationBytes == budgetEnd[i].allocationBytes &&
3932+ budgetEnd[i].allocationBytes == budgetWithBufs[i].allocationBytes );
3933+ TEST (budgetEnd[i].blockBytes == budgetEnd[i].blockBytes &&
3934+ budgetEnd[i].blockBytes == budgetWithBufs[i].blockBytes );
3935+ }
3936+ }
3937+ }
3938+
3939+ // DELME
3940+
3941+ {
3942+ std::vector<BufferInfo> buffers;
3943+
3944+ for (uint32_t i = 0 ; i < 160 ; ++i)
3945+ {
3946+ // vmaSetCurrentFrameIndex(g_hAllocator, ++g_FrameIndex);
3947+
3948+ VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
3949+ bufCreateInfo.size = 50ull * 1024 * 1024 ;
3950+ bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3951+
3952+ VmaAllocationCreateInfo allocCreateInfo = {};
3953+ // allocCreateInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
3954+ allocCreateInfo.memoryTypeBits = 1 ;
3955+ // allocCreateInfo.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
3956+
3957+ BufferInfo bufInfo = {};
3958+ VkResult res = vmaCreateBuffer (g_hAllocator, &bufCreateInfo, &allocCreateInfo, &bufInfo.Buffer , &bufInfo.Allocation , nullptr );
3959+ if (res == VK_SUCCESS)
3960+ {
3961+ buffers.push_back (std::move (bufInfo));
39263962 }
39273963 else
39283964 {
3929- TEST (budgetEnd.allocationBytes [i] == budgetEnd.allocationBytes [i] &&
3930- budgetEnd.allocationBytes [i] == budgetWithBufs.allocationBytes [i]);
3931- TEST (budgetEnd.blockBytes [i] == budgetEnd.blockBytes [i] &&
3932- budgetEnd.blockBytes [i] == budgetWithBufs.blockBytes [i]);
3965+ break ;
39333966 }
39343967 }
3968+
3969+ char * statsString;
3970+ vmaBuildStatsString (g_hAllocator, &statsString, VK_TRUE);
3971+ printf (" %s\n " , statsString);
3972+ vmaFreeStatsString (g_hAllocator, statsString);
3973+
3974+ VmaBudget budget1[VK_MAX_MEMORY_HEAPS];
3975+ vmaGetBudget (g_hAllocator, budget1);
3976+
3977+ vmaSetCurrentFrameIndex (g_hAllocator, ++g_FrameIndex);
3978+
3979+ VmaBudget budget2[VK_MAX_MEMORY_HEAPS];
3980+ vmaGetBudget (g_hAllocator, budget2);
3981+
3982+ for (size_t i = buffers.size (); i--; )
3983+ {
3984+ vmaDestroyBuffer (g_hAllocator, buffers[i].Buffer , buffers[i].Allocation );
3985+ }
39353986 }
39363987}
39373988
0 commit comments