P-ray Engine (OpenCL+OpenGL)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
JDB
Posts: 41
Joined: August 5th, 2015, 9:50 am
Location: Australia

P-ray Engine (OpenCL+OpenGL)

Post by JDB » December 16th, 2016, 4:04 am

I did quite a bit of work on updating my ray tracing engine to use the GPU instead of the CPU. As a result I totally recoded the Chili Framework to work with OpenCL and OpenGL instead of DirectX. OpenCL is used to compute the frame rendering which is then displayed in an OpenGL window. Interoperability between OpenCL and OpenGL is used so that OpenCL can share memory with OpenGL and write directly to the framebuffer in GPU memory.

I actually haven't done any work on this project in a few months because other things required my attention, so it's still in very early stages of development and has some bugs. Currently it can render a scene but it doesn't have any fancy stuff like lighting or shadows. It is faster than the CPU version but is still fairly slow and needs to be recoded without a separate buffer for each object mesh so that the 2D acceleration structure I described in my paper can be utilized.

I'm sharing it now since I don't know when I'll work on it again and it could be a useful resource for people interested in how to achieve OpenCL/OpenGL interoperability. Since it's in an early stage of development it also shouldn't be very hard to understand it and mess around with it. Doing so will help you learn how to write kernel code for the GPU. Parallel processing is very useful, the feeling of power I got was like when I first started learning to code.

One thing I've learned writing code for the GPU is that global memory access is the slowest part of an algorithm, and that's where you store things like meshes so you need to really worry about your memory access patterns, which is a very strange way to code because it's not something I usually think about when writing CPU code. Accessing memory in the wrong way can cause a sequential access pattern which destroys any advantage parallel processing provides.

Anyway the source for the project can be found here:
https://github.com/JacobBruce/P-ray-Eng ... CL-OpenGL-

PS: it may be slightly difficult to compile properly since there are a few dependencies. If you have any problems let me know and I will try to help.

Post Reply