How Cycles takes the mesh from Blender and feeds it to OpenCL GPU?

Last year we made a ray tracer in Scala (RayTracingSystem), that was really fun, this program is able to render OBJ files and supports almost all nodes and shaders you can find in Cycles.
Recently I came across the topic of OpenCL parallel programming and the question is how does Cycles takes the mesh and transfers it to OpenCL kernels in GPU.
The thing is that after examining Blender/2.79/scripts/addons/cycles I didn’t found and .dll or .exe files, I have no idea about how kernels from Blender/2.79/scripts/addons/cycles/source/kernel/kernels/opencl get into GPU.

The main my assumptions are:

  1. Temporary File: Cycles makes heavy use of my SSD by saving the model into some temporary file in a compact way.
  2. Reading .blender: Cycles reads .blender file.
  3. Python: Cycles asks Blender for a pointer to the mesh in GPU RAM.

Check out intern/cycles/blender/blender_mesh.cpp, BlenderSync::sync_mesh(), that’s where geometry gets from Blender to Cycles. Then in cycles/render/mesh.cpp MeshManager::device_update_mesh() is where Cycles copies the mesh to the compute device, that is the CUDA or OpenCL GPU.

2 Likes