I have some problems getting the device pointer of an OptiX buffer after updating from OptiX 3.8 to OptiX 4.0.
To create the buffer, this method is used:
void addOutputBufferFormatUser(optix::Context context,
std::string name,
unsigned int width,
unsigned int height)
{
Buffer buffer;
GLuint vbo = 0;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
size_t element_size = sizeof(PointXYZADIJK);
glBufferData(GL_ARRAY_BUFFER, element_size * width * height, 0, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
buffer = context->createBufferFromGLBO(RT_BUFFER_OUTPUT, vbo);
buffer->setFormat(RT_FORMAT_USER);
buffer->setElementSize(element_size);
buffer->setSize(width, height);
m_context[name]->setBuffer(buffer);
notify(WARN ,"addOutputBufferFormatUser() created buffer with name %s.", name.c_str());
}
Called by this line:
addOutputBufferFormatUser(m_context, "output_buffer_xyzaijk", m_width, m_height);
Now I would like to transfer the buffer to CUDA by calling:
void
postTrace() const
{
void* pointerToBuffer = NULL;
Buffer buffer = m_optiXInterface->getBuffer("output_buffer_xyzaijk");
if (buffer->get() == NULL)
{
notify(FATAL ,"postTrace() buffer null.");
}
buffer->getDevicePointer(0, &pointerToBuffer);
checkCudaErrors(cudaMemcpy(d_rayArray, (PointXYZADIJK*)pointerToBuffer, sizeof(PointXYZADIJK), cudaMemcpyDeviceToDevice));
// Unmap buffer:
rtBufferUnmap(buffer->get());
}
Or my older code:
void
postTrace() const
{
RTresult res = RT_SUCCESS;
void* pointerToBuffer = NULL;
Buffer buffer = m_optiXInterface->getBuffer("output_buffer_xyzaijk");
if (buffer->get() == NULL)
{
notify(FATAL ,"postTrace() buffer null.");
}
// Read OptiX buffer:
res = rtBufferGetDevicePointer(buffer->get(), 0, &pointerToBuffer);
if (res == 0)
{
checkCudaErrors(cudaMemcpy(d_rayArray, (PointXYZADIJK*)pointerToBuffer, sizeof(PointXYZADIJK), cudaMemcpyDeviceToDevice));
notify(WARN ,"postTrace() could copy buffer to cuda.");
}
else
{
notify(WARN ,"postTrace() could not copy buffer to cuda: result %u.", res);
}
// Unmap buffer:
rtBufferUnmap(buffer->get());
}
Both functions return this error:
display <Invalid value (Details: Function “RTresult _rtBufferGetDevicePointer(RTbuffer, int, void**)” caught exception: Cannot get device pointers from non-CUDA interop buffers.
As mentioned earlier, OptiX 3.8 works perfectly fine. I read about OptiX 4.0 being more strict with interop data but the error message does not ring a bell for me. Any help is highly appreciated!