Question

how can I send recursive data structure, like octree, to OpenGL GLSL shader? I think, I can send it as array of nodes and use indexes instead of pointers, is it a good idea? Are there other options to do it?

Was it helpful?

Solution

GPU ray tracing often uses recursive data structures such as triangles in kd-trees or sparse voxel octrees.

In a shader you can use a 1D texture sampler as though it was an array, making it easy to jump around.

However, performance suffers. All shaders in the batch (warp or whatever your card terms it) usually work in lock-step, so if one fragment requires recursing ten steps in the tree the other fragments in the batch have to wait for that fragment to do its ten random-memory-accesses before they can proceed.

GPUs work best when given a list of triangles to rasterise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top