Team Fortress 2, Quadcores and You
So recently I have begun making tweaks to my Team Fortress 2 seeing that there are some rough spots in my frames dipping below 50 FPS from 60 FPS. I remember Source being an older gaming engine would be CPU bound more than the newer engines which are GPU-bound. What I found was that there might be a multithreading bug in the Orange Box Source Engine.
This possible bug seem to affect quad core processors as I haven't found any dual core users having this issue at all. Apparently it has to do with the processor core affinity. If you just run hl2.exe for Team Fortress 2, it would just use Core 0 until you minimize the game and set the processor affinity in Windows Task Manager. So if I deselect Core 0 and Core 1 and run the system in a "dual core" configuration by having Cores 2 and 3 running, then it will load both cores to 100% and then the frames would be a lot steadier.
First, you may wonder, what is Processor Affinity? In layman's term, ever since processors come with more than one processing cores, the operating system (in this case Windows) allows users to control which application can use which core(s) that they allow the program to run on. It is used to also manipulate how many core(s) a program can use.
Once I realized this issue, I played around with the Processor Affinity settings and this is what I found out (note: all of these snapshots are taken when I ALT+TAB out of the game with Windows Task Manager running in the background. Also note that in computer terms Core 0 is the first core and Core 3 is the 4th core.)
So without touching the Processor Affinity settings, you will notice how all of the processor load is on Core 0 (the core to the furthest left). So seeing that I toggled the Set Affinity settings on Windows Task Manager.

Notice how after I toggle the Set Affinity settings, you can see that there's an immediate effect on the multicore options. Now why is that? Why does it only work when I toggle the Set Affinity settings? Shouldn't the software do it by itself if it should be multicore ready? Also, I set out to see if this Set Affinity trick make it spread to 3 of my cores.

Oh hey look! It worked! Sure it may not load up three of the cores fully, but having that extra core working, it makes things work smoothly. Ok, so far I've tested Cores 1, 2 and 3. Let's try applying the same to Cores 0, 1 and 2.

As you can see, it works, but unfortunately, you can see that there's still more load towards Core 0 instead of Cores 1 and 2. This is interesting as it seems like the Source engine is biased towards Core 0 for some odd reason. Could it be because programmers made it so? In a performance standpoint that shouldn't happen as all cores should be treated equally so they can handle the whole load. So seeing the success of 3 cores running Team Fortress 2, I tried toggling it to 4 cores.

Success again, so wait, by default if I don't touch any of the Affinity settings, Windows would automatically assign it to every single of my cores in my quad cores, so why would it default to using only 1 core? Why does it only work when I set the Affinity manually when the Source Engine use all four cores (well, not fully loading it but still distributing it equally).
This doesn't make any sense to me, is this a bug that no one has realized or something Valve has been quiet about? I hope it is a bug and be fixed because setting the Processor Affinity on Windows is temporary, you must set it manually every time you run a certain application. Once it's closed the setting is gone.
So now you might ask, "hey, how did you do all this? How do you make Team Fortress 2 multithreaded?" Here are the steps.
First create a file called autoexec.cfg in your %ProgramFiles%\Steam\Steamapps\<username>\team fortress 2\tf\cfg folder. Paste these options in:
cl_threaded_client_leaf_system "1"
cl_threaded_bone_setup "1"
mat_queue_mode "2"
r_threaded_renderables "1"
r_threaded_particles "1"
r_threaded_client_shadow_manager "1"
So now that you got these options in, launch Team Fortress 2 in STEAM. Once you do go to Options --> Video --> Advanced and then enable Multicore Rendering. After that, restart Team Fortress 2 and now Team Fortress 2 is multithreaded. Now, if you had Windows Task Manager opened the way how I had them above, then you should see that after playing about 3 minutes worth of TF2, you may notice that all of the CPU load is on Core 0 and none at any other cores (if you see load in other cores like my first screenshot, that's your system doing other background tasks unrelated to the game).
Now you may ask, "so now how do I change my Processor Affinity?" This is rather simple. On Windows Task Manager perform these steps:

As shown above, right click hl2.exe (or hl2.exe *32 as shown above if you have a 64-bit operating system like I do) and then select Set Affinity.

Once you do that, you should get a dialog box as shown above. Now you can deselect the cores that you don't want the application to use.
So now that you also know how it is done, test it out and please leave comments about your findings as well. Hopefully it's not only I'm having this unique issue. Also, tell me what you think of this strange finding.

Comments
1 comment postedUgh, still having this issue. Thanks for the Write up, hopefully Vavle fixes this :(
Post new comment