Asynchronous Display Flipping for Linux

Using display (or plane or page) flipping is a nice optimization for screen updates as it avoids copying the application render buffer to the separate scanout buffer. However, in the current DRM interface, the flip operation is not performed immediately. Rather, the flip operation must be presented to the kernel before the vertical blank interval preceding the desired display time.

If the flip operation is even slightly delayed, the new scanout image will not be visible until the following frame. With many applications pushing the performance of the graphics hardware right to the edge, it's not at all uncommon for an occasional frame to 'just miss' and cause an ugly jerk on the screen.

The GLX_EXT_swap_control_tear extension provides a way for applications to request that when the swap request is delivered too late, instead of delaying for the next frame, the contents should be presented as soon as possible, even if that might cause some tearing artifacts on the screen. This gives the application developer the choice between the two visual artifacts (tearing vs judder).

A Linux interface for Async Flipping

This part was pretty easy to implement.

First, a new capability value, DRM_CAP_ASYNC_PAGE_FLIP was added so that applications could discover whether the driver offered this feature or not.

Second, a new flag value, DRM_MODE_PAGE_FLIP_ASYNC was added to the DRM_IOCTL_MODE_PAGE_FLIP ioctl.

To get the new flag down into the driver required adding the flag parameter to the page_flip crtc function.

Async Display Flipping support in Intel Hardware

Recent Intel display hardware has support for asynchronous flipping, either through the ring using the MI_DISPLAY_FLIP instruction or directly through the registers. There are some limitations however:

  • The pitch of the current and new frame buffers must match

  • Both current and new frame buffers must use X tiling

I've also only implemented flipping on Sandybridge and Ivybridge hardware as that's what I've got for testing.

Using Async Display Flipping with Present

I'm using async display flipping when the kernel supports it in the current Present implementation. This offers the ability to short-circuit multiple presentations targeting the same scanout frame. I haven't exposed the ability to select this to applications over the Present protocol yet, but that's not a big change.

Implementing the GLX_EXT_swap_control_tear extension

I haven't even looked at implementing this extension; I'm hoping that once I've gotten the functionality exposed over the X protocol that someone will at least help me figure out how to hook this up.

Getting the Bits

The interesting pieces here are the new kernel bits; the DRM library changes simply add new defines to existing APIs.

  • Kernel bits are in my kernel.org repository

    git://git.kernel.org/pub/scm/linux/kernel/git/keithp/linux-2.6 dri3

  • DRM library bits are in my freedesktop.org drm repository

    git://people.freedesktop.org/home/keithp/drm.git dri3