Thursday, September 3, 2009

How to check if WPF is using Hardware or Software Rendering?

In general, software rendering will usually kick-in if your machine doesn't support DirectX or if the drivers installed are not working correctly (for whatever reason). WPF is entirely built on Direct3D, and software rendering means your WPF app will run painfully slow.

In borderline scenarios, such as running on portable device where hardware capability is constrained, you might find yourself in a bit of a mexican standoff situation where you don't know if the bottleneck is the hardware itself or the problem is just that hardware acceleration is not working and the system falls back to software rendering. So, how do you check if software rendering is kicking in?

You can do this from code querying the RenderCapability.Tier property, as follows:
//shifting some 16 bits will do the trick
int renderCapabilityTier = (RenderCapability.Tier >> 16);
The int above can have three possible values:
  • 0 --> you're screwed - no hardware acceleration
  • 1 --> you're half screwed - you got some hardware acceleration
  • 2 --> you're good to go with full blown hardware acceleration
You might also wanna run the DirectX diagnostic tool (just run dxdiag.exe) to double check the state of your hardware acceleration (check the display tab) and, since we are at it, the new WPF profiler.

1 comment:

Jose Abascal said...

It works