Pyry Haulos
2007-Mar-16 23:47 UTC
[compiz] [PATCH] Rendering: swap buffers and copy only needed parts
Hi, I've been experiencing serious tearing in compiz when screen is painted only partly. Either "Sync To Vblank" option in compiz doesn't work or copying repainted parts from backbuffer to frontbuffer is too slow. And since many people rely on driver's implementation of Sync to Vblank, it would be optimal to always use glXSwapBuffers. This can be accomplished via keeping up-to-date copy of frontbuffer in backbuffer and painting updates over it. My patch (swap-buffers-and-copy-only-needed.patch) keeps copy of last painted region and in case of partial screen repaint uses it to determine which parts should be copied from frontbuffer to backbuffer. Since region going to be painted this time is known, it can be substracted from last painted region. Thus only parts that were painted in previous pass and aren't going to be repainted, are copied saving expensive pixel copy operations. Since glxCopySubBufferMESA does only implement copy-from-backbuffer (correct me if I'm wrong) it is no longer needed (remove-copySubBuffer.patch). I've been using this a quite long time and it works generally well. Problem arises only when a plugin paints outside of the given region. For example screenshot (quick-n-dirty patch provided) and scale (shadows don't belong to damaged area, causing slowly darkening and finally solid black border around scaled windows) do that. Pyry -------------- next part -------------- A non-text attachment was scrubbed... Name: remove-copySubBuffer.patch Type: text/x-diff Size: 1444 bytes Desc: not available Url : http://lists.freedesktop.org/archives/compiz/attachments/20070317/b21ad045/remove-copySubBuffer.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: screenshot-dont-paint-outside-damage-region.patch Type: text/x-diff Size: 1523 bytes Desc: not available Url : http://lists.freedesktop.org/archives/compiz/attachments/20070317/b21ad045/screenshot-dont-paint-outside-damage-region.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: swap-buffers-and-copy-only-needed.patch Type: text/x-diff Size: 3567 bytes Desc: not available Url : http://lists.freedesktop.org/archives/compiz/attachments/20070317/b21ad045/swap-buffers-and-copy-only-needed.bin
David Reveman
2007-Mar-29 10:07 UTC
[compiz] [PATCH] Rendering: swap buffers and copy only needed parts
On Sat, 2007-03-17 at 08:20 +0200, Pyry Haulos wrote:> Hi, > > I've been experiencing serious tearing in compiz when screen is painted only > partly. Either "Sync To Vblank" option in compiz doesn't work or copying > repainted parts from backbuffer to frontbuffer is too slow. And since many > people rely on driver's implementation of Sync to Vblank, it would be optimal > to always use glXSwapBuffers. This can be accomplished via keeping up-to-date > copy of frontbuffer in backbuffer and painting updates over it."Sync To Vblank" works perfectly for me last time I tried it. Your driver need to support it. Direct rendering is required and nvidia's driver is the only way to get this right now. Relying on the driver to force "Sync To Vblank" when glXSwapBuffers is called is usually a very bad idea as if used with indirect rendering it most likely causes the X server to block when swapping buffers and this has horrible performance affects on the X server.> > My patch (swap-buffers-and-copy-only-needed.patch) keeps copy of last painted > region and in case of partial screen repaint uses it to determine which parts > should be copied from frontbuffer to backbuffer. Since region going to be > painted this time is known, it can be substracted from last painted region. > Thus only parts that were painted in previous pass and aren't going to be > repainted, are copied saving expensive pixel copy operations. > > Since glxCopySubBufferMESA does only implement copy-from-backbuffer (correct > me if I'm wrong) it is no longer needed (remove-copySubBuffer.patch). > > I've been using this a quite long time and it works generally well. Problem > arises only when a plugin paints outside of the given region. For example > screenshot (quick-n-dirty patch provided) and scale (shadows don't belong to > damaged area, causing slowly darkening and finally solid black border around > scaled windows) do that.There's a few cases where this is very hard to prevent. The current design relies on it being allowed to draw things outside the screen region we're updating. It's especially important for the blur plugin. - David