From patchwork Mon Mar 4 15:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 209587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1496844dyc; Mon, 4 Mar 2024 07:32:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWLHIIajeYh97nYWyi39GmBATOaLtaT75BDc496f2liie/pecjYmPYM761wMpkEXfTvdTY/5jpeP78V7S4PJtyup5vVqQ== X-Google-Smtp-Source: AGHT+IHJJDqM0dt61F1oRhH3mZNLfj38xA4VFXSmfNmMrnQntKhIdLqNfWjoOpRDeRXUM3Fvo5w/ X-Received: by 2002:a05:622a:1703:b0:42e:d5b0:3b7c with SMTP id h3-20020a05622a170300b0042ed5b03b7cmr10085852qtk.5.1709566341257; Mon, 04 Mar 2024 07:32:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709566341; cv=pass; d=google.com; s=arc-20160816; b=MpM+txhQkPzMnlnHBd66ZdXd5NfquCR44xn/emWx1cpxbT9yotGtiBUaGCxH1ptmQk sg+8I4OAr2W8K595CrMHec/1VxGfCjivo/a2RcSfShKn2VqvraofX55MMTUfu/vMQuWl 8wUIPNc6UprqDG0kj3SbCfsIVQICkfcTCEh21KiQJXnj+x+CrgFX7Q/rV8kipo9V03F+ Qjh7AOkhMnJfs0tVf8s9p07Lx7ckWxnm/Z7+I1O0go8OzK5fLVdR1v2sr8qI9zkPC8Rg RFwXFtHyVJdYROUsTjSNffZc2dn2/osfrtojHtWlJQ+DbPkiZzvHqzuRUyZDCwdCo8nN ubAw== 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=tkMA90xZNbAtS5RoA+EDPhLYGxyx6rZctamxCUhrcic=; fh=I1mDzpQ2i/fckVIeMd+WKWb14s85mMQWc3/wF4wbFPI=; b=SkKv6+D518YJm4rTx0qiO0/8qWUl00ZCr6XGUHrv1bTSOL2z+pS/QNR9ozdwQF0uKC hr1Er4VcAZe4CqpZpbANN1UQuRjXqWgxm8yz76ZZ+yyf93Pckr8CW4QMoUurs1D+Jzdk Qba3cBz+5DMj7MUh/jawxmGOq8D89uMrBR+CP4siSPZ9RrROXRw0q7I93lVK0SxOtBEp O1NAppSQMUF+uKtQaPMvvS27g7n0SOgPRjjsS7YnJdZAs7vmewBjq8jHiZ7PaZXtC1Wx A8YEaiBwRbq+AyqOXJ8tBjtGRNP09ar01iluun5uQs+LTDPcVPait5QcFRfoBAmMen7r w84w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=SGnKRm17; 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-90827-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90827-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i11-20020ac85e4b000000b0042eb3373cd8si3063459qtx.682.2024.03.04.07.32.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 07:32:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90827-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=SGnKRm17; 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-90827-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90827-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 027421C221C0 for ; Mon, 4 Mar 2024 15:32:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA59A5337B; Mon, 4 Mar 2024 15:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="SGnKRm17" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 8C9054778C for ; Mon, 4 Mar 2024 15:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709566170; cv=none; b=ay2Bhu4kTix0xSTDFFjaYpWq/UvjMhKaD9MNTicclyChvDM728VgaorNmIhE69EN9L3hjAputVy2FVbT0z0b5zlVjS+djWjB4uTp7y1r9gaO5W3fTBOBJcrk53VQa38/bOXcf0kUTbvUl0AHmdz2yOQkXVskkA40mxqSaP9/zoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709566170; c=relaxed/simple; bh=JIoXrYSBgeg0QLNIPh8bxgpI6Eagu1fkt6Zjo95AAXg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X+wJM7YFmKMDz8x3b92VMl6ZWWb7otE2jpnLtzst+7nqqC7n/YIH7ormu51d9fBqKXi4R3EjKQIycNvMYqG1BSY27wAYwXRrX0NIQZJxotpvYE2NzmdwzK5oDFnq1G6CjNegvo2LoNe95ufbQ+d85SKqtQBMjklh0sMqsPs0RI0= 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=SGnKRm17; arc=none smtp.client-ip=217.70.183.197 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 DD57E1C0005; Mon, 4 Mar 2024 15:29:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1709566166; 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=tkMA90xZNbAtS5RoA+EDPhLYGxyx6rZctamxCUhrcic=; b=SGnKRm17Zx46uCAKdiTDmu/qAN/XtL96BcTrAC1bWB7ZnvOBwmKWs1MZz2QPJcMLknjJMh 36o46HveSFxrg3CJl2FVwp3K5Aicl0s4kQqEtbeaVlvr4xwOJnEugokcBdiPCsXfsBQRvW 7vwAUJT7RXVCGzjJCbdTo+enZXXo05+2OY3bSHK2ANQc9a9hZ5t90DA5QxUhxCwlEm/m86 8pIWv8GQJ+zsL4hwu0KYAz+SOoqqGX/VDs4KcjSrQ5Hk8whMfCAAanhhtYKfCY2YXoCcM6 5RgZ/UJy9+9NUD4V1w+yQTwWY6ehW8UkRVlIDdUa44enrZEKkmXuQFedT0x3+w== From: Louis Chauvet Date: Mon, 04 Mar 2024 16:28:12 +0100 Subject: [PATCH v4 07/14] drm/vkms: Update pixels accessor to support packed and multi-plane formats. Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240304-yuv-v4-7-76beac8e9793@bootlin.com> References: <20240304-yuv-v4-0-76beac8e9793@bootlin.com> In-Reply-To: <20240304-yuv-v4-0-76beac8e9793@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 , 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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6343; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=JIoXrYSBgeg0QLNIPh8bxgpI6Eagu1fkt6Zjo95AAXg=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBl5ejLB5olR9HyMbIVafJg3K0bne07ZtxNWsInxYTw m3vcOXWJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZeXoywAKCRAgrS7GWxAs4qKkD/ 9uf7hPdWfm5uXVdtNAAm/Bml6Jt6c7eKPIqp0WVrbVRfu9v2xKRE0pAJTzj+ZcmyNfPcPbp89b8Wly 5eQNEXrjxhaIHFm2dgTOw6cOX5hLtWhhpLs6tYxpF6Lu9WXmpUhYDJVWqj9xwtgrrkLZ2jmQmSQjxS +eUyFtKGrMdN1BuCw3Dw2Hz4llqIny8G7McEVmcNspkvM/jwY3j77jm5zSO1JZ4kI/jtTFLOTmC3D4 oRSWZ6G92hKalEh1XHHrWlsAF0x0335u7q1cU61YZHURZuP+VIXPMtP2DT98DnlSk1RGUUeW64SGkt wOW0f79Ka4sg0xHFcrg3Nz3hULmSCQ5Nf4wUYp/zJ03Y+8JeEDcwh/2oyjE+4xnNl4JXhjan1JvSnZ J3dXLDLW6LDTBtRtappU5swFvgOsXtJQAQPS0JOxeSB2ZeVK1hgITV08YNA/dQz2gFbcg2Uk0bKaCU MLMQkOTJaNQJo0pJRCT0H4WYYSoKY7bOi5OFqgftXg6sf2JvM+hWk7Qr4ZkO5LAQpl0LzzHLcU1Qif YRPrfME2K5OT+pjHGOmin0As6MxALomwJFKod5WloVRoLWg2CLZxuQfimfoX7GPHT6fyyNItNmtS0K RItClVkD503P6MG9s+X1yGfGsWpXHE5Lc9W6COs9kjhbOTlGBb6a6LNyoSug== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792610236148075216 X-GMAIL-MSGID: 1792610236148075216 Introduce the usage of block_h/block_w to compute the offset and the pointer of a pixel. The previous implementation was specialized for planes with block_h == block_w == 1. To avoid confusion and allow easier implementation of tiled formats. It also remove the usage of the deprecated format field `cpp`. Introduce the plane_index parameter to get an offset/pointer on a different plane. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_formats.c | 59 +++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c index bdd15964ce24..089e4bdd5da8 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -10,23 +10,33 @@ #include "vkms_formats.h" /** - * pixel_offset() - Get the offset of the pixel at coordinates x/y in the first plane + * packed_pixels_offset() - Get the offset of the block containing the pixel at coordinates x/y * * @frame_info: Buffer metadata * @x: The x coordinate of the wanted pixel in the buffer * @y: The y coordinate of the wanted pixel in the buffer + * @plane_index: The index of the plane to use * - * The caller must ensure that the framebuffer associated with this request uses a pixel format - * where block_h == block_w == 1. - * If this requirement is not fulfilled, the resulting offset can point to an other pixel or - * outside of the buffer. + * The returned offset correspond to the offset of the block containing the pixel at coordinates + * x/y. + * The caller must use this offset with care, as for formats with block_h != 1 or block_w != 1 + * the requested pixel value may have to be extracted from the block, even if they are + * individually addressable. */ -static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x, int y) +static size_t packed_pixels_offset(const struct vkms_frame_info *frame_info, int x, int y, + size_t plane_index) { struct drm_framebuffer *fb = frame_info->fb; - - return fb->offsets[0] + (y * fb->pitches[0]) - + (x * fb->format->cpp[0]); + const struct drm_format_info *format = frame_info->fb->format; + /* Directly using x and y to multiply pitches and format->ccp is not sufficient because + * in some formats a block can represent multiple pixels. + * + * Dividing x and y by the block size allows to extract the correct offset of the block + * containing the pixel. + */ + return fb->offsets[plane_index] + + (y / drm_format_info_block_width(format, plane_index)) * fb->pitches[plane_index] + + (x / drm_format_info_block_height(format, plane_index)) * format->char_per_block[plane_index]; } /** @@ -36,30 +46,29 @@ static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x, int * @frame_info: Buffer metadata * @x: The x(width) coordinate inside the plane * @y: The y(height) coordinate inside the plane + * @plane_index: The index of the plane * - * Takes the information stored in the frame_info, a pair of coordinates, and - * returns the address of the first color channel. - * This function assumes the channels are packed together, i.e. a color channel - * comes immediately after another in the memory. And therefore, this function - * doesn't work for YUV with chroma subsampling (e.g. YUV420 and NV21). + * Takes the information stored in the frame_info, a pair of coordinates, and returns the address + * of the block containing this pixel. * - * The caller must ensure that the framebuffer associated with this request uses a pixel format - * where block_h == block_w == 1, otherwise the returned pointer can be outside the buffer. + * The returned pointer points to the block containing the pixel at coordinates x/y. + * The caller must use this pointer with care, as for formats with block_h != 1 or block_w != 1 + * the requested pixel may have to be extracted from the block, even if they are + * individually addressable. */ static void *packed_pixels_addr(const struct vkms_frame_info *frame_info, - int x, int y) + int x, int y, size_t plane_index) { - size_t offset = pixel_offset(frame_info, x, y); - - return (u8 *)frame_info->map[0].vaddr + offset; + return (u8 *)frame_info->map[0].vaddr + packed_pixels_offset(frame_info, x, y, plane_index); } -static void *get_packed_src_addr(const struct vkms_frame_info *frame_info, int y) +static void *get_packed_src_addr(const struct vkms_frame_info *frame_info, int y, + size_t plane_index) { int x_src = frame_info->src.x1 >> 16; int y_src = y - frame_info->rotated.y1 + (frame_info->src.y1 >> 16); - return packed_pixels_addr(frame_info, x_src, y_src); + return packed_pixels_addr(frame_info, x_src, y_src, plane_index); } static int get_x_position(const struct vkms_frame_info *frame_info, int limit, int x) @@ -168,14 +177,14 @@ void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state { struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; struct vkms_frame_info *frame_info = plane->frame_info; - u8 *src_pixels = get_packed_src_addr(frame_info, y); + u8 *src_pixels = get_packed_src_addr(frame_info, y, 0); int limit = min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffer->n_pixels); for (size_t x = 0; x < limit; x++, src_pixels += frame_info->fb->format->cpp[0]) { int x_pos = get_x_position(frame_info, limit, x); if (drm_rotation_90_or_270(frame_info->rotation)) - src_pixels = get_packed_src_addr(frame_info, x + frame_info->rotated.y1) + src_pixels = get_packed_src_addr(frame_info, x + frame_info->rotated.y1, 0) + frame_info->fb->format->cpp[0] * y; plane->pixel_read(src_pixels, &out_pixels[x_pos]); @@ -275,7 +284,7 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, { struct vkms_frame_info *frame_info = &wb->wb_frame_info; int x_dst = frame_info->dst.x1; - u8 *dst_pixels = packed_pixels_addr(frame_info, x_dst, y); + u8 *dst_pixels = packed_pixels_addr(frame_info, x_dst, y, 0); struct pixel_argb_u16 *in_pixels = src_buffer->pixels; int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), src_buffer->n_pixels);