This is an updated version of previous RFC series which adds post-blend
colorop support to AMD display driver [RFC v2].

As I mentioned in the previous version, I worked on a proposal to
migrate Gamescope, shifting from AMD driver-specific color properties to
the KMS colorop API [1], and the `AMD CRTC REGAMMA TF` is the only
driver-specific color property still missing upstream. I then
implemented this 1D post-blend curve — which had been missing from the
upstream kernel — based on Ariel&Nicolas’s proposal for post-blend
colorop support [2]. Matthew is now continuing and extending this work
on Gamescope.

Besides that, Robert is also using this support to offload the pre- and
post-blend color pipeline in Weston:
https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/2157

This series doesn't depend on the inactive plane color pipeline series
[3], but I already applied some of the plane rules:

1. AMD uses the committed state of colorops that aren't in the commit
   (as in "allow individual colorop changes").
2. "drm/atomic: duplicate CRTC colorop states" duplicates CRTC
   colorops for suspend/resume. If [3] lands first, the plane and CRTC
   duplication loops can be merged into one.

The rule that only colorops of an active (or (de)activating) pipeline
can be changed is not applied to CRTC colorops yet. I plan to extend it
once the plane approach in [3] is agreed.

Also, [3] adds a core check rejecting an enabled colorop without a DATA
blob. Until then, AMD checks it for the post-blend CTM itself.

[RFC v2] 
https://lore.kernel.org/dri-devel/[email protected]/
Changes:
- Rebase on drm-misc-next.
- New patches:
  - drm/atomic: handle CRTC colorops in drm_atomic_commit_set_colorop_state():
    adapt the lock assert added by 259907fef771 to CRTC colorops.
  - drm/atomic: duplicate CRTC colorop states: keep CRTC colorop values
    across suspend/resume.
  - drm/atomic: track individual CRTC colorop updates: set
    color_mgmt_changed when COLOR_PIPELINE changes, as done for planes.
  - drm/atomic: set hidden CRTC color mgmt model to default values.
- Dropped:
  - "drm/crtc: Track crtc color pipeline client cap in drm_crtc_state"
    and "drm/atomic: Pass crtc_color_pipeline client cap to atomic
    check": Drivers now choose between colorop and the CRTC color properties
    from crtc_state->color_pipeline, as for planes.
  - Dropped the CTM 3x4 and LUT32 extraction helpers: no users in this
    series.
- AMD:
  - enable post-blend colorop properties since the beginning of the
    post-blend colorop support to avoid unused function.
  - set colorop funcs on CRTC colorops (fixes a NULL dereference on destroy);
  - based on [3], use the committed state of colorops that aren't in the
    commit, check colorop types, program bypass explicitly, reject an
    enabled CTM colorop without DATA blob;
  - reset the CRTC degamma flags when in colorop mode;
  - move "move CRTC CTM color mgmt prop to check helper" before the
    post-blend colorop enablement.

You can check the implementation for Gamescope [1], which fully migrates
its color pipeline—shifting from AMD-specific color properties to
planes/CRTC colorops; on the kernel side, this just needs a
drm-misc-next kernel with this series applied.

[1] https://github.com/ValveSoftware/gamescope/pull/2113/commits
[2] 
https://lore.kernel.org/dri-devel/20251223-mtk-post-blend-color-pipeline-v3-0-7d969f9a3...@collabora.com/
[3] https://lore.kernel.org/dri-devel/[email protected]/

===  

This is one example of `drm_info` output on Steam Deck with
SteamOS/gamescope implementation and this kernel work:

├───CRTCs
│   ├───CRTC 0
│   │   ├───Object ID: 399
[...]
│   │       └───"COLOR_PIPELINE" (atomic): enum {Bypass, Color Pipeline 400} = 
Color Pipeline 400
│   │           ├───Bypass
│   │           └───Color Pipeline 400
│   │               ├───Color Operation 400
│   │               │   └───Properties
│   │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 3x4 Matrix
│   │               │       ├───"BYPASS" (atomic): range [0, 1] = 1
│   │               │       ├───"NEXT" (atomic, immutable): object colorop = 405
│   │               │       └───"DATA" (atomic): blob = 0
│   │               ├───Color Operation 405
│   │               │   └───Properties
│   │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D Curve
│   │               │       ├───"BYPASS" (atomic): range [0, 1] = 0
│   │               │       ├───"NEXT" (atomic, immutable): object colorop = 410
│   │               │       └───"CURVE_1D_TYPE" (atomic): enum {sRGB Inverse 
EOTF, PQ 125 Inverse EOTF, BT.2020 OETF, Gamma 2.2 Inverse, Gamma 2.4 Inverse, 
Gamma 2.6 Inverse} = PQ 125 Inverse EOTF
│   │               └───Color Operation 410
│   │                   └───Properties
│   │                       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D LUT
│   │                       ├───"BYPASS" (atomic): range [0, 1] = 1
│   │                       ├───"NEXT" (atomic, immutable): object colorop = 0
│   │                       ├───"SIZE" (atomic, immutable): range [0, 
UINT32_MAX] = 4096
│   │                       ├───"LUT1D_INTERPOLATION": enum {Linear} = Linear
│   │                       └───"DATA" (atomic): blob = 0

[...]

    ├───Plane 3
    │   ├───Object ID: 218
[...]
    │   └───Properties
    │       ├───"type" (immutable): enum {Overlay, Primary, Cursor} = Primary
    │       ├───"FB_ID" (atomic): object framebuffer = 513
    │       │   ├───Object ID: 513
[...]
    │       └───"COLOR_PIPELINE" (atomic): enum {Bypass, Color Pipeline 224} = 
Color Pipeline 224
    │           ├───Bypass
    │           └───Color Pipeline 224
    │               ├───Color Operation 224
    │               │   └───Properties
    │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = Fixed Matrix
    │               │       ├───"BYPASS" (atomic): range [0, 1] = 1
    │               │       ├───"NEXT" (atomic, immutable): object colorop = 229
    │               │       └───"FIXED_MATRIX_TYPE" (atomic): enum {YCbCr 601 
Full to RGB, YCbCr 601 Limited to RGB, YCbCr 709 Full to RGB, YCbCr 709 Limited 
to RGB, YCbCr 2020 NC Full to RGB, YCbCr 2020 NC Limited to RGB} = YCbCr 601 
Full to RGB
    │               ├───Color Operation 229
    │               │   └───Properties
    │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D Curve
    │               │       ├───"BYPASS" (atomic): range [0, 1] = 0
    │               │       ├───"NEXT" (atomic, immutable): object colorop = 234
    │               │       └───"CURVE_1D_TYPE" (atomic): enum {sRGB EOTF, PQ 
125 EOTF, BT.2020 Inverse OETF, Gamma 2.2, Gamma 2.4, Gamma 2.6} = sRGB EOTF
    │               ├───Color Operation 234
    │               │   └───Properties
    │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = Multiplier
    │               │       ├───"BYPASS" (atomic): range [0, 1] = 0
    │               │       ├───"NEXT" (atomic, immutable): object colorop = 239
    │               │       └───"MULTIPLIER" (atomic): range [0, UINT64_MAX] = 
4294967296
    │               ├───Color Operation 239
    │               │   └───Properties
    │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 3x4 Matrix
    │               │       ├───"BYPASS" (atomic): range [0, 1] = 1
    │               │       ├───"NEXT" (atomic, immutable): object colorop = 244
    │               │       └───"DATA" (atomic): blob = 0
    │               ├───Color Operation 244
    │               │   └───Properties
    │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D Curve
    │               │       ├───"BYPASS" (atomic): range [0, 1] = 0
    │               │       ├───"NEXT" (atomic, immutable): object colorop = 249
    │               │       └───"CURVE_1D_TYPE" (atomic): enum {sRGB Inverse 
EOTF, PQ 125 Inverse EOTF, BT.2020 OETF, Gamma 2.2 Inverse, Gamma 2.4 Inverse, 
Gamma 2.6 Inverse} = sRGB Inverse EOTF
    │               ├───Color Operation 249
    │               │   └───Properties
    │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D LUT
    │               │       ├───"BYPASS" (atomic): range [0, 1] = 0
    │               │       ├───"NEXT" (atomic, immutable): object colorop = 256
    │               │       ├───"SIZE" (atomic, immutable): range [0, 
UINT32_MAX] = 4096
    │               │       ├───"LUT1D_INTERPOLATION": enum {Linear} = Linear
    │               │       └───"DATA" (atomic): blob = 528
    │               ├───Color Operation 256
    │               │   └───Properties
    │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 3D LUT
    │               │       ├───"BYPASS" (atomic): range [0, 1] = 0
    │               │       ├───"NEXT" (atomic, immutable): object colorop = 263
    │               │       ├───"SIZE" (atomic, immutable): range [0, 
UINT32_MAX] = 17
    │               │       ├───"LUT3D_INTERPOLATION": enum {Tetrahedral} = 
Tetrahedral
    │               │       └───"DATA" (atomic): blob = 529
    │               ├───Color Operation 263
    │               │   └───Properties
    │               │       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D Curve
    │               │       ├───"BYPASS" (atomic): range [0, 1] = 0
    │               │       ├───"NEXT" (atomic, immutable): object colorop = 268
    │               │       └───"CURVE_1D_TYPE" (atomic): enum {sRGB EOTF, PQ 
125 EOTF, BT.2020 Inverse OETF, Gamma 2.2, Gamma 2.4, Gamma 2.6} = PQ 125 EOTF
    │               └───Color Operation 268
    │                   └───Properties
    │                       ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 
Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D LUT
    │                       ├───"BYPASS" (atomic): range [0, 1] = 1
    │                       ├───"NEXT" (atomic, immutable): object colorop = 0
    │                       ├───"SIZE" (atomic, immutable): range [0, 
UINT32_MAX] = 4096
    │                       ├───"LUT1D_INTERPOLATION": enum {Linear} = Linear
    │                       └───"DATA" (atomic): blob = 0

FWIW, here is the `drm_info` diff:

diff --git a/drm_info.h b/drm_info.h
index e61fda7..f7f2017 100644
--- a/drm_info.h
+++ b/drm_info.h
@@ -21,5 +21,6 @@ enum {
 /* Remove after updating libdrm */
 #define DRM_MODE_OBJECT_COLOROP 0xfafafafa
 #define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE    7
+#define DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE     8
 
 #endif
diff --git a/json.c b/json.c
index c9f8c72..b2c306b 100644
--- a/json.c
+++ b/json.c
@@ -29,6 +29,7 @@ static const struct {
        { "WRITEBACK_CONNECTORS", DRM_CLIENT_CAP_WRITEBACK_CONNECTORS },
        { "CURSOR_PLANE_HOTSPOT", DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT },
        { "PLANE_COLOR_PIPELINE", DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE },
+       { "CRTC_COLOR_PIPELINE", DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE },
 };

===

Melissa Wen (11):
  drm/atomic: handle CRTC colorops in drm_atomic_commit_set_colorop_state()
  drm/atomic: duplicate CRTC colorop states
  drm/atomic: track individual CRTC colorop updates
  drm/colorop: distinguish whether a colorop belongs to a plane or a CRTC
  drm/drm_mode_object: hide deprecated CRTC color mgmt props if colorop is set
  drm/atomic: set hidden CRTC color mgmt model to default values
  drm/drm_ioctl: guard DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE
  drm/amd/display: move CRTC CTM color mgmt prop to check helper
  drm/amd/display: enable post-blend CTM colorop
  drm/amd/display: add support to post-blend 1D-Curve colorop
  drm/amd/display: add support to post-blend 1D-LUT colorop

Nícolas F. R. A. Prado (8):
  drm/crtc: Add color pipeline to CRTC state
  drm/colorop: Allow parenting colorop to CRTC
  drm: Factor out common color_pipeline property initialization code
  drm/crtc: Add COLOR_PIPELINE property
  drm: Introduce DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE
  drm/atomic: Print the color pipeline as part of the CRTC state print
  drm/colorop: Factor out common paths from colorops helpers
  drm/colorop: Introduce colorop helpers for crtc

 .../amd/display/amdgpu_dm/amdgpu_dm_color.c   | 254 +++++++++++++---
 .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c |  76 +++++
 .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h |   2 +
 .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c    |  42 +++
 drivers/gpu/drm/drm_atomic.c                  |  17 +-
 drivers/gpu/drm/drm_atomic_helper.c           |  18 ++
 drivers/gpu/drm/drm_atomic_uapi.c             | 132 +++++++-
 drivers/gpu/drm/drm_colorop.c                 | 282 ++++++++++++++----
 drivers/gpu/drm/drm_connector.c               |   1 +
 drivers/gpu/drm/drm_crtc.c                    |  31 ++
 drivers/gpu/drm/drm_crtc_internal.h           |   1 +
 drivers/gpu/drm/drm_ioctl.c                   |  20 ++
 drivers/gpu/drm/drm_mode_object.c             |  18 ++
 drivers/gpu/drm/drm_plane.c                   |  34 +--
 drivers/gpu/drm/drm_property.c                |  44 +++
 include/drm/drm_atomic_uapi.h                 |   2 +
 include/drm/drm_colorop.h                     |  32 +-
 include/drm/drm_crtc.h                        |  21 ++
 include/drm/drm_file.h                        |   7 +
 include/drm/drm_property.h                    |   5 +
 include/uapi/drm/drm.h                        |  20 ++
 21 files changed, 912 insertions(+), 147 deletions(-)

-- 
2.53.0

Reply via email to