Jump to content
Hans♫

Slow rendering with SKIA on Windows

Recommended Posts

Having Skia on MacOS is a great improvement because it allows us to enable Metal without losing rendering quality. However, on Windows we experience slow rendering with Skia.

We use Delphi 12.1 Patch 1, with our FMX based app. A full screen slide-in animation of a TFrame on top of the main form is smooth with GlobalUseSkia=false. When setting GlobalUseSkia=true, the framerate of the animation goes down to around 2-4 fps.

 

This is with GlobalUseSkiaRasterWhenAvailable=true. Setting GlobalUseSkiaRasterWhenAvailable=false, then the framerate doubles, but then vector graphics is no longer antialiased.

 

We have not changed any components or code in paint routines, but maybe we should?

Any idea what goes wrong?

Share this post


Link to post

What kind of graphics hardware are you running on?

Share this post


Link to post

We have tried it on several PCs and laptops here at the office. Both new and old computers (and graphics cards), and both with 32 bit and 64 bit builds of our application. The result is the same everywhere. With Skia, the framerate is 2-4 fps, and without Skia the framerate is not visible, which I guess means 20+ fps.

 

PS. But if you want to know, I personally use a 12 years old AMD Radeon 6670, which is fast enough to run Delphi 🙂

Share this post


Link to post

Can you create a small app that demonstrates the problem and that you can share?

Share this post


Link to post
5 minutes ago, Lars Fosdal said:

Can you create a small app that demonstrates the problem and that you can share?

No, unfortunately a simple app does not have this problem.

 

And as a side-note, thinking about your question:

Asking "general" questions like I did is of course a tradeoff: When have I tried enough to ask? 

I am sure I would be able to solve the problem on my own, but I also know that it could easily take a day, a week or even a month to solve. Sometimes just to find out that the solution was simple, but locating it was complex. Sometimes others have been through the same and discovered something that might not be obvious.

I admit that I asked my question early in the process, long before having tried all options. But that was with a hope that someone else have been through this and have some useful information 🙂

Share this post


Link to post

The more details you provide, the more likely it is that someone with Skia experience may be able to help.

 

Ping @vfbb

 

  • Like 1

Share this post


Link to post
Posted (edited)

I want to confirm slow graphics rendering using GlobalUseSkia=True.
I create SCADA applications. There's a lot of graphics there. To make it 'nicer' I use animations. Unfortunately, with the GlobalUseSkia=True option it works terribly slowly (2-3 fps). With the GlobalUseSkia=False option it is much better. However, I would expect much smoother operation.
This problem also occurred in D11.3
I use equipment:
HP ZBOOK G7 i9; Quadro RTX 3000

Hardware is probably not the problem here.

Edited by Rafal.B
  • Like 1

Share this post


Link to post
On 5/3/2024 at 4:56 PM, Rafal.B said:

I want to confirm slow graphics rendering using GlobalUseSkia=True.

Thank you. Interesting where the bottleneck is?

 

BTW, we are not using the Skia Canvas (ISkCanvas), but as I understand the description, it is only needed to unlock more features, not to increase speed?

For now we can simply turn off Skia on Windows, and use it only on MacOS, Android and iOS. But as soon as we begin to implement SKIA specific functionality, it becomes more difficult to maintain, if we have to support non-Skia too.

Share this post


Link to post
Posted (edited)
4 hours ago, Uwe Raabe said:

Looks similar to this report: https://quality.embarcadero.com/browse/RSP-42714

Considering my case, this is exactly the problem. 😞
I haven't noticed this report until now.
Thank you for pointing out this report 🙂
As you can see, the topic is not new, and EMB has not done anything about it (for now) 😞

Edited by Rafal.B

Share this post


Link to post
3 hours ago, Rafal.B said:

As you can see, the topic is not new, and EMB has not done anything about it (for now) 😞

The question is whether they can do something about it at all.

 

For start, Skia in Delphi operates on several layers of indirection (including some poor design choices) which also involve memory intensive operations on each paint (including reference counting). When you add FireMonkey on top that is additional layer. Now, all that does make Skia slower than it could be. But that problem exists on all platforms. ARM and especially Apple Silicon have better performance when it comes to reference counting, but that is probably still not enough to explain the difference.

 

Some of the difference can also be explained with juggling memory between CPU and GPU on Windows as those other platforms use unified memory for CPU/GPU. However, my son Rene (who spends his days fiddling with GPU rendering stuff) said that from the way CPU and GPU behaves when running Skia benchmark test, that all this still might not be enough to explain observed difference, and that tiled based rendering on those other platforms could play a significant role. 

 

Another question is how Skia painting actually works underneath all those layers and whether there is some additional batching of operations or not. 

 

@Hans♫ Do the Macs you tested it on have Apple Silicon? If they do then they also support tile based rendering.

 

As far a solutions are concerned, it is always possible to achieve some speedups by reusing an caching some objects that are unnecessarily allocated on the fly, those could be both in FMX code itself, or in how FMX controls are used and how many are them on the screen. I used to create custom controls that would cache and reuse some FMX graphic objects when painting instead of creating complex layouts with many individual FMX controls.

  • Thanks 1

Share this post


Link to post
46 minutes ago, Dalija Prasnikar said:

@Hans♫ Do the Macs you tested it on have Apple Silicon? If they do then they also support tile based rendering.

Yes, we have both Intel macs and Apple Silicon macs at the office, but we currently build only for Intel and rely on the Rosetta 2 emulator. Both Intel and Silicon work "fine" when enabling Metal. However, we have not measured the framerate on animations or the painting speed, so here "fine" means that its high enough to not attract attention.

Share this post


Link to post
52 minutes ago, Dalija Prasnikar said:

The question is whether they can do something about it at all.

 

For start, Skia in Delphi operates on several layers of ...

Thank you for your substantive and extensive comment.
In one word, there is no reason to expect any improvement?

Share this post


Link to post
23 minutes ago, Rafal.B said:

there is no reason to expect any improvement?

At least not short term.

  • Like 1

Share this post


Link to post

I don't have the equipment to debug or deep dive in this subject, but from this

1 hour ago, Dalija Prasnikar said:

Some of the difference can also be explained with juggling memory between CPU and GPU on Windows as those other platforms use unified memory for CPU/GPU. However, my son Rene (who spends his days fiddling with GPU rendering stuff) said that from the way CPU and GPU behaves when running Skia benchmark test, that all this still might not be enough to explain observed difference, and that tiled based rendering on those other platforms could play a significant role. 

I want to point something and hope it is not waste of time, 

What about synchronizing objects here ? , how many are there ? what are they ? are they critical sections or something else? 

See, returning data form GPU done by either blocking or waiting, but in fact in both cases internally they are hardware interrupts triggers, so the derivers plays a role and if there is a waiting mechanism.

So, i would suggest to Rene to count these and if possible (of course in case there is many) on FireMonkey side to replace each and every one of them (aka patch someway or another) to be a spinlock, that spin with :

1) try to spin for 50k-100k loop in place before reduce the spin speed by SwitchToThread or Sleep(0).

2) tweak the range 50k-100k up and down and see the impact on FPS.

3) Use Sleep(0) and SwitchToThread without spinning in place.

 

also how many objects really are being sent to the GPU, (data or whatever), compared to haw many render call on FMX layer per object, a ratio would help here.

 

There was a bug or inefficiency in AlphaSkins, where paining a control needed its parent and this caused the parent to render all of its control on it and this triggered many render with each paint escalating or amplifying the CPU usage on main thread and that made it stutter. 

 

Here my AS demo it might help with more accurate or easier way to track this behavior with FMX

CustomDraw.rar

 

The is simple, these boxes should show 10 as 10 FPS objects to be rendered no more and no less.

 

In all case sorry if this post is a waste of time.

Share this post


Link to post
19 hours ago, Hans♫ said:

Both Intel and Silicon work "fine" when enabling Metal. However, we have not measured the framerate on animations or the painting speed, so here "fine" means that its high enough to not attract attention.

If all Macs work fine, then this is not due to tile based rendering (or at least not significantly), probably unified CPU/GPU memory is more relevant here. Another possibility would be that there is some difference in FMX platform specific code. But I cannot comment on that as I never looked at it.

 

 

Share this post


Link to post
On 5/2/2024 at 5:13 PM, Hans♫ said:

This is with GlobalUseSkiaRasterWhenAvailable=true. Setting GlobalUseSkiaRasterWhenAvailable=false, then the framerate doubles, but then vector graphics is no longer antialiased.

What are your exact settings when the drawing is slow on Windows? All GlobalXXX values you are using?

Share this post


Link to post
6 minutes ago, Dalija Prasnikar said:

What are your exact settings when the drawing is slow on Windows? All GlobalXXX values you are using?

 

Screenshot_1.png

Share this post


Link to post
23 minutes ago, Hans♫ said:

 

Screenshot_1.png

How it works when you UseVulkan? I have done some experiments and the fallback for Skia is OpenGL while FMX without Skia uses Direct2D. I am getting much better performance with Vulkan on Windows.

Share this post


Link to post
3 hours ago, Dalija Prasnikar said:

How it works when you UseVulkan?

Enabling Vulkan requires to uncheck SkiaRaster, according to the description.

We are seeing a performance improvement and it runs pretty smooth when unchecking the SkiaRaster. If there is an additional performance improvement by enabling Vulkan, it is not clearly visible, so I'll need to measure the frame rate to find.

However, unchecking SkiaRaster also disables anti-alias when drawing a path, so it is not currently an option.

Maybe that could be solved somehow by accessing the Skia Canvas?

Share this post


Link to post
30 minutes ago, Hans♫ said:

Enabling Vulkan requires to uncheck SkiaRaster, according to the description.

We are seeing a performance improvement and it runs pretty smooth when unchecking the SkiaRaster. If there is an additional performance improvement by enabling Vulkan, it is not clearly visible, so I'll need to measure the frame rate to find.

However, unchecking SkiaRaster also disables anti-alias when drawing a path, so it is not currently an option.

Maybe that could be solved somehow by accessing the Skia Canvas?

I don't know. The question is what do you get when you try enabling Vulkan. Do you have aliasing problem with Vulkan, too? Each of those checks uses completely different rendering technology. So Skia Raster canvas is a different one from Skia Vulkan.

Share this post


Link to post
40 minutes ago, Dalija Prasnikar said:

Do you have aliasing problem with Vulkan, too? 

Yes, it looks the same both with and without Vulkan: no anti-aliasing.

Share this post


Link to post
Posted (edited)
On 5/8/2024 at 5:51 PM, vfbb said:

@Hans♫ Please check your Form.Quality because the AntiAlias is direct related to the current form quality

Thank you. We had the Form.Quality set to SystemDefault, which seem to do the same as setting it to HighQuality. I tried to set it to HighQuality, but did not see any difference.

However, I just found out that with Skia+Vulkan, it actually draws with anti-aliasing, but in a very simple way.

Here is our back button. The version to the left is with no Skia. To the right it is with Skia + Vulkan:

 

<No skia | Skia+Vulkan>

Normal.png.d26a67f0a6f00f22073b23fd6bc559a4.png

 

I though the Skia+Vulkan version was not anti-aliased, but when enlarging, I can see that it is:

Enlarged.png.a600be6c5cff0d33bd7184d08f6588b2.png

The quality of the anti-aliasing is simply lower with Skia+Vulkan (and the forms quality is set to high quality).

Is there a way to change that?

Edited by Hans♫

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×