From: Oarora Etimis <oaroraetimis@gmail.com>
To: Louis Chauvet <louis.chauvet@bootlin.com>,
Haneen Mohammed <hamohammed.sa@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Melissa Wen <melissa.srw@gmail.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Alex Hung <alex.hung@amd.com>,
Robert Mader <robert.mader@collabora.com>,
Harry Wentland <harry.wentland@amd.com>,
Simon Ser <contact@emersion.fr>,
Daniel Stone <daniels@collabora.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/7] drm/vkms: add a 3D LUT colorop
Date: Sat, 28 Nov 2026 18:15:23 +0100 [thread overview]
Message-ID: <20261128-colorop-v1-5-dd79919f822b@gmail.com> (raw)
In-Reply-To: <20261128-colorop-v1-0-dd79919f822b@gmail.com>
Add a 3D LUT colorop of 17x17x17 entries, interpolated tetrahedrally.
The composer picks the cell each value falls in and weights the four
corners of the selected tetrahedron. Red is the fastest moving index, as
the uapi documents.
The existing colorops and their order are unchanged.
Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
drivers/gpu/drm/vkms/vkms_colorop.c | 19 ++++++
drivers/gpu/drm/vkms/vkms_composer.c | 126 +++++++++++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_composer.h | 2 +
drivers/gpu/drm/vkms/vkms_drv.h | 2 +
4 files changed, 149 insertions(+)
diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c
index 584305b0abfd..cceb9acca0da 100644
--- a/drivers/gpu/drm/vkms/vkms_colorop.c
+++ b/drivers/gpu/drm/vkms/vkms_colorop.c
@@ -138,6 +138,25 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr
drm_colorop_set_next_property(ops[i - 1], ops[i]);
+ i++;
+
+ /* 7th op: 3D LUT */
+ ops[i] = kzalloc_obj(*ops[i]);
+ if (!ops[i]) {
+ drm_err(dev, "KMS: Failed to allocate colorop\n");
+ ret = -ENOMEM;
+ goto cleanup;
+ }
+
+ ret = drm_plane_colorop_3dlut_init(dev, ops[i], plane, &vkms_colorop_funcs,
+ VKMS_LUT3D_SIZE,
+ DRM_COLOROP_LUT3D_INTERPOLATION_TETRAHEDRAL,
+ DRM_COLOROP_FLAG_ALLOW_BYPASS);
+ if (ret)
+ goto cleanup;
+
+ drm_colorop_set_next_property(ops[i - 1], ops[i]);
+
list->name = kasprintf(GFP_KERNEL, "Color Pipeline %d", ops[0]->base.id);
return 0;
diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
index e00d1d0b2f2d..51ac2ae75cf0 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -256,6 +256,115 @@ VISIBLE_IF_KUNIT u16 apply_lut32_to_channel_value(const struct drm_color_lut32 *
}
EXPORT_SYMBOL_IF_KUNIT(apply_lut32_to_channel_value);
+/*
+ * Tetrahedral interpolation of one channel in a 3D LUT. The input value of
+ * each axis selects a cell of the LUT; the fractions pick one of the six
+ * tetrahedra the cell is split into, and the four corners of that
+ * tetrahedron are weighted.
+ */
+static u16 apply_3dlut_to_channel_value(const struct drm_color_lut32 *lut, u32 size,
+ enum lut_channel channel, u16 r, u16 g, u16 b)
+{
+ u32 max_index = size - 1;
+ u32 r_index, g_index, b_index;
+ u32 r_fraction, g_fraction, b_fraction;
+ const struct drm_color_lut32 *v000;
+ u64 position, sum;
+ u16 v000_c, v100_c, v010_c, v001_c;
+ u16 v110_c, v101_c, v011_c, v111_c;
+
+ position = (u64)r * max_index;
+ r_index = position / U16_MAX;
+ r_fraction = position - (u64)r_index * U16_MAX;
+
+ position = (u64)g * max_index;
+ g_index = position / U16_MAX;
+ g_fraction = position - (u64)g_index * U16_MAX;
+
+ position = (u64)b * max_index;
+ b_index = position / U16_MAX;
+ b_fraction = position - (u64)b_index * U16_MAX;
+
+ if (r_index >= max_index) {
+ r_index = max_index - 1;
+ r_fraction = U16_MAX;
+ }
+
+ if (g_index >= max_index) {
+ g_index = max_index - 1;
+ g_fraction = U16_MAX;
+ }
+
+ if (b_index >= max_index) {
+ b_index = max_index - 1;
+ b_fraction = U16_MAX;
+ }
+
+ v000 = &lut[r_index + size * (g_index + size * b_index)];
+
+ v000_c = lut32_channel_value(v000, channel);
+ v100_c = lut32_channel_value(v000 + 1, channel);
+ v010_c = lut32_channel_value(v000 + size, channel);
+ v001_c = lut32_channel_value(v000 + size * size, channel);
+ v110_c = lut32_channel_value(v000 + size + 1, channel);
+ v101_c = lut32_channel_value(v000 + size * size + 1, channel);
+ v011_c = lut32_channel_value(v000 + size * size + size, channel);
+ v111_c = lut32_channel_value(v000 + size * size + size + 1, channel);
+
+ if (r_fraction >= g_fraction) {
+ if (g_fraction >= b_fraction)
+ sum = (u64)v000_c * (U16_MAX - r_fraction) +
+ (u64)v100_c * (r_fraction - g_fraction) +
+ (u64)v110_c * (g_fraction - b_fraction) +
+ (u64)v111_c * b_fraction;
+ else if (r_fraction >= b_fraction)
+ sum = (u64)v000_c * (U16_MAX - r_fraction) +
+ (u64)v100_c * (r_fraction - b_fraction) +
+ (u64)v101_c * (b_fraction - g_fraction) +
+ (u64)v111_c * g_fraction;
+ else
+ sum = (u64)v000_c * (U16_MAX - b_fraction) +
+ (u64)v001_c * (b_fraction - r_fraction) +
+ (u64)v101_c * (r_fraction - g_fraction) +
+ (u64)v111_c * g_fraction;
+ } else {
+ if (r_fraction >= b_fraction)
+ sum = (u64)v000_c * (U16_MAX - g_fraction) +
+ (u64)v010_c * (g_fraction - r_fraction) +
+ (u64)v110_c * (r_fraction - b_fraction) +
+ (u64)v111_c * b_fraction;
+ else if (g_fraction >= b_fraction)
+ sum = (u64)v000_c * (U16_MAX - g_fraction) +
+ (u64)v010_c * (g_fraction - b_fraction) +
+ (u64)v011_c * (b_fraction - r_fraction) +
+ (u64)v111_c * r_fraction;
+ else
+ sum = (u64)v000_c * (U16_MAX - b_fraction) +
+ (u64)v001_c * (b_fraction - g_fraction) +
+ (u64)v011_c * (g_fraction - r_fraction) +
+ (u64)v111_c * r_fraction;
+ }
+
+ return (u16)min_t(u64, DIV_ROUND_CLOSEST_ULL(sum, U16_MAX), U16_MAX);
+}
+
+VISIBLE_IF_KUNIT void apply_3dlut_to_pixel(struct pixel_argb_s32 *pixel,
+ const struct drm_color_lut32 *lut,
+ u32 size)
+{
+ u16 r = clamp_val(pixel->r, 0, 0xffff);
+ u16 g = clamp_val(pixel->g, 0, 0xffff);
+ u16 b = clamp_val(pixel->b, 0, 0xffff);
+
+ if (size < 2)
+ return;
+
+ pixel->r = apply_3dlut_to_channel_value(lut, size, LUT_RED, r, g, b);
+ pixel->g = apply_3dlut_to_channel_value(lut, size, LUT_GREEN, r, g, b);
+ pixel->b = apply_3dlut_to_channel_value(lut, size, LUT_BLUE, r, g, b);
+}
+EXPORT_SYMBOL_IF_KUNIT(apply_3dlut_to_pixel);
+
static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buffer *output_buffer)
{
@@ -347,6 +456,20 @@ static void apply_1d_lut(struct pixel_argb_s32 *pixel,
clamp_val(pixel->b, 0, 0xffff), LUT_BLUE);
}
+static void apply_3d_lut(struct pixel_argb_s32 *pixel,
+ const struct vkms_colorop_state *state)
+{
+ const struct drm_colorop *colorop = state->colorop;
+ const struct drm_color_lut32 *lut;
+
+ if (!state->data)
+ return;
+
+ lut = state->data->data;
+
+ apply_3dlut_to_pixel(pixel, lut, colorop->size);
+}
+
static void apply_colorop(struct pixel_argb_s32 *pixel,
const struct vkms_colorop_state *state)
{
@@ -363,6 +486,9 @@ static void apply_colorop(struct pixel_argb_s32 *pixel,
case DRM_COLOROP_1D_LUT:
apply_1d_lut(pixel, state);
break;
+ case DRM_COLOROP_3D_LUT:
+ apply_3d_lut(pixel, state);
+ break;
case DRM_COLOROP_FIXED_MATRIX:
break;
default:
diff --git a/drivers/gpu/drm/vkms/vkms_composer.h b/drivers/gpu/drm/vkms/vkms_composer.h
index 6da85efc5524..28323df662a4 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.h
+++ b/drivers/gpu/drm/vkms/vkms_composer.h
@@ -24,6 +24,8 @@ u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_val
enum lut_channel channel);
u16 apply_lut32_to_channel_value(const struct drm_color_lut32 *lut, u32 lut_size,
u16 channel_value, enum lut_channel channel);
+void apply_3dlut_to_pixel(struct pixel_argb_s32 *pixel,
+ const struct drm_color_lut32 *lut, u32 size);
void apply_3x4_matrix(struct pixel_argb_s32 *pixel, const struct drm_color_ctm_3x4 *matrix);
#endif
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 05fba864cf36..d975cb684fd9 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -38,6 +38,8 @@
/* Entries in the 1D LUT colorop of a plane's color pipeline. */
#define VKMS_LUT1D_SIZE 256
+/* Entries per dimension in the 3D LUT colorop of a plane's color pipeline. */
+#define VKMS_LUT3D_SIZE 17
/**
* struct vkms_frame_info - Structure to store the state of a frame
*
--
2.56.1
next prev parent reply other threads:[~2026-11-28 17:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 17:15 [PATCH 0/7] drm/vkms: complete the plane color pipeline Oarora Etimis
2026-11-28 17:15 ` [PATCH 1/7] drm/vkms: add the colorops of a plane that is being enabled Oarora Etimis
2026-11-28 17:15 ` [PATCH 2/7] drm/vkms: free the colorop whose initialization failed Oarora Etimis
2026-11-28 17:15 ` [PATCH 3/7] drm/vkms: use the colorop states of the state being composed Oarora Etimis
2026-11-28 17:15 ` [PATCH 4/7] drm/vkms: add a programmable 1D LUT colorop Oarora Etimis
2026-11-28 17:15 ` Oarora Etimis [this message]
2026-11-28 17:15 ` [PATCH 6/7] drm/vkms: add a multiplier colorop Oarora Etimis
2026-11-28 17:15 ` [PATCH 7/7] drm/vkms: add KUnit coverage for the 3D LUT and multiplier colorops Oarora Etimis
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=20261128-colorop-v1-5-dd79919f822b@gmail.com \
--to=oaroraetimis@gmail.com \
--cc=airlied@gmail.com \
--cc=alex.hung@amd.com \
--cc=contact@emersion.fr \
--cc=daniels@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=harry.wentland@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=louis.chauvet@bootlin.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=melissa.srw@gmail.com \
--cc=mripard@kernel.org \
--cc=robert.mader@collabora.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®