Fix leak of D3D12 fence share handle

The D3D12 fence share handle should be closed when the device is
deleted.

A future change will make it valid to call EndAccess after the device
is destroyed, thus the handle is closed in ~Device instead of
Device::DestroyImpl. It needs to live as long as ExternalImageDXGI
holds a reference onto the device.

Bug: chromium:1359106
Change-Id: Ib9c9aaa7fb0b5a3de035b512f8fc0316d4bd225e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104540
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Austin Eng 2022-10-04 15:10:26 +00:00 committed by Dawn LUCI CQ
parent 2a3eae7371
commit 5a687b084e
3 changed files with 9 additions and 2 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -58,7 +58,7 @@ class ExternalImageDXGIImpl : public LinkNode<ExternalImageDXGIImpl> {
void EndAccess(WGPUTexture texture, ExternalImageDXGIFenceDescriptor* signalFence);
private:
Device* mBackendDevice = nullptr;
Ref<Device> mBackendDevice;
Microsoft::WRL::ComPtr<ID3D12Resource> mD3D12Resource;
const bool mUseFenceSynchronization;