I am using OGRE for rendering some objects. At every frame, I would like to pass the resulting depth buffer to CUDA for running some kernels on it and computing a result.

How can I achieve this? How do I get access to depth buffer in OGRE? How do I pass this to CUDA for processing? I do not need to write to the depth buffer in the CUDA kernels, it can be read-only.


1 Answer 1


Firstly to get CUDA working you will need to download the correct drivers from NVIDIA for your graphics card.

You will also need to download the CUDA SDK and link against it and #include it in your program.

you can send data to the GPU by allocating a buffer and copying it to the GPU as so:

char *buffer;
cudaMalloc( (void**)&buffer, yourBufferSize );
cudaMemcpy( buffer, yourDepthBuffer, csize, cudaMemcpyHostToDevice );

To execute a kernel on this data

dim3 dimBlock( 1, 1 );
dim3 dimGrid( 1, 1 );
testKernel<<<dimGrid, dimBlock>>>(buffer);
//You'll probably want to decide on your own block size etc ...

Where the test Kernel is

void testKernel(char *a)
    a[threadIdx.x] = .....; //whatever you want to do

To get the result back you use

cudaMemcpy( yourResult, buffer, yourBufferSize, cudaMemcpyDeviceToHost );

And of course clean up after yourself

cudaFree( buffer);

That's the overall gist of it anyway. You'll probably need to fill is some gaps like error handling and so forth, but I figured it best to keep it simple.

See here for a walkthrough of the basics.


You must log in to answer this question.

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