Driver: 581.57.0.0
Device: GTX 1080
OS: Windows 10.0.19045
(I realize this is somewhat outdated, but it’s what I have!)
The driver does not free the underlying handle in vkFreeMemory for allocations imported from D3D11 with vkImportMemoryWin32HandleInfoKHR, even when Release is called on the ID3D11Texture, and when CloseHandle is correctly called application-side if applicable.
Spec: VkImportMemoryWin32HandleInfoKHR(3) :: Vulkan Documentation Project
This is true for both NT and global handles. For NT handles I close the handle with CloseHandle.
Non-NT handle import operations do not add a reference to their associated payload. If the original object owning the payload is destroyed, all resources and handles sharing that payload will become invalid.
The driver does not appear to follow this part of the spec. For global handles, the memory should be freed after Release (D3D11 side) / vkFreeMemory (Vulkan side), but it is not.
WinDbg !htrace -diff shows the D3DKmtCreateAllocation on the driver side for the leaked handles
0x00007ff9fc0547a4: win32u!NtGdiDdDDICreateAllocation+0x0000000000000014
0x00007ff9fd213890: GDI32!D3DKMTCreateAllocation+0x00000000000000f0
0x00007ff9f8088b9e: d3d11!CallAndLogImpl<long (__cdecl*)(_D3DKMT_CREATEALLOCATION * __ptr64),_D3DKMT_CREATEALLOCATION * __ptr64>+0x000000000000001e
0x00007ff9f80615c1: d3d11!NDXGI::CDevice::AllocateCB+0x00000000000000f1
0x00007ff9e0626cbb: nvwgf2umx!NVAPI_DirectMethods+0x00000000000c989b
0x00007ff9e0fb8ec4: nvwgf2umx!NVDEV_Thunk+0x0000000000244854
This causes a significant memory leak in my application that creates/imports/destroys many textures via D3D/Vulkan interop. Intel and AMD do not leak on systems I’ve tried.
Steps to reproduce:
- Create a D3D11 Device and Vulkan context on the same adapter (matched LUID/UUID)
- Create ID3D11Texture2D with MiscFlags = D3D11_RESOURCE_MISC_SHARED
- Import the texture to Vulkan via vkImportMemoryWin32HandleInfoKHR in the PNext chain for the allocation
- Free the memory with Release on the ID3D11Texture2D* and vkFreeMemory on the Vulkan DeviceMemory.
- Observe large increase in VRAM utilization over time, eventually spilling into system RAM and the page file.