Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3431876lqp; Tue, 26 Mar 2024 09:00:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0NkM/SRV1h5/5wSGlPgKU0Egs54dIUob38Ea9UvHAutdR64AYqNnfi9LIIEYPtAMDmR8+gI0uNKOA9v/3OaM4TN3CxeUaI97fBVZebQ== X-Google-Smtp-Source: AGHT+IHASpKbjrTTV0o/ZY5qguTcYgRT5gbP+s3xBB7hDGgeAM4FfeWLzfmVN+ZczworPkx8xipd X-Received: by 2002:a17:903:110f:b0:1e0:cea:257e with SMTP id n15-20020a170903110f00b001e00cea257emr3101729plh.2.1711468857646; Tue, 26 Mar 2024 09:00:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711468857; cv=pass; d=google.com; s=arc-20160816; b=dcxnPWI+QuN6MXoETI00r6NQOx8D7dYkyLpnz5kX80tN1nItFHz2Bf6RmET+H0q8js yhuGpdjP40kCxDVFTYZOFuJf8JyoLOk5hSC6A+BG6Xl3QFoVCA6l4Wpjm6YiNnpYZ5vo +1EndzuX/9gJZUmlfWFKWXYiF8+5kqltOz+Ft2B+hXCKe++q5ziigXwIYH8Xj78sRRKW Jv8AjFmVHVOAu+Qawzn+t6OW7MN3v2aX8PtueHtX7wJDDEnhvlRI2WEelcRtAnoxHWIC vWfXldNMVQ0EcWinwXjKIGn/haX2xkZ1xyew0jubS621AvmzP4UB34YKqOSihp0rQ9TW pvtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=pnySinwcOYAKZXyb1vn9/6Oj7QObM1Z+dGMb0GEyd3o=; fh=45eQo3ZJsZ9kxlKtiBlNFdEPxIxcGnXy8eMk/mnf88Q=; b=oXx6xAmau/7CKMohOWAmqW8I2M0WKGk94A5bP0IYFZyhhaXbkd2WirlPv9XuhdHX13 ordfachiyy7RSGZTjUGqo6bNG8eyfyQuMC7bCA5ep0OB4QTuVeACN2ilEkwKakAKVMgA j9rXFPWeEQd1wfrRxMaey8/As5EeNMw0M2FzAGNgcs75fyjc87iWWwbI7bac7n0ssuur bB+o75bQylfehknTAtmMsTamAI7uXxa28nP4rnjW+T1bMTlEEp1rHWLtwobrnnbuFDfo dgkYUSQmZPmLOlmoCcHO2jX7QFbuTKLv6tS+2DwNZMt+HKRTVJucRU7hpmGp2Hms/mxS V/Gw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="GTA4/8+j"; 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-119403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119403-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z16-20020a170903019000b001dc4b6c737dsi2791678plg.338.2024.03.26.09.00.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 09:00:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="GTA4/8+j"; 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-119403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119403-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6275732300A for ; Tue, 26 Mar 2024 15:58:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E91AB13CC41; Tue, 26 Mar 2024 15:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="GTA4/8+j" Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (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 B3BD513C918 for ; Tue, 26 Mar 2024 15:57:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711468629; cv=none; b=DUSX6xDVvuofJFC8ghGlTeCjJlo+RQdPkuTNtiKaD1nPaMp/DwTbtdrO5iKQucEPkUKEaHigI70MzoSFvGaOVOuBXF1wwghOV+1R06Z4PjuqyVrC6CH4+Pjflh8GLtoomdYnS0khlvtF3g3jmjkcgYFaDXSAzM5+OSe8nxOhFso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711468629; c=relaxed/simple; bh=b4q3+B9iTEAFNXMLwuH/mDEbKiNaJ9yAHQuRvViQoOo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iCLIxuDJCBAAQ2jUAdXH2bsYm0HyH2ysKxrjj2tjsjzeAtkxcgisvKLgs5eGeDt3a92ioErd2KDSHi2GAJc/xWb5ZExpPylns1pFDRFqsPe/ug0c0zwxuzLrXSoHMYY8xcooQjiqzGaj9I1JsWkhTe/e15bla3b3EXpjLZ4jhCA= 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=GTA4/8+j; arc=none smtp.client-ip=217.70.183.196 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 6EED3E0009; Tue, 26 Mar 2024 15:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711468625; 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=pnySinwcOYAKZXyb1vn9/6Oj7QObM1Z+dGMb0GEyd3o=; b=GTA4/8+jALINPJaZwUHA6jLm4JylzHndxYJznNr5MwzXz4kS+TrWAzJYbBRevZ2SlPtAYk b/jAJIPCIoU8fvt/ow7on+oy4GNr5jWu81iSB9Ut4C5a98DNCYpVtkJh2hQ8hj15NKs5FT y5amOcLo7+7jVXzbdBGGMtOO9mWchLkzE3qs7eF56hBkvquKK+YMeRPMS6zW7z0deUb7/+ xtkxE4Zm2y36OnKwES0y5Sa7oqdXnG4OgJNdTUKIUa03WaHKtp0MSLbtLj34+P2WpoYJNt bOriJXxd1hHuPy4RKMVna+gBMpI6VLDTX4xRlj70gE1n0h7E2jYb4uoX/X4tYw== Date: Tue, 26 Mar 2024 16:56:59 +0100 From: Louis Chauvet To: Pekka Paalanen Cc: Rodrigo Siqueira , Melissa Wen , =?iso-8859-1?Q?Ma=EDra?= Canal , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , 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 Subject: Re: [PATCH v5 07/16] drm/vkms: Update pixels accessor to support packed and multi-plane formats. Message-ID: Mail-Followup-To: Pekka Paalanen , Rodrigo Siqueira , Melissa Wen , =?iso-8859-1?Q?Ma=EDra?= Canal , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , 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 References: <20240313-yuv-v5-0-e610cbd03f52@bootlin.com> <20240313-yuv-v5-7-e610cbd03f52@bootlin.com> <20240325144043.77a42acb.pekka.paalanen@collabora.com> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240325144043.77a42acb.pekka.paalanen@collabora.com> X-GND-Sasl: louis.chauvet@bootlin.com Le 25/03/24 - 14:40, Pekka Paalanen a ?crit : > On Wed, 13 Mar 2024 18:45:01 +0100 > Louis Chauvet wrote: > > > 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 | 76 +++++++++++++++++++++++++------------ > > 1 file changed, 52 insertions(+), 24 deletions(-) > > > > diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c > > index b2f8dfc26c35..649d75d05b1f 100644 > > --- a/drivers/gpu/drm/vkms/vkms_formats.c > > +++ b/drivers/gpu/drm/vkms/vkms_formats.c > > @@ -10,23 +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 = x % drm_format_info_block_height(format, plane_index); > > typo: x should be y Fixed in v6. > > > + *offset = fb->offsets[plane_index] + > > + block_y * fb->pitches[plane_index] + > > + block_x * format->char_per_block[plane_index]; > > } > > Ok, this function looks very much plausible for handling blocky > formats. Good. Thanks! > > > > /** > > @@ -36,30 +56,35 @@ 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) > > +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; > > > > - 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); > > How can the caller be not interested in rem_x, rem_y? At this point of the series, I did not change how the rest was working. As this function will be deleted later, I just adapted it to use the new packed_pixel_addr implementation. > Maybe there is no IGT test that uses DRM_FORMAT_R1 FB on a plane and > has a source rectangle whose x is not divisible by 8 pixels? > Or maybe the FB is filled with a solid color instead of a pattern that > would show source rectangle positioning problems? Currently, there is no DRM_FORMAT_R1 test in IGT, and all formats supported by VKMS are aligned on 8/16 bits with block_w == block_h == 1, so rem_x and rem_y will be equal to zero. > Maybe at this point of the series, this should assert that rem_x and > rem_y are zero? That's what vkms_compose_row() assumes, right? Even more specificaly, vkms_compose_row() assumes that block_w == block_h == 1, so maybe more WARN_ONCE(drm_format_info_block_width(format, plane_index) != 1, "get_packed_pixel_addr() only support formats with block_w == 1"); WARN_ONCE(drm_format_info_block_hieght(format, plane_index) != 1, "get_packed_pixel_addr() only support formats with block_h == 1"); Thanks, Louis Chauvet > > Thanks, > pq > > > + return addr; > > } > > > > static int get_x_position(const struct vkms_frame_info *frame_info, int limit, int x) > > @@ -168,14 +193,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]); > > @@ -276,7 +301,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); > > > > > -- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com