mbox series

[0/7] New DRM properties for output color format

Message ID 20240109181104.1670304-1-andri@yngvason.is (mailing list archive)
Headers show
Series New DRM properties for output color format | expand

Message

Andri Yngvason Jan. 9, 2024, 6:10 p.m. UTC
This is a subset of patches, originally submitted by Werner Sembach
titled: New uAPI drm properties for color management [1]

I've rebased against the current master branch, made modifications where
needed, and tested with both HDMI and DP on both Intel and AMD hardware,
using modified sway [2] and wlroots [3].

The original patch set added the following properties:
 - active bpc
 - active color format
 - active color range
 - preferred color format
and consolidated "Broadcast RGB" into a single property.

I've elected to only include active and preferred color format in this
patch set as I've very little interest in the other properties and,
hopefully, this will be easier for others to review.

[1]: https://lore.kernel.org/dri-devel/20210630151018.330354-1-wse@tuxedocomputers.com/
[2]: https://github.com/swaywm/sway/pull/7903
[3]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4509

Werner Sembach (7):
  drm/amd/display: Remove unnecessary SIGNAL_TYPE_HDMI_TYPE_A check
  drm/uAPI: Add "active color format" drm property as feedback for
    userspace
  drm/amd/display: Add handling for new "active color format" property
  drm/i915/display: Add handling for new "active color format" property
  drm/uAPI: Add "preferred color format" drm property as setting for
    userspace
  drm/amd/display: Add handling for new "preferred color format"
    property
  drm/i915/display: Add handling for new "preferred color format"
    property

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  75 ++++++++++--
 .../display/amdgpu_dm/amdgpu_dm_mst_types.c   |   8 ++
 drivers/gpu/drm/drm_atomic_helper.c           |   4 +
 drivers/gpu/drm/drm_atomic_uapi.c             |   4 +
 drivers/gpu/drm/drm_connector.c               | 111 ++++++++++++++++++
 drivers/gpu/drm/i915/display/intel_display.c  |  33 ++++++
 drivers/gpu/drm/i915/display/intel_dp.c       |  23 ++--
 drivers/gpu/drm/i915/display/intel_dp_mst.c   |  10 ++
 drivers/gpu/drm/i915/display/intel_hdmi.c     |  16 ++-
 include/drm/drm_connector.h                   |  27 +++++
 10 files changed, 289 insertions(+), 22 deletions(-)


base-commit: 1f874787ed9a2d78ed59cb21d0d90ac0178eceb0

Comments

Andri Yngvason Jan. 10, 2024, 12:52 p.m. UTC | #1
mið., 10. jan. 2024 kl. 11:10 skrifaði Daniel Vetter <daniel@ffwll.ch>:
>
> On Tue, Jan 09, 2024 at 06:11:00PM +0000, Andri Yngvason wrote:
> > +     /* Extract information from crtc to communicate it to userspace as connector properties */
> > +     for_each_new_connector_in_state(state, connector, new_con_state, i) {
> > +             struct drm_crtc *crtc = new_con_state->crtc;
> > +             struct dc_stream_state *stream;
> > +
> > +             if (crtc) {
> > +                     new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
> > +                     dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
> > +                     stream = dm_new_crtc_state->stream;
> > +
> > +                     if (stream) {
> > +                             drm_connector_set_active_color_format_property(connector,
> > +                                     convert_dc_pixel_encoding_into_drm_color_format(
> > +                                             dm_new_crtc_state->stream->timing.pixel_encoding));
> > +                     }
> > +             } else {
> > +                     drm_connector_set_active_color_format_property(connector, 0);
>
> Just realized an even bigger reason why your current design doesn't work:
> You don't have locking here.
>
> And you cannot grab the required lock, which is
> drm_dev->mode_config.mutex, because that would result in deadlocks. So
> this really needs to use the atomic state based design I've described.
>

Maybe we should just drop "actual color format" and instead fail the
modeset if the "preferred color format" property cannot be satisfied?
It seems like the simplest thing to do here, though it is perhaps less
convenient for userspace. In that case, the "preferred color format"
property should just be called "color format".

Thanks,
Andri
Andri Yngvason Jan. 10, 2024, 5:15 p.m. UTC | #2
Hi Werner,

mið., 10. jan. 2024 kl. 13:14 skrifaði Werner Sembach <wse@tuxedocomputers.com>:
>
> Hi,
>
> Am 10.01.24 um 14:09 schrieb Daniel Vetter:
> > On Wed, 10 Jan 2024 at 13:53, Andri Yngvason <andri@yngvason.is> wrote:
> >> mið., 10. jan. 2024 kl. 11:10 skrifaði Daniel Vetter <daniel@ffwll.ch>:
> >>> On Tue, Jan 09, 2024 at 06:11:00PM +0000, Andri Yngvason wrote:
> >>>> +     /* Extract information from crtc to communicate it to userspace as connector properties */
> >>>> +     for_each_new_connector_in_state(state, connector, new_con_state, i) {
> >>>> +             struct drm_crtc *crtc = new_con_state->crtc;
> >>>> +             struct dc_stream_state *stream;
> >>>> +
> >>>> +             if (crtc) {
> >>>> +                     new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
> >>>> +                     dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
> >>>> +                     stream = dm_new_crtc_state->stream;
> >>>> +
> >>>> +                     if (stream) {
> >>>> +                             drm_connector_set_active_color_format_property(connector,
> >>>> +                                     convert_dc_pixel_encoding_into_drm_color_format(
> >>>> +                                             dm_new_crtc_state->stream->timing.pixel_encoding));
> >>>> +                     }
> >>>> +             } else {
> >>>> +                     drm_connector_set_active_color_format_property(connector, 0);
> >>> Just realized an even bigger reason why your current design doesn't work:
> >>> You don't have locking here.
> >>>
> >>> And you cannot grab the required lock, which is
> >>> drm_dev->mode_config.mutex, because that would result in deadlocks. So
> >>> this really needs to use the atomic state based design I've described.
> >>>
> >> Maybe we should just drop "actual color format" and instead fail the
> >> modeset if the "preferred color format" property cannot be satisfied?
> >> It seems like the simplest thing to do here, though it is perhaps less
> >> convenient for userspace. In that case, the "preferred color format"
> >> property should just be called "color format".
> > Yeah that's more in line with how other atomic properties work. This
> > way userspace can figure out what works with a TEST_ONLY commit too.
> > And for this to work you probably want to have an "automatic" setting
> > too.
> > -Sima
>
> The problem with TEST_ONLY probing is that color format settings are
> interdependent: https://gitlab.freedesktop.org/drm/amd/-/issues/476#note_966634
>
> So changing any other setting may require every color format to be TEST_ONLY
> probed again.
>

If we put a bit map containing the possible color formats into
drm_mode_mode_info (I'm thinking that it could go into flags), we'd be
able to eliminate a bunch of combinations early on. Do you think that
would make things more bearable?

I'm thinking, something like this:
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index 128d09138ceb3..59980803cb89e 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -124,6 +124,13 @@ extern "C" {
 #define  DRM_MODE_FLAG_PIC_AR_256_135 \
                        (DRM_MODE_PICTURE_ASPECT_256_135<<19)

+/* Possible color formats (4 bits) */
+#define DRM_MODE_FLAG_COLOR_FORMAT_MASK (0x0f << 22)
+#define DRM_MODE_FLAG_COLOR_FORMAT_RGB (1 << 22)
+#define DRM_MODE_FLAG_COLOR_FORMAT_YCBCR444 (1 << 23)
+#define DRM_MODE_FLAG_COLOR_FORMAT_YCBCR422 (1 << 24)
+#define DRM_MODE_FLAG_COLOR_FORMAT_YCBCR420 (1 << 25)
+
 #define  DRM_MODE_FLAG_ALL     (DRM_MODE_FLAG_PHSYNC |         \
                                 DRM_MODE_FLAG_NHSYNC |         \
                                 DRM_MODE_FLAG_PVSYNC |         \
@@ -136,7 +143,8 @@ extern "C" {
                                 DRM_MODE_FLAG_HSKEW |          \
                                 DRM_MODE_FLAG_DBLCLK |         \
                                 DRM_MODE_FLAG_CLKDIV2 |        \
-                                DRM_MODE_FLAG_3D_MASK)
+                                DRM_MODE_FLAG_3D_MASK |        \
+                                DRM_MODE_FLAG_COLOR_FORMAT_MASK)

 /* DPMS flags */
 /* bit compatible with the xorg definitions. */