rtBufferGetDevicePointer is reporting null pointer


I justed tried to use the Optix interop.
When I tried to get the pointer for a valid pointer, the following error occured:

Invalid value (Details: Function “_rtBufferGetDevicePointer” detected error: Pointer “device_pointer” is null)

The buffer is for sure valid:
m_context[“ultrasound_buffer”]->setBuffer(m_context->createBuffer( RT_BUFFER_INPUT_OUTPUT, RT_FORMAT_FLOAT, m_iSamplePoints, m_iRays, m_iDimZ_mul2));

The Device is for sure 0.

Any hints what could be the problem?

Hi Benny,

Are you trying to do CUDA or OpenGL/D3D interop? You might need to use rtBufferCreatefromGLBO() if using OpenGL, rtBufferCreateForCuda() if using a CUDA device pointer in OptiX, or rtBufferGetDevicePointer() if you want to use an OptiX pointer in CUDA. Quickest hint would be to check chapters 6 and 7 of the Programming Guide first.


Hi Marcus,

thanks for the fast answer.
I already read the manual and according to it, there is no need to use a function like rtBufferCreateForCuda() because the memory is allocated by OptiX and should be passed to a Cuda function.

Here an extract from the manual

Getting CUDA Device Pointers from OptiX
One way to achieve CUDA-OptiX interop is to ask OptiX to manage and allocate
device memory and simply get a pointer to it. This is done using the
rtBufferGetDevicePointer call:
rtBufferGetDevicePointer( buffer, optix_device_number,
This call will return the device pointer for the given buffer on the specified OptiX
device. If the application requests the buffer device pointer before OptiX has
launched, this pointer can be used to provide data to OptiX. If the application
requests the buffer device pointer after OptiX has launched, the application can then
postprocess OptiX’s output.

I did not try the other way round (create with Cuda and pass to Optix) because the first scenario better fits my needs.

Hi Benny,

this error happens when device_pointer in the rtBufferGetDevicePointer call is null. Note that it is a void**, so it has to contain the address of a pointer it can modify, but cannot be null. Something like:

void *dev_ptr;
RTresult res = rtBufferGetDevicePointer(buf, optixDeviceIndex, &dev_ptr);


Duh - Maybe I really forgot the adress operator I will have a look.
Thanks for the hint.

Ok I finally found the time to test the code again :-)
I indeed made an addressing error. I’m using the c++ wrapper functions and used:

CUdeviceptr *pointerToBuffer=NULL;
buffer->getDevicePointer(deviceId, pointerToBuffer);

because I though a **pointer is needed.
But the working code is just:

CUdeviceptr pointerToBuffer;
buffer->getDevicePointer(deviceId, &pointerToBuffer);

I don’t understand it completely, because CUdeviceptr is not a real pointer, but now everything is working fine.
typedef unsigned long long CUdeviceptr;

inline void BufferObj::getDevicePointer(unsigned int optix_device_number, CUdeviceptr device_pointer)
checkError( rtBufferGetDevicePointer( m_buffer, optix_device_number, (void
*)device_pointer ) );

Thanks again for the hint.