Why are games single-core bound on CPUs and not multithreaded? I understand why the rendering is offloaded to GPUs but what about other tasks?

44 views
0

Why are games single-core bound on CPUs and not multithreaded? I understand why the rendering is offloaded to GPUs but what about other tasks?

In: 5

Multithreading adds a lot of complexity to code. This adds bugs & development cost. Some games also don’t need multithreading because they achieve good performance on a single thread.

Most of the work required to run a video game is drawing frames, which is done on the GPU. The CPU is doing some things but its main job while running a game is just taking data & sending it to the GPU, with little or no processing in between.

Traditional graphics libraries such as OpenGL are single threaded meaning only one thread can talk to the GPU at one time. This has changed with Vulcan which has multithreading built in.

If most of your code is about rendering, introducing multiple threads into the mix would only add complexity, and that is something you want to avoid at all cost in software projects.

It is common to offload other non-graphical tasks to other threads, and modern game engines have more modern paralell architectures that will better take advantage of multithreaded hardware.

GPUs are best for handling lots of independent calculations, where you don’t need the results of one to calculate the next. However game calculations don’t often fit this, as physics and game state calculations often are dependent on each other and so you can’t start computing a later part until the previous calculations are complete. This makes the CPU better suited for this as while it’s not good at calculating many things at once, it can do individual calculations much faster.

A good program is optimized to send different calculations to different processors depending on the nature of those calculations. If it’s lots of independent calculations, let the GPU do it. If it’s a series of somewhat interdependent calculations, split it between a number of CPU cores. If it’s a series of calculations that all depend on the previous result, then let the fastest core do it all.

You can’t always speed up a program by adding more processors just like you can’t make a baby faster by adding more women.

Games, almost all, are written, and developed, to run on the LCD (lowest common demoninator) of hardware, to sell to the widest audience possible.

Why spend money developing for multi-processor/multi-core/multi-thread machines?

And what ‘Other Tasks’? For a single player game, the tasks are probably 95% rendering, 5% actual logic. For MMORPG’s, 85% rendoring, 10% dealing with comms, and 5% actual logic.

Quite simply, games require many things to be done *in order*. And getting an ordered output from a multi-threaded process is not always easy (could literally be impossible) and can actually end up being slower than a single-threaded strategy. Not everything can be parallelized.

And games will almost always have a singular “loop” running on one thread/core. This loop synchronizes everything, signals other threads, and likely does quite a bit of other miscellaneous work.

There’s always going to be serial work that needs done, no matter how parallel your software is.