About vectorization and planar channels in Krita

Dmitry Kazakov dimula73 at gmail.com
Fri Sep 28 13:39:03 UTC 2012


Hi!

After that long discussion about grayscale selections I decided to check
whether we really need planar channels for implementing the vectorization
in Krita. And it turned out, that we need *not* do it. The SIMD
instructions cannot work with bytes directly (we won't be able to multiply
anything), so in both of the cases, when we use planar bytes and not, we
will have to convert the pixel data into some other format: single
precision float or single word integer, doing some inevitable permutations
and wasting time on them. The flat channels will give us no help with it.

What we really need to do is just to use the advantages of RGBA pixel
layout (better data locality and good alignment) and optimize our code. As
a proof of concept, I've written a small benchmark, that compares our
standard integer COMPOSITE_OVER algorithm against its SIMD (avx)
implementation. The streamed implementation showed a 3.3 times better speed
than the algorithm we use right now. More than that, this sketch was
written in just a day so it has lots of possibilities for optimization (it
can be modified to process 10.6 pixels at a time instead of 8, for example).

The actual results of composing of 32 MPixels:

TestAvxCompositeOverTest::testPerPixelComposition(): 370 msecs
TestAvxCompositeOverTest::testAVXComposition():      147 msecs
TestAvxCompositeOverTest::testAVXCompositionx2():    113 msecs

What I want to tell with this mail:
1) There is no need to port the whole Krita to use some other channel
layouts. Even current layout gives us lots of possibilities to optimize our
code.
2) We still need to decide what to do with grayscale selections.

-- 
Dmitry Kazakov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kimageshop/attachments/20120928/5cfa9755/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst_testavxcompositeovertest.cpp
Type: text/x-c++src
Size: 16512 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kimageshop/attachments/20120928/5cfa9755/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestAvxCompositeOver.pro
Type: application/octet-stream
Size: 428 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kimageshop/attachments/20120928/5cfa9755/attachment.obj>


More information about the kimageshop mailing list