SkiaSharp
SkiaSharp copied to clipboard
[BUG] Major frames per second drops on 2.88.0
Description
My application goes from running at 30-32 FPS (on a 30hz refresh w/ vsync) down to 20 FPS after updating from 2.80.4 to 2.88.0
Using SKGLControl in WinForms .NET6
After I downgraded back to 2.80.4 my issue went away completely with no code changes.
// Vsync enabled on SKGLControl
private async void MainForm_Shown(object sender, EventArgs e)
{
while (glControl.GRContext is null) await Task.Delay(1); // Wait for GL Context to be set
glControl.GRContext.SetResourceCacheLimit(503316480); // Fixes low FPS on extra big bitmaps
while (true)
{
await Task.Run(() => Thread.SpinWait(50000)); // Delay between each frame
glControl.Refresh(); // draw next frame
}
}
private void SKGLCONTROL_PaintSurface(object sender, SKPaintGLSurfaceEventArgs e)
{
SKCanvas canvas = e.Surface.Canvas; // get Canvas reference to draw on
canvas.Clear(); // Clear canvas
canvas.DrawBitmap(); // Draw a cached bitmap on each render, roughly 3000x3000 resolution bitmap PNG
// draw some lines , circles, etc. less than 1000 items
canvas.Flush(); // commit frame to GPU
}
Expected Behavior
I expect to get around ~30 FPS like the previous version.
Actual Behavior
I am getting 20 FPS.
Basic Information
- Version with issue: 2.88.0
- Last known good version: 2.80.4
- IDE: VS 2022
- Platform Target Frameworks: WinForms .NET6 win-x64
Performance drop seems to be dependant of the bitmap size. For me, instead of getting c.a. 50 fps, Now I get c.a. 10, or even less - when working with 42 Megapixel SkBitmap - what is a blocker for the app. I've recorded a screen capturing - for 2.80.4 and for 2.88.0 on iPhone 11. I'l try to upload somewhere and share the links.
2.80.4 (fast) https://youtu.be/ZN3ki_IpPUg
2.88.0 (slow) https://youtu.be/jNvGh4R19cA
Could you attach a small repro that I can use to debug the process? Mainly I think I need some large images and some drawing code.
This appears to be the same as #2188, but this says GPU/GL and that is using raster. Not sure if this is a sign of bitmap drawing slow, or some GPU things.
Also some machine hardware numbers - like GPU model/spec.
@mattleibow skiasharp-bug-example-master.zip Here is a small repro, contains a good sized Bitmap
I turned off VSync to better demonstrate the frames per second differences when uncapped. Most apparent when the Window is maximized.
2.80.4 ~300 FPS
2.88.0 ~ 100 FPS
I am using a Dell Optiplex 7050 I7-7700 CPU Intel HD Graphics 630
in a Remote Desktop Session
Hope this helps
I am wondering if it is actually this change in 82:
Removed drawBitmap and related functions from SkDevice; all public drawBitmap functions on SkCanvas automatically wrap the bitmap in an SkImage and call the equivalent drawImage function. Drawing mutable SkBitmaps will now incur a mandatory copy. Switch to using SkImage directly or mark the bitmap as immutable before drawing.
https://github.com/mono/skia/blob/xamarin-mobile-bindings/RELEASE_NOTES.txt#L369-L372
I am wondering if it is actually this change in 82:
Removed drawBitmap and related functions from SkDevice; all public drawBitmap functions on SkCanvas automatically wrap the bitmap in an SkImage and call the equivalent drawImage function. Drawing mutable SkBitmaps will now incur a mandatory copy. Switch to using SkImage directly or mark the bitmap as immutable before drawing.
https://github.com/mono/skia/blob/xamarin-mobile-bindings/RELEASE_NOTES.txt#L369-L372
Bingo! That was it.
What changes did you make to get that sweet sweet speed back? Just using SkImage?
What changes did you make to get that sweet sweet speed back? Just using SkImage?
I ended up just making my SKBitmaps immutable :) worked perfectly per the referenced solution you posted