Cuda and OpenGL Interop

前端 未结 2 358
刺人心
刺人心 2020-12-08 10:48

I\'ve been reading through the CUDA documentation and it seems to me, that every buffer that needs to interface with OpenGL needs to be created in the glBuffer.

Acc

相关标签:
2条回答
  • 2020-12-08 11:38

    For an example of how to use CUDA-GL interop without having to re-map every frame, please refer to this example:

    https://github.com/nvpro-samples/gl_cuda_interop_pingpong_st

    0 讨论(0)
  • 2020-12-08 11:41

    As of CUDA 4.0, OpenGL interop is one-way. That means to do what you want (run a CUDA kernel that writes data to a GL buffer or texture image), you have to map the buffer to a device pointer, and pass that pointer to your kernel, as shown in your example.

    As for your side note: cudaGraphicsResourceGetMappedPointer is called every time display() is called because cudaGraphicsMapResource is called every frame. Any time you re-map a resource you should re-get the mapped pointer, because it may have changed. Why re-map every frame? Well, OpenGL sometimes moves buffer objects around in memory, for performance reasons (especially in memory-intensive GL applications). If you leave the resource mapped all the time, it can't do this, and performance may suffer. I believe GL's ability and need to virtualize memory objects is also one of the reasons the current GL interop API is one-way (the GL is not allowed to move CUDA allocations around, and therefore you can't map a CUDA-allocated device pointer into a GL buffer object).

    0 讨论(0)
提交回复
热议问题