]> Gentwo Git Trees - linux/.git/commitdiff
drm/colorop: Add 1D Curve Custom LUT type
authorAlex Hung <alex.hung@amd.com>
Sat, 15 Nov 2025 00:02:02 +0000 (17:02 -0700)
committerSimon Ser <contact@emersion.fr>
Wed, 26 Nov 2025 22:03:35 +0000 (23:03 +0100)
We've previously introduced DRM_COLOROP_1D_CURVE for
pre-defined 1D curves. But we also have HW that supports
custom curves and userspace needs the ability to pass
custom curves, aka LUTs.

This patch introduces a new colorop type, called
DRM_COLOROP_1D_LUT that provides a SIZE property which
is used by a driver to advertise the supported SIZE
of the LUT, as well as a DATA property which userspace
uses to set the LUT.

DATA and size function in the same way as current drm_crtc
GAMMA and DEGAMMA LUTs.

Reviewed-by: Simon Ser <contact@emersion.fr>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Co-developed-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Simon Ser <contact@emersion.fr>
Link: https://patch.msgid.link/20251115000237.3561250-38-alex.hung@amd.com
drivers/gpu/drm/drm_atomic.c
drivers/gpu/drm/drm_atomic_uapi.c
drivers/gpu/drm/drm_colorop.c
include/drm/drm_colorop.h
include/uapi/drm/drm_mode.h

index 60b3a069f4ddf1db589ec0495f559171b8826cfa..142fc52bc5b2d65f6d36d131c10617db9272e0b0 100644 (file)
@@ -794,6 +794,10 @@ static void drm_atomic_colorop_print_state(struct drm_printer *p,
                drm_printf(p, "\tcurve_1d_type=%s\n",
                           drm_get_colorop_curve_1d_type_name(state->curve_1d_type));
                break;
+       case DRM_COLOROP_1D_LUT:
+               drm_printf(p, "\tsize=%d\n", colorop->size);
+               drm_printf(p, "\tdata blob id=%d\n", state->data ? state->data->base.id : 0);
+               break;
        case DRM_COLOROP_CTM_3X4:
                drm_printf(p, "\tdata blob id=%d\n", state->data ? state->data->base.id : 0);
                break;
index 6f4345b9b2a3c1a4130e732d1a69de049e185b51..b9045b17fa62bbf28a0f7d87b5f66a93fab2b779 100644 (file)
@@ -699,6 +699,9 @@ static int drm_atomic_color_set_data_property(struct drm_colorop *colorop,
        bool replaced = false;
 
        switch (colorop->type) {
+       case DRM_COLOROP_1D_LUT:
+               size = colorop->size * sizeof(struct drm_color_lut32);
+               break;
        case DRM_COLOROP_CTM_3X4:
                size = sizeof(struct drm_color_ctm_3x4);
                break;
@@ -750,6 +753,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop,
                *val = state->bypass;
        else if (property == colorop->curve_1d_type_property)
                *val = state->curve_1d_type;
+       else if (property == colorop->size_property)
+               *val = colorop->size;
        else if (property == colorop->data_property)
                *val = (state->data) ? state->data->base.id : 0;
        else
index 46e4942b66e6099cf33fb2425b066fd4899bf873..eaf457d0700c11a94bf6881c5a9616720857bc33 100644 (file)
@@ -64,6 +64,7 @@
 
 static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = {
        { DRM_COLOROP_1D_CURVE, "1D Curve" },
+       { DRM_COLOROP_1D_LUT, "1D LUT" },
        { DRM_COLOROP_CTM_3X4, "3x4 Matrix"},
 };
 
@@ -264,6 +265,47 @@ static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_color
        return 0;
 }
 
+/**
+ * drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT
+ *
+ * @dev: DRM device
+ * @colorop: The drm_colorop object to initialize
+ * @plane: The associated drm_plane
+ * @lut_size: LUT size supported by driver
+ * @return zero on success, -E value on failure
+ */
+int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *colorop,
+                                       struct drm_plane *plane, uint32_t lut_size)
+{
+       struct drm_property *prop;
+       int ret;
+
+       ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_LUT);
+       if (ret)
+               return ret;
+
+       /* initialize 1D LUT only attribute */
+       /* LUT size */
+       prop = drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ATOMIC,
+                                        "SIZE", 0, UINT_MAX);
+       if (!prop)
+               return -ENOMEM;
+
+       colorop->size_property = prop;
+       drm_object_attach_property(&colorop->base, colorop->size_property, lut_size);
+       colorop->size = lut_size;
+
+       /* data */
+       ret = drm_colorop_create_data_prop(dev, colorop);
+       if (ret)
+               return ret;
+
+       drm_colorop_reset(colorop);
+
+       return 0;
+}
+EXPORT_SYMBOL(drm_plane_colorop_curve_1d_lut_init);
+
 int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
                                   struct drm_plane *plane)
 {
@@ -371,6 +413,7 @@ void drm_colorop_reset(struct drm_colorop *colorop)
 
 static const char * const colorop_type_name[] = {
        [DRM_COLOROP_1D_CURVE] = "1D Curve",
+       [DRM_COLOROP_1D_LUT] = "1D LUT",
        [DRM_COLOROP_CTM_3X4] = "3x4 Matrix",
 };
 
index 067805276b15babcf820a0ba4eca952d48453658..529af9f8266da6c28ca3cbd91fd8811153831c8b 100644 (file)
@@ -257,6 +257,13 @@ struct drm_colorop {
         */
        struct drm_property *bypass_property;
 
+       /**
+        * @size:
+        *
+        * Number of entries of the custom LUT. This should be read-only.
+        */
+       uint32_t size;
+
        /**
         * @curve_1d_type_property:
         *
@@ -264,6 +271,13 @@ struct drm_colorop {
         */
        struct drm_property *curve_1d_type_property;
 
+       /**
+        * @size_property:
+        *
+        * Size property for custom LUT from userspace.
+        */
+       struct drm_property *size_property;
+
        /**
         * @data_property:
         *
@@ -311,6 +325,8 @@ void drm_colorop_cleanup(struct drm_colorop *colorop);
 
 int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
                                    struct drm_plane *plane, u64 supported_tfs);
+int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *colorop,
+                                       struct drm_plane *plane, uint32_t lut_size);
 int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
                                   struct drm_plane *plane);
 
index 5e637ec7b64c77200c5579a26445e23d1bce772d..bec524e2fa320ecb5cad64ece6f8755ba595c7ea 100644 (file)
@@ -902,6 +902,20 @@ enum drm_colorop_type {
         */
        DRM_COLOROP_1D_CURVE,
 
+       /**
+        * @DRM_COLOROP_1D_LUT:
+        *
+        * enum string "1D LUT"
+        *
+        * A simple 1D LUT of uniformly spaced &drm_color_lut32 entries,
+        * packed into a blob via the DATA property. The driver's
+        * expected LUT size is advertised via the SIZE property.
+        *
+        * The DATA blob is an array of struct drm_color_lut32 with size
+        * of "size".
+        */
+       DRM_COLOROP_1D_LUT,
+
        /**
         * @DRM_COLOROP_CTM_3X4:
         *