Vulkan可以释放从其他API导入到Vulkan的内存吗? [英] Can memory imported to Vulkan from another API be freed by Vulkan?

查看:224
本文介绍了Vulkan可以释放从其他API导入到Vulkan的内存吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在POSIX系统上,可以使用VkImportMemoryFdInfoKHR通过文件描述符从其他API导入内存对象(在Windows中,使用VkImportMemoryWin32HandleInfoKHR类似地工作).导入内存对象后,是否允许Vulkan使用vkFreeMemory释放基础内存,还是只能由分配了该对象的API释放该内存?谢谢您的帮助!

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!

推荐答案

Vulkan不仅被允许释放VkDeviceMemory对象,还需要释放VkDeviceMemory对象.这样做是必需的.当您将内存导入Vulkan时,规格很明显Vulkan现在拥有可以处理:

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:

从文件描述符导入内存会将文件描述符的所有权从应用程序转移到Vulkan实现.成功导入后,应用程序必须不得对文件描述符执行任何操作.

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.

因此,您不再可以在该文件描述符上使用常规命令. Vulkan拥有它,并且对它调用vkFreeMemory不是可选的:

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:

当从其中检索到的所有VkQueue对象都处于空闲状态,并且从中创建的所有对象都已被破坏时,

VkDevice对象可以被销毁.其中包括以下对象:

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

由于内存导入操作而分配的VkDeviceMemory对象没有异常.

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

当然,现在您可以在不同的FD上执行操作,而恰恰是在与相同的内存通信(您甚至可以使用vkGetMemoryFdKHR这样做).但是您导入的特定FD归Vulkan拥有.释放内存将释放文件描述符;它不会影响内存本身.

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.

这篇关于Vulkan可以释放从其他API导入到Vulkan的内存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆