Handle MakeResident/Evict being refcounted, and handle placed resources

* Placed resources aren't directly resident or non-resident, it's the underlying
  heap that needs to be made resident or evicted.
This commit is contained in:
baldurk
2021-08-26 12:06:25 +01:00
parent a21d245114
commit 69a27aea40
8 changed files with 40 additions and 24 deletions
+2 -9
View File
@@ -152,8 +152,7 @@ class RefCounter12
{
private:
unsigned int m_iRefcount;
unsigned int m_InternalRefcount : 30;
unsigned int resident : 1;
unsigned int m_InternalRefcount : 31;
unsigned int m_SelfDeleting : 1;
protected:
@@ -165,11 +164,7 @@ protected:
public:
RefCounter12(RealType *real, bool selfDelete = true)
: m_pReal(real),
m_iRefcount(1),
m_InternalRefcount(0),
resident(1),
m_SelfDeleting(selfDelete ? 1 : 0)
: m_pReal(real), m_iRefcount(1), m_InternalRefcount(0), m_SelfDeleting(selfDelete ? 1 : 0)
{
}
virtual ~RefCounter12() {}
@@ -179,8 +174,6 @@ public:
// add them here and they're subtracted from return values
void AddInternalRef() { m_InternalRefcount++; }
void ReleaseInternalRef() { m_InternalRefcount--; }
bool Resident() { return resident != 0; }
void SetResident(bool r) { resident = r ? 1 : 0; }
//////////////////////////////
// implement IUnknown
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject)
+10 -8
View File
@@ -1569,7 +1569,7 @@ HRESULT WrappedID3D12Device::CreateCommittedResource(const D3D12_HEAP_PROPERTIES
pOptimizedClearValue, riidResource, (void **)&wrapped);
if(HeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT)
wrapped->SetResident(false);
wrapped->Evict();
D3D12ResourceRecord *record = GetResourceManager()->AddResourceRecord(wrapped->GetResourceID());
record->type = Resource_Resource;
@@ -1697,7 +1697,7 @@ HRESULT WrappedID3D12Device::CreateHeap(const D3D12_HEAP_DESC *pDesc, REFIID rii
Serialise_CreateHeap(ser, pDesc, riid, (void **)&wrapped);
if(pDesc->Flags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT)
wrapped->SetResident(false);
wrapped->Evict();
D3D12ResourceRecord *record = GetResourceManager()->AddResourceRecord(wrapped->GetResourceID());
record->type = Resource_Heap;
@@ -1868,6 +1868,8 @@ HRESULT WrappedID3D12Device::CreatePlacedResource(ID3D12Heap *pHeap, UINT64 Heap
{
WrappedID3D12Resource *wrapped = new WrappedID3D12Resource(real, this);
wrapped->SetHeap(pHeap);
if(IsCaptureMode(m_State))
{
CACHE_THREAD_SERIALISER();
@@ -3053,7 +3055,7 @@ HRESULT WrappedID3D12Device::OpenSharedHandleInternal(D3D12Chunk chunkType,
WrappedID3D12Resource *wrapped = new WrappedID3D12Resource(real, this);
if(HeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT)
wrapped->SetResident(false);
wrapped->Evict();
wrappedDeviceChild = wrapped;
@@ -3098,7 +3100,7 @@ HRESULT WrappedID3D12Device::OpenSharedHandleInternal(D3D12Chunk chunkType,
WrappedID3D12Heap *wrapped = new WrappedID3D12Heap(real, this);
if(HeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT)
wrapped->SetResident(false);
wrapped->Evict();
wrappedDeviceChild = wrapped;
@@ -3144,13 +3146,13 @@ HRESULT WrappedID3D12Device::MakeResident(UINT NumObjects, ID3D12Pageable *const
if(WrappedID3D12DescriptorHeap::IsAlloc(ppObjects[i]))
{
WrappedID3D12DescriptorHeap *heap = (WrappedID3D12DescriptorHeap *)ppObjects[i];
heap->SetResident(true);
heap->MakeResident();
unwrapped[i] = heap->GetReal();
}
else if(WrappedID3D12Resource::IsAlloc(ppObjects[i]))
{
WrappedID3D12Resource *res = (WrappedID3D12Resource *)ppObjects[i];
res->SetResident(true);
res->MakeResident();
unwrapped[i] = res->GetReal();
}
else
@@ -3171,13 +3173,13 @@ HRESULT WrappedID3D12Device::Evict(UINT NumObjects, ID3D12Pageable *const *ppObj
if(WrappedID3D12DescriptorHeap::IsAlloc(ppObjects[i]))
{
WrappedID3D12DescriptorHeap *heap = (WrappedID3D12DescriptorHeap *)ppObjects[i];
heap->SetResident(false);
heap->Evict();
unwrapped[i] = heap->GetReal();
}
else if(WrappedID3D12Resource::IsAlloc(ppObjects[i]))
{
WrappedID3D12Resource *res = (WrappedID3D12Resource *)ppObjects[i];
res->SetResident(false);
res->Evict();
unwrapped[i] = res->GetReal();
}
else
@@ -178,13 +178,13 @@ HRESULT WrappedID3D12Device::EnqueueMakeResident(D3D12_RESIDENCY_FLAGS Flags, UI
if(WrappedID3D12DescriptorHeap::IsAlloc(ppObjects[i]))
{
WrappedID3D12DescriptorHeap *heap = (WrappedID3D12DescriptorHeap *)ppObjects[i];
heap->SetResident(true);
heap->MakeResident();
unwrapped[i] = heap->GetReal();
}
else if(WrappedID3D12Resource::IsAlloc(ppObjects[i]))
{
WrappedID3D12Resource *res = (WrappedID3D12Resource *)ppObjects[i];
res->SetResident(true);
res->MakeResident();
unwrapped[i] = res->GetReal();
}
else
@@ -509,7 +509,7 @@ HRESULT WrappedID3D12Device::CreateHeap1(const D3D12_HEAP_DESC *pDesc,
Serialise_CreateHeap1(ser, pDesc, pProtectedSession, riid, (void **)&wrapped);
if(pDesc->Flags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT)
wrapped->SetResident(false);
wrapped->Evict();
D3D12ResourceRecord *record = GetResourceManager()->AddResourceRecord(wrapped->GetResourceID());
record->type = Resource_Heap;
@@ -413,6 +413,8 @@ HRESULT WrappedID3D12Device::CreatePlacedResource1(ID3D12Heap *pHeap, UINT64 Hea
{
WrappedID3D12Resource *wrapped = new WrappedID3D12Resource(real, this);
wrapped->SetHeap(pHeap);
if(IsCaptureMode(m_State))
{
CACHE_THREAD_SERIALISER();
+2 -2
View File
@@ -51,10 +51,10 @@ bool D3D12ResourceManager::Prepare_InitialState(ID3D12DeviceChild *res)
else if(type == Resource_Resource)
{
WrappedID3D12Resource *r = (WrappedID3D12Resource *)res;
ID3D12Pageable *pageable = r;
ID3D12Pageable *pageable = r->ResidencyPageable();
bool nonresident = false;
if(!r->Resident())
if(!r->IsResident())
nonresident = true;
D3D12_RESOURCE_DESC desc = r->GetDesc();
@@ -357,8 +357,6 @@ WrappedID3D12DescriptorHeap::WrappedID3D12DescriptorHeap(ID3D12DescriptorHeap *r
realCPUBase = real->GetCPUDescriptorHandleForHeapStart();
realGPUBase = real->GetGPUDescriptorHandleForHeapStart();
SetResident(true);
increment = device->GetUnwrappedDescriptorIncrement(desc.Type);
numDescriptors = UnpatchedNumDescriptors;
+21
View File
@@ -68,6 +68,7 @@ class WrappedDeviceChild12 : public RefCounter12<NestedType>,
{
protected:
WrappedID3D12Device *m_pDevice;
int32_t m_Resident = 1;
WrappedDeviceChild12(NestedType *real, WrappedID3D12Device *device)
: RefCounter12(real), m_pDevice(device)
@@ -105,6 +106,9 @@ protected:
public:
typedef NestedType InnerType;
bool IsResident() { return m_Resident > 0; }
void MakeResident() { Atomic::Inc32(&m_Resident); }
void Evict() { Atomic::Dec32(&m_Resident); }
NestedType *GetReal() { return m_pReal; }
ULONG STDMETHODCALLTYPE AddRef() { return RefCounter12::SoftRef(m_pDevice); }
ULONG STDMETHODCALLTYPE Release() { return RefCounter12::SoftRelease(m_pDevice); }
@@ -915,9 +919,26 @@ class WrappedID3D12Resource
WriteSerialiser &GetThreadSerialiser();
WrappedID3D12Heap *m_Heap = NULL;
public:
ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12Resource, false);
bool IsResident()
{
if(m_Heap)
return m_Heap->IsResident();
return WrappedDeviceChild12::IsResident();
}
ID3D12Pageable *ResidencyPageable()
{
if(m_Heap)
return m_Heap;
return this;
}
void SetHeap(ID3D12Heap *heap) { m_Heap = (WrappedID3D12Heap *)heap; }
static void RefBuffers(D3D12ResourceManager *rm);
static rdcarray<ID3D12Resource *> AddRefBuffersBeforeCapture(D3D12ResourceManager *rm);