Skip to contentSkip to conversation

drm: document uAPI page-flip flags

PATCH Superseded Simon Ser 5 participants 14 messages Aug 25, 2022 – Aug 30, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Simon Ser

author
#0 lore raw

PATCH 1/1 drm: document uAPI page-flip flags

Document flags accepted by the page-flip and atomic IOCTLs.

Cc Daniel Vetter <[email protected]>
---
 include/uapi/drm/drm_mode.h | 44 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
include/uapi/drm/drm_mode.h +43 -1
index fa953309d9ce..e1b04ffd54c3 100644
@@ -935,12 +935,30 @@ struct hdr_output_metadata {
 	};
 };
 
+/**
+ * DRM_MODE_PAGE_FLIP_EVENT
+ *
+ * Request that the kernel sends back a vblank event (see
+ * struct drm_event_vblank) when the page-flip is done.
+ */
 #define DRM_MODE_PAGE_FLIP_EVENT 0x01
+/**
+ * DRM_MODE_PAGE_FLIP_ASYNC
+ *
+ * Request that the page-flip is performed as soon as possible, ie. with no
+ * delay due to waiting for vblank. This may cause tearing to be visible on
+ * the screen.
+ */
 #define DRM_MODE_PAGE_FLIP_ASYNC 0x02
 #define DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE 0x4
 #define DRM_MODE_PAGE_FLIP_TARGET_RELATIVE 0x8
 #define DRM_MODE_PAGE_FLIP_TARGET (DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE | \
 				   DRM_MODE_PAGE_FLIP_TARGET_RELATIVE)
+/**
+ * DRM_MODE_PAGE_FLIP_FLAGS
+ *
+ * Bitmask of flags suitable for &drm_mode_crtc_page_flip_target.flags.
+ */
 #define DRM_MODE_PAGE_FLIP_FLAGS (DRM_MODE_PAGE_FLIP_EVENT | \
 				  DRM_MODE_PAGE_FLIP_ASYNC | \
 				  DRM_MODE_PAGE_FLIP_TARGET)
@@ -1034,11 +1052,35 @@ struct drm_mode_destroy_dumb {
 	__u32 handle;
 };
 
-/* page-flip flags are valid, plus: */
+/**
+ * DRM_MODE_ATOMIC_TEST_ONLY
+ *
+ * Do not apply the atomic commit, instead check whether the hardware supports
+ * this configuration.
+ *
+ * See drm_mode_config_funcs.atomic_check for more details on test-only
+ * commits.
+ */
 #define DRM_MODE_ATOMIC_TEST_ONLY 0x0100
+/**
+ * DRM_MODE_ATOMIC_NONBLOCK
+ *
+ * Do not block while applying the atomic commit.
+ */
 #define DRM_MODE_ATOMIC_NONBLOCK  0x0200
+/**
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.
+ */
 #define DRM_MODE_ATOMIC_ALLOW_MODESET 0x0400
 
+/**
+ * DRM_MODE_ATOMIC_FLAGS
+ *
+ * Bitfield of flags accepted by the &DRM_IOCTL_MODE_ATOMIC IOCTL in
+ * &drm_mode_atomic.flags.
+ */
 #define DRM_MODE_ATOMIC_FLAGS (\
 		DRM_MODE_PAGE_FLIP_EVENT |\
 		DRM_MODE_PAGE_FLIP_ASYNC |\
Signature · 1 line
2.37.2
#1 lore raw
Quoted 13 lines · On Wed, 24 Aug 2022 17:45:06 +0000 Simon Ser <[email protected]> wrote:

Document flags accepted by the page-flip and atomic IOCTLs.

Cc Daniel Vetter <[email protected]>
---
 include/uapi/drm/drm_mode.h | 44 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
include/uapi/drm/drm_mode.h +0 -0
index fa953309d9ce..e1b04ffd54c3 100644

include/uapi/drm/drm_mode.h struct hdr_output_metadata { · line 942

Quoted 8 lines
include/uapi/drm/drm_mode.h +5 -0
@@ -935,12 +935,30 @@ struct hdr_output_metadata {
 	};
 };
 
+/**
+ * DRM_MODE_PAGE_FLIP_EVENT
+ *
+ * Request that the kernel sends back a vblank event (see
+ * struct drm_event_vblank) when the page-flip is done.

...with type = DRM_EVENT_FLIP_COMPLETE?

This was a bit new to me, because libdrm abstracts vblank and pageflip events into different APIs.

include/uapi/drm/drm_mode.h struct hdr_output_metadata { · line 950

Quoted 8 lines
include/uapi/drm/drm_mode.h +7 -0
+ */
 #define DRM_MODE_PAGE_FLIP_EVENT 0x01
+/**
+ * DRM_MODE_PAGE_FLIP_ASYNC
+ *
+ * Request that the page-flip is performed as soon as possible, ie. with no
+ * delay due to waiting for vblank. This may cause tearing to be visible on
+ * the screen.

Btw. does the kernel fail the flip if the driver does not support async? Or does it silently fall back to sync flip?
Asking for both legacy and atomic APIs.

Quoted 23 lines
include/uapi/drm/drm_mode.h +10 -1
+ */
 #define DRM_MODE_PAGE_FLIP_ASYNC 0x02
 #define DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE 0x4
 #define DRM_MODE_PAGE_FLIP_TARGET_RELATIVE 0x8
 #define DRM_MODE_PAGE_FLIP_TARGET (DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE | \
 				   DRM_MODE_PAGE_FLIP_TARGET_RELATIVE)
+/**
+ * DRM_MODE_PAGE_FLIP_FLAGS
+ *
+ * Bitmask of flags suitable for &drm_mode_crtc_page_flip_target.flags.
+ */
 #define DRM_MODE_PAGE_FLIP_FLAGS (DRM_MODE_PAGE_FLIP_EVENT | \
 				  DRM_MODE_PAGE_FLIP_ASYNC | \
 				  DRM_MODE_PAGE_FLIP_TARGET)
@@ -1034,11 +1052,35 @@ struct drm_mode_destroy_dumb {
 	__u32 handle;
 };
 
-/* page-flip flags are valid, plus: */
+/**
+ * DRM_MODE_ATOMIC_TEST_ONLY
+ *
+ * Do not apply the atomic commit, instead check whether the hardware supports

include/uapi/drm/drm_mode.h struct drm_mode_destroy_dumb { · line 1068

Quoted 10 lines
include/uapi/drm/drm_mode.h +9 -0
+ * this configuration.
+ *
+ * See drm_mode_config_funcs.atomic_check for more details on test-only
+ * commits.
+ */
 #define DRM_MODE_ATOMIC_TEST_ONLY 0x0100
+/**
+ * DRM_MODE_ATOMIC_NONBLOCK
+ *
+ * Do not block while applying the atomic commit.

Maybe add something like:

The atomic commit ioctl returns immediately instead of waiting for the changes to be applied in hardware.

include/uapi/drm/drm_mode.h struct drm_mode_destroy_dumb { · line 1074

Quoted 6 lines
include/uapi/drm/drm_mode.h +5 -0
+ */
 #define DRM_MODE_ATOMIC_NONBLOCK  0x0200
+/**
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.

Maybe add:

...temporary or transient visible artifacts while the update is being applied. Applying the update may also take significantly more time than a page flip. The visual artifacts will not appear after the update is completed.

This flag must be set when the KMS update might cause visible artifacts. Without this flag such KMS update will return EINVAL error. What kind of updates may cause visible artifacts depends on the driver and the hardware. Userspace that needs to know beforehand if an update might cause visible artifacts can use DRM_MODE_ATOMIC_TEST_ONLY without DRM_MODE_ATOMIC_ALLOW_MODESET to see if it fails.

Visual artifacts are guaranteed to not appear when this flag is not set.

That "artifacts will not appear after the update is completed" is a bit awkward, because when this commit completes and triggers the completion event (if requested), the visual artifacts might still be on screen, but as soon as the scanout cycle that just started finishes, all artifacts are gone for good. Isn't that how it works?

Or does the kernel wait with the completion event until a good picture has been fully scanned out at least once? I'd expect not.

include/uapi/drm/drm_mode.h struct drm_mode_destroy_dumb { · line 1086

Quoted 12 lines
include/uapi/drm/drm_mode.h +7 -0
+ */
 #define DRM_MODE_ATOMIC_ALLOW_MODESET 0x0400
 
+/**
+ * DRM_MODE_ATOMIC_FLAGS
+ *
+ * Bitfield of flags accepted by the &DRM_IOCTL_MODE_ATOMIC IOCTL in
+ * &drm_mode_atomic.flags.
+ */
 #define DRM_MODE_ATOMIC_FLAGS (\
 		DRM_MODE_PAGE_FLIP_EVENT |\
 		DRM_MODE_PAGE_FLIP_ASYNC |\

Thanks,
pq

#2 lore raw
Quoted 105 lines · Pekka Paalanen
Quoted 13 lines · On Wed, 24 Aug 2022 17:45:06 +0000 Simon Ser <[email protected]> wrote:

Document flags accepted by the page-flip and atomic IOCTLs.

Cc Daniel Vetter <[email protected]>
---
 include/uapi/drm/drm_mode.h | 44 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
include/uapi/drm/drm_mode.h +0 -0
index fa953309d9ce..e1b04ffd54c3 100644

include/uapi/drm/drm_mode.h struct hdr_output_metadata { · line 942

Quoted 8 lines
include/uapi/drm/drm_mode.h +5 -0
@@ -935,12 +935,30 @@ struct hdr_output_metadata {
      };
 };
 
+/**
+ * DRM_MODE_PAGE_FLIP_EVENT
+ *
+ * Request that the kernel sends back a vblank event (see
+ * struct drm_event_vblank) when the page-flip is done.

...with type = DRM_EVENT_FLIP_COMPLETE?

This was a bit new to me, because libdrm abstracts vblank and pageflip events into different APIs.

include/uapi/drm/drm_mode.h struct hdr_output_metadata { · line 950

Quoted 8 lines
include/uapi/drm/drm_mode.h +7 -0
+ */
 #define DRM_MODE_PAGE_FLIP_EVENT 0x01
+/**
+ * DRM_MODE_PAGE_FLIP_ASYNC
+ *
+ * Request that the page-flip is performed as soon as possible, ie. with no
+ * delay due to waiting for vblank. This may cause tearing to be visible on
+ * the screen.

Btw. does the kernel fail the flip if the driver does not support async? Or does it silently fall back to sync flip?
Asking for both legacy and atomic APIs.

Quoted 23 lines
include/uapi/drm/drm_mode.h +10 -1
+ */
 #define DRM_MODE_PAGE_FLIP_ASYNC 0x02
 #define DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE 0x4
 #define DRM_MODE_PAGE_FLIP_TARGET_RELATIVE 0x8
 #define DRM_MODE_PAGE_FLIP_TARGET (DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE | \
                                 DRM_MODE_PAGE_FLIP_TARGET_RELATIVE)
+/**
+ * DRM_MODE_PAGE_FLIP_FLAGS
+ *
+ * Bitmask of flags suitable for &drm_mode_crtc_page_flip_target.flags.
+ */
 #define DRM_MODE_PAGE_FLIP_FLAGS (DRM_MODE_PAGE_FLIP_EVENT | \
                                DRM_MODE_PAGE_FLIP_ASYNC | \
                                DRM_MODE_PAGE_FLIP_TARGET)
@@ -1034,11 +1052,35 @@ struct drm_mode_destroy_dumb {
      __u32 handle;
 };
 
-/* page-flip flags are valid, plus: */
+/**
+ * DRM_MODE_ATOMIC_TEST_ONLY
+ *
+ * Do not apply the atomic commit, instead check whether the hardware supports

include/uapi/drm/drm_mode.h struct drm_mode_destroy_dumb { · line 1068

Quoted 10 lines
include/uapi/drm/drm_mode.h +9 -0
+ * this configuration.
+ *
+ * See drm_mode_config_funcs.atomic_check for more details on test-only
+ * commits.
+ */
 #define DRM_MODE_ATOMIC_TEST_ONLY 0x0100
+/**
+ * DRM_MODE_ATOMIC_NONBLOCK
+ *
+ * Do not block while applying the atomic commit.

Maybe add something like:

The atomic commit ioctl returns immediately instead of waiting for the changes to be applied in hardware.

include/uapi/drm/drm_mode.h struct drm_mode_destroy_dumb { · line 1074

Quoted 6 lines
include/uapi/drm/drm_mode.h +5 -0
+ */
 #define DRM_MODE_ATOMIC_NONBLOCK  0x0200
+/**
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.

Maybe add:

...temporary or transient visible artifacts while the update is being applied. Applying the update may also take significantly more time than a page flip. The visual artifacts will not appear after the update is completed.

This flag must be set when the KMS update might cause visible artifacts. Without this flag such KMS update will return EINVAL error. What kind of updates may cause visible artifacts depends on the driver and the hardware. Userspace that needs to know beforehand if an update might cause visible artifacts can use DRM_MODE_ATOMIC_TEST_ONLY without DRM_MODE_ATOMIC_ALLOW_MODESET to see if it fails.

Quoted 2 lines

Visual artifacts are guaranteed to not appear when this flag is not set.

That doesn't seem to be true, though. For example setting HDR_OUTPUT_METADATA for example does result in visual artifacts on my display no matter if the flag is specified or not because the artifacts are not the result of a mode set but of the display reacting to some AVI InfoFrame.

Quoted 26 lines

That "artifacts will not appear after the update is completed" is a bit awkward, because when this commit completes and triggers the completion event (if requested), the visual artifacts might still be on screen, but as soon as the scanout cycle that just started finishes, all artifacts are gone for good. Isn't that how it works?

Or does the kernel wait with the completion event until a good picture has been fully scanned out at least once? I'd expect not.

include/uapi/drm/drm_mode.h struct drm_mode_destroy_dumb { · line 1086

Quoted 12 lines
include/uapi/drm/drm_mode.h +7 -0
+ */
 #define DRM_MODE_ATOMIC_ALLOW_MODESET 0x0400
 
+/**
+ * DRM_MODE_ATOMIC_FLAGS
+ *
+ * Bitfield of flags accepted by the &DRM_IOCTL_MODE_ATOMIC IOCTL in
+ * &drm_mode_atomic.flags.
+ */
 #define DRM_MODE_ATOMIC_FLAGS (\
              DRM_MODE_PAGE_FLIP_EVENT |\
              DRM_MODE_PAGE_FLIP_ASYNC |\

Thanks,
pq

author
#3 lore raw
Quoted 20 lines · Sebastian Wick
Quoted 20 lines
Quoted 4 lines

+/*
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.

Maybe add:

...temporary or transient visible artifacts while the update is being applied. Applying the update may also take significantly more time than a page flip. The visual artifacts will not appear after the update is completed.

This flag must be set when the KMS update might cause visible artifacts. Without this flag such KMS update will return EINVAL error. What kind of updates may cause visible artifacts depends on the driver and the hardware. Userspace that needs to know beforehand if an update might cause visible artifacts can use DRM_MODE_ATOMIC_TEST_ONLY without DRM_MODE_ATOMIC_ALLOW_MODESET to see if it fails.

Quoted 8 lines
Quoted 2 lines

Visual artifacts are guaranteed to not appear when this flag is not set.

That doesn't seem to be true, though. For example setting HDR_OUTPUT_METADATA for example does result in visual artifacts on my display no matter if the flag is specified or not because the artifacts are not the result of a mode set but of the display reacting to some AVI InfoFrame.

One would need to read the HDMI spec to see if there's anything in there about artifacts on AVI InfoFrame change, then figure out whether this is a bug in the physical screen itself or whether the kernel driver should require ALLOW_MODESET when updating the HDR metadata.

#4 lore raw
Quoted 32 lines · Simon Ser
Quoted 20 lines · Sebastian Wick
Quoted 20 lines
Quoted 4 lines

+/*
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.

Maybe add:

...temporary or transient visible artifacts while the update is being applied. Applying the update may also take significantly more time than a page flip. The visual artifacts will not appear after the update is completed.

This flag must be set when the KMS update might cause visible artifacts. Without this flag such KMS update will return EINVAL error. What kind of updates may cause visible artifacts depends on the driver and the hardware. Userspace that needs to know beforehand if an update might cause visible artifacts can use DRM_MODE_ATOMIC_TEST_ONLY without DRM_MODE_ATOMIC_ALLOW_MODESET to see if it fails.

Quoted 8 lines
Quoted 2 lines

Visual artifacts are guaranteed to not appear when this flag is not set.

That doesn't seem to be true, though. For example setting HDR_OUTPUT_METADATA for example does result in visual artifacts on my display no matter if the flag is specified or not because the artifacts are not the result of a mode set but of the display reacting to some AVI InfoFrame.

Quoted 4 lines

One would need to read the HDMI spec to see if there's anything in there about artifacts on AVI InfoFrame change, then figure out whether this is a bug in the physical screen itself or whether the kernel driver should require ALLOW_MODESET when updating the HDR metadata.

I'm not even sure if that's the right thing to do. ALLOW_MODESET isn't really about if a commit can lead to visual artifacts but about keeping the existing links alive (someone with more knowledge on this subject probably has a better description for this). An async commit can also introduce visual artifacts for example and there are probably more cases.

Quoted 1 line
author
#5 lore raw
Quoted 38 lines · Sebastian Wick
Quoted 31 lines · On Fri, Aug 26, 2022 at 2:17 PM Simon Ser [email protected] wrote:
Quoted 20 lines · On Friday, August 26th, 2022 at 11:49, Sebastian Wick…
Quoted 20 lines
Quoted 4 lines

+/*
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.

Maybe add:

...temporary or transient visible artifacts while the update is being applied. Applying the update may also take significantly more time than a page flip. The visual artifacts will not appear after the update is completed.

This flag must be set when the KMS update might cause visible artifacts. Without this flag such KMS update will return EINVAL error. What kind of updates may cause visible artifacts depends on the driver and the hardware. Userspace that needs to know beforehand if an update might cause visible artifacts can use DRM_MODE_ATOMIC_TEST_ONLY without DRM_MODE_ATOMIC_ALLOW_MODESET to see if it fails.

Quoted 8 lines
Quoted 2 lines

Visual artifacts are guaranteed to not appear when this flag is not set.

That doesn't seem to be true, though. For example setting HDR_OUTPUT_METADATA for example does result in visual artifacts on my display no matter if the flag is specified or not because the artifacts are not the result of a mode set but of the display reacting to some AVI InfoFrame.

Quoted 4 lines

One would need to read the HDMI spec to see if there's anything in there about artifacts on AVI InfoFrame change, then figure out whether this is a bug in the physical screen itself or whether the kernel driver should require ALLOW_MODESET when updating the HDR metadata.

Quoted 6 lines

I'm not even sure if that's the right thing to do. ALLOW_MODESET isn't really about if a commit can lead to visual artifacts but about keeping the existing links alive (someone with more knowledge on this subject probably has a better description for this). An async commit can also introduce visual artifacts for example and there are probably more cases.

That's certainly not the intent of ALLOW_MODESET.

See the kernel docs for atomic_check:

Quoted 8 lines

This callback also needs to correctly fill out the drm_crtc_state in this update to make sure that drm_atomic_crtc_needs_modeset() reflects the nature of the possible update and returns true if and only if the update cannot be applied without tearing within one vblank on that CRTC. The core uses that information to reject updates which require a full modeset (i.e. blanking the screen, or at least pausing updates for a substantial amount of time) if userspace has disallowed that in its request.

I'm sure Daniel Vetter can confirm this as well.

#6 lore raw
Quoted 40 lines · On Fri, 26 Aug 2022 13:17:09 +0000 Simon Ser <[email protected]> wrote:
Quoted 38 lines · Sebastian Wick
Quoted 35 lines · On Fri, Aug 26, 2022 at 2:17 PM Simon Ser [email protected] wrote:
Quoted 20 lines · On Friday, August 26th, 2022 at 11:49, Sebastian Wick…
Quoted 20 lines
Quoted 4 lines

+/*
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.

Maybe add:

...temporary or transient visible artifacts while the update is being applied. Applying the update may also take significantly more time than a page flip. The visual artifacts will not appear after the update is completed.

This flag must be set when the KMS update might cause visible artifacts. Without this flag such KMS update will return EINVAL error. What kind of updates may cause visible artifacts depends on the driver and the hardware. Userspace that needs to know beforehand if an update might cause visible artifacts can use DRM_MODE_ATOMIC_TEST_ONLY without DRM_MODE_ATOMIC_ALLOW_MODESET to see if it fails.

Quoted 8 lines
Quoted 2 lines

Visual artifacts are guaranteed to not appear when this flag is not set.

That doesn't seem to be true, though. For example setting HDR_OUTPUT_METADATA for example does result in visual artifacts on my display no matter if the flag is specified or not because the artifacts are not the result of a mode set but of the display reacting to some AVI InfoFrame.

One would need to read the HDMI spec to see if there's anything in there about artifacts on AVI InfoFrame change, then figure out whether this is a bug in the physical screen itself or whether the kernel driver should require ALLOW_MODESET when updating the HDR metadata.

Quoted 8 lines
Quoted 6 lines

I'm not even sure if that's the right thing to do. ALLOW_MODESET isn't really about if a commit can lead to visual artifacts but about keeping the existing links alive (someone with more knowledge on this subject probably has a better description for this). An async commit can also introduce visual artifacts for example and there are probably more cases.

That's certainly not the intent of ALLOW_MODESET.

One could look at this from the perspective of who is allowed to break. Maybe the monitor is allowed to break any time (because it is out of our reach anyway, we can only control the electrical signals going into the cable), but the source hardware (the display block, everything before "the cable") is allowed to break only with ALLOW_MODESET.

IOW, if the electrical signal is kept "glitch free" in the sense that the sink (or a human looking at a sink) cannot see artifacts, then ALLOW_MODESET is not required. One could even change the video mode without ALLOW_MODESET if it does not result in artifacts, like switching from one constant refresh rate to another on VRR capable hardware - or what I heard Intel does with some transparent power saving by halving the refresh rate when nothing is changing.

So, at the minimum we must require that the electrical signal cannot "break". Do we include what a monitor does in ALLOW_MODESET or not is something I'm not sure, since different sinks presumably break on different changes.

Quoted 11 lines

See the kernel docs for atomic_check:

Quoted 8 lines

This callback also needs to correctly fill out the drm_crtc_state in this update to make sure that drm_atomic_crtc_needs_modeset() reflects the nature of the possible update and returns true if and only if the update cannot be applied without tearing within one vblank on that CRTC. The core uses that information to reject updates which require a full modeset (i.e. blanking the screen, or at least pausing updates for a substantial amount of time) if userspace has disallowed that in its request.

Quoted 1 line

I'm sure Daniel Vetter can confirm this as well.

I guess the new ASYNC flag patches will fix this wording to allow tearing in that case?

Thanks,
pq

author
#7 lore raw
In reply to Pekka Paalanen

CC Ville for the ASYNC bits, see below.

Quoted 10 lines · Pekka Paalanen
Quoted 5 lines

+/**
+ * DRM_MODE_PAGE_FLIP_EVENT
+ *
+ * Request that the kernel sends back a vblank event (see
+ * struct drm_event_vblank) when the page-flip is done.

...with type = DRM_EVENT_FLIP_COMPLETE?

This was a bit new to me, because libdrm abstracts vblank and pageflip events into different APIs.

Indeed.

Maybe should clarify what "done" means here? Would "when the page-flip has been displayed on-screen" be correct?

Quoted 9 lines
Quoted 8 lines

+ */
#define DRM_MODE_PAGE_FLIP_EVENT 0x01
+/**
+ * DRM_MODE_PAGE_FLIP_ASYNC
+ *
+ * Request that the page-flip is performed as soon as possible, ie. with no
+ * delay due to waiting for vblank. This may cause tearing to be visible on
+ * the screen.

Quoted 3 lines

Btw. does the kernel fail the flip if the driver does not support async? Or does it silently fall back to sync flip?
Asking for both legacy and atomic APIs.

Atomic doesn't support this yet, so it's pretty much TBD (see Ville's reply [1]).

For legacy, it seems like drivers do what they want. AFAIU, i915 will reject (see intel_async_flip_check_uapi etc), and amdgpu will silently fall back to vsync (see the acrtc_state->update_type == UPDATE_TYPE_FAST check in amdgpu_dm_commit_planes).

Maybe one of the drivers is wrong here and should be fixed?

[1]: https://lore.kernel.org/dri-devel/YwiB%[email protected]/

Quoted 9 lines
Quoted 4 lines

+/**
+ * DRM_MODE_ATOMIC_NONBLOCK
+ *
+ * Do not block while applying the atomic commit.

Maybe add something like:

The atomic commit ioctl returns immediately instead of waiting for the changes to be applied in hardware.

Good idea. Also added:

Note, the driver will still check that the update can be applied before retuning.

Quoted 25 lines
Quoted 6 lines

+ */
#define DRM_MODE_ATOMIC_NONBLOCK 0x0200
+/**
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.

Maybe add:

...temporary or transient visible artifacts while the update is being applied. Applying the update may also take significantly more time than a page flip. The visual artifacts will not appear after the update is completed.

This flag must be set when the KMS update might cause visible artifacts. Without this flag such KMS update will return EINVAL error. What kind of updates may cause visible artifacts depends on the driver and the hardware. Userspace that needs to know beforehand if an update might cause visible artifacts can use DRM_MODE_ATOMIC_TEST_ONLY without DRM_MODE_ATOMIC_ALLOW_MODESET to see if it fails.

Visual artifacts are guaranteed to not appear when this flag is not set.

Quoted 8 lines

That "artifacts will not appear after the update is completed" is a bit awkward, because when this commit completes and triggers the completion event (if requested), the visual artifacts might still be on screen, but as soon as the scanout cycle that just started finishes, all artifacts are gone for good. Isn't that how it works?

Or does the kernel wait with the completion event until a good picture has been fully scanned out at least once? I'd expect not.

That generally looks like a good description to me, and AFAIK is how things work indeed.

#8 lore raw
Quoted 12 lines · On Mon, 29 Aug 2022 15:37:52 +0000 Simon Ser <[email protected]> wrote:

CC Ville for the ASYNC bits, see below.

Quoted 8 lines · Pekka Paalanen
Quoted 5 lines

+/**
+ * DRM_MODE_PAGE_FLIP_EVENT
+ *
+ * Request that the kernel sends back a vblank event (see
+ * struct drm_event_vblank) when the page-flip is done.

...with type = DRM_EVENT_FLIP_COMPLETE?

Quoted 7 lines
Quoted 2 lines

This was a bit new to me, because libdrm abstracts vblank and pageflip events into different APIs.

Indeed.

Maybe should clarify what "done" means here? Would "when the page-flip has been displayed on-screen" be correct?

Good idea, but definition is not quite that AFAIU. I would understand "displayed" as "turned into light" or at least fully sent to the cable, when we are talking at this level of detail.

Hence, "has been displayed" is not it because the flip-done event is emitted before the new FB contents have been scanned out. That scanout cycle is only starting when the flip is done. The flip timestamp should correspond to the time when the first real pixel of the new FB hits the monitor cable.

A flip is done, when it is guaranteed that the next (or on-going, in case of tearing) scanout cycle will use the new FB, IOW the hardware programming has been done I believe.

If the flip is sync'd to vblank, the timestamp is as above, but the actual event might be emitted somewhat before or after the instant of the timestamp. Some drivers can predict the timestamp so can send the event early, others don't.

If the flip is tearing, then I'm not sure what the timestamp is or when the event is emitted.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

+ */
#define DRM_MODE_PAGE_FLIP_EVENT 0x01
+/**
+ * DRM_MODE_PAGE_FLIP_ASYNC
+ *
+ * Request that the page-flip is performed as soon as possible, ie. with no
+ * delay due to waiting for vblank. This may cause tearing to be visible on
+ * the screen.

Quoted 5 lines
Quoted 3 lines

Btw. does the kernel fail the flip if the driver does not support async? Or does it silently fall back to sync flip?
Asking for both legacy and atomic APIs.

Atomic doesn't support this yet, so it's pretty much TBD (see Ville's reply [1]).

So atomic commit ioctl will fail with EINVAL because userspace is giving it an unrecognized flag?

[1] is interesting. Apparently the atomic async flag will only be a hint, "make it tear if possible". That seems fine to me.

Quoted 17 lines

For legacy, it seems like drivers do what they want. AFAIU, i915 will reject (see intel_async_flip_check_uapi etc), and amdgpu will silently fall back to vsync (see the acrtc_state->update_type == UPDATE_TYPE_FAST check in amdgpu_dm_commit_planes).

Maybe one of the drivers is wrong here and should be fixed?

[1]: https://lore.kernel.org/dri-devel/YwiB%[email protected]/

Quoted 7 lines
Quoted 4 lines

+/**
+ * DRM_MODE_ATOMIC_NONBLOCK
+ *
+ * Do not block while applying the atomic commit.

Maybe add something like:

Quoted 7 lines
Quoted 2 lines

The atomic commit ioctl returns immediately instead of waiting for the changes to be applied in hardware.

Good idea. Also added:

Note, the driver will still check that the update can be applied before retuning.

Nice.

Quoted 31 lines
Quoted 31 lines
Quoted 6 lines

+ */
#define DRM_MODE_ATOMIC_NONBLOCK 0x0200
+/**
+ * DRM_MODE_ATOMIC_ALLOW_MODESET
+ *
+ * Allow the update to result in visible artifacts such as a black screen.

Maybe add:

...temporary or transient visible artifacts while the update is being applied. Applying the update may also take significantly more time than a page flip. The visual artifacts will not appear after the update is completed.

This flag must be set when the KMS update might cause visible artifacts. Without this flag such KMS update will return EINVAL error. What kind of updates may cause visible artifacts depends on the driver and the hardware. Userspace that needs to know beforehand if an update might cause visible artifacts can use DRM_MODE_ATOMIC_TEST_ONLY without DRM_MODE_ATOMIC_ALLOW_MODESET to see if it fails.

Visual artifacts are guaranteed to not appear when this flag is not set.

That "artifacts will not appear after the update is completed" is a bit awkward, because when this commit completes and triggers the completion event (if requested), the visual artifacts might still be on screen, but as soon as the scanout cycle that just started finishes, all artifacts are gone for good. Isn't that how it works?

Quoted 5 lines
Quoted 2 lines

Or does the kernel wait with the completion event until a good picture has been fully scanned out at least once? I'd expect not.

That generally looks like a good description to me, and AFAIK is how things work indeed.

Yeah, but swick has a good point: should we be talking about literal visual artifacts or do we only guarantee that the video signal on the cable is uninterrupted?

HDR_OUTPUT_METADATA is the prime example where that matters. It is infoframe data, which means changing it will never cause any interruption in the video signal. However, changing certain fields (and not with other fields) in the infoframe is likely to cause the monitor to glitch or blank for a moment.

Thanks,
pq

#9 lore raw
Quoted 15 lines · Pekka Paalanen
Quoted 13 lines · On Mon, 29 Aug 2022 15:37:52 +0000 Simon Ser <[email protected]> wrote:
Quoted 10 lines · Pekka Paalanen
Quoted 6 lines

+/**
+ * DRM_MODE_PAGE_FLIP_ASYNC
+ *
+ * Request that the page-flip is performed as soon as possible, ie. with no
+ * delay due to waiting for vblank. This may cause tearing to be visible on
+ * the screen.

Btw. does the kernel fail the flip if the driver does not support async? Or does it silently fall back to sync flip?
Asking for both legacy and atomic APIs.

Quoted 7 lines
Quoted 1 line

Atomic doesn't support this yet, so it's pretty much TBD (see Ville's reply [1]).

So atomic commit ioctl will fail with EINVAL because userspace is giving it an unrecognized flag?

[1] is interesting. Apparently the atomic async flag will only be a hint, "make it tear if possible". That seems fine to me.

To me it would seem better for the driver to return an error if the async flag is passed in, but the driver can't actually do an async update.

Otherwise it's tricky for a Wayland compositor to decide if it should use an async commit (which needs to be done ASAP to serve the intended purpose) or not (in which case the compositor may want to delay the commit as long as possible for minimal latency).

Quoted 8 lines
Quoted 8 lines

For legacy, it seems like drivers do what they want. AFAIU, i915 will reject (see intel_async_flip_check_uapi etc), and amdgpu will silently fall back to vsync (see the acrtc_state->update_type == UPDATE_TYPE_FAST check in amdgpu_dm_commit_planes).

Maybe one of the drivers is wrong here and should be fixed?

[1]: https://lore.kernel.org/dri-devel/YwiB%[email protected]

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
author
#10 lore raw
Quoted 10 lines · Michel Dänzer
Quoted 9 lines

For the atomic uAPI, we need to pick on of these two approaches:

1. Let the kernel fall back to a sync flip if async isn't possible. This simplifies user-space, but then user-space has no reliable way to figure out what really happened (sync or async?). That could be fixed with a new read-only CRTC prop indicating whether the last flip was async or not. However, maybe someone will come up in the future with user-space which needs to only apply an update if async flip is possible, in which case this approach falls short.

Quoted 7 lines

The future is now. :)

As I described in the documentation patch discussion, this approach would make it tricky for a Wayland compositor to decide if it should use an async commit (which needs to be done ASAP to serve the intended purpose) or not (in which case the compositor may want to delay the commit as long as possible for minimal latency).

Ah right. If an async page-flip is not possible, then a Wayland compositor could want to wait the "last moment" before the next vblank to see if a more up-to-date buffer is available.

With that + Xorg usage, I think we have a rather solid case for failing async flips rather than silently falling back to vsync.

#11 lore raw
In reply to Pekka Paalanen
Quoted 37 lines · Pekka Paalanen
Quoted 12 lines · On Mon, 29 Aug 2022 15:37:52 +0000 Simon Ser <[email protected]> wrote:

CC Ville for the ASYNC bits, see below.

Quoted 8 lines · Pekka Paalanen
Quoted 5 lines

+/**
+ * DRM_MODE_PAGE_FLIP_EVENT
+ *
+ * Request that the kernel sends back a vblank event (see
+ * struct drm_event_vblank) when the page-flip is done.

...with type = DRM_EVENT_FLIP_COMPLETE?

Quoted 7 lines
Quoted 2 lines

This was a bit new to me, because libdrm abstracts vblank and pageflip events into different APIs.

Indeed.

Maybe should clarify what "done" means here? Would "when the page-flip has been displayed on-screen" be correct?

Good idea, but definition is not quite that AFAIU. I would understand "displayed" as "turned into light" or at least fully sent to the cable, when we are talking at this level of detail.

Hence, "has been displayed" is not it because the flip-done event is emitted before the new FB contents have been scanned out. That scanout cycle is only starting when the flip is done. The flip timestamp should correspond to the time when the first real pixel of the new FB hits the monitor cable.

A flip is done, when it is guaranteed that the next (or on-going, in case of tearing) scanout cycle will use the new FB, IOW the hardware programming has been done I believe.

Quoted 7 lines

If the flip is sync'd to vblank, the timestamp is as above, but the actual event might be emitted somewhat before or after the instant of the timestamp. Some drivers can predict the timestamp so can send the event early, others don't.

If the flip is tearing, then I'm not sure what the timestamp is or when the event is emitted.

For i915 we emit the event when the hardware has indicated the flip has completed (ie. it has really started scanout from the new fb). After that you can safely reuse the old fb without accidentally doing frontbuffer rendering. It takes a bit of time (some smallish number of scanlines) for the hardware to flush the FIFOs/TLBs/whatever.

And IIRC we just send the last sampled vblank timestamp for the event. That is, the timestamp should look the same as for a sync flip submitted during the previous frame. I was thinking of making it more or less show the current time of the flip done indication as that's when the scanout from the new fb starts, but pretty much everyone else was of the opinion that there is no point in doing that.

Signature · 2 lines
Ville Syrjälä
Intel
#12 lore raw
Quoted 27 lines · On Tue, 30 Aug 2022 11:41:39 +0300 Ville Syrjälä…
Quoted 10 lines · Pekka Paalanen

Hence, "has been displayed" is not it because the flip-done event is emitted before the new FB contents have been scanned out. That scanout cycle is only starting when the flip is done. The flip timestamp should correspond to the time when the first real pixel of the new FB hits the monitor cable.

A flip is done, when it is guaranteed that the next (or on-going, in case of tearing) scanout cycle will use the new FB, IOW the hardware programming has been done I believe.

Quoted 7 lines

If the flip is sync'd to vblank, the timestamp is as above, but the actual event might be emitted somewhat before or after the instant of the timestamp. Some drivers can predict the timestamp so can send the event early, others don't.

If the flip is tearing, then I'm not sure what the timestamp is or when the event is emitted.

For i915 we emit the event when the hardware has indicated the flip has completed (ie. it has really started scanout from the new fb). After that you can safely reuse the old fb without accidentally doing frontbuffer rendering. It takes a bit of time (some smallish number of scanlines) for the hardware to flush the FIFOs/TLBs/whatever.

Quoted 7 lines

And IIRC we just send the last sampled vblank timestamp for the event. That is, the timestamp should look the same as for a sync flip submitted during the previous frame. I was thinking of making it more or less show the current time of the flip done indication as that's when the scanout from the new fb starts, but pretty much everyone else was of the opinion that there is no point in doing that.

Ugh. So we have two different meanings for the completion timestamp:

sync flip: when the first pixel from the new FB is emitted into the
video signal

async flip: something irrelevant

*sigh*

To me it would make sense for both to use the same definition, if that's technically possible. The point is to know roughly where the tear line is which could then answer the question "did it actually tear" which is related to the silent falling back to sync flips.

Thanks,
pq

#13 lore raw
Quoted 43 lines · Pekka Paalanen
Quoted 27 lines · On Tue, 30 Aug 2022 11:41:39 +0300 Ville Syrjälä…
Quoted 10 lines · Pekka Paalanen

Hence, "has been displayed" is not it because the flip-done event is emitted before the new FB contents have been scanned out. That scanout cycle is only starting when the flip is done. The flip timestamp should correspond to the time when the first real pixel of the new FB hits the monitor cable.

A flip is done, when it is guaranteed that the next (or on-going, in case of tearing) scanout cycle will use the new FB, IOW the hardware programming has been done I believe.

Quoted 7 lines

If the flip is sync'd to vblank, the timestamp is as above, but the actual event might be emitted somewhat before or after the instant of the timestamp. Some drivers can predict the timestamp so can send the event early, others don't.

If the flip is tearing, then I'm not sure what the timestamp is or when the event is emitted.

For i915 we emit the event when the hardware has indicated the flip has completed (ie. it has really started scanout from the new fb). After that you can safely reuse the old fb without accidentally doing frontbuffer rendering. It takes a bit of time (some smallish number of scanlines) for the hardware to flush the FIFOs/TLBs/whatever.

Quoted 7 lines

And IIRC we just send the last sampled vblank timestamp for the event. That is, the timestamp should look the same as for a sync flip submitted during the previous frame. I was thinking of making it more or less show the current time of the flip done indication as that's when the scanout from the new fb starts, but pretty much everyone else was of the opinion that there is no point in doing that.

Ugh. So we have two different meanings for the completion timestamp:

sync flip: when the first pixel from the new FB is emitted into the
video signal

Quoted 8 lines

async flip: something irrelevant

*sigh*

To me it would make sense for both to use the same definition, if that's technically possible. The point is to know roughly where the tear line is which could then answer the question "did it actually tear" which is related to the silent falling back to sync flips.

Yeah, that was pretty much my original thinking as well. Just no one else was interested in it so I figured it's better to not deviate from the common behaviour.

At least for i915 it shouldn't be too hard to do it properly. The biggest complication would be untangling the drm_vblank midlayer somehow.

Signature · 2 lines
Ville Syrjälä
Intel