From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795890033; b=2NoaH33gT36w0kMpmS2ckKytaL42bOUBt9K0vIC47i4esTID7algCUh240sT2rGt46GN 4RXvsDDgFEpXFOMnpi/geI+7oY1hu+L357ydCHepL85xmkrWJainROgxv7CH2aIfvrhmg iAxB6rLDxzmdWkjO0+pFwIyqoPpdXPRR4YLJElB1O5JVk1g/8Z3uvETtarKoCVWraQj3W 49CQDmM4PXAUjQmNOSSMOTeE5wgmYrNPcVCVYKPMyO79P7fGs1nexnonwHumJ52qs0AhN 48h5TMb+Vutw0ZxriYC+kycBAZADrhJXh8KK+VJipIk9j8IsPbA4dCdAHUWpxDs1PiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795890033; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=E+LNoliuJndycOh7l7fxGld1ch53Z7LWjZaE5/JQPQo=; b=bIKb53YgCsYutHep4Mm3pHE4mg9ruU33O2R4lRgSPM7oHYt9c9hoper5ir85iiwtBVFY IJamkHP+nI9FDqNqWRzTJ1a15W9HuKM53hKIyXEqgjg0LGo42veIRSxahvi5BVEmObyjw VpnTPCu6vBcjhHqrpz03hOhD5dEX5sVY4PmZ9Rc4XfDxAKc3g35jGddsICKAUKr5sYIVc L/27rZFCD+JPvo+Q6KLUa42AKVg0F7MPinIH5mL6oA04YMOY4ETmZQLnYcYjiaPNT8yGZ pY/BdeG67lrWYSBPvhIHoBOE5ZII6DtuE29Mgg639LPounYAoiY0zqxwHSaFDoSovmw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=05sUCaQd; arc=none smtp.remote-ip=209.85.128.49 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69923606A31C for ; Sat, 28 Nov 2026 18:20:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69923606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=05sUCaQd Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4bb5b8ef642so77126425e9.1 for ; Sat, 28 Nov 2026 10:20:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795890032; x=1796494832; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=E+LNoliuJndycOh7l7fxGld1ch53Z7LWjZaE5/JQPQo=; b=05sUCaQdSspVhhhK5KhCCg6GeAOoFyYms3sHnQ9rkdfdhnvdkRggf1+K+3O+nZ8vFJ HEION1TaIGYFA5kzJhdlPXnX/OC5bw1Sg9L+mKLUrwb0uUdzM1JxtNHJ2ebGiirahihW 1uZ25twtkprH4gze+JZc7u6U8p4/3AS7Cbijt5Qt8eIaeO15ktwgqEZA8vxF2GLyrTsJ UC/GJJzT+Hqz2UZ8hjVr/AjAnWe18edMjSd3do09ON912lf5fEmcPZsmpZ1HaNOCccwl Ny/4gWqXhrHPHD/IE09Ab25LjD96H7YRAq2qMdJVA9gx55MjWgRo9WNk1kNzDErxFD8j vETA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795890032; x=1796494832; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=E+LNoliuJndycOh7l7fxGld1ch53Z7LWjZaE5/JQPQo=; b=EiT+qxf/p3uNCLGXJeqR4NuzpXFxWq93cQ079zK4YEX8b7CG4ZbSRIn4e3K0zq7ll/ FBsm8p3+QVkEIaGzd7zF4+YvQvP9fTA35/oq/lp8/190u1kT/3+0j15dxtf3sQfT1DHi yfAbbM8T6WU7zVQBJyOe50Ft02P1c+GCNjhTh7uM5DP7B2a7vU8eDdA6FlehGvf2w16f RbmteIT5x4N7d3fY2n9c27draslTTeaEoqmtcemfoI+bqERiDH3R5fvD+Ob4cO9OMtUT vGqFQVoRH9oi9lzebIHY+lOUsbo27rcwflLPBbE4DkDSxTdnB2Hjf0uXLq+P5m77XkPN 4yFw== X-Forwarded-Encrypted: i=1; AL+hErHME0EIneYbtgYqrmPMFScHXnOb/IeDN4zMPGYmGsICJQg4S6NqG0bNdR1/ARlwmvZNJ3ktuxdU0wceaZA=@vger.kernel.org X-Gm-Message-State: APuU4Z9YFVcrf3813d1oe8ILYNV6OWrH69BhUewQc2IU6eEKNHSiZrdU NmS1Dxq1gmV/ImysdbY84friKOMas7kjiS4PUoCwI10rFJsvhvF6Acb+ X-Gm-Gg: AZFdTZcw/FlAY8LtQk4VnUakhg6OriZ89QFe0JdIpIxAg1LgD+nxdq1xaYGgqolDujW 3w/VAtefUizUrw6J9ZkhYKGfn62CEB9wdSE5eCPDY6mUwehqssA7oE56LAgVVr4ywnFqVnuzNcj ZgbNNRyIZJXEqVsutILqnr4Rh7u+Q6VJfSweCBNncWOhavvQUsXWEB2Zd41t4S7fIZL2q/r+Wqm +EnGx5KttOqKlUajVKNchFlEcrlfCd/n3eF7Z80EXAxmHsMtR9geeawQxMwz8jkUlePKikVB79o ElifZoeUQgwVrTflQKL21dGfWn4PH2YGH0j91GSzbNrnuSXFECslKSqKnaPRf3nHgfWRHD2wp9U aPVQu3cFauh5lwzf333+z7kzZaosIdUNTh5hK5aepmHmshvNFDmmD2i/gtDDiYXFKt5GKtMxs6u ZVUSYR9DbNVGCShjXBeoA/ryfUcd7BwUWce6Wk0uz6qJdjA86RZbt+u000OnEY829wwA/U4V/9+ aJSP1OT7wcIn6fcKT9jQ1TH5lDQ8BilbbY8rvIv9aW3hOGfP5s3lyPFJer3OO4/NhVekisTsX/y 2AOdJ3R60vDSQ+S/FMRrWAYkzG5O3sX3RMOXVQ== X-Received: by 2002:a05:600c:4ecd:b0:4a3:12fb:1ef1 with SMTP id 5b1f17b1804b1-4bb8881e81cmr589857825e9.29.1795890031719; Sat, 28 Nov 2026 10:20:31 -0800 (PST) Received: from [10.56.169.198] ([95.179.249.152]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853b2437sm1101005055e9.13.2026.11.28.10.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 10:20:30 -0800 (PST) From: Oarora Etimis Date: Sat, 28 Nov 2026 19:19:43 +0100 Subject: [PATCH v2 5/7] drm/vkms: add a 3D LUT colorop X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261128-colorop-v2-5-6e76c66cf1eb@gmail.com> References: <20261128-colorop-v2-0-6e76c66cf1eb@gmail.com> In-Reply-To: <20261128-colorop-v2-0-6e76c66cf1eb@gmail.com> 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@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.15.2 Add a 3D LUT colorop of 17x17x17 entries, interpolated tetrahedrally. The composer locates the cell of the pixel and weights the four corners of the tetrahedron its fractions select. Red is the fastest moving index, as the uapi documents. The existing colorops and their order are unchanged. Signed-off-by: Oarora Etimis --- drivers/gpu/drm/vkms/vkms_colorop.c | 19 +++++ drivers/gpu/drm/vkms/vkms_composer.c | 140 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_composer.h | 2 + drivers/gpu/drm/vkms/vkms_drv.h | 2 + 4 files changed, 163 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c index fdbdad103412..9ffc6e354206 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 56749ecdd17f..671c16854a49 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -255,6 +255,129 @@ VISIBLE_IF_KUNIT u16 apply_lut32_to_channel_value(const struct drm_color_lut32 * } EXPORT_SYMBOL_IF_KUNIT(apply_lut32_to_channel_value); +struct lut3d_cell { + u32 r_index, g_index, b_index; + u32 r_fraction, g_fraction, b_fraction; +}; + +/* + * Locate the cell of the 3D LUT a pixel falls in and the position inside it. + * The three axes share the same coordinates, so they are computed once for the + * pixel instead of once for each channel. + */ +static void lut3d_locate_cell(struct lut3d_cell *cell, u32 size, + u16 r, u16 g, u16 b) +{ + u32 max_index = size - 1; + u64 position; + + position = (u64)r * max_index; + cell->r_index = div_u64_rem(position, U16_MAX, &cell->r_fraction); + + position = (u64)g * max_index; + cell->g_index = div_u64_rem(position, U16_MAX, &cell->g_fraction); + + position = (u64)b * max_index; + cell->b_index = div_u64_rem(position, U16_MAX, &cell->b_fraction); + + if (cell->r_index >= max_index) { + cell->r_index = max_index - 1; + cell->r_fraction = U16_MAX; + } + + if (cell->g_index >= max_index) { + cell->g_index = max_index - 1; + cell->g_fraction = U16_MAX; + } + + if (cell->b_index >= max_index) { + cell->b_index = max_index - 1; + cell->b_fraction = U16_MAX; + } +} + +/* + * Tetrahedral interpolation of one channel in a 3D 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, + const struct lut3d_cell *cell) +{ + const struct drm_color_lut32 *v000; + u64 sum; + u16 v000_c, v100_c, v010_c, v001_c; + u16 v110_c, v101_c, v011_c, v111_c; + + v000 = &lut[cell->r_index + size * (cell->g_index + size * cell->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 (cell->r_fraction >= cell->g_fraction) { + if (cell->g_fraction >= cell->b_fraction) + sum = (u64)v000_c * (U16_MAX - cell->r_fraction) + + (u64)v100_c * (cell->r_fraction - cell->g_fraction) + + (u64)v110_c * (cell->g_fraction - cell->b_fraction) + + (u64)v111_c * cell->b_fraction; + else if (cell->r_fraction >= cell->b_fraction) + sum = (u64)v000_c * (U16_MAX - cell->r_fraction) + + (u64)v100_c * (cell->r_fraction - cell->b_fraction) + + (u64)v101_c * (cell->b_fraction - cell->g_fraction) + + (u64)v111_c * cell->g_fraction; + else + sum = (u64)v000_c * (U16_MAX - cell->b_fraction) + + (u64)v001_c * (cell->b_fraction - cell->r_fraction) + + (u64)v101_c * (cell->r_fraction - cell->g_fraction) + + (u64)v111_c * cell->g_fraction; + } else { + if (cell->r_fraction >= cell->b_fraction) + sum = (u64)v000_c * (U16_MAX - cell->g_fraction) + + (u64)v010_c * (cell->g_fraction - cell->r_fraction) + + (u64)v110_c * (cell->r_fraction - cell->b_fraction) + + (u64)v111_c * cell->b_fraction; + else if (cell->g_fraction >= cell->b_fraction) + sum = (u64)v000_c * (U16_MAX - cell->g_fraction) + + (u64)v010_c * (cell->g_fraction - cell->b_fraction) + + (u64)v011_c * (cell->b_fraction - cell->r_fraction) + + (u64)v111_c * cell->r_fraction; + else + sum = (u64)v000_c * (U16_MAX - cell->b_fraction) + + (u64)v001_c * (cell->b_fraction - cell->g_fraction) + + (u64)v011_c * (cell->g_fraction - cell->r_fraction) + + (u64)v111_c * cell->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) +{ + struct lut3d_cell cell; + 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; + + lut3d_locate_cell(&cell, size, r, g, b); + + pixel->r = apply_3dlut_to_channel_value(lut, size, LUT_RED, &cell); + pixel->g = apply_3dlut_to_channel_value(lut, size, LUT_GREEN, &cell); + pixel->b = apply_3dlut_to_channel_value(lut, size, LUT_BLUE, &cell); +} +EXPORT_SYMBOL_IF_KUNIT(apply_3dlut_to_pixel); + static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buffer *output_buffer) { @@ -346,6 +469,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) { @@ -362,6 +499,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