diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index f5f3c20e6..62ddd685e 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -246,8 +246,8 @@ HRESULT STDMETHODCALLTYPE WrappedCompatibilityDevice::CreateSharedResource( return hr; } - return m_pDevice.OpenSharedHandleInternal(D3D12Chunk::CompatDevice_CreateSharedResource, riid, - ppResource); + return m_pDevice.OpenSharedHandleInternal(D3D12Chunk::CompatDevice_CreateSharedResource, + HeapFlags, riid, ppResource); } HRESULT STDMETHODCALLTYPE WrappedCompatibilityDevice::CreateSharedHeap( @@ -268,7 +268,8 @@ HRESULT STDMETHODCALLTYPE WrappedCompatibilityDevice::CreateSharedHeap( return hr; } - return m_pDevice.OpenSharedHandleInternal(D3D12Chunk::CompatDevice_CreateSharedHeap, riid, ppHeap); + return m_pDevice.OpenSharedHandleInternal(D3D12Chunk::CompatDevice_CreateSharedHeap, + pHeapDesc->Flags, riid, ppHeap); } HRESULT STDMETHODCALLTYPE WrappedCompatibilityDevice::ReflectSharedProperties( @@ -1272,8 +1273,8 @@ IDXGIResource *WrappedID3D12Device::WrapExternalDXGIResource(IDXGIResource *res) } void *voidRes = (void *)res; - OpenSharedHandleInternal(D3D12Chunk::Device_ExternalDXGIResource, __uuidof(IDXGIResource), - &voidRes); + OpenSharedHandleInternal(D3D12Chunk::Device_ExternalDXGIResource, D3D12_HEAP_FLAG_NONE, + __uuidof(IDXGIResource), &voidRes); return (IDXGIResource *)voidRes; } diff --git a/renderdoc/driver/d3d12/d3d12_device.h b/renderdoc/driver/d3d12/d3d12_device.h index 01c82e9c5..043c0555e 100644 --- a/renderdoc/driver/d3d12/d3d12_device.h +++ b/renderdoc/driver/d3d12/d3d12_device.h @@ -1061,8 +1061,8 @@ public: const SECURITY_ATTRIBUTES *pAttributes, DWORD Access, LPCWSTR Name, HANDLE *pHandle); - HRESULT STDMETHODCALLTYPE OpenSharedHandleInternal(D3D12Chunk chunkType, REFIID riid, - void **ppvObj); + HRESULT STDMETHODCALLTYPE OpenSharedHandleInternal(D3D12Chunk chunkType, D3D12_HEAP_FLAGS HeapFlags, + REFIID riid, void **ppvObj); IMPLEMENT_FUNCTION_THREAD_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, OpenSharedHandle, HANDLE NTHandle, REFIID riid, void **ppvObj); diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index 9351d2559..6ebf42f3b 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -1255,6 +1255,9 @@ bool WrappedID3D12Device::Serialise_CreateCommittedResource( // always allow SRVs on replay so we can inspect resources desc.Flags &= ~D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE; + // don't create resources non-resident + HeapFlags &= ~D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT; + if(desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) { GPUAddressRange range; @@ -1378,6 +1381,9 @@ HRESULT WrappedID3D12Device::CreateCommittedResource(const D3D12_HEAP_PROPERTIES Serialise_CreateCommittedResource(ser, pHeapProperties, HeapFlags, pDesc, InitialResourceState, pOptimizedClearValue, riidResource, (void **)&wrapped); + if(HeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT) + wrapped->SetResident(false); + D3D12ResourceRecord *record = GetResourceManager()->AddResourceRecord(wrapped->GetResourceID()); record->type = Resource_Resource; record->Length = 0; @@ -1434,6 +1440,10 @@ bool WrappedID3D12Device::Serialise_CreateHeap(SerialiserType &ser, const D3D12_ if(IsReplayingAndReading()) { void *realptr = NULL; + + // don't create resources non-resident + Descriptor.Flags &= ~D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT; + HRESULT hr = m_pDevice->CreateHeap(&Descriptor, guid, &realptr); ID3D12Heap *ret = NULL; @@ -1490,6 +1500,9 @@ HRESULT WrappedID3D12Device::CreateHeap(const D3D12_HEAP_DESC *pDesc, REFIID rii SCOPED_SERIALISE_CHUNK(D3D12Chunk::Device_CreateHeap); Serialise_CreateHeap(ser, pDesc, riid, (void **)&wrapped); + if(pDesc->Flags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT) + wrapped->SetResident(false); + D3D12ResourceRecord *record = GetResourceManager()->AddResourceRecord(wrapped->GetResourceID()); record->type = Resource_Heap; record->Length = 0; @@ -2324,6 +2337,9 @@ bool WrappedID3D12Device::Serialise_OpenSharedHandle(SerialiserType &ser, HANDLE heapFlags &= ~(D3D12_HEAP_FLAG_DENY_BUFFERS | D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES); + // don't create resources non-resident + heapFlags &= ~D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT; + HRESULT hr; ID3D12Resource *ret; hr = m_pDevice->CreateCommittedResource(&heapProperties, heapFlags, &desc, @@ -2446,10 +2462,13 @@ HRESULT WrappedID3D12Device::OpenSharedHandle(HANDLE NTHandle, REFIID riid, void return hr; } - return OpenSharedHandleInternal(D3D12Chunk::Device_OpenSharedHandle, riid, ppvObj); + return OpenSharedHandleInternal(D3D12Chunk::Device_OpenSharedHandle, D3D12_HEAP_FLAG_NONE, riid, + ppvObj); } -HRESULT WrappedID3D12Device::OpenSharedHandleInternal(D3D12Chunk chunkType, REFIID riid, void **ppvObj) +HRESULT WrappedID3D12Device::OpenSharedHandleInternal(D3D12Chunk chunkType, + D3D12_HEAP_FLAGS HeapFlags, REFIID riid, + void **ppvObj) { if(IsReplayMode(m_State)) { @@ -2586,6 +2605,9 @@ HRESULT WrappedID3D12Device::OpenSharedHandleInternal(D3D12Chunk chunkType, REFI WrappedID3D12Resource1 *wrapped = new WrappedID3D12Resource1(real, this); + if(HeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT) + wrapped->SetResident(false); + wrappedDeviceChild = wrapped; D3D12_RESOURCE_DESC desc = wrapped->GetDesc(); @@ -2628,6 +2650,9 @@ HRESULT WrappedID3D12Device::OpenSharedHandleInternal(D3D12Chunk chunkType, REFI WrappedID3D12Heap1 *wrapped = new WrappedID3D12Heap1(real, this); + if(HeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT) + wrapped->SetResident(false); + wrappedDeviceChild = wrapped; record = GetResourceManager()->AddResourceRecord(wrapped->GetResourceID()); diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap4.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap4.cpp index 6b023fe6e..96ea93d24 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap4.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap4.cpp @@ -412,6 +412,10 @@ bool WrappedID3D12Device::Serialise_CreateHeap1(SerialiserType &ser, const D3D12 if(IsReplayingAndReading()) { void *realptr = NULL; + + // don't create resources non-resident + Descriptor.Flags &= ~D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT; + // don't replay with a protected session HRESULT hr = E_NOINTERFACE; if(m_pDevice4) @@ -476,6 +480,9 @@ HRESULT WrappedID3D12Device::CreateHeap1(const D3D12_HEAP_DESC *pDesc, SCOPED_SERIALISE_CHUNK(D3D12Chunk::Device_CreateHeap1); Serialise_CreateHeap1(ser, pDesc, pProtectedSession, riid, (void **)&wrapped); + if(pDesc->Flags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT) + wrapped->SetResident(false); + D3D12ResourceRecord *record = GetResourceManager()->AddResourceRecord(wrapped->GetResourceID()); record->type = Resource_Heap; record->Length = 0;