Record MemRefs for every VkDeviceMemory

This fixes an ambiguity between old captures (where missing MemRefs
indicates a lack of information, and we need to act pessimistically), vs
new captures where the memory contents were not accessed (e.g. only
bound to images). Now the latter case will have an explicit MemRefs
entry indicating that the memory was not referenced.

Change-Id: Ib76d56ef6f2e250952412b4cdbe0b2432a4ca0ec
This commit is contained in:
Benson Joeris
2020-02-21 17:16:08 -05:00
committed by Baldur Karlsson
parent aacf148201
commit 640fc256dd
3 changed files with 31 additions and 5 deletions
+24 -5
View File
@@ -535,13 +535,18 @@ bool VulkanResourceManager::Serialise_ImageRefs(ReadSerialiser &ser,
void VulkanResourceManager::InsertDeviceMemoryRefs(WriteSerialiser &ser)
{
rdcarray<MemRefInterval> data;
for(auto it = m_MemFrameRefs.begin(); it != m_MemFrameRefs.end(); it++)
MemRefs emptyMemRefs;
for(auto memIt = m_DeviceMemories.begin(); memIt != m_DeviceMemories.end(); memIt++)
{
ResourceId mem = it->first;
Intervals<FrameRefType> &rangeRefs = it->second.rangeRefs;
MemRefs *memRefs = NULL;
auto it = m_MemFrameRefs.find(*memIt);
if(it == m_MemFrameRefs.end())
memRefs = &emptyMemRefs;
else
memRefs = &it->second;
Intervals<FrameRefType> &rangeRefs = memRefs->rangeRefs;
for(auto jt = rangeRefs.begin(); jt != rangeRefs.end(); jt++)
data.push_back({mem, jt->start(), jt->value()});
data.push_back({*memIt, jt->start(), jt->value()});
}
uint64_t sizeEstimate = data.size() * sizeof(MemRefInterval) + 32;
@@ -851,6 +856,20 @@ void VulkanResourceManager::AddMemoryFrameRefs(ResourceId mem)
m_MemFrameRefs.insert({mem, MemRefs()});
}
void VulkanResourceManager::AddDeviceMemory(ResourceId mem)
{
SCOPED_LOCK(m_Lock);
m_DeviceMemories.insert(mem);
}
void VulkanResourceManager::RemoveDeviceMemory(ResourceId mem)
{
SCOPED_LOCK(m_Lock);
m_DeviceMemories.erase(mem);
}
void VulkanResourceManager::MergeReferencedMemory(std::map<ResourceId, MemRefs> &memRefs)
{
SCOPED_LOCK(m_Lock);
+3
View File
@@ -425,6 +425,8 @@ public:
void MarkMemoryFrameReferenced(ResourceId mem, VkDeviceSize start, VkDeviceSize end,
FrameRefType refType);
void AddMemoryFrameRefs(ResourceId mem);
void AddDeviceMemory(ResourceId mem);
void RemoveDeviceMemory(ResourceId mem);
void MergeReferencedMemory(std::map<ResourceId, MemRefs> &memRefs);
void ClearReferencedMemory();
@@ -460,5 +462,6 @@ private:
WrappedVulkan *m_Core;
std::map<ResourceId, MemRefs> m_MemFrameRefs;
std::set<ResourceId> m_DeviceMemories;
InitPolicy m_InitPolicy = eInitPolicy_CopyAll;
};
@@ -471,6 +471,8 @@ VkResult WrappedVulkan::vkAllocateMemory(VkDevice device, const VkMemoryAllocate
record->memMapState->mapCoherent = (memProps & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0;
record->memMapState->refData = NULL;
}
GetResourceManager()->AddDeviceMemory(id);
}
else
{
@@ -539,6 +541,8 @@ void WrappedVulkan::vkFreeMemory(VkDevice device, VkDeviceMemory memory,
SCOPED_LOCK(m_CoherentMapsLock);
m_CoherentMaps.removeOne(wrapped->record);
}
GetResourceManager()->RemoveDeviceMemory(wrapped->id);
}
m_CreationInfo.erase(GetResID(memory));