6

I need some help with OpenGL-Vulkan Memory Exchange. I've already found this topic How to render to OpenGL from Vulkan? But it is not quite what I need. I dont want Vulkan to allocate and export memory. I want to import OpenGL memory to Vulkan, create Vulkan Image and bind it to the imported memory.

My question is, is it actually possible to get 'HANDLE' (in terms of WinOS) that can be used with vk::ImportMemoryWin32HandleInfoKHR.

genpfault
  • 51,148
  • 11
  • 85
  • 139
DND
  • 63
  • 3

1 Answers1

5

As far as I can tell, there is no OpenGL extension yet, which would allow to do this. It also kind of makes sense, since memory semantics of OpenGL allocated objects are very vague and the data may actually be all over the place. When you create a texture, buffer, etc. in OpenGL it's completely open, when, how and where the thing will get its memory allocated eventually.

This is very different in Vulkan, where memory management is explicit, and once created you have "perfect" knowledge about it. Which is, why it's possible to simply "import" that memory into an OpenGL object; as far as the OpenGL driver goes, it's just another way to get to the memory, only that this way around it doesn't have to concern itself with the dirty details.

In the end it doesn't make a practical difference if you allocate the memory with Vulkan or OpenGL. Just allocate with Vulkan, then import into OpenGL. You can still write to the memory from OpenGL, i.e. also use it as a renderbuffer or texture for framebuffer attachment.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Is this still valid? Bcs if you have already OpenGL texture represented just as plain ID from lets say some 3rd party, you cannot dircetly connect it with VkImage. The only way how to get around is to create new InteropTexture via Vulkan->GL and then call something like `glCopyImageSubData`, which is not a big deal, as GPU copy will be pretty cheap I assume, but still it is little bit annoying. – CJ_Notned Jul 14 '23 at 08:34
  • @CJ_Notned: I am describing Vulkan→OpenGL interop in my answer. And when rendering to such an imported texture, no further copy will be required. Of course some form of layout transition fences should be implemented. – datenwolf Jul 14 '23 at 12:27
  • Yep, I understand that part, I was already using interop before, just I was curious if there is any possible GL->Vulkan transition, as you can be in a situation, where you have just GL texID/some chunk of GL memory and you want to create a vk::Image out of it. So my question was, if first paragraph is still valid and there is still no GL/VK extension for GL->Vulkan. – CJ_Notned Jul 14 '23 at 12:38
  • 1
    @CJ_Notned I think there might be some inofficial support for this, but nothing documented. If you look at the OpenVR API, through the same struct for passing images you can either supply OpenGL texture IDs or Vulkan images; the SteamVR compositor is using Vulkan. So there actually might be some hack in there to perform this transition. Or they might just doing a plain copy. – datenwolf Jul 14 '23 at 19:08