Smartrak / WpfSharpDxControl

Provides WPF control to host SharpDx content.
MIT License
29 stars 8 forks source link

Framerate artificially capped by WPF #3

Open code-beans opened 6 years ago

code-beans commented 6 years ago

Hey, first of all thanks for that great wpf control. I had way to many problems using MS' Interop library.

I am currently looking into rendering performance. Consider a barebone wpf application using the WpfSharpDxControl with an empty Render() method. In my understanding the framerate is determined by the number of calls of CompositionTarget.Rendering invoked internally by wpf. I did a little bit of testing and found out, that the will be somewhere around ~20-60 fps even with HardwareAcceleration (RenderCapacity.Tier 2) enabled. Now when putting the render call OnCompositionTargetRendering in a while(true) loop on a different thread I get framerates in >300 fps. Unfortunately I do get a ton of exceptions when the Resize event is raised.

Did you try to implement a renderloop other than (un-)subscribing to the CompositionTarget.Rendering event. Or do you know any reason why rendering has to be done that way? Did you do some profiling on your end regarding framerates?

Thanks.

oppassum commented 4 years ago

code-beans,

I realize this is a bit late, but I ran into similar issues with this when I went to implement the SharpDXControl.

I was able to solve framerate issues by including a timer to artificially call my render (I have it in fact just call the OnCompositionTargetRendering method).

To combat threading issues, I had to wrap the render methods in the application dispatcher. This also allowed me to set a priority for the SharpDXControl by doing a BeginInvoke and setting the dispatcherpriority.

Hope this helps.