Using PerfHUD with XNA

I am definitely a fan of ATI cards. Had a few Geforces but didn’t liked them very much. I actually noticed image quality decrease when switching from an old Radeon 9800 to a Geforce 8k something. I’m very happy with my Radeon 4890, now for the downside, PerfHUD, a very handy tool for Game Developers is only available for NVIDIA chipsets and although ATI has it’s own GPUPerfStudio it’s not the same thing.
Anyway for those who have one and are developing for XNA you may have noticed that it doesn’t run PerfHUD out of the box.
You will get an error, something like:
“This applications is not configured for using PerfHUD. Consult the User’s Guide for more information”

perfHUD_Error

Luckily there’s a little trick we can use to fix this, first we create a new class:

// class that inherits from GraphicsDeviceManager
public class PerfHUDGraphicDeviceManager : GraphicsDeviceManager
    {
        public PerfHUDGraphicDeviceManager(Game game)
            : base(game) // Pass game to base class
        {
        }
        // We override the RankDevices to search for a PerfHUD
        protected override void RankDevices(List foundDevices)
        {
            base.RankDevices(foundDevices);
            bool has_perfHud = false;
 
            foreach (var device in foundDevices)
            {
                if (device.Adapter.Description.Contains("PerfHUD"))
                {
                    has_perfHud = true;
                    break;
                }
            }
            // Found PerfHUD
            if (has_perfHud)
            {
                var temp = foundDevices.OrderBy(
                    (gdi) => !(gdi.Adapter.Description.Contains("PerfHUD"))
                ).ToArray();
 
                foundDevices.Clear();
                foundDevices.AddRange(temp);
 
                foreach (var dev in foundDevices)
                {
                    dev.DeviceType = DeviceType.Reference;
                }
            }
        }
    }

This class basically searches for PerfHUD, so when you open it with it this class detects that the software exists and allows it’s usage. If not found, the regular GraphicDeviceManager is used. Now instead of creating a new GraphicsDeviceManager() on your Game class just do something like:

public class Game1 : Game
{
		public Game1()
		{
                    new PerfHUDGraphicDeviceManager(this);
                }
}

perfHUD_runperfHUD_working_xna

I hope this helps.

2 Comments

  1. Popcorn

    XNA will set SoftwareVertexProcessing ON when perfhud is active
    which means (a) the performance metrics are wrong (b) is runs incredibly slowly

    how do you work around that?

Leave a Reply