All of lore.kernel.org
 help / color / mirror / Atom feed
From: <sunpeng.li-5C7GfCeVMHo@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: "Leo (Sunpeng) Li" <sunpeng.li-5C7GfCeVMHo@public.gmane.org>,
	michel-otUistvHUpPR7s880joybQ@public.gmane.org,
	harry.wentland-5C7GfCeVMHo@public.gmane.org
Subject: [PATCH xf86-video-amdgpu v2 1/7] Cache color property IDs and LUT sizes during pre-init
Date: Fri, 15 Jun 2018 17:02:57 -0400	[thread overview]
Message-ID: <1529096577-21872-1-git-send-email-sunpeng.li@amd.com> (raw)
In-Reply-To: <1527869017-9209-2-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>

From: "Leo (Sunpeng) Li" <sunpeng.li@amd.com>

DRM creates property types with unique IDs during kernel driver init.
Cache the color property IDs on DDX init for use later, when we need
to modify these properties. Also cache the (de)gamma LUT sizes, since
they are the same for all CRTCs on AMD hardware.

Since these values are the same regardless of the CRTC, they can be
cached within the private drmmode_rec object. We can also use any color-
management-enabled CRTC to initially fetch them.

Also introduce an enumeration of possible color management properties,
to provide a easy and unified way of referring to them.

v2:
- Reorder cm property enum so that LUT sizes are at the end. This allows
  us to use DEGAMMA_LUT_SIZE as an anchor for iterating over mutable cm
  properties.
- Cache (de)gamma LUT sizes within drmmode, since it's the same for all
  CRTCs on AMD hardware. Update commit message to reflect this.

Signed-off-by: Leo (Sunpeng) Li <sunpeng.li@amd.com>
---
 src/drmmode_display.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/drmmode_display.h | 22 ++++++++++++
 2 files changed, 120 insertions(+)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 8a1a201..994f130 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -746,6 +746,28 @@ drmmode_crtc_scanout_update(xf86CrtcPtr crtc, DisplayModePtr mode,
 	}
 }
 
+static char *cm_prop_names[] = {
+	"DEGAMMA_LUT",
+	"CTM",
+	"GAMMA_LUT",
+	"DEGAMMA_LUT_SIZE",
+	"GAMMA_LUT_SIZE",
+};
+
+/**
+ * Return the enum of the color management property with the given name.
+ */
+static enum drmmode_cm_prop get_cm_enum_from_str(const char *prop_name)
+{
+	enum drmmode_cm_prop ret;
+
+	for (ret = 0; ret < CM_NUM_PROPS; ret++) {
+		if (!strcmp(prop_name, cm_prop_names[ret]))
+			return ret;
+	}
+	return CM_INVALID_PROP;
+}
+
 static void
 drmmode_crtc_gamma_do_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
 			  uint16_t *blue, int size)
@@ -2413,6 +2435,80 @@ drmmode_page_flip_target_relative(AMDGPUEntPtr pAMDGPUEnt,
 				 drm_queue_seq);
 }
 
+/**
+ * Initialize DDX color management support. It does two things:
+ *
+ * 1. Cache DRM color management property type IDs, as they do not change. They
+ *    will be used later to modify color management via DRM, or to determine if
+ *    there's kernel support for color management.
+ *
+ * 2. Cache degamma/gamma LUT sizes, since all CRTCs have the same LUT sizes on
+ *    AMD hardware.
+ *
+ * If the cached ID's are all 0 after calling this function, then color
+ * management is not supported. For short, checking if the gamma LUT size
+ * property ID == 0 is sufficient.
+ *
+ * This should be called before CRTCs are initialized within pre_init, as the
+ * cached values will be used there.
+ *
+ * @drm_fd: DRM file descriptor
+ * @drmmode: drmmode object, where the cached IDs are stored
+ * @mode_res: The DRM mode resource containing the CRTC ids
+ */
+static void drmmode_cm_init(int drm_fd, drmmode_ptr drmmode,
+			    drmModeResPtr mode_res)
+{
+	drmModeObjectPropertiesPtr drm_props;
+	drmModePropertyPtr drm_prop;
+	enum drmmode_cm_prop cm_prop;
+	uint32_t cm_enabled = 0;
+	uint32_t cm_all_enabled = (1 << CM_NUM_PROPS) - 1;
+	int i;
+
+	memset(drmmode->cm_prop_ids, 0, sizeof(drmmode->cm_prop_ids));
+	drmmode->gamma_lut_size = drmmode->degamma_lut_size = 0;
+
+	/* AMD hardware has color management support on all pipes. It is
+	 * therefore sufficient to only check the first CRTC.
+	 */
+	drm_props = drmModeObjectGetProperties(drm_fd,
+					       mode_res->crtcs[0],
+					       DRM_MODE_OBJECT_CRTC);
+	if (!drm_props)
+		return;
+
+	for (i = 0; i < drm_props->count_props; i++) {
+		drm_prop = drmModeGetProperty(drm_fd,
+					      drm_props->props[i]);
+		if (!drm_prop)
+			continue;
+
+		cm_prop = get_cm_enum_from_str(drm_prop->name);
+		if (cm_prop == CM_INVALID_PROP)
+			continue;
+
+		if (cm_prop == CM_DEGAMMA_LUT_SIZE)
+			drmmode->degamma_lut_size = drm_props->prop_values[i];
+		else if (cm_prop == CM_GAMMA_LUT_SIZE)
+			drmmode->gamma_lut_size = drm_props->prop_values[i];
+
+		drmmode->cm_prop_ids[cm_prop] = drm_props->props[i];
+		cm_enabled |= 1 << cm_prop;
+
+		drmModeFreeProperty(drm_prop);
+	}
+	drmModeFreeObjectProperties(drm_props);
+
+	/* cm is enabled only if all prop ids are found */
+	if (cm_enabled == cm_all_enabled)
+		return;
+
+	/* Otherwise, disable DDX cm support */
+	memset(drmmode->cm_prop_ids, 0, sizeof(drmmode->cm_prop_ids));
+	drmmode->gamma_lut_size = drmmode->degamma_lut_size = 0;
+}
+
 Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
 	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(pScrn);
@@ -2459,6 +2555,8 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 	if (pScrn->depth == 30)
 		info->drmmode_crtc_funcs.gamma_set = NULL;
 
+	drmmode_cm_init(pAMDGPUEnt->fd, drmmode, mode_res);
+
 	for (i = 0; i < mode_res->count_crtcs; i++)
 		if (!xf86IsEntityShared(pScrn->entityList[0]) ||
 		    (crtcs_needed && !(pAMDGPUEnt->assigned_crtcs & (1 << i))))
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index 25ae9f8..4aa8e88 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -36,6 +36,22 @@
 #include "amdgpu_probe.h"
 #include "amdgpu.h"
 
+/*
+ * Enum of non-legacy color management properties, according to DRM. Note that
+ * the values should be incremental (with the exception of the INVALID member),
+ * as defined by C99. The ordering also matters. Some logics (such as iterators
+ * and bitmasks) depend on these facts.
+ */
+enum drmmode_cm_prop {
+	CM_DEGAMMA_LUT,
+	CM_CTM,
+	CM_GAMMA_LUT,
+	CM_DEGAMMA_LUT_SIZE,
+	CM_GAMMA_LUT_SIZE,
+	CM_NUM_PROPS,
+	CM_INVALID_PROP = -1,
+};
+
 typedef struct {
 	ScrnInfoPtr scrn;
 #ifdef HAVE_LIBUDEV
@@ -49,6 +65,12 @@ typedef struct {
 
 	Bool dri2_flipping;
 	Bool present_flipping;
+
+	/* Cache for DRM property type IDs for CRTC color management */
+	uint32_t cm_prop_ids[CM_NUM_PROPS];
+	/* Lookup table sizes */
+	uint32_t degamma_lut_size;
+	uint32_t gamma_lut_size;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-06-15 21:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01 16:03 [PATCH xf86-video-amdgpu 0/7] Enabling Color Management - Round 3 sunpeng.li-5C7GfCeVMHo
     [not found] ` <1527869017-9209-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-01 16:03   ` [PATCH xf86-video-amdgpu 1/7] Cache color property IDs during pre-init sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1527869017-9209-2-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-15 21:02       ` sunpeng.li-5C7GfCeVMHo [this message]
2018-06-01 16:03   ` [PATCH xf86-video-amdgpu 2/7] Initialize color properties on CRTC during CRTC init sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1527869017-9209-3-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-14 16:58       ` Michel Dänzer
2018-06-15 21:04       ` [PATCH xf86-video-amdgpu v2 " sunpeng.li-5C7GfCeVMHo
2018-06-01 16:03   ` [PATCH xf86-video-amdgpu 3/7] Configure color properties when creating output resources sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1527869017-9209-4-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-14 16:58       ` Michel Dänzer
2018-06-15 21:04       ` [PATCH xf86-video-amdgpu v2 " sunpeng.li-5C7GfCeVMHo
2018-06-01 16:03   ` [PATCH xf86-video-amdgpu 4/7] Update color properties on output_get_property sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1527869017-9209-5-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-15 21:05       ` [PATCH xf86-video-amdgpu v2 " sunpeng.li-5C7GfCeVMHo
2018-06-01 16:03   ` [PATCH xf86-video-amdgpu 5/7] Enable setting of color properties via RandR sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1527869017-9209-6-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-15 21:05       ` [PATCH xf86-video-amdgpu v2 " sunpeng.li-5C7GfCeVMHo
2018-06-01 16:03   ` [PATCH xf86-video-amdgpu 6/7] Compose non-legacy with legacy regamma LUT sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1527869017-9209-7-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-08 17:21       ` [PATCH xf86-video-amdgpu 6/7 v2] " sunpeng.li-5C7GfCeVMHo
     [not found]         ` <1528478484-31177-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-15 21:12           ` [PATCH xf86-video-amdgpu v3 6/7] " sunpeng.li-5C7GfCeVMHo
2018-06-01 16:03   ` [PATCH xf86-video-amdgpu 7/7] Also compose LUT when setting legacy gamma sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1527869017-9209-8-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-06-15 21:05       ` [PATCH xf86-video-amdgpu v2 " sunpeng.li-5C7GfCeVMHo
2018-06-06 16:01   ` [PATCH xf86-video-amdgpu 0/7] Enabling Color Management - Round 3 Michel Dänzer
     [not found]     ` <e0a71df1-265b-cb62-1c1f-567b26808b71-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-06-06 17:03       ` Michel Dänzer
     [not found]         ` <e47b6ff4-9696-bf20-d299-687b96ab0437-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-06-06 17:22           ` Leo Li
2018-06-07  7:36           ` Michel Dänzer
2018-06-07 22:21           ` Leo Li
     [not found]             ` <9392443d-13d4-c1c2-c07b-67a2b6c72556-5C7GfCeVMHo@public.gmane.org>
2018-06-08 14:33               ` Michel Dänzer
     [not found]                 ` <8807a407-352d-3caa-108a-95aadcd6b414-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-06-08 14:37                   ` Michel Dänzer
2018-06-07  7:22       ` Mike Lothian
     [not found]         ` <CAHbf0-GW9MDmTBDepJjG-WXdqNPhsHWwQMvHo1Sma+JCDy-1dQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-06-07  7:31           ` Michel Dänzer
     [not found]             ` <64b1e3fc-d267-b1fc-032a-86aebfe2ff1d-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-06-07 13:26               ` Mike Lothian
     [not found]                 ` <CAHbf0-E=KyYDVj-L5fknEPGL6kUeP--bDOuPXUz5oMjciABXYw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-06-07 13:55                   ` Michel Dänzer
2018-06-14 16:57   ` Michel Dänzer
     [not found]     ` <afdb23a3-8722-7928-a612-291b42e7f260-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-06-14 19:49       ` Leo Li
     [not found]         ` <a5a043dd-cd40-33bc-1e1d-e3f8980cb69d-5C7GfCeVMHo@public.gmane.org>
2018-06-15  6:57           ` Michel Dänzer
     [not found]             ` <b64b3eea-5780-ef62-2b59-b2e4733ead16-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-06-22 13:41               ` Leo Li
     [not found]                 ` <09c87c7a-76ed-062e-d911-5b188e3ed5cb-5C7GfCeVMHo@public.gmane.org>
2018-06-22 13:49                   ` Michel Dänzer
2018-06-26 15:46                   ` Michel Dänzer
     [not found]                     ` <d977b737-6d9d-de47-6a37-763af76efa54-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-06-26 18:16                       ` Harry Wentland

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=1529096577-21872-1-git-send-email-sunpeng.li@amd.com \
    --to=sunpeng.li-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=harry.wentland-5C7GfCeVMHo@public.gmane.org \
    --cc=michel-otUistvHUpPR7s880joybQ@public.gmane.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.