Re: [Intel-gfx] [PATCH 1/2] drm: Add color management LUT validation helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Matt,

On Tue, Dec 11, 2018 at 05:05:50PM -0800, Matt Roper wrote:
> Some hardware may place additional restrictions on the gamma/degamma
> curves described by our LUT properties.  E.g., that a gamma curve never
> decreases or that the red/green/blue channels of a LUT's entries must be
> equal.  Let's add a couple helpers that drivers can use to test that a
> userspace-provided LUT doesn't violate hardware requirements.
> 
> Cc: Uma Shankar <uma.shankar@xxxxxxxxx>
> Cc: Swati Sharma <swati2.sharma@xxxxxxxxx>
> Signed-off-by: Matt Roper <matthew.d.roper@xxxxxxxxx>
> ---
>  drivers/gpu/drm/drm_color_mgmt.c | 53 ++++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_color_mgmt.h     |  3 +++
>  2 files changed, 56 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c
> index 07dcf47daafe..41e617e34c10 100644
> --- a/drivers/gpu/drm/drm_color_mgmt.c
> +++ b/drivers/gpu/drm/drm_color_mgmt.c
> @@ -462,3 +462,56 @@ int drm_plane_create_color_properties(struct drm_plane *plane,
>  	return 0;
>  }
>  EXPORT_SYMBOL(drm_plane_create_color_properties);
> +
> +/**
> + * drm_color_lut_has_equal_channels - check LUT for equal r/g/b values
> + * @lut: property blob containing LUT to check
> + *
> + * Helper to check whether the entries of a LUT all have equal values for the
> + * red, green, and blue channels.  Some hardware can only be programmed
> + * with a single value per LUT entry, which is assumed to apply to all
> + * three color components.
> + */
> +bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut)
> +{
> +	struct drm_color_lut *entry;
> +	int i;
> +
> +	if (!lut)
> +		return true;
> +
> +	entry = lut->data;
> +	for (i = 0; i < drm_color_lut_size(lut); i++)
> +		if (entry[i].red != entry[i].blue ||
> +		    entry[i].red != entry[i].green)
> +			return false;
> +
> +	return true;
> +}
> +EXPORT_SYMBOL(drm_color_lut_has_equal_channels);

We've got this open-coded for some of our HW, so thanks for the helper
:-)

> +
> +/**
> + * drm_color_lut_is_increasing - check that LUT is always flat/increasing
> + * @lut: LUT to check
> + *
> + * Helper to check whether the entries of a LUT are always flat or increasing
> + * (never decreasing).
> + */
> +bool drm_color_lut_is_increasing(struct drm_property_blob *lut)
> +{
> +	struct drm_color_lut *entry;
> +	int i;
> +
> +	if (!lut)
> +		return true;
> +
> +	entry = lut->data;
> +	for (i = 1; i < drm_color_lut_size(lut); i++)
> +		if (entry[i].red < entry[i-1].red ||
> +		    entry[i].green < entry[i-1].green ||
> +		    entry[i].blue < entry[i-1].blue)
> +			return false;

nit: I think checkpatch likes spaces around operators: [i - 1]

Another thought: in the worst case with a valid LUT with HW that needs
both checks, you can end up iterating the whole LUT twice - once for
increasing, and once for equal channels.

Maybe this could be a single function with a mask of constraints to
check:

  drm_color_lut_check(lut, DRM_COLOR_LUT_EQUAL_CHANNELS | DRM_COLOR_LUT_INCREASING);

Not sure if it would turn out messy with the different loop bounds.

Either way, for mali-dp it makes no difference, and probably
LUTs aren't changing all the time so:

Reviewed-by: Brian Starkey <brian.starkey@xxxxxxx>

> +
> +	return true;
> +}
> +EXPORT_SYMBOL(drm_color_lut_is_increasing);
> diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h
> index 90ef9996d9a4..6c38f5477e29 100644
> --- a/include/drm/drm_color_mgmt.h
> +++ b/include/drm/drm_color_mgmt.h
> @@ -69,4 +69,7 @@ int drm_plane_create_color_properties(struct drm_plane *plane,
>  				      u32 supported_ranges,
>  				      enum drm_color_encoding default_encoding,
>  				      enum drm_color_range default_range);
> +
> +bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut);
> +bool drm_color_lut_is_increasing(struct drm_property_blob *lut);
>  #endif
> -- 
> 2.14.4
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux