Skip to contentSkip to conversation

A DRM API for adaptive sync and variable refresh rate support

PATCH New Nicholas Kazlauskas 4 participants 10 messages Nov 6, 2018 – Nov 20, 2018 4 messages not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v6 cover A DRM API for adaptive sync and variable refresh rate support

These patches are part of a proposed new interface for supporting variable refresh rate via DRM properties.

=== Changes from v5 ===

drm changes:

* Updated documentation to define userspace expectations when variable refresh rate is enabled

amd changes:

* Added patch to fix vblank timestamp calculations when vpos > vtotal

=== Changes from v4 ===

amd changes:

* Removed unused FreeSync functions from amdgpu

=== Changes from v3 ===

drm changes:

* Docstring and formatting fixes

amd/display changes:

* Updated commit message and debug statements

=== Changes from v2 ===

The interface has changed substantially from the last revision and the cover letter has been updated accordingly.

drm changes:

* Most "variable_refresh" prefixes in code have been shortened to just "vrr". This was motivated after changes to the interface had function names close to 80 characters long. Comments from the mailing list were already shortening these in discussion as well.
* Documentation for "Variable Refresh" has been added to the KMS properties subsection for DRM driver developers.
* The drm_connector property "variable_refresh_capable" has been renamed to "vrr_capable".
* The drm_crtc property "variable_refresh" has been been renamed "vrr_enabled" to better reflect its usage.
* The drm_connector "variable_refresh_enabled" property has been removed. Managing this is now up to userspace when it sets "vrr_enabled".
* The "vrr_capable" property no longer has any state in drm_connector_state associated with it. The value can now be updated with the drm_connector_set_vrr_capable_property() function. This better matches the immutable flag on the property.
* The "variable_refresh_changed" flag has been removed from atomic helpers based on feedback from the mailing list and updated interface usage in the amd kernel driver.

amd/display changes:

* Updated interface usage based on the new properties
* Updated VRR infopacket handling based on new xf86-video-amdgpu usage

=== Adaptive sync and variable refresh rate ===

Adaptive sync is part of the DisplayPort specification and allows for graphics adapters to drive displays with varying frame timings.

Variable refresh rate (VRR) is essentially the same, but defined for HDMI.

=== Use cases for variable refresh rate ===

Variable frame (flip) timings don't align well with fixed refresh rate displays. This results in stuttering, tearing and/or input lag. By adjusting the display refresh rate dynamically these issues can be reduced or eliminated.

However, not all content is suitable for dynamic refresh adaptation. The user may experience "flickering" from differences in panel luminance at different refresh rates. Content that flips at an infrequent rate or demand is more likely to cause large changes in refresh rate that result in flickering.

Userland needs a way to let the driver know when the screen content is suitable for variable refresh rates.

=== DRM API to support variable refresh rates ===

This patch introduces a new API via atomic properties on the DRM connector and CRTC.

The drm_connector has one new optional boolean property:

* bool vrr_capable - set by the driver if the hardware is capable of supporting variable refresh rates

The drm_crtc has one new default boolean property:

* bool vrr_enabled - set by userspace indicating that variable refresh rate should be enabled

== Overview for DRM driver developers ===

Driver developers can attach the "vrr_capable" property by calling drm_connector_attach_vrr_capable_property(). This should be done on connectors that could be capable of supporting variable refresh rates (such as DP or HDMI).

The "vrr_capable" can then be updated accordingly by calling drm_connector_set_vrr_capable_property().

The "vrr_enabled" property can be checked from the drm_crtc_state object.

=== Overview for Userland developers ==

The "vrr_enabled" property on the CRTC should be set to true when the CRTC is suitable for variable refresh rates.

To demonstrate the suitability of the API for variable refresh and dynamic adaptation there are additional patches using this API that implement adaptive variable refresh across kernel and userland projects:

* DRM (dri-devel)
* amdgpu DRM kernel driver (amd-gfx)
* xf86-video-amdgpu (https://gitlab.freedesktop.org/xorg/driver/xf86-video-amdgpu)
* mesa (mesa-dev)

These patches enable adaptive variable refresh on X for AMD hardware. Support for variable refresh is disabled by default in xf86-video-amdgpu and will require additional user configuration.

The patches have been tested as working on upstream userland with the GNOME desktop environment under a single monitor setup. They also work on KDE in a single monitor setup with the compositor disabled.

The patches require that suitable applications flip via the Present extension to xf86-video-amdgpu for the entire Screen. Some compositors may interfere with this if they are unable to unredirect the window.

Full implementation details for these changes can be reviewed in their respective mailing lists and the xf86-video-amdgpu GitLab.

=== Previous discussions ===

These patches are based upon feedback from previous threads on the subject. These are linked below for reference:

https://lists.freedesktop.org/archives/amd-gfx/2018-April/021047.html
https://lists.freedesktop.org/archives/dri-devel/2017-October/155207.html
https://lists.freedesktop.org/archives/dri-devel/2018-September/189404.htm
https://lists.freedesktop.org/archives/dri-devel/2018-September/190910.html
https://lists.freedesktop.org/archives/dri-devel/2018-October/192211.html
https://lists.freedesktop.org/archives/dri-devel/2018-October/192874.html

Nicholas Kazlauskas (5):
drm: Add vrr_capable property to the drm connector
drm: Add vrr_enabled property to drm CRTC
drm: Document variable refresh properties
drm/amdgpu: Correct get_crtc_scanoutpos behavior when vpos >= vtotal drm/amdgpu: Set FreeSync state using drm VRR properties

 Documentation/gpu/drm-kms.rst                 |   7 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c   |   7 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h      |   7 -
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 255 +++++++++---------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |   7 +-
 drivers/gpu/drm/drm_atomic_uapi.c             |   4 +
 drivers/gpu/drm/drm_connector.c               | 110 ++++++++
 drivers/gpu/drm/drm_crtc.c                    |   2 +
 drivers/gpu/drm/drm_mode_config.c             |   6 +
 include/drm/drm_connector.h                   |  15 ++
 include/drm/drm_crtc.h                        |   9 +
 include/drm/drm_mode_config.h                 |   5 +
 12 files changed, 302 insertions(+), 132 deletions(-)
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 20181106202435.23556-1-nicholas.kazlauskas-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH v6 1/5 drm: Add vrr_capable property to the drm connector

Modern display hardware is capable of supporting variable refresh rates. This patch introduces the "vrr_capable" property on the connector to allow userspace to query support for variable refresh rates.

Atomic drivers should attach this property to connectors that are capable of driving variable refresh rates using drm_connector_attach_vrr_capable_property().

The value should be updated based on driver and hardware capabiltiy by using drm_connector_set_vrr_capable_property().

---
 drivers/gpu/drm/drm_connector.c | 49 +++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     | 15 ++++++++++
 2 files changed, 64 insertions(+)
drivers/gpu/drm/drm_connector.c +49 -0
index 4943cef178be..49290060ab7b 100644
@@ -1255,6 +1255,37 @@ int drm_mode_create_scaling_mode_property(struct drm_device *dev)
 }
 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
 
+/**
+ * drm_connector_attach_vrr_capable_property - creates the
+ * vrr_capable property
+ * @connector: connector to create the vrr_capable property on.
+ *
+ * This is used by atomic drivers to add support for querying
+ * variable refresh rate capability for a connector.
+ *
+ * Returns:
+ * Zero on success, negative errono on failure.
+ */
+int drm_connector_attach_vrr_capable_property(
+	struct drm_connector *connector)
+{
+	struct drm_device *dev = connector->dev;
+	struct drm_property *prop;
+
+	if (!connector->vrr_capable_property) {
+		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
+			"vrr_capable");
+		if (!prop)
+			return -ENOMEM;
+
+		connector->vrr_capable_property = prop;
+		drm_object_attach_property(&connector->base, prop, 0);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
+
 /**
  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
  * @connector: connector to attach scaling mode property on.
@@ -1583,6 +1614,24 @@ void drm_connector_set_link_status_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_connector_set_link_status_property);
 
+/**
+ * drm_connector_set_vrr_capable_property - sets the variable refresh rate
+ * capable property for a connector
+ * @connector: drm connector
+ * @capable: True if the connector is variable refresh rate capable
+ *
+ * Should be used by atomic drivers to update the indicated support for
+ * variable refresh rate over a connector.
+ */
+void drm_connector_set_vrr_capable_property(
+		struct drm_connector *connector, bool capable)
+{
+	drm_object_property_set_value(&connector->base,
+				      connector->vrr_capable_property,
+				      capable);
+}
+EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
+
 /**
  * drm_connector_init_panel_orientation_property -
  *	initialize the connecters panel_orientation property
include/drm/drm_connector.h +15 -0
index 9ccad6b062f2..4e6befff153b 100644
@@ -959,6 +959,17 @@ struct drm_connector {
 	 */
 	struct drm_property *scaling_mode_property;
 
+	/**
+	 * @vrr_capable_property: Optional property to help userspace
+	 * query hardware support for variable refresh rate on a connector.
+	 * connector. Drivers can add the property to a connector by
+	 * calling drm_connector_attach_vrr_capable_property().
+	 *
+	 * This should be updated only by calling
+	 * drm_connector_set_vrr_capable_property().
+	 */
+	struct drm_property *vrr_capable_property;
+
 	/**
 	 * @content_protection_property: DRM ENUM property for content
 	 * protection. See drm_connector_attach_content_protection_property().
@@ -1250,6 +1261,8 @@ int drm_mode_create_scaling_mode_property(struct drm_device *dev);
 int drm_connector_attach_content_type_property(struct drm_connector *dev);
 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
 					       u32 scaling_mode_mask);
+int drm_connector_attach_vrr_capable_property(
+		struct drm_connector *connector);
 int drm_connector_attach_content_protection_property(
 		struct drm_connector *connector);
 int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
@@ -1266,6 +1279,8 @@ int drm_connector_update_edid_property(struct drm_connector *connector,
 				       const struct edid *edid);
 void drm_connector_set_link_status_property(struct drm_connector *connector,
 					    uint64_t link_status);
+void drm_connector_set_vrr_capable_property(
+		struct drm_connector *connector, bool capable);
 int drm_connector_init_panel_orientation_property(
 	struct drm_connector *connector, int width, int height);
 
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#3 lore raw

PATCH v6 2/5 drm: Add vrr_enabled property to drm CRTC

In reply to a message not in the archive

This patch introduces the 'vrr_enabled' CRTC property to allow dynamic control over variable refresh rate support for a CRTC.

This property should be treated like a content hint to the driver - if the hardware or driver is not capable of driving variable refresh timings then this is not considered an error.

Capability for variable refresh rate support should be determined by querying the vrr_capable drm connector property.

It is worth noting that while the property is intended for atomic use it isn't filtered from legacy userspace queries. This allows for Xorg userspace drivers to implement support.

---
 drivers/gpu/drm/drm_atomic_uapi.c | 4 ++++
 drivers/gpu/drm/drm_crtc.c        | 2 ++
 drivers/gpu/drm/drm_mode_config.c | 6 ++++++
 include/drm/drm_crtc.h            | 9 +++++++++
 include/drm/drm_mode_config.h     | 5 +++++
 5 files changed, 26 insertions(+)
drivers/gpu/drm/drm_atomic_uapi.c +4 -0
index d5b7f315098c..eec396a57b88 100644
@@ -433,6 +433,8 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
 		ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
 		drm_property_blob_put(mode);
 		return ret;
+	} else if (property == config->prop_vrr_enabled) {
+		state->vrr_enabled = val;
 	} else if (property == config->degamma_lut_property) {
 		ret = drm_atomic_replace_property_blob_from_id(dev,
 					&state->degamma_lut,
@@ -491,6 +493,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc,
 		*val = state->active;
 	else if (property == config->prop_mode_id)
 		*val = (state->mode_blob) ? state->mode_blob->base.id : 0;
+	else if (property == config->prop_vrr_enabled)
+		*val = state->vrr_enabled;
 	else if (property == config->degamma_lut_property)
 		*val = (state->degamma_lut) ? state->degamma_lut->base.id : 0;
 	else if (property == config->ctm_property)
drivers/gpu/drm/drm_crtc.c +2 -0
index 268a182ae189..6f8ddfcfaba5 100644
@@ -340,6 +340,8 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
 		drm_object_attach_property(&crtc->base, config->prop_mode_id, 0);
 		drm_object_attach_property(&crtc->base,
 					   config->prop_out_fence_ptr, 0);
+		drm_object_attach_property(&crtc->base,
+					   config->prop_vrr_enabled, 0);
 	}
 
 	return 0;
drivers/gpu/drm/drm_mode_config.c +6 -0
index ee80788f2c40..5670c67f28d4 100644
@@ -310,6 +310,12 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.prop_mode_id = prop;
 
+	prop = drm_property_create_bool(dev, 0,
+			"VRR_ENABLED");
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.prop_vrr_enabled = prop;
+
 	prop = drm_property_create(dev,
 			DRM_MODE_PROP_BLOB,
 			"DEGAMMA_LUT", 0);
include/drm/drm_crtc.h +9 -0
index b21437bc95bf..39c3900aab3c 100644
@@ -290,6 +290,15 @@ struct drm_crtc_state {
 	 */
 	u32 pageflip_flags;
 
+	/**
+	 * @vrr_enabled:
+	 *
+	 * Indicates if variable refresh rate should be enabled for the CRTC.
+	 * Support for the requested vrr state will depend on driver and
+	 * hardware capabiltiy - lacking support is not treated as failure.
+	 */
+	bool vrr_enabled;
+
 	/**
 	 * @event:
 	 *
include/drm/drm_mode_config.h +5 -0
index 928e4172a0bb..49f2fcfdb5fc 100644
@@ -639,6 +639,11 @@ struct drm_mode_config {
 	 * connectors must be of and active must be set to disabled, too.
 	 */
 	struct drm_property *prop_mode_id;
+	/**
+	 * @prop_vrr_enabled: Default atomic CRTC property to indicate
+	 * whether variable refresh rate should be enabled on the CRTC.
+	 */
+	struct drm_property *prop_vrr_enabled;
 
 	/**
 	 * @dvi_i_subconnector_property: Optional DVI-I property to
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#4 lore raw

PATCH v6 3/5 drm: Document variable refresh properties

In reply to a message not in the archive

These include the drm_connector 'vrr_capable' and the drm_crtc 'vrr_enabled' properties.

Cc Harry Wentland <[email protected]>
Cc Manasi Navare <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Michel Dänzer <[email protected]>
---
 Documentation/gpu/drm-kms.rst   |  7 ++++
 drivers/gpu/drm/drm_connector.c | 61 +++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
Documentation/gpu/drm-kms.rst +7 -0
index 4b1501b4835b..8da2a178cf85 100644
@@ -575,6 +575,13 @@ Explicit Fencing Properties
 .. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
    :doc: explicit fencing properties
 
+
+Variable Refresh Properties
+---------------------------
+
+.. kernel-doc:: drivers/gpu/drm/drm_connector.c
+   :doc: Variable refresh properties
+
 Existing KMS Properties
 -----------------------
 
drivers/gpu/drm/drm_connector.c +61 -0

67 lines not on this page · raw message

Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20181106202435.23556-4-nicholas.kazlauskas-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Re: [PATCH v6 3/5] drm: Document variable refresh properties

Quoted 37 lines · Nicholas Kazlauskas

These include the drm_connector 'vrr_capable' and the drm_crtc 'vrr_enabled' properties.

Cc Harry Wentland <[email protected]>
Cc Manasi Navare <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Michel Dänzer <[email protected]>
---
 Documentation/gpu/drm-kms.rst   |  7 ++++
 drivers/gpu/drm/drm_connector.c | 61 +++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
Documentation/gpu/drm-kms.rst +7 -0
index 4b1501b4835b..8da2a178cf85 100644
@@ -575,6 +575,13 @@ Explicit Fencing Properties
 .. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
    :doc: explicit fencing properties
 
+
+Variable Refresh Properties
+---------------------------
+
+.. kernel-doc:: drivers/gpu/drm/drm_connector.c
+   :doc: Variable refresh properties
+
 Existing KMS Properties
 -----------------------
 
drivers/gpu/drm/drm_connector.c +0 -0
index 49290060ab7b..a6adf5450db3 100644

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1262

Quoted 8 lines
drivers/gpu/drm/drm_connector.c +5 -0
@@ -1255,6 +1255,67 @@ int drm_mode_create_scaling_mode_property(struct drm_device *dev)
 }
 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
 
+/**
+ * DOC: Variable refresh properties
+ *
+ * Variable refresh rate capable displays can dynamically adjust their
+ * refresh rate by extending the duration of their vertical porch until

vertical porch -> vertical front porch

Quoted 24 lines
drivers/gpu/drm/drm_connector.c +24 -0
+ * page flip or timeout occurs. This can reduce or remove stuttering
+ * and latency in scenarios where the page flip does not align with the
+ * vblank interval.
+ *
+ * An example scenario would be an application flipping at a constant rate
+ * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
+ * interval and the same contents will be displayed twice. This can be
+ * observed as stuttering for content with motion.
+ *
+ * If variable refresh rate was active on a display that supported a
+ * variable refresh range from 35Hz to 60Hz no stuttering would be observable
+ * for the example scenario. The minimum supported variable refresh rate of
+ * 35Hz is below the page flip frequency and the vertical front porch can
+ * be extended until the page flip occurs. The vblank interval will be
+ * directly aligned to the page flip rate.
+ *
+ * Userspace control for variable refresh rate is supported via properties
+ * on the &drm_connector and &drm_crtc objects.
+ *
+ * "vrr_capable":
+ *	Optional &drm_connector boolean property that drivers should attach
+ *	with drm_connector_attach_vrr_capable_property() on connectors that
+ *	could support variable refresh rates. Drivers should update the
+ *	property value by calling drm_connector_set_vrr_capable_property().

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1296

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ *
+ *	Absence of the property should indicate absence of support.
+ *
+ * "vrr_enabled":
+ *	Default &drm_crtc boolean property that notifies the driver that the
+ *	content on the CRTC is suitable for variable refresh rate presentation.
+ *	The driver will take this property as a hint to enable variable
+ *	refresh rate support if the receiver supports it, ie. if the
+ *	"vrr_capable" property is true on the &drm_connector object. The
+ *	veritcal front porch duration will be extended until page-flip or

veritcal -> vertical

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +5 -0
+ *	timeout when enabled.
+ *
+ *	The minimum vertical front porch duration is defined as the vertical
+ *	front porch duration for the current mode.
+ *

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1311

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ *	The maximum vertical front porch duration is greater than or equal to
+ *	the minimum vertical front porch duration. The duration is derived
+ *	from the minimum supported variable refresh rate for the connector.
+ *
+ *	The driver may place further restrictions within these minimum
+ *	and maximum bounds.
+ *
+ *	Some displays may exhibit noticeable differences in brightness when
+ *	varying vertical front porch duration.
+ *

Maybe something like this makes sense here:

* Some displays may exhibit noticeable differences in brightness when
* varying vertical front porch duration drastically. It is therefore
* advised userspace only provide the "vrr_enabled" hint for content
* with a render rate that is expected to change gradually frame to frame,
* such as games.

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1321

Quoted 11 lines
drivers/gpu/drm/drm_connector.c +7 -0
+ *	The semantics for the vertical blank timestamp differ when
+ *	variable refresh rate is active. The vertical blank timestamp
+ *	is defined to be an estimate using the current mode's fixed
+ *	refresh rate timings. The semantics for the page-flip event
+ *	timestamp remain the same.
+ */
+
 /**
  * drm_connector_attach_vrr_capable_property - creates the
  * vrr_capable property

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#7 lore raw

Re: [PATCH v6 3/5] drm: Document variable refresh properties

Quoted 104 lines · Harry
Quoted 37 lines · Nicholas Kazlauskas

These include the drm_connector 'vrr_capable' and the drm_crtc 'vrr_enabled' properties.

Cc Harry Wentland <[email protected]>
Cc Manasi Navare <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Michel Dänzer <[email protected]>
---
  Documentation/gpu/drm-kms.rst   |  7 ++++
  drivers/gpu/drm/drm_connector.c | 61 +++++++++++++++++++++++++++++++++
  2 files changed, 68 insertions(+)
Documentation/gpu/drm-kms.rst +7 -0
index 4b1501b4835b..8da2a178cf85 100644
@@ -575,6 +575,13 @@ Explicit Fencing Properties
  .. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
     :doc: explicit fencing properties
 
+
+Variable Refresh Properties
+---------------------------
+
+.. kernel-doc:: drivers/gpu/drm/drm_connector.c
+   :doc: Variable refresh properties
+
  Existing KMS Properties
  -----------------------
 
drivers/gpu/drm/drm_connector.c +0 -0
index 49290060ab7b..a6adf5450db3 100644

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1262

Quoted 8 lines
drivers/gpu/drm/drm_connector.c +5 -0
@@ -1255,6 +1255,67 @@ int drm_mode_create_scaling_mode_property(struct drm_device *dev)
  }
  EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
 
+/**
+ * DOC: Variable refresh properties
+ *
+ * Variable refresh rate capable displays can dynamically adjust their
+ * refresh rate by extending the duration of their vertical porch until

vertical porch -> vertical front porch

Quoted 24 lines
drivers/gpu/drm/drm_connector.c +24 -0
+ * page flip or timeout occurs. This can reduce or remove stuttering
+ * and latency in scenarios where the page flip does not align with the
+ * vblank interval.
+ *
+ * An example scenario would be an application flipping at a constant rate
+ * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
+ * interval and the same contents will be displayed twice. This can be
+ * observed as stuttering for content with motion.
+ *
+ * If variable refresh rate was active on a display that supported a
+ * variable refresh range from 35Hz to 60Hz no stuttering would be observable
+ * for the example scenario. The minimum supported variable refresh rate of
+ * 35Hz is below the page flip frequency and the vertical front porch can
+ * be extended until the page flip occurs. The vblank interval will be
+ * directly aligned to the page flip rate.
+ *
+ * Userspace control for variable refresh rate is supported via properties
+ * on the &drm_connector and &drm_crtc objects.
+ *
+ * "vrr_capable":
+ *	Optional &drm_connector boolean property that drivers should attach
+ *	with drm_connector_attach_vrr_capable_property() on connectors that
+ *	could support variable refresh rates. Drivers should update the
+ *	property value by calling drm_connector_set_vrr_capable_property().

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1296

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ *
+ *	Absence of the property should indicate absence of support.
+ *
+ * "vrr_enabled":
+ *	Default &drm_crtc boolean property that notifies the driver that the
+ *	content on the CRTC is suitable for variable refresh rate presentation.
+ *	The driver will take this property as a hint to enable variable
+ *	refresh rate support if the receiver supports it, ie. if the
+ *	"vrr_capable" property is true on the &drm_connector object. The
+ *	veritcal front porch duration will be extended until page-flip or

veritcal -> vertical

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +5 -0
+ *	timeout when enabled.
+ *
+ *	The minimum vertical front porch duration is defined as the vertical
+ *	front porch duration for the current mode.
+ *

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1311

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ *	The maximum vertical front porch duration is greater than or equal to
+ *	the minimum vertical front porch duration. The duration is derived
+ *	from the minimum supported variable refresh rate for the connector.
+ *
+ *	The driver may place further restrictions within these minimum
+ *	and maximum bounds.
+ *
+ *	Some displays may exhibit noticeable differences in brightness when
+ *	varying vertical front porch duration.
+ *
Quoted 7 lines

Maybe something like this makes sense here:

* Some displays may exhibit noticeable differences in brightness when
* varying vertical front porch duration drastically. It is therefore
* advised userspace only provide the "vrr_enabled" hint for content
* with a render rate that is expected to change gradually frame to frame,
* such as games.

Good point about mentioning that userspace shouldn't expect this to work well with frequent (and large) changes in vertical front porch duration.

I should probably more clearly word that the panel brightness may differ based on the vertical front porch duration. So large changes will be more noticeable.

Quoted 12 lines

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1321

Quoted 12 lines
drivers/gpu/drm/drm_connector.c +7 -0
+ *	The semantics for the vertical blank timestamp differ when
+ *	variable refresh rate is active. The vertical blank timestamp
+ *	is defined to be an estimate using the current mode's fixed
+ *	refresh rate timings. The semantics for the page-flip event
+ *	timestamp remain the same.
+ */
+
  /**
   * drm_connector_attach_vrr_capable_property - creates the
   * vrr_capable property

Thanks for the review, I'll fix up these for the next revision.

Nicholas Kazlauskas
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): a48c02c9-0e35-a9ca-08ea-99df83014d3f-5C7GfCeVMHo@public.gmane.org

#9 lore raw

Re: [PATCH v6 3/5] drm: Document variable refresh properties

Quoted 133 lines · Nicholas
Quoted 104 lines · Harry
Quoted 37 lines · Nicholas Kazlauskas

These include the drm_connector 'vrr_capable' and the drm_crtc 'vrr_enabled' properties.

Cc Harry Wentland <[email protected]>
Cc Manasi Navare <[email protected]>
Cc Pekka Paalanen <[email protected]>
Cc Ville Syrjälä <ville.syrjala-VuQAYsv1563Yd54FQh9/[email protected]>
Cc Michel Dänzer <[email protected]>
---
  Documentation/gpu/drm-kms.rst   |  7 ++++
  drivers/gpu/drm/drm_connector.c | 61 +++++++++++++++++++++++++++++++++
  2 files changed, 68 insertions(+)
Documentation/gpu/drm-kms.rst +7 -0
index 4b1501b4835b..8da2a178cf85 100644
@@ -575,6 +575,13 @@ Explicit Fencing Properties
  .. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
     :doc: explicit fencing properties
 
+
+Variable Refresh Properties
+---------------------------
+
+.. kernel-doc:: drivers/gpu/drm/drm_connector.c
+   :doc: Variable refresh properties
+
  Existing KMS Properties
  -----------------------
 
drivers/gpu/drm/drm_connector.c +0 -0
index 49290060ab7b..a6adf5450db3 100644

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1262

Quoted 8 lines
drivers/gpu/drm/drm_connector.c +5 -0
@@ -1255,6 +1255,67 @@ int drm_mode_create_scaling_mode_property(struct drm_device *dev)
  }
  EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
 
+/**
+ * DOC: Variable refresh properties
+ *
+ * Variable refresh rate capable displays can dynamically adjust their
+ * refresh rate by extending the duration of their vertical porch until  

vertical porch -> vertical front porch

Quoted 24 lines
drivers/gpu/drm/drm_connector.c +24 -0
+ * page flip or timeout occurs. This can reduce or remove stuttering
+ * and latency in scenarios where the page flip does not align with the
+ * vblank interval.
+ *
+ * An example scenario would be an application flipping at a constant rate
+ * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
+ * interval and the same contents will be displayed twice. This can be
+ * observed as stuttering for content with motion.
+ *
+ * If variable refresh rate was active on a display that supported a
+ * variable refresh range from 35Hz to 60Hz no stuttering would be observable
+ * for the example scenario. The minimum supported variable refresh rate of
+ * 35Hz is below the page flip frequency and the vertical front porch can
+ * be extended until the page flip occurs. The vblank interval will be
+ * directly aligned to the page flip rate.
+ *
+ * Userspace control for variable refresh rate is supported via properties
+ * on the &drm_connector and &drm_crtc objects.
+ *
+ * "vrr_capable":
+ *	Optional &drm_connector boolean property that drivers should attach
+ *	with drm_connector_attach_vrr_capable_property() on connectors that
+ *	could support variable refresh rates. Drivers should update the
+ *	property value by calling drm_connector_set_vrr_capable_property().

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1296

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ *
+ *	Absence of the property should indicate absence of support.
+ *
+ * "vrr_enabled":
+ *	Default &drm_crtc boolean property that notifies the driver that the
+ *	content on the CRTC is suitable for variable refresh rate presentation.
+ *	The driver will take this property as a hint to enable variable
+ *	refresh rate support if the receiver supports it, ie. if the
+ *	"vrr_capable" property is true on the &drm_connector object. The
+ *	veritcal front porch duration will be extended until page-flip or  

veritcal -> vertical

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +5 -0
+ *	timeout when enabled.
+ *
+ *	The minimum vertical front porch duration is defined as the vertical
+ *	front porch duration for the current mode.
+ *

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1311

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ *	The maximum vertical front porch duration is greater than or equal to
+ *	the minimum vertical front porch duration. The duration is derived
+ *	from the minimum supported variable refresh rate for the connector.
+ *
+ *	The driver may place further restrictions within these minimum
+ *	and maximum bounds.
+ *
+ *	Some displays may exhibit noticeable differences in brightness when
+ *	varying vertical front porch duration.
+ *  
Quoted 7 lines

Maybe something like this makes sense here:

* Some displays may exhibit noticeable differences in brightness when
* varying vertical front porch duration drastically. It is therefore
* advised userspace only provide the "vrr_enabled" hint for content
* with a render rate that is expected to change gradually frame to frame,
* such as games.

Good point about mentioning that userspace shouldn't expect this to work well with frequent (and large) changes in vertical front porch duration.

I should probably more clearly word that the panel brightness may differ based on the vertical front porch duration. So large changes will be more noticeable.

Quoted 12 lines

drivers/gpu/drm/drm_connector.c int drm_mode_create_scaling_mode_property(struct drm_device *dev) · line 1321

Quoted 12 lines
drivers/gpu/drm/drm_connector.c +7 -0
+ *	The semantics for the vertical blank timestamp differ when
+ *	variable refresh rate is active. The vertical blank timestamp
+ *	is defined to be an estimate using the current mode's fixed
+ *	refresh rate timings. The semantics for the page-flip event
+ *	timestamp remain the same.
+ */
+
  /**
   * drm_connector_attach_vrr_capable_property - creates the
   * vrr_capable property
Quoted 1 line

Thanks for the review, I'll fix up these for the next revision.

Hi Nicholas,

I am happy with this documentation.

- It explains exactly what VRR does: VRR allows extending the front porch from the video mode defined length to some maximum length.

- It guarantees that a flip is performed ASAP: when the buffer becomes ready (fences) and when the driver agrees on the first possible time to flip.

- The point about drivers also allows for drivers to prevent the luminance flickering by enforcing a maximum slew rate on the timings, should anyone want to implement that.

- The timestamps for vblank and pageflip events.

Btw. I don't think I yet understood the underlying mechanism on how a monitor could exhibit luminance changes due to VRR. Do you know, can you point me to some analysis on what happens? Are the liquid crystals slowly turning on their own without a refresh cycle, or?

Thanks,
pq

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#10 lore raw

PATCH v6 4/5 drm/amdgpu: Correct get_crtc_scanoutpos behavior when vpos >= vtotal

In reply to a message not in the archive

When variable refresh rate is active the hardware counter can return a position >= vtotal. This results in a vpos being returned from amdgpu_display_get_crtc_scanoutpos that's a positive value. The positive value indicates to the caller that the display is currently in scanout when the display is actually still in vblank.

This is because the vfront porch duration is unknown with variable refresh active and will end when either a page flip occurs or the timeout specified by the driver/display is reached.

The behavior of the amdgpu_display_get_crtc_scanoutpos remains the same when the position is below vtotal. When the position is above vtotal the function will return a value that is effectively -vbl_end, the size of the vback porch.

The only caller affected by this change is the DRM helper for calculating vblank timestamps. This change corrects behavior for calculating the page flip timestap from being the previous timestamp to the calculation to the next timestamp when position >= vtotal.

Cc Michel Dänzer <[email protected]>
Cc Harry Wentland <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +6 -1
index 6748cd7fc129..cb331319f225 100644
@@ -850,7 +850,12 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev,
 	/* Inside "upper part" of vblank area? Apply corrective offset if so: */
 	if (in_vbl && (*vpos >= vbl_start)) {
 		vtotal = mode->crtc_vtotal;
-		*vpos = *vpos - vtotal;
+
+		/* With variable refresh rate displays the vpos can exceed
+		 * the vtotal value. Clamp to 0 to return -vbl_end instead
+		 * of guessing the remaining number of lines until scanout.
+		 */
+		*vpos = (*vpos < vtotal) ? (*vpos - vtotal) : 0;
 	}
 
 	/* Correct for shifted end of vbl at vbl_end. */
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20181106202435.23556-5-nicholas.kazlauskas-5C7GfCeVMHo@public.gmane.org

Reviewed-by Harry Wentland
#12 lore raw

Re: [PATCH v6 4/5] drm/amdgpu: Correct get_crtc_scanoutpos behavior when vpos >= vtotal

Quoted 15 lines · Nicholas Kazlauskas

When variable refresh rate is active the hardware counter can return a position >= vtotal. This results in a vpos being returned from amdgpu_display_get_crtc_scanoutpos that's a positive value. The positive value indicates to the caller that the display is currently in scanout when the display is actually still in vblank.

This is because the vfront porch duration is unknown with variable refresh active and will end when either a page flip occurs or the timeout specified by the driver/display is reached.

The behavior of the amdgpu_display_get_crtc_scanoutpos remains the same when the position is below vtotal. When the position is above vtotal the function will return a value that is effectively -vbl_end, the size of the vback porch.

Quoted 6 lines

The only caller affected by this change is the DRM helper for calculating vblank timestamps. This change corrects behavior for calculating the page flip timestap from being the previous timestamp to the calculation to the next timestamp when position >= vtotal.

Harry

Quoted 15 lines
Cc Michel Dänzer <[email protected]>
Cc Harry Wentland <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +0 -0
index 6748cd7fc129..cb331319f225 100644
@@ -850,7 +850,12 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev,
 	/* Inside "upper part" of vblank area? Apply corrective offset if so: */
 	if (in_vbl && (*vpos >= vbl_start)) {
 		vtotal = mode->crtc_vtotal;

drivers/gpu/drm/amd/amdgpu/amdgpu_display.c int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev, · line 861

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +6 -1
-		*vpos = *vpos - vtotal;
+
+		/* With variable refresh rate displays the vpos can exceed
+		 * the vtotal value. Clamp to 0 to return -vbl_end instead
+		 * of guessing the remaining number of lines until scanout.
+		 */
+		*vpos = (*vpos < vtotal) ? (*vpos - vtotal) : 0;
 	}
 
 	/* Correct for shifted end of vbl at vbl_end. */

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#13 lore raw

PATCH v6 5/5 drm/amdgpu: Set FreeSync state using drm VRR properties

In reply to a message not in the archive

Support for AMDGPU specific FreeSync properties and ioctls are dropped from amdgpu_dm in favor of supporting drm variable refresh rate properties.

The notify_freesync and set_freesync_property functions are dropped from amdgpu_display_funcs.

The drm vrr_capable property is now attached to any DP/HDMI connector. Its value is updated accordingly to the connector's FreeSync capabiltiy.

The freesync_enable logic and ioctl control has has been dropped in favor of utilizing the vrr_enabled on the drm CRTC. This allows for more fine grained atomic control over which CRTCs should support variable refresh rate.

To handle state changes for vrr_enabled it was easiest to drop the forced modeset on freesync_enabled change. This patch now performs the required stream updates when planes are flipped.

This is done for a few reasons:

(1) VRR stream updates can be done in the fast update path

(2) amdgpu_dm_atomic_check would need to be hacked apart to check desired variable refresh state and capability before the CRTC disable pass.

(3) Performing VRR stream updates on-flip is needed for enabling BTR support.

VRR packets and timing adjustments are now tracked and compared to previous values sent to the hardware.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h      |   7 -
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 255 +++++++++---------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |   7 +-
 3 files changed, 138 insertions(+), 131 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h +0 -7
index b9e9e8b02fb7..0cbe867ec375 100644
@@ -295,13 +295,6 @@ struct amdgpu_display_funcs {
 			      uint16_t connector_object_id,
 			      struct amdgpu_hpd *hpd,
 			      struct amdgpu_router *router);
-	/* it is used to enter or exit into free sync mode */
-	int (*notify_freesync)(struct drm_device *dev, void *data,
-			       struct drm_file *filp);
-	/* it is used to allow enablement of freesync mode */
-	int (*set_freesync_property)(struct drm_connector *connector,
-				     struct drm_property *property,
-				     uint64_t val);
 
 
 };
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +133 -122

415 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +5 -2
index 978b34a5011c..a5aaf8b08968 100644
@@ -185,7 +185,11 @@ struct dm_crtc_state {
 	int crc_skip_count;
 	bool crc_enabled;
 
-	bool freesync_enabled;
+	bool freesync_timing_changed;
+	bool freesync_vrr_info_changed;
+
+	bool vrr_supported;
+	struct mod_freesync_config freesync_config;
 	struct dc_crtc_timing_adjust adjust;
 	struct dc_info_packet vrr_infopacket;
 };
@@ -207,7 +211,6 @@ struct dm_connector_state {
 	uint8_t underscan_vborder;
 	uint8_t underscan_hborder;
 	bool underscan_enable;
-	bool freesync_enable;
 	bool freesync_capable;
 };
 
Signature · 6 lines
2.19.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx