Added support for recording and replaying object creation also when it originally failed.

This commit is contained in:
Adam Sawicki 2018-08-20 16:10:11 +02:00
parent e5d9b01a3a
commit 5c49bebe10
2 changed files with 139 additions and 102 deletions

View File

@ -501,7 +501,7 @@ private:
// If failed, prints warning, returns false and outPool = null.
bool FindPool(size_t lineNumber, uint64_t origPool, VmaPool& outPool);
// If allocation with that origPtr already exists, prints warning and replaces it.
void AddAllocation(size_t lineNumber, uint64_t origPtr, Allocation&& allocDesc);
void AddAllocation(size_t lineNumber, uint64_t origPtr, VkResult res, const char* functionName, Allocation&& allocDesc);
// Increments warning counter. Returns true if warning message should be printed.
bool IssueWarning();
@ -724,18 +724,58 @@ bool Player::FindPool(size_t lineNumber, uint64_t origPool, VmaPool& outPool)
return true;
}
void Player::AddAllocation(size_t lineNumber, uint64_t origPtr, Allocation&& allocDesc)
void Player::AddAllocation(size_t lineNumber, uint64_t origPtr, VkResult res, const char* functionName, Allocation&& allocDesc)
{
const auto existingIt = m_Allocations.find(origPtr);
if(existingIt != m_Allocations.end())
if(origPtr)
{
if(IssueWarning())
if(res == VK_SUCCESS)
{
printf("Line %zu: Allocation %llX already exists.\n", lineNumber, origPtr);
// Originally succeeded, currently succeeded.
// Just save pointer (done below).
}
else
{
// Originally succeeded, currently failed.
// Print warning. Save null pointer.
if(IssueWarning())
{
printf("Line %zu: %s failed (%d), while originally succeeded.\n", lineNumber, functionName, res);
}
}
const auto existingIt = m_Allocations.find(origPtr);
if(existingIt != m_Allocations.end())
{
if(IssueWarning())
{
printf("Line %zu: Allocation %llX already exists.\n", lineNumber, origPtr);
}
}
m_Allocations[origPtr] = std::move(allocDesc);
}
else
{
if(res == VK_SUCCESS)
{
// Originally failed, currently succeeded.
// Print warning, destroy the object.
if(IssueWarning())
{
printf("Line %zu: %s succeeded, originally failed.\n", lineNumber, functionName);
}
Destroy(allocDesc);
}
else
{
// Originally failed, currently failed.
// Print warning.
if(IssueWarning())
{
printf("Line %zu: %s failed (%d), originally also failed.\n", lineNumber, functionName, res);
}
}
}
m_Allocations[origPtr] = std::move(allocDesc);
}
bool Player::IssueWarning()
@ -1134,30 +1174,61 @@ void Player::ExecuteCreatePool(size_t lineNumber, const CsvSplit& csvSplit)
StrRangeToUint(csvSplit.GetRange(FIRST_PARAM_INDEX + 5), poolCreateInfo.frameInUseCount) &&
StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX + 6), origPtr))
{
m_Stats.RegisterCreatePool();
Pool poolDesc = {};
VkResult res = vmaCreatePool(m_Allocator, &poolCreateInfo, &poolDesc.pool);
if(res == VK_SUCCESS)
if(origPtr)
{
m_Stats.RegisterCreatePool();
if(res == VK_SUCCESS)
{
// Originally succeeded, currently succeeded.
// Just save pointer (done below).
}
else
{
// Originally succeeded, currently failed.
// Print warning. Save null pointer.
if(IssueWarning())
{
printf("Line %zu: vmaCreatePool failed (%d), while originally succeeded.\n", lineNumber, res);
}
}
const auto existingIt = m_Pools.find(origPtr);
if(existingIt != m_Pools.end())
{
if(IssueWarning())
{
printf("Line %zu: Pool %llX already exists.\n", lineNumber, origPtr);
}
}
m_Pools[origPtr] = poolDesc;
}
else
{
if(IssueWarning())
if(res == VK_SUCCESS)
{
printf("Line %zu: vmaCreatePool failed (%d).\n", lineNumber, res);
// Originally failed, currently succeeded.
// Print warning, destroy the pool.
if(IssueWarning())
{
printf("Line %zu: vmaCreatePool succeeded, originally failed.\n", lineNumber);
}
vmaDestroyPool(m_Allocator, poolDesc.pool);
}
else
{
// Originally failed, currently failed.
// Print warning.
if(IssueWarning())
{
printf("Line %zu: vmaCreatePool failed (%d), originally also failed.\n", lineNumber, res);
}
}
}
const auto existingIt = m_Pools.find(origPtr);
if(existingIt != m_Pools.end())
{
if(IssueWarning())
{
printf("Line %zu: Pool %llX already exists.\n", lineNumber, origPtr);
}
}
m_Pools[origPtr] = poolDesc;
}
else
{
@ -1227,21 +1298,11 @@ void Player::ExecuteCreateBuffer(size_t lineNumber, const CsvSplit& csvSplit)
{
FindPool(lineNumber, origPool, allocCreateInfo.pool);
m_Stats.RegisterCreateBuffer(bufCreateInfo.usage);
Allocation allocDesc = {};
VkResult res = vmaCreateBuffer(m_Allocator, &bufCreateInfo, &allocCreateInfo, &allocDesc.buffer, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS)
{
m_Stats.RegisterCreateBuffer(bufCreateInfo.usage);
}
else
{
if(IssueWarning())
{
printf("Line %zu: vmaCreateBuffer failed (%d).\n", lineNumber, res);
}
}
AddAllocation(lineNumber, origPtr, std::move(allocDesc));
AddAllocation(lineNumber, origPtr, res, "vmaCreateBuffer", std::move(allocDesc));
}
else
{
@ -1320,21 +1381,11 @@ void Player::ExecuteCreateImage(size_t lineNumber, const CsvSplit& csvSplit)
{
FindPool(lineNumber, origPool, allocCreateInfo.pool);
m_Stats.RegisterCreateImage(imageCreateInfo.usage, imageCreateInfo.tiling);
Allocation allocDesc = {};
VkResult res = vmaCreateImage(m_Allocator, &imageCreateInfo, &allocCreateInfo, &allocDesc.image, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS)
{
m_Stats.RegisterCreateImage(imageCreateInfo.usage, imageCreateInfo.tiling);
}
else
{
if(IssueWarning())
{
printf("Line %zu: vmaCreateImage failed (%d).\n", lineNumber, res);
}
}
AddAllocation(lineNumber, origPtr, std::move(allocDesc));
AddAllocation(lineNumber, origPtr, res, "vmaCreateImage", std::move(allocDesc));
}
else
{
@ -1358,7 +1409,7 @@ void Player::ExecuteCreateLostAllocation(size_t lineNumber, const CsvSplit& csvS
vmaCreateLostAllocation(m_Allocator, &allocDesc.allocation);
m_Stats.RegisterCreateAllocation();
AddAllocation(lineNumber, origPtr, std::move(allocDesc));
AddAllocation(lineNumber, origPtr, VK_SUCCESS, "vmaCreateLostAllocation", std::move(allocDesc));
}
else
{
@ -1392,21 +1443,11 @@ void Player::ExecuteAllocateMemory(size_t lineNumber, const CsvSplit& csvSplit)
{
FindPool(lineNumber, origPool, allocCreateInfo.pool);
m_Stats.RegisterCreateAllocation();
Allocation allocDesc = {};
VkResult res = vmaAllocateMemory(m_Allocator, &memReq, &allocCreateInfo, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS)
{
m_Stats.RegisterCreateAllocation();
}
else
{
if(IssueWarning())
{
printf("Line %zu: vmaAllocateMemory failed (%d).\n", lineNumber, res);
}
}
AddAllocation(lineNumber, origPtr, std::move(allocDesc));
AddAllocation(lineNumber, origPtr, res, "vmaAllocateMemory", std::move(allocDesc));
}
else
{
@ -1458,18 +1499,11 @@ void Player::ExecuteAllocateMemoryForBufferOrImage(size_t lineNumber, const CsvS
m_AllocateForBufferImageWarningIssued = true;
}
m_Stats.RegisterCreateAllocation();
Allocation allocDesc = {};
VkResult res = vmaAllocateMemory(m_Allocator, &memReq, &allocCreateInfo, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS)
{
m_Stats.RegisterCreateAllocation();
}
else
{
printf("Line %zu: vmaAllocateMemory (called as vmaAllocateMemoryForBuffer or vmaAllocateMemoryForImage) failed (%d).\n", lineNumber, res);
}
AddAllocation(lineNumber, origPtr, std::move(allocDesc));
AddAllocation(lineNumber, origPtr, res, "vmaAllocateMemory (called as vmaAllocateMemoryForBuffer or vmaAllocateMemoryForImage)", std::move(allocDesc));
}
else
{

View File

@ -8525,6 +8525,7 @@ VkResult VmaAllocator_T::Init(const VmaAllocatorCreateInfo* pCreateInfo)
}
m_pRecorder->RecordCreateAllocator(GetCurrentFrameIndex());
#else
VMA_ASSERT(0 && "VmaAllocatorCreateInfo::pRecordSettings used, but not supported due to VMA_RECORDING_ENABLED not defined to 1.");
return VK_ERROR_FEATURE_NOT_PRESENT;
#endif
}
@ -10212,7 +10213,7 @@ VkResult vmaCreatePool(
VkResult res = allocator->CreatePool(pCreateInfo, pPool);
#if VMA_RECORDING_ENABLED
if(res == VK_SUCCESS && allocator->GetRecorder() != VMA_NULL)
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordCreatePool(allocator->GetCurrentFrameIndex(), *pCreateInfo, *pPool);
}
@ -10305,7 +10306,7 @@ VkResult vmaAllocateMemory(
pAllocation);
#if VMA_RECORDING_ENABLED
if(result == VK_SUCCESS && allocator->GetRecorder() != VMA_NULL)
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordAllocateMemory(
allocator->GetCurrentFrameIndex(),
@ -10354,7 +10355,7 @@ VkResult vmaAllocateMemoryForBuffer(
pAllocation);
#if VMA_RECORDING_ENABLED
if(result == VK_SUCCESS && allocator->GetRecorder() != VMA_NULL)
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordAllocateMemoryForBuffer(
allocator->GetCurrentFrameIndex(),
@ -10404,7 +10405,7 @@ VkResult vmaAllocateMemoryForImage(
pAllocation);
#if VMA_RECORDING_ENABLED
if(result == VK_SUCCESS && allocator->GetRecorder() != VMA_NULL)
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordAllocateMemoryForImage(
allocator->GetCurrentFrameIndex(),
@ -10528,7 +10529,7 @@ VkResult vmaMapMemory(
VkResult res = allocator->Map(allocation, ppData);
#if VMA_RECORDING_ENABLED
if(res == VK_SUCCESS && allocator->GetRecorder() != VMA_NULL)
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordMapMemory(
allocator->GetCurrentFrameIndex(),
@ -10687,8 +10688,8 @@ VkResult vmaCreateBuffer(
allocator->GetBufferMemoryRequirements(*pBuffer, vkMemReq,
requiresDedicatedAllocation, prefersDedicatedAllocation);
// Make sure alignment requirements for specific buffer usages reported
// in Physical Device Properties are included in alignment reported by memory requirements.
// Make sure alignment requirements for specific buffer usages reported
// in Physical Device Properties are included in alignment reported by memory requirements.
if((pBufferCreateInfo->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) != 0)
{
VMA_ASSERT(vkMemReq.alignment %
@ -10715,6 +10716,18 @@ VkResult vmaCreateBuffer(
*pAllocationCreateInfo,
VMA_SUBALLOCATION_TYPE_BUFFER,
pAllocation);
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordCreateBuffer(
allocator->GetCurrentFrameIndex(),
*pBufferCreateInfo,
*pAllocationCreateInfo,
*pAllocation);
}
#endif
if(res >= 0)
{
// 3. Bind buffer with memory.
@ -10730,17 +10743,6 @@ VkResult vmaCreateBuffer(
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
}
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordCreateBuffer(
allocator->GetCurrentFrameIndex(),
*pBufferCreateInfo,
*pAllocationCreateInfo,
*pAllocation);
}
#endif
return VK_SUCCESS;
}
allocator->FreeMemory(*pAllocation);
@ -10837,6 +10839,18 @@ VkResult vmaCreateImage(
*pAllocationCreateInfo,
suballocType,
pAllocation);
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordCreateImage(
allocator->GetCurrentFrameIndex(),
*pImageCreateInfo,
*pAllocationCreateInfo,
*pAllocation);
}
#endif
if(res >= 0)
{
// 3. Bind image with memory.
@ -10852,17 +10866,6 @@ VkResult vmaCreateImage(
allocator->GetAllocationInfo(*pAllocation, pAllocationInfo);
}
#if VMA_RECORDING_ENABLED
if(allocator->GetRecorder() != VMA_NULL)
{
allocator->GetRecorder()->RecordCreateImage(
allocator->GetCurrentFrameIndex(),
*pImageCreateInfo,
*pAllocationCreateInfo,
*pAllocation);
}
#endif
return VK_SUCCESS;
}
allocator->FreeMemory(*pAllocation);