mypaint / libmypaint

libmypaint, a.k.a. "brushlib", is a library for making brushstrokes which is used by MyPaint and other projects.
http://mypaint.org
Other
307 stars 87 forks source link

GPU driven optimization #162

Closed TheJackiMonster closed 4 years ago

TheJackiMonster commented 4 years ago

I really like this software because it is way easier to use for me than GIMP or Krita on my graphic tablet. I like that I can control everything I need with just my pen without turning around to my keyboard or searching minutes through some menus. So you made a really good job so far...

But one thing annoys me a little. I get lags during editing my paintings and I know this program could easily display them smooth without these problems if it would use some proper acceleration. Because moving or just drawing layers can be done parallel for its pixels.

But at the current state (I checked out 2.0.0-beta.0.37) it uses only one of the threads of my CPU for 100% when I move the view around my layers or when I move a layer. It doesn't even make proper use of my GPU.

So I would like some optimizations in an upper release to look forward to. First I think this program could make use of some multi-threading which is easier to implement and after that it should get some performance improvement via using compute shaders on the GPU (or maybe only basic rasterization).

briend commented 4 years ago

GPU support is not very likely any time soon, unless someone more experienced can contribute. The released binaries of MyPaint have to be generic for compatibility with a large variety of CPUs. If you have any means to compile mypaint/libmypaint from source, you could enable optimizations for your specific CPU. This can dramatically improve performance and utilize more cores as well as autovectorization.

https://github.com/mypaint/mypaint/blob/master/BUILDING.md#using-optimization-flags

Also, the Pigment layer and brush modes are quite a bit slower. If you don't appreciate the blending you can use Normal mode and turn off Pigment, etc, which will speed things up quite a lot.

jplloyd commented 4 years ago

@TheJackiMonster The primary new source of slowdown since the MyPaint 1.2.1 release is indeed the pigment blending. If you don't want or need that, you can go to your compatibility settings (last tab in preferences) and set it to use the 1.x mode by default. That will speed up both drawing and the screen updates.

Another smaller source of slowdown is the 8x increase in number of control points for input mappings (from 8 to 64), which probably affects memory locality when calculating the dynamic brush values (even though most of them are not used).

I hope that multithreading can be put to more use in the future. In MyPaint it's currently only used for morphological operations in the fill tool. GPU-driven optimizations are less likely in the immediate future, but if you want to prototype something in that area you are most welcome!

TheJackiMonster commented 4 years ago

Thank you very much for the quick reply and the advices. It helps a lot already.

I can probably try to work on a solution with OpenCL or OpenGL. But it could take some time until I have finished the projects I am working on currently. I guess it would be best to implement it as optional dependency if I do so, right?

jplloyd commented 4 years ago

Yes, it should be an optional dependency.

I will say that I think you won't see much performance improvement from changes done only in libmypaint - I think most performance-critical issues (except for pigment blending, which briend already has a solution to) come down to the way rendering is handled in MyPaint itself.

It's worth keeping in mind that brush strokes are (in the general case) very sequential in their nature, and the only parallelism I can see being applied (again, in the general case) is far dabs that are large enough to cross multiple tiles. But anyway, good luck with your work!

TheJackiMonster commented 4 years ago

Hmm, I have tested with the current state and MyPaint seems to use all of my cores now. Maybe it was unrelated to MyPaint since 1.2.1 makes use of them too and I can't remember a package upgrade. I could also detect the GPU usage of around 20% when I stressed it. This should relate to updating the pixbuf via Gtk. The biggest problem I still have in 1.2.1 is the lags during zooming in drawings with many layers but 2.0.0-beta.0.76 seems to have fixed it. Good job guys, I guess! ^^ At least I have found the point to in the source from MyPaint itself where the rendering is done. So I guess this issue can be closed here.