35

I'm benchmarking a WPF application on various platforms and I need an easy way to determine if WPF is using hardware or software rendering.

I seem to recall a call to determine this, but can't lay my hands on it right now.

Also, is there an easy, code based way to force one rendering pipeline over the other?

rudigrobler
  • 17,045
  • 12
  • 60
  • 74
Charley Rathkopf
  • 4,720
  • 7
  • 38
  • 57

7 Answers7

38

Check RenderCapability.Tier

[UPDATE]

  • RenderCapability.IsPixelShaderVersionSupported - Gets a value that indicates whether the specified pixel shader version is supported.
  • RenderCapability.IsShaderEffectSoftwareRenderingSupported - Gets a value that indicates whether the system can render bitmap effects in software.
  • RenderCapability.Tier - Gets a value that indicates the rendering tier for the current thread.
  • RenderCapability.TierChanged - Occurs when the rendering tier has changed for the Dispatcher object of the current thread.

RenderCapability.Tier >> 16

  • Rendering Tier 0 - No graphics hardware acceleration. The DirectX version level is less than version 7.0.
  • Rendering Tier 1 - Partial graphics hardware acceleration. The DirectX version level is greater than or equal to version 7.0, and lesser than version 9.0.
  • Rendering Tier 2 - Most graphics features use graphics hardware acceleration. The DirectX version level is greater than or equal to version 9.0.
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
rudigrobler
  • 17,045
  • 12
  • 60
  • 74
  • did you programmatically call Rendering.Tier at runtime and check the value? – JohnIdol Sep 02 '09 at 18:13
  • 1
    I am not getting any of the values you list for RenderingCapability.Tier (0, 1, 2) - I am getting 131072! – JohnIdol Sep 03 '09 at 09:04
  • 8
    OK need to shift 16 bits --> RenderCapability.Tier >> 16 – JohnIdol Sep 03 '09 at 09:21
  • More to both questions can be found here http://stackoverflow.com/questions/3060329/system-windows-media-rendercapability-tier-returns-not-the-render-mode I think that may help people who could not work already with .net4 and must check the render mode. – HCL Jun 18 '10 at 11:56
  • Hey, it's in fact RenderCapability and not RenderingCapability :-) – Jonathan ANTOINE May 27 '11 at 08:30
  • I've updated the MSDN link to point to the .NET 4.0 version, as the current version (versionless) link is now broken -- MS seems to have removed the article for .NET 4.5+. – Bob Mar 01 '16 at 00:58
13

.NET 4.0 provides the ability to force software rendering in code:

public partial class App : Application 
{    
    protected override void OnStartup(StartupEventArgs e)    
    {         
        if (WeThinkWeShouldRenderInSoftware())            
            RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;    
    }
}

See this post for more information.

user259509
  • 265
  • 3
  • 7
  • 1
    +1 If we lived in a perfect world this wouldn't be necessary but for real-world deployment scenarios this is one of those things we need to offer. When running apps maximized on large monitors with poor cards this actually removes all the black lines and choppiness. Thx! – Adam Caviness Jun 03 '14 at 21:17
7

Maybe the following can help with the second part of your question, that is, can you force one rendering pipeline over another:

You can change a registry setting to disable hardware acceleration and force software rendering to occur at all times. We often use this to see if a particular issue we are seeing ... is related to video drivers. As an example of what I am talking about see this WPF forum post.

One obvious thing to note here though ... is that this affects all WPF applications and really should only be used for testing purposes.

To disable hardware acceleration:

[HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics]
"DisableHWAcceleration"=dword:00000001

To enable hardware acceleration:

[HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics]
"DisableHWAcceleration"=dword:00000000

Check out this MSDN link for more info.

cplotts
  • 13,941
  • 9
  • 55
  • 66
6

Based on the RenderingTier links, here is some code:

        logger.InfoFormat("WPF Tier = {0}",RenderCapability.Tier / 0x10000);
        RenderCapability.TierChanged +=
            (sender, args) => logger.InfoFormat("WPF Tier Changed to {0}",
                                                RenderCapability.Tier / 0x10000);

I'm still testing and working on this. See future edits/answers for what I find.

Community
  • 1
  • 1
Charley Rathkopf
  • 4,720
  • 7
  • 38
  • 57
4

Or use the Profiling Tools...

New checkbox was added to tint the target application elements that use SW rendered legacy Bitmap Effects.

rudigrobler
  • 17,045
  • 12
  • 60
  • 74
2

I agreee with the second answer but that just says something about the ability of the machine to run using hw rendering not if the app is actually hw rendered.

I made a simple app using a canvas and just rotating a rectangle with RotateTransform uses way to much CPU for a hw rendered application. That and the 'RenderCapability.Tier' value is 2 so there's enough hw capability to do it.

Why doesn't then?

1

To answer the second half of your question, there is no way I believe really to force one way over the other. Hardware rendering is automatically used if available, otherwise, software is.

If you need to test it in Software mode, you'll need to use a low spec machine or use Remote Desktop to view the application running on another computer. Apart from reduced performance/framerate however, there shouldn't be any visible differences in appearance between the two. Use the RenderCapability class to know if you should disable things such as animation or effects in favour of performance.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Nidonocu
  • 12,476
  • 7
  • 42
  • 43