From: Leandro Ribeiro <leandro.ribeiro@collabora.com>
To: Jani Nikula <jani.nikula@linux.intel.com>,
dri-devel@lists.freedesktop.org
Cc: airlied@gmail.com, daniels@collabora.com,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
pekka.paalanen@collabora.com, simona@ffwll.ch,
tzimmermann@suse.de, ville.syrjala@linux.intel.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] drm: ensure blend mode supported if alpha exposed
Date: Tue, 5 May 2026 10:14:33 -0300 [thread overview]
Message-ID: <f46b5843-017a-4717-8512-960e85bbe92a@collabora.com> (raw)
In-Reply-To: <c150652e3382375deea18c6c2555d5271c9ab8c5@intel.com>
On 5/5/26 4:57 AM, Jani Nikula wrote:
> On Mon, 04 May 2026, Leandro Ribeiro <leandro.ribeiro@collabora.com> wrote:
>> 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.
>>
>> Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
>> index c09409229644..bdbb6b9b94ea 100644
>> --- a/drivers/gpu/drm/drm_crtc_internal.h
>> +++ b/drivers/gpu/drm/drm_crtc_internal.h
>> @@ -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);
>> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
>> index 985c283cf59f..76766a370650 100644
>> --- a/drivers/gpu/drm/drm_drv.c
>> +++ b/drivers/gpu/drm/drm_drv.c
>> @@ -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.
>
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.
>
>> + if (ret)
>> + return ret;
>> + }
>> +
>> WARN_ON(!dev->managed.final_kfree);
>>
>> if (drm_dev_needs_global_mutex(dev))
>> diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c
>> index 66f7dc37b597..20fd26ecb957 100644
>> --- a/drivers/gpu/drm/drm_mode_config.c
>> +++ b/drivers/gpu/drm/drm_mode_config.c
>> @@ -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;
>> +}
>
--
Leandro Ribeiro
prev parent reply other threads:[~2026-05-05 13:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 14:06 [PATCH v2 0/2] drm/drm_blend: allow blend mode property without PREMULTI Leandro Ribeiro
2026-05-04 14:06 ` [PATCH v2 1/2] " Leandro Ribeiro
2026-05-04 14:06 ` [PATCH v2 2/2] drm: ensure blend mode supported if alpha exposed Leandro Ribeiro
2026-05-05 7:57 ` Jani Nikula
2026-05-05 13:14 ` Leandro Ribeiro [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f46b5843-017a-4717-8512-960e85bbe92a@collabora.com \
--to=leandro.ribeiro@collabora.com \
--cc=airlied@gmail.com \
--cc=daniels@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=pekka.paalanen@collabora.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
--cc=ville.syrjala@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox