diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index efb2038e3c..2cc42ece7d 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -362,8 +362,18 @@ namespace dawn_native { namespace d3d12 { mD3d12Device.Get(), 0, nullptr, 0, &iUnknownQueue, 1, 1, &d3d11Device, &d3d11DeviceContext, &d3dFeatureLevel), "D3D12 11on12 device create")); - DAWN_TRY(CheckHRESULT(d3d11Device.As(&mD3d11On12Device), + + ComPtr d3d11on12Device; + DAWN_TRY(CheckHRESULT(d3d11Device.As(&d3d11on12Device), "D3D12 QueryInterface ID3D11Device to ID3D11On12Device")); + + ComPtr d3d11DeviceContext2; + DAWN_TRY( + CheckHRESULT(d3d11DeviceContext.As(&d3d11DeviceContext2), + "D3D12 QueryInterface ID3D11DeviceContext to ID3D11DeviceContext2")); + + mD3d11On12DeviceContext = std::move(d3d11DeviceContext2); + mD3d11On12Device = std::move(d3d11on12Device); } ComPtr d3d11Texture; @@ -393,6 +403,18 @@ namespace dawn_native { namespace d3d12 { ID3D11Resource* d3d11ResourceRaw = d3d11Resource.Get(); mD3d11On12Device->ReleaseWrappedResources(&d3d11ResourceRaw, 1); + + d3d11Resource.Reset(); + dxgiKeyedMutex.Reset(); + + // 11on12 has a bug where D3D12 resources used only for keyed shared mutexes + // are not released until work is submitted to the device context and flushed. + // The most minimal work we can get away with is issuing a TiledResourceBarrier. + + // ID3D11DeviceContext2 is available in Win8.1 and above. This suffices for a + // D3D12 backend since both D3D12 and 11on12 first appeared in Windows 10. + mD3d11On12DeviceContext->TiledResourceBarrier(nullptr, nullptr); + mD3d11On12DeviceContext->Flush(); } }} // namespace dawn_native::d3d12 diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h index 3a41c84832..98ae4f1a57 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.h +++ b/src/dawn_native/d3d12/DeviceD3D12.h @@ -131,7 +131,10 @@ namespace dawn_native { namespace d3d12 { ComPtr mD3d12Device; // Device is owned by adapter and will not be outlived. ComPtr mCommandQueue; - ComPtr mD3d11On12Device; // 11on12 device corresponding to mCommandQueue + + // 11on12 device and device context corresponding to mCommandQueue + ComPtr mD3d11On12Device; + ComPtr mD3d11On12DeviceContext; ComPtr mDispatchIndirectSignature; ComPtr mDrawIndirectSignature; diff --git a/src/dawn_native/d3d12/d3d12_platform.h b/src/dawn_native/d3d12/d3d12_platform.h index ea42c26fd5..a64486c64b 100644 --- a/src/dawn_native/d3d12/d3d12_platform.h +++ b/src/dawn_native/d3d12/d3d12_platform.h @@ -15,6 +15,7 @@ #ifndef DAWNNATIVE_D3D12_D3D12PLATFORM_H_ #define DAWNNATIVE_D3D12_D3D12PLATFORM_H_ +#include #include #include #include