Sunday, March 28, 2010

Strangest Optimization Ever

The Draw_Character function has turned out to be a major performance bottleneck. I discovered this during my VMware tests of DirectQ on Windows 2000 and XP, when bringing down the console (or bringing up a menu) would drag framerates down into single digits.

Now, the VMware display driver is obviously not intended for serious game performance (although while it sucks at D3D it is quite good at OpenGL), but one thing that a low performer is great for doing is identifying trouble spots like this. If you test on high performance hardware everything is going to run fast anyway so you'll never know!

Of course it was necessary to confirm that this actually was Draw_Character at fault, and not some weird aberrant extra calls to SCR_UpdateScreen during the console drawing, so the simple thing was to just comment out the function body and see what happened.

The optimization then consisted of batching up characters (for bonus points I did all the other 2D stuff too) so that multiple polygons could be drawn in a single pass. The definitive confirmation was when I tested this on the same setup and got no speed drops.

The real culprit seems to have been my use of Triangle Fan primitive types. Even switching these to Triangle Lists, at the cost of 2 extra vertexes per Quad, was a major performance boost, and the few places remaining where I still have Fans still give the same speed drop as before. The next step is to take one of those, switch it to a List, and see what happens.

All in all it's been interesting stuff, with a good end result to show for it.

0 comments: