Thanks in advance for looking at my problem. I am very new to both OpenGL and CUDA, so please be patient with me!
I am attempting to use CUDA to perform some image processing tasks and display the results using OpenGL. My program worked when I had CUDA write the output back to the host, load into a texture (glTexImage2D) and display by binding the texture to polygon. I am attempting to “cut out the middle man” and load the output into the texture object on the device. Is this appropriate?
Essentially, can I (listing the steps and the commands I think might be pertinent to explain what I am doing):
Create the texture as before
Register with CUDA
Get a pointer to the cudaArray (on the device) that represents the texture object on the device (at least I think that this is what I am doing here…)
Write data to the cudaArray (cuArray) on the device
This is the step where the code tells me I’m doing something wrong.
Assume that I have a float4 array on the device (f4array_dev) with the RGBA values I want to display. How do I copy this array into the texture object? I tried:
This compiles but gives a runtime error message that I have an “invalid argument.” I tried creating my float4 array cudaMallocPitch and using cudaMemcpy2DToArray, but that gives a similar error message. I am beginning to think I am missing something fundamental. Any advice?
Release texture object on the device so that OpenGL can access it again for display.
And when I am done with the program, I won’t forget to unregister the texture object.
- When one calls cudaGraphicsSubResourceGetMappedArray, it is supposed to return a pointer to a cudaArray. The Programming Guide in 188.8.131.52 says that it should be possible to use cudaMemcpy2D to write to this array. Why not cudaMemcpy2DToArray (or cudaMemcpyToArray)? cudaMemcpy2D requires the pitch as an input. How do I determine the pitch for a cudaArray?
- Is it possible to check the parameters of the cudaGraphicsResource returned by cudaGraphicsMapResources or cudaGraphicsGLRegisterImage? (Bascially, is it the size and data type I think it is?)
Again, thanks for bearing with me.