Game Engine Architecture

(Ben Green) #1

104 3. Fundamentals of Software Engineering for Games


is performed on multiple quantities in parallel, using a single machine in-
struction. In order to be processed by the vector unit, two or more quanti-
ties are packed into a 64- or 128-bit CPU register. In game programming,
the most commonly used SIMD register format packs four 32-bit IEEE-754
fl oating-point quantities into a 128-bit SIMD register. This format allows us to
perform calculations such as vector dot products and matrix multiplications
much more effi ciently than would be possible with a SISD (single instruction,
single data) ALU.
Each microprocessor has a diff erent name for its SIMD instruction set,
and the compilers that target those microprocessors use a custom syntax to
declare SIMD variables. For example, on a Pentium class CPU, the SIMD in-
struction set is known as SSE (streaming SIMD extensions), and the Microsoft
Visual Studio compiler provides the built-in data type __m128 to represent a
four-fl oat SIMD quantity. The PowerPC class of CPUs used on the PLAYSTA-
TION 3 and Xbox 360 calls its SIMD instruction set Altivec, and the Gnu C++
compiler uses the syntax vector float to declare a packed four-fl oat SIMD
variable. We’ll discuss how SIMD programming works in more detail in Sec-
tion 4.7.

Portable Sized Types
Most other compilers have their own “sized” data types, with similar seman-
tics but slightly diff erent syntax. Because of these diff erences between compil-
ers, most game engines achieve source code portability by defi ning their own
custom atomic data types. For example, at Naughty Dog we use the following
atomic types:
z F32 is a 32-bit IEEE-754 fl oating-point value.
z U8, I8, U16, I16, U32, I32, U64, and I64 are unsigned and signed 8-,
16-, 32-, and 64-bit integers, respectively.
z U32F and I32F are “fast” unsigned and signed 32-bit values, respec-
tively. Each of these data types acts as though it contains a 32-bit value,
but it actually occupies 64 bits in memory. This permits the PS3’s cen-
tral PowerPC-based processor (called the PPU) to read and write these
variables directly into its 64-bit registers, providing a signifi cant speed
boost over reading and writing 32-bit variables.
z VF32 represents a packed four-fl oat SIMD value.

OGRE ’s Atomic Data Types
OGRE defi nes a number of atomic types of its own. Ogre::uint8, Ogre::
uint16 and Ogre::uint32 are the basic unsigned sized integral types.
Free download pdf