How are 3D games so efficient?

jmasterx picture jmasterx · Feb 7, 2010 · Viewed 8.6k times · Source

There is something I have never understood. How can a great big PC game like GTA IV use 50% of my CPU and run at 60fps while a DX demo of a rotating Teapot @ 60fps uses a whopping 30% ?

Answer

zebrabox picture zebrabox · Feb 7, 2010

Patience, technical skill and endurance.

First point is that a DX Demo is primarily a teaching aid so it's done for clarity not speed of execution.

It's a pretty big subject to condense but games development is primarily about understanding your data and your execution paths to an almost pathological degree.

  1. Your code is designed around two things - your data and your target hardware.
  2. The fastest code is the code that never gets executed - sort your data into batches and only do expensive operations on data you need to
  3. How you store your data is key - aim for contiguous access this allows you to batch process at high speed.
  4. Parellise everything you possibly can
  5. Modern CPUs are fast, modern RAM is very slow. Cache misses are deadly.
  6. Push as much to the GPU as you can - it has fast local memory so can blaze through the data but you need to help it out by organising your data correctly.
  7. Avoid doing lots of renderstate switches ( again batch similar vertex data together ) as this causes the GPU to stall
  8. Swizzle your textures and ensure they are powers of two - this improves texture cache performance on the GPU.
  9. Use levels of detail as much as you can -- low/medium/high versions of 3D models and switch based on distance from camera player - no point rendering a high-res version if it's only 5 pixels on screen.