Mixing shaders and CUDA

I’m fairly new to CUDA and completely new to OpenGL shaders and have a simple question: Can the two be mixed on the same data? Ie, if I have some simple filters that run as shaders and then want to implement a complex filter as a CUDA kernel, can that kernel access the same image that the shaders access? It doesn’t seem clear to me from the CUDA documentation I’ve read.



CUDA and OpenGL use completely different APIs and run in different contexts, so you can’t mix OpenGL shaders and CUDA programs directly. However it is possible to communicate between the two using OpenGL buffer objects (see the programming guide for details).

As an aside, DirectX 11 does expose compute functionality as just another type of shader, which allows better interoperability, but does have some restrictions compared to CUDA:

Ok, thanks. I’ll take a look at those.


There is an openGL post processing sample in the SDK. It shows how to use CUDA on the output of OpenGL. If OpenGL is made to render with a fragment shader, you get a combination of shaders and CUDA.