Performance of WriteableBitmap(Ex) vs DrawingContext
Asked Answered
I

1

6

I am building a custom UI framework in WPF where I basically ditch as much of the built-in layout system and controls as I can. So far I have been branching off from UIElement directly, but since I am already doing the measure, arrange and rendering myself, I am thinking I could slice off more of the WPF legacy by getting even "closer to the metal" (especially when it comes to layout / rendering). How close is it possible to get while staying in managed code and not being afraid of doing the dirty work myself?

I am toying with a prototype concept on the side now where I only have one element inheriting from UIElement: a Root object, similar to a stripped down Canvas, that "hosts" the rest of my layout engine and channels relevant IInputElement benefits into it. From that point onward, all elements would be completely custom objects not inheriting from anything in WPF, but rendering directly into the DrawingContext of Root (in its OnRender method).

Now I'm wondering about the relative performance of having a WriteableBitmap root element and manually draw onto that instead, for example using WriteableBitmapEx for convenience. Not having anti-aliasing isn't an issue, neither is a custom hit testing system.

My thoughts are primarily that WriteableBitmap(Ex) does not have the privilege of any GPU acceleration gains and therefore will be [much] slower when large areas needs to be repainted / transformed.

I do have other needs for a "pixel-based-rendering-engine-in-the-engine", though, so I am still interested in some perspective on this.

Any insights?

Edit: And what about SharpDX in this context? Maybe once I'm at it I might as well go for a WinForms solution with a DirectX wrapper like SharpDX (..or.. I guess what I really should do is sign up for the whole C++ enchilada, but unfortunately I don't have time to start learning that in the midst of things)..

Intendment answered 21/12, 2013 at 13:21 Comment(2)
You rock. Just wanted to say that.Unclear
In the end, I ditched WPF and .Net altogether and learned C++ instead. Then I started with Direct2D from native code, which seemed OK in the beginning. Then I decided I wanted even more control, so I ditched Direct2D, too, and rolled my own native 2D UI framework directly on top of Direct3D 11. Now I'm close enough to the metal.. So much more I can do now - and it's FAST. Custom-building my own graphics framework from scratch allows me to do a lot of optimizations. It's less flexible and expansive than Direct2D, but it performs better.Intendment
M
5

WriteableBitmapEx is quite fast, even when it just runs on the CPU. It's used in this high perf charting control: http://www.scichart.com

You should also checkout Direct3D indeed. You can get really good performance, but it really depends how it's used and that most draw operations are cached and the CPU-GPU communication is as lets as possible.

Mano answered 22/12, 2013 at 19:27 Comment(4)
Hi, Rene (remember this?).. Yes, WriteableBitmapEx is quite fast - for a lot of things. But I did a quick test of it now and it has some shortcomings for my needs. I also tested Direct2D via the SharpDX wrapper and that is very fast - especially for tossing large bitmaps around. Looks like I'm opting for that - which means I can drop WPF altogether and put my own layout system on right on top of "DirectX".. until I can go for C++ ;)Intendment
Direct2D is not that fast. Only non-antialiased lines perform quickly. I investigated it for SciChart and quickly dumped it as too slow. C++ drawing is not that fast either (we tried Agg which is a C++ drawing engine). Truth be told, WBEx is one of the fastest ways to draw on Windows. It took us almost 2 years of research to beat it with a DirectX10 custom 2D drawing engine! scichart.com/how-fast-is-scichart-wpf-chartWarsle
@Dr.ABT are you displaying your WriteableBitmap into Image control, or you have some better advice about displaying WriteableBitmap. And maybe you could give some advice about displaying large images? Thanks!Dot
Hi @Dot yes WriteableBitmap must be displayed inside an Image control in the Image.Source property. Large images? You might need to tile as there are limits on the largest bitmap size in Windows. In my company SciChart we've also successfully integrated DirectX content in an Image control by using Texture Readback into WriteableBitmap. This solution is very versatile for high performance graphics in WPF!Warsle

© 2022 - 2024 — McMap. All rights reserved.