Handle descriptor pools deleting their children implicitly on destroy

This commit is contained in:
baldurk
2015-10-12 21:09:39 +02:00
parent b28428cdf1
commit 8b7744e71c
3 changed files with 51 additions and 2 deletions
+34 -1
View File
@@ -141,7 +141,40 @@ class VulkanResourceManager : public ResourceManager<WrappedVkRes*, TypedRealHan
ResourceManager::MarkCleanResource(id);
ResourceManager::RemoveWrapper(ToTypedHandle(Unwrap(obj)));
ResourceManager::ReleaseCurrentResource(id);
if(GetRecord(obj)) GetRecord(obj)->Delete(this);
VkResourceRecord *record = GetRecord(obj);
if(record)
{
// we need to lock here because the app could be creating
// and deleting from this pool at the same time. We do know
// though that the pool isn't going to be destroyed while
// either allocation or freeing happens, so we only need to
// lock against concurrent allocs or deletes of children.
if(record->pool)
{
// here we lock against concurrent alloc/delete
record->pool->LockChunks();
for(auto it = record->pool->pooledChildren.begin(); it != record->pool->pooledChildren.end(); ++it)
{
if(*it == record)
{
// remove it from our pool so we don't try and destroy it
record->pool->pooledChildren.erase(it);
break;
}
}
record->pool->UnlockChunks();
}
else if(record->pooledChildren.size())
{
// delete all of our children
for(auto it = record->pooledChildren.begin(); it != record->pooledChildren.end(); ++it)
(*it)->Delete(this);
record->pooledChildren.clear();
}
record->Delete(this);
}
if(clearID)
{
// note the nulling of the wrapped object's ID here is rather unpleasant,
+6
View File
@@ -557,6 +557,7 @@ struct VkResourceRecord : public ResourceRecord
VkResourceRecord(ResourceId id) :
ResourceRecord(id, true),
bakedCommands(NULL),
pool(NULL),
memory(NULL)
{
}
@@ -641,6 +642,11 @@ struct VkResourceRecord : public ResourceRecord
// queues associated with this instance, so they can be shut down on destruction
vector<VkQueue> queues;
// pointer to either the pool this item is allocated from, or the children allocated
// from this pool. Protected by the chunk lock
VkResourceRecord *pool;
vector<VkResourceRecord *> pooledChildren;
// descriptor set bindings for this descriptor set. Filled out on
// create from the layout.
ResourceId layout;
@@ -269,7 +269,17 @@ VkResult WrappedVulkan::vkAllocDescriptorSets(
ResourceId layoutID = GetResID(pSetLayouts[i]);
record->AddParent(GetRecord(descriptorPool));
VkResourceRecord *poolrecord = GetRecord(descriptorPool);
{
poolrecord->LockChunks();
poolrecord->pooledChildren.push_back(record);
poolrecord->UnlockChunks();
}
record->pool = poolrecord;
record->AddParent(poolrecord);
record->AddParent(GetResourceManager()->GetResourceRecord(layoutID));
// just always treat descriptor sets as dirty