Vertex Cache Optimisation Library

July 28, 2009
Embroidery Sample

Image by kotog via Flickr

While working hard to make sure Conspiracies 2 is ready in time, I could not resist the temptation to tweak and optimize rendering a little more. This time I experimented with vertex cache optimizations and came up with a small piece of code that I thought it would be nice to share with the coders out there, since it is self-contained and easy to use.

The library consists of a single header file that -at least in theory- can be used with any C++ compiler, though it was only tested with visual studio (edit: gcc works as well, of course). It implements the algorithm descibed at:

http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html

Its usage is extremely simple: just initialize a VertexCacheOptimizer object and call the member function “Optimize”, passing your index buffer and triangle count.

Download the code from:

http://code.google.com/p/vcacne/

The downloadable archive contains documentation and a small test-benchmark program.

My results for optimizing generated plane meshes are very consistent (my CPU is a Athlon 64 x2 4400+ running at 2.22 GHz):

  • 143 nanoseconds per triangle
  • resulting ACMR of ~0.63 (0.63 cache misses per triangle)

The algorithm indeed runs in linear time. I always got 143 nper triangle no matter how large or small meshes I used.

Have some fun with it. Any kind of feedback is welcome. I am particularly interested in your benhmarking results and/or comparisons with other vertex cache optimizers.

Edit (18/10/2010) : Also tested with gcc. Not only it compiles, but its a lot faster. On the same system I get 22 nsec per triangle.


Follow

Get every new post delivered to your Inbox.