Optix7.0 opengl interoperation

Can I sample opengl texture directly in Optix shader?
There are some samples showing that we can upload texture to a pbo(pixel buffer object) and then bind it to optix,
however this is not a zero-copy solution.
Is there a direct way to handle opengl texture?

1 Like

Can I sample opengl texture directly in Optix shader?

Not at this time.

All interoperability between OptiX 7 and other graphics APIs is actually outside of OptiX 7 and happens completely via native CUDA mechanisms.

Also OptiX 7 itself has no knowledge of textures. That all happens via CUDA texture objects and the respective texture functions in CUDA’s texture_fetch_functions.h.

  • An OpenGL PixelBufferObject is just a linear memory area. You can do CUDA-OpenGL interop with that and render directly into the PBO from OptiX.
    You still need to do the glTex(Sub)Image2D call to upload the PBO contents to the OpenGL texture.
    That is actually used in most OptiX SDK examples to display the final image on the screen.
  • CUDA also allows to directly copy device-to-device into a registered OpenGL texture image but this is also not happening inside the shader code.
  • The third method would be to directly read from/write to CUDA surfaces, but this is currently not working in OptiX 7 and should be fixed in the next release.
    https://forums.developer.nvidia.com/t/bugreport-writing-to-cuda-surfaceobjects-produces-no-result/115109
    Searching the CUDA forums for CUDA reading from OpenGL texture image turns up some threads using CUDA surfaces for that.

Examples using no interop, OpenGL PBO interop and registered OpenGL texture images can be found here:
https://forums.developer.nvidia.com/t/optix-advanced-samples-on-github/48410/4

Search the source code for m_interop and you’ll find the different methods, easiest to be seen in this source:
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/rtigo3/src/DeviceSingleGPU.cpp#L54

1 Like

This post is almost 2 years old. Is there any update over this issue in OptiX 7.4? I saw the sample codes contain #include <cuda_gl_interop.h> and #include <cuda_runtime.h> headers.

All three OpenGL-CUDA interop methods I described above should be working with current drivers from R450 and newer.
If you followed the first link I posted above you should have seen my update from August 2020 to that originally reported issue.

1 Like