[PATCH V10 33/46] drm: Add Enhanced LUT precision structure

Borah, Chaitanya Kumar chaitanya.kumar.borah at intel.com
Wed Jul 9 18:49:22 UTC 2025


Hi Alex,

> -----Original Message-----
> From: Alex Hung <alex.hung at amd.com>
> Sent: Tuesday, June 17, 2025 9:47 AM
> To: dri-devel at lists.freedesktop.org; amd-gfx at lists.freedesktop.org
> Cc: wayland-devel at lists.freedesktop.org; harry.wentland at amd.com;
> alex.hung at amd.com; leo.liu at amd.com; ville.syrjala at linux.intel.com;
> pekka.paalanen at collabora.com; contact at emersion.fr; mwen at igalia.com;
> jadahl at redhat.com; sebastian.wick at redhat.com;
> shashank.sharma at amd.com; agoins at nvidia.com; joshua at froggi.es;
> mdaenzer at redhat.com; aleixpol at kde.org; xaver.hugl at gmail.com;
> victoria at system76.com; daniel at ffwll.ch; Shankar, Uma
> <uma.shankar at intel.com>; quic_naseer at quicinc.com;
> quic_cbraga at quicinc.com; quic_abhinavk at quicinc.com; marcan at marcan.st;
> Liviu.Dudau at arm.com; sashamcintosh at google.com; Borah, Chaitanya
> Kumar <chaitanya.kumar.borah at intel.com>; louis.chauvet at bootlin.com;
> arthurgrillo at riseup.net
> Subject: [PATCH V10 33/46] drm: Add Enhanced LUT precision structure
> 
> From: Uma Shankar <uma.shankar at intel.com>
> 
> Existing LUT precision structure drm_color_lut has only 16 bit precision. This
> is not enough for upcoming enhanced hardwares and advance usecases like
> HDR processing. Hence added a new structure with 32 bit precision values.
> 
> Signed-off-by: Alex Hung <alex.hung at amd.com>
> Signed-off-by: Uma Shankar <uma.shankar at intel.com>
> Signed-off-by: Chaitanya Kumar Borah <chaitanya.kumar.borah at intel.com>
> ---
> V10:
>  - Include drm_color_lut_32 from Intel to support 32BIT RGB in 1D & 3D
>    LUTs (Uma Shankar)
> 
>  drivers/gpu/drm/drm_color_mgmt.c | 43
> ++++++++++++++++++++++++++++++++
>  include/drm/drm_color_mgmt.h     | 13 ++++++++++
>  include/uapi/drm/drm_mode.h      | 11 ++++++++
>  3 files changed, 67 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_color_mgmt.c
> b/drivers/gpu/drm/drm_color_mgmt.c
> index 3969dc548cff..83dc850d3b54 100644
> --- a/drivers/gpu/drm/drm_color_mgmt.c
> +++ b/drivers/gpu/drm/drm_color_mgmt.c
> @@ -630,3 +630,46 @@ int drm_color_lut_check(const struct
> drm_property_blob *lut, u32 tests)
>  	return 0;
>  }
>  EXPORT_SYMBOL(drm_color_lut_check);
> +
> +/**
> + * drm_color_lut_32_check - check validity of extended lookup table
> + * @lut: property blob containing extended LUT to check
> + * @tests: bitmask of tests to run
> + *
> + * Helper to check whether a userspace-provided extended lookup table
> +is valid and
> + * satisfies hardware requirements.  Drivers pass a bitmask indicating
> +which of
> + * the tests in &drm_color_lut_tests should be performed.
> + *
> + * Returns 0 on success, -EINVAL on failure.
> + */
> +int drm_color_lut_32_check(const struct drm_property_blob *lut, u32
> +tests) {
> +	const struct drm_color_lut_32 *entry;
> +	int i;
> +
> +	if (!lut || !tests)
> +		return 0;
> +
> +	entry = lut->data;
> +	for (i = 0; i < drm_color_lut_32_size(lut); i++) {
> +		if (tests & DRM_COLOR_LUT_EQUAL_CHANNELS) {
> +			if (entry[i].red != entry[i].blue ||
> +			    entry[i].red != entry[i].green) {
> +				DRM_DEBUG_KMS("All LUT entries must have
> equal r/g/b\n");
> +				return -EINVAL;
> +			}
> +		}
> +
> +		if (i > 0 && tests & DRM_COLOR_LUT_NON_DECREASING) {
> +			if (entry[i].red < entry[i - 1].red ||
> +			    entry[i].green < entry[i - 1].green ||
> +			    entry[i].blue < entry[i - 1].blue) {
> +				DRM_DEBUG_KMS("LUT entries must never
> decrease.\n");
> +				return -EINVAL;
> +			}
> +		}
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_color_lut_32_check);
> diff --git a/include/drm/drm_color_mgmt.h
> b/include/drm/drm_color_mgmt.h index ed81741036d7..882253a82bf1
> 100644
> --- a/include/drm/drm_color_mgmt.h
> +++ b/include/drm/drm_color_mgmt.h
> @@ -72,6 +72,18 @@ static inline int drm_color_lut_size(const struct
> drm_property_blob *blob)
>  	return blob->length / sizeof(struct drm_color_lut);  }
> 
> +/**
> + * drm_color_lut_32_size - calculate the number of entries in the
> +extended LUT
> + * @blob: blob containing the LUT
> + *
> + * Returns:
> + * The number of entries in the color LUT stored in @blob.
> + */
> +static inline int drm_color_lut_32_size(const struct drm_property_blob
> +*blob) {
> +	return blob->length / sizeof(struct drm_color_lut_32); }
> +
>  enum drm_color_encoding {
>  	DRM_COLOR_YCBCR_BT601,
>  	DRM_COLOR_YCBCR_BT709,
> @@ -118,4 +130,5 @@ enum drm_color_lut_tests {  };
> 
>  int drm_color_lut_check(const struct drm_property_blob *lut, u32 tests);
> +int drm_color_lut_32_check(const struct drm_property_blob *lut, u32
> +tests);
>  #endif
> diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
> index 651bdf48b766..21bd96f437e0 100644
> --- a/include/uapi/drm/drm_mode.h
> +++ b/include/uapi/drm/drm_mode.h
> @@ -872,6 +872,16 @@ struct drm_color_lut {
>  	__u16 reserved;
>  };
> 
> +struct drm_color_lut_32 {
> +	/*
> +	 * Similar to drm_color_lut but for high precision LUTs
> +	 */
> +	__u32 red;
> +	__u32 green;
> +	__u32 blue;
> +	__u32 reserved;
> +};
> +

Since currently there is no way for the kernel to communicate the precision of HW to user-space, I am guessing that we assume the precision of the LUT as U0.32
and driver is responsible for converting it to whatever the precision the HW needs.

In that case, do we also need a function to extract that similar to drm_color_lut_extract(). Something on the line of [1].

[1] https://lore.kernel.org/intel-gfx/20250702091936.3004854-7-uma.shankar@intel.com/

Regards

Chaitanya

>  /**
>   * enum drm_colorop_type - Type of color operation
>   *
> @@ -879,6 +889,7 @@ struct drm_color_lut {
>   * and defines a different set of properties. This enum defines all types and
>   * gives a high-level description.
>   */
> +
>  enum drm_colorop_type {
>  	/**
>  	 * @DRM_COLOROP_1D_CURVE:
> --
> 2.43.0



More information about the amd-gfx mailing list