Squeezing more performance out of Skia

14 views
Skip to first unread message

Jeru Sanders

unread,
Nov 21, 2021, 3:06:12 PM (12 days ago) Nov 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 PM (12 days ago) Nov 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 PM (12 days ago) Nov 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 PM (12 days ago) Nov 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 PM (12 days ago) Nov 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.
Reply all
Reply to author
Forward
0 new messages