Using CUDA to transfer texture between EGL and OpenGL (GLX) contexts in the same process

I have two contexts in the same process (Linux, x86_64) - one is EGL, used for offscreen rendering and onother is OpenGL/GLX. The first context must be EGL for reasons that aren’t important to this conversation. We are using the second OpenGL/GLX context in hopes to view/introspect into what is going on with the EGL context in real-time, for example, displaying the contents of one of the FBO textures. Since EGL and OpenGL contexts cannot share texture resources, we thought about using CUDA to transfer data between the two contexts (we already do this for another out-of-process monitoring application, and that works just fine).

The general workflow we’re going for is the following:

[On EGL context]
1.a. Render to texture (created by EGL context)
1.b. Transfer to CUDA array

[On OpenGL/GLX context]
2.a. Create a “destination texture” to receive the data from the CUDA array above.
2.b. Read data in CUDA array #2 above) and blit that array data to a CUDA surface object mapped to this “destination texture”

When setting this up, I call “cudaGraphicsGLRegisterImage” from the EGL context with the flag “cudaGraphicsRegisterFlagsReadOnly” and “GL_TEXTURE_2D” as the target - and that seems to work just fine without error.

The EGL context is then made inactive, and the OpenGL/GLX context is set as active.

On the OpenGL/GLX context, (Step #2.b above) I call the same “cudaGraphicsGLRegisterImage” with the texture ID created on this OpenGL context, GL_TEXTURE_2D and cudaGraphicsRegisterFlagsWriteDiscard (I’ve also tried cudaGraphicsRegisterFlagsSurfaceLoadStore) and it fails every time with the error code 1 (cudaErrorInvalidValue) “invalid argument”. The only argument that I can think of being “invalid” is the texture name, but it is indeed the correct texture ID for the texture generated on this OpenGL context.

If I temporarily switch the first context to also be an OpenGL/GLX context, this works flawlessly, but when the first context is an EGL context, I can’t seem to get past the cudaGraphicsGLRegisterImage call for the destination texture on the GLX context.

Any help/ideas here? Am I chasing something that simply isn’t possible - is there any way that I can use CUDA to transfer data between an EGL context and an OpenGL context in the same process?