Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sim, Render, Repeat An Analysis of Game Loop Architectures Daniel Martin and Michael Balfour March 23, 2006.

Similar presentations


Presentation on theme: "Sim, Render, Repeat An Analysis of Game Loop Architectures Daniel Martin and Michael Balfour March 23, 2006."— Presentation transcript:

1 Sim, Render, Repeat An Analysis of Game Loop Architectures Daniel Martin and Michael Balfour March 23, 2006

2 “Who?” Introduction

3 Introduction: The Speakers  Technical directors at EA-Tiburon  MS degrees  7+ years in the game industry  Exposed to many games and architecture Also programmed on Apple ][’s and mainframes

4 Introduction: Motivation  Hidden complexities  Little coverage  Highest-level game architecture

5 Introduction: Agenda  Definitions  Timeline  Architecture decisions  Case study  Questions Slides will be made available on the GDC website

6 “What?” Game loop architectures defined

7 Definition: Background  Source Code  Digger  Duke3D  Freespace2  Harry Potter  Madden  Books  3D Game Engine Architecture, First Edition  Core Techniques and Algorithms in Game Programming  Game Coding Complete, Second Edition  NASCAR  Popcap Engine  Quake2  Unreal Tournament v432  Wumpus

8 Definition: Pseudocode pattern GameLoop() { Startup(); while (!done) { GetInput(); Sim(); Render(); } Shutdown(); }

9 Definition: Formal  Game Loop  A thread of execution consisting of  a startup phase,  a looping phase that processes inputs/outputs,  a shutdown phase.  We use “Game Loop” and “Loop” interchangeably

10 Definition: Formal  Video Game  A collection of one or more game loops processing inputs and outputs for entertainment purposes.

11 Definition: Formal  Game Loop Architecture  An architecture consisting of one or more game loops and the infrastructure to manage their execution and dependencies.

12 “When?” Game Loop Timeline

13 1947: Cathode Ray Tube Amusement Device  First patented video game  Game: Fire a missile at a target  Hardware loop run by master clock CRT Amusement Device Gypsy Juggler Genesis Saturn MHz Barrier Noughts and Crosses Gun Fight

14 1952: Noughts and Crosses  First software-based game  Game: Tic Tac Toe  Software loop CRT Amusement Device Gypsy Juggler Genesis Saturn MHz Barrier Noughts and Crosses Gun Fight

15 : Analysis  Game loops have existed for 50+ years  We still use the same game loop patterns today  Seems to be the most intuitive architecture for games  Hardware and software loops  Independently developed  Similar results

16 1975: Gun Fight  First CPU-based arcade video game  Game: Two players shoot at each other  Software Sim loop  Hardware Render and Audio loops CRT Amusement Device Gypsy Juggler Genesis Saturn MHz Barrier Noughts and Crosses Gun Fight

17 1978: Gypsy Juggler  First multi-CPU game  Game: Move a gypsy and juggle eggs  Concurrent Software Sim/Audio loops  Two symmetric S2650 CPUs CRT Amusement Device Gypsy Juggler Genesis Saturn MHz Barrier Noughts and Crosses Gun Fight

18 : Analysis  Multi-CPU arcade games have existed for 28+ years  Multi-CPU common in arcade games  Typically 2-3 CPUs  Common use of specialized processors  Moved hardware Render/Audio Loops to software

19 1988: Genesis  First multi-CPU console  CPU for Sim/Render  Z80 CPU for Audio CRT Amusement Device Gypsy Juggler Genesis Saturn MHz Barrier Noughts and Crosses Gun Fight

20 1994: Saturn  First symmetric Multi-CPU console  Two Hitachi RISC processors  6 processors for video/sound/control CRT Amusement Device Gypsy Juggler Genesis Saturn MHz Barrier Noughts and Crosses Gun Fight

21 : Analysis  Multi-CPU Consoles have existed for 18+ years  Many consoles with asymmetric CPUs  Few consoles with symmetric CPUs  “One very fast central processor would be preferable… I think only one out of 100 programmers is good enough to get that kind of speed out of the Saturn.” – Yu Suzuki

22 2003: MHz Barrier CPU frequency CRT Amusement Device Gypsy Juggler Genesis Saturn MHz Barrier Noughts and Crosses Gun Fight Year MHz

23 : Analysis  Paradigm Shift  “The Free Lunch is Over”  Parallel by necessity  Legacy code won’t run magically faster  More performance requires mastering concurrency  Single CPU no longer the norm

24 “How?” Game Loop Architecture Decisions

25 Architecture: Game loop complexity Complexity Time Concurrency Coupling

26 Architecture: Game loop complexity Time Concurrency Coupling Complexity

27 Architecture: Time  Problem  Running smoothly in real-time  Solution  Frequency-Driven Game Loop  Divide time into discrete iterations  Attempt to run “fast enough” and “smooth enough”  Consequence  Each Loop iteration is a time slice

28 Architecture: Time  Challenge  How to maintain a loop frequency with variable execution time  Factors  Performance  Tolerance  Architecture Decisions  Scheduling  Time Step  Determinism  Simplicity

29 Architecture: Time  Scheduling  Controls when a loop iteration starts Scheduling ImmediateBest-FitAligned

30 Architecture: Legend  Time Axis  Real time  Ticks at desired frequency  Box  Loop iteration  Length is processing time  Arrows  Time step  Length is simulated time  Data  Data used by a loop Time

31 Architecture: Time  Description  “As fast as it can”  Factors + Performance - Tolerance Determinism + Simplicity Time Exact Faster Slower Varied Scheduling Immediate

32 Architecture: Example  Early adventure games while (1) { GetInput(); Sim(); Render(); } Time Scheduling: Immediate

33 Architecture: Time  Description  “Averaging”  Tries to  Maintain frequency  Start at exact times  Catch up  Factors + Performance + Tolerance Determinism - Simplicity Scheduling Best-Fit Time Exact Faster Slower Varied

34 Architecture: Time  Description  “VSynced”  Factors - Performance - Tolerance Determinism + Simplicity Time Exact Faster Slower Varied Scheduling Aligned

35 Architecture: Time  Time Step  Controls interpretation of time  “Simulated” time Time Step NoneFixed-ValueReal-Time

36 Architecture: Time  Description  Ignores time  Factors Performance Tolerance + Determinism + Simplicity Time Exact Faster Slower Varied Time Step None

37 Architecture: Time  Description  Time step always constant  Factors Performance - Tolerance + Determinism - Simplicity Time Exact Faster Slower Varied Time Step Fixed-Value

38 Architecture: Example  Deterministic real-time games const float TIMESTEP = 1 / 60.0f; while (1) { curTime = GetTime(); if ((curTime – lastTime) >= TIMESTEP) { Sim(TIMESTEP); lastTime = curTime; } Best-Fit Fixed-Value Time Scheduling: Time Step:

39 Architecture: Example  Early PC games, assumed CPU bottleneck const float TIMESTEP = 1 / 60.0f; while (1) { Sim(TIMESTEP); } Time Scheduling: Time Step: Immediate Fixed-Value

40 Architecture: Time  Description  Sim Time == Real Time  Factors Performance + Tolerance - Determinism - Simplicity Time Exact Faster Slower Varied Time Step Real-Time

41 Architecture: Example  Interpolating Render loop, aligned to VSync while (1) { WaitForVSync(); curTime = GetTime(); step = curTime – lastTime; Clamp(step, 0, MAX_STEP); Render(step); lastTime = curTime; } Time Scheduling: Time Step: Aligned Real-Time

42 Architecture: Game Loop Complexity Time Concurrency Coupling Complexity

43 Architecture: Coupling  Problem  Supporting systems at different frequencies  Solution  Multiple game loops  Consequence  Loop Coupling  Dependencies between every pair of loops

44 Architecture: Coupling  Challenge  How to split code and data into multiple loops  Factors  Performance  Tolerance  Simplicity  Architecture Decisions  Frequency Coupling  Data Coupling  Video Modes  Memory  Scalability

45 Architecture: Coupling  Frequency  How much a loop relies on another’s frequency Frequency EqualMultipleDecoupled

46 Architecture: Coupling  Description  1:1  “Lockstep”  Factors - Video modes + Memory Performance - Tolerance - Scalability + Simplicity Time (Loop 2) Time (Loop 1) Frequency Equal

47 Architecture: Coupling  Description  N:1  Multiple of frequency  60 Hz  30 Hz  Factors - Video modes + Memory Performance - Tolerance - Scalability + Simplicity Time (Loop 2) Time (Loop 1) Frequency Multiple

48 Architecture: Coupling  Description  N:M  Two independent rates  Factors + Video modes - Memory Performance + Tolerance + Scalability - Simplicity Time (Loop 2) Time (Loop 1) Frequency Decoupled

49 Architecture: Example  Decoupled Sim and Render loops while (1) { time = GetTime() if ((time – lastTime) >= SIM_STEP) { Sim(SIM_STEP); lastTime = time; } while (1) { Render(RENDER_STEP); WaitForVSync(); } Scheduling: Time Step: Frequency: Aligned Fixed-Value Decoupled Best-Fit Fixed-Value Decoupled Scheduling: Time Step: Frequency:

50 Architecture: Coupling  Data Coupling  The amount and method of sharing data Data Coupling TightLooseNone

51 Architecture: Coupling  Description  Data structure reliance  Factors Video modes + Memory + Performance Tolerance - Scalability - Simplicity Data Coupling Tight

52 Architecture: Coupling  Description  Formalized data passing  Factors Video modes - Memory - Performance Tolerance + Scalability + Simplicity Data Coupling Loose

53 Architecture: Example  Sim at 60 Hz, Render at 50 Hz Scheduling: Time Step: Frequency: Data Coupling: Aligned N/A Decoupled Loose Scheduling: Time Step: Best-Fit N/A

54 Architecture: Coupling  Description  Fully independent  No data passing  Factors Video modes + Memory + Performance Tolerance + Scalability + Simplicity Data Coupling None

55 Architecture: Game loop complexity Time Concurrency Coupling Complexity

56 Architecture: Concurrency  Problem  Hardware makers need cutting edge performance  Solution  Hardware contains multiple CPUs  Consequence  Concurrency  Mapping between game loops and CPUs

57 Architecture: Concurrency  Challenge  How to manage simultaneous execution  Factors  Performance  Simplicity  Scalability  Architecture Decisions  Low-Level Concurrency  High-Level Concurrency

58 Architecture: Concurrency  Low-Level  Parallelism within a game loop Low-Level NoneInstructionFunctions

59 Architecture: Concurrency  Low-Level  Covered extensively  Easiest transition to NextGen  Start small and grow  OpenMP  “Bottom up” approach  Can be postponed

60 Architecture: Concurrency  High-Level  Parallelism across a pair of game loops High-Level SequentialInterleavedParallel

61 Architecture: Concurrency  Description  No overlap of loop execution  Factors - Performance - Scalability + Simplicity Time Sequential Exact Varied High-Level

62 Architecture: Concurrency  Description  Loops iterate in parallel  Sequential at instruction level  Concurrency on 1 CPU  Factors - Performance + Scalability - Simplicity Time Exact Varied Interleaved High-Level

63 Architecture: Concurrency  Description  Instructions execute at same time  Factors + Performance + Scalability - Simplicity Time Exact Varied Parallel High-Level

64 “Why?” Case Study

65 Case Study: Madden Xbox vs Madden X360 VS

66 Case Study: Madden Xbox vs Madden X360 Sim Render Audio Render Audio Sim Scheduling ImmediateBest-FitAligned

67 Case Study: Madden Xbox vs Madden X360 Audio Sim Render Sim Render Audio Time Step NoneFixed-ValueReal-Time

68 Case Study: Madden Xbox vs Madden X360 Sim-Render Sim-Audio Render-Audio Sim-Audio Render-Audio Frequency Coupling EqualMultipleDecoupled

69 Case Study: Madden Xbox vs Madden X360 Render-Audio Sim-Render Sim-Audio Sim-Render Sim-Audio Data Coupling TightLooseNone

70 Case Study: Madden Xbox vs Madden X360 Sim Render Audio Sim Render Audio Low-Level Concurrency NoneInstructionFunctions

71 Case Study: Madden Xbox vs Madden X360 Sim Render Audio Sim Render Audio High-Level Concurrency SequentialInterleavedParallel

72 “!” Conclusion

73  Hidden complexities  Make key architecture decisions early  Our decisions  Use multiple game loops  Decouple data

74 “???” Questions? Slides, speaker notes and references available

75 “Where?” References

76 References: Literature  Game Loops in Literature  “3D Game Engine Architecture, First Edition”, David Eberly  on on  “Core Techniques and Algorithms in Game Programming”, Daniel Sanchez-Crespo   “Game Coding Complete, Second Edition”, Mike McShaffry   Task Manager Papers  “Game Engineering for a Multiprocessor Architecture”, Abdennour El Rhalibi, Dave England, and Steven Costa   “Compositional Constraints Generation for Concurrent Real-Time Loops with Interdependent Iterations”, I. Assayad and S. Yovine   “Hierarchical Finite State Machines with Multiple Concurrency Models”, Alain Girault, Bilung Lee, and Edward A. Lee 

77 References: Video Game History  “Patent # : Cathode Ray Tube Amusement Device”, Thomas Goldsmith Jr and Estle Ray Mann   “PONG-Story”, David Winter   “The Edsac Simulator”, Martin Campbell-Kelly   “The First Video Game”, Brookhaven National Laboratory   “Gun Fight”, Midway Mfg. Co.   “Atari Jaguar”, Wikipedia   “SEGA SATURN F.A.Q.”, John Hokanson Jr. 

78 References: Concurrency  “The Free Lunch is Over: A Fundamental Turn Toward Concurrency in Software”, Herb Sutter   “Software and the Concurrency Revolution”, Herb Sutter and James Larus   “Debugging Concurrency”, Philippe Paquet   “Real-World Case Studies: Threading Games for High Performance on Intel Processors”, Sara Sarmiento   “Trials and Tribulations of Debugging Concurrency”, Kang Su Gatlin   “Software Challenges in Nanoscale Technologies”, James Larus   “Threading 3D Game Engine Basics”, Henry Gabb and Adam Lake   “Compiler Technology for Scalable Architectures”, Alexandre E. Eichenberger, Kevin O’Brien, and Kathryn O’Brien   “The Next Mainstream Programming Language: A Game Developer’s Perspective”, Tim Sweeney 

79 References: Public Source Code  “Digger”, Windmill Software   “Duke Nukem 3D Source Code”, 3D Realms   “ Freespace2 Source Code”, Volition Software   “PopCap Engine”, PopCap Games   “Quake II Source Code”, Id Software   “Unreal Tournament v432 Source Code”, Epic Games   “Wumpus 1”, Gregory Yob 


Download ppt "Sim, Render, Repeat An Analysis of Game Loop Architectures Daniel Martin and Michael Balfour March 23, 2006."

Similar presentations


Ads by Google