cuda interop with two OpenGL windows

We are struggling with an OpenGL/Cuda interoperability issue.
So far, our cuda app creates images and renders to one OpenGL window - this is working fine.

Now, we want to have TWO OpenGL windows, and we want the cuda routines to create two versions of our images, that will appear in the two OpenGL windows. This is where we are stuck!

The 2 OpenGL windows have unique ID’s and only one is active at a time. The whole process of creating and registering the texture buffer object and then rendering to it works fine on one window or the other, but we haven’t found a way for the cuda routines to render to buffers associated with both windows. We need to avoid any costly steps like transferring the images up to the host…

Can someone help with this?

In principle each cuda context and each opengl context and each device context is associated with a thread.

All three can be considered a compounded context, meaning one big context.

For correct operation all three contexes must be active for the same thread.

From your description it seems one thread is trying to render to two opengl windows.

This will require the opengl context and device context to be made active first for that opengl window, which requires what is known as a “activate rendering context” or “switch rendering context”.

This is something operating system specific and requires a special windows api call.

I think also pixel buffer objects for example will have to be mapped so cuda can use them and then unmap. That’s for drawing… before that they also first need to be registered when creating them.

I suspect your cuda app is not switching rendering contexes properly ?

Or perhaps it’s a cuda issue not designed for multiple opengl windows… for now I think it’s probably not switching contexes properly ;)