620 likes | 630 Views
1 November 2006. Source Multicore. New Source Features. Dynamic Shadow Mapping New Foliage System Cinematic Physics Version 2 of Facial Animation System Dynamic Scripted Sequences Particle System 64-Bit Source Engine Reworked Character Lighting Model Companion AI (Alyx in Episode One)
E N D
1 November 2006 Source Multicore
New Source Features Dynamic Shadow Mapping New Foliage System Cinematic Physics Version 2 of Facial Animation System Dynamic Scripted Sequences Particle System 64-Bit Source Engine Reworked Character Lighting Model Companion AI (Alyx in Episode One) Real-Time statistics gathering Automatic game cache defragmentation Multicore
New Features in Source Multiple Approches to multi-core games Source is implementing Hybrid-Threading Close to linear improvements Pretty but dumb era is ending, scalability we've seen in graphics will now apply to rest of the game Hybrid Threading Source will ship before Episode Two You'll get a version of this engine to take home to test with
Multicore Most significant development since 3D cards Huge potential Huge challenge
Multicore Most significant development since 3D cards Huge potential Huge challenge The decisions faced with multiple cores How we are using multiple cores
Multicore Most significant development since 3D cards Huge potential Huge challenge The decisions faced with multiple cores How we are using multiple cores Four cores is more than twice as interesting as two cores
Challenges Games always want 100% CPU utilization
Challenges Games always want 100% CPU utilization Games are inherently serial
Challenges Games always want 100% CPU utilization Games are inherently serial Decades of experience in single threaded optimization
Challenges Games always want 100% CPU utilization Games are inherently serial Decades of experience in single threaded optimization Millions of lines of code written for single threading
Strategies Threading model Threading framework Application of cores
Theading Models Single threading Coarse threading Fine grained threading Hybrid threading
Single threading Easy Obsolete
Coarse threading Put whole systems on cores Pretty easy, “multiple single threads” Stay partially serialized, or double buffer
Coarse threading: Early experimentation Client User input Rendering Graphics simulation Server AI Physics Game logic
Coarse threading: Early experimentation Experiment: run client and server each on own core
Coarse threading: Early experimentation Experiment: run client and server each on own core Benefits: forced to confront systems that are not thread safe or not thread efficient
Coarse threading: Early experimentation Experiment: run client and server each on own core Benefits: forced to confront systems that are not thread safe or not thread efficient Outcome: Can approach 2x in contrived maps
Coarse threading: Early experimentation Experiment: run client and server each on own core Benefits: forced to confront systems that are not thread safe or not thread efficient Outcome: Can approach 2x in contrived maps More like 1.2x in real single player Added latency to single player game
Coarse threading: Early experimentation Experiment: run client and server each on own core Benefits: forced to confront systems that are not thread safe or not thread efficient Outcome: Can approach 2x in contrived maps More like 1.2x in real single player Added latency to single player game Opened door to improved listen servers
Coarse threading Put whole systems on cores Pretty easy, “multiple single threads” Stay partially serialized, or double buffer Scales poorly Partially idle cores Synchronization, or lag Entirely idle cores
Fine grained threading Divide many small identical tasks across cores E.g., take a loop that updates state of 1000 objects and perform 1000/N on each core for N cores Moderate difficulty Scales well… Tricky if cost of each unit is variable Memory bandwidth Limited problem domains
Fine grained threading Leverage multicore in production tools: VMPI
Fine grained threading VVIS – Visibility calculations VRAD – Lighting calculations
Hybrid threading Performance tuned for mid-level work sharing Not splitting sets of very small operations over cores Not putting whole systems onto cores
Hybrid threading Use the appropriate tool for the job Some systems on cores (e.g. sound) Some systems split internally similar to coarse Split expensive iterations across cores fine grained Queue some work to run when a core goes idle Most difficult Scales well Maximum core utilization
Hybrid threading: Rendering Rough pipeline Build world lists Build object lists Graphical simulation (particles, ropes, sprites) Update animations Compute shadows Draw Once for every “view” Player’s POV TV monitors Water reflections Many times CPU bound
Hybrid threading: Rendering Revised pipeline Construct scene rendering lists for multiple scenes in parallel (e.g., the world and its reflection in water) Overlap graphics simulation Compute character bone transformations for all characters in all scenes in parallel Compute shadows for all characters Allow multiple threads to draw in parallel Serialize drawing operations on another core
Threading Tools Implementing Hybrid Threading Operating system: pools, synchronization Compiler extensions: OpenMP, fine threading Tailored tools Programmers solve game development problems, not threading problems
Operating system Too low level Prone to error Lots of stalling Unpredictable scheduling Unpredictable cost
Compiler extensions OpenMP Focused on fine threading Lack of control Implementation interferes
Tailored tools: Game Threading Infrastructure Custom work management system Aimed at gaming problems, intuitive for game programmers Focus on keeping cores busy Thread pool: N-1 threads for N cores Support hybrid threading Function threading Array parallelism Multiple work modes Opportunistic core utilization Queued core utilization
Tailored tools: Game Threading Infrastructure The simple thing is the worst thing “Lock-free” algorithms Never leave cores idle waiting on other cores Leverages atomic write primitives of the CPU Under the hood of all services and data structures See: http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms Example: the spatial partition
Application of cores Dual core CPUs: framerate
Application of cores Dual core CPUs: framerate Quad core CPUs: new experiences
Application of cores Dual core CPUs: framerate Quad core CPUs: new experiences Richer visuals Improved simulation Richer AI
Application of cores: Particle Simulation Not simply a GPU issue Interactivity Presence
Application of cores: Particle Simulation Use cores to run multiple particle systems in parallel Individual particle systems using multiple cores
Application of cores: Particle Simulation More complicated systems Interactive particle systems Particles with gameplay implications Like rigid body physics, reinforce consistency of world
AI Traditionally strict CPU limits Interesting combinations of minimalist algorithms “What could we do if extra CPU were given to AI?”
AI Better framerate Run AI in parallel with other systems Parallel agent execution
AI Example: Parallel Animation
AI Better framerate Increased sophistication Without hitching by asynchronously running on secondary cores