* [PATCH 0/7] drm/vkms: complete the plane color pipeline
@ 2026-11-28 17:15 Oarora Etimis
2026-11-28 17:15 ` [PATCH 1/7] drm/vkms: add the colorops of a plane that is being enabled Oarora Etimis
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Oarora Etimis @ 2026-11-28 17:15 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Alex Hung, Robert Mader, Harry Wentland, Simon Ser,
Daniel Stone
Cc: dri-devel, linux-kernel
The vkms plane pipeline has a fixed matrix, two 1D curves and two 3x4
matrices. Userspace cannot supply its own LUT, do a 3D lookup, or apply
a gain to the channels.
Patches 1 to 3 fix three bugs in the pipeline plumbing. Patches 4 to 6
add a 1D LUT, a 3D LUT and a multiplier. Patch 7 adds KUnit coverage for
the 3D LUT and the multiplier; the 1D LUT gets its coverage in patch 4.
The color math has KUnit coverage; there is no IGT test for the color
pipeline yet, so the uAPI paths are not exercised end-to-end.
The three new colorops are appended after the existing ones; their order
is unchanged.
---
Oarora Etimis (7):
drm/vkms: add the colorops of a plane that is being enabled
drm/vkms: free the colorop whose initialization failed
drm/vkms: use the colorop states of the state being composed
drm/vkms: add a programmable 1D LUT colorop
drm/vkms: add a 3D LUT colorop
drm/vkms: add a multiplier colorop
drm/vkms: add KUnit coverage for the 3D LUT and multiplier colorops
drivers/gpu/drm/vkms/tests/vkms_color_test.c | 194 +++++++++++++++++
drivers/gpu/drm/vkms/vkms_colorop.c | 61 +++++-
drivers/gpu/drm/vkms/vkms_composer.c | 314 +++++++++++++++++++++++----
drivers/gpu/drm/vkms/vkms_composer.h | 5 +
drivers/gpu/drm/vkms/vkms_crtc.c | 59 ++++-
drivers/gpu/drm/vkms/vkms_drv.h | 61 ++++++
drivers/gpu/drm/vkms/vkms_plane.c | 2 +
7 files changed, 646 insertions(+), 50 deletions(-)
---
base-commit: 5ce32a0c94a827ff44ee60898c28060714dcff75
change-id: 20261113-colorop-693f016a156d
Best regards,
--
Oarora Etimis <oaroraetimis@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/7] drm/vkms: add the colorops of a plane that is being enabled
2026-11-28 17:15 [PATCH 0/7] drm/vkms: complete the plane color pipeline Oarora Etimis
@ 2026-11-28 17:15 ` Oarora Etimis
2026-11-28 17:15 ` [PATCH 2/7] drm/vkms: free the colorop whose initialization failed Oarora Etimis
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Oarora Etimis @ 2026-11-28 17:15 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Alex Hung, Robert Mader, Harry Wentland, Simon Ser,
Daniel Stone
Cc: dri-devel, linux-kernel
drm_atomic_add_affected_planes() walks the plane mask of the old CRTC
state, so a plane that is being enabled is not in that mask and its
colorops are left out of the commit. Its first frame then sees the
pipeline as bypassed, and a YUV plane is composed without the YUV-to-RGB
conversion.
Add them explicitly in vkms_crtc_atomic_check().
Fixes: 589179b18224 ("drm/vkms: Add atomic check and matrix handling for fixed matrix colorop")
Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
drivers/gpu/drm/vkms/vkms_crtc.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 019d7bc90cdc..7d18178d5320 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -129,6 +129,22 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
if (ret < 0)
return ret;
+ /*
+ * drm_atomic_add_affected_planes() only walks the plane mask of the
+ * old CRTC state. A plane that is being enabled is not in that mask,
+ * so its colorops would be missing from this commit.
+ */
+ drm_for_each_plane_mask(plane, crtc->dev, crtc_state->plane_mask) {
+ plane_state = drm_atomic_get_new_plane_state(crtc_state->state, plane);
+
+ if (!plane_state || !plane_state->color_pipeline)
+ continue;
+
+ ret = drm_atomic_add_affected_colorops(crtc_state->state, plane);
+ if (ret < 0)
+ return ret;
+ }
+
drm_for_each_plane_mask(plane, crtc->dev, crtc_state->plane_mask) {
plane_state = drm_atomic_get_new_plane_state(crtc_state->state, plane);
WARN_ON(!plane_state);
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/7] drm/vkms: free the colorop whose initialization failed
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 ` Oarora Etimis
2026-11-28 17:15 ` [PATCH 3/7] drm/vkms: use the colorop states of the state being composed Oarora Etimis
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Oarora Etimis @ 2026-11-28 17:15 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Alex Hung, Robert Mader, Harry Wentland, Simon Ser,
Daniel Stone
Cc: dri-devel, linux-kernel
The error path of vkms_initialize_color_pipeline() walks ops[0..i-1],
but ops[i] is already allocated when its drm_plane_colorop_*_init()
call fails, so it leaks.
Include it in the walk.
Fixes: c1e578bd08da ("drm/vkms: Add enumerated 1D curve colorop")
Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
drivers/gpu/drm/vkms/vkms_colorop.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c
index 9424b1994239..ed557a1c6a05 100644
--- a/drivers/gpu/drm/vkms/vkms_colorop.c
+++ b/drivers/gpu/drm/vkms/vkms_colorop.c
@@ -126,7 +126,7 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr
return 0;
cleanup:
- for (j = 0; j < i; j++) {
+ for (j = 0; j <= i && j < ARRAY_SIZE(ops); j++) {
if (ops[j]) {
drm_colorop_cleanup(ops[j]);
kfree(ops[j]);
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/7] drm/vkms: use the colorop states of the state being composed
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 ` Oarora Etimis
2026-11-28 17:15 ` [PATCH 4/7] drm/vkms: add a programmable 1D LUT colorop Oarora Etimis
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Oarora Etimis @ 2026-11-28 17:15 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Alex Hung, Robert Mader, Harry Wentland, Simon Ser,
Daniel Stone
Cc: dri-devel, linux-kernel
The composer runs asynchronously and reads drm_colorop::state, which a
later commit can replace and free. If that commit writes a value the
colorop already has, core leaves the plane and its CRTC out, so nothing
flushes the composer first and the worker is left holding a pointer to
the freed state.
Record the values the composer needs in vkms_plane_state from
atomic_flush(), together with a reference of the LUT blob, and read only
that copy.
Fixes: c1e578bd08da ("drm/vkms: Add enumerated 1D curve colorop")
Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
drivers/gpu/drm/vkms/vkms_colorop.c | 4 +-
drivers/gpu/drm/vkms/vkms_composer.c | 92 +++++++++++++++++++-----------------
drivers/gpu/drm/vkms/vkms_crtc.c | 43 ++++++++++++++++-
drivers/gpu/drm/vkms/vkms_drv.h | 56 ++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_plane.c | 2 +
5 files changed, 149 insertions(+), 48 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c
index ed557a1c6a05..01b1ed2a5991 100644
--- a/drivers/gpu/drm/vkms/vkms_colorop.c
+++ b/drivers/gpu/drm/vkms/vkms_colorop.c
@@ -24,11 +24,9 @@ static const struct drm_colorop_funcs vkms_colorop_funcs = {
.destroy = drm_colorop_destroy,
};
-#define MAX_COLOR_PIPELINE_OPS 5
-
static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_prop_enum_list *list)
{
- struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS];
+ struct drm_colorop *ops[VKMS_MAX_COLOROPS];
struct drm_device *dev = plane->dev;
int ret;
int i = 0, j = 0;
diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
index 7a6a7875520c..2cd909bc8adc 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -247,39 +247,48 @@ VISIBLE_IF_KUNIT void apply_3x4_matrix(struct pixel_argb_s32 *pixel,
}
EXPORT_SYMBOL_IF_KUNIT(apply_3x4_matrix);
-static void apply_colorop(struct pixel_argb_s32 *pixel, struct drm_colorop *colorop)
+static void apply_1d_curve(struct pixel_argb_s32 *pixel,
+ const struct vkms_colorop_state *state)
{
- struct drm_colorop_state *colorop_state = colorop->state;
- struct drm_device *dev = colorop->dev;
-
- if (colorop->type == DRM_COLOROP_1D_CURVE) {
- switch (colorop_state->curve_1d_type) {
- case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF:
- pixel->r = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->r, LUT_RED);
- pixel->g = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->g, LUT_GREEN);
- pixel->b = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->b, LUT_BLUE);
- break;
- case DRM_COLOROP_1D_CURVE_SRGB_EOTF:
- pixel->r = apply_lut_to_channel_value(&srgb_eotf, pixel->r, LUT_RED);
- pixel->g = apply_lut_to_channel_value(&srgb_eotf, pixel->g, LUT_GREEN);
- pixel->b = apply_lut_to_channel_value(&srgb_eotf, pixel->b, LUT_BLUE);
- break;
- default:
- drm_WARN_ONCE(dev, true,
- "unknown colorop 1D curve type %d\n",
- colorop_state->curve_1d_type);
- break;
- }
- } else if (colorop->type == DRM_COLOROP_CTM_3X4) {
- if (colorop_state->data)
- apply_3x4_matrix(pixel,
- (struct drm_color_ctm_3x4 *)colorop_state->data->data);
- } else if (colorop->type == DRM_COLOROP_FIXED_MATRIX) {
- /*
- * Fixed Matrix is a no-op here. YUV-to-RGB conversion
- * is handled at format read time via the
- * conversion_matrix set in vkms_plane_atomic_update().
- */
+ struct drm_device *dev = state->colorop->dev;
+
+ switch (state->curve_1d_type) {
+ case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF:
+ pixel->r = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->r, LUT_RED);
+ pixel->g = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->g, LUT_GREEN);
+ pixel->b = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->b, LUT_BLUE);
+ break;
+ case DRM_COLOROP_1D_CURVE_SRGB_EOTF:
+ pixel->r = apply_lut_to_channel_value(&srgb_eotf, pixel->r, LUT_RED);
+ pixel->g = apply_lut_to_channel_value(&srgb_eotf, pixel->g, LUT_GREEN);
+ pixel->b = apply_lut_to_channel_value(&srgb_eotf, pixel->b, LUT_BLUE);
+ break;
+ default:
+ drm_WARN_ONCE(dev, true, "unknown colorop 1D curve type %d\n",
+ state->curve_1d_type);
+ break;
+ }
+}
+
+static void apply_colorop(struct pixel_argb_s32 *pixel,
+ const struct vkms_colorop_state *state)
+{
+ const struct drm_colorop *colorop = state->colorop;
+
+ switch (colorop->type) {
+ case DRM_COLOROP_1D_CURVE:
+ apply_1d_curve(pixel, state);
+ break;
+ case DRM_COLOROP_CTM_3X4:
+ if (state->data)
+ apply_3x4_matrix(pixel, (struct drm_color_ctm_3x4 *)state->data->data);
+ break;
+ case DRM_COLOROP_FIXED_MATRIX:
+ break;
+ default:
+ drm_WARN_ONCE(colorop->dev, true, "unknown colorop type %d\n",
+ colorop->type);
+ break;
}
}
@@ -289,8 +298,6 @@ static void pre_blend_color_transform(const struct vkms_plane_state *plane_state
struct pixel_argb_s32 pixel;
for (size_t x = 0; x < output_buffer->n_pixels; x++) {
- struct drm_colorop *colorop = plane_state->base.base.color_pipeline;
-
/*
* Some operations, such as applying a BT709 encoding matrix,
* followed by a decoding matrix, require that we preserve
@@ -306,18 +313,15 @@ static void pre_blend_color_transform(const struct vkms_plane_state *plane_state
pixel.g = output_buffer->pixels[x].g;
pixel.b = output_buffer->pixels[x].b;
- while (colorop) {
- struct drm_colorop_state *colorop_state;
-
- colorop_state = colorop->state;
-
- if (!colorop_state)
- return;
+ for (size_t i = 0; i < ARRAY_SIZE(plane_state->colorop_states); i++) {
+ const struct vkms_colorop_state *state;
- if (!colorop_state->bypass)
- apply_colorop(&pixel, colorop);
+ state = &plane_state->colorop_states[i];
+ if (!state->colorop)
+ break;
- colorop = colorop->next;
+ if (!state->bypass)
+ apply_colorop(&pixel, state);
}
/* clamp values */
diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 7d18178d5320..e7ea487187bc 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -5,6 +5,7 @@
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_blend.h>
+#include <drm/drm_colorop.h>
#include <drm/drm_managed.h>
#include <drm/drm_print.h>
#include <drm/drm_probe_helper.h>
@@ -186,11 +187,43 @@ static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
spin_lock_irq(&vkms_output->lock);
}
+static void vkms_plane_colorops_update(struct vkms_plane_state *plane_state,
+ struct drm_atomic_commit *commit)
+{
+ struct drm_colorop *colorop;
+ size_t slot = 0;
+
+ /*
+ * The plane state is freshly allocated for this commit, so its
+ * colorop_states array is zero and holds nothing to release.
+ */
+ for (colorop = plane_state->base.base.color_pipeline;
+ colorop && slot < ARRAY_SIZE(plane_state->colorop_states);
+ colorop = colorop->next) {
+ struct drm_colorop_state *colorop_state;
+ struct vkms_colorop_state *state;
+
+ colorop_state = drm_atomic_get_new_colorop_state(commit, colorop);
+ if (!colorop_state)
+ break;
+
+ state = &plane_state->colorop_states[slot++];
+ state->colorop = colorop;
+ state->bypass = colorop_state->bypass;
+ state->curve_1d_type = colorop_state->curve_1d_type;
+ state->multiplier = colorop_state->multiplier;
+
+ if (colorop_state->data)
+ state->data = drm_property_blob_get(colorop_state->data);
+ }
+}
+
static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
struct drm_atomic_commit *state)
__releases(&vkms_output->lock)
{
struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+ struct vkms_crtc_state *crtc_state = to_vkms_crtc_state(crtc->state);
if (crtc->state->event) {
spin_lock(&crtc->dev->event_lock);
@@ -205,7 +238,15 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
crtc->state->event = NULL;
}
- vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
+ /*
+ * Capture the color operations of this commit: drm_colorop::state is
+ * the current value of the colorop, not the one this frame was built
+ * from, and the composer runs asynchronously, so it must not read it.
+ */
+ for (size_t i = 0; i < crtc_state->num_active_planes; i++)
+ vkms_plane_colorops_update(crtc_state->active_planes[i], state);
+
+ vkms_output->composer_state = crtc_state;
spin_unlock_irq(&vkms_output->lock);
}
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index b7eb7033fb4b..1c5205aa6e0c 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -6,6 +6,7 @@
#include <linux/hrtimer.h>
#include <drm/drm.h>
+#include <drm/drm_colorop.h>
#include <drm/drm_framebuffer.h>
#include <drm/drm_gem.h>
#include <drm/drm_gem_atomic_helper.h>
@@ -25,6 +26,13 @@
#define NUM_OVERLAY_PLANES 8
+/*
+ * Number of color operations in a plane's color pipeline. Must match the
+ * number of colorops that vkms_initialize_color_pipeline() creates, with
+ * room for the ones that follow.
+ */
+#define VKMS_MAX_COLOROPS 10
+
#define VKMS_GAMMA_LUT_SIZE 256
/**
@@ -139,6 +147,44 @@ struct conversion_matrix {
int y_offset;
};
+/**
+ * struct vkms_colorop_state - colorop state recorded at commit time
+ * @colorop: the color operation these states belong to
+ * @data: LUT blob, with a reference held by this state
+ * @multiplier: gain of a DRM_COLOROP_MULTIPLIER
+ * @curve_1d_type: curve of a DRM_COLOROP_1D_CURVE
+ * @bypass: whether the operation is bypassed
+ *
+ * The composer must not read drm_colorop::state: that is the current value
+ * of the colorop, not the one the frame is built from, and the worker runs
+ * asynchronously. Writing the value a colorop property already has does not
+ * count as a change, so core leaves the plane out of that commit and the
+ * replaced state can be freed while a published frame still refers to it.
+ * Copy the states the composer needs instead.
+ */
+struct vkms_colorop_state {
+ const struct drm_colorop *colorop;
+ struct drm_property_blob *data;
+ u64 multiplier;
+ enum drm_colorop_curve_1d_type curve_1d_type;
+ bool bypass;
+};
+
+/**
+ * vkms_colorop_state_release - drop what a state holds
+ * @state: the state to clear
+ *
+ * The blob reference is the only thing a state owns. Clearing a state
+ * without dropping it leaks that reference, so every place that discards
+ * one goes through here.
+ */
+static inline void
+vkms_colorop_state_release(struct vkms_colorop_state *state)
+{
+ drm_property_blob_put(state->data);
+ memset(state, 0, sizeof(*state));
+}
+
/**
* struct vkms_plane_state - Driver specific plane state
* @base: base plane state
@@ -146,14 +192,24 @@ struct conversion_matrix {
* @pixel_read_line: function to read a pixel line in this plane. The creator of a
* struct vkms_plane_state must ensure that this pointer is valid
* @conversion_matrix: matrix used for yuv formats to convert to rgb
+ * @colorop_states: the color operations of this plane's pipeline, with the state
+ * the composer needs, recorded when this state was committed
*/
struct vkms_plane_state {
struct drm_shadow_plane_state base;
struct vkms_frame_info frame_info;
pixel_read_line_t pixel_read_line;
struct conversion_matrix conversion_matrix;
+ struct vkms_colorop_state colorop_states[VKMS_MAX_COLOROPS];
};
+static inline void
+vkms_plane_colorops_release(struct vkms_plane_state *plane_state)
+{
+ for (size_t i = 0; i < ARRAY_SIZE(plane_state->colorop_states); i++)
+ vkms_colorop_state_release(&plane_state->colorop_states[i]);
+}
+
struct vkms_plane {
struct drm_plane base;
};
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
index fd3d34dcf0fe..b05475b0f5d4 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -79,6 +79,8 @@ static void vkms_plane_destroy_state(struct drm_plane *plane,
drm_framebuffer_put(vkms_state->frame_info.fb);
}
+ vkms_plane_colorops_release(vkms_state);
+
__drm_gem_destroy_shadow_plane_state(&vkms_state->base);
kfree(vkms_state);
}
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/7] drm/vkms: add a programmable 1D LUT colorop
2026-11-28 17:15 [PATCH 0/7] drm/vkms: complete the plane color pipeline Oarora Etimis
` (2 preceding siblings ...)
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 ` Oarora Etimis
2026-11-28 17:15 ` [PATCH 5/7] drm/vkms: add a 3D " Oarora Etimis
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Oarora Etimis @ 2026-11-28 17:15 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Alex Hung, Robert Mader, Harry Wentland, Simon Ser,
Daniel Stone
Cc: dri-devel, linux-kernel
The two curve stages apply a curve built into the driver, so userspace
can pick one but cannot supply a table.
Add a 1D LUT colorop with 256 entries and linear interpolation, and look
the entries up in the composer from the blob it carries. The values are
U0.32 and are scaled to the 16-bit range the composer works in.
Add KUnit coverage for the interpolation, including a table that
decreases.
The existing colorops and their order are unchanged.
Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
drivers/gpu/drm/vkms/tests/vkms_color_test.c | 89 ++++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_colorop.c | 19 ++++++
drivers/gpu/drm/vkms/vkms_composer.c | 80 +++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_composer.h | 2 +
drivers/gpu/drm/vkms/vkms_drv.h | 3 +
5 files changed, 193 insertions(+)
diff --git a/drivers/gpu/drm/vkms/tests/vkms_color_test.c b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
index c3c61037cb71..0d68de6462d9 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_color_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
@@ -120,6 +120,91 @@ static void vkms_color_test_linear(struct kunit *test)
}
}
+/*
+ * A two-entry LUT that maps 0 to 0 and 1.0 to 1.0 is the identity, so every
+ * input has to come back unchanged, including the ones between the entries.
+ */
+static const struct drm_color_lut32 test_lut32_identity[] = {
+ { 0x00000000, 0x00000000, 0x00000000, 0 },
+ { 0xffffffff, 0xffffffff, 0xffffffff, 0 },
+};
+
+static void vkms_color_test_lut32_identity(struct kunit *test)
+{
+ static const u16 inputs[] = { 0x0000, 0x4000, 0x8000, 0xc000, 0xffff };
+
+ for (size_t i = 0; i < ARRAY_SIZE(inputs); i++)
+ KUNIT_EXPECT_EQ(test, inputs[i],
+ apply_lut32_to_channel_value(test_lut32_identity,
+ ARRAY_SIZE(test_lut32_identity),
+ inputs[i], LUT_RED));
+}
+
+/*
+ * Three entries at 0, 0.5 and 1.0. The values tested here fall exactly on
+ * the entries or halfway between two of them, so the expected output is
+ * exact.
+ */
+static const struct drm_color_lut32 test_lut32_three_points[] = {
+ { 0x00000000, 0x00000000, 0x00000000, 0 },
+ { 0x80000000, 0x80000000, 0x80000000, 0 },
+ { 0xffffffff, 0xffffffff, 0xffffffff, 0 },
+};
+
+static void vkms_color_test_lut32_three_points(struct kunit *test)
+{
+ static const struct {
+ u16 input;
+ u16 expected;
+ } cases[] = {
+ { 0x0000, 0x0000 },
+ { 0x4000, 0x4000 },
+ { 0x8000, 0x8000 },
+ { 0xc000, 0xc000 },
+ { 0xffff, 0xffff },
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(cases); i++)
+ KUNIT_EXPECT_EQ(test, cases[i].expected,
+ apply_lut32_to_channel_value(test_lut32_three_points,
+ ARRAY_SIZE(test_lut32_three_points),
+ cases[i].input, LUT_RED));
+}
+
+/* A single-entry LUT returns that entry for every input. */
+static const struct drm_color_lut32 test_lut32_single[] = {
+ { 0x12345678, 0x12345678, 0x12345678, 0 },
+};
+
+/* A decreasing table must round the same way an increasing one does. */
+static const struct drm_color_lut32 test_lut32_descending[] = {
+ { 0xffffffff, 0xffffffff, 0xffffffff, 0 },
+ { 0x00000000, 0x00000000, 0x00000000, 0 },
+};
+
+static void vkms_color_test_lut32_descending(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, 0xffff,
+ apply_lut32_to_channel_value(test_lut32_descending, 2,
+ 0x0000, LUT_RED));
+ KUNIT_EXPECT_EQ(test, 0x7fff,
+ apply_lut32_to_channel_value(test_lut32_descending, 2,
+ 0x8000, LUT_RED));
+ KUNIT_EXPECT_EQ(test, 0x0000,
+ apply_lut32_to_channel_value(test_lut32_descending, 2,
+ 0xffff, LUT_RED));
+}
+
+static void vkms_color_test_lut32_single_entry(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, 0x1234,
+ apply_lut32_to_channel_value(test_lut32_single, 1,
+ 0x0000, LUT_RED));
+ KUNIT_EXPECT_EQ(test, 0x1234,
+ apply_lut32_to_channel_value(test_lut32_single, 1,
+ 0xffff, LUT_RED));
+}
+
static void vkms_color_srgb_inv_srgb(struct kunit *test)
{
u16 srgb, final;
@@ -385,6 +470,10 @@ static struct kunit_case vkms_color_test_cases[] = {
KUNIT_CASE(vkms_color_test_get_uniform_lut_index),
KUNIT_CASE(vkms_color_test_lerp),
KUNIT_CASE(vkms_color_test_linear),
+ KUNIT_CASE(vkms_color_test_lut32_identity),
+ KUNIT_CASE(vkms_color_test_lut32_three_points),
+ KUNIT_CASE(vkms_color_test_lut32_single_entry),
+ KUNIT_CASE(vkms_color_test_lut32_descending),
KUNIT_CASE(vkms_color_srgb_inv_srgb),
KUNIT_CASE(vkms_color_ctm_3x4_50_desat),
KUNIT_CASE(vkms_color_ctm_3x4_bt709),
diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c
index 01b1ed2a5991..584305b0abfd 100644
--- a/drivers/gpu/drm/vkms/vkms_colorop.c
+++ b/drivers/gpu/drm/vkms/vkms_colorop.c
@@ -119,6 +119,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++;
+
+ /* 6th op: 1D 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_curve_1d_lut_init(dev, ops[i], plane, &vkms_colorop_funcs,
+ VKMS_LUT1D_SIZE,
+ DRM_COLOROP_LUT1D_INTERPOLATION_LINEAR,
+ 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 2cd909bc8adc..e00d1d0b2f2d 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -1,10 +1,13 @@
// SPDX-License-Identifier: GPL-2.0+
+#include <linux/bits.h>
#include <linux/crc32.h>
+#include <linux/limits.h>
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_blend.h>
+#include <drm/drm_color_mgmt.h>
#include <drm/drm_colorop.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_fixed.h>
@@ -198,6 +201,61 @@ VISIBLE_IF_KUNIT u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut
}
EXPORT_SYMBOL_IF_KUNIT(apply_lut_to_channel_value);
+static u16 lut32_channel_value(const struct drm_color_lut32 *entry,
+ enum lut_channel channel)
+{
+ switch (channel) {
+ case LUT_RED:
+ return drm_color_lut32_extract(entry->red, BITS_PER_TYPE(u16));
+ case LUT_GREEN:
+ return drm_color_lut32_extract(entry->green, BITS_PER_TYPE(u16));
+ case LUT_BLUE:
+ return drm_color_lut32_extract(entry->blue, BITS_PER_TYPE(u16));
+ case LUT_RESERVED:
+ break;
+ }
+
+ return 0;
+}
+
+/*
+ * Apply a uniformly spaced 1D LUT to one channel, interpolating linearly
+ * between the two entries around the input value.
+ */
+VISIBLE_IF_KUNIT u16 apply_lut32_to_channel_value(const struct drm_color_lut32 *lut,
+ u32 lut_size, u16 channel_value,
+ enum lut_channel channel)
+{
+ u64 position;
+ u32 index, fraction;
+ s64 delta, result;
+ u16 floor_value, ceil_value;
+
+ if (!lut_size)
+ return channel_value;
+
+ if (lut_size == 1)
+ return lut32_channel_value(&lut[0], channel);
+
+ position = (u64)channel_value * (lut_size - 1);
+ index = position / U16_MAX;
+
+ if (index >= lut_size - 1)
+ return lut32_channel_value(&lut[lut_size - 1], channel);
+
+ fraction = position - (u64)index * U16_MAX;
+
+ floor_value = lut32_channel_value(&lut[index], channel);
+ ceil_value = lut32_channel_value(&lut[index + 1], channel);
+
+ delta = (s64)ceil_value - (s64)floor_value;
+ result = (s64)floor_value +
+ DIV_ROUND_CLOSEST(delta * fraction, (s64)U16_MAX);
+
+ return (u16)clamp(result, 0LL, (s64)U16_MAX);
+}
+EXPORT_SYMBOL_IF_KUNIT(apply_lut32_to_channel_value);
+
static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buffer *output_buffer)
{
@@ -270,6 +328,25 @@ static void apply_1d_curve(struct pixel_argb_s32 *pixel,
}
}
+static void apply_1d_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;
+
+ pixel->r = apply_lut32_to_channel_value(lut, colorop->size,
+ clamp_val(pixel->r, 0, 0xffff), LUT_RED);
+ pixel->g = apply_lut32_to_channel_value(lut, colorop->size,
+ clamp_val(pixel->g, 0, 0xffff), LUT_GREEN);
+ pixel->b = apply_lut32_to_channel_value(lut, colorop->size,
+ clamp_val(pixel->b, 0, 0xffff), LUT_BLUE);
+}
+
static void apply_colorop(struct pixel_argb_s32 *pixel,
const struct vkms_colorop_state *state)
{
@@ -283,6 +360,9 @@ static void apply_colorop(struct pixel_argb_s32 *pixel,
if (state->data)
apply_3x4_matrix(pixel, (struct drm_color_ctm_3x4 *)state->data->data);
break;
+ case DRM_COLOROP_1D_LUT:
+ apply_1d_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 fa003af12f85..6da85efc5524 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.h
+++ b/drivers/gpu/drm/vkms/vkms_composer.h
@@ -22,6 +22,8 @@ u16 lerp_u16(u16 a, u16 b, s64 t);
s64 get_uniform_lut_index(const struct vkms_color_lut *lut, u16 channel_value);
u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value,
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_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 1c5205aa6e0c..05fba864cf36 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -35,6 +35,9 @@
#define VKMS_GAMMA_LUT_SIZE 256
+/* Entries in the 1D LUT colorop of a plane's color pipeline. */
+#define VKMS_LUT1D_SIZE 256
+
/**
* struct vkms_frame_info - Structure to store the state of a frame
*
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/7] drm/vkms: add a 3D LUT colorop
2026-11-28 17:15 [PATCH 0/7] drm/vkms: complete the plane color pipeline Oarora Etimis
` (3 preceding siblings ...)
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
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
6 siblings, 0 replies; 8+ messages in thread
From: Oarora Etimis @ 2026-11-28 17:15 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Alex Hung, Robert Mader, Harry Wentland, Simon Ser,
Daniel Stone
Cc: dri-devel, linux-kernel
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 6/7] drm/vkms: add a multiplier colorop
2026-11-28 17:15 [PATCH 0/7] drm/vkms: complete the plane color pipeline Oarora Etimis
` (4 preceding siblings ...)
2026-11-28 17:15 ` [PATCH 5/7] drm/vkms: add a 3D " Oarora Etimis
@ 2026-11-28 17:15 ` Oarora Etimis
2026-11-28 17:15 ` [PATCH 7/7] drm/vkms: add KUnit coverage for the 3D LUT and multiplier colorops Oarora Etimis
6 siblings, 0 replies; 8+ messages in thread
From: Oarora Etimis @ 2026-11-28 17:15 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Alex Hung, Robert Mader, Harry Wentland, Simon Ser,
Daniel Stone
Cc: dri-devel, linux-kernel
Add a multiplier colorop that scales the channels by an S31.32 gain. The
value is sign-magnitude like the 3x4 matrix, so it goes through
drm_sm2fixp() first.
Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
drivers/gpu/drm/vkms/vkms_colorop.c | 17 +++++++++++++++++
drivers/gpu/drm/vkms/vkms_composer.c | 14 ++++++++++++++
drivers/gpu/drm/vkms/vkms_composer.h | 1 +
3 files changed, 32 insertions(+)
diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c
index cceb9acca0da..1e1e470be4dd 100644
--- a/drivers/gpu/drm/vkms/vkms_colorop.c
+++ b/drivers/gpu/drm/vkms/vkms_colorop.c
@@ -157,6 +157,23 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr
drm_colorop_set_next_property(ops[i - 1], ops[i]);
+ i++;
+
+ /* 8th op: multiplier */
+ 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_mult_init(dev, ops[i], plane, &vkms_colorop_funcs,
+ 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 51ac2ae75cf0..b94c51264c64 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -365,6 +365,17 @@ VISIBLE_IF_KUNIT void apply_3dlut_to_pixel(struct pixel_argb_s32 *pixel,
}
EXPORT_SYMBOL_IF_KUNIT(apply_3dlut_to_pixel);
+VISIBLE_IF_KUNIT void apply_multiplier_to_pixel(struct pixel_argb_s32 *pixel,
+ u64 multiplier)
+{
+ s64 gain = drm_sm2fixp(multiplier);
+
+ pixel->r = drm_fixp2int_round(drm_fixp_mul(drm_int2fixp(pixel->r), gain));
+ pixel->g = drm_fixp2int_round(drm_fixp_mul(drm_int2fixp(pixel->g), gain));
+ pixel->b = drm_fixp2int_round(drm_fixp_mul(drm_int2fixp(pixel->b), gain));
+}
+EXPORT_SYMBOL_IF_KUNIT(apply_multiplier_to_pixel);
+
static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buffer *output_buffer)
{
@@ -489,6 +500,9 @@ static void apply_colorop(struct pixel_argb_s32 *pixel,
case DRM_COLOROP_3D_LUT:
apply_3d_lut(pixel, state);
break;
+ case DRM_COLOROP_MULTIPLIER:
+ apply_multiplier_to_pixel(pixel, state->multiplier);
+ 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 28323df662a4..5546ee864504 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.h
+++ b/drivers/gpu/drm/vkms/vkms_composer.h
@@ -26,6 +26,7 @@ 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_multiplier_to_pixel(struct pixel_argb_s32 *pixel, u64 multiplier);
void apply_3x4_matrix(struct pixel_argb_s32 *pixel, const struct drm_color_ctm_3x4 *matrix);
#endif
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 7/7] drm/vkms: add KUnit coverage for the 3D LUT and multiplier colorops
2026-11-28 17:15 [PATCH 0/7] drm/vkms: complete the plane color pipeline Oarora Etimis
` (5 preceding siblings ...)
2026-11-28 17:15 ` [PATCH 6/7] drm/vkms: add a multiplier colorop Oarora Etimis
@ 2026-11-28 17:15 ` Oarora Etimis
6 siblings, 0 replies; 8+ messages in thread
From: Oarora Etimis @ 2026-11-28 17:15 UTC (permalink / raw)
To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Alex Hung, Robert Mader, Harry Wentland, Simon Ser,
Daniel Stone
Cc: dri-devel, linux-kernel
The 3D LUT test uses a 2x2x2 identity LUT with inputs that reach all six
tetrahedra, and checks that values outside [0, 1] saturate. The
multiplier test covers gains of 1.0, 0.5, 2.0 and -0.5.
Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
drivers/gpu/drm/vkms/tests/vkms_color_test.c | 105 +++++++++++++++++++++++++++
1 file changed, 105 insertions(+)
diff --git a/drivers/gpu/drm/vkms/tests/vkms_color_test.c b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
index 0d68de6462d9..15f71a977ed9 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_color_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
@@ -205,6 +205,108 @@ static void vkms_color_test_lut32_single_entry(struct kunit *test)
0xffff, LUT_RED));
}
+/*
+ * A 2x2x2 identity LUT: every corner maps the axis index to the same
+ * value, so any input has to come back unchanged. The entries are ordered
+ * with red as the fastest moving index, as the uapi documents.
+ */
+static const struct drm_color_lut32 test_lut3d_identity[] = {
+ { 0x00000000, 0x00000000, 0x00000000, 0 },
+ { 0xffffffff, 0x00000000, 0x00000000, 0 },
+ { 0x00000000, 0xffffffff, 0x00000000, 0 },
+ { 0xffffffff, 0xffffffff, 0x00000000, 0 },
+ { 0x00000000, 0x00000000, 0xffffffff, 0 },
+ { 0xffffffff, 0x00000000, 0xffffffff, 0 },
+ { 0x00000000, 0xffffffff, 0xffffffff, 0 },
+ { 0xffffffff, 0xffffffff, 0xffffffff, 0 },
+};
+
+static void vkms_color_test_lut3d_identity(struct kunit *test)
+{
+ static const struct {
+ u16 r, g, b;
+ } cases[] = {
+ { 0x0000, 0x0000, 0x0000 },
+ { 0xffff, 0xffff, 0xffff },
+ { 0x8000, 0x8000, 0x8000 },
+ { 0xffff, 0x0000, 0x0000 },
+ { 0x0000, 0xffff, 0x0000 },
+ { 0x0000, 0x0000, 0xffff },
+ { 0x8000, 0x4000, 0x1000 },
+ /* One input per tetrahedron the lists above do not reach. */
+ { 0x9000, 0x1000, 0x5000 },
+ { 0x5000, 0x1000, 0x9000 },
+ { 0x1000, 0x9000, 0x5000 },
+ { 0x1000, 0x5000, 0x9000 },
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
+ struct pixel_argb_s32 pixel = {
+ .r = cases[i].r,
+ .g = cases[i].g,
+ .b = cases[i].b,
+ .a = 0xffff,
+ };
+
+ apply_3dlut_to_pixel(&pixel, test_lut3d_identity, 2);
+
+ KUNIT_EXPECT_EQ(test, cases[i].r, pixel.r);
+ KUNIT_EXPECT_EQ(test, cases[i].g, pixel.g);
+ KUNIT_EXPECT_EQ(test, cases[i].b, pixel.b);
+ KUNIT_EXPECT_EQ(test, 0xffff, pixel.a);
+ }
+}
+
+/* A value outside [0, 1] saturates at the LUT input instead of wrapping. */
+static void vkms_color_test_lut3d_clamp(struct kunit *test)
+{
+ struct pixel_argb_s32 pixel = {
+ .r = -1,
+ .g = 0x10000,
+ .b = 0xffff,
+ .a = 0xffff,
+ };
+
+ apply_3dlut_to_pixel(&pixel, test_lut3d_identity, 2);
+
+ KUNIT_EXPECT_EQ(test, 0x0000, pixel.r);
+ KUNIT_EXPECT_EQ(test, 0xffff, pixel.g);
+ KUNIT_EXPECT_EQ(test, 0xffff, pixel.b);
+}
+
+static void vkms_color_test_multiplier(struct kunit *test)
+{
+ struct pixel_argb_s32 pixel;
+
+ /* 1.0 leaves the pixel unchanged. */
+ pixel = (struct pixel_argb_s32){ .r = 0x8000, .g = 0x4000, .b = 0x2000 };
+ apply_multiplier_to_pixel(&pixel, 1ULL << 32);
+ KUNIT_EXPECT_EQ(test, 0x8000, pixel.r);
+ KUNIT_EXPECT_EQ(test, 0x4000, pixel.g);
+ KUNIT_EXPECT_EQ(test, 0x2000, pixel.b);
+
+ /* 0.5 halves every channel. */
+ pixel = (struct pixel_argb_s32){ .r = 0x8000, .g = 0x4000, .b = 0x2000 };
+ apply_multiplier_to_pixel(&pixel, 1ULL << 31);
+ KUNIT_EXPECT_EQ(test, 0x4000, pixel.r);
+ KUNIT_EXPECT_EQ(test, 0x2000, pixel.g);
+ KUNIT_EXPECT_EQ(test, 0x1000, pixel.b);
+
+ /* 2.0 doubles every channel. */
+ pixel = (struct pixel_argb_s32){ .r = 0x4000, .g = 0x2000, .b = 0x1000 };
+ apply_multiplier_to_pixel(&pixel, 1ULL << 33);
+ KUNIT_EXPECT_EQ(test, 0x8000, pixel.r);
+ KUNIT_EXPECT_EQ(test, 0x4000, pixel.g);
+ KUNIT_EXPECT_EQ(test, 0x2000, pixel.b);
+
+ /* A negative gain flips the sign; the composer clamps it at the end. */
+ pixel = (struct pixel_argb_s32){ .r = 0x8000, .g = 0x4000, .b = 0x2000 };
+ apply_multiplier_to_pixel(&pixel, (1ULL << 63) | (1ULL << 31));
+ KUNIT_EXPECT_EQ(test, -0x4000, pixel.r);
+ KUNIT_EXPECT_EQ(test, -0x2000, pixel.g);
+ KUNIT_EXPECT_EQ(test, -0x1000, pixel.b);
+}
+
static void vkms_color_srgb_inv_srgb(struct kunit *test)
{
u16 srgb, final;
@@ -474,6 +576,9 @@ static struct kunit_case vkms_color_test_cases[] = {
KUNIT_CASE(vkms_color_test_lut32_three_points),
KUNIT_CASE(vkms_color_test_lut32_single_entry),
KUNIT_CASE(vkms_color_test_lut32_descending),
+ KUNIT_CASE(vkms_color_test_lut3d_identity),
+ KUNIT_CASE(vkms_color_test_lut3d_clamp),
+ KUNIT_CASE(vkms_color_test_multiplier),
KUNIT_CASE(vkms_color_srgb_inv_srgb),
KUNIT_CASE(vkms_color_ctm_3x4_50_desat),
KUNIT_CASE(vkms_color_ctm_3x4_bt709),
--
2.56.1
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-28 17:16 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 5/7] drm/vkms: add a 3D " Oarora Etimis
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
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®