Bug 361619

Summary: Input event lag/drop-out when OpenGL is ON with large window
Product: [Applications] krita Reporter: Tyson Tan <tysontanx>
Component: OpenGL CanvasAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: major CC: dimula73, griffinvalley, halfspike, halla
Priority: NOR    
Version First Reported In: 3.0 Alpha   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Krita 3.0 Alpha input lagging when OpenGL is ON with large window
Krita 3.0 Alpha input not very lagging when OpenGL is ON with small window
Krita 3.0 Alpha input not lagging when OpenGL is OFF with large window
Krita 3.0 Alpha input lagging when OpenGL is ON with large window, tablet log
Krita 3.0 Alpha input not very lagging when OpenGL is ON with small window, tablet log
Krita 3.0 Alpha input not lagging when OpenGL is OFF with large window, tablet log
Krita 3.0 alpha slow antialiasing
Recored desktop video of Krita 3.0 alpha lags when OpenGL is ON
Recored desktop video of Krita 2.9.11 drawing when OpenGL is ON

Description Tyson Tan 2016-04-11 08:26:35 UTC
In Krita 3.0 Alpha (Krita-3.0-Alpha-master-e5109c2-x86_64.AppImage), when OpenGL is ON and Krita's window is large -- 1920x1080 maximized window, or a windows that is almost that big but not maximized, I can notice input lag from my graphics tablet and mouse. Some curves I drew even has straight line sessions in them, probably due to event drop-out.

When Krita's window is smaller -- around 1280x800 or 960x1080, the lagging seems to be much less noticeable. When OpenGL is OFF, the lag didn't happen at all.

I will upload screenshots and tablet logs for each testcase.

Reproducible: Always
Comment 1 Tyson Tan 2016-04-11 08:28:36 UTC
Created attachment 98328 [details]
Krita 3.0 Alpha input lagging when OpenGL is ON with large window
Comment 2 Tyson Tan 2016-04-11 08:29:39 UTC
Created attachment 98329 [details]
Krita 3.0 Alpha input not very lagging when OpenGL is ON with small window
Comment 3 Tyson Tan 2016-04-11 08:31:54 UTC
Created attachment 98330 [details]
Krita 3.0 Alpha input not lagging when OpenGL is OFF with large window
Comment 4 Tyson Tan 2016-04-11 08:32:59 UTC
Created attachment 98331 [details]
Krita 3.0 Alpha input lagging when OpenGL is ON with large window, tablet log
Comment 5 Tyson Tan 2016-04-11 08:35:24 UTC
Created attachment 98332 [details]
Krita 3.0 Alpha input not very lagging when OpenGL is ON with small window, tablet log
Comment 6 Tyson Tan 2016-04-11 08:38:24 UTC
Created attachment 98333 [details]
Krita 3.0 Alpha input not lagging when OpenGL is OFF with large window, tablet log
Comment 7 Tyson Tan 2016-04-11 08:43:51 UTC
Tested on Ubuntu 15.10 64-Bit
CPU: Intel® Core™ i5-3470 CPU @ 3.20GHz × 4
RAM: 15.6 GiB
GPU: AMD Firepro V4900, opensource driver, Gallium 0.4 on AMD TURKS (DRM 2.43.0, LLVM 3.6.2)

Krita 2.9 runs fine on this setup.
Comment 8 wolthera 2016-04-11 12:26:30 UTC
did you turn off instant preview via view? It might be affecting thing as well?
Comment 9 Tyson Tan 2016-04-11 13:21:51 UTC
Hi wolthera, that option has no effect at all.

I've also tested this on another PC running Xeon E3-1230v5 and AMD Firepro W5100 using proprietary driver, the result was the same.
Comment 10 Halla Rempt 2016-04-11 19:10:23 UTC
Hm... Both graphics cards are amd's. Could you check what happens if you disable "Use Texture Buffer"? We added that option because on AMD gpu's that often improves performance.

It's really provoking... Here on an Nvidia card, I _cannot_ get bended lines anymore. If I start Krita under valgrind, I can draw spirals, and it takes ages before they pop up on the screen, but when they do, they're perfectly round :-(
Comment 11 Tyson Tan 2016-04-12 00:31:18 UTC
Hi Boud, that option has no effect either. As long as OpenGL is ON, I can't find any options that can alleviate the problem. If there is more test I can do, please tell me how to.
Comment 12 Halla Rempt 2016-04-12 06:22:48 UTC
Could you make a test with performance logging and opengl logging enabled? Also, which preset are you using to test with?
Comment 13 Tyson Tan 2016-04-12 07:40:24 UTC
I tested mostly using Fill_circle but every preset lags.

I tried enabling logging but I could find the log. Krita says it saves those in <working_dir>, I suppose it's the same directory where I saved the .kra file? The terminal returns:
QIODevice::write (QFile, "log/Fill_block.stroke.rdata"): device not open
Requested FPS: 16.4121
QIODevice::write (QFile, "log/Fill_circle.stroke.rdata"): device not open
Requested FPS: 35.841
Requested FPS: 113.739
QIODevice::write (QFile, "log/Ink_gpen_10.stroke.rdata"): device not open
Requested FPS: 8.15437
Requested FPS: 59.5519
Requested FPS: 123.021
Comment 14 Halla Rempt 2016-04-12 10:20:13 UTC
That actually sounds like Dmitry's logging code got broken! I'll try to investigate it
on the train home from work...
Comment 15 Tyson Tan 2016-04-12 11:43:06 UTC
I've built Krita 3.0 Alpha locally, and things behave a bit differently now:

1. Krita's performance logging still fails, but it now shows "QFSFileEngine::open: No file name specified" instead.

2. Slowdowns still occur when drawing, but at least curves do not occasionally become straight lines anymore. But the canvas updates even slower. I can feel it updates only 4 or 5 times during a very long stroke.

3. It's so slow that I can see a curve stroke with zig-zag at its edge, then about 1 second later the antialiasing makes it smoother.

4. Appimage version uses GTK file dialogue. Local build uses KDE file dialogue.
Comment 16 Tyson Tan 2016-04-12 12:00:56 UTC
Created attachment 98352 [details]
Krita 3.0 alpha slow antialiasing

LEFT: during the stroke
RIGHT: 1 second after the stroke is made
Comment 17 Tyson Tan 2016-04-12 12:40:49 UTC
Tested under Windows 10 x64 on my Xeon/Firepro W5100 machine. There is no slowdown or it was very hard to notice. Curves don't become straight lines.

However, the slow antialiasing described in Comment 16 is still noticeable. And the canvas updates in multiple noticeable horizontal stripes.
Comment 18 Dmitry Kazakov 2016-04-12 16:18:15 UTC
Hi, Tyson!

I will try to investigate into your slowdown bug now.

The antialiasing bug happens because of Instant Preview functionality. If you disable it, the lines will be correct right from the beginning.
Comment 19 Halla Rempt 2016-04-12 16:23:18 UTC
Dmitry is looking into it:   https://phabricator.kde.org/T2224

It's probably an AMD specific issue:

18:20:21 < dmitryK|log1> boud: looking at his log I can guess that fence sync doesn't work
Comment 20 Dmitry Kazakov 2016-04-12 20:15:50 UTC
Hi, Tyson!

Can I ask you to record a video with the slowdown? Activate crosshair cursor + brush brush outline dispay, so I could see the real delay.

I would also like to know, what happens if you activate openGL performance logging and do a very long stroke (20-30 seconds long). Do you see any "glSync effectiveness" lines in the terminal output?
Comment 21 Tyson Tan 2016-04-13 03:51:21 UTC
Hi Dmitry, When using the Appimage version, with Crosshair cursor, Brush Outline and Instant Preview, logging options all checked, Krita crashes immediately. The terminal says "Segment fault". I don't see "glSync effectiveness" lines in the terminal when I draw long strokes.

Meanwhile, I'm preparing means to record video on my PC. Will report back later.
Comment 22 Tyson Tan 2016-04-13 03:52:32 UTC
Correction for Comment 21:
When using the Appimage version, with Crosshair cursor, Brush Outline and Instant Preview, logging options all checked, Krita crashes immediately WHEN I DRAW SOMETHING.
Comment 23 Tyson Tan 2016-04-13 04:19:19 UTC
Created attachment 98369 [details]
Recored desktop video of Krita 3.0 alpha lags when OpenGL is ON
Comment 24 Tyson Tan 2016-04-13 04:20:26 UTC
Created attachment 98370 [details]
Recored desktop video of Krita 2.9.11 drawing when OpenGL is ON
Comment 25 Halla Rempt 2016-04-13 13:33:49 UTC
Dmitry's laptop has an amd gpu, but that doesn't work at all. We're speccing & pricing a test system now so the Foundation can buy one for Dmitry. It'll also be useful to check the other bug reports we have about amd gpu and cpu's :-)
Comment 26 Halla Rempt 2016-04-13 13:43:20 UTC
Plotted measurements: http://nonaynever.ru/pub/tablet_logging.pdf
Comment 27 Tyson Tan 2016-04-14 01:36:40 UTC
GPU wise you may consider:

AMD Radeon R7 360 -- basically the same chipset as AMD Firepro W5100, supports D3D 12, OpenGL 4.5 and OpenCL 2.0, with a TDP of 100W, requires a 6pin power supply. Price range: $109.

AMD Radeon HD 6570 -- basically the same chipset as AMD Firepro V4900, supports D3D 11, OpenGL 4.4 and OpenCL 1.2, with a TDP of 60W, doesn't require a 6 pin power supply and has a smallform factor. Price range: $39.

I have been using their equivalent AMD Firepro cards, so I suppose they won't give you hard times under GNU/Linux. Personally, I would recommend HD 6570 because it's cheaper, cooler and has well-matured open source drivers. It should be much easier to manage.

As for CPU (APU):

AMD A8-7600, the most popular APU in recent AMD generations, supports AVX, has an integrated R7 GPU so you might save the GPU. TDP 65W. Price range: $109($79 at constant sale). 

Use with an A88X chipset motherboard. I suggest ASUS A88XM-A, it might give you less trouble because of a potentially better BIOS. Price range: $149.

The APU plan is probably better because you may want to test against every aspect of AMD's shenanigans. XD
Comment 28 Halla Rempt 2016-04-14 09:30:24 UTC
11:29:04 < dmitryK|log> boud: ok, ordered with delivery on Saturday :)
11:30:04 < dmitryK|log> boud: Tyson's recommendations are almost exactly the same as I ordered
Comment 29 Halla Rempt 2016-04-16 13:57:09 UTC
The box is being assembled :-)
Comment 30 Dmitry Kazakov 2016-04-18 17:23:22 UTC
I got a new PC with AMD on Saturday. The first tries show that the problem is not only in AMD. It is in combination of Qt 5.6, AMD and openGL mode. Absence of any part of the equation, make the bug not reproducible :) E.g. Qt 5.6 + Haswell + openGL works fine, Qt 5.5.1 + AMD + openGL works also fine :)
Comment 31 Tyson Tan 2016-04-19 00:47:30 UTC
But I'm using Ubuntu 15.10, it has Qt 5.4.2 with it. Both AppImage and my local build had this problem, while Windows version seems to work fine. I'm not very sure about the speculation in Comment 30.
Comment 32 Dmitry Kazakov 2016-04-20 08:51:13 UTC
Well, AppImage has Qt 5.6 bundled inside :) Anyway, I'm going to work on this bug today
Comment 33 Tyson Tan 2016-04-20 11:32:35 UTC
I mean, I built my own binaries from the source code on Ubuntu 15.10, and it still has the same problem.
Comment 34 Dmitry Kazakov 2016-04-20 20:07:46 UTC
Hi, Tyson!

Did you compile Qt yourself or you use the system's one? Qt 5.4.2, right?

The point is that the real cause of bended lines was introduced in Qt 5.6. But if you say that Qt 5.4.2 is also affected, then it starts looking a bit too weird :)
Comment 35 Dmitry Kazakov 2016-04-20 20:41:36 UTC
Git commit 31195a85a054e50af2d61ae764f341db12190f1e by Dmitry Kazakov.
Committed on 20/04/2016 at 20:03.
Pushed by dkazakov into branch 'master'.

Fix a "bended lines"+AMD+Qt5.6 bug

The bug is actually in Qt 5.6. They decided to implement a motion event
compression without *any* way to disable it. So we have a lot of events
dropped resulting in "bended lines" on canvas.

For some reason the bug is reproducible on AMD GPUs only, with openGL
activated. It seems like either Qt asks for some synchronization, or
rendering on AMD is just too slow. I don't know the exact reason,
but being busy with rendering makes Qt drop a lot of events.

Since this event compression cannot be disabled in any official way, we
should start patching Qt on Linux as well. Yes, it means that Krita 3.0
cannot be distributed through official distribution repositories. Which
means that Krita Lime will have to be shut down as soon as Ubuntu 16.04
will upgrade to Qt 5.6.

CC:kimageshop@kde.org
CC:Shawn.Rutledge@theqtcompany.com
Fixes T2224

M  +1    -0    3rdparty/ext_qt/CMakeLists.txt
A  +20   -0    3rdparty/ext_qt/qt-no-motion-compression.diff

http://commits.kde.org/krita/31195a85a054e50af2d61ae764f341db12190f1e
Comment 36 Tyson Tan 2016-04-22 03:30:22 UTC
Thank you! Please update the Krita Lime PPA so I can test them. Krita 3.0 builds are only available for 16.04 so I upgraded to it, but Krita 2.9.11 from that PPA is not installable as it requires libgsl0ldbl (>=1.9), while Ubuntu 16.04 LTS supplies libgsl2 (2.1+dfsg-2).
Comment 37 Tyson Tan 2016-04-22 05:21:09 UTC
Just tested Krita3-testing (2+git20160407+r9-67~ubuntu16.04.1) from Krita Lime PPA on Ubuntu 16.04. The slowdown did not happen.

Well I don't know what is happening anymore XD

Anyway. I will be using krita3-testing from now on (unless it has major malfunction), and report the bugs I encountered.
Comment 38 Dmitry Kazakov 2016-04-22 08:18:33 UTC
Hi, Tyson!

Ubuntu 16.04 has Qt 5.5.1, so the problem will not happen on it at all, until Canonical decides to update it. Though atm we are discussing with people in Qt how we can workaround it and make Krita Lime still available to the users even when Ubuntu is updated.

This weekend we are going to build new AppImage builds. Could you please check them when they are released? They are from the affected group, but now the bug should not happen anymore! :)
Comment 39 Tyson Tan 2016-04-22 08:43:57 UTC
Thanks! Silly me to think 16.04 would have included the newest Qt...as if they ever did! lol
Comment 40 Dmitry Kazakov 2016-04-22 09:48:24 UTC
Hi, Tyson!

Still they include a better Qt than 15.10. I cannot remember what exactly, but some small Krita features are disabled on Qt 5.4 :)
Comment 41 Dmitry Kazakov 2016-04-22 15:56:20 UTC
Git commit 3fba314ffa7fcb3d07f62be9f04fbe5ad8978286 by Dmitry Kazakov.
Committed on 22/04/2016 at 15:56.
Pushed by dkazakov into branch 'master'.

Add a workaround for Qt's event compression bug

This environment variable will appear only in Qt 5.6.1. Before that
we will still have to patch it manually.

https://codereview.qt-project.org/#/c/156755/

M  +10   -0    krita/main.cc

http://commits.kde.org/krita/3fba314ffa7fcb3d07f62be9f04fbe5ad8978286
Comment 42 Halla Rempt 2016-04-29 08:48:57 UTC
*** Bug 362444 has been marked as a duplicate of this bug. ***