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.

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.

share|improve this question
    
This question has been answered on SO, however only for Direct3D: stackoverflow.com/questions/17140255/… –  Philip Allgaier Dec 1 '13 at 17:08

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

__global__
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.

share|improve this answer

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.