Link Mauve’s Blog

Bringing GPU Acceleration to Inkscape, Week 2

Published the

Hello everyone!

For the past two weeks since the beginning of this GSoC 2020 I have attempted to integrate Pathfinder into Inkscape, in order to draw (and refresh!) the canvas much faster by using your GPU.

After some early attempts, where I created a C++ Inkscape extension opening Pathfinder’s demo on the current SVG, and another extension which was basically a copy of Pathfinder’s C canvas example, I’ve started to properly integrate it into Inkscape’s widgets.

That’s where the fun began, here is a small tour of the fun bugs I encountered:

Using apitrace On Wayland Can Be Interesting

apitrace is a very handy tool for debugging OpenGL applications, it avoids having to understand the code’s structure, and allows me to focus on the actual behaviour from the driver’s point of view.

glXGetCurrentContext() not found: /usr/bin/../lib/apitrace/wrappers/egltrace.so: undefined symbol: glXGetCurrentContext
apitrace: warning: caught signal 6

I was a bit sad to see that a bug I found at the intersection of apitrace and libepoxy back in 2015 reappeared now, this time caused by GDK doing the same. In the end I rebuilt both libepoxy and GTK+ with only their Wayland backend so they wouldn’t be tempted to call GLX symbols. This breaks Firefox and probably some other software which link against their X11 symbols, but on my build/testing machine it’s fine.

Speaking of running a (soon-to-be) OpenGL program on a remote machine, waypipe from last year’s GSoC is extremely useful, it feels almost instantaneous on my 900 KiB/s down 80 KiB/s up ADSL connection. For comparison, I also tried X11 forwarding over ssh which only shows Inkscape’s window after 1:05, and also mounting the build directory over sshfs where it takes 1:20 to do the same, and 6:40 (!) to generate a stack trace in case of a panic. I probably should have figured that out during the community bonding period, but I didn’t think of it.

Pathfinder Doesn’t Like To Draw Into Gtk::GLArea Very Much

I spent quite a few days trying to get Pathfinder to draw into a GTK+ widget, first inside of Inkscape, then in a testcase application. The Gtk::GLArea widget lets an application draw using OpenGL. I want it to eventually replace Inkscape’s SPCanvas, once I’m done and Tavmjong as well, but in the meantime I’ll keep them both side-by-side in order to compare their rendering more easily.

Despite the rendering being done, according to apitrace’s step-by-step debugging, the Gtk::GLArea stayed hopelessly black. Even though I could render a simple solid colour using glClearColor() and glClear(GL_COLOR_BUFFER_BIT), as soon as I tried to render using Pathfinder it went back to a solid black.

Experimenting with the OpenGL contexts, I could make Pathfinder render its iconic tiny house everywhere but where I wanted it:

Here is a particularly trippy rendering I got, when Gtk::GLArea is reading from a framebuffer Pathfinder hasn’t written into:

It was only with the help of sebk that I finally figured out that I wasn’t passing the correct fbo to Pathfinder. I was passing 0 which means the default (display’s) framebuffer instead of the one created for me by GTK+. With this fixed, everything rendered fine, even on resize:

After that it was a simple matter of adding some API to Pathfinder’s C bindings and I can render the same SVG as Inkscape!

On the left hand side we can see poezio’s logo rendered by Inkscape with cairo; on the right hand side the same logo being serialised and passed to Pathfinder to be rendered on the GPU.

And this concludes my first progress report of this GSoC, a big thanks to ebassi, halfline and Neville[m] from #gtk, and especially sebk from #pathfinder, who helped me a lot in that process!