by coffeeaddict1 · 2y ago · 0 comments
I wish there was a nice and small vector graphics library with GPU acceleration. So far Skia is the only real option, despite its downsides.
Maybe once a year I bite the bullet, do a new Skia build on all the platforms, and then I have to figure out how the C++ API has changed. At least that’s just rote work of fixing compiler errors by looking at the new header files.
Even though it’s a pain in the ass, I still use Skia because it’s got the best combination of performance and features. Sadly Cairo doesn’t quite compete. Skia gives my project a pretty good guarantee that 2D graphics render like in Chrome, and that’s important for this use case.
Yes. So in Sciter I've replaced its build system with relatively simple premake5 script. That replacement took couple of days but was worth it. Premake5 generates human-readable IDE solutions and make files. So you need just a compiler to build the whole thing.
> building it from source takes 20-30 minutes on a modern laptop.
It is not that bad actually. Just tried full rebuild of x64/Windows version:
Whole sciter.dll (HTML/CSS/JS/Graphics) with Skia backend:
sciter.dll build completed at 9:11 AM and took 07:03.415 minutes
Same sciter.dll but with Direct2D backend: sciter.dll build completed at 9:22 AM and took 02:34.412 minutes
So Skia takes ~4 minutes to build on pretty average development desktop machine.> it's constantly changing its APIs
That's very true and is a pain indeed if to change its version frequently. Yet there is no such concept as "Skia version" - just revisions/milestones. It used to be an attempt to make stable plain C API but AFAIR it was removed recently.
Same thing about Google ANGLE that I started to use recently in Sciter.GLX: https://sciter.com/sciter-glx-beta2/
premake5 is a monolithic/portable executable that contains Lua + specific runtime.
Thus it does not rely on installed Python as in GN case as other tools.
Having standard and well known and documented Lua on board benefits the maker a lot. In my opinion any modern build system must include generic and known PL.
And that above is the problem of modern CMake. It started as simple static declarative thing but life forced it to evolve into dynamic programming language with very strange notation and runtime model.
I'm curious if you can expand on how you're using python, and what pain points you have there? I think python 3.9 was one for us but not too bad.
I'm personally skeptical about GPU acceleration being the answer to 2D rendering for various reasons.
I'm looking forward to Blend2D < https://blend2d.com/ > which is JIT based maturing and being the preferred solution.
I believe the best way is probably to use Blend2D for rendering glyph bitmaps and then compositing them into the full text on GPU.
Sadly, CPU memory is still plenty slow compared to GPU memory and when you need to copy around 100 MB images (4K RGB float), then that quickly becomes the limiting factor.
At the moment when you render text Blend2D queries each character from the font and then rasterizes all the edges and runs a pipeline to composite them. All these steps are super optimized (there is even a SIMD accelerated TrueType decoder, which I have successfully ported to AArch64 recently), so when you compare this approach against other libraries you still get like 4-5x performance difference in favor of Blend2D, but if you compare this method against cached glyphs Blend2D loses as it has to do much more work per glyph.
So the plan is to use the existing pipeline for glyphs that are larger (let's say 30px+ vertically) and to use caching for glyphs that are smaller, but how it's gonna be cached is currently in research as I don't consider simple glyph caching in a mask a great solution (it cannot be sub-pixel positioned and it cannot be rotated - and if you want that subpixel positioned the cache would have to store each glyph several times).
There is a demo application in blend2d-apps repository that can be used to compare Blend2D text rendering vs Qt, and the caching Qt does is clearly visible in this demo - when the text is smaller Qt renders it differently and characters can "jump" from one pixel to another when the font size is slightly scaled up and down, so Qt glyph caching has its limits and it's not nice when you render animated text, for example. This is a property that I consider very important so that's why I want to design something better than glyph masks that would be simple to calculate on CPU. One additional interesting property of Qt glyph caching is that once you want to render text having a size that was not cached previously, something in Qt takes 5ms to setup, which is insane...
BTW one nice property of Blend2D text rendering is that when you use the multithreaded rendering context the whole text pipeline would run multithreaded as well (all the outline decoding, GSUB/GPOS processing, rasterization, etc...).
You can see some existing benchmarks here:
- https://blend2d.com/performance.html
Both the benchmarking tool and Blend2D are open-source projects so anyone can verify the numbers presented are indeed correct, and anyone can review/improve the backend-specific code that is used by the benchmarking tool.I wonder what he’s up to these days?
Update/edit:
Ahh he moved on to Ampere: https://www.linkedin.com/in/carl-worth
Also I was a bad fan: the library had a co-founder too I thought it was a bespoke creation of Carl’s own making.
I remember building a bunch of stuff from source back in the day and a lot of Linux applications had Cairo as a dependency.
That's too bad. Is their a successor planned or is Skia the recommended alternative?
> There was an attempt at making Cairo support GPU rendering, which did not work particularly well due to the library being designed around stateful operation based upon the PostScript model—resulting in a convenient and familiar API, great output quality, but hard to retarget and with some particularly slow corner cases. Meanwhile, other web engines have moved more work to the GPU, including 2D rendering, where many operations are considerably faster.
https://medium.com/@gauravswarankar/flutter-will-use-an-impe...
And to do so onto multiple OS & hardware backends?
There’s no free lunch, Impeller has a different set of trade offs that are a better fit for Flutter.
CPU renderer uses a tiny, custom fork of Skia (we only use the path rasterizer and their SSE2, AVX2, NEON backends) and our GPU renderer draws directly on GPU via tessellated paths / hardware MSAA (DX11, DX12, GL, Metal, Vulkan).
There's also the question of "which parts of Skia". If there are five different conceivable ways to implement something in vector graphics, Skia will implement all five, and there will be some sort of hidden obscure configuration setting that Chrome and Android will use to determine which one actually gets used. It's a very unfriendly piece of software to use, honestly.
I found this:
https://github.com/google/skia-buildbot
Assuming that the Skia maintainers keep that working, it might be easier to build the buildbot and use that to build Skia, than to build Skia directly!
Skia really isn't that hard to use IMO even for GPU accelerated stuff.
o_O unlike GN?
Have you used it much?
I've been using it for years and have no complaints.
The official instructions are https://skia.org/docs/user/build/
As a maintainer of a project that includes another popular library from Google, here's why it's difficult to build:
- building requires downloading Googles custom toolchain and build system
- dependencies are huge, so you have lenghty download times even on fast connections
- it usually works if you are using a recent versions of OS and Python, but if you try running the same command in a year or two it might fail because they changed the requirements
- if anything fails you have to dig through multiple levels of abstractions to figure out where it failed and why
- if you want to maintain software for a few years, you'll have to keep fixing the build process because the build will suddenly stop working for unknown reasons once a year or so
Around 5 minutes.
>That's part of the build process.
It's dependent on one's internet speed so I didn't think it made much sense to time it. If it took 20 to 30 minutes to download I would have mentioned it.
If this seems like a big lift, people are going to hate building Chromium.
https://github.com/linebender/vello is written in Rust and already used as the backend for Xilem, a reactive framework for native UI.
https://skia.googlesource.com/skia/+/2e551697dc56/third_part...
My understanding, having not dug into it too much, is that the Skia integration does exist, but isn't enabled by default/any clients at the moment. That is, I don't know that this integration is shipping anywhere.
Vello still has some definite rough edges at the moment, so I'm not sure I'd recommend using it in a production application at the moment. We also don't have a C API, which might rule it out for some cases where you'd be considering Skia.
We use it in LibreOffice, but its a right pain to update versions and debugging it is.... challenging.
The upside is that the Google Skia team is super friendly and willing to help.
Check out nanovg: https://github.com/memononen/nanovg
- NanoVG
- bgfx with vg-renderer
- Impeller
- Starling