how to pass a complex hierarchical structure to OpenCL


I have a raytrace software and would like to implement a part of it with OpenCL.
In order to do this I must pass the entire scene information to OpenCL…

My problem is that it is a complex ‘structure/class’ hierarchy that use a lot of pointers.

And I don’t know an efficient way to pass this scene information to OpenCL.

By example :

struct Scene
Lights * lights;
InstanceList * instanceList;

struct InstanceList
Instance * instance;
int Count;

struct Instance
Geometry * geometry;
Instance * next;

struct Geometry
int GeometryType; // 0 = sphere, 1 = cylinder, 2 = Triangle mesh
Sphere * sphere;
Cylinder * cylinder;
TriangleMesh * triangleMesh;

struct TriangleMesh
int Indices;
float Vertices;

So, with this (simplified) version of the scene, how can I pass this information to openCl and use it ?

Thanks for your help

I’ve been thinking about this lately and it might not be trivial. In CUDA you had pointers (which could point to device data) with C syntax, in OpenCL you have Buffers represented by cl_mem objects.

I’m not sure how to do this elegantly (without making the code less readable). But keep in mind, pointer-chasing can be a HUGE performance issue on many high performance architectures (and most definitely on GPUs, good luck coalescing accesses). You might consider restructuring your program to use plain arrays and simple structures anyway.