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. // If failed, prints warning, returns false and outPool = null.
bool FindPool(size_t lineNumber, uint64_t origPool, VmaPool& outPool); bool FindPool(size_t lineNumber, uint64_t origPool, VmaPool& outPool);
// If allocation with that origPtr already exists, prints warning and replaces it. // 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. // Increments warning counter. Returns true if warning message should be printed.
bool IssueWarning(); bool IssueWarning();
@ -724,18 +724,58 @@ bool Player::FindPool(size_t lineNumber, uint64_t origPool, VmaPool& outPool)
return true; 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(origPtr)
if(existingIt != m_Allocations.end())
{ {
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() 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) && StrRangeToUint(csvSplit.GetRange(FIRST_PARAM_INDEX + 5), poolCreateInfo.frameInUseCount) &&
StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX + 6), origPtr)) StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX + 6), origPtr))
{ {
m_Stats.RegisterCreatePool();
Pool poolDesc = {}; Pool poolDesc = {};
VkResult res = vmaCreatePool(m_Allocator, &poolCreateInfo, &poolDesc.pool); 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 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 else
{ {
@ -1227,21 +1298,11 @@ void Player::ExecuteCreateBuffer(size_t lineNumber, const CsvSplit& csvSplit)
{ {
FindPool(lineNumber, origPool, allocCreateInfo.pool); FindPool(lineNumber, origPool, allocCreateInfo.pool);
m_Stats.RegisterCreateBuffer(bufCreateInfo.usage);
Allocation allocDesc = {}; Allocation allocDesc = {};
VkResult res = vmaCreateBuffer(m_Allocator, &bufCreateInfo, &allocCreateInfo, &allocDesc.buffer, &allocDesc.allocation, nullptr); VkResult res = vmaCreateBuffer(m_Allocator, &bufCreateInfo, &allocCreateInfo, &allocDesc.buffer, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS) AddAllocation(lineNumber, origPtr, res, "vmaCreateBuffer", std::move(allocDesc));
{
m_Stats.RegisterCreateBuffer(bufCreateInfo.usage);
}
else
{
if(IssueWarning())
{
printf("Line %zu: vmaCreateBuffer failed (%d).\n", lineNumber, res);
}
}
AddAllocation(lineNumber, origPtr, std::move(allocDesc));
} }
else else
{ {
@ -1320,21 +1381,11 @@ void Player::ExecuteCreateImage(size_t lineNumber, const CsvSplit& csvSplit)
{ {
FindPool(lineNumber, origPool, allocCreateInfo.pool); FindPool(lineNumber, origPool, allocCreateInfo.pool);
m_Stats.RegisterCreateImage(imageCreateInfo.usage, imageCreateInfo.tiling);
Allocation allocDesc = {}; Allocation allocDesc = {};
VkResult res = vmaCreateImage(m_Allocator, &imageCreateInfo, &allocCreateInfo, &allocDesc.image, &allocDesc.allocation, nullptr); VkResult res = vmaCreateImage(m_Allocator, &imageCreateInfo, &allocCreateInfo, &allocDesc.image, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS) AddAllocation(lineNumber, origPtr, res, "vmaCreateImage", std::move(allocDesc));
{
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));
} }
else else
{ {
@ -1358,7 +1409,7 @@ void Player::ExecuteCreateLostAllocation(size_t lineNumber, const CsvSplit& csvS
vmaCreateLostAllocation(m_Allocator, &allocDesc.allocation); vmaCreateLostAllocation(m_Allocator, &allocDesc.allocation);
m_Stats.RegisterCreateAllocation(); m_Stats.RegisterCreateAllocation();
AddAllocation(lineNumber, origPtr, std::move(allocDesc)); AddAllocation(lineNumber, origPtr, VK_SUCCESS, "vmaCreateLostAllocation", std::move(allocDesc));
} }
else else
{ {
@ -1392,21 +1443,11 @@ void Player::ExecuteAllocateMemory(size_t lineNumber, const CsvSplit& csvSplit)
{ {
FindPool(lineNumber, origPool, allocCreateInfo.pool); FindPool(lineNumber, origPool, allocCreateInfo.pool);
m_Stats.RegisterCreateAllocation();
Allocation allocDesc = {}; Allocation allocDesc = {};
VkResult res = vmaAllocateMemory(m_Allocator, &memReq, &allocCreateInfo, &allocDesc.allocation, nullptr); VkResult res = vmaAllocateMemory(m_Allocator, &memReq, &allocCreateInfo, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS) AddAllocation(lineNumber, origPtr, res, "vmaAllocateMemory", std::move(allocDesc));
{
m_Stats.RegisterCreateAllocation();
}
else
{
if(IssueWarning())
{
printf("Line %zu: vmaAllocateMemory failed (%d).\n", lineNumber, res);
}
}
AddAllocation(lineNumber, origPtr, std::move(allocDesc));
} }
else else
{ {
@ -1458,18 +1499,11 @@ void Player::ExecuteAllocateMemoryForBufferOrImage(size_t lineNumber, const CsvS
m_AllocateForBufferImageWarningIssued = true; m_AllocateForBufferImageWarningIssued = true;
} }
m_Stats.RegisterCreateAllocation();
Allocation allocDesc = {}; Allocation allocDesc = {};
VkResult res = vmaAllocateMemory(m_Allocator, &memReq, &allocCreateInfo, &allocDesc.allocation, nullptr); VkResult res = vmaAllocateMemory(m_Allocator, &memReq, &allocCreateInfo, &allocDesc.allocation, nullptr);
if(res == VK_SUCCESS) AddAllocation(lineNumber, origPtr, res, "vmaAllocateMemory (called as vmaAllocateMemoryForBuffer or vmaAllocateMemoryForImage)", std::move(allocDesc));
{
m_Stats.RegisterCreateAllocation();
}
else
{
printf("Line %zu: vmaAllocateMemory (called as vmaAllocateMemoryForBuffer or vmaAllocateMemoryForImage) failed (%d).\n", lineNumber, res);
}
AddAllocation(lineNumber, origPtr, std::move(allocDesc));
} }
else else
{ {

View File

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