Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1887563lqo; Mon, 13 May 2024 01:02:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXWxgjzXuHDluOcz4ZQhliJVOclWDZ/WqrDemIK5cn0oHRPgZUgOAtkWtWThgdjawnZTeDXkc530rwz+JpMQR6yH8dG4v3ozDHJhOPX9w== X-Google-Smtp-Source: AGHT+IF9HURvIVR0iDZp31wQTvJ9BWbQLCaHxbsWJ+nv4N9bVWjzzMkv9/7Yjk+Msh4guGJa9aib X-Received: by 2002:a17:906:31d7:b0:a59:c7d9:9d39 with SMTP id a640c23a62f3a-a5a2d54c0b5mr621800666b.10.1715587376417; Mon, 13 May 2024 01:02:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715587376; cv=pass; d=google.com; s=arc-20160816; b=cYyKFO85xAORcY/s0Ph39+nj2Fi10fetxShWws3agrts8+jT/GC/xCUmZGTrjVzHOK 3HWirMATrpZx06vFn8jiiyogk08WTSE/lOLWAu2YOg/CywVr2qO+JLkwcozXRaC6qFBz R9M+sRNcKuJQxo1aKxE+yFLpEXSmKn8CV7btqdiRf8mcOnmO4nyUQPEVxwAoNF2Dsf/x bIXw8e8Z5iskVbegyWHL3CZ71Atgx/CJ/UZrxVmVrNtthq80DEWReEwsK1da9sA2AvzA tE63rU7/qKDy2H6ncInkESB9juNnqApNIGQU936MeqRPlRg5sT8RNUVNeGhpZyT52FDj oDGg== 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=jW6DJ9S3mqFKWT8KFPowyNAHMw0TcUPA3XMPnCxRxmkDlk/IlMzn6rmLMzq0Uqaw8D pn2kNa6hDQZU4XdBbgAJ2W+wmbi1LD2W3WuAOBCeGCf8SUTWEE9mifRxPzwccMkeHEpj hsOstX3CRz7IMoktRPrAVQuWiN0R/EVVpNEOVKz8SOzay30AzxXifQ6Am8BVyuSHHxYs gj82LLpADUNtVu4bJ6iFwcBXm6EfGXKukOiCuNdTSpuhuDSkecO3qCXatxuw5p4tbCm9 iCC+nfF/71HXf+MCMTH9bItxtEtdJ2jS1yUtTW/+cVhuU2gWOWxQmxCIY3Vb0YWQVKdn Bi0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=JG9zxmx0; 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-177295-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177295-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-a5a38a8dbebsi329359766b.620.2024.05.13.01.02.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:02:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177295-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=JG9zxmx0; 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-177295-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177295-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 E43521F21C65 for ; Mon, 13 May 2024 07:52:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFC6F1487DB; Mon, 13 May 2024 07:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="JG9zxmx0" Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 D6F9414830E for ; Mon, 13 May 2024 07:50:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715586650; cv=none; b=dHo9o+GPsmY6MfRMK58P1WtlE1YnjED/Jz//DlobXvpilelIj+gcU55s0f423OqJWL2STvTCFvp85K1NHYUWzVWF/UpmWRB/tXtF2mNYmzC8W89kX18B1Um4xWMQgocMXDZ0i/gLT2H28cc226oOWlhzmvg83xPaxTbeRFnT81o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715586650; 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=OnvjFU0aLSkZlNGedG9v8BpmKKPENj63Ile4PjuBv6bkvqhmZQvoD4tIsPv0TKQgcyEV5KtGpiH+oRbuaoavElAgFBgXni6Bnz68WPTSOMpdrcqH+PKAVdcw8Sn+LipdWkvC9RrCdacFyuNdiuo/DrgkzVWmRFDYLyEXEmNbiOo= 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=JG9zxmx0; arc=none smtp.client-ip=217.70.183.200 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 1C45720013; Mon, 13 May 2024 07:50:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715586647; 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=JG9zxmx0QE5XZwwAB23VPSaT876MjLJpxYpEOKyvK+6U7/doJAkLitv0fs22KEk9r2nnff S76qlW1GCzw9wHOiBW0s0qF7U9fUM6a9GK76pFXEymZ5WlSxBI0y1auRYVYUTBc4MADUv+ W7GD0a7PvV2IB9bXEQXKUVbcpKohUdBk8oJMcb3Ff7BwAXtIZHpT/9EfI4Al9Pvsavrznv aP40L+JTUXbj1ses74ogXs/CVn4GefXQBNI+kRh9RKur5V6C6+4oKov560DzzSgsqbCrwV oMmQZHRYR/sGEKbxuhzmKFF5A2E1tvlYr/tJq8WYJU/GM1Lo3oSkCwDVIYISxA== From: Louis Chauvet Date: Mon, 13 May 2024 09:50:29 +0200 Subject: [PATCH v7 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: <20240513-yuv-v7-8-380e9ffec502@bootlin.com> References: <20240513-yuv-v7-0-380e9ffec502@bootlin.com> In-Reply-To: <20240513-yuv-v7-0-380e9ffec502@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/ZANAwAIASCtLsZbECziAcsmYgBmQcZDw7+y+Iv1zpmacs/s2ByIy4kkuPgEUkd6i KIXbdumtgqJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZkHGQwAKCRAgrS7GWxAs 4ui/EACTJGgpB/8K/B25SVUZ3HyHEzDf94M3L7psRDl6kaozHoD3oNgsuVqjiYSOsQx+LbbFSCT aKiQ/xf6mS2QxLKMDFyHj38eaiMu7N6yx0qqIxjN41B9zQwVii8pYzW9l3E5OUXa5M6zQUDQuDe vQTqXw4nwnTc41Gdui3TWfLGbyS2cuW89uiU8KasZjTuvcbDNm/Ipa7Y4tZGLoURdYdzpfYfd1N phWVYQO92h1wlvi3fCVz2Lnx+tGdSEDhraiPh29TmtwLzIaJpCFBS4VGW6vh6d735OdVEFrX3Gg tuqATNem/pIRFSiT15chhaInC3utoyHvvyjLJuQ5FkY1Vt3HPTZDB2M61B7IMDK7IYT2j2DfPl5 z6HVq4mjLxdHcT8p2PY+bmJe2tFAZnlxgxy1MC0TiWA4952rzOlwLFFCNF9UJ9hpSKuVrvdOR1n AS3x64eGoHnMhm6kwtA1VdoxBNgMSCrXFOSS7UEQcIlEApxpVZ5t2WgcTzDhgAgpfcv/D3khu2T y0UjxEM9FxvMTCV62iohWdBlc9LibGVqNFU0MuZGtC7MmY9cirZjEspvqcyaG8xlCn+JrXjM237 zlUIpCLMbyqLSMfC8T2fK2VZUJIW4TkH4ixXTCFnNqPb9plKO1a7YXeN9IkGPJa9ZavoqNkPkvv nWk6jJpVewLVhpQ== 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