Can memory imported to Vulkan from another API be freed by Vulkan?

狂风中的少年 提交于 2020-01-24 15:08:06

问题


On POSIX systems, one can import memory objects from other APIs through file descriptors using VkImportMemoryFdInfoKHR (it works similarly on Windows using VkImportMemoryWin32HandleInfoKHR). Once the memory object has been imported, is Vulkan allowed to free the underlying memory with vkFreeMemory, or can the memory only be freed by the API that has allocated it? Thank you for your help!


回答1:


Vulkan is not merely allowed to free the VkDeviceMemory object; it is required to do so. When you import memory into Vulkan, the specification is clear that Vulkan now owns that handle:

Importing memory from a file descriptor transfers ownership of the file descriptor from the application to the Vulkan implementation. The application must not perform any operations on the file descriptor after a successful import.

So you're not allowed to use regular commands on that file descriptor anymore. Vulkan owns it, and calling vkFreeMemory on it is not optional:

VkDevice objects can be destroyed when all VkQueue objects retrieved from them are idle, and all objects created from them have been destroyed. This includes the following objects:

...

  • VkDeviceMemory

No exception is made for VkDeviceMemory objects allocated as the result of an memory import operation.

Now of course, you can perform operations on a different FD that just so happens to be talking to the same memory (you can even use vkGetMemoryFdKHR to do so). But the specific FD you imported becomes owned by Vulkan. Freeing the memory frees the file descriptor; it doesn't affect the memory itself.



来源:https://stackoverflow.com/questions/59444668/can-memory-imported-to-vulkan-from-another-api-be-freed-by-vulkan

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!