Hi,
I initialize my buffer like this (p_tab is a cpu buffer):
std::string nameBuffer = "Sh_buffer";
optix::Variable var = m_context->declareVariable(nameBuffer);
optix::Buffer buf;
int d;
cudaGetDevice(&d);
buf = m_context->createBufferForCUDA(RT_BUFFER_INPUT,RT_FORMAT_USER,width,height,depth);
buf->setElementSize(tailleElementaire) ;
T* d_test;
cudaMalloc((void**)&d_test,width*height*depth*tailleElementaire);
cudaMemcpy(d_test,p_tab,width*height*depth*tailleElementaire,cudaMemcpyHostToDevice);
rtBufferSetDevicePointer(buf->get(), d,(CUdeviceptr)d_test);
This works well: the value of the index SH_buffer requested is correct.
I want to change the value of SH_buffer when the camera is moving. I tried several methods:
Method 1
optix::Buffer buf = m_context[nameBuffer]->getBuffer();
T* d_test;
cudaMalloc((void**)&d_test,width*height*depth*tailleElementaire);
float* h_test = (float*)malloc(width*height*depth*tailleElementaire);
for(int i=0 ; i<width*height*depth ; i++)
h_test[i]=8;
cudaMemcpy(d_test,h_test,width*height*depth*tailleElementaire,cudaMemcpyHostToDevice);
rtBufferSetDevicePointer(buf->get(), 0,(CUdeviceptr)d_test);
m_context[nameBuffer]->set(buf);
Error :
Invalid value (Details: Function "_rtContextLaunch2D" caught exception: Encountered a CUDA error: driver().cuMemcpyPeer( other_devmem->getDevicePtr(), device->getCudaContext()->getCUcontext(), my_devmem->getDevicePtr(), my_device->getCudaContext()->getCUcontext(), numBytes) returned (1): Invalid value, [786493])
Methode 2 (use both rtBufferSetDevicePointer rtBufferGetDevicePointer)
optix::Buffer buf = m_context[nameBuffer]->getBuffer();
T* d_test;
cudaMalloc((void**)&d_test,width*height*depth*tailleElementaire);
rtBufferGetDevicePointer(buf->get(), 0,(void**)&d_test);
float* h_test = (float*)malloc(width*height*depth*tailleElementaire);
for(int i=0 ; i<width*height*depth ; i++)
h_test[i]=8;
cudaMemcpy(d_test,h_test,width*height*depth*tailleElementaire,cudaMemcpyHostToDevice);
rtBufferSetDevicePointer(buf->get(), 0,(CUdeviceptr)d_test);
m_context[nameBuffer]->set(buf);
No error but no change in the value of SH_buffer with the method 2.
Can you tell me how to change the value of the buffer just before use rtTrace ?