Don't reference in-progress command buffer recordings. Closes #925

* When pulling in command buffers, we want to include their allocation
  chunk and descriptor pool. Previously we did this by marking their
  record as referenced, however this had the problem where if the
  application started recording new commands into that command buffer
  before the record was referenced and processed, the capture would
  include those chunks without any of the proper references etc.
* To avoid this, we take advantage of the fact that the allocation chunk
  is already stored in a separate record so that it doesn't get thrown
  away every time the command buffer is baked. We can instead directly
  reference this record when pulling in at submit time.
This commit is contained in:
baldurk
2018-04-20 16:40:18 +01:00
parent 550f4f4424
commit af4dbcd29b
2 changed files with 10 additions and 7 deletions
@@ -517,9 +517,10 @@ VkResult WrappedVulkan::vkAllocateCommandBuffers(VkDevice device,
}
// a bit of a hack, we make a parallel resource record with the same lifetime as the command
// buffer and make it a parent, so it will hold onto our allocation chunk and not try to
// record it (and throw it away with baked commands that are unused), then it'll be pulled
// into the capture.
// buffer, so it will hold onto our allocation chunk & pool parent.
// It will be pulled into the capture explicitly, since the command buffer record itself is
// used directly for recording in-progress commands, and we can't pull that in since it
// might be partially recorded at the time of a submit of a previously baked list.
VkResourceRecord *allocRecord =
GetResourceManager()->AddResourceRecord(ResourceIDGen::GetNewUniqueID());
allocRecord->SpecialResource = true;
@@ -529,7 +530,7 @@ VkResult WrappedVulkan::vkAllocateCommandBuffers(VkDevice device,
record->bakedCommands = NULL;
record->pool = GetRecord(pAllocateInfo->commandPool);
record->AddParent(record->pool);
allocRecord->AddParent(record->pool);
{
record->pool->LockChunks();
@@ -652,8 +652,9 @@ VkResult WrappedVulkan::vkQueueSubmit(VkQueue queue, uint32_t submitCount,
record->bakedCommands->AddResourceReferences(GetResourceManager());
record->bakedCommands->AddReferencedIDs(refdIDs);
// ref the parent command buffer by itself, this will pull in the cmd buffer pool
GetResourceManager()->MarkResourceFrameReferenced(record->GetResourceID(), eFrameRef_Read);
// ref the parent command buffer's alloc record, this will pull in the cmd buffer pool
GetResourceManager()->MarkResourceFrameReferenced(
record->cmdInfo->allocRecord->GetResourceID(), eFrameRef_Read);
for(size_t sub = 0; sub < record->bakedCommands->cmdInfo->subcmds.size(); sub++)
{
@@ -661,7 +662,8 @@ VkResult WrappedVulkan::vkQueueSubmit(VkQueue queue, uint32_t submitCount,
GetResourceManager());
record->bakedCommands->cmdInfo->subcmds[sub]->bakedCommands->AddReferencedIDs(refdIDs);
GetResourceManager()->MarkResourceFrameReferenced(
record->bakedCommands->cmdInfo->subcmds[sub]->GetResourceID(), eFrameRef_Read);
record->bakedCommands->cmdInfo->subcmds[sub]->cmdInfo->allocRecord->GetResourceID(),
eFrameRef_Read);
record->bakedCommands->cmdInfo->subcmds[sub]->bakedCommands->AddRef();
}