mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
synced 2025-05-29 07:59:17 +00:00
Fix sample application to also pass VkAllocationCallbacks to Vulkan, not only to VMA
Also remove function TestResize, no longer working or needed.
This commit is contained in:
parent
17c4aba057
commit
1f84f62a85
2 changed files with 82 additions and 225 deletions
183
src/Tests.cpp
183
src/Tests.cpp
|
@ -33,6 +33,7 @@
|
|||
static const char* CODE_DESCRIPTION = "Foo";
|
||||
|
||||
extern VkCommandBuffer g_hTemporaryCommandBuffer;
|
||||
extern const VkAllocationCallbacks* g_Allocs;
|
||||
void BeginSingleTimeCommands();
|
||||
void EndSingleTimeCommands();
|
||||
|
||||
|
@ -706,11 +707,11 @@ void AllocInfo::Destroy()
|
|||
{
|
||||
if(m_Image)
|
||||
{
|
||||
vkDestroyImage(g_hDevice, m_Image, nullptr);
|
||||
vkDestroyImage(g_hDevice, m_Image, g_Allocs);
|
||||
}
|
||||
if(m_Buffer)
|
||||
{
|
||||
vkDestroyBuffer(g_hDevice, m_Buffer, nullptr);
|
||||
vkDestroyBuffer(g_hDevice, m_Buffer, g_Allocs);
|
||||
}
|
||||
if(m_Allocation)
|
||||
{
|
||||
|
@ -1178,9 +1179,9 @@ static void RecreateAllocationResource(AllocInfo& allocation)
|
|||
|
||||
if(allocation.m_Buffer)
|
||||
{
|
||||
vkDestroyBuffer(g_hDevice, allocation.m_Buffer, nullptr);
|
||||
vkDestroyBuffer(g_hDevice, allocation.m_Buffer, g_Allocs);
|
||||
|
||||
VkResult res = vkCreateBuffer(g_hDevice, &allocation.m_BufferInfo, nullptr, &allocation.m_Buffer);
|
||||
VkResult res = vkCreateBuffer(g_hDevice, &allocation.m_BufferInfo, g_Allocs, &allocation.m_Buffer);
|
||||
TEST(res == VK_SUCCESS);
|
||||
|
||||
// Just to silence validation layer warnings.
|
||||
|
@ -1193,9 +1194,9 @@ static void RecreateAllocationResource(AllocInfo& allocation)
|
|||
}
|
||||
else
|
||||
{
|
||||
vkDestroyImage(g_hDevice, allocation.m_Image, nullptr);
|
||||
vkDestroyImage(g_hDevice, allocation.m_Image, g_Allocs);
|
||||
|
||||
VkResult res = vkCreateImage(g_hDevice, &allocation.m_ImageInfo, nullptr, &allocation.m_Image);
|
||||
VkResult res = vkCreateImage(g_hDevice, &allocation.m_ImageInfo, g_Allocs, &allocation.m_Image);
|
||||
TEST(res == VK_SUCCESS);
|
||||
|
||||
// Just to silence validation layer warnings.
|
||||
|
@ -2862,13 +2863,13 @@ static void BenchmarkAlgorithmsCase(FILE* file,
|
|||
|
||||
// Buffer created just to get memory requirements. Never bound to any memory.
|
||||
VkBuffer dummyBuffer = VK_NULL_HANDLE;
|
||||
res = vkCreateBuffer(g_hDevice, &sampleBufCreateInfo, nullptr, &dummyBuffer);
|
||||
res = vkCreateBuffer(g_hDevice, &sampleBufCreateInfo, g_Allocs, &dummyBuffer);
|
||||
TEST(res == VK_SUCCESS && dummyBuffer);
|
||||
|
||||
VkMemoryRequirements memReq = {};
|
||||
vkGetBufferMemoryRequirements(g_hDevice, dummyBuffer, &memReq);
|
||||
|
||||
vkDestroyBuffer(g_hDevice, dummyBuffer, nullptr);
|
||||
vkDestroyBuffer(g_hDevice, dummyBuffer, g_Allocs);
|
||||
|
||||
VmaAllocationCreateInfo allocCreateInfo = {};
|
||||
allocCreateInfo.pool = pool;
|
||||
|
@ -3073,14 +3074,14 @@ static void TestPool_SameSize()
|
|||
uint32_t memoryTypeBits = UINT32_MAX;
|
||||
{
|
||||
VkBuffer dummyBuffer;
|
||||
res = vkCreateBuffer(g_hDevice, &bufferInfo, nullptr, &dummyBuffer);
|
||||
res = vkCreateBuffer(g_hDevice, &bufferInfo, g_Allocs, &dummyBuffer);
|
||||
TEST(res == VK_SUCCESS);
|
||||
|
||||
VkMemoryRequirements memReq;
|
||||
vkGetBufferMemoryRequirements(g_hDevice, dummyBuffer, &memReq);
|
||||
memoryTypeBits = memReq.memoryTypeBits;
|
||||
|
||||
vkDestroyBuffer(g_hDevice, dummyBuffer, nullptr);
|
||||
vkDestroyBuffer(g_hDevice, dummyBuffer, g_Allocs);
|
||||
}
|
||||
|
||||
VmaAllocationCreateInfo poolAllocInfo = {};
|
||||
|
@ -3341,159 +3342,6 @@ static void TestPool_SameSize()
|
|||
vmaDestroyPool(g_hAllocator, pool);
|
||||
}
|
||||
|
||||
static void TestResize()
|
||||
{
|
||||
wprintf(L"Testing vmaResizeAllocation...\n");
|
||||
|
||||
const VkDeviceSize KILOBYTE = 1024ull;
|
||||
const VkDeviceSize MEGABYTE = KILOBYTE * 1024;
|
||||
|
||||
VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
|
||||
bufCreateInfo.size = 2 * MEGABYTE;
|
||||
bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||
|
||||
VmaAllocationCreateInfo allocCreateInfo = {};
|
||||
allocCreateInfo.usage = VMA_MEMORY_USAGE_CPU_ONLY;
|
||||
|
||||
uint32_t memTypeIndex = UINT32_MAX;
|
||||
TEST( vmaFindMemoryTypeIndexForBufferInfo(g_hAllocator, &bufCreateInfo, &allocCreateInfo, &memTypeIndex) == VK_SUCCESS );
|
||||
|
||||
VmaPoolCreateInfo poolCreateInfo = {};
|
||||
poolCreateInfo.flags = VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT;
|
||||
poolCreateInfo.blockSize = 8 * MEGABYTE;
|
||||
poolCreateInfo.minBlockCount = 1;
|
||||
poolCreateInfo.maxBlockCount = 1;
|
||||
poolCreateInfo.memoryTypeIndex = memTypeIndex;
|
||||
|
||||
VmaPool pool;
|
||||
TEST( vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool) == VK_SUCCESS );
|
||||
|
||||
allocCreateInfo.pool = pool;
|
||||
|
||||
// Fill 8 MB pool with 4 * 2 MB allocations.
|
||||
VmaAllocation allocs[4] = {};
|
||||
|
||||
VkMemoryRequirements memReq = {};
|
||||
memReq.memoryTypeBits = UINT32_MAX;
|
||||
memReq.alignment = 4;
|
||||
memReq.size = bufCreateInfo.size;
|
||||
|
||||
VmaAllocationInfo allocInfo = {};
|
||||
|
||||
for(uint32_t i = 0; i < 4; ++i)
|
||||
{
|
||||
TEST( vmaAllocateMemory(g_hAllocator, &memReq, &allocCreateInfo, &allocs[i], nullptr) == VK_SUCCESS );
|
||||
}
|
||||
|
||||
// Now it's: a0 2MB, a1 2MB, a2 2MB, a3 2MB
|
||||
|
||||
// Case: Resize to the same size always succeeds.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, allocs[0], 2 * MEGABYTE) == VK_SUCCESS);
|
||||
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
|
||||
TEST(allocInfo.size == 2ull * 1024 * 1024);
|
||||
}
|
||||
|
||||
// Case: Shrink allocation at the end.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, allocs[3], 1 * MEGABYTE) == VK_SUCCESS );
|
||||
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
|
||||
TEST(allocInfo.size == 1ull * 1024 * 1024);
|
||||
}
|
||||
|
||||
// Now it's: a0 2MB, a1 2MB, a2 2MB, a3 1MB, free 1MB
|
||||
|
||||
// Case: Shrink allocation before free space.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, allocs[3], 512 * KILOBYTE) == VK_SUCCESS );
|
||||
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
|
||||
TEST(allocInfo.size == 512 * KILOBYTE);
|
||||
}
|
||||
|
||||
// Now it's: a0 2MB, a1 2MB, a2 2MB, a3 0.5MB, free 1.5MB
|
||||
|
||||
// Case: Shrink allocation before next allocation.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, allocs[0], 1 * MEGABYTE) == VK_SUCCESS );
|
||||
vmaGetAllocationInfo(g_hAllocator, allocs[0], &allocInfo);
|
||||
TEST(allocInfo.size == 1 * MEGABYTE);
|
||||
}
|
||||
|
||||
// Now it's: a0 1MB, free 1 MB, a1 2MB, a2 2MB, a3 0.5MB, free 1.5MB
|
||||
|
||||
// Case: Grow allocation while there is even more space available.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, allocs[3], 1 * MEGABYTE) == VK_SUCCESS );
|
||||
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
|
||||
TEST(allocInfo.size == 1 * MEGABYTE);
|
||||
}
|
||||
|
||||
// Now it's: a0 1MB, free 1 MB, a1 2MB, a2 2MB, a3 1MB, free 1MB
|
||||
|
||||
// Case: Grow allocation while there is exact amount of free space available.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, allocs[0], 2 * MEGABYTE) == VK_SUCCESS );
|
||||
vmaGetAllocationInfo(g_hAllocator, allocs[0], &allocInfo);
|
||||
TEST(allocInfo.size == 2 * MEGABYTE);
|
||||
}
|
||||
|
||||
// Now it's: a0 2MB, a1 2MB, a2 2MB, a3 1MB, free 1MB
|
||||
|
||||
// Case: Fail to grow when there is not enough free space due to next allocation.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, allocs[0], 3 * MEGABYTE) == VK_ERROR_OUT_OF_POOL_MEMORY );
|
||||
vmaGetAllocationInfo(g_hAllocator, allocs[0], &allocInfo);
|
||||
TEST(allocInfo.size == 2 * MEGABYTE);
|
||||
}
|
||||
|
||||
// Case: Fail to grow when there is not enough free space due to end of memory block.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, allocs[3], 3 * MEGABYTE) == VK_ERROR_OUT_OF_POOL_MEMORY );
|
||||
vmaGetAllocationInfo(g_hAllocator, allocs[3], &allocInfo);
|
||||
TEST(allocInfo.size == 1 * MEGABYTE);
|
||||
}
|
||||
|
||||
for(uint32_t i = 4; i--; )
|
||||
{
|
||||
vmaFreeMemory(g_hAllocator, allocs[i]);
|
||||
}
|
||||
|
||||
vmaDestroyPool(g_hAllocator, pool);
|
||||
|
||||
// Test dedicated allocation
|
||||
{
|
||||
VmaAllocationCreateInfo dedicatedAllocCreateInfo = {};
|
||||
dedicatedAllocCreateInfo.usage = VMA_MEMORY_USAGE_CPU_ONLY;
|
||||
dedicatedAllocCreateInfo.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
|
||||
|
||||
VmaAllocation dedicatedAlloc = VK_NULL_HANDLE;
|
||||
TEST( vmaAllocateMemory(g_hAllocator, &memReq, &dedicatedAllocCreateInfo, &dedicatedAlloc, nullptr) == VK_SUCCESS );
|
||||
|
||||
// Case: Resize to the same size always succeeds.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, dedicatedAlloc, 2 * MEGABYTE) == VK_SUCCESS);
|
||||
vmaGetAllocationInfo(g_hAllocator, dedicatedAlloc, &allocInfo);
|
||||
TEST(allocInfo.size == 2ull * 1024 * 1024);
|
||||
}
|
||||
|
||||
// Case: Shrinking fails.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, dedicatedAlloc, 1 * MEGABYTE) < VK_SUCCESS);
|
||||
vmaGetAllocationInfo(g_hAllocator, dedicatedAlloc, &allocInfo);
|
||||
TEST(allocInfo.size == 2ull * 1024 * 1024);
|
||||
}
|
||||
|
||||
// Case: Growing fails.
|
||||
{
|
||||
TEST( vmaResizeAllocation(g_hAllocator, dedicatedAlloc, 3 * MEGABYTE) < VK_SUCCESS);
|
||||
vmaGetAllocationInfo(g_hAllocator, dedicatedAlloc, &allocInfo);
|
||||
TEST(allocInfo.size == 2ull * 1024 * 1024);
|
||||
}
|
||||
|
||||
vmaFreeMemory(g_hAllocator, dedicatedAlloc);
|
||||
}
|
||||
}
|
||||
|
||||
static bool ValidatePattern(const void* pMemory, size_t size, uint8_t pattern)
|
||||
{
|
||||
const uint8_t* pBytes = (const uint8_t*)pMemory;
|
||||
|
@ -3622,27 +3470,27 @@ static void TestPool_Benchmark(
|
|||
uint32_t bufferMemoryTypeBits = UINT32_MAX;
|
||||
{
|
||||
VkBuffer dummyBuffer;
|
||||
VkResult res = vkCreateBuffer(g_hDevice, &bufferInfo, nullptr, &dummyBuffer);
|
||||
VkResult res = vkCreateBuffer(g_hDevice, &bufferInfo, g_Allocs, &dummyBuffer);
|
||||
TEST(res == VK_SUCCESS);
|
||||
|
||||
VkMemoryRequirements memReq;
|
||||
vkGetBufferMemoryRequirements(g_hDevice, dummyBuffer, &memReq);
|
||||
bufferMemoryTypeBits = memReq.memoryTypeBits;
|
||||
|
||||
vkDestroyBuffer(g_hDevice, dummyBuffer, nullptr);
|
||||
vkDestroyBuffer(g_hDevice, dummyBuffer, g_Allocs);
|
||||
}
|
||||
|
||||
uint32_t imageMemoryTypeBits = UINT32_MAX;
|
||||
{
|
||||
VkImage dummyImage;
|
||||
VkResult res = vkCreateImage(g_hDevice, &imageInfo, nullptr, &dummyImage);
|
||||
VkResult res = vkCreateImage(g_hDevice, &imageInfo, g_Allocs, &dummyImage);
|
||||
TEST(res == VK_SUCCESS);
|
||||
|
||||
VkMemoryRequirements memReq;
|
||||
vkGetImageMemoryRequirements(g_hDevice, dummyImage, &memReq);
|
||||
imageMemoryTypeBits = memReq.memoryTypeBits;
|
||||
|
||||
vkDestroyImage(g_hDevice, dummyImage, nullptr);
|
||||
vkDestroyImage(g_hDevice, dummyImage, g_Allocs);
|
||||
}
|
||||
|
||||
uint32_t memoryTypeBits = 0;
|
||||
|
@ -5245,7 +5093,6 @@ void Test()
|
|||
#else
|
||||
TestPool_SameSize();
|
||||
TestHeapSizeLimit();
|
||||
TestResize();
|
||||
#endif
|
||||
#if VMA_DEBUG_INITIALIZE_ALLOCATIONS
|
||||
TestAllocationsInitialization();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue