Advertisement

Texture sharing between different processes on Linux

Started by June 01, 2017 06:19 PM
8 comments, last by godmodder 7 years, 8 months ago

Hello,

I want to produce a texture in one OpenGL process and consume it (read-only) in another OpenGL process. The texture should remain on the GPU at all times.

Ideally, I would want to share the texture, but from what I've read this isn't possible.

Another option would be to use NV_copy_image to copy the texture from one context to another, but still on the GPU. Would this work or is something like this simply not possible?

Thanks for helping me out!

I believe NV_copy_image won't do this.

GLX_copy_image, on the other hand, explicitly will -- It takes a source & dest context as well as image IDs, XY, width and height.

It may not be massively efficient though.

What are you trying to achieve?

Advertisement

I want to share texture data between different processes, which for legal reasons I cannot merge into one process. (It's stupid, but out of my control)

I know that in Vulkan I can do this with the VK_external_memory and VK_external_semaphore extensions, but I am not aware of how to do this in OpenGL. If I could interop between Vulkan and OpenGL, that would be fine, but I only found an extension GL_draw_vulkan_image. This means I can communicate from Vulkan to OpenGL, but not the other way around.

The problem is that my two processes are heavily dependent on OpenGL, so porting them to Vulkan would be a pain.

Is there a reason they have to be OpenGL textures -- can you share the data in the regular system memory before it's uploaded? That's a lot easier.

Is there a reason they have to be OpenGL textures -- can you share the data in the regular system memory before it's uploaded? That's a lot easier.

This is almost certainly the only thing that is possible. Such as, keep the data in a shared mapping (in two processes), and then upload from there.

NV_copy_image won't work, I don't think there's any chance of that happening. Even though it allows copying between contexts, and contexts that may be on different devices. But still, a GL context is a handle owned by a process with at least two rather complex memory structures associated (one owned by the driver, one owned by your process).
You can't just take that handle (which, in reality, is a pointer) from within a different process and expect that to do anything meaningful by magic. How would that work?

Remember that the management of GPU memory is very non-explicit (read as: managed, obscure) under OpenGL. You don't know, nor do you have much control over what's going on at any time. So let's say you share texture memory between two processes, and due to memory pressure, the driver that is just handling one process decides to free the texture memory. What then?

Can you share the data in the regular system memory before it's uploaded?

The data is generated on the GPU, so getting it to system memory would be too slow.

You can't just take that handle (which, in reality, is a pointer) from within a different process and expect that to do anything meaningful by magic.

Ok, I am confused now. This is possible with VK_external_memory in Vulkan right?

Advertisement

Ok, I am confused now. This is possible with VK_external_memory in Vulkan right?

]If you have VK_KHX_external_memory or the corresponding NV extension available (which is not the case on my nVidia 1060 card!), and if you can figure out how to do it (I can't, apparently you need to pass some extra structures when creating objects... but then... who knows), then, in theory, it looks like you might be able to do such a thing with Vulkan.

Which basically boils down to somehow duplicating a HANDLE under WIndows, or creating a POSIX file descriptor (that can then be transfered via a FIFO). There's a _fd and a _win32 extension to be found under "appendices" which apparently do such things. But I'm unable to figure out how they'd work, nor do I see any of them exposed on my computer, and they seem to be kinda half-finished, too.

Either way, even if you can figure these out, that doesn't mean you can do it with OpenGL (which your question was about). I am not aware of any GL extension with similar functionality, and given the complexity/obscurity of GL memory management, I doubt it's even possible in theory.

Ok, Samoth. It seems I will have to use Vulkan for this then. Thank you for your help!

If I figure out how to do it, I will post the solution here.

EDIT: just saw that my GTX970 exposes the required extensions here. Maybe my drivers are more recent?

Maybe this could be of use?

http://oss.sgi.com/projects/ogl-sample/registry/EXT/import_context.txt


"This extension allows multiple X clients to share an indirect rendering context."

I guess it could, but rendering with an indirect context would be slow, no?

This topic is closed to new replies.

Advertisement