vkFreeMemory memory leaks while the VkDeviceMemory object was allocated with VkExportMemoryAllocateInfo

Viewed 38

I am using the VK_KHR_external_memory_win32 extension to share GPU memory with OpenGL on Windows, the shared texture works fine.

The memory was allocated by vkAllocateMemory() with VkMemoryAllocateInfo that the pNext contains a VkExternalMemoryImageCreateInfo structure whose handleTypes is VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT or VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_IMAGE_BIT_NV for Nvidia cards.

But the memory will not return to the GPU memory heap after the related VkDeviceMemory object was freed by vkFreeMemory().

I have test Intel HD 630 / AMD RX 5700XT / Nvidia 1660 Ti graphics cards, all of them have the memory leaks issue no matter if the dedicated memory is enable or not.

1 Answers

Problem solved according to the vulkan spec:

For handle types defined as NT handles, the handles returned by vkGetMemoryWin32HandleKHR are owned by the application and hold a reference to their payload. To avoid leaking resources, the application must release ownership of them using the CloseHandle system call when they are no longer needed.

Related