Multithreading Saga Continued...
This week I grappled with Unreal Engine multithreading some more. I'm trying to make the terrain generation as efficient as possible for the planets, and that has consisted of lots of trial and error, and several rewrites, which means learning!
I came across this great Unreal Fest Gold Cost talk from 2024 which explains UE multithreading and how to use it. I'm surprised I hadn't come across this before because it has lots of great info. The biggest revelation I had was that I was using the wrong method of multithreading for what I wanted to do. Before this week I was using an FRunnable to calculate the terrain. In the talk however, Alex explains that these FRunnables are meant for larger lifecycle tasks and are intended to be kept running. For my use-case though I want more fire and forget type functionality. Give a thread some info, let it run its calculations, and give the resulting data back to the game thread whenever it's done.
For this job I looked into several of the options outlined in the talk: the thread pool, async tasks, and atomics. Though I ended up settling with the Task System for a couple of reasons:
- Very robust compared to other methods while still having minimal overhead.
- Claimed to be fantastic at going wide with tasks which is what I want.
- Improvement of the Task Graph which has been in the engine for a while.
- Better debugging capabilities.
- And I got the sense that the Unreal Engine team it putting more effort into expanding and supporting the Task System.
This whole saga of finding the solution that I would go forward with involved many rewrites and changes where I got turned around and frustrated at times. Taking a step back and keeping notes on what was working and what wasn't helped me through this part. At time of writing, it's still a work in progress though.
I intended to end this week with a fully functional and optimized version of the terrain generation with stat traces to show the improvement, but alas, going down too many rabbit holes means that I will be continuing this work into next week. Though I am hopeful that taking it slow here will lead to better results.
Comments
Post a Comment