Make vmaResizeAllocation deprecated, always return failure unless newSize == current size

Bump CSV file format version to 1,6.
This commit is contained in:
Adam Sawicki 2019-07-02 12:54:35 +02:00
parent 543ba5baec
commit 4a4cfad2eb
5 changed files with 38 additions and 244 deletions

View File

@ -23,7 +23,7 @@ Formats with only minor version incremented are backward compatible.
VmaReplay application supports all older versions.
Current version is:
1,5
1,6
# Configuration
@ -222,7 +222,7 @@ No parameters.
- pool : pointer
**vmaResizeAllocation** (min format version: 1.4)
**vmaResizeAllocation** (min format version: 1.4, max format version: 1.5)
- allocation : pointer
- newSize : uint64

View File

@ -333,7 +333,7 @@ Functions</h2></td></tr>
<tr class="memdesc:ab9e709de044c5d8476bea77a4e755840"><td class="mdescLeft">&#160;</td><td class="mdescRight">Frees memory and destroys multiple allocations. <a href="#ab9e709de044c5d8476bea77a4e755840">More...</a><br /></td></tr>
<tr class="separator:ab9e709de044c5d8476bea77a4e755840"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0ff488958ca72b28e545880463cb8696"><td class="memItemLeft" align="right" valign="top">VkResult&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="vk__mem__alloc_8h.html#a0ff488958ca72b28e545880463cb8696">vmaResizeAllocation</a> (<a class="el" href="struct_vma_allocator.html">VmaAllocator</a> allocator, <a class="el" href="struct_vma_allocation.html">VmaAllocation</a> allocation, VkDeviceSize newSize)</td></tr>
<tr class="memdesc:a0ff488958ca72b28e545880463cb8696"><td class="mdescLeft">&#160;</td><td class="mdescRight">Tries to resize an allocation in place, if there is enough free memory after it. <a href="#a0ff488958ca72b28e545880463cb8696">More...</a><br /></td></tr>
<tr class="memdesc:a0ff488958ca72b28e545880463cb8696"><td class="mdescLeft">&#160;</td><td class="mdescRight">Deprecated. <a href="#a0ff488958ca72b28e545880463cb8696">More...</a><br /></td></tr>
<tr class="separator:a0ff488958ca72b28e545880463cb8696"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a86dd08aba8633bfa4ad0df2e76481d8b"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b">vmaGetAllocationInfo</a> (<a class="el" href="struct_vma_allocator.html">VmaAllocator</a> allocator, <a class="el" href="struct_vma_allocation.html">VmaAllocation</a> allocation, <a class="el" href="struct_vma_allocation_info.html">VmaAllocationInfo</a> *pAllocationInfo)</td></tr>
<tr class="memdesc:a86dd08aba8633bfa4ad0df2e76481d8b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns current information about specified allocation and atomically marks it as used in current frame. <a href="#a86dd08aba8633bfa4ad0df2e76481d8b">More...</a><br /></td></tr>
@ -2700,15 +2700,8 @@ Functions</h2></td></tr>
</table>
</div><div class="memdoc">
<p>Tries to resize an allocation in place, if there is enough free memory after it. </p>
<p>Tries to change allocation's size without moving or reallocating it. You can both shrink and grow allocation size. When growing, it succeeds only when the allocation belongs to a memory block with enough free space after it.</p>
<p>Returns <code>VK_SUCCESS</code> if allocation's size has been successfully changed. Returns <code>VK_ERROR_OUT_OF_POOL_MEMORY</code> if allocation's size could not be changed.</p>
<p>After successful call to this function, <a class="el" href="struct_vma_allocation_info.html#aac76d113a6a5ccbb09fea00fb25fd18f" title="Size of this allocation, in bytes.">VmaAllocationInfo::size</a> of this allocation changes. All other parameters stay the same: memory pool and type, alignment, offset, mapped pointer.</p>
<ul>
<li>Calling this function on allocation that is in lost state fails with result <code>VK_ERROR_VALIDATION_FAILED_EXT</code>.</li>
<li>Calling this function with <code>newSize</code> same as current allocation size does nothing and returns <code>VK_SUCCESS</code>.</li>
<li>Resizing dedicated allocations, as well as allocations created in pools that use linear or buddy algorithm, is not supported. The function returns <code>VK_ERROR_FEATURE_NOT_PRESENT</code> in such cases. Support may be added in the future. </li>
</ul>
<p>Deprecated. </p>
<p>In version 2.2.0 it used to try to change allocation's size without moving or reallocating it. In current version it returns <code>VK_SUCCESS</code> only if <code>newSize</code> equals current allocation's size. Otherwise returns <code>VK_ERROR_OUT_OF_POOL_MEMORY</code>, indicating that allocation's size could not be changed. </p>
</div>
</div>

File diff suppressed because one or more lines are too long

View File

@ -688,7 +688,7 @@ static size_t g_DefragmentAfterLineNextIndex = 0;
static bool ValidateFileVersion()
{
if(GetVersionMajor(g_FileVersion) == 1 &&
GetVersionMinor(g_FileVersion) <= 5)
GetVersionMinor(g_FileVersion) <= 6)
{
return true;
}

View File

@ -2629,25 +2629,11 @@ void vmaFreeMemoryPages(
size_t allocationCount,
VmaAllocation* pAllocations);
/** \brief Tries to resize an allocation in place, if there is enough free memory after it.
/** \brief Deprecated.
Tries to change allocation's size without moving or reallocating it.
You can both shrink and grow allocation size.
When growing, it succeeds only when the allocation belongs to a memory block with enough
free space after it.
Returns `VK_SUCCESS` if allocation's size has been successfully changed.
Returns `VK_ERROR_OUT_OF_POOL_MEMORY` if allocation's size could not be changed.
After successful call to this function, VmaAllocationInfo::size of this allocation changes.
All other parameters stay the same: memory pool and type, alignment, offset, mapped pointer.
- Calling this function on allocation that is in lost state fails with result `VK_ERROR_VALIDATION_FAILED_EXT`.
- Calling this function with `newSize` same as current allocation size does nothing and returns `VK_SUCCESS`.
- Resizing dedicated allocations, as well as allocations created in pools that use linear
or buddy algorithm, is not supported.
The function returns `VK_ERROR_FEATURE_NOT_PRESENT` in such cases.
Support may be added in the future.
In version 2.2.0 it used to try to change allocation's size without moving or reallocating it.
In current version it returns `VK_SUCCESS` only if `newSize` equals current allocation's size.
Otherwise returns `VK_ERROR_OUT_OF_POOL_MEMORY`, indicating that allocation's size could not be changed.
*/
VkResult vmaResizeAllocation(
VmaAllocator allocator,
@ -5067,7 +5053,6 @@ public:
VmaDeviceMemoryBlock* block,
VkDeviceSize offset);
void ChangeSize(VkDeviceSize newSize);
void ChangeOffset(VkDeviceSize newOffset);
// pMappedData not null means allocation is created with MAPPED flag.
@ -5338,9 +5323,6 @@ public:
virtual void Free(const VmaAllocation allocation) = 0;
virtual void FreeAtOffset(VkDeviceSize offset) = 0;
// Tries to resize (grow or shrink) space for given allocation, in place.
virtual bool ResizeAllocation(const VmaAllocation alloc, VkDeviceSize newSize) { return false; }
protected:
const VkAllocationCallbacks* GetAllocationCallbacks() const { return m_pAllocationCallbacks; }
@ -5419,8 +5401,6 @@ public:
virtual void Free(const VmaAllocation allocation);
virtual void FreeAtOffset(VkDeviceSize offset);
virtual bool ResizeAllocation(const VmaAllocation alloc, VkDeviceSize newSize);
////////////////////////////////////////////////////////////////////////////////
// For defragmentation
@ -6555,10 +6535,6 @@ public:
void RecordFreeMemoryPages(uint32_t frameIndex,
uint64_t allocationCount,
const VmaAllocation* pAllocations);
void RecordResizeAllocation(
uint32_t frameIndex,
VmaAllocation allocation,
VkDeviceSize newSize);
void RecordSetAllocationUserData(uint32_t frameIndex,
VmaAllocation allocation,
const void* pUserData);
@ -7329,12 +7305,6 @@ void VmaAllocation_T::ChangeBlockAllocation(
m_BlockAllocation.m_Offset = offset;
}
void VmaAllocation_T::ChangeSize(VkDeviceSize newSize)
{
VMA_ASSERT(newSize > 0);
m_Size = newSize;
}
void VmaAllocation_T::ChangeOffset(VkDeviceSize newOffset)
{
VMA_ASSERT(m_Type == ALLOCATION_TYPE_BLOCK);
@ -8290,133 +8260,6 @@ void VmaBlockMetadata_Generic::FreeAtOffset(VkDeviceSize offset)
VMA_ASSERT(0 && "Not found!");
}
bool VmaBlockMetadata_Generic::ResizeAllocation(const VmaAllocation alloc, VkDeviceSize newSize)
{
typedef VmaSuballocationList::iterator iter_type;
for(iter_type suballocItem = m_Suballocations.begin();
suballocItem != m_Suballocations.end();
++suballocItem)
{
VmaSuballocation& suballoc = *suballocItem;
if(suballoc.hAllocation == alloc)
{
iter_type nextItem = suballocItem;
++nextItem;
// Should have been ensured on higher level.
VMA_ASSERT(newSize != alloc->GetSize() && newSize > 0);
// Shrinking.
if(newSize < alloc->GetSize())
{
const VkDeviceSize sizeDiff = suballoc.size - newSize;
// There is next item.
if(nextItem != m_Suballocations.end())
{
// Next item is free.
if(nextItem->type == VMA_SUBALLOCATION_TYPE_FREE)
{
// Grow this next item backward.
UnregisterFreeSuballocation(nextItem);
nextItem->offset -= sizeDiff;
nextItem->size += sizeDiff;
RegisterFreeSuballocation(nextItem);
}
// Next item is not free.
else
{
// Create free item after current one.
VmaSuballocation newFreeSuballoc;
newFreeSuballoc.hAllocation = VK_NULL_HANDLE;
newFreeSuballoc.offset = suballoc.offset + newSize;
newFreeSuballoc.size = sizeDiff;
newFreeSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
iter_type newFreeSuballocIt = m_Suballocations.insert(nextItem, newFreeSuballoc);
RegisterFreeSuballocation(newFreeSuballocIt);
++m_FreeCount;
}
}
// This is the last item.
else
{
// Create free item at the end.
VmaSuballocation newFreeSuballoc;
newFreeSuballoc.hAllocation = VK_NULL_HANDLE;
newFreeSuballoc.offset = suballoc.offset + newSize;
newFreeSuballoc.size = sizeDiff;
newFreeSuballoc.type = VMA_SUBALLOCATION_TYPE_FREE;
m_Suballocations.push_back(newFreeSuballoc);
iter_type newFreeSuballocIt = m_Suballocations.end();
RegisterFreeSuballocation(--newFreeSuballocIt);
++m_FreeCount;
}
suballoc.size = newSize;
m_SumFreeSize += sizeDiff;
}
// Growing.
else
{
const VkDeviceSize sizeDiff = newSize - suballoc.size;
// There is next item.
if(nextItem != m_Suballocations.end())
{
// Next item is free.
if(nextItem->type == VMA_SUBALLOCATION_TYPE_FREE)
{
// There is not enough free space, including margin.
if(nextItem->size < sizeDiff + VMA_DEBUG_MARGIN)
{
return false;
}
// There is more free space than required.
if(nextItem->size > sizeDiff)
{
// Move and shrink this next item.
UnregisterFreeSuballocation(nextItem);
nextItem->offset += sizeDiff;
nextItem->size -= sizeDiff;
RegisterFreeSuballocation(nextItem);
}
// There is exactly the amount of free space required.
else
{
// Remove this next free item.
UnregisterFreeSuballocation(nextItem);
m_Suballocations.erase(nextItem);
--m_FreeCount;
}
}
// Next item is not free - there is no space to grow.
else
{
return false;
}
}
// This is the last item - there is no space to grow.
else
{
return false;
}
suballoc.size = newSize;
m_SumFreeSize -= sizeDiff;
}
// We cannot call Validate() here because alloc object is updated to new size outside of this call.
return true;
}
}
VMA_ASSERT(0 && "Not found!");
return false;
}
bool VmaBlockMetadata_Generic::ValidateFreeSuballocationList() const
{
VkDeviceSize lastSize = 0;
@ -13632,7 +13475,7 @@ VkResult VmaRecorder::Init(const VmaRecordSettings& settings, bool useMutex)
// Write header.
fprintf(m_File, "%s\n", "Vulkan Memory Allocator,Calls recording");
fprintf(m_File, "%s\n", "1,5");
fprintf(m_File, "%s\n", "1,6");
return VK_SUCCESS;
}
@ -13828,20 +13671,6 @@ void VmaRecorder::RecordFreeMemoryPages(uint32_t frameIndex,
Flush();
}
void VmaRecorder::RecordResizeAllocation(
uint32_t frameIndex,
VmaAllocation allocation,
VkDeviceSize newSize)
{
CallParams callParams;
GetBasicParams(callParams);
VmaMutexLock lock(m_FileMutex, m_UseMutex);
fprintf(m_File, "%u,%.3f,%u,vmaResizeAllocation,%p,%llu\n", callParams.threadId, callParams.time, frameIndex,
allocation, newSize);
Flush();
}
void VmaRecorder::RecordSetAllocationUserData(uint32_t frameIndex,
VmaAllocation allocation,
const void* pUserData)
@ -14981,6 +14810,7 @@ VkResult VmaAllocator_T::ResizeAllocation(
const VmaAllocation alloc,
VkDeviceSize newSize)
{
// This function is deprecated and so it does nothing. It's left for backward compatibility.
if(newSize == 0 || alloc->GetLastUseFrameIndex() == VMA_FRAME_INDEX_LOST)
{
return VK_ERROR_VALIDATION_FAILED_EXT;
@ -14989,27 +14819,8 @@ VkResult VmaAllocator_T::ResizeAllocation(
{
return VK_SUCCESS;
}
switch(alloc->GetType())
{
case VmaAllocation_T::ALLOCATION_TYPE_DEDICATED:
return VK_ERROR_FEATURE_NOT_PRESENT;
case VmaAllocation_T::ALLOCATION_TYPE_BLOCK:
if(alloc->GetBlock()->m_pMetadata->ResizeAllocation(alloc, newSize))
{
alloc->ChangeSize(newSize);
VMA_HEAVY_ASSERT(alloc->GetBlock()->m_pMetadata->Validate());
return VK_SUCCESS;
}
else
{
return VK_ERROR_OUT_OF_POOL_MEMORY;
}
default:
VMA_ASSERT(0);
return VK_ERROR_VALIDATION_FAILED_EXT;
}
}
void VmaAllocator_T::CalculateStats(VmaStats* pStats)
{
@ -16459,16 +16270,6 @@ VkResult vmaResizeAllocation(
VMA_DEBUG_GLOBAL_MUTEX_LOCK
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordResizeAllocation(
allocator->GetCurrentFrameIndex(),
allocation,
newSize);
}
#endif
return allocator->ResizeAllocation(allocation, newSize);
}