| 7344 | } |
| 7345 | |
| 7346 | static void TestMappingMultithreaded() |
| 7347 | { |
| 7348 | wprintf(L"Testing mapping multithreaded...\n"); |
| 7349 | |
| 7350 | static const uint32_t threadCount = 16; |
| 7351 | static const uint32_t bufferCount = 1024; |
| 7352 | static const uint32_t threadBufferCount = bufferCount / threadCount; |
| 7353 | |
| 7354 | VkResult res; |
| 7355 | volatile uint32_t memTypeIndex = UINT32_MAX; |
| 7356 | |
| 7357 | enum TEST |
| 7358 | { |
| 7359 | TEST_NORMAL, |
| 7360 | TEST_POOL, |
| 7361 | TEST_DEDICATED, |
| 7362 | TEST_COUNT |
| 7363 | }; |
| 7364 | for(uint32_t testIndex = 0; testIndex < TEST_COUNT; ++testIndex) |
| 7365 | { |
| 7366 | VmaPool pool = nullptr; |
| 7367 | if(testIndex == TEST_POOL) |
| 7368 | { |
| 7369 | TEST(memTypeIndex != UINT32_MAX); |
| 7370 | VmaPoolCreateInfo poolInfo = {}; |
| 7371 | poolInfo.memoryTypeIndex = memTypeIndex; |
| 7372 | res = vmaCreatePool(g_hAllocator, &poolInfo, &pool); |
| 7373 | TEST(res == VK_SUCCESS); |
| 7374 | } |
| 7375 | |
| 7376 | VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; |
| 7377 | bufCreateInfo.size = 0x10000; |
| 7378 | bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 7379 | |
| 7380 | VmaAllocationCreateInfo allocCreateInfo = {}; |
| 7381 | allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO; |
| 7382 | allocCreateInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; |
| 7383 | allocCreateInfo.pool = pool; |
| 7384 | if(testIndex == TEST_DEDICATED) |
| 7385 | allocCreateInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; |
| 7386 | |
| 7387 | std::thread threads[threadCount]; |
| 7388 | for(uint32_t threadIndex = 0; threadIndex < threadCount; ++threadIndex) |
| 7389 | { |
| 7390 | threads[threadIndex] = std::thread([=, &memTypeIndex](){ |
| 7391 | // ======== THREAD FUNCTION ======== |
| 7392 | |
| 7393 | RandomNumberGenerator rand{threadIndex}; |
| 7394 | |
| 7395 | enum class MODE |
| 7396 | { |
| 7397 | // Don't map this buffer at all. |
| 7398 | DONT_MAP, |
| 7399 | // Map and quickly unmap. |
| 7400 | MAP_FOR_MOMENT, |
| 7401 | // Map and unmap before destruction. |
| 7402 | MAP_FOR_LONGER, |
| 7403 | // Map two times. Quickly unmap, second unmap before destruction. |
no test coverage detected