Skip to content

Commit 99a4e4f

Browse files
Alex Hungemersion
authored andcommitted
drm/colorop: Add 1D Curve Custom LUT type
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
1 parent 9452977 commit 99a4e4f

5 files changed

Lines changed: 82 additions & 0 deletions

File tree

drivers/gpu/drm/drm_atomic.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,10 @@ static void drm_atomic_colorop_print_state(struct drm_printer *p,
794794
drm_printf(p, "\tcurve_1d_type=%s\n",
795795
drm_get_colorop_curve_1d_type_name(state->curve_1d_type));
796796
break;
797+
case DRM_COLOROP_1D_LUT:
798+
drm_printf(p, "\tsize=%d\n", colorop->size);
799+
drm_printf(p, "\tdata blob id=%d\n", state->data ? state->data->base.id : 0);
800+
break;
797801
case DRM_COLOROP_CTM_3X4:
798802
drm_printf(p, "\tdata blob id=%d\n", state->data ? state->data->base.id : 0);
799803
break;

drivers/gpu/drm/drm_atomic_uapi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@ static int drm_atomic_color_set_data_property(struct drm_colorop *colorop,
699699
bool replaced = false;
700700

701701
switch (colorop->type) {
702+
case DRM_COLOROP_1D_LUT:
703+
size = colorop->size * sizeof(struct drm_color_lut32);
704+
break;
702705
case DRM_COLOROP_CTM_3X4:
703706
size = sizeof(struct drm_color_ctm_3x4);
704707
break;
@@ -750,6 +753,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop,
750753
*val = state->bypass;
751754
else if (property == colorop->curve_1d_type_property)
752755
*val = state->curve_1d_type;
756+
else if (property == colorop->size_property)
757+
*val = colorop->size;
753758
else if (property == colorop->data_property)
754759
*val = (state->data) ? state->data->base.id : 0;
755760
else

drivers/gpu/drm/drm_colorop.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = {
6666
{ DRM_COLOROP_1D_CURVE, "1D Curve" },
67+
{ DRM_COLOROP_1D_LUT, "1D LUT" },
6768
{ DRM_COLOROP_CTM_3X4, "3x4 Matrix"},
6869
};
6970

@@ -264,6 +265,47 @@ static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_color
264265
return 0;
265266
}
266267

268+
/**
269+
* drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT
270+
*
271+
* @dev: DRM device
272+
* @colorop: The drm_colorop object to initialize
273+
* @plane: The associated drm_plane
274+
* @lut_size: LUT size supported by driver
275+
* @return zero on success, -E value on failure
276+
*/
277+
int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *colorop,
278+
struct drm_plane *plane, uint32_t lut_size)
279+
{
280+
struct drm_property *prop;
281+
int ret;
282+
283+
ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_LUT);
284+
if (ret)
285+
return ret;
286+
287+
/* initialize 1D LUT only attribute */
288+
/* LUT size */
289+
prop = drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ATOMIC,
290+
"SIZE", 0, UINT_MAX);
291+
if (!prop)
292+
return -ENOMEM;
293+
294+
colorop->size_property = prop;
295+
drm_object_attach_property(&colorop->base, colorop->size_property, lut_size);
296+
colorop->size = lut_size;
297+
298+
/* data */
299+
ret = drm_colorop_create_data_prop(dev, colorop);
300+
if (ret)
301+
return ret;
302+
303+
drm_colorop_reset(colorop);
304+
305+
return 0;
306+
}
307+
EXPORT_SYMBOL(drm_plane_colorop_curve_1d_lut_init);
308+
267309
int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
268310
struct drm_plane *plane)
269311
{
@@ -371,6 +413,7 @@ void drm_colorop_reset(struct drm_colorop *colorop)
371413

372414
static const char * const colorop_type_name[] = {
373415
[DRM_COLOROP_1D_CURVE] = "1D Curve",
416+
[DRM_COLOROP_1D_LUT] = "1D LUT",
374417
[DRM_COLOROP_CTM_3X4] = "3x4 Matrix",
375418
};
376419

include/drm/drm_colorop.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,27 @@ struct drm_colorop {
257257
*/
258258
struct drm_property *bypass_property;
259259

260+
/**
261+
* @size:
262+
*
263+
* Number of entries of the custom LUT. This should be read-only.
264+
*/
265+
uint32_t size;
266+
260267
/**
261268
* @curve_1d_type_property:
262269
*
263270
* Sub-type for DRM_COLOROP_1D_CURVE type.
264271
*/
265272
struct drm_property *curve_1d_type_property;
266273

274+
/**
275+
* @size_property:
276+
*
277+
* Size property for custom LUT from userspace.
278+
*/
279+
struct drm_property *size_property;
280+
267281
/**
268282
* @data_property:
269283
*
@@ -311,6 +325,8 @@ void drm_colorop_cleanup(struct drm_colorop *colorop);
311325

312326
int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
313327
struct drm_plane *plane, u64 supported_tfs);
328+
int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *colorop,
329+
struct drm_plane *plane, uint32_t lut_size);
314330
int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
315331
struct drm_plane *plane);
316332

include/uapi/drm/drm_mode.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,20 @@ enum drm_colorop_type {
902902
*/
903903
DRM_COLOROP_1D_CURVE,
904904

905+
/**
906+
* @DRM_COLOROP_1D_LUT:
907+
*
908+
* enum string "1D LUT"
909+
*
910+
* A simple 1D LUT of uniformly spaced &drm_color_lut32 entries,
911+
* packed into a blob via the DATA property. The driver's
912+
* expected LUT size is advertised via the SIZE property.
913+
*
914+
* The DATA blob is an array of struct drm_color_lut32 with size
915+
* of "size".
916+
*/
917+
DRM_COLOROP_1D_LUT,
918+
905919
/**
906920
* @DRM_COLOROP_CTM_3X4:
907921
*

0 commit comments

Comments
 (0)