OptiX 6, clear output buffer

Hi all,

I use OptiX to make some computation, and I need to get back some data. For this I use an output buffer, like this:

optix::Buffer outBuffer;

My problem is, between two Optix runs, this buffer is not cleared, this mean, data from the first run are still present after the second run.

I achieved to clear the buffer with the code below, but I had to set the buffer as “RT_BUFFER_INPUT_OUTPUT”, which is not really correct.

optix::Buffer outBuffer;
outData* pointerOutData;
pointerOutData = (outData*)outBuffer->map(0,
memset(pointerOutData, 0, N*N*sizeof(outData));

Is there a way to clear an output buffer, without mapping it on the host and doing a “memset” on it?


Depending on your algorithm there are two simple ways to do that with the GPU.

If you’re not doing any scattered writes and the buffer size == launch dimension, you can simply clear resp. initialize with the first calculation.
Something like this in an iterative accumulation:

If you’re programming some scatter algorithm and need all data to be initialized before starting the calculation, you can implement a specific ray generation program which is just filling the output buffer and launch that with the buffer size dimension explicitly by selecting it with the entry point argument in rtContextLaunch().
Note that the first time you invoke an entry point the device kernel gets compiled for that. Means the very first launch will take longer than the following invocations
Basically this:

(In OptiX 7 latter could simply be done with CUDA runtime API cudaMemset*() resp. CUDA driver API cuMemset*() functions on the device pointer.)

Thanks for your answer.

While the buffer size is different from the launch dimension, I tried the second method you proposed. And it works fine.