How to assign a RT_BUFFER_INPUT_OUTPUT type optix::Buffer to optix::TextureSampler


I am doing something step by step like this:

  1. Create a RT_BUFFER_INPUT_OUTPUT type optix::Buffer
  2. Launch to compute and write data to the buffer
  3. Assign the buffer to a optix::TextureSampler
  4. Using the texture when launch ray tracing

My question is:

  1. When I am doing step 3, the program just crashed... why @@!?
  2. When I create a new buffer with RT_BUFFER_INPUT_OUTPUT type (A brand new, without write anything into it), and assign to the textureSampler. It will correctly caught exception without crashed: OptiX Error: 'Unknown error (Details: Function "_rtTextureSamplerSetBuffer" caught exception: Assertion failed: "m_iotype == RT_BUFFER_INPUT", file: , line: 453)' Why the behavior is not the same
  3. How to get type from optix::Buffer? The interface only can get format, size... etc.
  4. How to assign the RT_BUFFER_INPUT_OUTPUT type optix::Buffer to optix::TextureSampler? I currenty copy the data to another RT_BUFFER_INPUT type buffer before step 3 to avoid the problem...

This is simply not supported in OptiX. Buffers attached to a TextureSampler are required to be RT_BUFFER_INPUT.
It’s also not possible to access a buffer attached to a texture sampler for writing for the reasons given here:
Your workaround in step 4 is the correct approach.

In step 3 you mean you want to determine the buffer format of a buffer attached to a texture sampler on device side?
That is not necessary because you can only read from it via the rtTex(int texId, float u, …) bindless texture intrinsics in OptiX. The read mode defines the behavior. If you need additional information you would need to store them along with your OptiX bindless texture IDs.


The data is huge…

Too sad that I need to copy them via host memory. :(…