Handle maps on D3D12 of different aliases in a placed heap

* We need to check for map writes even if the mapped buffer isn't the one that's
  referenced by a submit but still overlaps it. We do this by moving to the heap
  for all placed resources so any map to a buffer on a heap is checked as long
  as any buffer bound to that heap is referenced.
This commit is contained in:
baldurk
2023-03-13 17:39:16 +00:00
parent f4529141d2
commit 36731cb841
7 changed files with 194 additions and 3 deletions
@@ -886,6 +886,12 @@ void WrappedID3D12CommandQueue::ExecuteCommandListsInternal(UINT NumCommandLists
{
rdcarray<MapState> maps = m_pDevice->GetMaps();
// get the Mappable referenced IDs. With the case of placed resources the resource that's
// mapped may not be the one that was bound but they may overlap, so we use the heap as
// reference for non-committed resource.
std::unordered_set<ResourceId> mappableIDs;
WrappedID3D12Resource::GetMappableIDs(GetResourceManager(), refdIDs, mappableIDs);
for(auto it = maps.begin(); it != maps.end(); ++it)
{
WrappedID3D12Resource *res = GetWrapped(it->res);
@@ -893,10 +899,10 @@ void WrappedID3D12CommandQueue::ExecuteCommandListsInternal(UINT NumCommandLists
size_t size = (size_t)it->totalSize;
// only need to flush memory that could affect this submitted batch of work
if(refdIDs.find(res->GetResourceID()) == refdIDs.end())
if(mappableIDs.find(res->GetMappableID()) == mappableIDs.end())
{
RDCDEBUG("Map of memory %s not referenced in this queue - not flushing",
ToStr(res->GetResourceID()).c_str());
RDCDEBUG("Map of memory %s (mappable ID %s) not referenced in this queue - not flushing",
ToStr(res->GetResourceID()).c_str(), ToStr(res->GetMappableID()).c_str());
continue;
}
@@ -327,6 +327,22 @@ void WrappedID3D12Resource::RefBuffers(D3D12ResourceManager *rm)
rm->MarkResourceFrameReferenced(m_Addresses.addresses[i].id, eFrameRef_Read);
}
void WrappedID3D12Resource::GetMappableIDs(D3D12ResourceManager *rm,
const std::unordered_set<ResourceId> &refdIDs,
std::unordered_set<ResourceId> &mappableIDs)
{
SCOPED_READLOCK(m_Addresses.addressLock);
for(size_t i = 0; i < m_Addresses.addresses.size(); i++)
{
if(refdIDs.find(m_Addresses.addresses[i].id) != refdIDs.end())
{
WrappedID3D12Resource *resource =
(WrappedID3D12Resource *)rm->GetCurrentResource(m_Addresses.addresses[i].id);
mappableIDs.insert(resource->GetMappableID());
}
}
}
rdcarray<ID3D12Resource *> WrappedID3D12Resource::AddRefBuffersBeforeCapture(D3D12ResourceManager *rm)
{
rdcarray<ID3D12Resource *> ret;
+9
View File
@@ -946,12 +946,21 @@ public:
return this->GetReal();
}
ResourceId GetMappableID()
{
if(m_Heap)
return m_Heap->GetResourceID();
return this->GetResourceID();
}
void SetHeap(ID3D12Heap *heap)
{
m_Heap = (WrappedID3D12Heap *)heap;
SAFE_ADDREF(m_Heap);
}
static void RefBuffers(D3D12ResourceManager *rm);
static void GetMappableIDs(D3D12ResourceManager *rm, const std::unordered_set<ResourceId> &refdIDs,
std::unordered_set<ResourceId> &mappableIDs);
static rdcarray<ID3D12Resource *> AddRefBuffersBeforeCapture(D3D12ResourceManager *rm);