I would like to know what is the best way of using D3D11 textures with TextureSampler in Optix 4.1.1 ? It is obvious that Optix + D3D11 is not officially supported anymore. So I use CUDA as a bridge. Is there a way to make it as efficient as possible?
It seems, TextureSampler::setBuffer() doesn’t accept a buffer that was created as RT_BUFFER_INPUT_OUTPUT | RT_BUFFER_GPU_LOCAL, it just assert crashes with error code unknown:
_buffer = _context->createBuffer(RT_BUFFER_INPUT_OUTPUT | RT_BUFFER_GPU_LOCAL, RT_FORMAT_UNSIGNED_BYTE4, _width, _height);
_buffer->validate(); // no assert crash
_textureSampler->setBuffer(_buffer); // assert crash error unknown.
Therefore it seemed I was not able to share CUDA buffers. Then, I tried to copy from CUDA to optix Buffer.
cudaMalloc((void**) &cuData, 4 * _width * _height);
cudaMemset(cuData, 255, 4 * _width * _height);
// Note here RT_BUFFER_INPUT_OUTPUT also leads to assert crash in setBuffer, it seems not documented.
_buffer = _context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_UNSIGNED_BYTE4, _width, _height);
void* devicePointer = _buffer->getDevicePointer(_context->getOptixDeviceOrdinal());
cudaMemcpy(devicePointer, cuData, 4 * _width * _height, cudaMemcpyDeviceToDevice);
However the result was black. As I set per byte 255, it should have been white.
I also tried RT_BUFFER_INPUT | RT_BUFFER_COPY_ON_DIRTY with MarkDirty. But the result was black as well.
So finally I tried copy from CPU with map and unmap buffers. it works…
But D3D11 → CUDA → CPU → Optix, such a workflow is too slow for me.
Maybe I did something wrong.
Thanks for any suggestions,