Vulkan图像导出到Win32或fd的句柄.如何反转win32句柄获取图像信息?



当我从Vulkan图像导出Win32句柄时。Vulkan为另一个过程。此时,如何根据win32 Handle反向查找Vulkan Image的信息?

我在一个进程中用Vulkan创建了一个Handle,并根据Handle创建了OpenGL的纹理。然后与另一个进程共享。因此存在上述问题之一。

我不知道图像的信息是什么。如何创建映像并将其导入共享内存?我不知道图像信息是什么,所以我如何创建一个OpenGL纹理对象?因此,我想获取Handle.

中包含的图像信息。
// Get the Vulkan texture and create the OpenGL equivalent using the memory allocated in Vulkan
inline void createTextureGL(nvvk::ResourceAllocator& alloc, Texture2DVkGL& texGl, int format, int minFilter, int magFilter, int wraps, int wrapt)
{
vk::Device                  device = alloc.getDevice();
nvvk::MemAllocator::MemInfo info = alloc.getMemoryAllocator()->getMemoryInfo(texGl.texVk.memHandle);
texGl.handle = device.getMemoryWin32HandleKHR({ info.memory, vk::ExternalMemoryHandleTypeFlagBits::eOpaqueWin32 });
auto req = device.getImageMemoryRequirements(texGl.texVk.image);
glCreateMemoryObjectsEXT(1, &texGl.memoryObject);
glImportMemoryWin32HandleEXT(texGl.memoryObject, req.size, GL_HANDLE_TYPE_OPAQUE_WIN32_EXT, texGl.handle);
glCreateTextures(GL_TEXTURE_2D, 1, &texGl.oglId);
glTextureStorageMem2DEXT(texGl.oglId, texGl.mipLevels, format, texGl.imgSize.width, texGl.imgSize.height, texGl.memoryObject, info.offset);

goolge-image-import项目:

::VkImage image = *images_[0];
VkMemoryRequirements requirements;
device_->vkGetImageMemoryRequirements(device_, image, &requirements);
aligned_data_size_ =
vulkan::RoundUp(requirements.size, requirements.alignment);
uint32_t memory_index =
vulkan::GetMemoryIndex(&device, log, requirements.memoryTypeBits,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
#ifdef _WIN32
VkImportMemoryWin32HandleInfoKHR import_allocate_info{
VK_STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR, nullptr,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT, handle, nullptr};
#elif __linux__
VkImportMemoryFdInfoKHR import_allocate_info{
VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR, nullptr,
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT, fd};
#endif
VkMemoryAllocateInfo allocate_info{
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,  // sType
&import_allocate_info,                   // pNext
aligned_data_size_ * num_images,         // allocationSize
memory_index};
VkDeviceMemory device_memory;
LOG_ASSERT(==, log, VK_SUCCESS,
device->vkAllocateMemory(device, &allocate_info, nullptr,
&device_memory));

我不知道图像的信息是什么

不,你有。你在Vulkan创造了它。你知道它的大小。你知道它的格式。你知道图像的一切。

如果你可以传递一个句柄给这个函数来创建一个OpenGL纹理,那么你也可以传递其他信息。

没有API来检索有关窗口的任何信息。驱动程序甚至可能没有保存这些信息,因为这些信息是你已经拥有的,因此是多余的。

最新更新