5

I'm doing a path tracer on GPU, and I got some traced results of pixel data (which is an array of float3) on GPU global memory, what I do to display the array on screen is to copy the array to CPU memory and call OpenGL glTexImage2D:

glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixelArray);

then display the texture. pixelArray is the pixel data array to show. As GPU is the device managing the whole rendering process, is there a way to display the pixelArray on screen without copying data from GPU to CPU?

Tony
  • 127
  • 1
  • 6
  • 2
    What exactly do you mean by a "color pixel array"? Are you talking about an OpenGL buffer object that stores pixel data, a piece of CUDA memory that stores pixel data, or what? – Nicol Bolas Mar 27 '13 at 06:28
  • that would be just an array of float3 (RGBcolor) type, which stored in GPU global memory. @NicolBolas – Tony Mar 27 '13 at 06:39
  • 4
    Right, but you tagged this as both OpenGL and CUDA. Each of them have their own, *separate* ways of storing an array of data in GPU global memory. And which way you used will impact the options you have for sticking this into a texture. So which is it? – Nicol Bolas Mar 27 '13 at 06:44
  • we can forget about OpenGL. Pixel data do exist in cuda global memory like [(R,G,B),(R,G,B),...,(R,G,B)], to put array like this onto screen directly without CPU involved would reduce overhead. @NicolBolas – Tony Mar 27 '13 at 07:31
  • 1
    @Tony: No we can't forget about OpenGL. CUDA has graphics and OpenGL interop. You can map a OpenGL texture as CUDA global memory array. Either you write your data directly to a mapped texture, or you do a cudaMemcpy2D into the texture mapping. – datenwolf Mar 27 '13 at 10:52

2 Answers2

2

Use CUDA OpenGL graphics interop to map a OpenGL texture as CUDA global memory. Either write your data directly to the texture or use a cudaMemcpy2D.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
1

Here is a function I made once, to render the image whose data resides in the global memory of GPU. You will require freeglut and glew, alongwith CUDA to run it. Currently it works only on Windows.

I still use this function to render GPU images. Just call ShowRawImage and you are done.

The only overhead it has, is a memory copy from global memory to OpenGL device buffer. But its better because its a device to device copy.

sgarizvi
  • 16,623
  • 9
  • 64
  • 98