Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp272744lqo; Thu, 16 May 2024 06:07:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXLzJlu1Df9DhgYo78nCliaF7+pP+UO4TTrXzwYs1hlMl6bcsYsy3XSQlkrn+BBv6aUIPs/6ZeOXlYHi3k6sKh8WGVpnmhgB0iK0CA5Hw== X-Google-Smtp-Source: AGHT+IHSea9tWOjzCU12YdwMTdofqqg0VhT8fe3mQopHFA5JtNaVpYTUGYxHJXuo13Yzr/FfSUVs X-Received: by 2002:a17:907:7843:b0:a59:b4e8:d927 with SMTP id a640c23a62f3a-a5a2d55a73emr1332323466b.15.1715864848487; Thu, 16 May 2024 06:07:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715864848; cv=pass; d=google.com; s=arc-20160816; b=c+Yu0JIlI5P7lqr7rql8ygsqkV840T9Bj5Vpt+ACS+5MJd38pNQq47NA0SsWTik0pi sqFOP0axd1FplNdbIbuA6cYI3Vvp2GmWGmkCyN4HA+M6bCfD9bdC37BU/6PXJwLfDVMM UENCCUfvht6TW8lxbryvlW8F+f64ZbpflilxhXZGu9N8fFErcIDFyPgeaZnLy7Lg6wDU N8XcD+MksXr8leh0Lz1TwlQQ77nrhQ3rqYMU9z18Fns4lIFBUCoBsJ6rNp+66VdDHv4y O144D+vbHnW8szA6cQLq0ZLOFIfJO4gG+rAEzub7uDZZEHHzlKUzmS4x6eSRBVf5LksX jbuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=p0FKIVGwbdpHIb8BuI5L8JvoZwrAcNtiZQ1DnM4vR/k=; fh=Qobrj7Y+D9wgq6uDoMzPfrxFbhCTKChuimkMa0d8zso=; b=w17+mxqOLyPKLeIasg6REsbdu9IU231JDLz2+EDV4kyrIkAceL/rJ7C0IQG5nQ1MPZ tMs4BN8oXywSQw29tcja9brlMycfKXiMNbrc2pzFNMsSYoa9B/+QvcTE3bIX9ukH6gFK BA3gbWuv6HhUlSNpWMcZndzvgDRbIyVMegJvHF0mC5UxvZLHnDsLMCTxgEwCbg/zkO2O tTiDF11wrIbkr8bd9K1D7pMcFjzGWfxspf50Pfg3dW21anLyM3pDWIUkw5pIpv3XDqZE HvMiUDoK6Dv0ZI0NTNg3VRO9f/qXqAMYe3l9GjT/gb+cSxCkrhKGB8Ybp42AKK731u50 FCxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=g0isA34k; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-181077-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181077-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17946721si872960966b.72.2024.05.16.06.07.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 06:07:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181077-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=g0isA34k; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-181077-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181077-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5F3891F22399 for ; Thu, 16 May 2024 13:07:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D02C14E2D9; Thu, 16 May 2024 13:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="g0isA34k" Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D85014D44F for ; Thu, 16 May 2024 13:05:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715864731; cv=none; b=eZTgi7PvdPHuxz8vLtCRQogNmLMvRyPiHOTccz+JfNOCmiKl7+tP12qVathmNwz843e+wTr4EkKA3F6FEyqA4Hk/L/H8Bf9XNBUXwFfcg9DClC29HLCx7oSXLJUnH4liOAP2YFKisSf1kXQIJ3lkR1CxCBEIqEFuFcuHbESEM0Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715864731; c=relaxed/simple; bh=OA93dxY/QDeSwlJlrfR8nLFV2Zt/dq9YRAcwRpxm6+s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lV6GHDmaXshJY/eqOzE9XNnNaifFKJ42u1hkSS3u94A1+vO6CA3h1O0bRdDOiqIuNIF/pT79HRgEcGKrSea3MvA0jLKayy/ZY/qBbKYDYZksYYw/2PYR4m2D7W4Vii8Dp1rItbj6JFZdLfI/deULTeD0wvOdd/Y1P5xevDcTDkk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=g0isA34k; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 2582FC0008; Thu, 16 May 2024 13:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715864728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p0FKIVGwbdpHIb8BuI5L8JvoZwrAcNtiZQ1DnM4vR/k=; b=g0isA34kjJGTb/yB22Lfo6Hm9n+2CLZMRm7RjrhjqUixs3tN2m1bHIadRsMl4gK72w/Zsb xCoVBgxiSFNtvU5wY7pFmRSaM6esyM6v+Z+4doOoFXJb14fh67aWXqMzSiCWEtELH09ss2 rqDIZkbamqMbhXbj4T0POHYEuw2EkTCc5qmxY/eVseF1wNg0Po4hhBeTfE6Fa7KVEFkOXG yGJkfuph4Cb1gaBbQM3WowQu5RQLaKRSY+N1ujQEZnqwLe0cYw0Jock+7WD1jK7nhz6jEu Yz4bvAtAkwieA2AeVUcv6ccgQHLAI1bDa3ikyHgwXBDTYvPuwkog/UgysTf+IA== From: Louis Chauvet Date: Thu, 16 May 2024 15:04:53 +0200 Subject: [PATCH v8 08/17] drm/vkms: Avoid computing blending limits inside pre_mul_alpha_blend Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240516-yuv-v8-8-cf8d6f86430e@bootlin.com> References: <20240516-yuv-v8-0-cf8d6f86430e@bootlin.com> In-Reply-To: <20240516-yuv-v8-0-cf8d6f86430e@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet , Pekka Paalanen X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4075; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=OA93dxY/QDeSwlJlrfR8nLFV2Zt/dq9YRAcwRpxm6+s=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmRgSBbEXibmqFdsFH5YkN9+LiZ8XMk4CAWGTkQ FdSwEkDfHqJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZkYEgQAKCRAgrS7GWxAs 4iLLEADWzDvk5UWG+lsOaNlVF3HHWgLrUnAiXHFjuP0iT5ygzm65EOWSe95Qias6+ZYgZFF7Wck x1M6e+qzWv+BPdgES6Idl97UDYrk2gQMjAm9vYp8Lawyez8orGTDlQfTEpNKOGC35yKAh0wOTJg RHEOZMyz24EbJCzswOD/csh2sDGu4cLGOne1NFCHxmPbov1+slmC1Ys2JKfE2pHYo5Yk4VWRAMS L62Qyo6FeYkY1mtwlsGMWqSOAqXmc1A1UgnQgcgRmOpHL5uojz2IfNmXkpqkqwoybrS1fgYXjjZ oUwmqmJfgndGgg5IF4J8AoE7lM+UZdEprc/DXmGe2pajE0r2cl1enqLHSA0h9rA/AAV02NUF6vn xD/YYV+5oErKQTFwgwtiHFr16II2RCYrAzpxFrL1auVMdaBcy90ER6SaoqTx0UP3lE6sGjuuF2s ustLkyUHN1rE6LfEmoWbEpz/EF2zQkCNwS4LZL3srHag6dQiS5pANQ04y/avO72ZA1R/JanJouP K3iU7L/vr7IGYR/sx1qzyf/08TUUDjbMENbyPygUUplj6IqcBIAjt3wwDbC7CmbgmJ67J0kJI/j ROMIPlfovJdqQCPlSyTtm0rYPv14mcZn7YkcU2i+G2PEOXDvyQRmqlwwJe5aw96jsSwhdznOC0w lVr4e/GRJ3TQnug== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com The pre_mul_alpha_blend is dedicated to blending, so to avoid mixing different concepts (coordinate calculation and color management), extract the x_limit and x_dst computation outside of this helper. It also increases the maintainability by grouping the computation related to coordinates in the same place: the loop in `blend`. Reviewed-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_composer.c | 40 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index da0651a94c9b..45b111c74884 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -24,34 +24,30 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha) /** * pre_mul_alpha_blend - alpha blending equation - * @frame_info: Source framebuffer's metadata * @stage_buffer: The line with the pixels from src_plane * @output_buffer: A line buffer that receives all the blends output + * @x_start: The start offset + * @pixel_count: The number of pixels to blend * - * Using the information from the `frame_info`, this blends only the - * necessary pixels from the `stage_buffer` to the `output_buffer` - * using premultiplied blend formula. + * The pixels 0..@pixel_count in stage_buffer are blended at @x_start..@x_start+@pixel_count in + * output_buffer. * * The current DRM assumption is that pixel color values have been already * pre-multiplied with the alpha channel values. See more * drm_plane_create_blend_mode_property(). Also, this formula assumes a * completely opaque background. */ -static void pre_mul_alpha_blend(struct vkms_frame_info *frame_info, - struct line_buffer *stage_buffer, - struct line_buffer *output_buffer) +static void pre_mul_alpha_blend(const struct line_buffer *stage_buffer, + struct line_buffer *output_buffer, int x_start, int pixel_count) { - int x_dst = frame_info->dst.x1; - struct pixel_argb_u16 *out = output_buffer->pixels + x_dst; - struct pixel_argb_u16 *in = stage_buffer->pixels; - int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), - stage_buffer->n_pixels); - - for (int x = 0; x < x_limit; x++) { - out[x].a = (u16)0xffff; - out[x].r = pre_mul_blend_channel(in[x].r, out[x].r, in[x].a); - out[x].g = pre_mul_blend_channel(in[x].g, out[x].g, in[x].a); - out[x].b = pre_mul_blend_channel(in[x].b, out[x].b, in[x].a); + struct pixel_argb_u16 *out = &output_buffer->pixels[x_start]; + const struct pixel_argb_u16 *in = stage_buffer->pixels; + + for (int i = 0; i < pixel_count; i++) { + out[i].a = (u16)0xffff; + out[i].r = pre_mul_blend_channel(in[i].r, out[i].r, in[i].a); + out[i].g = pre_mul_blend_channel(in[i].g, out[i].g, in[i].a); + out[i].b = pre_mul_blend_channel(in[i].b, out[i].b, in[i].a); } } @@ -183,7 +179,7 @@ static void blend(struct vkms_writeback_job *wb, { struct vkms_plane_state **plane = crtc_state->active_planes; u32 n_active_planes = crtc_state->num_active_planes; - int y_pos; + int y_pos, x_dst, pixel_count; const struct pixel_argb_u16 background_color = { .a = 0xffff }; @@ -201,14 +197,16 @@ static void blend(struct vkms_writeback_job *wb, /* The active planes are composed associatively in z-order. */ for (size_t i = 0; i < n_active_planes; i++) { + x_dst = plane[i]->frame_info->dst.x1; + pixel_count = min_t(int, drm_rect_width(&plane[i]->frame_info->dst), + (int)stage_buffer->n_pixels); y_pos = get_y_pos(plane[i]->frame_info, y); if (!check_limit(plane[i]->frame_info, y_pos)) continue; vkms_compose_row(stage_buffer, plane[i], y_pos); - pre_mul_alpha_blend(plane[i]->frame_info, stage_buffer, - output_buffer); + pre_mul_alpha_blend(stage_buffer, output_buffer, x_dst, pixel_count); } apply_lut(crtc_state, output_buffer); -- 2.43.2