11/10/09 1 Multicore Strategies for Games Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology 2 Bad multithreading Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Slide from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 3 Rendering Thread Rendering Thread Rendering Thread Game Thread Good multithreading Main Thread Physics Rendering Thread Animation/ Skinning Particle Systems Networking File I/O Game Thread Slide from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 4 Another paradigm: cascades Thread 2: Physics Thread 4: Rendering Thread 5: Present Thread 1: Input Thread 3: AI • Advantages: – Synchronization points are few and well-defined • Disadvantages: – Increases latency (for constant frame rate) – Needs simple (one-way) data flow – For balance, each chunk needs to take a similar amount of time Slide from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation11/10/09 2 5 Typical task: File decompression • Most common CPU heavy thread on the Xbox 360 • Easy to multithread • Allows use of aggressive compression to improve load times • Don’t throw a thread at a problem better solved by offline processing – Texture compression, file packing, etc. Slide from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 6 Typical task: Rendering • Separate update and render threads • Rendering on multiple threads usually works poorly – GPU can have trouble if multiple threads try to talk to it at once (Xbox 360 command buffers are supposed to be OK) • Special case of cascades paradigm – Pass render state from update to render Slideadapted from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 7 Separate rendering thread Update Thread Buffer 1 Render Thread Buffer 0 Slide from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 8 Typical task: Graphics fluff • Extra graphics that doesn’t affect play – Procedurally generated animating cloud textures – Cloth simulations – Procedurally generated vegetation, etc. – Extra particles, better particle physics, etc. • Can run at lower frame rate • Easy to synchronize • One game had one thread manipulating cloth, another thread handling cloth shadows • On single-core machines, can drop or simplify the fluff without effecting gameplay Slide adapted from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation11/10/09 3 9 Typical tasks: Physics? • Could cascade from update to physics to rendering – Makes use of three threads – May be too much latency • Could run physics on many threads – Uses many threads while doing physics – May leave threads mostly idle elsewhere Slide from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 10 Careful with simultaneous multi-threading • Not the same as double the number of cores • Can give a small performance boost… – …if first thread is underutilizing execution resources because of dependency stalls • Can cause a performance drop – Two threads may fight over L1 cache • Can avoid scheduler latency – Have a thread that is ready to run but OS waits for current “scheduling quantum” to expire before running the thread – Hardware threads can wake up faster; works well if you have a thread that mostly sleeps but needs to wake quickly on demand Slide adapted from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 11 How Many Threads? • No more than one CPU intensive software thread per core – 3-6 on Xbox 360 – 1-? On PC (1-4 for now, need to query) • Too many busy threads adds complexity and lowers performance – Context switches are not free • Can have many non-CPU intensive threads – I/O threads that block, or intermittent tasks Slide from from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 12 Rare’s Kameo Screenshots from www.rareware.com11/10/09 4 13 Case study: Kameo (1) • Started out as single threaded – Was going to be an original Xbox game, but decided to and make it a 360 launch title • CPU usage split was 51/49 for update/render, so rendering was put on separate thread – Two render-description buffers created to communicate from update to render – Linear read/write access for best cache usage – Doesn't copy const data Slide adapted from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 14 Case study: Kameo (2) • Decompression thread: • Saved space on DVD and improved load times • Cost was some spare CPU cycles • Actually two threads for file I/O • One for reading and one for decompressing, because some calls can block for ~0.5s doing directory lookups • Multithreading added about six months before launch - but it worked! Slide adapted from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 15 Case Study: Kameo (3) Core Thread Software threads 0 0 Game update 1 File I/O 1 0 Rendering 1 2 0 XAudio 1 File decompression • Total usage was ~2.2-2.5 cores 80-99% 80-99% 50% Screenshot from www.rareware.com Slide adapted from Bruce Dawson & Chuck Walbourn, Microsoft Game Technology Group, “Coding for Multiple Cores,” PowerPoint presentation 16 Bizarre Creations’ Project Gotham Racing 3 See http://media.xbox360.gamespy.com/media/741/741362/vids_1.html for movie clips!Screenshot from projectgothamracing3.com/screenshots11/10/09 5 17 Case Study: Project Gotham Racing 3 Core Thread Software threads 0 0 Update, physics, rendering, UI 1 Audio update, networking 1 0 Crowd update, texture decompression 1 Texture decompression 2 0 XAudio 1 •
View Full Document