| 3857 | } |
| 3858 | |
| 3859 | void TestHeapSizeLimit() |
| 3860 | { |
| 3861 | wprintf(L"Test heap size limit\n"); |
| 3862 | |
| 3863 | const VkDeviceSize HEAP_SIZE_LIMIT = 100ull * 1024 * 1024; // 100 MB |
| 3864 | const VkDeviceSize BLOCK_SIZE = 10ull * 1024 * 1024; // 10 MB |
| 3865 | |
| 3866 | VkDeviceSize heapSizeLimit[VK_MAX_MEMORY_HEAPS]; |
| 3867 | for(uint32_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i) |
| 3868 | { |
| 3869 | heapSizeLimit[i] = HEAP_SIZE_LIMIT; |
| 3870 | } |
| 3871 | |
| 3872 | VmaAllocatorCreateInfo allocatorCreateInfo = {}; |
| 3873 | allocatorCreateInfo.physicalDevice = g_hPhysicalDevice; |
| 3874 | allocatorCreateInfo.device = g_hDevice; |
| 3875 | allocatorCreateInfo.instance = g_hVulkanInstance; |
| 3876 | allocatorCreateInfo.pHeapSizeLimit = heapSizeLimit; |
| 3877 | #ifdef VOLK_HEADER_VERSION |
| 3878 | VmaVulkanFunctions vulkanFunctions = {}; |
| 3879 | vmaImportVulkanFunctionsFromVolk(&allocatorCreateInfo, &vulkanFunctions); |
| 3880 | allocatorCreateInfo.pVulkanFunctions = &vulkanFunctions; |
| 3881 | #endif |
| 3882 | #if VMA_DYNAMIC_VULKAN_FUNCTIONS |
| 3883 | VmaVulkanFunctions vulkanFunctions = {}; |
| 3884 | vulkanFunctions.vkGetInstanceProcAddr = vkGetInstanceProcAddr; |
| 3885 | vulkanFunctions.vkGetDeviceProcAddr = vkGetDeviceProcAddr; |
| 3886 | allocatorCreateInfo.pVulkanFunctions = &vulkanFunctions; |
| 3887 | #endif |
| 3888 | |
| 3889 | VmaAllocator hAllocator; |
| 3890 | VkResult res = vmaCreateAllocator(&allocatorCreateInfo, &hAllocator); |
| 3891 | TEST(res == VK_SUCCESS); |
| 3892 | |
| 3893 | struct Item |
| 3894 | { |
| 3895 | VkBuffer hBuf; |
| 3896 | VmaAllocation hAlloc; |
| 3897 | }; |
| 3898 | std::vector<Item> items; |
| 3899 | |
| 3900 | VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; |
| 3901 | bufCreateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; |
| 3902 | |
| 3903 | // 1. Allocate two blocks of dedicated memory, half the size of BLOCK_SIZE. |
| 3904 | VmaAllocationInfo dedicatedAllocInfo; |
| 3905 | { |
| 3906 | VmaAllocationCreateInfo allocCreateInfo = {}; |
| 3907 | allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; |
| 3908 | allocCreateInfo.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; |
| 3909 | |
| 3910 | bufCreateInfo.size = BLOCK_SIZE / 2; |
| 3911 | |
| 3912 | for(size_t i = 0; i < 2; ++i) |
| 3913 | { |
| 3914 | Item item; |
| 3915 | res = vmaCreateBuffer(hAllocator, &bufCreateInfo, &allocCreateInfo, &item.hBuf, &item.hAlloc, &dedicatedAllocInfo); |
| 3916 | TEST(res == VK_SUCCESS); |
no test coverage detected