Re: [PATCH v11 15/28] drm/connector: hdmi: Compute bpc and format automatically

From: Maxime Ripard
Date: Fri Apr 19 2024 - 09:02:52 EST


On Tue, Apr 16, 2024 at 04:50:58PM +0300, Ville Syrjälä wrote:
> On Tue, Mar 26, 2024 at 04:40:19PM +0100, Maxime Ripard wrote:
> > Now that we have all the infrastructure needed, we can add some code
> > that will, for a given connector state and mode, compute the best output
> > format and bpc.
> >
> > The algorithm is equivalent to the one already found in i915 and vc4.
> >
> > Signed-off-by: Maxime Ripard <mripard@xxxxxxxxxx>
> > ---
> > drivers/gpu/drm/display/drm_hdmi_state_helper.c | 197 ++++++++++++++++++++-
> > drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 25 ++-
> > 2 files changed, 210 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/display/drm_hdmi_state_helper.c b/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> > index 063421835dba..b9bc0fb027ea 100644
> > --- a/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> > +++ b/drivers/gpu/drm/display/drm_hdmi_state_helper.c
> > @@ -1,9 +1,11 @@
> > // SPDX-License-Identifier: MIT
> >
> > #include <drm/drm_atomic.h>
> > #include <drm/drm_connector.h>
> > +#include <drm/drm_edid.h>
> > +#include <drm/drm_print.h>
> >
> > #include <drm/display/drm_hdmi_helper.h>
> > #include <drm/display/drm_hdmi_state_helper.h>
> >
> > /**
> > @@ -46,10 +48,110 @@ connector_state_get_mode(const struct drm_connector_state *conn_state)
> > return NULL;
> >
> > return &crtc_state->mode;
> > }
> >
> > +static bool
> > +sink_supports_format_bpc(const struct drm_connector *connector,
> > + const struct drm_display_info *info,
> > + const struct drm_display_mode *mode,
> > + unsigned int format, unsigned int bpc)
> > +{
> > + struct drm_device *dev = connector->dev;
> > + u8 vic = drm_match_cea_mode(mode);
> > +
> > + /*
> > + * CTA-861-F, section 5.4 - Color Coding & Quantization states
> > + * that the bpc must be 8, 10, 12 or 16 except for the default
> > + * 640x480 VIC1 where the value must be 8.
> > + *
> > + * The definition of default here is ambiguous but the spec
> > + * refers to VIC1 being the default timing in several occasions
> > + * so our understanding is that for the default timing (ie,
> > + * VIC1), the bpc must be 8.
> > + */
> > + if (vic == 1 && bpc != 8) {
> > + drm_dbg_kms(dev, "VIC1 requires a bpc of 8, got %u\n", bpc);
> > + return false;
> > + }
> > +
> > + if (!info->is_hdmi &&
> > + (format != HDMI_COLORSPACE_RGB || bpc != 8)) {
> > + drm_dbg_kms(dev, "DVI Monitors require an RGB output at 8 bpc\n");
> > + return false;
> > + }
> > +
> > + if (!(connector->hdmi.supported_formats & BIT(format))) {
>
> These are the capabilities of the souce I take it?
>
> > + drm_dbg_kms(dev, "%s format unsupported by the connector.\n",
> > + drm_hdmi_connector_get_output_format_name(format));
> > + return false;
> > + }
> > +
> > + switch (format) {
> > + case HDMI_COLORSPACE_RGB:
> > + drm_dbg_kms(dev, "RGB Format, checking the constraints.\n");
> > +
> > + if (!(info->color_formats & DRM_COLOR_FORMAT_RGB444))
> > + return false;
>
> and this is the sink.
>
> Maybe we should use the same bits for both? Anyways, that seems like
> material for a followup series.

Ack

> > +
> > + if (bpc == 10 && !(info->edid_hdmi_rgb444_dc_modes & DRM_EDID_HDMI_DC_30)) {
> > + drm_dbg_kms(dev, "10 BPC but sink doesn't support Deep Color 30.\n");
> > + return false;
> > + }
> > +
> > + if (bpc == 12 && !(info->edid_hdmi_rgb444_dc_modes & DRM_EDID_HDMI_DC_36)) {
> > + drm_dbg_kms(dev, "12 BPC but sink doesn't support Deep Color 36.\n");
> > + return false;
> > + }
> > +
> > + drm_dbg_kms(dev, "RGB format supported in that configuration.\n");
> > +
> > + return true;
> > +
> > + case HDMI_COLORSPACE_YUV422:
> > + drm_dbg_kms(dev, "YUV422 format, checking the constraints.\n");
> > +
> > + if (!(info->color_formats & DRM_COLOR_FORMAT_YCBCR422)) {
> > + drm_dbg_kms(dev, "Sink doesn't support YUV422.\n");
> > + return false;
> > + }
> > +
> > + if (bpc != 12) {
> > + drm_dbg_kms(dev, "YUV422 only supports 12 bpc.\n");
> > + return false;
> > + }
>
> Did something change around here from the last time?

The format selection code now prefers to select a lower bpc rather than
another format, which is what you asked for in the previous version.

Attachment: signature.asc
Description: PGP signature