-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GPU-accelerated WPF without WindowsFormsHost #745
Comments
Okay, after some more debugging, I figured out what caused the However, when closing the window, I'm now getting an
If anyone could shed some light on that, that would be great. I've updated the sample repo, just launch it and close the window to reproduce. |
Turns out that @mattleibow if you think that SkiaSharp would benefit from a WPF view implementing this approach, let me know, otherwise feel free to close! |
From @Mikolaytis in #819:
|
From @Mikolaytis:
|
From @Mikolaytis:
|
From @john-cullen:
|
@john-cullen, I can't be sure at this point, but it might be that the stencil buffers aren't set up right. I see this is Hopefully @Mikolaytis has got a working solution that we can benefit from. 🤞 |
Just merging some issues and it appears that @freezy has some code in a repo:
|
@mattleibow thanks for responding immediately! I have a couple of questions. First of all, I apologise if these are obvious, but I've never done any graphics work before now. How does the approach in this issue / the linked repository differ from using a Does being accelerated imply that the rendering to the bitmap buffer is calculated on the graphics card instead of the cpu? Does this translate to noticeably better performance for Skia? If I'm just issuing API calls to Skia, from a development perspective should the experience be transparent? ie, could I develop using the mechanism I've got to work and later on switch to an accelerated backend without any change in the Skia code? (obviously I'd expect some change in that code that wires up the bitmap to my WPF control). Basically, I'm evaluating a method to create a high performance chart as there does not seem to be an existing general-purpose implementation that both fits our use-case well enough and has the required performance. SkiaSharp seems to be the nicest way to accomplish that on dotnetcore. Thank you for your time. edit: both approaches seem to have about the same performance if I call |
@mattleibow We are using @freezy approach for a 6 month already. Issue is - we are still using
2-4 steps are terrific performance downgrade. I want to have next pipeline:
I imagine this pipeline should work at least 10x faster than first one. I've tried a lot of options over a 6 month and did not found a working solution. |
So, the fail of my code was to use Avalonia EGL libs. Today I've built angle myself and everything is working. Wow! https://github.com/Mikolaytis/WpfSkiaAngleSharpDxOpenTK - here is an example with updated libs. |
OpenTK GLWpfControl is (almost) a drop-in replacement for its WinForms counterpart GLControl. So, I used it to port SKGLcontrol to WPF (a SKWpfGLControl, if you will) and it seems to work in my limited testing with GPU support, no flickering etc. My use-case is fairly limited to just some background, lines and text so please let me know if I am missing anything or if there is a reason that this is not a good solution. |
cool! may i try it? |
Here is a small example that compares to SKElement: |
The program runs normally. |
@enissimsek Thanks alot! It works just beautifully. Here is a before and after comparison video: But it does have some problems, it doesn't really seem to like rendering two dock windows (AvalonDock) it gets confused. Definitely related to GL, if I swap back to SKElement it renders normally again. WolfCorps/TacControl@a90164a Edit: I thought this might be the problem. Changing the code to manually get the correct window handle via |
I don’t have the expertise in this area to offer deeper insight but I knew it is something that needs to be worked around explicitly if you need multiple instances of controls that use GRContext. This may help: [BUG] Weird crosstalk between multiple canvas when using GPU-accelerated WPF with WindowsFormsHost |
Hey guys, just came across this randomly and might have something that could help you out. It seems that you try to resolve the classic airspace wpf issue. The only solution that I've found is by creating a transparent forewindow and transfer the overlay contents there. I've used the libvlcsharp's code as a base (I've also resolved the issue rendering during the design mode and fullscreen, i will commit my version soon). You can find the libvlcsharp's code here https://github.com/videolan/libvlcsharp/tree/3.x/src/LibVLCSharp.WPF |
Hello, I also encountered the same problem. I have tried various attempts and still have not solved it. Do you have any new progress? Thank you. I tried: |
Y'all know that you can open issues in the OpenTK repos and we are likely able to fix the problems you are encountering? |
My repro is very dependent on Mapsui/SkiaSharp/AvalonDock, I have no repro with GLWpfControl itself, without SkiaSharp. |
Is it just me or is there no way to make |
im not exactly sure this is trying to achieve but if you want a GPU accelerated off-screen surface then why not create a new GL thread with Gr* api's to create GL context in the new thread, and then obtain a SKSurface and draw to it's Canvas ? |
or might you be trying to create a |
Please consider this for soon @mattleibow would be super useful! |
I've attempted to add a GL element for WPF that utilizes OpenTK's GL WPF control here: #2317 |
seems to work ok for me, even in cross-talk scenarios (multiple elements on same thread) after I started resetting the Graphics context before painting |
Has anyone managed to get performant GL rendering? I've tried several options posted on here, and can't seem to get over 15-30 fps and my render feels sluggish. I get 300+ fps on native WinForms with SKGLControl (for some reason I can't do this using the FormsHost in WPF) Is WPF just a bad choice for this? |
I tried out @freezy solution and it worked good, even over rdp (this is where OpenTk fails). |
Likewise, I just tried it now with SkiaSharp 2.88.6 - and mine is crashing on the same line of code (DrawSurface), but with this similar error: System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' Our project is fine with the "copy back to writeable Bitmap" performance hit - although a pure GPU solution is way better. Our main reason for needing a GPU Surface is because we're using SKSL Shaders that only work on GPU surfaces. It's working fine for us on Android now (haven't checked iOS yet), but having big issues on WPF. I've also dabbled with just trying to get a GPU Surface to copy it's contents to a CPU-base SKBitmap - no luck here either - same error as above. We would really appreciate seeing ANY GL-based WPF Surface Solution working in the main SkiaSharp.Views package. == Ping @mattleibow @freezy |
After reading through many issues mentioning the drawbacks of
WindowsFormsHost
(no transparency, no event bubbling, no borderless windows), I've tried to implement another approach: Do the expensive computing off-screen and copy the result into a (non-GPU-accelerated)SKElement
.As @mattleibow mentioned in #717, the unit tests'
WglContext
should be able to deliver a GPU-accelerated off-screen context.My main view with
SKElement
:Code behind:
The
WglContext
class is copied from this repo's test directory.The problem I'm having is when running this, I'm getting first this:
This is followed by a
System.NullReferenceException
without any stack trace. So it's somewhere in a native call, but I can't figure out where. Any hints or suggestions would be appreciated!I've created a repo to reproduce: freezy/wpf-skia-opengl.
Related: #213, #622, #688
The text was updated successfully, but these errors were encountered: