Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
    
Great info! Thanks a lot. –  Tae-Sung Shin Feb 21 '13 at 2:51
add comment

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.

share|improve this answer
    
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. –  Sean Middleditch Feb 21 '13 at 18:19
    
Oh, Realy? i dident even know that the support was so bad for OpenCL on Linux :O –  Tordin Feb 22 '13 at 9:55
    
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. –  Sean Middleditch Feb 22 '13 at 17:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.