wpf icon indicating copy to clipboard operation
wpf copied to clipboard

Enhancement of RenderTargetBitmap to Support Hardware Rendering

Open DearVa opened this issue 1 year ago • 4 comments

Fixes #9021

Description

In WPF, RenderTargetBitmap (also RTB) currently only supports software rendering. This limitation leads to performance bottlenecks and causes ShaderEffect implementations to become ineffective. Enhancing RTB to support hardware rendering would provide significant performance improvements and enable high-quality rendering features that are currently restricted. This limitation has been extensively discussed in the past (#144, Add optional hardware acceleration to RenderTargetBitmap and some website was lost: RenderTargetBitmap and Hardware WPF Rendering).

As a developer who is proficient in graphics and C#, one of my requirements is to export WPF-rendered UI as video efficiently. Current methods such as using BitmapCache (which cannot retrieve content back to memory) and hooking DirectX APIs (which is complex and unstable) are not feasible solutions.

Customer Impact

RenderTargetBitmap will only support software rendering and may experience performance bottlenecks as well as ShaderEffect not working as expected.

Regression

No

Testing

Additional tests may need to be added to verify that it behaves correctly with different drivers (no graphics, integrated graphics, discrete graphics) and in the event of missing devices, etc. May also need to check for potential memory leaks.

Risk

Due to API changes, PixelFormats.Prgba128Float will no longer be supported when creating a RenderTargetBitmap.

Although code can fall back to software when no hardware device context is acquired, this needs to be extensively verified. May also need to check for potential memory leaks.

This is a huge change, but I think it deserves to be discussed in depth and considered carefully!

Microsoft Reviewers: Open in CodeFlow

DearVa avatar Apr 13 '24 03:04 DearVa

@dotnet-policy-service agree

DearVa avatar Apr 13 '24 04:04 DearVa

Awesome! 666

lindexi avatar Apr 13 '24 06:04 lindexi

incredible performance improve! I will test in my device later.

RCUTANF avatar Apr 14 '24 04:04 RCUTANF

Hello every reviewers, I was wondering if there's any update on this PR? @singhashish-wpf @dipeshmsft I tagged you as you seem to be the expert in this area and I'm a bit lost on how to proceed. My apologies if I'm out of line.

DearVa avatar May 12 '24 13:05 DearVa

Hello every reviewers, I was wondering if there's any update on this PR? @singhashish-wpf @dipeshmsft I tagged you as you seem to be the expert in this area and I'm a bit lost on how to proceed. My apologies if I'm out of line.

Pretty sure this PR will be on hold for yet another several months before it finally gets reviewed and merged just like any other community PR which touches some fundamental things.

hez2010 avatar May 17 '24 05:05 hez2010

Hello every reviewers, I was wondering if there's any update on this PR? @singhashish-wpf @dipeshmsft I tagged you as you seem to be the expert in this area and I'm a bit lost on how to proceed. My apologies if I'm out of line.

Pretty sure this PR will be on hold for yet another several months before it finally gets reviewed and merged just like any other community PR which touches some fundamental things.

Thanks for your reply, waiting for good news!

DearVa avatar May 17 '24 05:05 DearVa

BitmapCacheBrush?

heu33 avatar May 27 '24 01:05 heu33

Current methods such as using BitmapCache (which cannot retrieve content back to memory)

As I have mentioned above: BitmapCache cannot retrieve it's content back to memory. It only stays in GPU memory. If you try to use BitmapCacheBrush and draw it to a DrawingContext then renders it to a RenderTargetBitmap, it still fallbacks to CPU render.

DearVa avatar May 27 '24 02:05 DearVa

BitmapCacheBrush?

The only way you can "capture" a Visual into a CPU accessable memory is to use RenderTargetBitmap. This will inevitably result in all the content on it being rendered using the CPU. As proof, you can add a GPU only DX shader on Visual as ShaderEffect, and I guarantee it won't take effect.

DearVa avatar May 27 '24 02:05 DearVa