Squeezing more performance out of Skia

1,059 views
Skip to first unread message

Jeru Sanders

unread,
Nov 21, 2021, 3:06:12 PM11/21/21
to skia-discuss
What's the most performant way to render paths in Skia (gpu), right now Skia is 84% of my frame time on Windows, and even more in webgl.

Trying to narrow it down in Vtune, it seems like a lot of time is spent inside of triangulation related functions.

vtune perf.png

Right now I'm drawing everything "immediate mode" by calling stuff like paint.setColor() and path.quadTo() a whole lot, about 250 drawPath() calls per frame. But everything I draw with Skia is preloaded from an swf and isn't dynamic, outside matrix transforms. Is there a way to cache triangulation and paths operation in some kind of "SkShape" class?

I see SkPicture, but that's just a command recorder right? So that won't help. Is it viable to create thousands of SkCanvas's and draw 250 of them per frame onto the "main canvas"?

Greg Daniel

unread,
Nov 21, 2021, 3:16:44 PM11/21/21
to skia-discuss
Hi. Some of the path renderers will cache stuff to make subsequent rendering faster. For example the Triangulating path renderer will cache a GPU vertex buffer. The big thing to take advantage of this is that you must use the same SkPath object each frame. Are you creating new SkPaths each time (since you said immediate mode) or are you reusing the static SkPaths? The latter is the right pattern.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/b8f99063-3e56-4a81-9acb-e6f6f6e92b95n%40googlegroups.com.

Jeru Sanders

unread,
Nov 21, 2021, 6:02:29 PM11/21/21
to skia-discuss
Ah, I was reusing a single SkPath over and over with path.reset()'s in between. I wouldn't have thought of caching those upfront, that sounds simple enough.

Greg Daniel

unread,
Nov 21, 2021, 6:50:51 PM11/21/21
to skia-discuss
Yeah each path has an id which is what we'll used to get a key for caching stuff on the backend. This id changes whenever you change an SkPath (add verb, reset, etc.). So keeping around a const SkPath for each path you plan to redraw multiple times can have performance wins.

Jeru Sanders

unread,
Nov 21, 2021, 9:02:21 PM11/21/21
to skia-discuss
Lmao, now Skia's only 7.5% of my frame time, that translates to ~7x higher fps in game.

That's pretty amazing, I wonder how many devs are missing out on this. Caching paths like this isn't standard in the Canvas API, although I guess it does make sense to do it this way.

남세현

unread,
Aug 11, 2023, 1:14:56 PM8/11/23
to skia-discuss
Is it the right choice to cache paint as well as path?
According to the documentation (https://skia.org/docs/user/api/skpaint_overview/), it says "paints are relatively light-weight, so the client may create and maintain any number of paint objects". I am confused whether I can understand that I can create this every time without caching.
It will be easy to see if I test it, but I wanted to ask a question here.

2021년 11월 22일 월요일 오전 11시 2분 21초 UTC+9에 jerus...@gmail.com님이 작성:

John Stiles

unread,
Aug 11, 2023, 1:18:22 PM8/11/23
to skia-d...@googlegroups.com
It should be fine to recreate a SkPaint from scratch every time it's used.

That doesn't necessarily hold for the things attached to the SkPaint. For instance, if you have a very complex SkShader tree, that might be a bit expensive to set up. And if you're going to the trouble of saving your SkShader tree, you might decide it's simpler to hold onto the whole finished SkPaint. But the SkPaint itself is meant to be featherweight.


Reply all
Reply to author
Forward
0 new messages