Fps limit configuration
ClosedPublic

Authored by poke1024 on Oct 8 2017, 10:40 AM.

Details

Summary

Something I built for myself for doing some tests, not sure if this is interesting for a wider public.

Adds a configuration setting that limits the frames per second Krita heads for:

On OS X, at least 70% to 80% of the main thread is blocked inside OpenGL calls, Krita's own but QT GL compositor code as wel and there's nothing we can do about it (using non-GL output is even worse as it uses CPU based QRasterPainter)l. During that time, events like stylus tablet events are delayed (and dropped by the OS it seems to me). Reducing the fps can improve this situation by giving more time in the main thread to event handling. Obviously this hurts visual feedback.

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
poke1024 created this revision.Oct 8 2017, 10:40 AM

Might make more sense to actually move the OpenGL rendering code to another thread... iirc Boud considered doing this some time ago.

poke1024 added a subscriber: rempt.Oct 8 2017, 7:20 PM

@alvinhochun @rempt This is definitely the right idea and it would be so great having this as it's the one central performance hog on macOS. Alas, I spent a day last week trying to do exactly that and had to find out that with the current QT implementation there's seemingly no way to do it. It used to be possible with QT 4. But with QT5 and QTQuick, the compositing in the main thread doesn't inform any other thread of when the context is occupied and QT crashes with an assertion that a context cannot be used by two threads. The official sample code (https://github.com/qt/qtbase/blob/5.9/examples/opengl/threadedqopenglwidget) is a hack and only works as long as the OpenGL runs in a separate window without other widgets; if there are any other widgets in the other, QT's compositing code fails to properly call onAboutToCompose and onFrameSwapped and so the whole fragile GL context grabbing logic breaks down. It's sad state of affairs with QT.

Deevad added a subscriber: Deevad.Oct 8 2017, 7:54 PM

I like it.

rempt accepted this revision.Oct 9 2017, 8:54 AM

So, basically we have to choose between having QtQuick based components (currently two dockers in master) or moving the rendering to another thread? If that's the case, I think we should get rid those components and go for rendering in a thread.

In any case, this limit slider works for me, although even when set to 20, I don't really have a problem with responsiveness :-)

This revision is now accepted and ready to land.Oct 9 2017, 8:54 AM
This revision now requires review to proceed.Oct 9 2017, 9:07 AM

Hi, @poke1024!

Could you check if glSync functionality actually works for you (m_d->canvasWidget->isBusy())? Because that is an already present functionality on limiting FPS. It doesn't issue one more frame until the previous one is fully processed.

To check that glSync functionality works, you need to activate "Enable debug logging of openGL framerate" in the performance tab, restart Krita and then look into the debugging output. You should lines like:

glSync effectiveness: 0.0818363

If "effectiveness" is exactly 0.0 or 1.0, then glSync doesn't work and you should try to fix it first. If not, then the patch is perfectly fine to be pushed.

So please check glSync() thing and, if it works fine for you, just push the patch. If not, we should work on the fix further

PS:
Qt must *not* drop any tablet events even if the main event loop is busy 100% of the time. That is what we fought for on Linux and Windows, and the same thing should be on OSX. We will never manage to make main thread free enough to guarantee responsiveness at 8 (!) ms, which is the rate at which tablet events come.

rempt added a comment.Oct 9 2017, 9:49 AM

To achieve that, we might have to re-implement Qt's tablet support ourselves, like we do on Windows and OSX...

In D8193#153655, @rempt wrote:

To achieve that, we might have to re-implement Qt's tablet support ourselves, like we do on Windows and OSX...

Or just patch it before building as we did a couple of times :)

Anyway, it is still not much related to the patch in question.

Hi @dkazakov,

the glSync functionality works for me as expected (e.g. glSync effectiveness: 0.0598802).

The QT "no drop" situation is good to hear :-) Though I still get the impression that there is someone dropping on OS X. Might be the OS, might be Wacom's driver. Nothing I can pinpoint, just the impression that some random jerkiness is going on. But it's good to know that QT gives us everything it gets.

I'll push this now.

This revision was automatically updated to reflect the committed changes.