Posts Tagged ‘nvidia’

Cuda integration with Ogre3D

April 26th, 2010

If you already start to play with Cuda you know that graphic interop is not an easy task. Indeed you need to register graphic ressources using different methods accordings to the Ogre::RenderSytem (DX9, DX10, GL). As Ogre3D main objective is to hide DirectX and OpenGL “specificities”,  I have decided to create a tiny lib for Ogre3D to help registering and mapping ressources for Cuda. This tiny lib, named Ogre::Cuda, helps registering Ogre::Texture and Ogre::HardwareVertexBuffer for Cuda.

This video is just a very basic example showing an integration of two Cuda samples inside Ogre3D. The vertex buffer and the 2D texture cuda kernels are part of the Nvidia GPU Computing SDK.

This library is in beta stage, there is still room for improvement, but the base are settled for a cross-platform and cross-graphics API way to use Cuda thanks to Ogre3D.

Source code and binary demo available on the demo page.

Utilisation example :

Ogre::TexturePtr texture;
Ogre::Cuda::Root* mCudaRoot = Ogre::Cuda::Root::createRoot(renderWindow, renderSystem);
mCudaRoot->init();
Ogre::Cuda::Texture* mCudaTex;
mCudaTex = mCudaRoot->getTextureManager()->createTexture(texture);
//init
mCudaTex->registerForCudaUse();
//on each Cuda update
mCudaTex->map();
Ogre::Cuda::TextureDeviceHandle textureHandle;
textureHandle = mCudaTex->getDeviceHandle(0, 0);
cudaFunction(textureHandle->getPointer());
mCudaTex->update(textureHandle); //reflect changes to the Ogre::Texture
mCudaTex->unmap();
//shutdown
mCudaTex->unregister();
mCudaRoot->shutdown();
Share