Thursday, January 19, 2006

The Crayon Rule

Quick note: the region system will go in a later version of X-Plane, not 8.30. It's coming soon though! I will try to post a spec soon...I am way behind on my documentation.

Anyway, the "Crayon Rule": the worst thing you can do for frame-rate in X-Plane is change textures.

The name comes from a conversation almost three years ago when Austin explained to Sergio the cost of changing textures like this: drawing in OpenGL is like drawing with a crayon. Changing textures is like going back and getting a different crayon. It's a lot faster to do all the red in your picture and not have to change between red and blue crayons all the time.

The crayon rule continues to hold true and it's understandable why:
  • The texture you are using to draw is usually in VRAM. But the texture you are changing to could be in physical RAM (and must be transferred to the card), or worse it could have been paged out and must come from disk.
  • The drawing pipeline must be stopped and reconfigured with the texture change.
  • These things involve the host machine and CPU. Graphics cards are getting faster but CPUs are not - at least not much faster. So while the new graphics cards will be able to draw twice as many triangles, they will not be able to change textures twice as fast. In other words, we're stuck with the crayon rule for a long time.
The crayon rule is why Austin and I insist on using one texture per object, and always recommend that you use a few large textures rather than many smaller ones. Fewer textures means fewer texture changes.

So the big things you can do as an author to obey the crayon rule are:
  • Use fewer large textures instead of many small ones.
  • Group your polygons that use the panel texture together - switching to the panel texture is a crayon change.
The crayon rule makes it more difficult to make scenery, but that extra effort has a huge payoff in framerate.

No comments: