Keep chunk allocator memory in resource records in D3D12

* These records can then be kept alive during capture even if the resource is
  released.
This commit is contained in:
baldurk
2021-04-23 20:33:28 +01:00
parent e8e4e64182
commit acf9987055
7 changed files with 30 additions and 7 deletions
@@ -438,7 +438,8 @@ HRESULT WrappedID3D12GraphicsCommandList::ResetInternal(ID3D12CommandAllocator *
m_ListRecord->bakedCommands->InternalResource = true;
m_ListRecord->bakedCommands->cmdInfo = new CmdListRecordingInfo();
m_ListRecord->cmdInfo->alloc = &((WrappedID3D12CommandAllocator *)pAllocator)->alloc;
m_ListRecord->cmdInfo->alloc = ((WrappedID3D12CommandAllocator *)pAllocator)->alloc;
m_ListRecord->cmdInfo->allocRecord = GetRecord(pAllocator);
{
CACHE_THREAD_SERIALISER();
@@ -155,6 +155,7 @@ class WrappedID3D12CommandQueue : public ID3D12CommandQueue,
WrappedID3D12CompatibilityQueue m_WrappedCompat;
rdcarray<D3D12ResourceRecord *> m_CmdListRecords;
rdcarray<D3D12ResourceRecord *> m_CmdListAllocators;
std::unordered_set<ResourceId> m_SparseBindResources;
@@ -850,6 +850,9 @@ void WrappedID3D12CommandQueue::ExecuteCommandListsInternal(UINT NumCommandLists
m_CmdListRecords.push_back(record->bakedCommands->cmdInfo->bundles[sub]->bakedCommands);
}
m_CmdListAllocators.push_back(record->bakedCommands->cmdInfo->allocRecord);
record->bakedCommands->cmdInfo->allocRecord->AddRef();
record->bakedCommands->AddRef();
}
@@ -535,7 +535,11 @@ void WrappedID3D12CommandQueue::ClearAfterCapture()
for(size_t i = 0; i < m_CmdListRecords.size(); i++)
m_CmdListRecords[i]->Delete(GetResourceManager());
for(size_t i = 0; i < m_CmdListAllocators.size(); i++)
m_CmdListAllocators[i]->Delete(GetResourceManager());
m_CmdListRecords.clear();
m_CmdListAllocators.clear();
m_QueueRecord->DeleteChunks();
}
@@ -231,6 +231,11 @@ HRESULT WrappedID3D12Device::CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE type
record->Length = 0;
wrapped->SetResourceRecord(record);
record->cmdInfo = new CmdListRecordingInfo;
record->cmdInfo->allocPool = new ChunkPagePool(32 * 1024);
record->cmdInfo->alloc = new ChunkAllocator(*record->cmdInfo->allocPool);
record->AddChunk(scope.Get());
}
else
+11 -1
View File
@@ -420,7 +420,10 @@ struct D3D12ResourceRecord;
struct CmdListRecordingInfo
{
ChunkAllocator *alloc;
ChunkPagePool *allocPool = NULL;
ChunkAllocator *alloc = NULL;
D3D12ResourceRecord *allocRecord = NULL;
rdcarray<D3D12_RESOURCE_BARRIER> barriers;
@@ -503,6 +506,11 @@ struct D3D12ResourceRecord : public ResourceRecord
}
~D3D12ResourceRecord()
{
if(type == Resource_CommandAllocator)
{
SAFE_DELETE(cmdInfo->alloc);
SAFE_DELETE(cmdInfo->allocPool);
}
SAFE_DELETE(cmdInfo);
SAFE_DELETE(sparseTable);
SAFE_DELETE_ARRAY(m_Maps);
@@ -515,6 +523,8 @@ struct D3D12ResourceRecord : public ResourceRecord
cmdInfo->dirtied.swap(bakedCommands->cmdInfo->dirtied);
cmdInfo->boundDescs.swap(bakedCommands->cmdInfo->boundDescs);
cmdInfo->bundles.swap(bakedCommands->cmdInfo->bundles);
bakedCommands->cmdInfo->alloc = cmdInfo->alloc;
bakedCommands->cmdInfo->allocRecord = cmdInfo->allocRecord;
}
D3D12ResourceType type;
+4 -5
View File
@@ -333,8 +333,7 @@ class WrappedID3D12CommandAllocator : public WrappedDeviceChild12<ID3D12CommandA
public:
ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12CommandAllocator);
ChunkPagePool allocPool;
ChunkAllocator alloc;
ChunkAllocator *alloc = NULL;
bool m_Internal = false;
enum
@@ -343,7 +342,7 @@ public:
};
WrappedID3D12CommandAllocator(ID3D12CommandAllocator *real, WrappedID3D12Device *device)
: WrappedDeviceChild12(real, device), allocPool(32 * 1024), alloc(allocPool)
: WrappedDeviceChild12(real, device)
{
}
virtual ~WrappedID3D12CommandAllocator() { Shutdown(); }
@@ -356,8 +355,8 @@ public:
{
// reset the allocator. D3D12 munges the pool and the allocator together, so the allocator
// becomes redundant as the only pool client and the pool is reset together.
if(Atomic::CmpExch32(&m_ResetEnabled, 1, 1) == 1)
alloc.Reset();
if(Atomic::CmpExch32(&m_ResetEnabled, 1, 1) == 1 && alloc)
alloc->Reset();
return m_pReal->Reset();
}
};