mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
synced 2024-11-10 10:41:52 +00:00
More coding and more tests. Basic functionality is working now.
This commit is contained in:
parent
dc644281ac
commit
e1812303d6
@ -6860,10 +6860,7 @@ public:
|
|||||||
const VkAllocationCallbacks m_AllocationCallbacks;
|
const VkAllocationCallbacks m_AllocationCallbacks;
|
||||||
|
|
||||||
VmaVirtualBlock_T(const VmaVirtualBlockCreateInfo& createInfo);
|
VmaVirtualBlock_T(const VmaVirtualBlockCreateInfo& createInfo);
|
||||||
~VmaVirtualBlock_T()
|
~VmaVirtualBlock_T();
|
||||||
{
|
|
||||||
vma_delete(GetAllocationCallbacks(), m_Metadata);
|
|
||||||
}
|
|
||||||
VkResult Init()
|
VkResult Init()
|
||||||
{
|
{
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
@ -16665,6 +16662,15 @@ VmaVirtualBlock_T::VmaVirtualBlock_T(const VmaVirtualBlockCreateInfo& createInfo
|
|||||||
m_Metadata->Init(createInfo.size);
|
m_Metadata->Init(createInfo.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VmaVirtualBlock_T::~VmaVirtualBlock_T()
|
||||||
|
{
|
||||||
|
// This is an important assert!!!
|
||||||
|
// Hitting it means you have some memory leak - unreleased virtual allocations.
|
||||||
|
VMA_ASSERT(m_Metadata->IsEmpty() && "Some virtual allocations were not freed before destruction of this virtual block!");
|
||||||
|
|
||||||
|
vma_delete(GetAllocationCallbacks(), m_Metadata);
|
||||||
|
}
|
||||||
|
|
||||||
VkResult VmaVirtualBlock_T::Allocate(const VmaVirtualAllocationCreateInfo& createInfo, VkDeviceSize& outOffset)
|
VkResult VmaVirtualBlock_T::Allocate(const VmaVirtualAllocationCreateInfo& createInfo, VkDeviceSize& outOffset)
|
||||||
{
|
{
|
||||||
outOffset = VK_WHOLE_SIZE;
|
outOffset = VK_WHOLE_SIZE;
|
||||||
|
@ -2709,46 +2709,45 @@ static void TestVirtualBlocks()
|
|||||||
allocCreateInfo.pUserData = (void*)(uintptr_t)1;
|
allocCreateInfo.pUserData = (void*)(uintptr_t)1;
|
||||||
allocCreateInfo.size = 8 * MEGABYTE;
|
allocCreateInfo.size = 8 * MEGABYTE;
|
||||||
VkDeviceSize alloc0Offset;
|
VkDeviceSize alloc0Offset;
|
||||||
TEST(vmaVirtualAllocate(block, &allocCreateInfo, &alloc0Offset) == VK_SUCCESS && alloc0Offset < blockSize);
|
TEST(vmaVirtualAllocate(block, &allocCreateInfo, &alloc0Offset) == VK_SUCCESS);
|
||||||
|
TEST(alloc0Offset < blockSize);
|
||||||
|
|
||||||
#if 0
|
|
||||||
// # Validate the allocation
|
// # Validate the allocation
|
||||||
|
|
||||||
VIRTUAL_ALLOCATION_INFO allocInfo = {};
|
VmaVirtualAllocationInfo allocInfo = {};
|
||||||
block->GetAllocationInfo(alloc0Offset, &allocInfo);
|
vmaGetVirtualAllocationInfo(block, alloc0Offset, &allocInfo);
|
||||||
CHECK_BOOL( allocInfo.size == allocDesc.Size );
|
TEST(allocInfo.size == allocCreateInfo.size);
|
||||||
CHECK_BOOL( allocInfo.pUserData == allocDesc.pUserData );
|
TEST(allocInfo.pUserData = allocCreateInfo.pUserData);
|
||||||
|
|
||||||
// # Check SetUserData
|
// # Check SetUserData
|
||||||
|
|
||||||
block->SetAllocationUserData(alloc0Offset, (void*)(uintptr_t)2);
|
vmaSetVirtualAllocationUserData(block, alloc0Offset, (void*)(uintptr_t)2);
|
||||||
block->GetAllocationInfo(alloc0Offset, &allocInfo);
|
vmaGetVirtualAllocationInfo(block, alloc0Offset, &allocInfo);
|
||||||
CHECK_BOOL( allocInfo.pUserData == (void*)(uintptr_t)2 );
|
TEST(allocInfo.pUserData = (void*)(uintptr_t)2);
|
||||||
|
|
||||||
// # Allocate 4 MB
|
// # Allocate 4 MB
|
||||||
|
|
||||||
allocDesc.Size = 4 * MEGABYTE;
|
allocCreateInfo.size = 4 * MEGABYTE;
|
||||||
allocDesc.Alignment = alignment;
|
|
||||||
UINT64 alloc1Offset;
|
UINT64 alloc1Offset;
|
||||||
CHECK_HR( block->Allocate(&allocDesc, &alloc1Offset) );
|
TEST(vmaVirtualAllocate(block, &allocCreateInfo, &alloc1Offset) == VK_SUCCESS);
|
||||||
CHECK_BOOL( alloc1Offset < blockSize );
|
TEST(alloc1Offset < blockSize);
|
||||||
CHECK_BOOL( alloc1Offset + 4 * MEGABYTE <= alloc0Offset || alloc0Offset + 8 * MEGABYTE <= alloc1Offset ); // Check if they don't overlap.
|
TEST(alloc1Offset + 4 * MEGABYTE <= alloc0Offset || alloc0Offset + 8 * MEGABYTE <= alloc1Offset); // Check if they don't overlap.
|
||||||
|
|
||||||
// # Allocate another 8 MB - it should fail
|
// # Allocate another 8 MB - it should fail
|
||||||
|
|
||||||
allocDesc.Size = 8 * MEGABYTE;
|
allocCreateInfo.size = 8 * MEGABYTE;
|
||||||
allocDesc.Alignment = alignment;
|
|
||||||
UINT64 alloc2Offset;
|
UINT64 alloc2Offset;
|
||||||
CHECK_BOOL( FAILED(block->Allocate(&allocDesc, &alloc2Offset)) );
|
TEST(vmaVirtualAllocate(block, &allocCreateInfo, &alloc2Offset) < 0);
|
||||||
CHECK_BOOL( alloc2Offset == UINT64_MAX );
|
TEST(alloc2Offset == VK_WHOLE_SIZE);
|
||||||
|
|
||||||
// # Free the 4 MB block. Now allocation of 8 MB should succeed.
|
// # Free the 4 MB block. Now allocation of 8 MB should succeed.
|
||||||
|
|
||||||
block->FreeAllocation(alloc1Offset);
|
vmaVirtualFree(block, alloc1Offset);
|
||||||
CHECK_HR( block->Allocate(&allocDesc, &alloc2Offset) );
|
TEST(vmaVirtualAllocate(block, &allocCreateInfo, &alloc2Offset) == VK_SUCCESS);
|
||||||
CHECK_BOOL( alloc2Offset < blockSize );
|
TEST(alloc2Offset < blockSize);
|
||||||
CHECK_BOOL( alloc2Offset + 4 * MEGABYTE <= alloc0Offset || alloc0Offset + 8 * MEGABYTE <= alloc2Offset ); // Check if they don't overlap.
|
TEST(alloc2Offset + 4 * MEGABYTE <= alloc0Offset || alloc0Offset + 8 * MEGABYTE <= alloc2Offset); // Check if they don't overlap.
|
||||||
|
|
||||||
|
#if 0
|
||||||
// # Calculate statistics
|
// # Calculate statistics
|
||||||
|
|
||||||
StatInfo statInfo = {};
|
StatInfo statInfo = {};
|
||||||
@ -2803,6 +2802,7 @@ static void TestVirtualBlocks()
|
|||||||
block->FreeAllocation(alloc2Offset);
|
block->FreeAllocation(alloc2Offset);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vmaVirtualFree(block, alloc2Offset);
|
||||||
//vmaClearVirtualBlock(block);
|
//vmaClearVirtualBlock(block);
|
||||||
vmaDestroyVirtualBlock(block);
|
vmaDestroyVirtualBlock(block);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user