Skip to contentSkip to conversation

drm/docs: Document where the C8 color lut is stored

PATCH In review Daniel Vetter 7 participants 14 messages Jan 24, 2022 – Jan 25, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/docs: Document where the C8 color lut is stored

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Motivated by comments from Geert that we have a gap here.

Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +4 -0
index bb14f488c8f6..96ce57ad37e6 100644
@@ -82,6 +82,10 @@
  *	driver boot-up state too. Drivers can access this blob through
  *	&drm_crtc_state.gamma_lut.
  *
+ *	Note that for mostly historical reasons stemming from Xorg heritage,
+ *	this is also used to store the color lookup table (CLUT) for indexed
+ *	formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *	Unsigned range property to give the size of the lookup table to be set
  *	on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +10 -0
index 4d01b4d89775..03cc53220a2a 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
 	 * Lookup table for converting pixel data after the color conversion
 	 * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
 	 * NULL) is an array of &struct drm_color_lut.
+	 *
+	 * Note that for mostly historical reasons stemming from Xorg heritage,
+	 * this is also used to store the color lookup table (CLUT) for indexed
+	 * formats like DRM_FORMAT_C8.
 	 */
 	struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
 	/**
 	 * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
 	 * by calling drm_mode_crtc_set_gamma_size().
+	 *
+	 * Note that atomic drivers need to instead use
+	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
 	 */
 	uint32_t gamma_size;
 
 	/**
 	 * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
 	 * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+	 *
+	 * Note that atomic drivers need to instead use
+	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
 	 */
 	uint16_t *gamma_store;
 
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Daniel,

Thank you for the patch.

Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Exists, maybe, exists and has a real use case, I'd be surprised.

Quoted 20 lines

Motivated by comments from Geert that we have a gap here.

Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +0 -0
index bb14f488c8f6..96ce57ad37e6 100644

drivers/gpu/drm/drm_color_mgmt.c line 87

Quoted 6 lines
drivers/gpu/drm/drm_color_mgmt.c +3 -0
@@ -82,6 +82,10 @@
  *	driver boot-up state too. Drivers can access this blob through
  *	&drm_crtc_state.gamma_lut.
  *
+ *	Note that for mostly historical reasons stemming from Xorg heritage,
+ *	this is also used to store the color lookup table (CLUT) for indexed
+ *	formats like DRM_FORMAT_C8.

CLUT also stands for Cubic Look Up Table, a type of LUT commonly used for tone mapping that maps an RGB sample (in 3D space) to a colour. Compared to traditional LUTs such as gamma and degamma, it allows correlating colour components, while the gamma and degamma LUTs operate on each colour component independently.

Is there any commonly used acronym for the indexed colours lookup table that we could use here, to avoid future confusions ?

Other than that,

Quoted 38 lines
drivers/gpu/drm/drm_color_mgmt.c +1 -0
+ *
  * “GAMMA_LUT_SIZE”:
  *	Unsigned range property to give the size of the lookup table to be set
  *	on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +10 -0
index 4d01b4d89775..03cc53220a2a 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
 	 * Lookup table for converting pixel data after the color conversion
 	 * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
 	 * NULL) is an array of &struct drm_color_lut.
+	 *
+	 * Note that for mostly historical reasons stemming from Xorg heritage,
+	 * this is also used to store the color lookup table (CLUT) for indexed
+	 * formats like DRM_FORMAT_C8.
 	 */
 	struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
 	/**
 	 * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
 	 * by calling drm_mode_crtc_set_gamma_size().
+	 *
+	 * Note that atomic drivers need to instead use
+	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
 	 */
 	uint32_t gamma_size;
 
 	/**
 	 * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
 	 * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+	 *
+	 * Note that atomic drivers need to instead use
+	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
 	 */
 	uint16_t *gamma_store;
 
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw
Quoted 51 lines · Laurent Pinchart

Hi Daniel,

Thank you for the patch.

Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Exists, maybe, exists and has a real use case, I'd be surprised.

Quoted 20 lines

Motivated by comments from Geert that we have a gap here.

Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +0 -0
index bb14f488c8f6..96ce57ad37e6 100644

drivers/gpu/drm/drm_color_mgmt.c line 87

Quoted 6 lines
drivers/gpu/drm/drm_color_mgmt.c +3 -0
@@ -82,6 +82,10 @@
  *   driver boot-up state too. Drivers can access this blob through
  *   &drm_crtc_state.gamma_lut.
  *
+ *   Note that for mostly historical reasons stemming from Xorg heritage,
+ *   this is also used to store the color lookup table (CLUT) for indexed
+ *   formats like DRM_FORMAT_C8.

CLUT also stands for Cubic Look Up Table, a type of LUT commonly used for tone mapping that maps an RGB sample (in 3D space) to a colour. Compared to traditional LUTs such as gamma and degamma, it allows correlating colour components, while the gamma and degamma LUTs operate on each colour component independently.

Quoted 2 lines

Is there any commonly used acronym for the indexed colours lookup table that we could use here, to avoid future confusions ?

Hm intel calls these 3DLUT, so for me there's not confusion here :-) But also since random acronyms are bad I put both the acronym and the full spelling into the text.

The cubic lut for me sounds more like cubic filtering from texture units (yet another thing). Do you want me to just drop the CLUT (I figured some people might search for that in the docs, and there's really no other way find this) or ok this way? I don't really have a better idea.
-Daniel

Quoted 48 lines

Other than that,

Quoted 28 lines
drivers/gpu/drm/drm_color_mgmt.c +1 -0
+ *
  * “GAMMA_LUT_SIZE”:
  *   Unsigned range property to give the size of the lookup table to be set
  *   on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +7 -0
index 4d01b4d89775..03cc53220a2a 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
       * Lookup table for converting pixel data after the color conversion
       * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
       * NULL) is an array of &struct drm_color_lut.
+      *
+      * Note that for mostly historical reasons stemming from Xorg heritage,
+      * this is also used to store the color lookup table (CLUT) for indexed
+      * formats like DRM_FORMAT_C8.
       */
      struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
      /**
       * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
       * by calling drm_mode_crtc_set_gamma_size().
+      *
+      * Note that atomic drivers need to instead use
+      * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
       */
      uint32_t gamma_size;

include/drm/drm_crtc.h struct drm_crtc { · line 1096

Quoted 10 lines
include/drm/drm_crtc.h +3 -0
 
      /**
       * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
       * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+      *
+      * Note that atomic drivers need to instead use
+      * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
       */
      uint16_t *gamma_store;
 

--
Regards,

Laurent Pinchart

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#3 lore raw

Hi Daniel,

Quoted 54 lines · Daniel Vetter
Quoted 46 lines · Laurent Pinchart
Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Exists, maybe, exists and has a real use case, I'd be surprised.

Quoted 20 lines

Motivated by comments from Geert that we have a gap here.

Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +0 -0
index bb14f488c8f6..96ce57ad37e6 100644

drivers/gpu/drm/drm_color_mgmt.c line 87

Quoted 6 lines
drivers/gpu/drm/drm_color_mgmt.c +3 -0
@@ -82,6 +82,10 @@
  *   driver boot-up state too. Drivers can access this blob through
  *   &drm_crtc_state.gamma_lut.
  *
+ *   Note that for mostly historical reasons stemming from Xorg heritage,
+ *   this is also used to store the color lookup table (CLUT) for indexed
+ *   formats like DRM_FORMAT_C8.

CLUT also stands for Cubic Look Up Table, a type of LUT commonly used for tone mapping that maps an RGB sample (in 3D space) to a colour. Compared to traditional LUTs such as gamma and degamma, it allows correlating colour components, while the gamma and degamma LUTs operate on each colour component independently.

Quoted 2 lines

Is there any commonly used acronym for the indexed colours lookup table that we could use here, to avoid future confusions ?

Hm intel calls these 3DLUT, so for me there's not confusion here :-) But also since random acronyms are bad I put both the acronym and the full spelling into the text.

Quoted 5 lines

The cubic lut for me sounds more like cubic filtering from texture units (yet another thing). Do you want me to just drop the CLUT (I figured some people might search for that in the docs, and there's really no other way find this) or ok this way? I don't really have a better idea.

fbdev uses "color map", "color palette" seems to also be a common term. Maybe use one of those two ?

Quoted 42 lines
Quoted 42 lines

Other than that,

Quoted 38 lines
drivers/gpu/drm/drm_color_mgmt.c +1 -0
+ *
  * “GAMMA_LUT_SIZE”:
  *   Unsigned range property to give the size of the lookup table to be set
  *   on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +10 -0
index 4d01b4d89775..03cc53220a2a 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
       * Lookup table for converting pixel data after the color conversion
       * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
       * NULL) is an array of &struct drm_color_lut.
+      *
+      * Note that for mostly historical reasons stemming from Xorg heritage,
+      * this is also used to store the color lookup table (CLUT) for indexed
+      * formats like DRM_FORMAT_C8.
       */
      struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
      /**
       * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
       * by calling drm_mode_crtc_set_gamma_size().
+      *
+      * Note that atomic drivers need to instead use
+      * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
       */
      uint32_t gamma_size;
 
      /**
       * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
       * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+      *
+      * Note that atomic drivers need to instead use
+      * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
       */
      uint16_t *gamma_store;
 
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw
Quoted 58 lines · Laurent Pinchart

Hi Daniel,

Quoted 54 lines · Daniel Vetter
Quoted 46 lines · Laurent Pinchart
Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Exists, maybe, exists and has a real use case, I'd be surprised.

Quoted 20 lines

Motivated by comments from Geert that we have a gap here.

Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +0 -0
index bb14f488c8f6..96ce57ad37e6 100644

drivers/gpu/drm/drm_color_mgmt.c line 87

Quoted 6 lines
drivers/gpu/drm/drm_color_mgmt.c +3 -0
@@ -82,6 +82,10 @@
  *   driver boot-up state too. Drivers can access this blob through
  *   &drm_crtc_state.gamma_lut.
  *
+ *   Note that for mostly historical reasons stemming from Xorg heritage,
+ *   this is also used to store the color lookup table (CLUT) for indexed
+ *   formats like DRM_FORMAT_C8.

CLUT also stands for Cubic Look Up Table, a type of LUT commonly used for tone mapping that maps an RGB sample (in 3D space) to a colour. Compared to traditional LUTs such as gamma and degamma, it allows correlating colour components, while the gamma and degamma LUTs operate on each colour component independently.

Quoted 2 lines

Is there any commonly used acronym for the indexed colours lookup table that we could use here, to avoid future confusions ?

Hm intel calls these 3DLUT, so for me there's not confusion here :-) But also since random acronyms are bad I put both the acronym and the full spelling into the text.

Quoted 8 lines
Quoted 5 lines

The cubic lut for me sounds more like cubic filtering from texture units (yet another thing). Do you want me to just drop the CLUT (I figured some people might search for that in the docs, and there's really no other way find this) or ok this way? I don't really have a better idea.

fbdev uses "color map", "color palette" seems to also be a common term. Maybe use one of those two ?

Sounds good, I'll just add them all in parathesis. The more the better the chance people find this.
-Daniel

Quoted 48 lines
Quoted 34 lines
Quoted 34 lines

Other than that,

Quoted 29 lines
drivers/gpu/drm/drm_color_mgmt.c +1 -0
+ *
  * “GAMMA_LUT_SIZE”:
  *   Unsigned range property to give the size of the lookup table to be set
  *   on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +7 -0
index 4d01b4d89775..03cc53220a2a 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
       * Lookup table for converting pixel data after the color conversion
       * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
       * NULL) is an array of &struct drm_color_lut.
+      *
+      * Note that for mostly historical reasons stemming from Xorg heritage,
+      * this is also used to store the color lookup table (CLUT) for indexed
+      * formats like DRM_FORMAT_C8.
       */
      struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
      /**
       * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
       * by calling drm_mode_crtc_set_gamma_size().
+      *
+      * Note that atomic drivers need to instead use
+      * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
       */
      uint32_t gamma_size;
 
Quoted 9 lines
Quoted 9 lines

include/drm/drm_crtc.h struct drm_crtc { · line 1096

Quoted 9 lines
include/drm/drm_crtc.h +3 -0
      /**
       * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
       * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+      *
+      * Note that atomic drivers need to instead use
+      * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
       */
      uint16_t *gamma_store;
 

--
Regards,

Laurent Pinchart

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#5 lore raw

PATCH 1/1 drm/docs: Document where the C8 color lut is stored

In reply to Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

Cc Laurent Pinchart <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +4 -0
index bb14f488c8f6..9079fbe21d2f 100644
@@ -82,6 +82,10 @@
  *	driver boot-up state too. Drivers can access this blob through
  *	&drm_crtc_state.gamma_lut.
  *
+ *	Note that for mostly historical reasons stemming from Xorg heritage,
+ *	this is also used to store the color map (also sometimes color lut, CLUT
+ *	or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *	Unsigned range property to give the size of the lookup table to be set
  *	on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +10 -0
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
 	 * Lookup table for converting pixel data after the color conversion
 	 * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
 	 * NULL) is an array of &struct drm_color_lut.
+	 *
+	 * Note that for mostly historical reasons stemming from Xorg heritage,
+	 * this is also used to store the color map (also sometimes color lut,
+	 * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
 	 */
 	struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
 	/**
 	 * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
 	 * by calling drm_mode_crtc_set_gamma_size().
+	 *
+	 * Note that atomic drivers need to instead use
+	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
 	 */
 	uint32_t gamma_size;
 
 	/**
 	 * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
 	 * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+	 *
+	 * Note that atomic drivers need to instead use
+	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
 	 */
 	uint16_t *gamma_store;
 
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#6 lore raw
Quoted 15 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

Quoted 10 lines
Cc Laurent Pinchart <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Quoted 57 lines
---
 drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +4 -0
index bb14f488c8f6..9079fbe21d2f 100644
@@ -82,6 +82,10 @@
  *     driver boot-up state too. Drivers can access this blob through
  *     &drm_crtc_state.gamma_lut.
  *
+ *     Note that for mostly historical reasons stemming from Xorg heritage,
+ *     this is also used to store the color map (also sometimes color lut, CLUT
+ *     or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *     Unsigned range property to give the size of the lookup table to be set
  *     on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +10 -1
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
         * Lookup table for converting pixel data after the color conversion
         * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
         * NULL) is an array of &struct drm_color_lut.
+        *
+        * Note that for mostly historical reasons stemming from Xorg heritage,
+        * this is also used to store the color map (also sometimes color lut,
+        * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
         */
        struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
        /**
         * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
         * by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint32_t gamma_size;
 
        /**
         * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
         * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint16_t *gamma_store;
 
--

2.33.0

#7 lore raw
Quoted 27 lines · Alex Deucher
Quoted 15 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

Quoted 10 lines
Cc Laurent Pinchart <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Quoted 1 line

Thanks for taking a look, pushed to drm-misc-next. -Daniel

Quoted 58 lines
Quoted 58 lines
---
 drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
 include/drm/drm_crtc.h           | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +4 -0
index bb14f488c8f6..9079fbe21d2f 100644
@@ -82,6 +82,10 @@
  *     driver boot-up state too. Drivers can access this blob through
  *     &drm_crtc_state.gamma_lut.
  *
+ *     Note that for mostly historical reasons stemming from Xorg heritage,
+ *     this is also used to store the color map (also sometimes color lut, CLUT
+ *     or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *     Unsigned range property to give the size of the lookup table to be set
  *     on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +10 -1
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
         * Lookup table for converting pixel data after the color conversion
         * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
         * NULL) is an array of &struct drm_color_lut.
+        *
+        * Note that for mostly historical reasons stemming from Xorg heritage,
+        * this is also used to store the color map (also sometimes color lut,
+        * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
         */
        struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
        /**
         * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
         * by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint32_t gamma_size;
 
        /**
         * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
         * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint16_t *gamma_store;
 
--

2.33.0

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#8 lore raw
In reply to Daniel Vetter

Hi

Am 24.01.22 um 23:16 schrieb Daniel Vetter:

Quoted 7 lines

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm

Older HW has cursor planes with separate palettes; 16 colors on Matrox IIRC. Not very useful for us, though.

Best regards
Thomas

Quoted 71 lines

also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

Cc Laurent Pinchart <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
  drivers/gpu/drm/drm_color_mgmt.c |  4 ++++
  include/drm/drm_crtc.h           | 10 ++++++++++
  2 files changed, 14 insertions(+)
drivers/gpu/drm/drm_color_mgmt.c +4 -0
index bb14f488c8f6..9079fbe21d2f 100644
@@ -82,6 +82,10 @@
   *	driver boot-up state too. Drivers can access this blob through
   *	&drm_crtc_state.gamma_lut.
   *
+ *	Note that for mostly historical reasons stemming from Xorg heritage,
+ *	this is also used to store the color map (also sometimes color lut, CLUT
+ *	or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
   * “GAMMA_LUT_SIZE”:
   *	Unsigned range property to give the size of the lookup table to be set
   *	on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +10 -0
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
  	 * Lookup table for converting pixel data after the color conversion
  	 * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
  	 * NULL) is an array of &struct drm_color_lut.
+	 *
+	 * Note that for mostly historical reasons stemming from Xorg heritage,
+	 * this is also used to store the color map (also sometimes color lut,
+	 * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
  	 */
  	struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
  	/**
  	 * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
  	 * by calling drm_mode_crtc_set_gamma_size().
+	 *
+	 * Note that atomic drivers need to instead use
+	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
  	 */
  	uint32_t gamma_size;
 
  	/**
  	 * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
  	 * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+	 *
+	 * Note that atomic drivers need to instead use
+	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
  	 */
  	uint16_t *gamma_store;
 
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#9 lore raw
In reply to Daniel Vetter

Hi Daniel,

Thanks for your patch!

Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

IIRC (it's been a looong time) some set-top-box hardware did support this. It made sense, as the CLUT is per-plane, while the gamma value is a property of the display output device.
At that time, desktop hardware supported only a single plane, so hardware complexity could be reduced by letting software handle that through a single clut (for "pseudocolor") or gamma table (for "directcolor").
For hardware with multiple alpha-blended planes (some CLUT, some ARGB, some (A)YCbCr), doing it in software is either very complicated or impossible, especially if you have two heads needing different gamma values.
Whether such hardware still exists, and needs to be supported, I do not know...

Quoted 3 lines

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

+1, that would help for sure!

Quoted 38 lines
drivers/gpu/drm/drm_color_mgmt.c +4 -0
@@ -82,6 +82,10 @@
  *     driver boot-up state too. Drivers can access this blob through
  *     &drm_crtc_state.gamma_lut.
  *
+ *     Note that for mostly historical reasons stemming from Xorg heritage,
+ *     this is also used to store the color map (also sometimes color lut, CLUT
+ *     or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *     Unsigned range property to give the size of the lookup table to be set
  *     on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +7 -0
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
         * Lookup table for converting pixel data after the color conversion
         * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
         * NULL) is an array of &struct drm_color_lut.
+        *
+        * Note that for mostly historical reasons stemming from Xorg heritage,
+        * this is also used to store the color map (also sometimes color lut,
+        * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
         */
        struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
        /**
         * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
         * by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */

include/drm/drm_crtc.h struct drm_crtc { · line 1095

Quoted 10 lines
include/drm/drm_crtc.h +3 -0
        uint32_t gamma_size;
 
        /**
         * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
         * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint16_t *gamma_store;

This is indeed what I ended up using, as drivers/gpu/drm/drm_fb_helper.c:setcmap_atomic() fills in drm_crtc.gamma_store[]. But as I understand it, I should instead use the gamma_lut above?

BTW, to check if the CLUT changed, I look at drm_crtc_state.color_mgmt_changed. This works reasonably well, but I still see more CLUT reloads than expected.
Who clears drm_crtc_state.color_mgmt_changed again? Is there a better check?

Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#10 lore raw
Quoted 15 lines · Geert Uytterhoeven

Hi Daniel,

Thanks for your patch!

Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Quoted 13 lines

IIRC (it's been a looong time) some set-top-box hardware did support this. It made sense, as the CLUT is per-plane, while the gamma value is a property of the display output device.
At that time, desktop hardware supported only a single plane, so hardware complexity could be reduced by letting software handle that through a single clut (for "pseudocolor") or gamma table (for "directcolor").
For hardware with multiple alpha-blended planes (some CLUT, some ARGB, some (A)YCbCr), doing it in software is either very complicated or impossible, especially if you have two heads needing different gamma values.
Whether such hardware still exists, and needs to be supported, I do not know...

Yeah I think extending this is a all-around compatible way isn't too tricky, just a bit of work:
- add the clut to the plane state
- add a helper which takes the plane state, and if you have an indexed pixel format first grabs the plane state clut, and if that's not present, the crtc gamma lut as fallback. Also gives you nothing if you don't have a indexed pixel format
- convert drivers over to that helper

This way legacy userspace which only uses a primary plane and the gamma-as-a-clut thing will keep working, while we can expose the full features. And drivers don't have to care about the compat either.

Quoted 46 lines
Quoted 3 lines

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

+1, that would help for sure!

Quoted 40 lines
drivers/gpu/drm/drm_color_mgmt.c +4 -0
@@ -82,6 +82,10 @@
  *     driver boot-up state too. Drivers can access this blob through
  *     &drm_crtc_state.gamma_lut.
  *
+ *     Note that for mostly historical reasons stemming from Xorg heritage,
+ *     this is also used to store the color map (also sometimes color lut, CLUT
+ *     or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *     Unsigned range property to give the size of the lookup table to be set
  *     on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +7 -0
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
         * Lookup table for converting pixel data after the color conversion
         * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
         * NULL) is an array of &struct drm_color_lut.
+        *
+        * Note that for mostly historical reasons stemming from Xorg heritage,
+        * this is also used to store the color map (also sometimes color lut,
+        * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
         */
        struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
        /**
         * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
         * by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint32_t gamma_size;
 
Quoted 13 lines

include/drm/drm_crtc.h struct drm_crtc { · line 1095

Quoted 8 lines
include/drm/drm_crtc.h +3 -0
        /**
         * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
         * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint16_t *gamma_store;

This is indeed what I ended up using, as drivers/gpu/drm/drm_fb_helper.c:setcmap_atomic() fills in drm_crtc.gamma_store[]. But as I understand it, I should instead use the gamma_lut above?

Yup.

Quoted 5 lines

BTW, to check if the CLUT changed, I look at drm_crtc_state.color_mgmt_changed. This works reasonably well, but I still see more CLUT reloads than expected.
Who clears drm_crtc_state.color_mgmt_changed again? Is there a better check?

It only checks whether the blob property changed, but not the contents. So if you see this set when nothing changes then I guess some code somewhere is creating a new lut blob property for every screen update. If this goes through the legacy gamma_set ioctl/vfunc interface then I think we'll do that in there every time, and at least for fbdev emulation the fix would be to instead use the atomic interfaces and cache the blob prop. Or implement the lut blob prop caching in gamma_set, but that's kinda a hack (since userspace also shouldn't call that one just for lolz). -Daniel

Quoted 13 lines

Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#11 lore raw
Quoted 103 lines · Daniel Vetter
Quoted 15 lines · Geert Uytterhoeven

Hi Daniel,

Thanks for your patch!

Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Quoted 13 lines

IIRC (it's been a looong time) some set-top-box hardware did support this. It made sense, as the CLUT is per-plane, while the gamma value is a property of the display output device.
At that time, desktop hardware supported only a single plane, so hardware complexity could be reduced by letting software handle that through a single clut (for "pseudocolor") or gamma table (for "directcolor").
For hardware with multiple alpha-blended planes (some CLUT, some ARGB, some (A)YCbCr), doing it in software is either very complicated or impossible, especially if you have two heads needing different gamma values.
Whether such hardware still exists, and needs to be supported, I do not know...

Yeah I think extending this is a all-around compatible way isn't too tricky, just a bit of work:
- add the clut to the plane state
- add a helper which takes the plane state, and if you have an indexed pixel format first grabs the plane state clut, and if that's not present, the crtc gamma lut as fallback. Also gives you nothing if you don't have a indexed pixel format
- convert drivers over to that helper

This way legacy userspace which only uses a primary plane and the gamma-as-a-clut thing will keep working, while we can expose the full features. And drivers don't have to care about the compat either.

Quoted 46 lines
Quoted 3 lines

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

+1, that would help for sure!

Quoted 40 lines
drivers/gpu/drm/drm_color_mgmt.c +4 -0
@@ -82,6 +82,10 @@
  *     driver boot-up state too. Drivers can access this blob through
  *     &drm_crtc_state.gamma_lut.
  *
+ *     Note that for mostly historical reasons stemming from Xorg heritage,
+ *     this is also used to store the color map (also sometimes color lut, CLUT
+ *     or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *     Unsigned range property to give the size of the lookup table to be set
  *     on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +7 -0
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
         * Lookup table for converting pixel data after the color conversion
         * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
         * NULL) is an array of &struct drm_color_lut.
+        *
+        * Note that for mostly historical reasons stemming from Xorg heritage,
+        * this is also used to store the color map (also sometimes color lut,
+        * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
         */
        struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
        /**
         * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
         * by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint32_t gamma_size;
 
Quoted 13 lines

include/drm/drm_crtc.h struct drm_crtc { · line 1095

Quoted 8 lines
include/drm/drm_crtc.h +3 -0
        /**
         * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
         * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint16_t *gamma_store;

This is indeed what I ended up using, as drivers/gpu/drm/drm_fb_helper.c:setcmap_atomic() fills in drm_crtc.gamma_store[]. But as I understand it, I should instead use the gamma_lut above?

Quoted 1 line

Yup.

I forgot to add why: The legacy store is only filled in for the legacy interfaces, so if someone uses the atomic properties directly, then your driver looking at the legacy gamma store will see nothing.

We could/should perhaps make the legacy store entirely defunct for atomic drivers, but that means a bunch of typing and auditing. We have the same problem in other areas too due to the gradual switch towards atomic in many drivers, so definitely an area where you can sink a lot of time into. -Daniel

Quoted 34 lines
Quoted 5 lines

BTW, to check if the CLUT changed, I look at drm_crtc_state.color_mgmt_changed. This works reasonably well, but I still see more CLUT reloads than expected.
Who clears drm_crtc_state.color_mgmt_changed again? Is there a better check?

It only checks whether the blob property changed, but not the contents. So if you see this set when nothing changes then I guess some code somewhere is creating a new lut blob property for every screen update. If this goes through the legacy gamma_set ioctl/vfunc interface then I think we'll do that in there every time, and at least for fbdev emulation the fix would be to instead use the atomic interfaces and cache the blob prop. Or implement the lut blob prop caching in gamma_set, but that's kinda a hack (since userspace also shouldn't call that one just for lolz). -Daniel

Quoted 13 lines

Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#12 lore raw
Quoted 40 lines · Daniel Vetter
Quoted 39 lines · Daniel Vetter
Quoted 15 lines · Geert Uytterhoeven

Hi Daniel,

Thanks for your patch!

Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Quoted 13 lines

IIRC (it's been a looong time) some set-top-box hardware did support this. It made sense, as the CLUT is per-plane, while the gamma value is a property of the display output device.
At that time, desktop hardware supported only a single plane, so hardware complexity could be reduced by letting software handle that through a single clut (for "pseudocolor") or gamma table (for "directcolor").
For hardware with multiple alpha-blended planes (some CLUT, some ARGB, some (A)YCbCr), doing it in software is either very complicated or impossible, especially if you have two heads needing different gamma values.
Whether such hardware still exists, and needs to be supported, I do not know...

Yeah I think extending this is a all-around compatible way isn't too tricky, just a bit of work:
- add the clut to the plane state
- add a helper which takes the plane state, and if you have an indexed pixel format first grabs the plane state clut, and if that's not present, the crtc gamma lut as fallback. Also gives you nothing if you don't have a indexed pixel format
- convert drivers over to that helper

Quoted 3 lines
Quoted 3 lines

This way legacy userspace which only uses a primary plane and the gamma-as-a-clut thing will keep working, while we can expose the full features. And drivers don't have to care about the compat either.

https://github.com/vsyrjala/linux/commits/fb_helper_c8_lut_4

Quoted 63 lines
Quoted 61 lines
Quoted 47 lines
Quoted 4 lines

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

+1, that would help for sure!

Quoted 40 lines
drivers/gpu/drm/drm_color_mgmt.c +4 -0
@@ -82,6 +82,10 @@
  *     driver boot-up state too. Drivers can access this blob through
  *     &drm_crtc_state.gamma_lut.
  *
+ *     Note that for mostly historical reasons stemming from Xorg heritage,
+ *     this is also used to store the color map (also sometimes color lut, CLUT
+ *     or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *     Unsigned range property to give the size of the lookup table to be set
  *     on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +7 -0
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
         * Lookup table for converting pixel data after the color conversion
         * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
         * NULL) is an array of &struct drm_color_lut.
+        *
+        * Note that for mostly historical reasons stemming from Xorg heritage,
+        * this is also used to store the color map (also sometimes color lut,
+        * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
         */
        struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
        /**
         * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
         * by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint32_t gamma_size;
 
Quoted 13 lines

include/drm/drm_crtc.h struct drm_crtc { · line 1095

Quoted 8 lines
include/drm/drm_crtc.h +3 -0
        /**
         * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
         * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint16_t *gamma_store;

This is indeed what I ended up using, as drivers/gpu/drm/drm_fb_helper.c:setcmap_atomic() fills in drm_crtc.gamma_store[]. But as I understand it, I should instead use the gamma_lut above?

Quoted 1 line

Yup.

Quoted 8 lines

I forgot to add why: The legacy store is only filled in for the legacy interfaces, so if someone uses the atomic properties directly, then your driver looking at the legacy gamma store will see nothing.

We could/should perhaps make the legacy store entirely defunct for atomic drivers, but that means a bunch of typing and auditing. We have the same problem in other areas too due to the gradual switch towards atomic in many drivers, so definitely an area where you can sink a lot of time into.

I have some wip stuff here that tried to nuke the gamma_store stuff:
https://github.com/vsyrjala/linux/commits/fb_helper_c8_lut_4

As for adding a LUT to the planes that needs careful thought as it interacts heavily with the whole plane color management work.

Also there's hardware (everything supported by i915 for example) where each plane might have a dedicated gamma ramp for !C8 while still relying on the pipe LUT for C8 scanout. Multiple planes can be scanning out C8 simultaneously and they all share the same LUT. And while that is going on the pipe LUT can then not be used for anything else.

Signature · 2 lines
Ville Syrjälä
Intel
#13 lore raw
Quoted 41 lines · Ville Syrjälä
Quoted 40 lines · Daniel Vetter
Quoted 39 lines · Daniel Vetter
Quoted 15 lines · Geert Uytterhoeven

Hi Daniel,

Thanks for your patch!

Quoted 9 lines · Daniel Vetter

Also add notes that for atomic drivers it's really somewhere else and no longer in struct drm_crtc.

Maybe we should put a bigger warning here that this is confusing, since the pixel format is a plane property, but the GAMMA_LUT property is on the crtc. But I think we can fix this if/when someone finds a need for a per-plane CLUT, since I'm not sure such hw even exists. I'm also not sure whether even hardware with a CLUT and a full color correction pipeline with degamm/cgm/gamma exists.

Quoted 13 lines

IIRC (it's been a looong time) some set-top-box hardware did support this. It made sense, as the CLUT is per-plane, while the gamma value is a property of the display output device.
At that time, desktop hardware supported only a single plane, so hardware complexity could be reduced by letting software handle that through a single clut (for "pseudocolor") or gamma table (for "directcolor").
For hardware with multiple alpha-blended planes (some CLUT, some ARGB, some (A)YCbCr), doing it in software is either very complicated or impossible, especially if you have two heads needing different gamma values.
Whether such hardware still exists, and needs to be supported, I do not know...

Yeah I think extending this is a all-around compatible way isn't too tricky, just a bit of work:
- add the clut to the plane state
- add a helper which takes the plane state, and if you have an indexed pixel format first grabs the plane state clut, and if that's not present, the crtc gamma lut as fallback. Also gives you nothing if you don't have a indexed pixel format
- convert drivers over to that helper

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

This way legacy userspace which only uses a primary plane and the gamma-as-a-clut thing will keep working, while we can expose the full features. And drivers don't have to care about the compat either.

https://github.com/vsyrjala/linux/commits/fb_helper_c8_lut_4

Yeah resurrecting those might be a good idea.
-Daniel

Quoted 88 lines
Quoted 64 lines
Quoted 62 lines
Quoted 48 lines
Quoted 5 lines

Motivated by comments from Geert that we have a gap here.

v2: More names for color luts (Laurent).

+1, that would help for sure!

Quoted 40 lines
drivers/gpu/drm/drm_color_mgmt.c +4 -0
@@ -82,6 +82,10 @@
  *     driver boot-up state too. Drivers can access this blob through
  *     &drm_crtc_state.gamma_lut.
  *
+ *     Note that for mostly historical reasons stemming from Xorg heritage,
+ *     this is also used to store the color map (also sometimes color lut, CLUT
+ *     or color palette) for indexed formats like DRM_FORMAT_C8.
+ *
  * “GAMMA_LUT_SIZE”:
  *     Unsigned range property to give the size of the lookup table to be set
  *     on the GAMMA_LUT property (the size depends on the underlying hardware).
include/drm/drm_crtc.h +7 -0
index 4d01b4d89775..a70baea0636c 100644
@@ -285,6 +285,10 @@ struct drm_crtc_state {
         * Lookup table for converting pixel data after the color conversion
         * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
         * NULL) is an array of &struct drm_color_lut.
+        *
+        * Note that for mostly historical reasons stemming from Xorg heritage,
+        * this is also used to store the color map (also sometimes color lut,
+        * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
         */
        struct drm_property_blob *gamma_lut;
 
@@ -1075,12 +1079,18 @@ struct drm_crtc {
        /**
         * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
         * by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint32_t gamma_size;
 
Quoted 13 lines

include/drm/drm_crtc.h struct drm_crtc { · line 1095

Quoted 8 lines
include/drm/drm_crtc.h +3 -0
        /**
         * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
         * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
+        *
+        * Note that atomic drivers need to instead use
+        * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
         */
        uint16_t *gamma_store;

This is indeed what I ended up using, as drivers/gpu/drm/drm_fb_helper.c:setcmap_atomic() fills in drm_crtc.gamma_store[]. But as I understand it, I should instead use the gamma_lut above?

Quoted 1 line

Yup.

Quoted 8 lines

I forgot to add why: The legacy store is only filled in for the legacy interfaces, so if someone uses the atomic properties directly, then your driver looking at the legacy gamma store will see nothing.

We could/should perhaps make the legacy store entirely defunct for atomic drivers, but that means a bunch of typing and auditing. We have the same problem in other areas too due to the gradual switch towards atomic in many drivers, so definitely an area where you can sink a lot of time into.

I have some wip stuff here that tried to nuke the gamma_store stuff:
https://github.com/vsyrjala/linux/commits/fb_helper_c8_lut_4

As for adding a LUT to the planes that needs careful thought as it interacts heavily with the whole plane color management work.

Also there's hardware (everything supported by i915 for example) where each plane might have a dedicated gamma ramp for !C8 while still relying on the pipe LUT for C8 scanout. Multiple planes can be scanning out C8 simultaneously and they all share the same LUT. And while that is going on the pipe LUT can then not be used for anything else.

Signature · 2 lines
Ville Syrjälä
Intel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch