CUDA / OpenGL / GLSL Pixel Shader running within the same application.

Is it possible to run a graphics application using OpenGL and GLSL pixel shaders at the same time as CUDA?

My intent is to render a scene to a texture using OpenGL and then perform image processing tasks on the resulting image.

Currently I perform the processing on the Host but it is too slow. I would rather create a CUDA kernel that handles the processing and bridge the image texture into the CUDA kernel.

Is this possible?

If you mean “Run pixel shaders, and then post-process with CUDA”, yes. If you mean “concurrently run pixel shaders and CUDA”, then no.

Specifically, you can map an OpenGL texture or renderbuffer into a CUDA array, and access it in CUDA using texture fetches. The downside is that you have to write your output to a linear deviceptr, so, if you want to turn around and display the results of the CUDA kernel, you will need to copy that data back into an OpenGL texture (for instance, if you are doing post-processing on the OpenGL texture, such as HDR to LDR tonemapping).

What do you mean by “map an OpenGL texture or renderbuffer into a CUDA array”?

Is that something I need to do in CPU space or can the graphics rendering pipeline and CUDA share the same texture without reading the memory back to the CPU?

My intent would be to compress and encode the texture into a new buffer that would be then read off of the GPU and sent over the network. I’d run the compression once per openGL frame.

See “OpenGL Interoperability” in the Cuda programming guide.

Basically, you can do Render-to-texture in OpenGL and then get access to that OpenGL texture as Cuda Array. Then you can bind a cuda texture to that array, and sample that cuda texture in your kernel.