KMS page-flip event delivered while the previous framebuffer is still being scanned out (3840x2160@240Hz, DP)

System

  • GPU: GeForce RTX 4070 Ti SUPER
  • Driver: 615.78.08 (nvidia-open), nvidia-drm modeset=1 fbdev=1
  • Kernel: Linux 7.2.11 (Arch, zen)
  • Monitor: Dell AW3225QF over DisplayPort, 3840x2160 @ 239.991 Hz (pixel clock 2331.75 MHz), VRR off
  • Compositor: Jay (Wayland), atomic KMS, double-buffered primary plane

Summary

After the page-flip event (DRM_MODE_PAGE_FLIP_EVENT) of a nonblocking atomic commit has been delivered, the display still reads the previously displayed framebuffer for some time. If the compositor starts rendering the next frame into that framebuffer directly after the event, which KMS allows, partially rendered content becomes visible: flickering horizontal black lines, or windows below showing through the window on top. This only happens in the lower right part of the screen, and only at 240 Hz. At 3840x2160 @ 119.88 Hz on the same monitor, the problem does not occur.

Measurements (with instrumentation in the compositor)

  • Every frame is committed only after its rendering has completed. This was checked with a timeline semaphore signaled by the same submission, over about 25000 frames, with no frame committed early. So the framebuffer is complete when it is flipped to.
  • At 240 Hz, rendering of the next frame starts less than 500 µs after the page-flip event in almost every frame.
  • Delaying the start of rendering by 1 ms after the page-flip event makes the artifacts less frequent. Delaying it by 3 ms (of a 4.17 ms frame) makes them disappear.
  • Using a third framebuffer, so that rendering only targets a buffer that was replaced two flips ago, makes them disappear as well, even though rendering still starts directly after the event.
  • The framebuffer format (XRGB8888 or ABGR2101010) makes no difference.

My guess is that this mode is driven with two heads because of its pixel clock, and that the event is sent before the head driving the right half has stopped reading the old framebuffer, but I can’t verify that.

Expected behavior

Once the page-flip event for a commit has been delivered, the previous framebuffer is no longer read by the display, so a compositor can render into it.

Workaround in the compositor

Jay now allocates three scanout buffers on nvidia: metal: use three scanout buffers on nvidia by XairRrR · Pull Request #1317 · mahkoh/jay · GitHub

An nvidia-bug-report.log.gz from the same system is attached to my previous report: Vulkan: SYNC_FD exported from the first fence signals before the submission completes when it waits on an imported SYNC_FD semaphore (Xid 31)