Optix7.0 opengl interoperation

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