| 6545 | } |
| 6546 | |
| 6547 | static void TestDeviceCoherentMemory() |
| 6548 | { |
| 6549 | if(!VK_AMD_device_coherent_memory_enabled) |
| 6550 | return; |
| 6551 | |
| 6552 | uint32_t deviceCoherentMemoryTypeBits = FindDeviceCoherentMemoryTypeBits(); |
| 6553 | // Extension is enabled, feature is enabled, and the device still doesn't support any such memory type? |
| 6554 | // OK then, so it's just fake! |
| 6555 | if(deviceCoherentMemoryTypeBits == 0) |
| 6556 | return; |
| 6557 | |
| 6558 | wprintf(L"Testing device coherent memory...\n"); |
| 6559 | |
| 6560 | // 1. Try to allocate buffer from a memory type that is DEVICE_COHERENT. |
| 6561 | |
| 6562 | VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; |
| 6563 | bufCreateInfo.size = 0x10000; |
| 6564 | bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 6565 | |
| 6566 | VmaAllocationCreateInfo allocCreateInfo = {}; |
| 6567 | allocCreateInfo.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; |
| 6568 | allocCreateInfo.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD; |
| 6569 | |
| 6570 | AllocInfo alloc = {}; |
| 6571 | VmaAllocationInfo allocInfo = {}; |
| 6572 | VkResult res = vmaCreateBuffer(g_hAllocator, &bufCreateInfo, &allocCreateInfo, &alloc.m_Buffer, &alloc.m_Allocation, &allocInfo); |
| 6573 | |
| 6574 | // Make sure it succeeded and was really created in such memory type. |
| 6575 | TEST(res == VK_SUCCESS); |
| 6576 | TEST((1u << allocInfo.memoryType) & deviceCoherentMemoryTypeBits); |
| 6577 | |
| 6578 | alloc.Destroy(); |
| 6579 | |
| 6580 | // 2. Try to create a pool in such memory type. |
| 6581 | { |
| 6582 | VmaPoolCreateInfo poolCreateInfo = {}; |
| 6583 | |
| 6584 | res = vmaFindMemoryTypeIndex(g_hAllocator, UINT32_MAX, &allocCreateInfo, &poolCreateInfo.memoryTypeIndex); |
| 6585 | TEST(res == VK_SUCCESS); |
| 6586 | TEST((1u << poolCreateInfo.memoryTypeIndex) & deviceCoherentMemoryTypeBits); |
| 6587 | |
| 6588 | VmaPool pool = VK_NULL_HANDLE; |
| 6589 | res = vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool); |
| 6590 | TEST(res == VK_SUCCESS); |
| 6591 | |
| 6592 | vmaDestroyPool(g_hAllocator, pool); |
| 6593 | } |
| 6594 | |
| 6595 | // 3. Try the same with a local allocator created without VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT. |
| 6596 | |
| 6597 | VmaAllocatorCreateInfo allocatorCreateInfo = {}; |
| 6598 | SetAllocatorCreateInfo(allocatorCreateInfo); |
| 6599 | allocatorCreateInfo.flags &= ~VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT; |
| 6600 | |
| 6601 | VmaAllocator localAllocator = VK_NULL_HANDLE; |
| 6602 | res = vmaCreateAllocator(&allocatorCreateInfo, &localAllocator); |
| 6603 | TEST(res == VK_SUCCESS && localAllocator); |
| 6604 |
no test coverage detected