Compositing on separate thread(s)
While testing compositing timing (with per screen rendering unlocked), I've noticed a common pattern that looks something like this
Compositing on the 144Hz monitor usually finishes on time, but then, all of sudden, the 60Hz monitor needs to be repainted. Due to the contention, we miss the deadline on the 144Hz monitor. However, most likely, we would've finished compositing on time if not because of the 60Hz monitor.
In order to fix that point of contention, we need to perform compositing on separate threads. The tricky part is that the effects system is written in "single-threaded fashion." In addition to that, KWaylandServer code is not thread-safe. Fixing that will be unfeasible.
A better (and more reasonable) approach to tackle this issue would be to create a Scene (and all effects) per individual composited output. On X11, things would stay the same way, but on Wayland, every output will have its own Scene. The effects
pointer will become a thread-local global.
Before a render thread starts compositing, it has to synchronize its state with the main thread. After that it can proceed to recording render commands, etc. Going with this design may involve changes in some effects.