Tag Archives: c#

Profiling XNA Level loading times using Slimtune

Work has started on a small internal project that may turn into a game once some of the edges are smoothed off. The game features some maps that are produced on the CPU. This process on the PC takes a few seconds but on an XBOX it takes a few minutes!

Why is this? Time to start profiling.

One lesson I have definitely learnt over the years is profile first and then optimise your algorithms. Do it that way around. Profiling can definitely throw up some counter intuitive results.

My actual frame rate is fine (60 Hz locked to refresh) on both PC and XBOX.

I’m using slimtune which has some pretty good features – lets see how it does. http://code.google.com/p/slimtune/

I’m starting the profiling straight away and exiting out immediately upon loading.

Once I have profiled lets look at what slimtune shows us.

I have 7 threads going. That’s OK, I use background loading of all the levels and the XNA framework generates a few of its own. I can see the GamerServices object is eating quite a lot of CPU. That’s not to surprising and not too much I can do about it.

If I drill into my own threads what we see is a substantial amount of time spent in creating vertex buffers. Ah!

The game world is split into a number of regions. Each region has an associated volume and bounding box. If the bounding box intersects the view frustrum then it is rendered in its entirety. Each region is a voxel space and each block within that space can be turned into a renderable cube. However the engine we’re creating also allows for blocks that are actually models. Each of these has a “cube renderer” that can also build vertex buffers.

Does each of these need its own vertex buffer or could we do better?

These cube renderers need to start sharing one big vertex buffer (independent mobiles / NPCs use different techniques)

Lets put that optimisation in place and see what happens. Load time is down to seconds!

Profilers are powerful tools – the high end commercial profiles can give you more details about what is going on but Slimtune is a pretty good starting point.