Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1883430lqo; Mon, 13 May 2024 00:52:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXRyHiF29un7EU/+EwrbcIAi2kgrMuHDhNlaCoEZJnfjmI62jiQMu5Fc07aph9hqEQ9vZTWdhQv/dA7jjeibnbNGuAZVQYyHpMaDZAuPQ== X-Google-Smtp-Source: AGHT+IH924u8EcRBgcP5W/Upzaz+q8XuO6V5fFMWEFemBLEIly74LLi7Yv5aSsscV2IFKG1wEgbD X-Received: by 2002:a05:6358:88c:b0:192:725f:10a4 with SMTP id e5c5f4694b2df-193bb626213mr926264355d.9.1715586721119; Mon, 13 May 2024 00:52:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715586721; cv=pass; d=google.com; s=arc-20160816; b=vCinLhHF0Rn0m75AQR9MncJqNHu74zPTfCLhH/MElj3jTCe9N5fdPbzdi/5keu+mEU YGrYTyAoMTn4VN6OlQV+OEuRP/4nYmjzWTmuq6EBuprsWwDUCeAdl4mLEqMMFy0u8Dxe XX8xC+yox6xFDjV1kt8i5+XorFqNx+XiFGXJ4Ew1n42pBXUPap5scA5NUKrKwL7IU8qu 5VEj/8QxNZMIsk5UBV3neBKwVTHxz+G6qdx5/SeutaEBIF8ifnVOKw2YgcbO9LTBWBc3 OhXdYh2G8F8y3N6CV75/tC2exqYGCzB5sT97PjBVM4z3BqEhTNHfs2ifkRdSUYLA4qJX R74g== 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=VA+3kkOkmxN6JGQji44tqIpv1ukeuuvSVGAGVFtW8cQ=; fh=fk3KVJ6e//5DsoobLkOAw6e5yTly2+YwRiAZojsT3v4=; b=s9ii9d0y2q9vQ7JLtGlxcB9XrMtoCY2CXtMB6SAnYbksqBLtUj+IsnteQJL9QFQNnW gbYxSTDaFgx9biOhXOalpbBe5tX25b4c5w7Q2MPJZZvBYK3WJYuWjQ/iLHvunm1rNutc K41Sjk84rzf2hkwV3HKW3kqbTp5TMLUAMHN4fi6bTfWrrkhSruduMI+OWgxNlDu6nj4I DtJIpwdqUv4D0Op+zjVPp1HIwsfPmUIoZmaJzV/zpeTvIrQDl+pnYKCbdM/sjAZbQ/51 TNQA9o1Nm3gnIlta2p2MHP4K20OUhHC5FB7LdOyiCBN7xoNwvl5gJ4ydoPNMZXL9abyP Sdvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=NwmM84T8; 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-177294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177294-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6340fe3ae01si8587101a12.290.2024.05.13.00.52.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 00:52:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=NwmM84T8; 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-177294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177294-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 01C67B206B2 for ; Mon, 13 May 2024 07:52:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9B3E1487D0; Mon, 13 May 2024 07:50:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="NwmM84T8" 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 7F94B147C98 for ; Mon, 13 May 2024 07:50:47 +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=1715586649; cv=none; b=NjOByarvWRdirMNmwOq2n77TmQWUC6CPFbyKITSgG23EZYz6DI9mDqW+7FVLoR5K5g1jYJ+0ixl9bqys/sThjds0F6sPEJ/b5r7UeLM6Y7LDsBbWLSHlOfy5nYgEW+Lm07GqAjIU7aMFXZOy7vPYcYhmFOLO17/na90+Ho/SqmU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715586649; c=relaxed/simple; bh=ShQymX7W1zpEO2xcq1CKpIMhcZ1Q46wF+hboMw3ayvo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iJ4jW7pIKmxK6mgDr1mgl9x2Yc6XneD46vVLE87/rrw9S+kzoX/s+92IZlmLmhcL4hztGsiMCfAb+0iuM1XagfffOQsBoTz3XzIFjhE47y9zbQDbenMsyg+mecE2E99+R0uKh+44KYBaMmAT80mpts7qdbUnD/GoAIf99lRfWcE= 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=NwmM84T8; 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 2CE472000B; Mon, 13 May 2024 07:50:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715586646; 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=VA+3kkOkmxN6JGQji44tqIpv1ukeuuvSVGAGVFtW8cQ=; b=NwmM84T8tIg+NCKxfHkdmt7fawk2Nz3rrspe/kgI6rAthZBFv6cR9CDJbMpu2yBKHU9g0w GPL3yijPiYvN5MM3nZSTyQbmQ677PngYYYZHjfDMS7vrfMFmFxi54/HNnEKG+zl19h5rY+ 4KcaIhlEA48yP0mh04vCzwiTouVwz7QVwnxVXEvoL9cwvnVy7YvyDigSPmpuCELBJzU58N rZXIigETG4abmvStJTNoVg0Hqe7L1q4rsPxJSj6GMzdmIsng+iVsfY1/8MUmloRvFp4RHw Totnwk7pYhyDO4QszLS7E0incba65DCFUv7x24sxTxxrGfrxVWHW/ZrJTCR9SA== From: Louis Chauvet Date: Mon, 13 May 2024 09:50:28 +0200 Subject: [PATCH v7 07/17] 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240513-yuv-v7-7-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 X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=8553; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=ShQymX7W1zpEO2xcq1CKpIMhcZ1Q46wF+hboMw3ayvo=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmQcZDSytbFanugTfmjfHDHEXIB+GQqSmAxZaaD z5KV3mKDZOJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZkHGQwAKCRAgrS7GWxAs 4pvFEADIRVCLCYorq4Z80tIlgmFcP12nYnS14DL7Z1tJ7tsT1U5FY6azDzfQTkkQZnIKxieLbo2 bpfvJeFhx7JJ7ExcpdV7kwyPI+XdMWdBFrfATvrsYn20z2teUknW7I7Peb8BKxvC+1zMjEVs6fp P0JUKD1sHi/I2VdAfT2P0B7SZxSg+sqogeG4ZiuKWTYDMXIVTV2fM5URxHC8kjKbcI11DHyz+Wf PKBIQADXbXl1fH7yFzSREwzWEJ+Nw3t0pX8VMJSIXy7kJQ/Q0wMgjDPsT9gG2FApkuXySzc16aj M3Sb/gl94n6d+qgA7YlLd3PF4uC92ndGUiEMD06s4Smzd+PT7pEEfop/Mu3UDkQONH4FXXgcSYs NpUQfWPFp8TkHuK2whUa1uG86uVi35quWpA9/VtayqlXa9L2LQVu4xYOirbnkFciOEKIon3glL6 LTITUUs1lIhjseFkZSoQWABpxRVRWhAwsB0ediCZtkbkockzI8uGZGSgvIjgckDv9WMJxwYcoP4 K80vwB7BZTrWv1PYffuY3xqwSAtRIsjwy7IWBHXZ6TOlH2Q2u4Ee5N0/UNqLHwKpX+CLRa6S0VO B2LhT2reFAbtiJv5TVUdOIdjTdUmoFZwFotgDSDPCzxnp1FECAd1RV9aLe3q8g5ImCFpExLXSxh U0sZRffc5pdy8rw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com 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 | 110 ++++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c index 69cf9733fec5..9a1400ad4db6 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -10,22 +10,43 @@ #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 + * @offset: The returned offset inside the buffer of the block + * @rem_x,@rem_y: The returned coordinate of the requested pixel in the block * - * 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. + * As some pixel formats store multiple pixels in a block (DRM_FORMAT_R* for example), some + * pixels are not individually addressable. This function return 3 values: the offset of the + * whole block, and the coordinate of the requested pixel inside this block. + * For example, if the format is DRM_FORMAT_R1 and the requested coordinate is 13,5, the offset + * will point to the byte 5*pitches + 13/8 (second byte of the 5th line), and the rem_x/rem_y + * coordinates will be (13 % 8, 5 % 1) = (5, 0) + * + * With this function, the caller just have to extract the correct pixel from the block. */ -static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x, int y) +static void packed_pixels_offset(const struct vkms_frame_info *frame_info, int x, int y, + int plane_index, int *offset, int *rem_x, int *rem_y) { struct drm_framebuffer *fb = frame_info->fb; + 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[0] + (y * fb->pitches[0]) + (x * fb->format->cpp[0]); + int block_x = x / drm_format_info_block_width(format, plane_index); + int block_y = y / drm_format_info_block_height(format, plane_index); + *rem_x = x % drm_format_info_block_width(format, plane_index); + *rem_y = y % drm_format_info_block_height(format, plane_index); + *offset = fb->offsets[plane_index] + + block_y * fb->pitches[plane_index] + + block_x * format->char_per_block[plane_index]; } /** @@ -35,30 +56,70 @@ 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 + * @addr: The returned pointer + * @rem_x,@rem_y: The returned coordinate of the requested pixel in the block * - * 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 and the pixel position inside this block. * - * 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. + * See @packed_pixel_offset for details about rem_x/rem_y behavior. */ -static void *packed_pixels_addr(const struct vkms_frame_info *frame_info, - int x, int y) +static void packed_pixels_addr(const struct vkms_frame_info *frame_info, + int x, int y, int plane_index, u8 **addr, int *rem_x, + int *rem_y) { - size_t offset = pixel_offset(frame_info, x, y); + int offset; - return (u8 *)frame_info->map[0].vaddr + offset; + packed_pixels_offset(frame_info, x, y, plane_index, &offset, rem_x, rem_y); + *addr = (u8 *)frame_info->map[0].vaddr + offset; } -static void *get_packed_src_addr(const struct vkms_frame_info *frame_info, int y) +/** + * packed_pixels_addr_1x1() - Get the pointer to the block containing the pixel at the given + * coordinates + * + * @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 + * @addr: The returned pointer + * + * This function can only be used with format where block_h == block_w == 1. + */ +static void packed_pixels_addr_1x1(const struct vkms_frame_info *frame_info, + int x, int y, int plane_index, u8 **addr) +{ + int offset, rem_x, rem_y; + + WARN_ONCE(drm_format_info_block_width(frame_info->fb->format, + plane_index) != 1, + "%s() only support formats with block_w == 1", __func__); + WARN_ONCE(drm_format_info_block_height(frame_info->fb->format, + plane_index) != 1, + "%s() only support formats with block_h == 1", __func__); + + packed_pixels_offset(frame_info, x, y, plane_index, &offset, &rem_x, + &rem_y); + *addr = (u8 *)frame_info->map[0].vaddr + offset; +} + +static void *get_packed_src_addr(const struct vkms_frame_info *frame_info, int y, + int plane_index) { int x_src = frame_info->src.x1 >> 16; int y_src = y - frame_info->rotated.y1 + (frame_info->src.y1 >> 16); + u8 *addr; + int rem_x, rem_y; + + WARN_ONCE(drm_format_info_block_width(frame_info->fb->format, plane_index) != 1, + "%s() only support formats with block_w == 1", __func__); + WARN_ONCE(drm_format_info_block_height(frame_info->fb->format, plane_index) != 1, + "%s() only support formats with block_h == 1", __func__); - return packed_pixels_addr(frame_info, x_src, y_src); + packed_pixels_addr(frame_info, x_src, y_src, plane_index, &addr, &rem_x, &rem_y); + + return addr; } static int get_x_position(const struct vkms_frame_info *frame_info, int limit, int x) @@ -167,14 +228,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 +336,10 @@ 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; + int rem_x, rem_y; + + packed_pixels_addr(frame_info, x_dst, y, 0, &dst_pixels, &rem_x, &rem_y); 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); -- 2.43.2