All of lore.kernel.org
 help / color / mirror / Atom feed
From: venkata.sai.patnana@intel.com
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 10/24] kms_color_helper: Add helper functions to support logarithmic gamma mode
Date: Thu,  3 Jun 2021 17:50:13 +0530	[thread overview]
Message-ID: <20210603122027.27330-10-venkata.sai.patnana@intel.com> (raw)
In-Reply-To: <20210603122027.27330-1-venkata.sai.patnana@intel.com>

From: Mukunda Pramodh Kumar <mukunda.pramodh.kumar@intel.com>

Add helper functions to support logarithmic gamma mode

v5: Move all compute/set logic to advance gamma mode function
v4: Removed unnecessary code and checks
    Makes the changes more generic
v3: calculate luts using gamma coefficients(Uma Shankar)

Cc: Uma Shankar <uma.shankar@intel.com>
Signed-off-by: Mukunda Pramodh Kumar <mukunda.pramodh.kumar@intel.com>
(cherry picked from commit de9636f5ac840d03c1ed77fa928212b85b250bf9)
---
 tests/kms_color_helper.c | 132 ++++++++++++++++++++++++++++++++++++++-
 tests/kms_color_helper.h |  16 +++++
 2 files changed, 147 insertions(+), 1 deletion(-)

diff --git a/tests/kms_color_helper.c b/tests/kms_color_helper.c
index a14a97999e..36a9964cbf 100644
--- a/tests/kms_color_helper.c
+++ b/tests/kms_color_helper.c
@@ -24,6 +24,8 @@
 
 #include "kms_color_helper.h"
 
+#define DRM_CLIENT_CAP_ADVANCE_GAMMA_MODES     6
+
 void paint_gradient_rectangles(data_t *data,
 			       drmModeModeInfo *mode,
 			       color_t *colors,
@@ -166,7 +168,8 @@ struct drm_color_lut *coeffs_to_lut(data_t *data,
 		 * Mask the lower bits not provided by the framebuffer so we
 		 * can do CRC comparisons.
 		 */
-		v &= mask;
+		if (intel_gen(data->devid) < 13)
+			v &= mask;
 
 		lut[i].red = v;
 		lut[i].green = v;
@@ -181,6 +184,33 @@ struct drm_color_lut *coeffs_to_lut(data_t *data,
 	return lut;
 }
 
+struct drm_color_lut *coeffs_to_logarithmic_lut(data_t *data,
+						const gamma_lut_t *gamma,
+						uint32_t color_depth,
+						int off)
+{
+	struct drm_color_lut *lut;
+	int i, lut_size = gamma->size;
+	/* This is the maximum value due to 16 bit precision in hardware. */
+	uint32_t max_hw_value = (1 << 16) - 1;
+	uint32_t v;
+	unsigned int max_segment_value = 1 << 24;
+	double scaling_factor;
+
+	lut = malloc(sizeof(struct drm_color_lut) * lut_size);
+
+	for (i = 0; i < lut_size; i++) {
+		scaling_factor = (double)max_hw_value / (double)max_segment_value;
+		v = (double)gamma->coeffs[i] * (double)scaling_factor;
+		v =  MIN(v, max_hw_value);
+		lut[i].red = v;
+		lut[i].green = v;
+		lut[i].blue = v;
+	}
+
+	return lut;
+}
+
 void set_degamma(data_t *data,
 		 igt_pipe_t *pipe,
 		 const gamma_lut_t *gamma)
@@ -194,6 +224,15 @@ void set_degamma(data_t *data,
 	free(lut);
 }
 
+void set_pipe_gamma(igt_pipe_t *pipe,
+		    uint64_t value,
+		    struct drm_color_lut *lut,
+		    uint32_t size)
+{
+	igt_pipe_obj_set_prop_value(pipe, IGT_CRTC_GAMMA_MODE, value);
+	igt_pipe_obj_replace_prop_blob(pipe, IGT_CRTC_GAMMA_LUT, lut, size);
+}
+
 void set_gamma(data_t *data,
 	       igt_pipe_t *pipe, const gamma_lut_t *gamma)
 {
@@ -232,6 +271,51 @@ void disable_prop(igt_pipe_t *pipe, enum igt_atomic_crtc_properties prop)
 		igt_pipe_obj_replace_prop_blob(pipe, prop, NULL, 0);
 }
 
+drmModePropertyPtr get_pipe_gamma_degamma_mode(igt_pipe_t *pipe,
+					       enum igt_atomic_crtc_properties prop)
+{
+	igt_display_t *display = pipe->display;
+	uint32_t prop_id = pipe->props[prop];
+	drmModePropertyPtr drmProp;
+
+	igt_assert(prop_id);
+
+	drmProp = drmModeGetProperty(display->drm_fd, prop_id);
+
+	igt_assert(drmProp);
+	igt_assert(drmProp->count_enums);
+
+	return drmProp;
+}
+
+gamma_lut_t *pipe_create_linear_lut(segment_data_t *info)
+{
+	uint32_t segment, entry, index = 0;
+	double val;
+	int i = 0;
+	gamma_lut_t *gamma = alloc_lut(info->entries_count);
+
+	igt_assert(gamma);
+
+	gamma->size = info->entries_count;
+	for (segment = 0; segment < info->segment_count; segment++) {
+		uint32_t entry_count = info->segment_data[segment].count;
+		uint32_t start = (segment == 0) ? 0 : (1 << (segment - 1));
+		uint32_t end = 1 << segment;
+
+		for (entry = 0; entry < entry_count; entry++) {
+			val = (index == 0) ? /* First entry is Zero. */
+				0 : start + entry *
+				((end - start) * 1.0 / entry_count);
+
+			gamma->coeffs[i++] = val;
+			index++;
+		}
+	}
+
+	return gamma;
+}
+
 drmModePropertyPtr get_plane_gamma_degamma_mode(igt_plane_t *plane,
 				enum igt_atomic_plane_properties prop)
 {
@@ -322,6 +406,7 @@ segment_data_t *get_segment_data(data_t *data,
 	info->segment_data = malloc(sizeof(struct drm_color_lut_range) * info->segment_count);
 	igt_assert(info->segment_data);
 
+	info->entries_count = 0;
 	for (i = 0; i < info->segment_count; i++) {
 		info->entries_count += lut_range[i].count;
 		info->segment_data[i] = lut_range[i];
@@ -332,6 +417,51 @@ segment_data_t *get_segment_data(data_t *data,
 	return info;
 }
 
+void set_advance_gamma(data_t *data, igt_pipe_t *pipe, enum gamma_type type)
+{
+	igt_display_t *display = &data->display;
+	gamma_lut_t *gamma_log;
+	drmModePropertyPtr gamma_mode = NULL;
+	segment_data_t *segment_info = NULL;
+	struct drm_color_lut *lut = NULL;
+	int lut_size = 0;
+
+	drmSetClientCap(data->drm_fd, DRM_CLIENT_CAP_ADVANCE_GAMMA_MODES, 1);
+	gamma_mode = get_pipe_gamma_degamma_mode(pipe, IGT_CRTC_GAMMA_MODE);
+
+	for (int i = 0; i < gamma_mode->count_enums; i++) {
+		if (!strcmp(gamma_mode->enums[i].name, "logarithmic gamma")) {
+			segment_info = get_segment_data(data,
+							gamma_mode->enums[i].value,
+							gamma_mode->enums[i].name);
+			lut_size = sizeof(struct drm_color_lut) *
+					  segment_info->entries_count;
+			if (type == LINEAR_GAMMA) {
+				gamma_log = pipe_create_linear_lut(segment_info);
+				lut = coeffs_to_logarithmic_lut(data,
+								gamma_log,
+								data->color_depth,
+								0);
+			} else if (type == MAX_GAMMA) {
+				gamma_log = generate_table_max(segment_info->entries_count);
+				gamma_log->size = segment_info->entries_count;
+				lut = coeffs_to_lut(data, gamma_log,
+						    data->color_depth, 0);
+			}
+			set_pipe_gamma(pipe, gamma_mode->enums[i].value,
+				       lut, lut_size);
+			igt_display_commit2(display, display->is_atomic
+					    ? COMMIT_ATOMIC : COMMIT_LEGACY);
+			break;
+		}
+	}
+	drmSetClientCap(data->drm_fd, DRM_CLIENT_CAP_ADVANCE_GAMMA_MODES, 0);
+	free(gamma_log);
+	free(lut);
+	clear_segment_data(segment_info);
+	drmModeFreeProperty(gamma_mode);
+}
+
 void set_plane_gamma(igt_plane_t *plane,
 		char *mode,
 		struct drm_color_lut_ext *lut,
diff --git a/tests/kms_color_helper.h b/tests/kms_color_helper.h
index 945cc475e3..14d42d29cc 100644
--- a/tests/kms_color_helper.h
+++ b/tests/kms_color_helper.h
@@ -70,6 +70,11 @@ typedef struct {
 	uint32_t entries_count;
 } segment_data_t;
 
+enum gamma_type {
+	LINEAR_GAMMA,
+	MAX_GAMMA
+};
+
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
 void paint_gradient_rectangles(data_t *data,
@@ -89,6 +94,10 @@ struct drm_color_lut *coeffs_to_lut(data_t *data,
 				    const gamma_lut_t *gamma,
 				    uint32_t color_depth,
 				    int off);
+struct drm_color_lut *coeffs_to_logarithmic_lut(data_t *data,
+						const gamma_lut_t *gamma,
+						uint32_t color_depth,
+						int off);
 void set_degamma(data_t *data,
 		 igt_pipe_t *pipe,
 		 const gamma_lut_t *gamma);
@@ -98,12 +107,19 @@ void set_gamma(data_t *data,
 void set_ctm(igt_pipe_t *pipe, const double *coefficients);
 void disable_prop(igt_pipe_t *pipe, enum igt_atomic_crtc_properties prop);
 
+drmModePropertyPtr get_pipe_gamma_degamma_mode(igt_pipe_t *pipe,
+					       enum igt_atomic_crtc_properties
+					       prop);
 drmModePropertyPtr get_plane_gamma_degamma_mode(igt_plane_t *plane,
 	enum igt_atomic_plane_properties prop);
 void clear_segment_data(segment_data_t *info);
+gamma_lut_t *pipe_create_linear_lut(segment_data_t *info);
 struct drm_color_lut_ext *create_linear_lut(segment_data_t *info);
 struct drm_color_lut_ext *create_max_lut(segment_data_t *info);
 segment_data_t *get_segment_data(data_t *data, uint64_t blob_id, char *mode);
+void set_pipe_gamma(igt_pipe_t *pipe, uint64_t value,
+		    struct drm_color_lut *lut, uint32_t size);
+void set_advance_gamma(data_t *data, igt_pipe_t *pipe, enum gamma_type type);
 void set_plane_gamma(igt_plane_t *plane,
 	char *mode, struct drm_color_lut_ext *lut, uint32_t size);
 void set_plane_degamma(igt_plane_t *plane,
-- 
2.25.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2021-06-03 12:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 12:20 [igt-dev] [PATCH i-g-t 01/24] lib/igt_kms: Add plane color mgmt properties venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 02/24] kms_color_helper: Add helper functions for plane color mgmt venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 03/24] tests/kms_color: New subtests for Plane gamma venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 04/24] tests/kms_color: New subtests for Plane degamma venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 05/24] tests/kms_color: New subtests for Plane CTM venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 06/24] tests/kms_color_chamelium: New subtests for Plane gamma venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 07/24] tests/kms_color_chamelium: New subtests for Plane degamma venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 08/24] tests/kms_color_chamelium: New subtests for Plane CTM venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 09/24] lib/igt_kms: Add pipe color mgmt properties venkata.sai.patnana
2021-06-03 12:20 ` venkata.sai.patnana [this message]
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 11/24] tests/kms_color: Extended IGT tests to support logarithmic gamma mode venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 12/24] tests/kms_color_chamelium: " venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 13/24] tests/kms_color: Optimize plane ctm test venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 14/24] tests/kms_color_chamelium: " venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 15/24] tests/kms_dither: New IGT to validate crtc Dithering venkata.sai.patnana
2021-06-15  5:45   ` Shankar, Uma
2021-06-15  5:56     ` Modem, Bhanuprakash
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 16/24] tests/kms_dither: Validate dither after CC blocks venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 17/24] tests/kms_dither: Dont assert if debugfs is not present venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 18/24] tests/device_reset: Unload snd driver before i915 unbind venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 19/24] tests/core_hotunplug: " venkata.sai.patnana
2021-06-03 12:20 ` [igt-dev] [PATCH i-g-t 21/24] lib/igt_debugfs: Add suppress wakeup hpds enable for display venkata.sai.patnana
2021-06-03 12:46   ` Petri Latvala
2021-06-03 12:41 ` [igt-dev] [PATCH i-g-t 01/24] lib/igt_kms: Add plane color mgmt properties Petri Latvala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210603122027.27330-10-venkata.sai.patnana@intel.com \
    --to=venkata.sai.patnana@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.