Game Engine Architecture

(Ben Green) #1
387

this reason, and/or for convenience, many game engines provide an in-game
profi ling tool of some sort.
Typically an in-game profi ler permits the programmer to annotate blocks
of code which should be timed and give them human-readable names. The
profi ler measures the execution time of each annotated block via the CPU’s
hi-res timer, and stores the results in memory. A heads-up display is provided
which shows up-to-date execution times for each code block (examples are
shown in Figure 9.10, Figure 9.11, and Figure 9.12). The display oft en provides
the data in various forms, including raw numbers of cycles, execution times
in micro-seconds, and percentages relative to the execution time of the entire
frame.


9.8.1. Hierarchical Profi ling


Computer programs writt en in an imperative language are inherently hierar-
chical—a function calls other functions, which in turn call still more functions.
For example, let’s imagine that function a() calls functions b() and c(), and
function b() in turn calls functions d(), e() and f(). The pseudocode for this
is shown below.


voida()
{
b();
c();
}

9.8. In-Game Profi ling


Figure 9.12. The timeline mode in Uncharted 2 shows exactly when various operations are
performed across a single frame on the PS3’s SPUs, GPU and PPU.

Free download pdf