Software Rendering Mode - Wpf

Software rendering mode - WPF

Here's what we did:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (ForceSoftwareRendering)
{
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
HwndTarget hwndTarget = hwndSource.CompositionTarget;
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
}
}

It worked OK for us, EXCEPT... This needs to be done for every Window. In .NET 3.5 there was no way to make the setting take effect application-wide. And there are some windows that you won't have as much control over - for example, right-click "context" windows. We found that there was no good solution for .NET 3.5 except the registry setting.

Edited

Here's the logic we used to determine when to force software rendering. It was suggested by a Microsoft support engineer.

public bool ForceSoftwareRendering 
{
get
{
int renderingTier = (System.Windows.Media.RenderCapability.Tier >> 16);
return renderingTier == 0;
}
}

In .NET 4 Microsoft added an application-wide setting that works perfectly for us. Its a much better option because you don't need to set it on every window. You just set it once and it applies to all windows.

System.Windows.Media.RenderOptions.ProcessRenderMode

Edited

The new .NET 4.0 property can be set at application startup like this:

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

How do you determine if WPF is using Hardware or Software Rendering?

Check RenderCapability.Tier

  • Graphics Rendering Tiers
  • RenderCapability Class

[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.

WPF 4+ software rendering still an issue?

This list is still accurate.

This is covered on MSDN's page regarding Graphics Rendering Tiers. The second labeled as "The following features and capabilities are not hardware accelerated:" lists the specific criteria that can cause non-accellerated rendering in WPF.

This includes:

  • TileBrush
  • Content rendered via RenderTargetBitmap
  • Any printed output
  • Surfaces exceeding the graphics hardware's maximum texture size
  • Layered windows on Windows XP.

WPF poor rendering of application

try disabling GPU acceleration:
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

Sometimes WPF GPU caching does a lot of tricks, and this can help, without degrading much performance imo.

WPF rendering lines on window

We have similar issues with big black vertical bars. Only resolved by switching to software only rendering:

System.Windows.Media.RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

Visual Studio WinForm Render Mode

Software rendering is what WinForms do already, for all windows and controls, using GDI and GDI+, you can get started here.

If you want hardware accelerated graphics, you need to use some graphics library, like OpenGL or DirectX.

WPF uses DirectX modules to render, because of this you have such option.



Related Topics



Leave a reply



Submit