+ All Categories
Home > Documents > Sim, Render, Repeat An Analysis of Game Loop Architectures Daniel Martin and Michael Balfour March...

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

Date post: 15-Dec-2015
Category:
Upload: lena-hayhurst
View: 221 times
Download: 0 times
Share this document with a friend
Popular Tags:
74
Sim, Render, Repeat An Analysis of Game Loop Architectures Daniel Martin and Michael Balfour March 23, 2006
Transcript

Sim, Render, Repeat

An Analysis of Game Loop Architectures

Daniel Martin and Michael BalfourMarch 23, 2006

“Who?”

Introduction

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

Introduction: Motivation

Hidden complexities

Little coverage

Highest-level game architecture

Introduction: Agenda

Definitions

Timeline

Architecture decisions

Case study

Questions

Slides will be made available on the GDC website

“What?”

Game loop architectures defined

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

Definition: Pseudocode pattern

GameLoop(){

Startup();

while (!done) {

GetInput(); Sim(); Render();

}

Shutdown();}

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

“When?”

Game Loop Timeline

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 BarrierNoughts and

Crosses

Gun Fight

1952: Noughts and Crosses

First software-based game

Game: Tic Tac Toe

Software loop

CRT Amusement Device

Gypsy Juggler

Genesis

Saturn

MHz BarrierNoughts and

Crosses

Gun Fight

1940-1970: 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

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 BarrierNoughts and

Crosses

Gun Fight

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 BarrierNoughts and

Crosses

Gun Fight

1970-1980: 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

1988: Genesis

First multi-CPU console

68000 CPU for Sim/Render

Z80 CPU for Audio

CRT Amusement Device

Gypsy Juggler

Genesis

Saturn

MHz BarrierNoughts and

Crosses

Gun Fight

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 BarrierNoughts and

Crosses

Gun Fight

1980-2000: 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

2003: MHz Barrier

0

500

1000

1500

2000

2500

3000

3500

4000

95 96 97 98 99 00 01 02 03 04 05 06

Intel

Amd

CPU frequency 1995-2006

CRT Amusement Device

Gypsy Juggler

Genesis

Saturn

MHz BarrierNoughts and

Crosses

Gun Fight

Year

MH

z

2000-2006: 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

“How?”

Game Loop Architecture Decisions

Architecture: Game loop complexity

ComplexityTime

Concurrency

Coupling

Architecture: Game loop complexity

Time

Concurrency

Coupling

Complexity

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

Architecture: Time

Challenge

How to maintain a loop frequency with variable execution time

Factors

Performance

Tolerance

Architecture Decisions

Scheduling

Time Step

Determinism

Simplicity

Architecture: Time

Scheduling

Controls when a loop iteration starts

Scheduling

Immediate Best-Fit Aligned

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

Architecture: Time

Description

“As fast as it can”

Factors

+ Performance

- Tolerance

Determinism

+ Simplicity

Time

Exact

Faster

Slower

Varied

Scheduling

Immediate

Architecture: Example

Early adventure games

while (1){ GetInput(); Sim(); Render();}

Time

Scheduling: Immediate

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

Architecture: Time

Description

“VSynced”

Factors

- Performance

- Tolerance

Determinism

+ Simplicity

Time

Exact

Faster

Slower

Varied

Scheduling

Aligned

Architecture: Time

Time Step

Controls interpretation of time

“Simulated” time

Time Step

None Fixed-Value Real-Time

Architecture: Time

Description

Ignores time

Factors

Performance

Tolerance

+ Determinism

+ Simplicity

Time

Exact

Faster

Slower

Varied

Time Step

None

Architecture: Time

Description

Time step always constant

Factors

Performance

- Tolerance

+ Determinism

- Simplicity

Time

Exact

Faster

Slower

Varied

Time Step

Fixed-Value

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-FitFixed-Value

Time

Scheduling:Time Step:

Architecture: Time

Description

Sim Time == Real Time

Factors

Performance

+ Tolerance

- Determinism

- Simplicity

Time

Exact

Faster

Slower

Varied

Time Step

Real-Time

Architecture: Game Loop Complexity

Time

Concurrency

Coupling

Complexity

Architecture: Coupling

Problem

Supporting systems at different frequencies

Solution

Multiple game loops

Consequence

Loop Coupling

Dependencies between every pair of loops

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

Architecture: Coupling

Frequency

How much a loop relies on another’s frequency

Frequency

Equal Multiple Decoupled

Architecture: Coupling

Description

1:1

“Lockstep”

Factors

- Video modes

+ Memory

Performance

- Tolerance

- Scalability

+ Simplicity Time (Loop 2)

Time (Loop 1)

Frequency

Equal

Architecture: Coupling

Description

N:1

Multiple of frequency

Sim @ 60 Hz

Render @ 30 Hz

Factors

- Video modes

+ Memory

Performance

- Tolerance

- Scalability

+ Simplicity

Time (Loop 2)

Time (Loop 1)

Frequency

Multiple

Architecture: Coupling

Description

N:M

Two independent rates

Factors

+ Video modes

- Memory

Performance

+ Tolerance

+ Scalability

- Simplicity

Time (Loop 2)

Time (Loop 1)

Frequency

Decoupled

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:

Architecture: Coupling

Data Coupling

The amount and method of sharing data

Data Coupling

Tight Loose None

Architecture: Coupling

Description

Data structure reliance

Factors

Video modes

+ Memory

+ Performance

Tolerance

- Scalability

- Simplicity

Data Coupling

Tight

Architecture: Coupling

Description

Formalized data passing

Factors

Video modes

- Memory

- Performance

Tolerance

+ Scalability

+ Simplicity

Data Coupling

Loose

Architecture: Coupling

Description

Fully independent

No data passing

Factors

Video modes

+ Memory

+ Performance

Tolerance

+ Scalability

+ Simplicity

Data Coupling

None

Architecture: Game loop complexity

Time

Concurrency

Coupling

Complexity

Architecture: Concurrency

Problem

Hardware makers need cutting edge performance

Solution

Hardware contains multiple CPUs

Consequence

Concurrency

Mapping between game loops and CPUs

Architecture: Concurrency

Challenge

How to manage simultaneous execution

Factors

Performance

Simplicity

Scalability

Architecture Decisions

Low-Level Concurrency

High-Level Concurrency

Architecture: Concurrency

Low-Level

Parallelism within a game loop

Low-Level

None Instruction Functions

Architecture: Concurrency

Low-Level

Covered extensively

Easiest transition to NextGen

Start small and grow

OpenMP

“Bottom up” approach

Can be postponed

Architecture: Concurrency

High-Level

Parallelism across a pair of game loops

High-Level

Sequential Interleaved Parallel

Architecture: Concurrency

Description

No overlap of loop execution

Factors

- Performance

- Scalability

+ Simplicity

Time

Sequential

Exact

Varied

High-Level

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

Architecture: Concurrency

Description

Instructions execute at same time

Factors

+ Performance

+ Scalability

- Simplicity

Time

Exact

Varied

Parallel

High-Level

“Why?”

Case Study

Case Study: Madden Xbox vs Madden X360

VS

Case Study: Madden Xbox vs Madden X360

SimRender

Audio

RenderAudio

Sim

Scheduling

Immediate Best-Fit Aligned

Case Study: Madden Xbox vs Madden X360

AudioSim

Render

Sim RenderAudio

Time Step

None Fixed-Value Real-Time

Case Study: Madden Xbox vs Madden X360

Sim-Render

Sim-RenderSim-Audio

Render-Audio

Sim-AudioRender-Audio

Frequency Coupling

Equal Multiple Decoupled

Case Study: Madden Xbox vs Madden X360

Render-Audio

Render-AudioSim-RenderSim-Audio

Sim-Render Sim-Audio

Data Coupling

Tight Loose None

Case Study: Madden Xbox vs Madden X360Sim

RenderAudio

SimRenderAudio

Low-Level Concurrency

None Instruction Functions

Case Study: Madden Xbox vs Madden X360

SimRender

Audio

SimRender Audio

High-Level Concurrency

Sequential Interleaved Parallel

“!”

Conclusion

Conclusion

Hidden complexities

Make key architecture decisions early

Our decisions

Use multiple game loops

Decouple data

“???”

Questions?

Slides, speaker notes and references available

http://www.gdconf.com

“Where?”

References

References: Literature

Game Loops in Literature

“3D Game Engine Architecture, First Edition”, David Eberly http://www.elsevier.com/wps/find/bookdescription.cws_home/704123/description#des

cription

“Core Techniques and Algorithms in Game Programming”, Daniel Sanchez-Crespo

http://www.novarama.com/users/dani/docs/book/index-en.shtml

“Game Coding Complete, Second Edition”, Mike McShaffry http://www.mcshaffry.com/GameCode/

Task Manager Papers

“Game Engineering for a Multiprocessor Architecture”, Abdennour El Rhalibi, Dave England, and Steven Costa

http://www.gamesconference.org/digra2005/papers/a4458b374e5b16f16e725fdbeed4.doc

“Compositional Constraints Generation for Concurrent Real-Time Loops with Interdependent Iterations”, I. Assayad and S. Yovine

http://www-verimag.imag.fr/~yovine/articles/i2cs05.pdf

“Hierarchical Finite State Machines with Multiple Concurrency Models”, Alain Girault, Bilung Lee, and Edward A. Lee

http://ptolemy.eecs.berkeley.edu/papers/99/starcharts/starcharts.pdf

References: Video Game History

“Patent #2455992: Cathode Ray Tube Amusement Device”, Thomas Goldsmith Jr and Estle Ray Mann

http://www.pong-story.com/2455992.pdf

“PONG-Story”, David Winter

http://www.pong-story.com/intro.htm

“The Edsac Simulator”, Martin Campbell-Kelly

http://www.dcs.warwick.ac.uk/~edsac/

“The First Video Game”, Brookhaven National Laboratory

http://www.bnl.gov/bnlweb/history/higinbotham.asp

“Gun Fight”, Midway Mfg. Co.

http://www.arcadedocs.com/vidmanuals/G/gunfight_2.pdf

“Atari Jaguar”, Wikipedia

http://en.wikipedia.org/wiki/Atari_Jaguar#Technical_specifications

“SEGA SATURN F.A.Q.”, John Hokanson Jr.

http://www.classicgaming.com/saturn/content/vault/faqs/saturn/system/saturnfaqb.txt

References: Concurrency

“The Free Lunch is Over: A Fundamental Turn Toward Concurrency in Software”, Herb Sutter

http://www.gotw.ca/publications/concurrency-ddj.htm

“Software and the Concurrency Revolution”, Herb Sutter and James Larus

http://www.acmqueue.org/modules.php?name=Content&pa=showpage&pid=332&page=1

“Debugging Concurrency”, Philippe Paquet

http://www.gamasutra.com/features/20050606/paquet_01.shtml

“Real-World Case Studies: Threading Games for High Performance on Intel Processors”, Sara Sarmiento

http://cache-www.intel.com/cd/00/00/20/40/204080_204080.pdf

“Trials and Tribulations of Debugging Concurrency”, Kang Su Gatlin

http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=226

“Software Challenges in Nanoscale Technologies”, James Larus

http://research.microsoft.com/~larus/Talks/CRA%20Architecture%20Challenge.ppt

“Threading 3D Game Engine Basics”, Henry Gabb and Adam Lake

http://www.gamasutra.com/features/20051117/gabb_01.shtml

“Compiler Technology for Scalable Architectures”, Alexandre E. Eichenberger, Kevin O’Brien, and Kathryn O’Brien

http://domino.research.ibm.com/comm/research_projects.nsf/pages/cellcompiler.index.html

“The Next Mainstream Programming Language: A Game Developer’s Perspective”, Tim Sweeney

http://www.cs.princeton.edu/~dpw/popl/06/Tim-POPL.ppt

References: Public Source Code

“Digger”, Windmill Software

http://www.digger.org/download.html

“Duke Nukem 3D Source Code”, 3D Realms

http://www.3drealms.com/downloads.html

“Freespace2 Source Code”, Volition Software

http://www.gamespot.com/pc/sim/freespace2/download.html?sid=2862847

“PopCap Engine”, PopCap Games

http://developer.popcap.com/

“Quake II Source Code”, Id Software

http://www.idsoftware.com/business/techdownloads/

“Unreal Tournament v432 Source Code”, Epic Games

http://www.fileshack.com/file.x?fid=308

“Wumpus 1”, Gregory Yob

http://www.atariarchives.org/morebasicgames/showpage.php?page=178


Recommended