Skip to contentSkip to conversation

drm/amd/display: Add Gamma 2.4 and 2.6 colorop support

PATCH Superseded Harry Wentland 2 participants 6 messages Nov 19

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Harry Wentland

author maintainer
#0 lore raw

cover drm/amd/display: Add Gamma 2.4 and 2.6 colorop support

Mutter needs a pure 2.4 power curve. The color pipeline only has 2.2. This series adds 2.4, and 2.6 for completeness.

Tested on Navi 48.

IGT patches for the Gamma 2.4 and 2.6 tests are on the igt-dev mailing list.

Harry Wentland (4):
drm/colorop: Define Gamma 2.4 and 2.6 and its Inverse drm/amd/display: Use the wide CM3 curve for gamma 2.4 and 2.6 drm/amd/display: Add support for 2.4 and 2.6 Gamma and its Inverse drm/amd/display: Add KUnit cases for gamma 2.4 and 2.6 colorops

 .../amd/display/amdgpu_dm/amdgpu_dm_color.c   |  6 +++
 .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 12 +++--
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    | 18 +++++++
 .../amdgpu_dm/tests/amdgpu_dm_colorop_test.c  | 54 +++++++++++++++++--
 .../amd/display/dc/dcn30/dcn30_cm_common.c    |  2 +
 drivers/gpu/drm/drm_colorop.c                 |  4 ++
 include/drm/drm_colorop.h                     | 39 ++++++++++++++
 7 files changed, 129 insertions(+), 6 deletions(-)
Signature · 1 line
2.56.1
author maintainer
#1 lore raw

PATCH 1/4 drm/colorop: Define Gamma 2.4 and 2.6 and its Inverse

Add new 1D curve colorop types for the Gamma 2.4 and Gamma 2.6 power functions and their inverses.

---
 drivers/gpu/drm/drm_colorop.c |  4 ++++
 include/drm/drm_colorop.h     | 39 +++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
drivers/gpu/drm/drm_colorop.c +4 -0
index 682fcc651525..d62153fd9c71 100644
@@ -79,6 +79,10 @@ static const char * const colorop_curve_1d_type_names[] = {
 	[DRM_COLOROP_1D_CURVE_BT2020_OETF] = "BT.2020 OETF",
 	[DRM_COLOROP_1D_CURVE_GAMMA22] = "Gamma 2.2",
 	[DRM_COLOROP_1D_CURVE_GAMMA22_INV] = "Gamma 2.2 Inverse",
+	[DRM_COLOROP_1D_CURVE_GAMMA24] = "Gamma 2.4",
+	[DRM_COLOROP_1D_CURVE_GAMMA24_INV] = "Gamma 2.4 Inverse",
+	[DRM_COLOROP_1D_CURVE_GAMMA26] = "Gamma 2.6",
+	[DRM_COLOROP_1D_CURVE_GAMMA26_INV] = "Gamma 2.6 Inverse",
 };
 
 static const struct drm_prop_enum_list drm_colorop_lut1d_interpolation_list[] = {
include/drm/drm_colorop.h +39 -0
index 224fae40ed2b..5c4c763da83e 100644
@@ -126,6 +126,45 @@ enum drm_colorop_curve_1d_type {
 	 * The inverse of &DRM_COLOROP_1D_CURVE_GAMMA22
 	 */
 	DRM_COLOROP_1D_CURVE_GAMMA22_INV,
+
+	/**
+	 * @DRM_COLOROP_1D_CURVE_GAMMA24:
+	 *
+	 * enum string "Gamma 2.4"
+	 *
+	 * A gamma 2.4 power function. This applies a power curve with
+	 * gamma value of 2.4 to the input values.
+	 */
+	DRM_COLOROP_1D_CURVE_GAMMA24,
+
+	/**
+	 * @DRM_COLOROP_1D_CURVE_GAMMA24_INV:
+	 *
+	 * enum string "Gamma 2.4 Inverse"
+	 *
+	 * The inverse of &DRM_COLOROP_1D_CURVE_GAMMA24
+	 */
+	DRM_COLOROP_1D_CURVE_GAMMA24_INV,
+
+	/**
+	 * @DRM_COLOROP_1D_CURVE_GAMMA26:
+	 *
+	 * enum string "Gamma 2.6"
+	 *
+	 * A gamma 2.6 power function. This applies a power curve with
+	 * gamma value of 2.6 to the input values.
+	 */
+	DRM_COLOROP_1D_CURVE_GAMMA26,
+
+	/**
+	 * @DRM_COLOROP_1D_CURVE_GAMMA26_INV:
+	 *
+	 * enum string "Gamma 2.6 Inverse"
+	 *
+	 * The inverse of &DRM_COLOROP_1D_CURVE_GAMMA26
+	 */
+	DRM_COLOROP_1D_CURVE_GAMMA26_INV,
+
 	/**
 	 * @DRM_COLOROP_1D_CURVE_COUNT:
 	 *
Signature · 1 line
2.56.1
author maintainer
#2 lore raw

PATCH 2/4 drm/amd/display: Use the wide CM3 curve for gamma 2.4 and 2.6

In reply to Harry Wentland

cm3_helper_translate_curve_to_hw_format() puts PQ, gamma 2.2, and HLG on 32 regions from 2^-25 to 2^7. Gamma 2.4 and 2.6 used the other layout, 12 regions from 2^-12 to 2^0.

The inverse curve is the shaper, and its input is linear light from degamma. A 10-bit code v becomes (v/1023)^g. That is below 2^-12 for v = 1..31 at gamma 2.4 and v = 1..41 at gamma 2.6, so those codes come back as 0. On a gray ramp the round trip then misses the IGT bracket of 13. Gamma 2.4 needs a bracket of 33 and gamma 2.6 needs 41. Gamma 2.2 already uses the wide curve and its round trip is exact.

Use the 32-region curve for gamma 2.4 and 2.6. Its low end is 2^-25, which covers those dark codes. On DCN 4.0.1 the gamma 2.4 round trip is exact and gamma 2.6 is off by one 10-bit code, so the original bracket of 13 passes.

---
 drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c +2 -0
index eb299f7f9c41..8a76e985d359 100644
@@ -133,6 +133,8 @@ bool cm3_helper_translate_curve_to_hw_format(struct dc_context *ctx,
 	memset(seg_distr, 0, sizeof(seg_distr));
 
 	if (output_tf->tf == TRANSFER_FUNCTION_PQ || output_tf->tf == TRANSFER_FUNCTION_GAMMA22 ||
+		output_tf->tf == TRANSFER_FUNCTION_GAMMA24 ||
+		output_tf->tf == TRANSFER_FUNCTION_GAMMA26 ||
 		output_tf->tf == TRANSFER_FUNCTION_HLG) {
 		/* 32 segments
 		 * segments are from 2^-25 to 2^7
Signature · 1 line
2.56.1
author maintainer
#3 lore raw

PATCH 3/4 drm/amd/display: Add support for 2.4 and 2.6 Gamma and its Inverse

In reply to Harry Wentland

Wire up the newly defined Gamma 2.4 and Gamma 2.6 curve types in the amdgpu DM color pipeline. Map them to the corresponding DC transfer functions and advertise them in the supported degamma, shaper, and blend transfer function masks.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c  |  6 ++++++
 .../drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c    | 12 +++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +6 -0
index 45cea72111c7..c4df67aa421e 100644
@@ -945,6 +945,12 @@ amdgpu_colorop_tf_to_dc_tf(enum drm_colorop_curve_1d_type tf)
 	case DRM_COLOROP_1D_CURVE_GAMMA22:
 	case DRM_COLOROP_1D_CURVE_GAMMA22_INV:
 		return TRANSFER_FUNCTION_GAMMA22;
+	case DRM_COLOROP_1D_CURVE_GAMMA24:
+	case DRM_COLOROP_1D_CURVE_GAMMA24_INV:
+		return TRANSFER_FUNCTION_GAMMA24;
+	case DRM_COLOROP_1D_CURVE_GAMMA26:
+	case DRM_COLOROP_1D_CURVE_GAMMA26_INV:
+		return TRANSFER_FUNCTION_GAMMA26;
 	default:
 		return TRANSFER_FUNCTION_LINEAR;
 	}
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +9 -3
index d32bf2bf2847..935c041c1d31 100644
@@ -38,21 +38,27 @@ const u64 amdgpu_dm_supported_degam_tfs =
 	BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_PQ_125_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_BT2020_INV_OETF) |
-	BIT(DRM_COLOROP_1D_CURVE_GAMMA22);
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA22) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA24) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA26);
 EXPORT_IF_KUNIT(amdgpu_dm_supported_degam_tfs);
 
 const u64 amdgpu_dm_supported_shaper_tfs =
 	BIT(DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_BT2020_OETF) |
-	BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV);
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA24_INV) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA26_INV);
 EXPORT_IF_KUNIT(amdgpu_dm_supported_shaper_tfs);
 
 const u64 amdgpu_dm_supported_blnd_tfs =
 	BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_PQ_125_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_BT2020_INV_OETF) |
-	BIT(DRM_COLOROP_1D_CURVE_GAMMA22);
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA22) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA24) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA26);
 EXPORT_IF_KUNIT(amdgpu_dm_supported_blnd_tfs);
 
 #define MAX_COLOR_PIPELINE_OPS 10
Signature · 1 line
2.56.1
#4 lore raw

Re: [PATCH v1 3/4] drm/amd/display: Add support for 2.4 and 2.6 Gamma and its Inverse

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/amd/display: missing Gamma 2.4/2.6 wide curve in cm_helper_translate_curve_to_hw_format() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/amd/display: missing Gamma 2.4/2.6 wide curve in cm_helper_translate_curve_to_hw_format()
--

commit 9ada1f8d824096557c1dda5282f2d0aa09bccdb4
Author: Harry Wentland <[email protected]>

drm/amd/display: Add support for 2.4 and 2.6 Gamma and its Inverse

This commit maps the Gamma 2.4 and 2.6 1D curve types to the corresponding DC transfer functions and advertises them in the supported degamma, shaper, and blend transfer function masks.

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +3 -1
index d32bf2bf28478..935c041c1d316 100644
@@ -38,21 +38,27 @@ const u64 amdgpu_dm_supported_degam_tfs =
 	BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_PQ_125_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_BT2020_INV_OETF) |
-	BIT(DRM_COLOROP_1D_CURVE_GAMMA22);
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA22) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA24) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA26);
 EXPORT_IF_KUNIT(amdgpu_dm_supported_degam_tfs);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c const u64 amdgpu_dm_supported_degam_tfs = · line 53

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +3 -1
 
 const u64 amdgpu_dm_supported_shaper_tfs =
 	BIT(DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF) |
 	BIT(DRM_COLOROP_1D_CURVE_BT2020_OETF) |
-	BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV);
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA22_INV) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA24_INV) |
+	BIT(DRM_COLOROP_1D_CURVE_GAMMA26_INV);
 EXPORT_IF_KUNIT(amdgpu_dm_supported_shaper_tfs);

[Severity: Medium]
Should cm_helper_translate_curve_to_hw_format() also select the wide 32-region curve for TRANSFER_FUNCTION_GAMMA24 and TRANSFER_FUNCTION_GAMMA26?

While commit "drm/amd/display: Use the wide CM3 curve for gamma 2.4 and 2.6" updated cm3_helper_translate_curve_to_hw_format() (used on DCN 3.2 and 4.01), DCN 3.0, 3.01, 3.1, and 3.14 wire set_shaper_3dlut to dcn20_set_shaper_3dlut(), which translates plane_state->cm.shaper_func via cm_helper_translate_curve_to_hw_format():

drivers/gpu/drm/amd/display/dc/dcn10/dcn10_cm_common.c:cm_helper_translate_curve_to_hw_format() {
	...
	if (output_tf->tf == TRANSFER_FUNCTION_PQ || output_tf->tf == TRANSFER_FUNCTION_GAMMA22) {
		...
	} else {
		corner_points[0].red.x = dc_fixpt_from_fraction(1, 4096);
	...
}

When userspace configures DRM_COLOROP_1D_CURVE_GAMMA24_INV or DRM_COLOROP_1D_CURVE_GAMMA26_INV on the plane shaper colorop on DCN 3.0..3.14, the shaper LUT falls back to the 12-region (2^-12 to 2^0) curve and crushes dark linear values below 2^-12 to zero.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
author maintainer
#5 lore raw

PATCH 4/4 drm/amd/display: Add KUnit cases for gamma 2.4 and 2.6 colorops

In reply to Harry Wentland

Check that amdgpu_colorop_tf_to_dc_tf() maps the gamma 2.4 and 2.6 curves and their inverses to TRANSFER_FUNCTION_GAMMA24 and TRANSFER_FUNCTION_GAMMA26.

Check that the degamma and blend masks include gamma 2.4 and 2.6, and that the shaper mask includes their inverses. Update the *_no_extra_bits cases for the new mask values.

---
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    | 18 +++++++
 .../amdgpu_dm/tests/amdgpu_dm_colorop_test.c  | 54 +++++++++++++++++--
 2 files changed, 69 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_color_test.c +18 -0
index 7ad8c56cbcf3..7a2c137f2967 100644
@@ -330,6 +330,22 @@ static void dm_test_colorop_tf_to_dc_tf_gamma22(struct kunit *test)
 			(int)TRANSFER_FUNCTION_GAMMA22);
 }
 
+static void dm_test_colorop_tf_to_dc_tf_gamma24(struct kunit *test)
+{
+	KUNIT_EXPECT_EQ(test, (int)amdgpu_colorop_tf_to_dc_tf(DRM_COLOROP_1D_CURVE_GAMMA24),
+			(int)TRANSFER_FUNCTION_GAMMA24);
+	KUNIT_EXPECT_EQ(test, (int)amdgpu_colorop_tf_to_dc_tf(DRM_COLOROP_1D_CURVE_GAMMA24_INV),
+			(int)TRANSFER_FUNCTION_GAMMA24);
+}
+
+static void dm_test_colorop_tf_to_dc_tf_gamma26(struct kunit *test)
+{
+	KUNIT_EXPECT_EQ(test, (int)amdgpu_colorop_tf_to_dc_tf(DRM_COLOROP_1D_CURVE_GAMMA26),
+			(int)TRANSFER_FUNCTION_GAMMA26);
+	KUNIT_EXPECT_EQ(test, (int)amdgpu_colorop_tf_to_dc_tf(DRM_COLOROP_1D_CURVE_GAMMA26_INV),
+			(int)TRANSFER_FUNCTION_GAMMA26);
+}
+
 static void dm_test_colorop_tf_to_dc_tf_default(struct kunit *test)
 {
 	KUNIT_EXPECT_EQ(test, (int)amdgpu_colorop_tf_to_dc_tf(DRM_COLOROP_1D_CURVE_COUNT),
@@ -2928,6 +2944,8 @@ static struct kunit_case dm_color_test_cases[] = {
 	KUNIT_CASE(dm_test_colorop_tf_to_dc_tf_pq),
 	KUNIT_CASE(dm_test_colorop_tf_to_dc_tf_bt2020),
 	KUNIT_CASE(dm_test_colorop_tf_to_dc_tf_gamma22),
+	KUNIT_CASE(dm_test_colorop_tf_to_dc_tf_gamma24),
+	KUNIT_CASE(dm_test_colorop_tf_to_dc_tf_gamma26),
 	KUNIT_CASE(dm_test_colorop_tf_to_dc_tf_default),
 	/* __drm_lut_to_dc_gamma */
 	KUNIT_CASE(dm_test_drm_lut_to_dc_gamma_legacy_zero),
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c +51 -3

105 lines not on this page · raw message

Signature · 1 line
2.56.1