I would like to know if it is possible to map the data of a 2D texture in opengl as a contiguous memory in CUDA (being accessed as a device_ptr), similar to a glReadPixels operation, but in gpu and without copying the texture memory.
I would like to do that to experiment the nvcomp library to compress both color and depth textures, only getting the gpu memory back to cpu after compression.
I guess what you are asking is can you get a CUDA linear buffer (i.e. ordinary device memory) representation of the underlying data in a GL texture.
AFAIK, this wouldn’t be typical/straightforward with “ordinary” CUDA/GL interop. A general mental model I have for CUDA/GL interop is that GL textures map to cudaArray, and GL buffers map to ordinary CUDA linear device memory. If there is a way to directly extract a CUDA linear buffer from a GL texture via CUDA/GL interop, I’m unaware of such. I don’t know if there are tricks on the GL side to do this; I’m unaware of any way to do this via CUDA.
However two alternate/indirect paths I can think of are:
map the GL texture to a CUDA surface (or texture) and extract the data that way. If need be, you could write it to a linear buffer. If you need to send it back to the GL side, use a surface.
use CUDA/GL interop via a GL buffer, and on the GL side use that buffer to populate the GL texture.
Thanks for the reply!
Yes, i was trying to find out if it would be possible to get a CUDA linear buffer as a representation of the GL texture data.
I tried using cudaMemcpyFromArrayAsync to copy the data to a CUDA linear buffer from the mapped cudaArray. I guess it’s fine since the memory is transferred Device to Device (even though this method is deprecated, so i think mapping to a CUDA surface/texture first might be better).
For texture with depth format, it seems cudaGraphicsGLRegisterImage does not support depth data, so i think i’ll try to use a different texture to store this data in a better format before mapping to CUDA.