Add range info to Vulkan memory tracking.

In the capture-time tracking of resource usage, this change adds information on
the offset and size of accesses to Vulkan VkDeviceMemory. This information is
curretnly discarded, but will be used in a later change to implement
finer-grained usage tracking for VkDeviceMemory.
This commit is contained in:
Benson Joeris
2019-02-01 11:16:55 -05:00
committed by Baldur Karlsson
parent 967d03083d
commit a9cedfda25
7 changed files with 137 additions and 116 deletions
+11 -2
View File
@@ -365,14 +365,17 @@ void VulkanResourceManager::MarkSparseMapReferenced(ResourceInfo *sparse)
}
for(size_t i = 0; i < sparse->opaquemappings.size(); i++)
MarkResourceFrameReferenced(GetResID(sparse->opaquemappings[i].memory), eFrameRef_Read);
MarkMemoryFrameReferenced(GetResID(sparse->opaquemappings[i].memory),
sparse->opaquemappings[i].memoryOffset,
sparse->opaquemappings[i].size, eFrameRef_Read);
for(int a = 0; a < NUM_VK_IMAGE_ASPECTS; a++)
{
VkDeviceSize totalSize =
VkDeviceSize(sparse->imgdim.width) * sparse->imgdim.height * sparse->imgdim.depth;
for(VkDeviceSize i = 0; sparse->pages[a] && i < totalSize; i++)
MarkResourceFrameReferenced(GetResID(sparse->pages[a][i].first), eFrameRef_Read);
MarkMemoryFrameReferenced(GetResID(sparse->pages[a][i].first), 0, VK_WHOLE_SIZE,
eFrameRef_Read);
}
}
@@ -604,6 +607,12 @@ ResourceId VulkanResourceManager::GetFirstIDForHandle(uint64_t handle)
return ResourceId();
}
void VulkanResourceManager::MarkMemoryFrameReferenced(ResourceId mem, VkDeviceSize offset,
VkDeviceSize size, FrameRefType refType)
{
MarkResourceFrameReferenced(mem, refType);
}
bool VulkanResourceManager::Force_InitialState(WrappedVkRes *res, bool prepare)
{
return false;
+3
View File
@@ -410,6 +410,9 @@ public:
void SetInternalResource(ResourceId id);
void MarkMemoryFrameReferenced(ResourceId mem, VkDeviceSize start, VkDeviceSize end,
FrameRefType refType);
private:
bool ResourceTypeRelease(WrappedVkRes *res);
+35
View File
@@ -3030,6 +3030,41 @@ VkResourceRecord::~VkResourceRecord()
SAFE_DELETE(descTemplateInfo);
}
void VkResourceRecord::MarkMemoryFrameReferenced(ResourceId mem, VkDeviceSize offset,
VkDeviceSize size, FrameRefType refType)
{
MarkResourceFrameReferenced(mem, refType);
}
void VkResourceRecord::MarkBufferFrameReferenced(VkResourceRecord *buf, VkDeviceSize offset,
VkDeviceSize size, FrameRefType refType)
{
// mark buffer just as read
MarkResourceFrameReferenced(buf->GetResourceID(), eFrameRef_Read);
if(size == VK_WHOLE_SIZE)
{
size = buf->memSize;
}
if(buf->resInfo)
cmdInfo->sparse.insert(buf->resInfo);
if(buf->baseResource != ResourceId())
MarkMemoryFrameReferenced(buf->baseResource, buf->memOffset + offset, size, refType);
}
void VkResourceRecord::MarkBufferViewFrameReferenced(VkResourceRecord *bufView, FrameRefType refType)
{
// mark the VkBufferView and VkBuffer as read
MarkResourceFrameReferenced(bufView->GetResourceID(), eFrameRef_Read);
MarkResourceFrameReferenced(bufView->baseResource, eFrameRef_Read);
if(bufView->resInfo)
cmdInfo->sparse.insert(bufView->resInfo);
if(bufView->baseResource != ResourceId())
MarkMemoryFrameReferenced(bufView->baseResourceMem, bufView->memOffset, bufView->memSize,
refType);
}
void ResourceInfo::Update(uint32_t numBindings, const VkSparseImageMemoryBind *pBindings)
{
// update image page table mappings
+8
View File
@@ -1097,6 +1097,14 @@ public:
ResourceId baseResource;
ResourceId baseResourceMem; // for image views, we need to point to both the image and mem
VkDeviceSize memOffset;
VkDeviceSize memSize;
void MarkMemoryFrameReferenced(ResourceId mem, VkDeviceSize offset, VkDeviceSize size,
FrameRefType refType);
void MarkBufferFrameReferenced(VkResourceRecord *buf, VkDeviceSize offset, VkDeviceSize size,
FrameRefType refType);
void MarkBufferViewFrameReferenced(VkResourceRecord *buf, FrameRefType refType);
// these are all disjoint, so only a record of the right type will have each
// Note some of these need to be deleted in the constructor, so we check the
// allocation type of the Resource
@@ -2190,10 +2190,8 @@ void WrappedVulkan::vkCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32
record->AddChunk(scope.Get());
for(uint32_t i = 0; i < bindingCount; i++)
{
record->MarkResourceFrameReferenced(GetResID(pBuffers[i]), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(pBuffers[i])->baseResource, eFrameRef_Read);
if(GetRecord(pBuffers[i])->resInfo)
record->cmdInfo->sparse.insert(GetRecord(pBuffers[i])->resInfo);
record->MarkBufferFrameReferenced(GetRecord(pBuffers[i]), pOffsets[i], VK_WHOLE_SIZE,
eFrameRef_Read);
}
}
}
@@ -2267,10 +2265,7 @@ void WrappedVulkan::vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer
Serialise_vkCmdBindIndexBuffer(ser, commandBuffer, buffer, offset, indexType);
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(buffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(buffer)->baseResource, eFrameRef_Read);
if(GetRecord(buffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(buffer)->resInfo);
record->MarkBufferFrameReferenced(GetRecord(buffer), 0, VK_WHOLE_SIZE, eFrameRef_Read);
}
}
@@ -2335,15 +2330,7 @@ void WrappedVulkan::vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer de
record->AddChunk(scope.Get());
VkResourceRecord *buf = GetRecord(destBuffer);
// mark buffer just as read, and memory behind as write & dirtied
record->MarkResourceFrameReferenced(buf->GetResourceID(), eFrameRef_Read);
record->MarkResourceFrameReferenced(buf->baseResource, eFrameRef_Write);
if(buf->baseResource != ResourceId())
record->cmdInfo->dirtied.insert(buf->baseResource);
if(buf->resInfo)
record->cmdInfo->sparse.insert(buf->resInfo);
record->MarkBufferFrameReferenced(GetRecord(destBuffer), destOffset, dataSize, eFrameRef_Write);
}
}
@@ -2404,15 +2391,7 @@ void WrappedVulkan::vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dest
record->AddChunk(scope.Get());
VkResourceRecord *buf = GetRecord(destBuffer);
// mark buffer just as read, and memory behind as write & dirtied
record->MarkResourceFrameReferenced(buf->GetResourceID(), eFrameRef_Read);
record->MarkResourceFrameReferenced(buf->baseResource, eFrameRef_Write);
if(buf->baseResource != ResourceId())
record->cmdInfo->dirtied.insert(buf->baseResource);
if(buf->resInfo)
record->cmdInfo->sparse.insert(buf->resInfo);
record->MarkBufferFrameReferenced(GetRecord(destBuffer), destOffset, fillSize, eFrameRef_Write);
}
}
@@ -2775,17 +2754,15 @@ void WrappedVulkan::vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQ
destBuffer, destOffset, destStride, flags);
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(queryPool), eFrameRef_Read);
VkResourceRecord *buf = GetRecord(destBuffer);
// mark buffer just as read, and memory behind as write & dirtied
record->MarkResourceFrameReferenced(buf->GetResourceID(), eFrameRef_Read);
record->MarkResourceFrameReferenced(buf->baseResource, eFrameRef_Write);
if(buf->baseResource != ResourceId())
record->cmdInfo->dirtied.insert(buf->baseResource);
if(buf->resInfo)
record->cmdInfo->sparse.insert(buf->resInfo);
VkDeviceSize size = (queryCount - 1) * destStride + 4;
if(flags & VK_QUERY_RESULT_64_BIT)
{
size += 4;
}
record->MarkBufferFrameReferenced(GetRecord(destBuffer), destOffset, size, eFrameRef_Write);
}
}
@@ -3804,10 +3781,8 @@ void WrappedVulkan::vkCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
if(write.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER ||
write.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)
{
record->MarkResourceFrameReferenced(GetResID(write.pTexelBufferView[d]), eFrameRef_Read);
if(GetRecord(write.pTexelBufferView[d])->baseResource != ResourceId())
record->MarkResourceFrameReferenced(GetRecord(write.pTexelBufferView[d])->baseResource,
ref);
VkResourceRecord *bufView = GetRecord(write.pTexelBufferView[d]);
record->MarkBufferViewFrameReferenced(bufView, ref);
}
else if(write.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
write.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ||
@@ -3833,10 +3808,9 @@ void WrappedVulkan::vkCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
}
else
{
record->MarkResourceFrameReferenced(GetResID(write.pBufferInfo[d].buffer), eFrameRef_Read);
if(GetRecord(write.pBufferInfo[d].buffer)->baseResource != ResourceId())
record->MarkResourceFrameReferenced(
GetRecord(write.pBufferInfo[d].buffer)->baseResource, ref);
record->MarkBufferFrameReferenced(GetRecord(write.pBufferInfo[d].buffer),
write.pBufferInfo[d].offset, write.pBufferInfo[d].range,
ref);
}
}
}
@@ -3975,6 +3949,8 @@ void WrappedVulkan::vkCmdPushDescriptorSetWithTemplateKHR(
// since it's relatively expensive to walk the memory, we gather frame references at the same time
// as unwrapping
std::vector<std::pair<ResourceId, FrameRefType> > frameRefs;
std::vector<std::pair<VkBufferView, FrameRefType> > bufViewFrameRefs;
std::vector<std::pair<VkDescriptorBufferInfo, FrameRefType> > bufFrameRefs;
{
DescUpdateTemplate *tempInfo = GetRecord(descriptorUpdateTemplate)->descTemplateInfo;
@@ -3999,9 +3975,7 @@ void WrappedVulkan::vkCmdPushDescriptorSetWithTemplateKHR(
VkBufferView *bufView = (VkBufferView *)dst;
frameRefs.push_back(std::make_pair(GetResID(*bufView), eFrameRef_Read));
if(GetRecord(*bufView)->baseResource != ResourceId())
frameRefs.push_back(std::make_pair(GetRecord(*bufView)->baseResource, ref));
bufViewFrameRefs.push_back(std::make_pair(*bufView, ref));
*bufView = Unwrap(*bufView);
}
@@ -4047,9 +4021,7 @@ void WrappedVulkan::vkCmdPushDescriptorSetWithTemplateKHR(
VkDescriptorBufferInfo *info = (VkDescriptorBufferInfo *)dst;
frameRefs.push_back(std::make_pair(GetResID(info->buffer), eFrameRef_Read));
if(GetRecord(info->buffer)->baseResource != ResourceId())
frameRefs.push_back(std::make_pair(GetRecord(info->buffer)->baseResource, ref));
bufFrameRefs.push_back(std::make_pair(*info, ref));
info->buffer = Unwrap(info->buffer);
}
@@ -4076,6 +4048,13 @@ void WrappedVulkan::vkCmdPushDescriptorSetWithTemplateKHR(
record->MarkResourceFrameReferenced(GetResID(descriptorUpdateTemplate), eFrameRef_Read);
for(size_t i = 0; i < frameRefs.size(); i++)
record->MarkResourceFrameReferenced(frameRefs[i].first, frameRefs[i].second);
for(size_t i = 0; i < bufViewFrameRefs.size(); i++)
record->MarkBufferViewFrameReferenced(GetRecord(bufViewFrameRefs[i].first),
bufViewFrameRefs[i].second);
for(size_t i = 0; i < bufFrameRefs.size(); i++)
record->MarkBufferFrameReferenced(GetRecord(bufFrameRefs[i].first.buffer),
bufFrameRefs[i].first.offset, bufFrameRefs[i].first.range,
bufFrameRefs[i].second);
}
}
@@ -4142,15 +4121,7 @@ void WrappedVulkan::vkCmdWriteBufferMarkerAMD(VkCommandBuffer commandBuffer,
record->AddChunk(scope.Get());
VkResourceRecord *buf = GetRecord(dstBuffer);
// mark buffer just as read, and memory behind as write & dirtied
record->MarkResourceFrameReferenced(buf->GetResourceID(), eFrameRef_Read);
record->MarkResourceFrameReferenced(buf->baseResource, eFrameRef_Write);
if(buf->baseResource != ResourceId())
record->cmdInfo->dirtied.insert(buf->baseResource);
if(buf->resInfo)
record->cmdInfo->sparse.insert(buf->resInfo);
record->MarkBufferFrameReferenced(GetRecord(dstBuffer), dstOffset, 4, eFrameRef_Write);
}
}
@@ -4505,10 +4476,12 @@ void WrappedVulkan::vkCmdBindTransformFeedbackBuffersEXT(VkCommandBuffer command
record->AddChunk(scope.Get());
for(uint32_t i = 0; i < bindingCount; i++)
{
record->MarkResourceFrameReferenced(GetResID(pBuffers[i]), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(pBuffers[i])->baseResource, eFrameRef_Read);
if(GetRecord(pBuffers[i])->resInfo)
record->cmdInfo->sparse.insert(GetRecord(pBuffers[i])->resInfo);
VkDeviceSize size = VK_WHOLE_SIZE;
if(pSizes != NULL)
{
size = pSizes[i];
}
record->MarkBufferFrameReferenced(GetRecord(pBuffers[i]), pOffsets[i], size, eFrameRef_Read);
}
}
}
@@ -738,10 +738,12 @@ void WrappedVulkan::vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer bu
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(buffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(buffer)->baseResource, eFrameRef_Read);
if(GetRecord(buffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(buffer)->resInfo);
VkDeviceSize size = 0;
if(count > 0)
{
size = (count - 1) * stride + sizeof(VkDrawIndirectCommand);
}
record->MarkBufferFrameReferenced(GetRecord(buffer), offset, size, eFrameRef_Read);
}
}
@@ -1117,10 +1119,12 @@ void WrappedVulkan::vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBu
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(buffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(buffer)->baseResource, eFrameRef_Read);
if(GetRecord(buffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(buffer)->resInfo);
VkDeviceSize size = 0;
if(count > 0)
{
size = (count - 1) * stride + sizeof(VkDrawIndexedIndirectCommand);
}
record->MarkBufferFrameReferenced(GetRecord(buffer), offset, size, eFrameRef_Read);
}
}
@@ -1288,10 +1292,8 @@ void WrappedVulkan::vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffe
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(buffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(buffer)->baseResource, eFrameRef_Read);
if(GetRecord(buffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(buffer)->resInfo);
record->MarkBufferFrameReferenced(GetRecord(buffer), offset, sizeof(VkDispatchIndirectCommand),
eFrameRef_Read);
}
}
@@ -2004,20 +2006,13 @@ void WrappedVulkan::vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcB
Serialise_vkCmdCopyBuffer(ser, commandBuffer, srcBuffer, destBuffer, regionCount, pRegions);
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(srcBuffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(srcBuffer)->baseResource, eFrameRef_Read);
VkResourceRecord *buf = GetRecord(destBuffer);
// mark buffer just as read, and memory behind as write & dirtied
record->MarkResourceFrameReferenced(buf->GetResourceID(), eFrameRef_Read);
record->MarkResourceFrameReferenced(buf->baseResource, eFrameRef_Write);
if(buf->baseResource != ResourceId())
record->cmdInfo->dirtied.insert(buf->baseResource);
if(GetRecord(srcBuffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(srcBuffer)->resInfo);
if(buf->resInfo)
record->cmdInfo->sparse.insert(buf->resInfo);
for(uint32_t i = 0; i < regionCount; i++)
{
record->MarkBufferFrameReferenced(GetRecord(srcBuffer), pRegions[i].srcOffset,
pRegions[i].size, eFrameRef_Read);
record->MarkBufferFrameReferenced(GetRecord(destBuffer), pRegions[i].dstOffset,
pRegions[i].size, eFrameRef_Write);
}
}
}
@@ -2782,15 +2777,10 @@ void WrappedVulkan::vkCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkB
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(buffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(buffer)->baseResource, eFrameRef_Read);
if(GetRecord(buffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(buffer)->resInfo);
record->MarkResourceFrameReferenced(GetResID(countBuffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(countBuffer)->baseResource, eFrameRef_Read);
if(GetRecord(countBuffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(countBuffer)->resInfo);
record->MarkBufferFrameReferenced(GetRecord(buffer), offset,
stride * (maxDrawCount - 1) + sizeof(VkDrawIndirectCommand),
eFrameRef_Read);
record->MarkBufferFrameReferenced(GetRecord(countBuffer), countBufferOffset, 4, eFrameRef_Read);
}
}
@@ -3102,15 +3092,10 @@ void WrappedVulkan::vkCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuff
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(buffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(buffer)->baseResource, eFrameRef_Read);
if(GetRecord(buffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(buffer)->resInfo);
record->MarkResourceFrameReferenced(GetResID(countBuffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(countBuffer)->baseResource, eFrameRef_Read);
if(GetRecord(countBuffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(countBuffer)->resInfo);
record->MarkBufferFrameReferenced(GetRecord(buffer), offset,
stride * (maxDrawCount - 1) + sizeof(VkDrawIndirectCommand),
eFrameRef_Read);
record->MarkBufferFrameReferenced(GetRecord(countBuffer), countBufferOffset, 4, eFrameRef_Read);
}
}
@@ -3235,10 +3220,8 @@ void WrappedVulkan::vkCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer,
record->AddChunk(scope.Get());
record->MarkResourceFrameReferenced(GetResID(counterBuffer), eFrameRef_Read);
record->MarkResourceFrameReferenced(GetRecord(counterBuffer)->baseResource, eFrameRef_Read);
if(GetRecord(counterBuffer)->resInfo)
record->cmdInfo->sparse.insert(GetRecord(counterBuffer)->resInfo);
record->MarkBufferFrameReferenced(GetRecord(counterBuffer), counterBufferOffset, 4,
eFrameRef_Read);
}
}
@@ -655,7 +655,8 @@ void WrappedVulkan::vkUnmapMemory(VkDevice device, VkDeviceMemory mem)
else
{
m_FrameCaptureRecord->AddChunk(scope.Get());
GetResourceManager()->MarkResourceFrameReferenced(id, eFrameRef_Write);
GetResourceManager()->MarkMemoryFrameReferenced(id, state.mapOffset, state.mapSize,
eFrameRef_Write);
}
}
}
@@ -800,8 +801,9 @@ VkResult WrappedVulkan::vkFlushMappedMemoryRanges(VkDevice device, uint32_t memR
if(capframe)
{
GetResourceManager()->MarkResourceFrameReferenced(GetResID(pMemRanges[i].memory),
eFrameRef_Write);
GetResourceManager()->MarkMemoryFrameReferenced(GetResID(pMemRanges[i].memory),
pMemRanges[i].offset, pMemRanges[i].size,
eFrameRef_Write);
}
else
{
@@ -897,6 +899,7 @@ VkResult WrappedVulkan::vkBindBufferMemory(VkDevice device, VkBuffer buffer, VkD
record->AddParent(GetRecord(memory));
record->baseResource = GetResID(memory);
record->memOffset = memoryOffset;
}
return ret;
@@ -1089,6 +1092,7 @@ VkResult WrappedVulkan::vkCreateBuffer(VkDevice device, const VkBufferCreateInfo
VkResourceRecord *record = GetResourceManager()->AddResourceRecord(*pBuffer);
record->AddChunk(chunk);
record->memSize = pCreateInfo->size;
bool isSparse = (pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_BINDING_BIT |
VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT)) != 0;
@@ -1270,8 +1274,13 @@ VkResult WrappedVulkan::vkCreateBufferView(VkDevice device, const VkBufferViewCr
record->AddParent(bufferRecord);
// store the base resource
record->baseResource = bufferRecord->baseResource;
record->baseResource = bufferRecord->GetResourceID();
record->baseResourceMem = bufferRecord->baseResource;
record->resInfo = bufferRecord->resInfo;
record->memOffset = bufferRecord->memOffset + pCreateInfo->offset;
record->memSize = pCreateInfo->range;
if(record->memSize == VK_WHOLE_SIZE)
record->memSize = bufferRecord->memSize - pCreateInfo->offset;
}
else
{
@@ -1917,6 +1926,7 @@ VkResult WrappedVulkan::vkBindBufferMemory2(VkDevice device, uint32_t bindInfoCo
bufrecord->AddParent(memrecord);
bufrecord->baseResource = memrecord->GetResourceID();
bufrecord->memOffset = pBindInfos[i].memoryOffset;
}
}