diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp index c9a90483de..840351c104 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.cpp +++ b/src/dawn/native/d3d12/DeviceD3D12.cpp @@ -193,6 +193,13 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) { Device::~Device() { Destroy(); + + // Close the handle here instead of in DestroyImpl. The handle is returned from + // ExternalImageDXGI, so it needs to live as long as the Device ref does, even if the device + // state is destroyed. + if (mFenceHandle != nullptr) { + ::CloseHandle(mFenceHandle); + } } ID3D12Device* Device::GetD3D12Device() const { diff --git a/src/dawn/native/d3d12/ExternalImageDXGIImpl.cpp b/src/dawn/native/d3d12/ExternalImageDXGIImpl.cpp index 268e430d95..5ffd1c76be 100644 --- a/src/dawn/native/d3d12/ExternalImageDXGIImpl.cpp +++ b/src/dawn/native/d3d12/ExternalImageDXGIImpl.cpp @@ -111,7 +111,7 @@ WGPUTexture ExternalImageDXGIImpl::BeginAccess( } } else { d3d11on12Resource = mD3D11on12ResourceCache->GetOrCreateD3D11on12Resource( - mBackendDevice, mD3D12Resource.Get()); + mBackendDevice.Get(), mD3D12Resource.Get()); if (d3d11on12Resource == nullptr) { dawn::ErrorLog() << "Unable to create 11on12 resource for external image"; return nullptr; diff --git a/src/dawn/native/d3d12/ExternalImageDXGIImpl.h b/src/dawn/native/d3d12/ExternalImageDXGIImpl.h index ee12a1664e..b3b914ca05 100644 --- a/src/dawn/native/d3d12/ExternalImageDXGIImpl.h +++ b/src/dawn/native/d3d12/ExternalImageDXGIImpl.h @@ -58,7 +58,7 @@ class ExternalImageDXGIImpl : public LinkNode { void EndAccess(WGPUTexture texture, ExternalImageDXGIFenceDescriptor* signalFence); private: - Device* mBackendDevice = nullptr; + Ref mBackendDevice; Microsoft::WRL::ComPtr mD3D12Resource; const bool mUseFenceSynchronization;