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

发布于 2024-07-07 11:05:31 字数 146 浏览 10 评论 0原文

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

我似乎记得曾打电话来确定此事,但现在无法联系。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

胡大本事 2024-07-14 11:05:32

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

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

请参阅 这篇文章了解更多信息。

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

北恋 2024-07-14 11:05:32

也许以下内容可以帮助解决您问题的第二部分,即您是否可以强制一个渲染管道优于另一个渲染管道:

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

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

要禁用硬件加速:

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

要启用硬件加速:

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

请查看此 MSDN 链接了解更多信息。

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.

肤浅与狂妄 2024-07-14 11:05:32

基于 RenderingTier 链接< /a>,这是一些代码:

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

我仍在测试和处理此问题。 请参阅未来的编辑/答案以了解我发现的内容。

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.

此刻的回忆 2024-07-14 11:05:32

或者使用分析工具...

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

Or use the Profiling Tools...

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

晨与橙与城 2024-07-14 11:05:32

我同意第二个答案,但这只是说明了机器使用硬件渲染运行的能力,而不是应用程序实际上是硬件渲染的。

我使用画布制作了一个简单的应用程序,仅使用 RotateTransform 旋转一个矩形就占用了硬件渲染应用程序的大量 CPU。 而且“RenderCapability.Tier”值为 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?

我也只是我 2024-07-14 11:05:32

为了回答你问题的后半部分,我认为没有办法真正强迫一种方式优于另一种方式。 如果可用,将自动使用硬件渲染,否则,将使用软件渲染。

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

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.

甜尕妞 2024-07-14 11:05:31

检查 RenderCapability.Tier

[更新]

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

RenderCapability.Tier>> 16

  • 渲染层 0 - 无图形硬件加速。 DirectX 版本级别低于 7.0 版本。
  • 渲染层 1 - 部分图形硬件加速。 DirectX版本级别大于或等于版本7.0且小于版本9.0。
  • 渲染层 2 - 大多数图形功能都使用图形硬件加速。 DirectX版本级别大于或等于版本9.0。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文