Skip to contentSkip to conversation

drm/drm_blend: allow blend mode property without PREMULTI

PATCH Superseded Leandro Ribeiro 2 participants 5 messages May 4 – May 5

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover drm/drm_blend: allow blend mode property without PREMULTI

Some hardware only supports the COVERAGE blend mode and lacks PREMULTI support entirely. DRM currently requires that PREMULTI is present when creating a blend mode property, which prevents such drivers from being properly upstreamed.

This series remove such restriction and allow drivers to create a blend mode property without PREMULTI.

v2: force drivers to expose blend mode if plane supports alpha property or pixel format with alpha.

Leandro Ribeiro (2):
drm/drm_blend: allow blend mode property without PREMULTI
drm: ensure blend mode supported if alpha exposed

 drivers/gpu/drm/drm_blend.c         | 21 ++++++++++-----
 drivers/gpu/drm/drm_crtc_internal.h |  1 +
 drivers/gpu/drm/drm_drv.c           |  7 ++++-
 drivers/gpu/drm/drm_mode_config.c   | 42 +++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 8 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/2 drm/drm_blend: allow blend mode property without PREMULTI

Some hardware only supports the COVERAGE blend mode and lacks PREMULTI support entirely. DRM currently requires that PREMULTI is present when creating a blend mode property, which prevents such drivers from being properly upstreamed.

Remove this restriction and allow drivers to create a blend mode property without PREMULTI, enabling support for hardware that implements only COVERAGE blend mode.

This does not introduce a regression, as no existing upstream drivers expose only COVERAGE. However, userspace that wants to support such kind of hardware in the future will have to check the supported blend modes instead of assuming PREMULTI is always supported.

---
 drivers/gpu/drm/drm_blend.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_blend.c +14 -7
index 1f3af27d2418..5ea0767f1cf5 100644
@@ -563,10 +563,10 @@ EXPORT_SYMBOL(drm_atomic_normalize_zpos);
 /**
  * drm_plane_create_blend_mode_property - create a new blend mode property
  * @plane: drm plane
- * @supported_modes: bitmask of supported modes, must include
- *		     BIT(DRM_MODE_BLEND_PREMULTI). Current DRM assumption is
- *		     that alpha is premultiplied, and old userspace can break if
- *		     the property defaults to anything else.
+ * @supported_modes: bitmask of supported modes. When
+ *		     BIT(DRM_MODE_BLEND_PREMULTI) is included, it will be used
+ *		     as the default. Otherwise, the default will fallback to one
+ *		     of the supported modes.
  *
  * This creates a new property describing the blend mode.
  *
@@ -599,13 +599,13 @@ int drm_plane_create_blend_mode_property(struct drm_plane *plane,
 		{ DRM_MODE_BLEND_PREMULTI, "Pre-multiplied" },
 		{ DRM_MODE_BLEND_COVERAGE, "Coverage" },
 	};
+	unsigned int default_mode;
 	unsigned int valid_mode_mask = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
 				       BIT(DRM_MODE_BLEND_PREMULTI)   |
 				       BIT(DRM_MODE_BLEND_COVERAGE);
 	int i;
 
-	if (WARN_ON((supported_modes & ~valid_mode_mask) ||
-		    ((supported_modes & BIT(DRM_MODE_BLEND_PREMULTI)) == 0)))
+	if (WARN_ON((supported_modes & ~valid_mode_mask)))
 		return -EINVAL;
 
 	prop = drm_property_create(dev, DRM_MODE_PROP_ENUM,
@@ -630,7 +630,14 @@ int drm_plane_create_blend_mode_property(struct drm_plane *plane,
 		}
 	}
 
-	drm_object_attach_property(&plane->base, prop, DRM_MODE_BLEND_PREMULTI);
+	if (supported_modes & BIT(DRM_MODE_BLEND_PREMULTI))
+		default_mode = DRM_MODE_BLEND_PREMULTI;
+	else if (supported_modes & BIT(DRM_MODE_BLEND_COVERAGE))
+		default_mode = DRM_MODE_BLEND_COVERAGE;
+	else
+		default_mode = DRM_MODE_BLEND_PIXEL_NONE;
+
+	drm_object_attach_property(&plane->base, prop, default_mode);
 	plane->blend_mode_property = prop;
 
 	return 0;
Signature · 1 line
2.54.0
#2 lore raw

PATCH v2 2/2 drm: ensure blend mode supported if alpha exposed

In reply to Leandro Ribeiro

Before "drm/drm_blend: allow blend mode property without PREMULTI", userspace would have to assume that only PREMULTI was supported by drivers that didn't expose the blend mode property. But now userspace shouldn't relly on that, as they can't count with drivers always supporting PREMULTI.

Error out if a driver expose alpha property or pixel formats with alpha and does not expose the blend mode property. This way userspace don't have to guess. Drivers that hit such error must be fixed.

---
 drivers/gpu/drm/drm_crtc_internal.h |  1 +
 drivers/gpu/drm/drm_drv.c           |  7 ++++-
 drivers/gpu/drm/drm_mode_config.c   | 42 +++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_crtc_internal.h +1 -0
index c09409229644..bdbb6b9b94ea 100644
@@ -96,6 +96,7 @@ int drm_mode_setcrtc(struct drm_device *dev,
 int drm_modeset_register_all(struct drm_device *dev);
 void drm_modeset_unregister_all(struct drm_device *dev);
 void drm_mode_config_validate(struct drm_device *dev);
+int drm_mode_config_enforce(struct drm_device *dev);
 
 /* drm_modes.c */
 const char *drm_get_mode_status_name(enum drm_mode_status status);
drivers/gpu/drm/drm_drv.c +6 -1
index 985c283cf59f..76766a370650 100644
@@ -1059,9 +1059,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 	const struct drm_driver *driver = dev->driver;
 	int ret;
 
-	if (!driver->load)
+	if (!driver->load) {
 		drm_mode_config_validate(dev);
 
+		ret = drm_mode_config_enforce(dev);
+		if (ret)
+			return ret;
+	}
+
 	WARN_ON(!dev->managed.final_kfree);
 
 	if (drm_dev_needs_global_mutex(dev))
drivers/gpu/drm/drm_mode_config.c +42 -0

45 lines not on this page · raw message

Signature · 1 line
2.54.0
#3 lore raw

Re: [PATCH v2 2/2] drm: ensure blend mode supported if alpha exposed

Quoted 34 lines · Leandro Ribeiro

Before "drm/drm_blend: allow blend mode property without PREMULTI", userspace would have to assume that only PREMULTI was supported by drivers that didn't expose the blend mode property. But now userspace shouldn't relly on that, as they can't count with drivers always supporting PREMULTI.

Error out if a driver expose alpha property or pixel formats with alpha and does not expose the blend mode property. This way userspace don't have to guess. Drivers that hit such error must be fixed.

---
 drivers/gpu/drm/drm_crtc_internal.h |  1 +
 drivers/gpu/drm/drm_drv.c           |  7 ++++-
 drivers/gpu/drm/drm_mode_config.c   | 42 +++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_crtc_internal.h +1 -0
index c09409229644..bdbb6b9b94ea 100644
@@ -96,6 +96,7 @@ int drm_mode_setcrtc(struct drm_device *dev,
 int drm_modeset_register_all(struct drm_device *dev);
 void drm_modeset_unregister_all(struct drm_device *dev);
 void drm_mode_config_validate(struct drm_device *dev);
+int drm_mode_config_enforce(struct drm_device *dev);
 
 /* drm_modes.c */
 const char *drm_get_mode_status_name(enum drm_mode_status status);
drivers/gpu/drm/drm_drv.c +0 -0
index 985c283cf59f..76766a370650 100644

drivers/gpu/drm/drm_drv.c int drm_dev_register(struct drm_device *dev, unsigned long flags) · line 1065

Quoted 8 lines
drivers/gpu/drm/drm_drv.c +2 -1
@@ -1059,9 +1059,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 	const struct drm_driver *driver = dev->driver;
 	int ret;
 
-	if (!driver->load)
+	if (!driver->load) {
 		drm_mode_config_validate(dev);
 
+		ret = drm_mode_config_enforce(dev);

Reading the code, I'll have no idea what "enforce" means here. Reading the function itself isn't helping either.

BR,
Jani.

Quoted 57 lines
drivers/gpu/drm/drm_drv.c +4 -0
+		if (ret)
+			return ret;
+	}
+
 	WARN_ON(!dev->managed.final_kfree);
 
 	if (drm_dev_needs_global_mutex(dev))
drivers/gpu/drm/drm_mode_config.c +42 -0
index 66f7dc37b597..20fd26ecb957 100644
@@ -738,3 +738,45 @@ void drm_mode_config_validate(struct drm_device *dev)
 	     "Must have as many primary planes as there are CRTCs, but have %u primary planes and %u CRTCs",
 	     num_primary, dev->mode_config.num_crtc);
 }
+
+static int plane_require_blend_mode_for_alpha(struct drm_plane *plane)
+{
+	struct drm_device *dev = plane->dev;
+	const struct drm_format_info *fmt;
+	u32 i;
+
+	/* blend mode property supported, no need to check anything */
+	if (plane->blend_mode_property)
+		return 0;
+
+	if (plane->alpha_property) {
+		drm_err(dev, "[PLANE:%d:%s] alpha property exposed but blend mode not setup",
+			plane->base.id, plane->name);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < plane->format_count; i++) {
+		fmt = drm_format_info(plane->format_types[i]);
+		if (fmt->has_alpha) {
+			drm_err(dev, "[PLANE:%d:%s] pixel format with alpha exposed but blend mode not setup",
+			        plane->base.id, plane->name);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+int drm_mode_config_enforce(struct drm_device *dev)
+{
+	struct drm_plane *plane;
+	int ret;
+
+	drm_for_each_plane(plane, dev) {
+		ret = plane_require_blend_mode_for_alpha(plane);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
Signature · 1 line
Jani Nikula, Intel
#4 lore raw

Re: [PATCH v2 2/2] drm: ensure blend mode supported if alpha exposed

Quoted 42 lines · Jani Nikula
Quoted 41 lines · Leandro Ribeiro

Before "drm/drm_blend: allow blend mode property without PREMULTI", userspace would have to assume that only PREMULTI was supported by drivers that didn't expose the blend mode property. But now userspace shouldn't relly on that, as they can't count with drivers always supporting PREMULTI.

Error out if a driver expose alpha property or pixel formats with alpha and does not expose the blend mode property. This way userspace don't have to guess. Drivers that hit such error must be fixed.

---
 drivers/gpu/drm/drm_crtc_internal.h |  1 +
 drivers/gpu/drm/drm_drv.c           |  7 ++++-
 drivers/gpu/drm/drm_mode_config.c   | 42 +++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_crtc_internal.h +1 -0
index c09409229644..bdbb6b9b94ea 100644
@@ -96,6 +96,7 @@ int drm_mode_setcrtc(struct drm_device *dev,
 int drm_modeset_register_all(struct drm_device *dev);
 void drm_modeset_unregister_all(struct drm_device *dev);
 void drm_mode_config_validate(struct drm_device *dev);
+int drm_mode_config_enforce(struct drm_device *dev);
 
 /* drm_modes.c */
 const char *drm_get_mode_status_name(enum drm_mode_status status);
drivers/gpu/drm/drm_drv.c +1 -1
index 985c283cf59f..76766a370650 100644
@@ -1059,9 +1059,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 	const struct drm_driver *driver = dev->driver;
 	int ret;
 
-	if (!driver->load)
+	if (!driver->load) {
 		drm_mode_config_validate(dev);
 
Quoted 8 lines

drivers/gpu/drm/drm_drv.c int drm_dev_register(struct drm_device *dev, unsigned long flags) · line 1065

Quoted 1 line
drivers/gpu/drm/drm_drv.c +1 -0
+		ret = drm_mode_config_enforce(dev);

Reading the code, I'll have no idea what "enforce" means here. Reading the function itself isn't helping either.

BR,
Jani.

Yes, the function name choice wasn't good.

drm_mode_config_validate() only produces warnings, while drm_mode_config_enforce() returns error codes and should be used to prevent initializing a driver that does not comply with the required rules. In this case, the rule being added is supporting plane alpha but not the blend mode property.

I could add such kind of rule to drm_mode_config_validate() itself, but I wasn't sure if people would be happy with it producing both warnings and errors. But maybe that would be a better approach than what I did.

Quoted 59 lines
Quoted 58 lines
drivers/gpu/drm/drm_drv.c +4 -0
+		if (ret)
+			return ret;
+	}
+
 	WARN_ON(!dev->managed.final_kfree);
 
 	if (drm_dev_needs_global_mutex(dev))
drivers/gpu/drm/drm_mode_config.c +42 -0
index 66f7dc37b597..20fd26ecb957 100644
@@ -738,3 +738,45 @@ void drm_mode_config_validate(struct drm_device *dev)
 	     "Must have as many primary planes as there are CRTCs, but have %u primary planes and %u CRTCs",
 	     num_primary, dev->mode_config.num_crtc);
 }
+
+static int plane_require_blend_mode_for_alpha(struct drm_plane *plane)
+{
+	struct drm_device *dev = plane->dev;
+	const struct drm_format_info *fmt;
+	u32 i;
+
+	/* blend mode property supported, no need to check anything */
+	if (plane->blend_mode_property)
+		return 0;
+
+	if (plane->alpha_property) {
+		drm_err(dev, "[PLANE:%d:%s] alpha property exposed but blend mode not setup",
+			plane->base.id, plane->name);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < plane->format_count; i++) {
+		fmt = drm_format_info(plane->format_types[i]);
+		if (fmt->has_alpha) {
+			drm_err(dev, "[PLANE:%d:%s] pixel format with alpha exposed but blend mode not setup",
+			        plane->base.id, plane->name);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+int drm_mode_config_enforce(struct drm_device *dev)
+{
+	struct drm_plane *plane;
+	int ret;
+
+	drm_for_each_plane(plane, dev) {
+		ret = plane_require_blend_mode_for_alpha(plane);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
Signature · 1 line
Leandro Ribeiro