Skip to content

Draw assistants directly on the canvas

Maciej Jesionowski requested to merge yavn/krita:uncached-assistants into master

Change the way assistants are rendered on the canvas. Instead of drawing the assistants into a pixmap, storing the pixmap in QPixmapCache, and then painting the pixmap onto the canvas, this patch skips the intermediate pixmap and draws the assistants directly on the canvas.

The QPixmapCache method is prone to a bug where the pixmap is evicted from the cache before the rendering is complete, resulting in a black rectangle. Also this method performs very poorly with hardware acceleration, because we're doing a costly texture upload, texture sampling, and blending. The performance is especially bad when assistants take a large portion of the screen when zoomed in and the canvas is zoomed or rotated.

Changes in this patch:

  • Add a menu option in Display settings to toggle assistants drawing mode
  • Use direct drawing mode by default
  • Remove the workaround detection for NVIDIA

The old options are left for troubleshooting, but it's unlikely anyone would find them to work better on the current GPU hardware.

Details

To validate the performance uplift, I have tested the following configurations:

  • Windows 11 + AMD Radeon (OpenGL)
  • Windows 11 + NVIDIA GeForce (ANGLE)
  • Ubuntu 22.04 + AMD Radeon (OpenGL)
  • Ubuntu 22.04 + software rendering
  • couldn't build Android with the master branch, sorry...

In all cases of GPU acceleration, bypassing the QPixmapCache improved the performance tremendously. In case of software rendering on a Ryzen 5 5600X, I didn't notice a difference.

Please refer to this KA post and thread for more in-depth information: https://krita-artists.org/t/analysis-of-assistant-tool-problems/76043/4?u=yrh

There's also a video comparing the old mode and new mode on AMD Radeon with OpenGL: https://www.youtube.com/watch?v=v9inL3N6SG8 (also linked in KA posts).

Test Plan

You can use assistants_stress_test.kra to test assistants' performance.

  1. Krita should start in the new Default mode, which improves the performance.
  2. Move around the canvas, especially try various zoom levels and rotation. Try painting when zoomed in.
  3. Open Settings > Configure Krita > Display and change Assistants Mode from Default to one of Pixmap Cache options. Switching to pixmap doesn't require a restart, but using a large pixmap does. If you see a black rectangle bug, restart Krita.
  4. Compare the performance of zooming, rotating, and painting on the canvas. It should be very choppy compared to the new "Default" mode.

image

Expectations

(These screenshots use a modified FPS display, which isn't changed in this patch.)

Before

image

After

image

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.

Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list, kimageshop@kde.org.

Merge request reports

Loading