Vertex Cache Optimisation Library

2While 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:

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:

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.

3 thoughts on “Vertex Cache Optimisation Library

  1. I can’t beleive I haven’t tried this out yet. I must try a real test soon, I mean on the actual graphics card, and measure performance.

    Btw, at the test program, change the unix ifdef a bit:
    #if defined(unix) || defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))

    Unfortunately, MacOSX doesn’t define unix or __unix__. I’m testing for both __APPLE__ and __MACH__ since I guess that __APPLE__ alone would also be defined for MacOS <=9 which is definitely *not* UNIX, but apple in conjuction with the mach microkernel definitely means OSX.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s