5
\$\begingroup\$

My platform is Windows PC and C++. I am using an image buffer in GPU video memory via CUDA. Is there any way to directly send the content to GPU for display? Currently, I am getting the content into system memory and then use API function (such as GDI, OpenGL. DirectX) to send it back to GPU for display. I wonder if there is a faster way to do this.

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

You can bind a CUDA array as a texture, and then use that texture for rendering. There are restrictions on valid texture formats, and limits imposed on CUDA arrays to make this all work, but it does.

The specific API call in CUDA varies by which graphic API you're using, but look for "register resource."

Basically, create the texture with the appropriate image data like you wanted to render it (say, with D3D's CreateTexture or GL's glTexSubData2D). Register the texture with CUDA using the appropriate API (cudaGraphicsGLRegisterImage for OpenGL). Bind the registered texture to a CUDA array (cudaBindTextureToArray).

Do the same for your render buffer (output texture, FBO bound in GL or RenderTarget bound in D3D, using slightly different methods to bind/map it to CUDA - see the docs). Run your kernel. Bind the output texture for rendering in API of choice. Render using it as source, e.g. as a full-screen quad.

A not-great but not-terrible article with OpenGL integration with CUDA is on 3dgep.com.

\$\endgroup\$
1
  • \$\begingroup\$ @Sean: cudaGraphicsGLRegisterImage returns a cudaGraphicsResource whereas cudaBindTexture* work on textureReference. How to glue those functions together!? Is there a way to make OpenGL texture to look at an existing CUDA memory region without copying? \$\endgroup\$ Commented Apr 16, 2017 at 1:26
1
\$\begingroup\$

Maybe this might not be of use to you, but Direct Compute will let you create a UAV (which can be used to calculate stuff onto, aswell as render to the display.

Direct Compute is staright forward and isent much of hassle to implement. i have used this myself when doing GPGPU stuff.

\$\endgroup\$
3
  • \$\begingroup\$ ALso, OpenGL 4.3 has Compute Shaders. Never used them, but they're an option. Not that it matters much if you only use NVIDIA hardware; the only OS to even support GL 4.3 besides Windows is Linux via the non-default proprietary drivers, and NVIDIA supports CUDA on Linux, so you gain no additional OS portability by using Khronos' API. \$\endgroup\$ Commented Feb 21, 2013 at 18:19
  • \$\begingroup\$ Oh, Realy? i dident even know that the support was so bad for OpenCL on Linux :O \$\endgroup\$
    – Tordin
    Commented Feb 22, 2013 at 9:55
  • \$\begingroup\$ If you install the proprietary non-standard drivers (like you mayve have to do on Windows if the vendor didn't pre-install them), it's fine. It's still in its infancy for the standard FOSS stack Linux and its future tech (Wayland, etc.) rely on. Also, OpenCL is not ideal for graphics - there's a reason Khronos relented and added Compute Shaders to GL 4.3, despite OpenCL working with OpenGL already. \$\endgroup\$ Commented Feb 22, 2013 at 17:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .