如何确定 WPF 是使用硬件渲染还是软件渲染?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/149763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:40:31  来源:igfitidea点击:

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

wpfrenderingpipeline

提问by Chasler

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.

我正在各种平台上对 WPF 应用程序进行基准测试,我需要一种简单的方法来确定 WPF 是使用硬件渲染还是软件渲染。

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?

另外,是否有一种简单的、基于代码的方法来强制一个渲染管道覆盖另一个渲染管道?

回答by rudigrobler

Check the RenderCapability.Tier

检查 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.IsPixelShaderVersionSupported- 获取一个值,该值指示是否支持指定的像素着色器版本。
  • RenderCapability.IsShaderEffectSoftwareRenderingSupported- 获取一个值,该值指示系统是否可以在软件中渲染位图效果。
  • RenderCapability.Tier- 获取一个值,该值指示当前线程的呈现层。
  • RenderCapability.TierChanged- 当前线程的 Dispatcher 对象的呈现层已更改时发生。

RenderCapability.Tier >> 16

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.
  • 渲染层 0- 无图形硬件加速。DirectX 版本级别低于 7.0 版。
  • 渲染层 1- 部分图形硬件加速。DirectX 版本级别大于等于 7.0 版,小于 9.0 版。
  • 渲染层 2- 大多数图形功能使用图形硬件加速。DirectX 版本级别大于等于 9.0。

回答by user259509

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

.NET 4.0 提供了在代码中强制软件渲染的能力:

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

See this postfor more information.

有关更多信息,请参阅此帖子

回答by cplotts

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.

您可以更改注册表设置以禁用硬件加速并强制始终进行软件渲染。我们经常使用它来查看我们看到的特定问题是否与视频驱动程序有关。作为我正在谈论的示例,请参阅此WPF 论坛帖子

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

不过,这里要注意的一件显而易见的事情是……这会影响所有WPF 应用程序,并且实际上应该仅用于测试目的。

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 linkfor more info.

查看此MSDN 链接以获取更多信息。

回答by Chasler

Based on the RenderingTier links, here is some code:

基于RenderingTier 链接,这里有一些代码:

        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.

我仍在测试和研究这个。有关我发现的内容,请参阅未来的编辑/答案。

回答by rudigrobler

Or use the Profiling Tools...

或者使用分析工具...

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

添加了新的复选框来为使用软件渲染的旧位图效果的目标应用程序元素着色。

回答by Nidonocu

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.

如果您需要在软件模式下对其进行测试,则需要使用低规格机器或使用远程桌面来查看在另一台计算机上运行的应用程序。然而,除了性能/帧率降低之外,两者之间在外观上不应该有任何明显的差异。使用 RenderCapability 类来了解是否应该禁用动画或效果等内容以提高性能。

回答by Nidonocu

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.

我使用画布制作了一个简单的应用程序,只需使用 RotateTransform 旋转一个矩形,就可以为硬件渲染应用程序使用大量 CPU。那和 'RenderCapability.Tier' 值是 2,所以有足够的硬件能力来做到这一点。

Why doesn't then?

那为什么不呢?