Ray tracing: CPU vs. GPU

Hey guys!

Over the weekend I did this comparison of the modern hardware ray tracing performance, comparing CPU and GPU.
Tracing with 8 rays per pixels using i7-4790K on the CPU side and Titan X on the GPU side.
There aren’t any “short and sweet” topical videos out there so I hope I managed to create one.

https://youtube.com/watch?v=BnW7VE1wTwk

Details

CPU stats
Render time: 1748 seconds
Rendered at: 480x400

GPU stats
Render time: 16 seconds
Rendered at: 960x800

GPU outperformed CPU about 437 times.

Please note that none of the algorithms are optimal, many things could be improved, like the smoothing of the CPU workload spikes (consequence of thread synchronization) etc.

Ran on this machine on these (stock) settings:

Motherboard: Z97-DELUXE(NFC & WLC)
PSU: Cooler Master “V Series” V850
CPU: Intel® Core™ i7-4790K 4.4Ghz
CPU cooler: Hydro Series™ H100i Extreme Performance
GPU: GeForce GTX TITAN X
RAM: G.SKILL Trident X Series 32GB (4 x 8GB) DDR3 2400 Mhz
SSD0: Samsung SSD 850 PRO 256GB
SSD1: Samsung SSD 850 EVO 500GB
HDD: WD Green 2TB
CASE: NZXT. Phantom 410 Black

This topic is not directly related to Unreal Engine.

What API did you use? OpenCL? CUDA?
Very impressive.

Thank you! None, it’s all done in a fragment shader program in GLSL, OpenGL 3.1 and the tracer itself is written in C++. The CPU ray tracing path is writting a buffer and then updating a texture on the GPU so that way I can keep it nice and clean in the code and it’s not really a lot of overhead, because the CPU needs a lot of time to do the traces so the RAM to VRAM transfer of the 480x400x32 bits for the texture is not an issue.

I don’t understand.
I thought one should always use the GPU in visual stuff.

I cannot think of any movie that did not use a raytraced for there CG, And most raytraced renderers (that I know of) use the CPU.
It’s just that the GPU tends to do such work better.

That’s a pretty common generalization but yes in general it is true in the current era of hardware, but with ray tracing things get a bit more complicated. The GPUs as we have them today are designed for rasterization of geometry and ray tracing solves the same problem as rasterization in a different way. To keep it simple, ray tracing is going to win in the end - I think that’s pretty clear, it’s been around since forever, it simulates nature very well, but it’s a very, very resource demanding process because you’re basically shotting photons (rays) around the scene and recursively bouncing until a certain point and gathering the results that then determine the color of a certain pixel.
What you may not know is that recursion is not supported on GPUs (or not very well supported/limited on most) and that shader complexity is limited, along with other architectural differences a ray tracing algorithm needs to be redesigned to work on a GPU but on a CPU is a pretty straightforward process. A lot of ray tracers use CPUs (probably the majority), there are a bunch of reasons for it, from code complexity to performance per dollar to already established hardware architecture in the company.
This is a huge topic to discuss, so I’ll leave it here for this reply. Hope this clears things up a bit. :slight_smile: