dpq
dpq

Reputation: 9268

Accessing video RAM with mmap() knowing OpenGL context and visual ID

is it possible to learn the allocated memory range of an OpenGL context? Supposedly this memory range should then be accessed with mmap() from another process. Can this technique work, or are there fundamental problems with it?

Update We're using a GNU/Linux system with a modern X11 installation and can pick the video card manufacturer whose drivers support such a trick.

Upvotes: 2

Views: 1052

Answers (3)

datenwolf
datenwolf

Reputation: 162164

is it possible to learn the allocated memory range of an OpenGL context?

I think you're asking for accessing the memory where a OpenGL context keeps its objects and the render output.

No. The OpenGL context is an abstract construct and have it's memory on an entirely different machine and/or architecture.

In addition to that there is no standard or even common memory layout for the contents of an OpenGL context. If you're interested in the rendering outcome only, you could tap the framebuffer device (/dev/fb…), though the performance will be inferior to just read back the framebuffer contents with glReadPixels. Similar goes for tapping the PCI memory range, which is virtually the same as tapping the framebuffer device.

Upvotes: 0

Nicol Bolas
Nicol Bolas

Reputation: 473407

Well, there are innumerable reasons why it won't work.

First, the "allocated memory range of an OpenGL context" is always changing. OpenGL contexts allocate new memory and deallocate it as it decides to.

Second, I would not trust an OpenGL driver to survive under memory mapped conditions like this. Multiple OpenGL contexts can coexist, but only because they all know about each other and the driver can therefore compensate for them. It is highly unlikely that a context can assimilate changes made by another context.

Third, GPUs often work with graphics memory. Even if you can use mmap on GPU memory (which itself is unlikely), you're probably going to lose a lot of performance when you do. And GPU memory gets shuffled around a lot more than CPU memory.

You appear to be trying to do IPC-based graphics. Your best bet would be to have the graphics system be its own process that you communicate with via IPC methods, rather than trying to talk to OpenGL via IPC.

Upvotes: 3

Martin Beckett
Martin Beckett

Reputation: 96109

Depends on the OS and driver. It's possible with an X-server. Although a combination of the X server, display driver and openGL means it could move the memory for a particular object around on the card when it draws it.

An easier way is probably to use an openGL pixel/vertex buffer and get the buffer pointer

Upvotes: 0

Related Questions