Building a Threaded Game Engine

Valve Software researched and experimented with all three multithreading models, and some of the results were promising. The first thing they did was to look at coarse threading, being that it is usually the easiest approach. Like Quake 4 and Call of Duty 2, Valve also has a client-server architecture in the Source engine, so that's where they started. The results can be summarized with the following slide:


There were benefits to the work that was done, but long-term such an approach is destined to fall short. If you only have a client and a server thread, you are only using two processor cores at most, and even then it is unlikely that you're making full use of both cores. The decision was ultimately reached that the only approach truly worth pursuing as a long-term solution is hybrid threading. It will require the most effort but it will also give the most benefit. As long as you're already rewriting large portions of your engine, the thinking goes, you might as well make sure you do it right so as to avoid doing the same thing again in the near future. The next step is to come up with a threading framework that will allow the developers to accomplish their goals.


Operating systems and compilers already provide some support for multithreaded programs. In some cases, this support is sufficient, but when it comes to building a real-time gaming engine anything short of a custom threading tool may not provided the desired flexibility. Valve's problems with OS and compiler level threading can be summarized in the following two slides.



We've already stated several times that making multithreaded programs can be difficult, and the problem is exacerbated when you have many programmers -- some of them junior programmers that have never seen threaded code in their life -- all trying to work together. Valve decided that ultimately what they wanted to create was a threading framework and a set of tools that would allow the programmers and content creators to focus on the important thing, actually creating the games, rather than trying to constantly deal with threading issues. Tom Leonard and a couple other helpers were tasked with creating this toolset, and as you can guess by the existence of this article, their efforts are about to reach fruition.



We're not going to try and snowball you with any more information on the low level details at present. Basically, Valve is working hard to provide a toolset that will enable their developers -- as well as mod creators and engine licensees -- to take full advantage of multi-core platforms. They aren't just looking at dual core or even quad core; their goal is to build an engine that is scalable to whatever type of platform users may be running in the future. Of course that doesn't mean they won't be rewriting portions of their engine at some point anyway, but all signs indicate that they should be at the forefront of creating multi-core games and gaming engines.

Threading Models The Future of Gaming?
Comments Locked

55 Comments

View All Comments

  • yacoub - Wednesday, November 8, 2006 - link

    sorry about that. got a little too excited.
  • Ruark - Tuesday, November 7, 2006 - link

    Page 6: ". . . everything crawls to a slow."
  • duploxxx - Tuesday, November 7, 2006 - link

    page 8 test setup, clear a cut/paste job... all of the cpu's are the same Athlon.

    put an allendale in the benchmark, lot's of people want to see how cache related this multithread sw is.

    Valve talks about 64-bit... tests are 32bit? Since some competitors are talking about 64-bit code in there gaming also, should be interesting to see what the difference is vs 32bit.
  • JarredWalton - Tuesday, November 7, 2006 - link

    Sorry 'bout that - I've fixed the CPU line. All systems were tested at stock and 20% OC. The problem with Allendale is that it has different stock clock speeds, so you're not just comparing different CPU speeds (unless you use a lower multiplier on Conroe). Anyway, this is a first look, and the next CPU article should have additional benches.

    The tests are all 32-bit. This is not full Episode 2 code, and most people are waiting for Vista to switch to running 64-bit anyway. All we know is that Episode 2 will support 64-bits natively, but we weren't given any information on how it will perform in such an environment yet.
  • brshoemak - Tuesday, November 7, 2006 - link

    Nice to know where things are headed. Great article.

    Jarred, 2nd page, 2nd paragraph

    quote:

    place it into a pan and start beating the oven


    should be 'heating the oven' - although quite funny as is, you may want to keep it ;)
  • JarredWalton - Tuesday, November 7, 2006 - link

    Darn speech recognition. And "b" and "h" looked close enough that I missed it. Heh. No ovens were harmed in the making of this article.
  • MrJim - Tuesday, November 7, 2006 - link

    This was a very interesting article to read, the future looks bright for us with multi-core systems and Valve games. Excellent work Mr Walton!
  • timmiser - Tuesday, November 7, 2006 - link

    Shoot, I didn't make it past the dinner description. Got too hungry!
  • George Powell - Tuesday, November 7, 2006 - link

    I quite agree. Top notch article there. It is great to see how Valve are committed to giving us the best gaming experience.
  • Regs - Tuesday, November 7, 2006 - link

    The future looks bright for people willing to buy valve and multi-core CPUs!!

Log in

Don't have an account? Sign up now