Reading 3D buffers on CPU

Hello,

I’m working on ray-tracing applied to ultra-sonic wave simulation. The results OptiX produce are stored into a 3D buffer that is transferred to the CPU memory in order to be read by a C++ program.
My problem is the following : I don’t exactly know how to get the (x,y,z) element from my buffer once it’s mapped.

First, I wrote an accessor like this :

size_t global_id_element = x * n_y * n_z + + y * n_z + z;

It didn’t work so my new accessor is the following :

size_t global_id_element = x + n_x * (y + n_y * z);

Is it correct ?

Thanks,
Hamza

This depends on how you write the elements into the buffer in your OptiX programs.

Have a look at http://www.cplusplus.com/forum/beginner/2903/, hope this helps.

I agree with m_sch, it depends on how you decide to store elements inside the buffer.

I was just using the 3D launch index to write into my buffer :

buffer[launch_index] = data;

Anyway, what I wrote was correct, I checked it.
So it’s a “minor-first” array.

Thanks.