Jump to content
  • entries
    945
  • comments
    5,899
  • views
    930,138

A tale of optimization


Josh

3,124 views

 Share

I'm really shocked by how fast C++ can be. iOS and Android do not support GPU skinning, so I had to implement vertex-weighted skinning on the CPU. It took about a day to get running, and then I started optimizing code.

 

My test case was an 8400 polygon model. Each vertex could be attached to as many as four bones, but most just used two or three bones. To make it more interesting, I put the vertex weighting code inside a loop so it would be performed ten times instead of once.

 

When I started, the process took 23 milliseconds. I replace OO math code with procedural (including some inline functions), reduce the number of dynamically allocated objects, and make looping code as small as possible.

 

One interesting thing I did was merging four float variables in a loop into a single float array. Instead of resetting each variable to 0 in each iteration of the loop, I did a single memcpy() from an array of zeroes I created just for this purpose.

 

Before:

position[0]=0;
position[1]=0;
position[2]=0;
sumweights=0;

 

After:

memcpy(position,nullarray,16);

 

This actually resulted in a very big speed increase!

 

The Result

By the time I was done, my stress test was executing in 4-5 milliseconds. The program now renders an 8400 skinned model at 1000 FPS, which I thought was impossible with CPU skinning.

 

We're still going to implement GPU skinning in our high-end PC renderer, but the CPU skinning will be good for mobile devices and older hardware.

 

blogentry-1-0-32614800-1343949561_thumb.jpg

  • Upvote 1
 Share

6 Comments


Recommended Comments

Awesome optimization. But won't CPU skinning still steal your cpu if you have 50 crawlers crawling round? (but then again if you have 50 of them you're probably on gpu skinning by then)

Link to comment

You wont be using this with 50 high poly characters, but it runs on everything. The opengl4 renderer will use gpu skinning.

Link to comment
Guest Red Ocktober

Posted

"I had to implement vertex-weighted skinning on the CPU. It took about a day to get running,"

 

only a day... i'm impressed... no, seriously... i'm really impressed...

 

ahhh, he's done this before though :)

 

good work...

 

--Mike

Link to comment

Great job Josh! I'm impressed, never would of thought there'd be much of a difference between procedural code and dynamically located objects....

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...