Skip to contentSkip to conversation

drm/color: Document CTM eqations

PATCH Superseded Brian Starkey 7 participants 17 messages Jan 31, 2017 – Feb 26, 2017

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/color: Document CTM eqations

Explicitly state the expected CTM equations in the kerneldoc for the CTM property, and the form of the matrix on struct drm_color_ctm.

Cc Ville Syrjälä <[email protected]>
Cc Lionel Landwerlin <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |   13 +++++++++++++
 include/uapi/drm/drm_mode.h      |    8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_color_mgmt.c +13 -0
index 789b4c65cd69..7573ca4b6ea6 100644
@@ -62,6 +62,19 @@
  *	unit/pass-thru matrix should be used. This is generally the driver
  *	boot-up state too.
  *
+ *	The output vector is related to the input vector as below:
+ *
+ *	| ``out[0] = matrix[0] * in[0] + matrix[1] * in[1] + matrix[2] * in[2];``
+ *	| ``out[1] = matrix[3] * in[0] + matrix[4] * in[1] + matrix[5] * in[2];``
+ *	| ``out[2] = matrix[6] * in[0] + matrix[7] * in[1] + matrix[8] * in[2];``
+ *
+ *	The component order in the input/output vectors is assumed to be
+ *	{ R, G, B }.
+ *
+ *	The color-space of the input vector must not be confused with the
+ *	color-space implied by a framebuffer pixel format, which may be the same
+ *	or different.
+ *
  * “GAMMA_LUT”:
  *	Blob property to set the gamma lookup table (LUT) mapping pixel data
  *	after the transformation matrix to data sent to the connector. The
include/uapi/drm/drm_mode.h +7 -1
index ce7efe2e8a5e..3401637caf8e 100644
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };
 
 struct drm_color_ctm {
-	/* Conversion matrix in S31.32 format. */
+	/*
+	 * Conversion matrix in S31.32 format, in row-major form:
+	 *
+	 * | matrix[0] matrix[1] matrix[2] |
+	 * | matrix[3] matrix[4] matrix[5] |
+	 * | matrix[6] matrix[7] matrix[8] |
+	 */
 	__s64 matrix[9];
 };
 
Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 17 lines · Brian Starkey

Explicitly state the expected CTM equations in the kerneldoc for the CTM property, and the form of the matrix on struct drm_color_ctm.

Cc Ville Syrjälä <[email protected]>
Cc Lionel Landwerlin <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |   13 +++++++++++++
 include/uapi/drm/drm_mode.h      |    8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_color_mgmt.c +0 -0
index 789b4c65cd69..7573ca4b6ea6 100644

drivers/gpu/drm/drm_color_mgmt.c line 69

Quoted 8 lines
drivers/gpu/drm/drm_color_mgmt.c +5 -0
@@ -62,6 +62,19 @@
  *	unit/pass-thru matrix should be used. This is generally the driver
  *	boot-up state too.
  *
+ *	The output vector is related to the input vector as below:
+ *
+ *	| ``out[0] = matrix[0] * in[0] + matrix[1] * in[1] + matrix[2] * in[2];``
+ *	| ``out[1] = matrix[3] * in[0] + matrix[4] * in[1] + matrix[5] * in[2];``
+ *	| ``out[2] = matrix[6] * in[0] + matrix[7] * in[1] + matrix[8] * in[2];``

Would that not work better with a preformatted block? Replace the colon in the preceding paragraph with the double colon ::, and indent the block.

Quoted 17 lines
drivers/gpu/drm/drm_color_mgmt.c +8 -0
+ *
+ *	The component order in the input/output vectors is assumed to be
+ *	{ R, G, B }.
+ *
+ *	The color-space of the input vector must not be confused with the
+ *	color-space implied by a framebuffer pixel format, which may be the same
+ *	or different.
+ *
  * “GAMMA_LUT”:
  *	Blob property to set the gamma lookup table (LUT) mapping pixel data
  *	after the transformation matrix to data sent to the connector. The
include/uapi/drm/drm_mode.h +0 -0
index ce7efe2e8a5e..3401637caf8e 100644
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };

include/uapi/drm/drm_mode.h struct drm_mode_crtc_lut { · line 534

Quoted 10 lines
include/uapi/drm/drm_mode.h +7 -1
 
 struct drm_color_ctm {
-	/* Conversion matrix in S31.32 format. */
+	/*
+	 * Conversion matrix in S31.32 format, in row-major form:
+	 *
+	 * | matrix[0] matrix[1] matrix[2] |
+	 * | matrix[3] matrix[4] matrix[5] |
+	 * | matrix[6] matrix[7] matrix[8] |
+	 */

Same here.

Quoted 2 lines
include/uapi/drm/drm_mode.h +0 -0
 	__s64 matrix[9];
 };
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Hi Jani,

Quoted 22 lines · Jani Nikula
Quoted 21 lines · Brian Starkey

Explicitly state the expected CTM equations in the kerneldoc for the CTM property, and the form of the matrix on struct drm_color_ctm.

Cc Ville Syrjälä <[email protected]>
Cc Lionel Landwerlin <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |   13 +++++++++++++
 include/uapi/drm/drm_mode.h      |    8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_color_mgmt.c +1 -0
index 789b4c65cd69..7573ca4b6ea6 100644
@@ -62,6 +62,19 @@
  *	unit/pass-thru matrix should be used. This is generally the driver
  *	boot-up state too.
  *
+ *	The output vector is related to the input vector as below:
Quoted 9 lines

drivers/gpu/drm/drm_color_mgmt.c line 69

Quoted 4 lines
drivers/gpu/drm/drm_color_mgmt.c +4 -0
+ *
+ *	| ``out[0] = matrix[0] * in[0] + matrix[1] * in[1] + matrix[2] * in[2];``
+ *	| ``out[1] = matrix[3] * in[0] + matrix[4] * in[1] + matrix[5] * in[2];``
+ *	| ``out[2] = matrix[6] * in[0] + matrix[7] * in[1] + matrix[8] * in[2];``

Would that not work better with a preformatted block? Replace the colon in the preceding paragraph with the double colon ::, and indent the block.

Ah thanks for the tip, I couldn't get it to work but it looks like my syntax was a bit off. I'll resend with that change.

Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/drm_color_mgmt.c +8 -0
+ *
+ *	The component order in the input/output vectors is assumed to be
+ *	{ R, G, B }.
+ *
+ *	The color-space of the input vector must not be confused with the
+ *	color-space implied by a framebuffer pixel format, which may be the same
+ *	or different.
+ *
  * “GAMMA_LUT”:
  *	Blob property to set the gamma lookup table (LUT) mapping pixel data
  *	after the transformation matrix to data sent to the connector. The
include/uapi/drm/drm_mode.h +0 -0
index ce7efe2e8a5e..3401637caf8e 100644
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };
 
Quoted 11 lines

include/uapi/drm/drm_mode.h struct drm_mode_crtc_lut { · line 534

Quoted 9 lines
include/uapi/drm/drm_mode.h +7 -1
 struct drm_color_ctm {
-	/* Conversion matrix in S31.32 format. */
+	/*
+	 * Conversion matrix in S31.32 format, in row-major form:
+	 *
+	 * | matrix[0] matrix[1] matrix[2] |
+	 * | matrix[3] matrix[4] matrix[5] |
+	 * | matrix[6] matrix[7] matrix[8] |
+	 */

Same here.

This comment isn't actually kerneldoc, so I guess not rst either. I can include the markup if you like, but the |s here were to indicate it's a matrix rather than for rst.

Cheers,
-Brian

Quoted 6 lines
Quoted 3 lines
include/uapi/drm/drm_mode.h +0 -0
 	__s64 matrix[9];
 };
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 68 lines · Brian Starkey

Hi Jani,

Quoted 22 lines · Jani Nikula
Quoted 21 lines · Brian Starkey

Explicitly state the expected CTM equations in the kerneldoc for the CTM property, and the form of the matrix on struct drm_color_ctm.

Cc Ville Syrjälä <[email protected]>
Cc Lionel Landwerlin <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |   13 +++++++++++++
 include/uapi/drm/drm_mode.h      |    8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_color_mgmt.c +1 -0
index 789b4c65cd69..7573ca4b6ea6 100644
@@ -62,6 +62,19 @@
  *	unit/pass-thru matrix should be used. This is generally the driver
  *	boot-up state too.
  *
+ *	The output vector is related to the input vector as below:
Quoted 9 lines

drivers/gpu/drm/drm_color_mgmt.c line 69

Quoted 4 lines
drivers/gpu/drm/drm_color_mgmt.c +4 -0
+ *
+ *	| ``out[0] = matrix[0] * in[0] + matrix[1] * in[1] + matrix[2] * in[2];``
+ *	| ``out[1] = matrix[3] * in[0] + matrix[4] * in[1] + matrix[5] * in[2];``
+ *	| ``out[2] = matrix[6] * in[0] + matrix[7] * in[1] + matrix[8] * in[2];``

Would that not work better with a preformatted block? Replace the colon in the preceding paragraph with the double colon ::, and indent the block.

Ah thanks for the tip, I couldn't get it to work but it looks like my syntax was a bit off. I'll resend with that change.

Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/drm_color_mgmt.c +8 -0
+ *
+ *	The component order in the input/output vectors is assumed to be
+ *	{ R, G, B }.
+ *
+ *	The color-space of the input vector must not be confused with the
+ *	color-space implied by a framebuffer pixel format, which may be the same
+ *	or different.
+ *
  * “GAMMA_LUT”:
  *	Blob property to set the gamma lookup table (LUT) mapping pixel data
  *	after the transformation matrix to data sent to the connector. The
include/uapi/drm/drm_mode.h +0 -0
index ce7efe2e8a5e..3401637caf8e 100644
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };
 
Quoted 11 lines

include/uapi/drm/drm_mode.h struct drm_mode_crtc_lut { · line 534

Quoted 9 lines
include/uapi/drm/drm_mode.h +7 -1
 struct drm_color_ctm {
-	/* Conversion matrix in S31.32 format. */
+	/*
+	 * Conversion matrix in S31.32 format, in row-major form:
+	 *
+	 * | matrix[0] matrix[1] matrix[2] |
+	 * | matrix[3] matrix[4] matrix[5] |
+	 * | matrix[6] matrix[7] matrix[8] |
+	 */

Same here.

Quoted 3 lines

This comment isn't actually kerneldoc, so I guess not rst either. I can include the markup if you like, but the |s here were to indicate it's a matrix rather than for rst.

Oh, right. Up to you.

Quoted 10 lines

Cheers,
-Brian

Quoted 6 lines
Quoted 3 lines
include/uapi/drm/drm_mode.h +0 -0
 	__s64 matrix[9];
 };
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
In reply to Brian Starkey
Quoted 41 lines · Brian Starkey

Explicitly state the expected CTM equations in the kerneldoc for the CTM property, and the form of the matrix on struct drm_color_ctm.

Cc Ville Syrjälä <[email protected]>
Cc Lionel Landwerlin <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |   13 +++++++++++++
 include/uapi/drm/drm_mode.h      |    8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_color_mgmt.c +13 -0
index 789b4c65cd69..7573ca4b6ea6 100644
@@ -62,6 +62,19 @@
  *	unit/pass-thru matrix should be used. This is generally the driver
  *	boot-up state too.
  *
+ *	The output vector is related to the input vector as below:
+ *
+ *	| ``out[0] = matrix[0] * in[0] + matrix[1] * in[1] + matrix[2] * in[2];``
+ *	| ``out[1] = matrix[3] * in[0] + matrix[4] * in[1] + matrix[5] * in[2];``
+ *	| ``out[2] = matrix[6] * in[0] + matrix[7] * in[1] + matrix[8] * in[2];``
+ *
+ *	The component order in the input/output vectors is assumed to be
+ *	{ R, G, B }.
+ *
+ *	The color-space of the input vector must not be confused with the
+ *	color-space implied by a framebuffer pixel format, which may be the same
+ *	or different.
+ *
  * “GAMMA_LUT”:
  *	Blob property to set the gamma lookup table (LUT) mapping pixel data
  *	after the transformation matrix to data sent to the connector. The
include/uapi/drm/drm_mode.h +0 -0
index ce7efe2e8a5e..3401637caf8e 100644

include/uapi/drm/drm_mode.h struct drm_mode_crtc_lut { · line 529

Quoted 6 lines
include/uapi/drm/drm_mode.h +2 -1
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };
 
 struct drm_color_ctm {
-	/* Conversion matrix in S31.32 format. */
+	/*
+	 * Conversion matrix in S31.32 format, in row-major form:

s32.32 is how I'd state that (to match the regular s32 and whatnot types).

Quoted 10 lines
include/uapi/drm/drm_mode.h +5 -0
+	 *
+	 * | matrix[0] matrix[1] matrix[2] |
+	 * | matrix[3] matrix[4] matrix[5] |
+	 * | matrix[6] matrix[7] matrix[8] |
+	 */
 	__s64 matrix[9];
 };
 
Signature · 1 line
1.7.9.5
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

Hi Ville,

Quoted 44 lines · Ville Syrjälä
Quoted 43 lines · Brian Starkey

Explicitly state the expected CTM equations in the kerneldoc for the CTM property, and the form of the matrix on struct drm_color_ctm.

Cc Ville Syrjälä <[email protected]>
Cc Lionel Landwerlin <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |   13 +++++++++++++
 include/uapi/drm/drm_mode.h      |    8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_color_mgmt.c +13 -0
index 789b4c65cd69..7573ca4b6ea6 100644
@@ -62,6 +62,19 @@
  *	unit/pass-thru matrix should be used. This is generally the driver
  *	boot-up state too.
  *
+ *	The output vector is related to the input vector as below:
+ *
+ *	| ``out[0] = matrix[0] * in[0] + matrix[1] * in[1] + matrix[2] * in[2];``
+ *	| ``out[1] = matrix[3] * in[0] + matrix[4] * in[1] + matrix[5] * in[2];``
+ *	| ``out[2] = matrix[6] * in[0] + matrix[7] * in[1] + matrix[8] * in[2];``
+ *
+ *	The component order in the input/output vectors is assumed to be
+ *	{ R, G, B }.
+ *
+ *	The color-space of the input vector must not be confused with the
+ *	color-space implied by a framebuffer pixel format, which may be the same
+ *	or different.
+ *
  * “GAMMA_LUT”:
  *	Blob property to set the gamma lookup table (LUT) mapping pixel data
  *	after the transformation matrix to data sent to the connector. The
include/uapi/drm/drm_mode.h +0 -0
index ce7efe2e8a5e..3401637caf8e 100644
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };
 
Quoted 8 lines

include/uapi/drm/drm_mode.h struct drm_mode_crtc_lut { · line 529

Quoted 4 lines
include/uapi/drm/drm_mode.h +2 -1
 struct drm_color_ctm {
-	/* Conversion matrix in S31.32 format. */
+	/*
+	 * Conversion matrix in S31.32 format, in row-major form:

s32.32 is how I'd state that (to match the regular s32 and whatnot types).

Can you explain a bit more what exactly you mean by s32.32? e.g. what would be the bitfield representing the most negative number?

I understand the S31.32 here as a sign + magnitude format (which makes it rather odd to store it in a signed variable, but never mind). This also appears to be what igt does in set_ctm() in kms_pipe_color.c:

	for (i = 0; i < ARRAY_SIZE(ctm.matrix); i++) {
		if (coefficients[i] < 0) {
			ctm.matrix[i] =
				(int64_t) (-coefficients[i] * ((int64_t) 1L << 32));
			ctm.matrix[i] |= 1ULL << 63;
		} else
			ctm.matrix[i] =
				(int64_t) (coefficients[i] * ((int64_t) 1L << 32));
	}

If that's what you meant as well, then I don't think s32.32 is a good way to describe it, because the integer part has only 31 bits available.

If you meant a regular two's-complement fixed-point number, where the most negative number would be 0x10000000.00000000, then yeah that's what I thought it meant too originally. Clarifying the docs here sounds like a great plan.

I guess the igt implementation means that it's a sign + magnitude number, and the fact that it's stored in an s64 is a bizarre quirk that we just live with.

Cheers,
Brian

Quoted 8 lines
Quoted 8 lines
include/uapi/drm/drm_mode.h +5 -0
+	 *
+	 * | matrix[0] matrix[1] matrix[2] |
+	 * | matrix[3] matrix[4] matrix[5] |
+	 * | matrix[6] matrix[7] matrix[8] |
+	 */
 	__s64 matrix[9];
 };
 
Quoted 6 lines
Quoted 2 lines

--
1.7.9.5

Signature · 2 lines
Ville Syrjälä
Intel OTC

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
Quoted 77 lines · Brian Starkey

Hi Ville,

Quoted 44 lines · Ville Syrjälä
Quoted 43 lines · Brian Starkey

Explicitly state the expected CTM equations in the kerneldoc for the CTM property, and the form of the matrix on struct drm_color_ctm.

Cc Ville Syrjälä <[email protected]>
Cc Lionel Landwerlin <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_color_mgmt.c |   13 +++++++++++++
 include/uapi/drm/drm_mode.h      |    8 +++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_color_mgmt.c +13 -0
index 789b4c65cd69..7573ca4b6ea6 100644
@@ -62,6 +62,19 @@
  *	unit/pass-thru matrix should be used. This is generally the driver
  *	boot-up state too.
  *
+ *	The output vector is related to the input vector as below:
+ *
+ *	| ``out[0] = matrix[0] * in[0] + matrix[1] * in[1] + matrix[2] * in[2];``
+ *	| ``out[1] = matrix[3] * in[0] + matrix[4] * in[1] + matrix[5] * in[2];``
+ *	| ``out[2] = matrix[6] * in[0] + matrix[7] * in[1] + matrix[8] * in[2];``
+ *
+ *	The component order in the input/output vectors is assumed to be
+ *	{ R, G, B }.
+ *
+ *	The color-space of the input vector must not be confused with the
+ *	color-space implied by a framebuffer pixel format, which may be the same
+ *	or different.
+ *
  * “GAMMA_LUT”:
  *	Blob property to set the gamma lookup table (LUT) mapping pixel data
  *	after the transformation matrix to data sent to the connector. The
include/uapi/drm/drm_mode.h +0 -0
index ce7efe2e8a5e..3401637caf8e 100644
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };
 
Quoted 8 lines

include/uapi/drm/drm_mode.h struct drm_mode_crtc_lut { · line 529

Quoted 4 lines
include/uapi/drm/drm_mode.h +2 -1
 struct drm_color_ctm {
-	/* Conversion matrix in S31.32 format. */
+	/*
+	 * Conversion matrix in S31.32 format, in row-major form:

s32.32 is how I'd state that (to match the regular s32 and whatnot types).

Can you explain a bit more what exactly you mean by s32.32? e.g. what would be the bitfield representing the most negative number?

I understand the S31.32 here as a sign + magnitude format (which makes it rather odd to store it in a signed variable, but never mind). This also appears to be what igt does in set_ctm() in kms_pipe_color.c:

	for (i = 0; i < ARRAY_SIZE(ctm.matrix); i++) {
		if (coefficients[i] < 0) {
			ctm.matrix[i] =
				(int64_t) (-coefficients[i] * ((int64_t) 1L << 32));
			ctm.matrix[i] |= 1ULL << 63;
		} else
			ctm.matrix[i] =
				(int64_t) (coefficients[i] * ((int64_t) 1L << 32));
	}

If that's what you meant as well, then I don't think s32.32 is a good way to describe it, because the integer part has only 31 bits available.

Quoted 8 lines

If you meant a regular two's-complement fixed-point number, where the most negative number would be 0x10000000.00000000, then yeah that's what I thought it meant too originally. Clarifying the docs here sounds like a great plan.

I guess the igt implementation means that it's a sign + magnitude number, and the fact that it's stored in an s64 is a bizarre quirk that we just live with.

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw
Quoted 42 lines · Ville Syrjälä
Quoted 42 lines
Quoted 7 lines
Quoted 7 lines
include/uapi/drm/drm_mode.h +0 -0
index ce7efe2e8a5e..3401637caf8e 100644
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };
 
Quoted 8 lines

include/uapi/drm/drm_mode.h struct drm_mode_crtc_lut { · line 529

Quoted 4 lines
include/uapi/drm/drm_mode.h +2 -1
 struct drm_color_ctm {
-  /* Conversion matrix in S31.32 format. */
+  /*
+   * Conversion matrix in S31.32 format, in row-major form:

s32.32 is how I'd state that (to match the regular s32 and whatnot types).

Can you explain a bit more what exactly you mean by s32.32? e.g. what would be the bitfield representing the most negative number?

I understand the S31.32 here as a sign + magnitude format (which makes it rather odd to store it in a signed variable, but never mind). This also appears to be what igt does in set_ctm() in kms_pipe_color.c:

      for (i = 0; i < ARRAY_SIZE(ctm.matrix); i++) {
              if (coefficients[i] < 0) {
                      ctm.matrix[i] =
                              (int64_t) (-coefficients[i] * ((int64_t) 1L << 32));
                      ctm.matrix[i] |= 1ULL << 63;
              } else
                      ctm.matrix[i] =
                              (int64_t) (coefficients[i] * ((int64_t) 1L << 32));
      }

If that's what you meant as well, then I don't think s32.32 is a good way to describe it, because the integer part has only 31 bits available.

If you meant a regular two's-complement fixed-point number, where the most negative number would be 0x10000000.00000000, then yeah that's what I thought it meant too originally. Clarifying the docs here sounds like a great plan.

Quoted 7 lines
Quoted 3 lines

I guess the igt implementation means that it's a sign + magnitude number, and the fact that it's stored in an s64 is a bizarre quirk that we just live with.

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore? -Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw
Quoted 48 lines · Daniel Vetter
Quoted 46 lines · Ville Syrjälä
Quoted 45 lines
Quoted 7 lines
Quoted 7 lines
include/uapi/drm/drm_mode.h +0 -0
index ce7efe2e8a5e..3401637caf8e 100644
@@ -525,7 +525,13 @@ struct drm_mode_crtc_lut {
 };
 
Quoted 8 lines

include/uapi/drm/drm_mode.h struct drm_mode_crtc_lut { · line 529

Quoted 4 lines
include/uapi/drm/drm_mode.h +2 -1
 struct drm_color_ctm {
-  /* Conversion matrix in S31.32 format. */
+  /*
+   * Conversion matrix in S31.32 format, in row-major form:

s32.32 is how I'd state that (to match the regular s32 and whatnot types).

Can you explain a bit more what exactly you mean by s32.32? e.g. what would be the bitfield representing the most negative number?

I understand the S31.32 here as a sign + magnitude format (which makes it rather odd to store it in a signed variable, but never mind). This also appears to be what igt does in set_ctm() in kms_pipe_color.c:

      for (i = 0; i < ARRAY_SIZE(ctm.matrix); i++) {
              if (coefficients[i] < 0) {
                      ctm.matrix[i] =
                              (int64_t) (-coefficients[i] * ((int64_t) 1L << 32));
                      ctm.matrix[i] |= 1ULL << 63;
              } else
                      ctm.matrix[i] =
                              (int64_t) (coefficients[i] * ((int64_t) 1L << 32));
      }

If that's what you meant as well, then I don't think s32.32 is a good way to describe it, because the integer part has only 31 bits available.

If you meant a regular two's-complement fixed-point number, where the most negative number would be 0x10000000.00000000, then yeah that's what I thought it meant too originally. Clarifying the docs here sounds like a great plan.

I guess the igt implementation means that it's a sign + magnitude number, and the fact that it's stored in an s64 is a bizarre quirk that we just live with.

Quoted 5 lines
Quoted 3 lines

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore?

I have no idea. Anyone else?

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

Hi,

Quoted 10 lines · Ville Syrjälä
Quoted 7 lines · Daniel Vetter
Quoted 3 lines · Ville Syrjälä

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore?

I have no idea. Anyone else?

I don't know of any implementation using this; maybe closed Intel Android stuff? Certainly GitHub showed no-one using it, and neither X nor Weston/Mutter are using it yet.

Cheers,
Daniel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

What's the verdict? We've got [1] which is about to become another (driver) implementation - better to change before that merges than after I guess.

-Brian

[1] https://lkml.org/lkml/2017/2/13/304

Quoted 13 lines · Daniel Stone

Hi,

Quoted 9 lines · Ville Syrjälä
Quoted 7 lines · Daniel Vetter
Quoted 3 lines · Ville Syrjälä

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore?

Quoted 8 lines
Quoted 1 line

I have no idea. Anyone else?

I don't know of any implementation using this; maybe closed Intel Android stuff? Certainly GitHub showed no-one using it, and neither X nor Weston/Mutter are using it yet.

Cheers,
Daniel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw
Quoted 4 lines · Brian Starkey

What's the verdict? We've got [1] which is about to become another (driver) implementation - better to change before that merges than after I guess.

Quoted 27 lines

-Brian

[1] https://lkml.org/lkml/2017/2/13/304

Quoted 21 lines · Daniel Stone

Hi,

Quoted 10 lines · Ville Syrjälä
Quoted 7 lines · Daniel Vetter
Quoted 3 lines · Ville Syrjälä

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore?

I have no idea. Anyone else?

I don't know of any implementation using this; maybe closed Intel Android stuff? Certainly GitHub showed no-one using it, and neither X nor Weston/Mutter are using it yet.

Cheers,
Daniel

If we're talking fixed point reprsentation, ChromeOS is using this :

https://cs.chromium.org/chromium/src/ui/ozone/platform/drm/gpu/drm_device.cc?q=DrmDevice&l=209

-
Lionel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw
Quoted 29 lines · Lionel Landwerlin
Quoted 28 lines · Brian Starkey

What's the verdict? We've got [1] which is about to become another (driver) implementation - better to change before that merges than after I guess.

-Brian

[1] https://lkml.org/lkml/2017/2/13/304

Quoted 19 lines · Daniel Stone

Hi,

Quoted 10 lines · Ville Syrjälä
Quoted 7 lines · Daniel Vetter
Quoted 3 lines · Ville Syrjälä

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore?

I have no idea. Anyone else?

I don't know of any implementation using this; maybe closed Intel Android stuff? Certainly GitHub showed no-one using it, and neither X nor Weston/Mutter are using it yet.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Cheers,
Daniel

If we're talking fixed point reprsentation, ChromeOS is using this :

https://cs.chromium.org/chromium/src/ui/ozone/platform/drm/gpu/drm_device.cc?q=DrmDevice&l=209

So it's already using the sign+magnitude stuff. Which presumably means we can't change it to two's complement anymore :( Maybe we add a CTM2 property ;)

Using sign+magnitude definitely looks rather inefficient since there's a branch inside the loop. With two's complement you wouldn't need that thing slowing you down.

Signature · 2 lines
Ville Syrjälä
Intel OTC
#13 lore raw
Quoted 31 lines · Ville Syrjälä
Quoted 30 lines · Lionel Landwerlin
Quoted 4 lines · Brian Starkey

What's the verdict? We've got [1] which is about to become another (driver) implementation - better to change before that merges than after I guess.

Quoted 23 lines

-Brian

[1] https://lkml.org/lkml/2017/2/13/304

Quoted 18 lines · Daniel Stone

Hi,

Quoted 8 lines · Ville Syrjälä
Quoted 6 lines · Daniel Vetter
Quoted 3 lines · Ville Syrjälä

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore?

I have no idea. Anyone else?

I don't know of any implementation using this; maybe closed Intel Android stuff? Certainly GitHub showed no-one using it, and neither X nor Weston/Mutter are using it yet.

Cheers,
Daniel

If we're talking fixed point reprsentation, ChromeOS is using this :

Quoted 9 lines
Quoted 1 line

https://cs.chromium.org/chromium/src/ui/ozone/platform/drm/gpu/drm_device.cc?q=DrmDevice&l=209

So it's already using the sign+magnitude stuff. Which presumably means we can't change it to two's complement anymore :( Maybe we add a CTM2 property ;)

Using sign+magnitude definitely looks rather inefficient since there's a branch inside the loop. With two's complement you wouldn't need that thing slowing you down.

If you're seriously considering that, you might also want to bump struct drm_color_lut to use 32bits fields. It seems some people have concerned about HDR.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#14 lore raw
Quoted 37 lines · Lionel Landwerlin
Quoted 36 lines · Ville Syrjälä
Quoted 26 lines · Lionel Landwerlin
Quoted 25 lines · Brian Starkey

What's the verdict? We've got [1] which is about to become another (driver) implementation - better to change before that merges than after I guess.

-Brian

[1] https://lkml.org/lkml/2017/2/13/304

Quoted 16 lines · Daniel Stone

Hi,

Quoted 8 lines · Ville Syrjälä
Quoted 6 lines · Daniel Vetter
Quoted 3 lines · Ville Syrjälä

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore?

I have no idea. Anyone else?

I don't know of any implementation using this; maybe closed Intel Android stuff? Certainly GitHub showed no-one using it, and neither X nor Weston/Mutter are using it yet.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

Cheers,
Daniel

If we're talking fixed point reprsentation, ChromeOS is using this :

https://cs.chromium.org/chromium/src/ui/ozone/platform/drm/gpu/drm_device.cc?q=DrmDevice&l=209

So it's already using the sign+magnitude stuff. Which presumably means we can't change it to two's complement anymore :( Maybe we add a CTM2 property ;)

Quoted 6 lines
Quoted 4 lines

Using sign+magnitude definitely looks rather inefficient since there's a branch inside the loop. With two's complement you wouldn't need that thing slowing you down.

If you're seriously considering that, you might also want to bump struct drm_color_lut to use 32bits fields.

Which is what I thought we had already agreed to do when we started planning this color management stuff. But I guess that plan got somehow scrapped after I was no longer part of the discussions.

Quoted 1 line

It seems some people have concerned about HDR.

HDR is definitely something I'd like to have a look at.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#15 lore raw
In reply to Ville Syrjälä

Hi,

Quoted 8 lines · Ville Syrjälä
Quoted 3 lines · Lionel Landwerlin

If we're talking fixed point reprsentation, ChromeOS is using this :

https://cs.chromium.org/chromium/src/ui/ozone/platform/drm/gpu/drm_device.cc?q=DrmDevice&l=209

So it's already using the sign+magnitude stuff. Which presumably means we can't change it to two's complement anymore :( Maybe we add a CTM2 property ;)

I wouldn't be so sure; AFAIK it only ships on platforms where the kernel is also built from the same tree, and generally where the support is backported anyway. So it would be possible to atomically land a change to CrOS such that the kernels and Chrome move together to a changed representation.

Cheers,
Daniel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#16 lore raw
In reply to Brian Starkey
Quoted 3 lines · Brian Starkey

What's the verdict? We've got [1] which is about to become another (driver) implementation - better to change before that merges than after I guess.

We could also just switch the internal representation to something more reasonable, and add glue code in the atomic core to remap between whatever the properties are and the internal representation. Same thing we essentially already do with the display mode.

That would then also extend to CTM2 or whatever.

For sure not really a good reason to stall a driver imo. -Daniel

Quoted 27 lines

-Brian

[1] https://lkml.org/lkml/2017/2/13/304

Quoted 21 lines · Daniel Stone

Hi,

Quoted 10 lines · Ville Syrjälä
Quoted 7 lines · Daniel Vetter
Quoted 3 lines · Ville Syrjälä

Hmm. Two's complement is what I was thinking it is. Which shows that I never managed to read the code in any detail. Definitely needs to be documented properly.

That sounds supremely backwards. I guess we can't fix this anymore?

I have no idea. Anyone else?

I don't know of any implementation using this; maybe closed Intel Android stuff? Certainly GitHub showed no-one using it, and neither X nor Weston/Mutter are using it yet.

Cheers,
Daniel

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