Game Development Reference
In-Depth Information
Video Memory (VRAM)
Video RAM is the memory installed on your video card, unless we
re talking about an
Xbox. Xbox hardware has unified memory architecture (or UMI), so there
'
s no differ-
ence between system RAM and VRAM. It would be nice if the rest of the world
worked that way. Other hardware, such as the Intel architecture, must send any data
between VRAM and system RAM over a bus. The PS3 has even more different kinds
of memory. There are quite a few bus architectures and speeds out there, and it is wise
to understand how reading and writing data across the bus affects your game
'
'
sspeed.
As long as the CPU doesn
t have to read from VRAM, everything clicks along pretty
fast. If you need to grab a piece of VRAM for something, the bits have to be sent
across the bus to system RAM. Depending on your architecture, your CPU and
GPU must argue for a moment about timing, stream the bits, and go their separate
ways. While this painful process is occurring, your game has come to a complete halt.
This problem was pretty horrific back in the days of fixed function pipelines when
anything not supported by the video card had to be done with the CPU, such as
the first attempts at motion blur. With programmable pipelines, you can create shad-
ers that can run directly on the bits stored in VRAM, making this kind of graphical
effect extremely efficient.
The hard disk can
'
'
t write straight to VRAM, so every time a new texture is needed,
you
ll need to stop the presses, so to speak. The smart approach is to limit any com-
munication needed between the CPU and the video card. If you are going to send
anything to it, it is best to send it in batches.
If you
'
ll realize that the GPU in your video card is sim-
ply painting the screen using the components in VRAM. If it ever has to stop and ask
system RAM for something, your game won
'
ve been paying attention, you
'
'
t run as fast as it could.
Optimizing Memory Access
Every access to system RAM uses a CPU cache. If the desired memory location is
already in the cache, the contents of the memory location are presented to the CPU
extremely quickly. If, on the other hand, the memory is not in the cache, a new block
of system RAM must be fetched into the cache. This takes a lot longer than you
'
d
think.
A good test bed for this problem uses multidimensional arrays. C++ defines its arrays
in row major order. This ordering puts the members of the right-most index next to
each other in memory.
TestData[0][0][0] and TestData[0][0][1] are stored in adjacent memory
locations.
 
 
Search WWH ::




Custom Search