From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 331BB195FF0; Mon, 30 Sep 2024 15:32:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710337; cv=none; b=uLzWcu5uJEdWBYONHQ8A/JqoEGh2DU1Ou/DSrX6F8Bb7FTL21kX+P0OMr3jRIqttFSrGL91bsQvM2b2wHku+pvrVFjXC1cZEyexlBKK3DpqMBFNUewKcES2XXw7OD12BA3PMscNLovrJUOJN6QjmrVsyCS4GTjl8KTmsB1GZ5zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710337; c=relaxed/simple; bh=+UNcxZgMXrYbfQ0Wk9GKtPGOAGGqTYaVl8i/PMhH4u4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eMEb9r3b5vgIKgg4BepRatgVAN+ZN5OrddRIHkcjgninWDLI664UPXwNPvcs5Bl8tt/XBkE9gaMounXChgj533T18D+ur1sAih3FKDDm4lZf8UYXo0iEyzfVN/1f9wPaPCGyNMKRJZeXzuFABsDA59wTf/eHqxMoB11xOx2MhBo= 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=MSqmmGCx; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MSqmmGCx" Received: by mail.gandi.net (Postfix) with ESMTPSA id EC1D240009; Mon, 30 Sep 2024 15:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710333; 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=nPw90jBWzUneCJNYVnnpD4jiAcd/VX1BxcTgAriuwkw=; b=MSqmmGCx2TBHfJwq6nBE1ZvCH98/OhIWQ3j1bSyuRxxF1G48rG++PcZWpvgcvHujtHQbSp yqdXwBPTF0tlbx7A8NCNAphpjv+0c51OymRxyoJq9gRkuSyJFZB8CcG3vyScTQ5pUVRpCm ZtzugxU0jGCqgWYjpL8OdH5Fpvky/BSmTj4BZzdulfWIrImflVwGKTs22K/xhMkXoeDe/1 deOcGzmecb/TTcEHDzKY31eX2yBALHNA+8c7x+4OyuO6Y2T6NEPH5GwQgv5wt7qSKn/pZx EehdH95+ptj6F1SsDHtksWZ1DScCpNFmAKF2ECHDj/cfuQ+0mPhFofawKKSEWw== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:41 +0200 Subject: [PATCH v11 01/15] drm/vkms: Code formatting 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: quoted-printable Message-Id: <20240930-yuv-v11-1-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen , =?utf-8?q?Ma=C3=ADra_Canal?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4941; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=+UNcxZgMXrYbfQ0Wk9GKtPGOAGGqTYaVl8i/PMhH4u4=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRtmPjVjnUBnnFpY/M3C/CXVkX52LI/NIyCy VV99iVsFV+JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbQAKCRAgrS7GWxAs 4ohlD/0Y/tgQBhM88roTcVd4dsh5cq/+WygCW8oooepbRO0qMVuMB0SLiBzdP4G3Sgnt4OGvhHG e5NZqOMyibfNuN21Jy8fmX5UygyrQN6r127NAyomxjdFeNtLhcSzTLKpFGeBjLRl5ToPzdDO8eD pxx0xLmMvMhy46PuyHmBO1JLiAxovw7l9x2qdq29cQFqL0ZuzVHDIZk/RzOkAyBLKNE4Rp7c1Pa kEmfQf/9f3XlWk6p40+BrNZ+TbV64IHPowwrF1TdGmJfBfNVaV0jsmvXxtnIpf6Ij+GCwilEI5X m8NuEgcWkzFVo/kzWhUZY5ejZ3UH61VAeXuNAJoaoW09M39CMIqF3jgpAOY8QHD3X3UUxJpgEFO R1Waizp+zd7YUmAHJay1awGBnJkwUwyiF4pYUUUvjocC/jxTGn4TJAJCXFVmt2DKFwkIaZ26wK4 xXdHVTA6YUesaYPZ0uAm/Tmmq0RxOov1UBQy0Rbx+lUYITrQ6QuG9dalKIOT/bUNQU5uVQPwfxt KCFMcCBY3jZHBFYjMyOohenSPx02kFjcQt5JtFnJJU/NXsvpjCZT+xLaA6zkNKddtPwzY/JDDXR CBYreSK6twOpE57pBeuN+00y6elrzZP7zZWNT1jChWIQANueGyEDu9rqHo69FupMBg0sbdzF1FF a/MrmOmXoCyB6QA== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Few no-op changes to remove double spaces and fix wrong alignments. Reviewed-by: Pekka Paalanen Reviewed-by: Ma=C3=ADra Canal Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_composer.c | 10 +++++----- drivers/gpu/drm/vkms/vkms_crtc.c | 6 ++---- drivers/gpu/drm/vkms/vkms_drv.c | 3 +-- drivers/gpu/drm/vkms/vkms_plane.c | 8 ++++---- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vk= ms_composer.c index 57a5769fc994..931e214b225c 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -96,7 +96,7 @@ static u16 lerp_u16(u16 a, u16 b, s64 t) s64 a_fp =3D drm_int2fixp(a); s64 b_fp =3D drm_int2fixp(b); =20 - s64 delta =3D drm_fixp_mul(b_fp - a_fp, t); + s64 delta =3D drm_fixp_mul(b_fp - a_fp, t); =20 return drm_fixp2int(a_fp + delta); } @@ -309,8 +309,8 @@ static int compose_active_planes(struct vkms_writeback_= job *active_wb, void vkms_composer_worker(struct work_struct *work) { struct vkms_crtc_state *crtc_state =3D container_of(work, - struct vkms_crtc_state, - composer_work); + struct vkms_crtc_state, + composer_work); struct drm_crtc *crtc =3D crtc_state->base.crtc; struct vkms_writeback_job *active_wb =3D crtc_state->active_writeback; struct vkms_output *out =3D drm_crtc_to_vkms_output(crtc); @@ -335,7 +335,7 @@ void vkms_composer_worker(struct work_struct *work) crtc_state->gamma_lut.base =3D (struct drm_color_lut *)crtc->state->gamm= a_lut->data; crtc_state->gamma_lut.lut_length =3D crtc->state->gamma_lut->length / sizeof(struct drm_color_lut); - max_lut_index_fp =3D drm_int2fixp(crtc_state->gamma_lut.lut_length - 1); + max_lut_index_fp =3D drm_int2fixp(crtc_state->gamma_lut.lut_length - 1); crtc_state->gamma_lut.channel_value2index_ratio =3D drm_fixp_div(max_lut= _index_fp, u16_max_fp); =20 @@ -374,7 +374,7 @@ void vkms_composer_worker(struct work_struct *work) drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32); } =20 -static const char * const pipe_crc_sources[] =3D {"auto"}; +static const char *const pipe_crc_sources[] =3D { "auto" }; =20 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, size_t *count) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_c= rtc.c index a40295c18b48..39bf9d4247fa 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -188,8 +188,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, return ret; =20 drm_for_each_plane_mask(plane, crtc->dev, crtc_state->plane_mask) { - plane_state =3D drm_atomic_get_existing_plane_state(crtc_state->state, - plane); + plane_state =3D drm_atomic_get_existing_plane_state(crtc_state->state, p= lane); WARN_ON(!plane_state); =20 if (!plane_state->visible) @@ -205,8 +204,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, =20 i =3D 0; drm_for_each_plane_mask(plane, crtc->dev, crtc_state->plane_mask) { - plane_state =3D drm_atomic_get_existing_plane_state(crtc_state->state, - plane); + plane_state =3D drm_atomic_get_existing_plane_state(crtc_state->state, p= lane); =20 if (!plane_state->visible) continue; diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_dr= v.c index 2d1e95cb66e5..19b7322ce49d 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -82,8 +82,7 @@ static void vkms_atomic_commit_tail(struct drm_atomic_sta= te *old_state) drm_atomic_helper_wait_for_flip_done(dev, old_state); =20 for_each_old_crtc_in_state(old_state, crtc, old_crtc_state, i) { - struct vkms_crtc_state *vkms_state =3D - to_vkms_crtc_state(old_crtc_state); + struct vkms_crtc_state *vkms_state =3D to_vkms_crtc_state(old_crtc_state= ); =20 flush_work(&vkms_state->composer_work); } diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index e5c625ab8e3e..5a8d295e65f2 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -117,10 +117,10 @@ static void vkms_plane_atomic_update(struct drm_plane= *plane, memcpy(&frame_info->map, &shadow_plane_state->data, sizeof(frame_info->ma= p)); drm_framebuffer_get(frame_info->fb); frame_info->rotation =3D drm_rotation_simplify(new_state->rotation, DRM_M= ODE_ROTATE_0 | - DRM_MODE_ROTATE_90 | - DRM_MODE_ROTATE_270 | - DRM_MODE_REFLECT_X | - DRM_MODE_REFLECT_Y); + DRM_MODE_ROTATE_90 | + DRM_MODE_ROTATE_270 | + DRM_MODE_REFLECT_X | + DRM_MODE_REFLECT_Y); =20 drm_rect_rotate(&frame_info->rotated, drm_rect_width(&frame_info->rotated= ), drm_rect_height(&frame_info->rotated), frame_info->rotation); --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 2E34F196C86; Mon, 30 Sep 2024 15:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710342; cv=none; b=cwMP4sBfcTD5Ik2KDIF8G8UXj8Hy8WyYwwlRrnu4e7nnbaxoU14p0BT9ohpdeu2ASID8F4TGpSS6eL3Oyqdfkdn1DJ1VKcX29p95gnE2xgzqRfR2oO58xPQCYoUkkU95xvkmYOfl32PLNx/zgHVBnIimkj4bcsWXkPhOtfomZ2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710342; c=relaxed/simple; bh=ZCZchl8YXaJKXMTOIfi3f6uTp8wXE1eZQ6XB+/K8JTg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G7p3cLY77oXGa8xPmkzmOHyS2FgqxnDoYzna+VVzbe/pXz0+3HBR/ko8mz+AmH/J99ES8kZlCs5z6yw/wE+Qk+A16WfIQaJng3dmD8f69D1QHEBqZbWS0NGUqorQEjp52nedFo/5484CGVVRqw79UnbPySbIlwMa1UNA5JDkcuY= 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=jl8RZI6L; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="jl8RZI6L" Received: by mail.gandi.net (Postfix) with ESMTPSA id C901C40008; Mon, 30 Sep 2024 15:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710338; 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=2C5hZ/knWBtoOPrBC9CFpCsHQ2ytwSQQLFNkYLaAoVE=; b=jl8RZI6LQo1VzGknLEiyc2rg65lYYX4dKAQepv6vDK3DZjDJbmqtbl+PIHu34E91P/GAgg lVvFoxBIK6e3o4+Z25uZgJ/Ya7lAkVwDlPTSCR2PgOZMJrSWTWbV5UrN1xlqJLCmjUNc+Q ZEReBxsMaLpM1X6U9Zu7hUCjxCHSuRkfr3LKuoeMdHJPr65+Spd9kNs5UG4vDlK7OkCsNV 4BhqvDPz9AcxnkzRA/4jO320mn3qDAuh8Cw89ys+LjTpxmyKJ8jxAGzyOnrtw9OAUqP6+n MEn41krDqAsn8X5k1Dg0j3ZnbAZraiZXZNo7dYuVTIC6+HZEzY+e1CQk5D6mVw== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:42 +0200 Subject: [PATCH v11 02/15] drm/vkms: Use drm_frame directly 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: quoted-printable Message-Id: <20240930-yuv-v11-2-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen , =?utf-8?q?Ma=C3=ADra_Canal?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4276; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=2sG3hL92AI5p05ggDfRLdPBFv95vU35OetchXGlRuB8=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRtXIjLJANoYTWg8lb1BFlZNXUX9WADboB9l aUu7GhnWiaJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbQAKCRAgrS7GWxAs 4slhD/9o9BzJq2AHhI3tHqcm5RBD9bYeSXrFuIdGfi+NiQaUJiDjgSCuDYnxckMowVBDSpyJdSJ WKvFoZizPIJm4qazjA36YgJsaARgvdNiDK6tF/sBMh3327AdxPj7Q0ZS785/JbErCuupQjLkHvR f91+bd4aJ3C/vAGdv/t45ktOQQ7uEzwkBYVJlwNah71MFBDEoXdlN1c77HcAK8TdacT2vqDDfoA p+omDAXDL3FTIhL9iVK1se7xhor3/YF287ANEinA1Y5uO8vnbf+92ybaOORyz+GbYva5K1eC2xk S/vUde4VcsYhX6AUxE5+03s/KaMcOfUK3Sa+iSXUgG7/cp51zBtA8OzlPK6tbEwOb++t33s7pcX rXzugJOaZ9vjtGPI/+MxMu/6tSp6v8peW4wUZeLlrX2TS/vfyuDEBfUCxMnooGFeIQfsYRlNCx/ sxe3EGvhavgbIUIx5dRqGkh+9m+2thPxlXbwwzo0tZfLFSBtKuh04tQU37rOKbkR3OCIv4jMSe0 QtLA/cfxaKQ6koOdipqCFei+4cfnMDxVB+RS9Jh21DdbX2vZpyckIeNhffB7/jb+uqBjOekCiEV HYK1A7E8QnS204WFXb0woa02TGvx/+9Cmpkoj3BhXWvqdzz10lMB6GRVPIWQ9Ma5c6JPfwsGdcx VqOxNj+mM4JdeJw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Remove intermidiary variables and access the variables directly from drm_frame. These changes should be noop. Signed-off-by: Arthur Grillo Acked-by: Pekka Paalanen Reviewed-by: Ma=C3=ADra Canal Reviewed-by: Louis Chauvet [Louis Chauvet: Applied review from Ma=C3=ADra] Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.h | 3 --- drivers/gpu/drm/vkms/vkms_formats.c | 11 ++++++----- drivers/gpu/drm/vkms/vkms_plane.c | 3 --- drivers/gpu/drm/vkms/vkms_writeback.c | 5 ----- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index 672fe191e239..fcb5a5ff7df7 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -42,9 +42,6 @@ struct vkms_frame_info { struct drm_rect rotated; struct iosys_map map[DRM_FORMAT_MAX_PLANES]; unsigned int rotation; - unsigned int offset; - unsigned int pitch; - unsigned int cpp; }; =20 struct pixel_argb_u16 { diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index e8a5cc235ebb..2a0fbe27d8b2 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -23,8 +23,9 @@ */ static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x= , int y) { - return frame_info->offset + (y * frame_info->pitch) - + (x * frame_info->cpp); + struct drm_framebuffer *fb =3D frame_info->fb; + + return fb->offsets[0] + (y * fb->pitches[0]) + (x * fb->format->cpp[0]); } =20 /** @@ -154,12 +155,12 @@ void vkms_compose_row(struct line_buffer *stage_buffe= r, struct vkms_plane_state u8 *src_pixels =3D get_packed_src_addr(frame_info, y); int limit =3D min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffe= r->n_pixels); =20 - for (size_t x =3D 0; x < limit; x++, src_pixels +=3D frame_info->cpp) { + for (size_t x =3D 0; x < limit; x++, src_pixels +=3D frame_info->fb->form= at->cpp[0]) { int x_pos =3D get_x_position(frame_info, limit, x); =20 if (drm_rotation_90_or_270(frame_info->rotation)) src_pixels =3D get_packed_src_addr(frame_info, x + frame_info->rotated.= y1) - + frame_info->cpp * y; + + frame_info->fb->format->cpp[0] * y; =20 plane->pixel_read(src_pixels, &out_pixels[x_pos]); } @@ -253,7 +254,7 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, struct pixel_argb_u16 *in_pixels =3D src_buffer->pixels; int x_limit =3D min_t(size_t, drm_rect_width(&frame_info->dst), src_buffe= r->n_pixels); =20 - for (size_t x =3D 0; x < x_limit; x++, dst_pixels +=3D frame_info->cpp) + for (size_t x =3D 0; x < x_limit; x++, dst_pixels +=3D frame_info->fb->fo= rmat->cpp[0]) wb->pixel_write(dst_pixels, &in_pixels[x]); } =20 diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index 5a8d295e65f2..21b5adfb44aa 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -125,9 +125,6 @@ static void vkms_plane_atomic_update(struct drm_plane *= plane, drm_rect_rotate(&frame_info->rotated, drm_rect_width(&frame_info->rotated= ), drm_rect_height(&frame_info->rotated), frame_info->rotation); =20 - frame_info->offset =3D fb->offsets[0]; - frame_info->pitch =3D fb->pitches[0]; - frame_info->cpp =3D fb->format->cpp[0]; vkms_plane_state->pixel_read =3D get_pixel_conversion_function(fmt); } =20 diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/v= kms_writeback.c index bc724cbd5e3a..c8582df1f739 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -149,11 +149,6 @@ static void vkms_wb_atomic_commit(struct drm_connector= *conn, crtc_state->active_writeback =3D active_wb; crtc_state->wb_pending =3D true; spin_unlock_irq(&output->composer_lock); - - wb_frame_info->offset =3D fb->offsets[0]; - wb_frame_info->pitch =3D fb->pitches[0]; - wb_frame_info->cpp =3D fb->format->cpp[0]; - drm_writeback_queue_job(wb_conn, connector_state); active_wb->pixel_write =3D get_pixel_write_function(wb_format); drm_rect_init(&wb_frame_info->src, 0, 0, crtc_width, crtc_height); --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 874F41990A1; Mon, 30 Sep 2024 15:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710347; cv=none; b=HR4bxm6yD3cx1X/fEF14rX3DEgBvT8B/DZSiMZMytEbB4pVQYw7HqP9gm8RIpIlrCsnTD/j+xJIHMv54G3mYTzOvsyu3G4f0pssbiGkbforFdnd6Mk4dxdfF38gKeAlUkNvWrD90fD3XkDUC59TZ3KtBiV6TFUVg0D9m4BJFsek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710347; c=relaxed/simple; bh=2wQl/VLOHLkG9pjPWFcWisup0t5KvV8JA6u2m3rRhWQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GhJrAkSvdVOJ+MsKjKx9NtaMCkGUWkUKuURmH2PxOsPUSd3CdYGaKT1kdIbOYFOBFn2brKvlx49ukIojlMmT2MlPK8FDaiQBmijzqmQ9mBcNFK8zogIVuhxIraQwdmUNOWmyL2nU9yTKkSAGLcsJEGKhPt8y643fwtXIeBiHBpY= 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=YtM7iDla; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YtM7iDla" Received: by mail.gandi.net (Postfix) with ESMTPSA id A188340005; Mon, 30 Sep 2024 15:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710343; 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=oMYvnzBIhRioyKhVje/Xu2+NURr078CBubcECinfAuM=; b=YtM7iDlail7kwyzfuuOYHOMYRqxvOWDU3Rzr2FKhWl/mfqU43HRKhBWyuey7OtGvIWOE3C qUMAsqtOaZUFMHOxqMErBSxxAjqFaujiphfyPBa2FIWxdeFy6Fg/MKWiRImBvPQ+7PV/fB PKi162289CfJn/2Be4ZOriHiHyrQmdL0z+lqhPgjYNEI69uY/AFmBFSvh/e/cRFhg5fecj q4KqAQhFhlZ9Wom0ABiv2tUMFnT10HBn/8bcWPBqEdZLs0TcbIyCyklY81bFGvctBJEJr2 6Mmxf2VQ+f1G/JOlMPdBlO1/Cgy9oHzYz26httbg7c4n7z+04tzOIXpOWT+qOw== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:43 +0200 Subject: [PATCH v11 03/15] drm/vkms: Add typedef and documentation for pixel_read and pixel_write functions 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: quoted-printable Message-Id: <20240930-yuv-v11-3-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=13184; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=2wQl/VLOHLkG9pjPWFcWisup0t5KvV8JA6u2m3rRhWQ=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRurxY5qU29i2tsZSFwbcX5rHOlkN1j4BdOV b2aIGt45BSJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbgAKCRAgrS7GWxAs 4q+fEAC9KL+mCD75ejrFcoZy0ppMviXW7DyZTCJu+Vxx7iY4Brt9nQnHU1oBKHUxqt9IrAiqnDh daSZ0i8ntQJNYUHepyQpR1YSEjhstY6sqmbPJRESZZ5OsWLgGD9kPJNyIyTLMqQeWBaFyv2jZsp 5nJ5B3A3mUZNZvEQ20Fqh63UVxoBBKon76ODb8XhnCnzCvbW2y5rFT/bqzYcHOE3R5yqhPzNYqh oHtCUNJS3qz6FJwyG6kWNZ057Jhmastp5cucxQ/xSpwgbz4qBKHYC8BE7ANL1Yzi1rD2+zcQUEs 1gzF+f1Y5Pm/EtJsqNHFlXUFxpI6nBiDHZXeQkRtfHd0S7/wrs8mibI1bFfVlH1IQGDpoyNFc6l MqZJvwc3AkD+QFSIdZE97QZ7u7EqLY/f9XjadLlmDsE0DlSGlM7lKw3o/zrmGnCw94qoI3s4a3L HE8z8gXTkl3HCuzujk+mmOxCXRMln+rLtKKP2L5ORZx2d46eQmTRQ33pIGA94ERkCb7g2aLLNGz QFEyDeMtTBOrI5yecLdWnInMqYeR0tjnzxDril05r8OC1DNPiY4LoVCFmX0shm07vclh2/U3mdR 0+2ZMXsNjhU72Pxh1nDGRYEVDqd5XM7XSCG9Uq1YjirtofaGsGki36/Tl1YYrTp/R+w5YMaBG6y M/TxTNAqHHQXuJA== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Introduce two typedefs: pixel_read_t and pixel_write_t. It allows the compiler to check if the passed functions take the correct arguments. Such typedefs will help ensuring consistency across the code base in case of update of these prototypes. Rename input/output variable in a consistent way between read_line and write_line. A warn has been added in get_pixel_*_function to alert when an unsupported pixel format is requested. As those formats are checked before atomic_update callbacks, it should never happen. Document for those typedefs. Reviewed-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.h | 23 ++++++- drivers/gpu/drm/vkms/vkms_formats.c | 124 ++++++++++++++++++++------------= ---- drivers/gpu/drm/vkms/vkms_formats.h | 4 +- drivers/gpu/drm/vkms/vkms_plane.c | 2 +- 4 files changed, 94 insertions(+), 59 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index fcb5a5ff7df7..137348f4adb2 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -53,12 +53,31 @@ struct line_buffer { struct pixel_argb_u16 *pixels; }; =20 +/** + * typedef pixel_write_t - These functions are used to read a pixel from a + * &struct pixel_argb_u16, convert it in a specific format and write it in= the @dst_pixels + * buffer. + * + * @out_pixel: destination address to write the pixel + * @in_pixel: pixel to write + */ +typedef void (*pixel_write_t)(u8 *out_pixel, struct pixel_argb_u16 *in_pix= el); + struct vkms_writeback_job { struct iosys_map data[DRM_FORMAT_MAX_PLANES]; struct vkms_frame_info wb_frame_info; - void (*pixel_write)(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel); + pixel_write_t pixel_write; }; =20 +/** + * typedef pixel_read_t - These functions are used to read a pixel in the = source frame, + * convert it to `struct pixel_argb_u16` and write it to @out_pixel. + * + * @in_pixel: pointer to the pixel to read + * @out_pixel: pointer to write the converted pixel + */ +typedef void (*pixel_read_t)(u8 *in_pixel, struct pixel_argb_u16 *out_pixe= l); + /** * struct vkms_plane_state - Driver specific plane state * @base: base plane state @@ -69,7 +88,7 @@ struct vkms_writeback_job { struct vkms_plane_state { struct drm_shadow_plane_state base; struct vkms_frame_info *frame_info; - void (*pixel_read)(u8 *src_buffer, struct pixel_argb_u16 *out_pixel); + pixel_read_t pixel_read; }; =20 struct vkms_plane { diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 2a0fbe27d8b2..b9544e67cd4f 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -75,7 +75,7 @@ static int get_x_position(const struct vkms_frame_info *f= rame_info, int limit, i * They are used in the vkms_compose_row() function to handle multiple for= mats. */ =20 -static void ARGB8888_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *ou= t_pixel) +static void ARGB8888_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *out_= pixel) { /* * The 257 is the "conversion ratio". This number is obtained by the @@ -83,48 +83,48 @@ static void ARGB8888_to_argb_u16(u8 *src_pixels, struct= pixel_argb_u16 *out_pixe * the best color value in a pixel format with more possibilities. * A similar idea applies to others RGB color conversions. */ - out_pixel->a =3D (u16)src_pixels[3] * 257; - out_pixel->r =3D (u16)src_pixels[2] * 257; - out_pixel->g =3D (u16)src_pixels[1] * 257; - out_pixel->b =3D (u16)src_pixels[0] * 257; + out_pixel->a =3D (u16)in_pixel[3] * 257; + out_pixel->r =3D (u16)in_pixel[2] * 257; + out_pixel->g =3D (u16)in_pixel[1] * 257; + out_pixel->b =3D (u16)in_pixel[0] * 257; } =20 -static void XRGB8888_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *ou= t_pixel) +static void XRGB8888_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *out_= pixel) { out_pixel->a =3D (u16)0xffff; - out_pixel->r =3D (u16)src_pixels[2] * 257; - out_pixel->g =3D (u16)src_pixels[1] * 257; - out_pixel->b =3D (u16)src_pixels[0] * 257; + out_pixel->r =3D (u16)in_pixel[2] * 257; + out_pixel->g =3D (u16)in_pixel[1] * 257; + out_pixel->b =3D (u16)in_pixel[0] * 257; } =20 -static void ARGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16= *out_pixel) +static void ARGB16161616_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *= out_pixel) { - __le16 *pixels =3D (__force __le16 *)src_pixels; + __le16 *pixel =3D (__le16 *)in_pixel; =20 - out_pixel->a =3D le16_to_cpu(pixels[3]); - out_pixel->r =3D le16_to_cpu(pixels[2]); - out_pixel->g =3D le16_to_cpu(pixels[1]); - out_pixel->b =3D le16_to_cpu(pixels[0]); + out_pixel->a =3D le16_to_cpu(pixel[3]); + out_pixel->r =3D le16_to_cpu(pixel[2]); + out_pixel->g =3D le16_to_cpu(pixel[1]); + out_pixel->b =3D le16_to_cpu(pixel[0]); } =20 -static void XRGB16161616_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16= *out_pixel) +static void XRGB16161616_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *= out_pixel) { - __le16 *pixels =3D (__force __le16 *)src_pixels; + __le16 *pixel =3D (__le16 *)in_pixel; =20 out_pixel->a =3D (u16)0xffff; - out_pixel->r =3D le16_to_cpu(pixels[2]); - out_pixel->g =3D le16_to_cpu(pixels[1]); - out_pixel->b =3D le16_to_cpu(pixels[0]); + out_pixel->r =3D le16_to_cpu(pixel[2]); + out_pixel->g =3D le16_to_cpu(pixel[1]); + out_pixel->b =3D le16_to_cpu(pixel[0]); } =20 -static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_= pixel) +static void RGB565_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *out_pi= xel) { - __le16 *pixels =3D (__force __le16 *)src_pixels; + __le16 *pixel =3D (__le16 *)in_pixel; =20 s64 fp_rb_ratio =3D drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31)); s64 fp_g_ratio =3D drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63)); =20 - u16 rgb_565 =3D le16_to_cpu(*pixels); + u16 rgb_565 =3D le16_to_cpu(*pixel); s64 fp_r =3D drm_int2fixp((rgb_565 >> 11) & 0x1f); s64 fp_g =3D drm_int2fixp((rgb_565 >> 5) & 0x3f); s64 fp_b =3D drm_int2fixp(rgb_565 & 0x1f); @@ -168,12 +168,12 @@ void vkms_compose_row(struct line_buffer *stage_buffe= r, struct vkms_plane_state =20 /* * The following functions take one &struct pixel_argb_u16 and convert it = to a specific format. - * The result is stored in @dst_pixels. + * The result is stored in @out_pixel. * * They are used in vkms_writeback_row() to convert and store a pixel from= the src_buffer to * the writeback buffer. */ -static void argb_u16_to_ARGB8888(u8 *dst_pixels, struct pixel_argb_u16 *in= _pixel) +static void argb_u16_to_ARGB8888(u8 *out_pixel, struct pixel_argb_u16 *in_= pixel) { /* * This sequence below is important because the format's byte order is @@ -185,43 +185,43 @@ static void argb_u16_to_ARGB8888(u8 *dst_pixels, stru= ct pixel_argb_u16 *in_pixel * | Addr + 2 | =3D Red channel * | Addr + 3 | =3D Alpha channel */ - dst_pixels[3] =3D DIV_ROUND_CLOSEST(in_pixel->a, 257); - dst_pixels[2] =3D DIV_ROUND_CLOSEST(in_pixel->r, 257); - dst_pixels[1] =3D DIV_ROUND_CLOSEST(in_pixel->g, 257); - dst_pixels[0] =3D DIV_ROUND_CLOSEST(in_pixel->b, 257); + out_pixel[3] =3D DIV_ROUND_CLOSEST(in_pixel->a, 257); + out_pixel[2] =3D DIV_ROUND_CLOSEST(in_pixel->r, 257); + out_pixel[1] =3D DIV_ROUND_CLOSEST(in_pixel->g, 257); + out_pixel[0] =3D DIV_ROUND_CLOSEST(in_pixel->b, 257); } =20 -static void argb_u16_to_XRGB8888(u8 *dst_pixels, struct pixel_argb_u16 *in= _pixel) +static void argb_u16_to_XRGB8888(u8 *out_pixel, struct pixel_argb_u16 *in_= pixel) { - dst_pixels[3] =3D 0xff; - dst_pixels[2] =3D DIV_ROUND_CLOSEST(in_pixel->r, 257); - dst_pixels[1] =3D DIV_ROUND_CLOSEST(in_pixel->g, 257); - dst_pixels[0] =3D DIV_ROUND_CLOSEST(in_pixel->b, 257); + out_pixel[3] =3D 0xff; + out_pixel[2] =3D DIV_ROUND_CLOSEST(in_pixel->r, 257); + out_pixel[1] =3D DIV_ROUND_CLOSEST(in_pixel->g, 257); + out_pixel[0] =3D DIV_ROUND_CLOSEST(in_pixel->b, 257); } =20 -static void argb_u16_to_ARGB16161616(u8 *dst_pixels, struct pixel_argb_u16= *in_pixel) +static void argb_u16_to_ARGB16161616(u8 *out_pixel, struct pixel_argb_u16 = *in_pixel) { - __le16 *pixels =3D (__force __le16 *)dst_pixels; + __le16 *pixel =3D (__le16 *)out_pixel; =20 - pixels[3] =3D cpu_to_le16(in_pixel->a); - pixels[2] =3D cpu_to_le16(in_pixel->r); - pixels[1] =3D cpu_to_le16(in_pixel->g); - pixels[0] =3D cpu_to_le16(in_pixel->b); + pixel[3] =3D cpu_to_le16(in_pixel->a); + pixel[2] =3D cpu_to_le16(in_pixel->r); + pixel[1] =3D cpu_to_le16(in_pixel->g); + pixel[0] =3D cpu_to_le16(in_pixel->b); } =20 -static void argb_u16_to_XRGB16161616(u8 *dst_pixels, struct pixel_argb_u16= *in_pixel) +static void argb_u16_to_XRGB16161616(u8 *out_pixel, struct pixel_argb_u16 = *in_pixel) { - __le16 *pixels =3D (__force __le16 *)dst_pixels; + __le16 *pixel =3D (__le16 *)out_pixel; =20 - pixels[3] =3D cpu_to_le16(0xffff); - pixels[2] =3D cpu_to_le16(in_pixel->r); - pixels[1] =3D cpu_to_le16(in_pixel->g); - pixels[0] =3D cpu_to_le16(in_pixel->b); + pixel[3] =3D cpu_to_le16(0xffff); + pixel[2] =3D cpu_to_le16(in_pixel->r); + pixel[1] =3D cpu_to_le16(in_pixel->g); + pixel[0] =3D cpu_to_le16(in_pixel->b); } =20 -static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_p= ixel) +static void argb_u16_to_RGB565(u8 *out_pixel, struct pixel_argb_u16 *in_pi= xel) { - __le16 *pixels =3D (__force __le16 *)dst_pixels; + __le16 *pixel =3D (__le16 *)out_pixel; =20 s64 fp_rb_ratio =3D drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31)); s64 fp_g_ratio =3D drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63)); @@ -234,7 +234,7 @@ static void argb_u16_to_RGB565(u8 *dst_pixels, struct p= ixel_argb_u16 *in_pixel) u16 g =3D drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio)); u16 b =3D drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio)); =20 - *pixels =3D cpu_to_le16(r << 11 | g << 5 | b); + *pixel =3D cpu_to_le16(r << 11 | g << 5 | b); } =20 /** @@ -259,13 +259,13 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, } =20 /** - * get_pixel_conversion_function() - Retrieve the correct read_pixel funct= ion for a specific + * get_pixel_read_function() - Retrieve the correct read_pixel function fo= r a specific * format. The returned pointer is NULL for unsupported pixel formats. The= caller must ensure that * the pointer is valid before using it in a vkms_plane_state. * * @format: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) */ -void *get_pixel_conversion_function(u32 format) +pixel_read_t get_pixel_read_function(u32 format) { switch (format) { case DRM_FORMAT_ARGB8888: @@ -279,7 +279,15 @@ void *get_pixel_conversion_function(u32 format) case DRM_FORMAT_RGB565: return &RGB565_to_argb_u16; default: - return NULL; + /* + * This is a bug in vkms_plane_atomic_check(). All the supported + * format must: + * - Be listed in vkms_formats in vkms_plane.c + * - Have a pixel_read callback defined here + */ + pr_err("Pixel format %p4cc is not supported by VKMS planes. This is a ke= rnel bug, atomic check must forbid this configuration.\n", + &format); + BUG(); } } =20 @@ -290,7 +298,7 @@ void *get_pixel_conversion_function(u32 format) * * @format: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) */ -void *get_pixel_write_function(u32 format) +pixel_write_t get_pixel_write_function(u32 format) { switch (format) { case DRM_FORMAT_ARGB8888: @@ -304,6 +312,14 @@ void *get_pixel_write_function(u32 format) case DRM_FORMAT_RGB565: return &argb_u16_to_RGB565; default: - return NULL; + /* + * This is a bug in vkms_writeback_atomic_check. All the supported + * format must: + * - Be listed in vkms_wb_formats in vkms_writeback.c + * - Have a pixel_write callback defined here + */ + pr_err("Pixel format %p4cc is not supported by VKMS writeback. This is a= kernel bug, atomic check must forbid this configuration.\n", + &format); + BUG(); } } diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkm= s_formats.h index cf59c2ed8e9a..3ecea4563254 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -5,8 +5,8 @@ =20 #include "vkms_drv.h" =20 -void *get_pixel_conversion_function(u32 format); +pixel_read_t get_pixel_read_function(u32 format); =20 -void *get_pixel_write_function(u32 format); +pixel_write_t get_pixel_write_function(u32 format); =20 #endif /* _VKMS_FORMATS_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index 21b5adfb44aa..10e9b23dab28 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -125,7 +125,7 @@ static void vkms_plane_atomic_update(struct drm_plane *= plane, drm_rect_rotate(&frame_info->rotated, drm_rect_width(&frame_info->rotated= ), drm_rect_height(&frame_info->rotated), frame_info->rotation); =20 - vkms_plane_state->pixel_read =3D get_pixel_conversion_function(fmt); + vkms_plane_state->pixel_read =3D get_pixel_read_function(fmt); } =20 static int vkms_plane_atomic_check(struct drm_plane *plane, --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 BA7CE1991B3; Mon, 30 Sep 2024 15:32:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710351; cv=none; b=T1x3/be98vLLAqh9fJovdXzYiotx+K3TUfypheqxfpROeVL+5BSGf9ljyOeOH8V+t+6AdSi59B9UCVLVSdmH4aM2ePHhm5Hb/dGGkNZUjKfWBIG9kVokNJSv081LVwjovlTVu7xAN9W070Pd25GIxuzkRtQAv4ZxOhVFzqYLliQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710351; c=relaxed/simple; bh=pcO7PJljvN+5ZMRN62ei/7AXlRn2UOK1It95XxXYjy0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nMBehWwb/zmMBaRQA57kGpnliaY/gR7rZpyVoSGS6RRs2Vt4zxmM1229ftlnNsO8g0PIM29FugQVRb3kzPJs8c7vXZr4oxhw6COWhm2Wx0lSFCyXL3RXuNs3QEH/TbeAygkm8kMmpkSi2rtXTfCFXcFOtU0ymgwfhFRshtq7QOM= 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=IsMMNWID; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="IsMMNWID" Received: by mail.gandi.net (Postfix) with ESMTPSA id 5C46D40003; Mon, 30 Sep 2024 15:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710348; 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=hgr/XrTxDtIWwsS5/vbZyxbbV6+JuFoUt1MFA4iMZ/c=; b=IsMMNWIDmmFRkWcJGsRUrdAMjdowvR+aR4VdfhK77O1FOWJbpQdI99Wc/zjVRd4Nm4tubT 0PmSojVj7/TgxbIfWxo/erVXJkfUK2MU2hLl8TVYmdBjnQvhVCpgEtr0HscovuAMpjUdos ymFf9lMt7MCcdZoDkKVRf37PTXRPnXMV/6CJjgBasaYm80sMA75TiKhAXV5EgloqVUcOL8 vFdWLZQ4VeCdRuhrcdQIvaUaf4oON4xcW9BZH23a4oFxcIGQ0TrGhlnqmpddKIXgkIrxS+ Holago6fDQF4YemLHOOTUTrjsZxyPttBB8NZ+eNHn9idCoUw7KyPy0FnoFFUfw== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:44 +0200 Subject: [PATCH v11 04/15] drm/vkms: Use const for input pointers in pixel_read an pixel_write functions 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: quoted-printable Message-Id: <20240930-yuv-v11-4-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen , =?utf-8?q?Ma=C3=ADra_Canal?= X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=5640; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=pcO7PJljvN+5ZMRN62ei/7AXlRn2UOK1It95XxXYjy0=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRuZgIpJ0xgZLi8eXBKKzyjgAwef1YOxm0A1 LfDux2oKReJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbgAKCRAgrS7GWxAs 4mAdEAC2GjCmS35cV1Obvoph/pYwitgzV83T0hrRAeDGhkb1Xaz9Ol1EBLrpGM8+SpY6O/eiF6y 85Qrr9aTe5EMP65ZjZxGX78l3yvKkm58uCTHgF5lAOTy92pQwws+drbuEFuiJ6SURzQT9OukrFT vVlGjf3IAEG199iVVAO227tqrV1Yju4Brqs9mIEDADHEcKfBwuDDUsktlirhtrfMs5ArQ3kMPeh u9WhRU2XKhy9XQvtQIH9HqNfYZwIZVXxL9KYK5Lq8Xq60kCQrOMZkWtc0PtbtMxpxfkhZBAO1C8 Ctjls/dV/IqljQlxNO9ASJVsVwxD1sSMYbCWebRVY42x7I8GgbrOrGCGedhHVOp3snkhhOZsq2b DUt81AeISVlaTe8uTSzZSAuOSlPTQFQCDLpGMC803f8qhqLGKFX6tKiKiIYKDGVCcz/W+LZ0gTR xiK4/yRCvLuFlzunvhoX1GO8BzF6FQYJtU25prU7cKDIeOxAzETJlhOSeDiqzHB0LAmUaL5kgck WGB4y4gVYRLMcOlrYwS+U7B+rGwyU+PfL0mtEW7eXLaVD8zuxIiDXhGhVI1TH2MX+YI/8cJbqKU 4xxhxYj12fMSdGVj9fdX9psGvlzQSc2VRgD7Fc9Eo3xvidE8NNVx5c2xe/klF2Tpdk1B694Lz6M X69k0P1nE1NPlMw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com As the pixel_read and pixel_write function should never modify the input buffer, mark those pointers const. Reviewed-by: Pekka Paalanen Reviewed-by: Ma=C3=ADra Canal Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.h | 4 ++-- drivers/gpu/drm/vkms/vkms_formats.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index 137348f4adb2..a3020c49d1b3 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -61,7 +61,7 @@ struct line_buffer { * @out_pixel: destination address to write the pixel * @in_pixel: pixel to write */ -typedef void (*pixel_write_t)(u8 *out_pixel, struct pixel_argb_u16 *in_pix= el); +typedef void (*pixel_write_t)(u8 *out_pixel, const struct pixel_argb_u16 *= in_pixel); =20 struct vkms_writeback_job { struct iosys_map data[DRM_FORMAT_MAX_PLANES]; @@ -76,7 +76,7 @@ struct vkms_writeback_job { * @in_pixel: pointer to the pixel to read * @out_pixel: pointer to write the converted pixel */ -typedef void (*pixel_read_t)(u8 *in_pixel, struct pixel_argb_u16 *out_pixe= l); +typedef void (*pixel_read_t)(const u8 *in_pixel, struct pixel_argb_u16 *ou= t_pixel); =20 /** * struct vkms_plane_state - Driver specific plane state diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index b9544e67cd4f..06aef5162529 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -75,7 +75,7 @@ static int get_x_position(const struct vkms_frame_info *f= rame_info, int limit, i * They are used in the vkms_compose_row() function to handle multiple for= mats. */ =20 -static void ARGB8888_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *out_= pixel) +static void ARGB8888_to_argb_u16(const u8 *in_pixel, struct pixel_argb_u16= *out_pixel) { /* * The 257 is the "conversion ratio". This number is obtained by the @@ -89,7 +89,7 @@ static void ARGB8888_to_argb_u16(u8 *in_pixel, struct pix= el_argb_u16 *out_pixel) out_pixel->b =3D (u16)in_pixel[0] * 257; } =20 -static void XRGB8888_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *out_= pixel) +static void XRGB8888_to_argb_u16(const u8 *in_pixel, struct pixel_argb_u16= *out_pixel) { out_pixel->a =3D (u16)0xffff; out_pixel->r =3D (u16)in_pixel[2] * 257; @@ -97,7 +97,7 @@ static void XRGB8888_to_argb_u16(u8 *in_pixel, struct pix= el_argb_u16 *out_pixel) out_pixel->b =3D (u16)in_pixel[0] * 257; } =20 -static void ARGB16161616_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *= out_pixel) +static void ARGB16161616_to_argb_u16(const u8 *in_pixel, struct pixel_argb= _u16 *out_pixel) { __le16 *pixel =3D (__le16 *)in_pixel; =20 @@ -107,7 +107,7 @@ static void ARGB16161616_to_argb_u16(u8 *in_pixel, stru= ct pixel_argb_u16 *out_pi out_pixel->b =3D le16_to_cpu(pixel[0]); } =20 -static void XRGB16161616_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *= out_pixel) +static void XRGB16161616_to_argb_u16(const u8 *in_pixel, struct pixel_argb= _u16 *out_pixel) { __le16 *pixel =3D (__le16 *)in_pixel; =20 @@ -117,7 +117,7 @@ static void XRGB16161616_to_argb_u16(u8 *in_pixel, stru= ct pixel_argb_u16 *out_pi out_pixel->b =3D le16_to_cpu(pixel[0]); } =20 -static void RGB565_to_argb_u16(u8 *in_pixel, struct pixel_argb_u16 *out_pi= xel) +static void RGB565_to_argb_u16(const u8 *in_pixel, struct pixel_argb_u16 *= out_pixel) { __le16 *pixel =3D (__le16 *)in_pixel; =20 @@ -173,7 +173,7 @@ void vkms_compose_row(struct line_buffer *stage_buffer,= struct vkms_plane_state * They are used in vkms_writeback_row() to convert and store a pixel from= the src_buffer to * the writeback buffer. */ -static void argb_u16_to_ARGB8888(u8 *out_pixel, struct pixel_argb_u16 *in_= pixel) +static void argb_u16_to_ARGB8888(u8 *out_pixel, const struct pixel_argb_u1= 6 *in_pixel) { /* * This sequence below is important because the format's byte order is @@ -191,7 +191,7 @@ static void argb_u16_to_ARGB8888(u8 *out_pixel, struct = pixel_argb_u16 *in_pixel) out_pixel[0] =3D DIV_ROUND_CLOSEST(in_pixel->b, 257); } =20 -static void argb_u16_to_XRGB8888(u8 *out_pixel, struct pixel_argb_u16 *in_= pixel) +static void argb_u16_to_XRGB8888(u8 *out_pixel, const struct pixel_argb_u1= 6 *in_pixel) { out_pixel[3] =3D 0xff; out_pixel[2] =3D DIV_ROUND_CLOSEST(in_pixel->r, 257); @@ -199,7 +199,7 @@ static void argb_u16_to_XRGB8888(u8 *out_pixel, struct = pixel_argb_u16 *in_pixel) out_pixel[0] =3D DIV_ROUND_CLOSEST(in_pixel->b, 257); } =20 -static void argb_u16_to_ARGB16161616(u8 *out_pixel, struct pixel_argb_u16 = *in_pixel) +static void argb_u16_to_ARGB16161616(u8 *out_pixel, const struct pixel_arg= b_u16 *in_pixel) { __le16 *pixel =3D (__le16 *)out_pixel; =20 @@ -209,7 +209,7 @@ static void argb_u16_to_ARGB16161616(u8 *out_pixel, str= uct pixel_argb_u16 *in_pi pixel[0] =3D cpu_to_le16(in_pixel->b); } =20 -static void argb_u16_to_XRGB16161616(u8 *out_pixel, struct pixel_argb_u16 = *in_pixel) +static void argb_u16_to_XRGB16161616(u8 *out_pixel, const struct pixel_arg= b_u16 *in_pixel) { __le16 *pixel =3D (__le16 *)out_pixel; =20 @@ -219,7 +219,7 @@ static void argb_u16_to_XRGB16161616(u8 *out_pixel, str= uct pixel_argb_u16 *in_pi pixel[0] =3D cpu_to_le16(in_pixel->b); } =20 -static void argb_u16_to_RGB565(u8 *out_pixel, struct pixel_argb_u16 *in_pi= xel) +static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 = *in_pixel) { __le16 *pixel =3D (__le16 *)out_pixel; =20 --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 45A5F199223; Mon, 30 Sep 2024 15:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710357; cv=none; b=AIfH3oEBEQdDgeGTQaKgmQw/gUoDaN749C1o/4602b0wzGRDNUWLGlJtdSshwrzfJB6YOgV1LMm8zmFsvs64MZ2/bxFvJCzwt/0H0KSvmAXOFeXMU6NfBtktE/VjIKq22hotqpK6UvhC37Ie06TtiBMli5ath9MlzCBbYC4Magk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710357; c=relaxed/simple; bh=WSLobhH0HgpInydxPdlo3xquv0fIb51hh/0x7kvEA8g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hlU1IWe7EFng27AtoxXIw3MCtsJ+tRL73HEjgr8ActWcsQET8d7fOh+Raxvqwj2NO0ecJTOpwCtmNw0UsAo/JKxtWPiLoHfeJu5ieygnKUeEczB11dCm3DHBhDRG3Zrx+Pw9QMQRtpWT+0fWcUc3sZRr3pX6/8bBMRny5A34vQw= 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=LXjhYvty; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="LXjhYvty" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9579240009; Mon, 30 Sep 2024 15:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710353; 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=KPJGKEsxz1PC1IeGIUlzazKnNt9mMdttLIEPvXgoXtI=; b=LXjhYvtyr7lFynAHwGox1kivO5IYV7KKAPiUPP4e/6ZVr+gHVsuvhSs9BP34Uaiv30Dnvo tnm+s9OviHuXRMG5s9RbuJPg2Jce9QcK1TAC6DnPo90LJyYHNQ5EmHvoZe679w9St4iq1s 5aKWT+LKhKw3L0OqOqP46847eXo62NPuuGpfukTKemmf5JUzBun+Y2lpsA/h+VlWdVs8Gl Cmdvp970ncS3GuqG9POVGEdTWscDHiZSKD3G1ZhtDGxdnrS95KPn16JA/RYBsZ2hLA0Nri voWmvtHmTW3RP/Chg/HG9RJ3wmO9ek/wAsE73r69CZHg3VXEcsEDuG9gamZDmg== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:45 +0200 Subject: [PATCH v11 05/15] 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: quoted-printable Message-Id: <20240930-yuv-v11-5-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=8793; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=WSLobhH0HgpInydxPdlo3xquv0fIb51hh/0x7kvEA8g=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRuugdVNx9wj//VDGBzfc8d6PEKwEnRg1wq2 RMxFHYYsd6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbgAKCRAgrS7GWxAs 4tESEACdIfAWRAVCnfwL9zSzIt57q5XA1n/SF6z4vtNkfe35MxE66wLUJHg3NNwOoDhcKoJy6LJ tJ1PqEFJXbQUC0ScGgQiQMsEQIepmAUFbPtkx+jPLrlfgcj1xDVWeTAEnvb4lBimCfXXw6Qjl3c 2UH0OVgEkRA5JLI0mgm5HAk45DeGQ689A3GFoW5lHKjeYJ7FLV2umtdWk24gSGK90fwLNm8SOzJ bwXySGmvICPrzp8Jbj/s5RE/lnmVEKQZ5tS294C2XDHDbBqmbfifqolU161FD/xHMbH+QjaOrzA LVAqRJt86yTxZninl0vVmN/+xWDGoqR5Em5gw5oab9tWWdjXz93B0mB9e7cfxL38PE/oAflFYjq ULtst7f81WGO6LCiRsWL1WOMK5QpxmTQ/DlL8QFGLaFandiP9Bg+txI2ycZ67OpEeiVmyPFKbVu AoFvkXqvwG/jJFM1DgQJnqfowK2ULFDt/4uuskJbMEnloKBSFAwOfPVHwuPuBWJl2BIz5nd1+Jm 9n+2jMA8Am7N3WAI7Qw7PDOhtf0ZJ4zx2H4iqA4iUtksVFWuMSTuPoFLSaqg9LOq3/7Qbn9c4MU sIQWQhi2tkbtB6FAS7opmjE7cp46yQOFHKxz5ljcweyBZXgWVjT6TEFYZpm5ILzQ+qZFekic6VQ JWwPbXbvJgulk1g== 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 =3D=3D block_w =3D=3D 1. To avoid confusion and allow e= asier 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 | 114 ++++++++++++++++++++++++++++----= ---- 1 file changed, 91 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 06aef5162529..7f932d42394d 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -10,22 +10,46 @@ #include "vkms_formats.h" =20 /** - * 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 pix= el 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: The returned X coordinate of the requested pixel in the block + * @rem_y: The returned Y coordinate of the requested pixel in the block * - * The caller must ensure that the framebuffer associated with this reques= t uses a pixel format - * where block_h =3D=3D block_w =3D=3D 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* f= or 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 bloc= k. + * For example, if the format is DRM_FORMAT_R1 and the requested coordinat= e 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) =3D (5, 0) + * + * With this function, the caller just have to extract the correct pixel f= rom 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 =3D frame_info->fb; + const struct drm_format_info *format =3D frame_info->fb->format; + /* Directly using x and y to multiply pitches and format->ccp is not suff= icient because + * in some formats a block can represent multiple pixels. + * + * Dividing x and y by the block size allows to extract the correct offse= t of the block + * containing the pixel. + */ =20 - return fb->offsets[0] + (y * fb->pitches[0]) + (x * fb->format->cpp[0]); + int block_x =3D x / drm_format_info_block_width(format, plane_index); + int block_y =3D y / drm_format_info_block_height(format, plane_index); + int block_pitch =3D fb->pitches[plane_index] * drm_format_info_block_heig= ht(format, + plane_index); + *rem_x =3D x % drm_format_info_block_width(format, plane_index); + *rem_y =3D y % drm_format_info_block_height(format, plane_index); + *offset =3D fb->offsets[plane_index] + + block_y * block_pitch + + block_x * format->char_per_block[plane_index]; } =20 /** @@ -35,30 +59,71 @@ 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: The returned X coordinate of the requested pixel in the block + * @rem_y: The returned Y 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 ch= annel - * comes immediately after another in the memory. And therefore, this func= tion - * 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 b= lock. * - * The caller must ensure that the framebuffer associated with this reques= t uses a pixel format - * where block_h =3D=3D block_w =3D=3D 1, otherwise the returned pointer c= an 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 =3D pixel_offset(frame_info, x, y); + int offset; =20 - return (u8 *)frame_info->map[0].vaddr + offset; + packed_pixels_offset(frame_info, x, y, plane_index, &offset, rem_x, rem_y= ); + *addr =3D (u8 *)frame_info->map[0].vaddr + offset; } =20 -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 =3D=3D block_w= =3D=3D 1. + */ +static void packed_pixels_addr_1x1(const struct vkms_frame_info *frame_inf= o, + 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) !=3D 1, + "%s() only support formats with block_w =3D=3D 1", __func__); + WARN_ONCE(drm_format_info_block_height(frame_info->fb->format, + plane_index) !=3D 1, + "%s() only support formats with block_h =3D=3D 1", __func__); + + packed_pixels_offset(frame_info, x, y, plane_index, &offset, &rem_x, + &rem_y); + *addr =3D (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 =3D frame_info->src.x1 >> 16; int y_src =3D 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= ) !=3D 1, + "%s() only support formats with block_w =3D=3D 1", __func__); + WARN_ONCE(drm_format_info_block_height(frame_info->fb->format, plane_inde= x) !=3D 1, + "%s() only support formats with block_h =3D=3D 1", __func__); =20 - 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; } =20 static int get_x_position(const struct vkms_frame_info *frame_info, int li= mit, int x) @@ -152,14 +217,14 @@ void vkms_compose_row(struct line_buffer *stage_buffe= r, struct vkms_plane_state { struct pixel_argb_u16 *out_pixels =3D stage_buffer->pixels; struct vkms_frame_info *frame_info =3D plane->frame_info; - u8 *src_pixels =3D get_packed_src_addr(frame_info, y); + u8 *src_pixels =3D get_packed_src_addr(frame_info, y, 0); int limit =3D min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffe= r->n_pixels); =20 for (size_t x =3D 0; x < limit; x++, src_pixels +=3D frame_info->fb->form= at->cpp[0]) { int x_pos =3D get_x_position(frame_info, limit, x); =20 if (drm_rotation_90_or_270(frame_info->rotation)) - src_pixels =3D get_packed_src_addr(frame_info, x + frame_info->rotated.= y1) + src_pixels =3D get_packed_src_addr(frame_info, x + frame_info->rotated.= y1, 0) + frame_info->fb->format->cpp[0] * y; =20 plane->pixel_read(src_pixels, &out_pixels[x_pos]); @@ -250,7 +315,10 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, { struct vkms_frame_info *frame_info =3D &wb->wb_frame_info; int x_dst =3D frame_info->dst.x1; - u8 *dst_pixels =3D 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 =3D src_buffer->pixels; int x_limit =3D min_t(size_t, drm_rect_width(&frame_info->dst), src_buffe= r->n_pixels); =20 --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 6D9B5199930; Mon, 30 Sep 2024 15:32:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710362; cv=none; b=YK0sSXaLmuaHhHA3J6ZDnu8A7utXc1PJCFRPw3OqdAW3jMjeK80CxPHhTp2kLGTP5//OtMhBjIzccTCk9B317GwkKvBksbVKi+CUCV8CbbR9bFk7BHos4INTPZzF3SLd28NC5EEUdIDJUEjznBYwDWYRgj6TUFsLSqkB2H5SptE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710362; c=relaxed/simple; bh=r2/XngenrNzJPC8UuP2Lk3h2Erls9ge8Xk7h7YOWlsc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KpdeLVO4FLMsZ87Uaujbz4m8gbsKOrR5ZIBaerQnuKTaWfSOfh8mxpMd7CrGO7BURq8J/ywa68q9G0e1V527+Gq5l95FPjI/e79e+ENPmxihgg5CNh0vdnerltgT1nlElifdW7WEjhyJeNvvwNNgoSogrZDO1GB6XtSowU4+ewU= 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=hzWiI7Z9; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="hzWiI7Z9" Received: by mail.gandi.net (Postfix) with ESMTPSA id 014A240005; Mon, 30 Sep 2024 15:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710358; 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=HYxQHT0hznL90lhhiFvano2jVpncd0wNCg9mS2aefmo=; b=hzWiI7Z9iEnwjY/DlJlwFlR2pN4SZCnr0rmMym0CkP3hMKyGUcrf5NtnyJvW06icLhs07/ NAYt5F24U6IAYTfR9GNooONDimURf1T1I5L50nlFNCw3DUOohZVmJ8HlQNSC9SGtTvv0SK dSHRXkCuSP8pZWQ73Gb6UkhGFvU93OOu8nk2fBE5pwS5xSaeBHiABOLm72A9AMlJoG1YJZ +VlCMGSt+Z6p2soLrPikC3/juQS9PDnYd50Os6wncyoq46wgf/iR8dcBUMPcY0QNog3+hc xTYaa8V3nK29hvNqMkzfA5/5f5xWCPVZBcCDYutUjZWcBbj87BXGfM4FoR8Adw== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:46 +0200 Subject: [PATCH v11 06/15] 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: quoted-printable Message-Id: <20240930-yuv-v11-6-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4075; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=r2/XngenrNzJPC8UuP2Lk3h2Erls9ge8Xk7h7YOWlsc=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRupNVSNrTrDQDeULOhRsvfoLPoDbOks911p hSc3DcNjGOJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbgAKCRAgrS7GWxAs 4urfEACIeW8VqNzR2toAFQiKbAAGYvf7oYupQ0huQpcW4fyNcxqztO271jxdGmYE0sNDsWIVN0u WeBY4D1RObmNh6DfZF2xqtgYvOMVtblyuJwssrYSzn5DbXffbwHQ8mmX5+0JvpEmfsNYdHxOb/I 8xZSnyMZQ/X+bOMRvv/42rTKUMb+xRbbwa75fCH8amzrdULH8+ykABYvBGPTgh010JN7Jyd9km6 H6mt/sN77omBaRDgAUIDNimnx7ACKqHE+VTSYqMi8MZhc/sSKWbjUru7IwnqffqslUVXflvR8kE 9uDTGyJwV1uwhj7AYwDXJm5/azKhoUHDpQtse2aDW3eDYIgq6JCRv/Ee5+K7Pr3+1Gujm6ir4iD bSbWUim4Cex3VxIW1fNk01dUNVjvKZ35wEcj/i2hIqJi+tpLY3adeued6ZS7eLc4EVA42VuTnbW hTVIKQ5rxbCaU+5CLAZQkdq/SK/s45PwCSyGNHdWSTAOjrHvZnoOdAZ2RJhU19KGx0uCRa8Zdzy ZpklidUxRYXgjPWBAztBYbCfiSW5UPMV06iASK9+PsZB2+3rDDtVWuZo1G1AoDBmLlAzDt5LzJo B0jvmBGFtEiwDM4WEXv5ru+aOPFpgPJ6Qh3jLebsWkMv0nslasrcUhe5culUYgTuN5UbkA/1Ep3 JyrhL81EF0ceS3g== 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/vk= ms_composer.c index 931e214b225c..4d220bbb023c 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) =20 /** * 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 =3D frame_info->dst.x1; - struct pixel_argb_u16 *out =3D output_buffer->pixels + x_dst; - struct pixel_argb_u16 *in =3D stage_buffer->pixels; - int x_limit =3D min_t(size_t, drm_rect_width(&frame_info->dst), - stage_buffer->n_pixels); - - for (int x =3D 0; x < x_limit; x++) { - out[x].a =3D (u16)0xffff; - out[x].r =3D pre_mul_blend_channel(in[x].r, out[x].r, in[x].a); - out[x].g =3D pre_mul_blend_channel(in[x].g, out[x].g, in[x].a); - out[x].b =3D pre_mul_blend_channel(in[x].b, out[x].b, in[x].a); + struct pixel_argb_u16 *out =3D &output_buffer->pixels[x_start]; + const struct pixel_argb_u16 *in =3D stage_buffer->pixels; + + for (int i =3D 0; i < pixel_count; i++) { + out[i].a =3D (u16)0xffff; + out[i].r =3D pre_mul_blend_channel(in[i].r, out[i].r, in[i].a); + out[i].g =3D pre_mul_blend_channel(in[i].g, out[i].g, in[i].a); + out[i].b =3D pre_mul_blend_channel(in[i].b, out[i].b, in[i].a); } } =20 @@ -183,7 +179,7 @@ static void blend(struct vkms_writeback_job *wb, { struct vkms_plane_state **plane =3D crtc_state->active_planes; u32 n_active_planes =3D crtc_state->num_active_planes; - int y_pos; + int y_pos, x_dst, pixel_count; =20 const struct pixel_argb_u16 background_color =3D { .a =3D 0xffff }; =20 @@ -201,14 +197,16 @@ static void blend(struct vkms_writeback_job *wb, =20 /* The active planes are composed associatively in z-order. */ for (size_t i =3D 0; i < n_active_planes; i++) { + x_dst =3D plane[i]->frame_info->dst.x1; + pixel_count =3D min_t(int, drm_rect_width(&plane[i]->frame_info->dst), + (int)stage_buffer->n_pixels); y_pos =3D get_y_pos(plane[i]->frame_info, y); =20 if (!check_limit(plane[i]->frame_info, y_pos)) continue; =20 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); } =20 apply_lut(crtc_state, output_buffer); --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 DBE3E199EB8; Mon, 30 Sep 2024 15:32:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710367; cv=none; b=hpVtvT4Lg0KTzeXAA597IUkEvnQMgX3B9K+A8fmG74TpPUneduIriKIITntG5RYT/ahIYobkTbpJ9KeulfC31TvtzibogGNpeJj4Usle7Nh3pcp6eda/sKjG5VrU3dVrAi6sQsnin/1fLwOfZoKjOq+zJQL76E/HcCHrnWBr2/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710367; c=relaxed/simple; bh=6W9rv40tuYJEZ28RMBweCevdGJE9o2DSx2qeLSMpRm4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aClmhk3Ib5NAkoHwgeeY2sb+vDpQFtm4YunYmSX/mGQFyKDu9/S52yWKPROZE2FXwjO0hVykZSKUcUvosEFKp9zEw2YMLioJi6M7hXamD0OlgCHs0Zlmfi67dlZhqdQn/RURM5/05PvNko83/gyFSNXFjNU4pXgrbm2HEv5cAjA= 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=T+L12uFN; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="T+L12uFN" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4425040002; Mon, 30 Sep 2024 15:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710364; 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=ZNMLvLMnHeJWYC5Vs72z6cHyMVRK581ZUkwykAbDkYE=; b=T+L12uFNNk4FeUnKu/FrLJPzf4cKEkIVHvg3RuvJQur5cIrBEStS3ZCmjHSgBcC5/q28kK N/m7FQUcTqOOGvbYLzYNNiFGg7XP7B0yYCE+G4lZpAfvIe3qRBpO5eUqyyby333WAWOH4W 5jSKQI+DA+2+RWK6Ah4ZNhPZvQGSp8RikNcFIzMxyleA51R3ORvg7vun2gxGyNCrBK9zAe xFBrqNAJnyWiEqsrqNavCYnmByCPQIYLxxp3iE80+ymNAe5qGzw6ZXR7jQBiijadyRSDwu v0GYimnE3362lVH3fRcY69OvV28NEb4bS8zyFunTR8UaWk4Q/U7gqgxs1vUegQ== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:47 +0200 Subject: [PATCH v11 07/15] drm/vkms: Introduce pixel_read_direction enum 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: quoted-printable Message-Id: <20240930-yuv-v11-7-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=5166; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=6W9rv40tuYJEZ28RMBweCevdGJE9o2DSx2qeLSMpRm4=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRvwu0x0cQvYApyOI89R4YNMWwjfFa2T30kp rA08X6AlZmJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbwAKCRAgrS7GWxAs 4jSNEADEOS+5V97rHc3uaZ9fN4Tl3SvcpNfmlroCWvTp0594rZz5x7n2gfs6xfFrnEA4POflGVQ UOcUDRAYtfPetGRbC5Bkq20yucUE/bYFTCuz7xvyMdoM+A8P8JrbJraE8OKLBzB0IXJ9SA+4cLG PxewBPVDkgWweN7B8JSR8Q+cSuay1GngeTCBL3lps480PfrxUAIhdb2dldv7IsBcBOcQIhD59fb MSmJlhdtRQ8tQIArxRxIwUOkKKf+IACYTgiJtCdhfoGZaOCLtFyLMwuGh/039qYZHk5VcD9nZGO 12FQScXNUy9FuCYNpL3MHLUJTwa4e2EGQ2g3qHkbI+DqSvrK9UJXXYEdD999kk41ku8SED/g1Ji obHzUBJ7zQkmGKW0992mR1B2upwd7m1rkY6dGgs7tYFppJ5UkOb695nDAiLRo7o29ki6fXYYvZB TQ220PJkf3cG3eA1KkoxMH1+6mzUAneQ0FqficxtqtM+vrP+/xXlk2YDZ2fyZguo0rF6dXPVhTI ioupSJA0Sk1bEs7PEKKGx+fQi8VRZ15K6gNrjVdRuucA5SjXxpSZCV5nlJYD7Dji3QlTD649B77 6ujfXaRVIgLhH+L75ZcmsqLnOc7cOjgyj1cKgRoT0mFy17j0pFzQJFNCb0mV5BXIGWfZRLozk5w XSlL82sC0HkaV8A== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com The pixel_read_direction enum is useful to describe the reading direction in a plane. It avoids using the rotation property of DRM, which not practical to know the direction of reading. This patch also introduce two helpers, one to compute the pixel_read_direction from the DRM rotation property, and one to compute the step, in byte, between two successive pixel in a specific direction. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_composer.c | 44 ++++++++++++++++++++++++++++++++= ++++ drivers/gpu/drm/vkms/vkms_drv.h | 11 +++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 32 ++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vk= ms_composer.c index 4d220bbb023c..4ebeaf58fa75 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -159,6 +159,50 @@ static void apply_lut(const struct vkms_crtc_state *cr= tc_state, struct line_buff } } =20 +/** + * direction_for_rotation() - Get the correct reading direction for a give= n rotation + * + * @rotation: Rotation to analyze. It correspond the field @frame_info.rot= ation. + * + * This function will use the @rotation setting of a source plane to compu= te the reading + * direction in this plane which correspond to a "left to right writing" i= n the CRTC. + * For example, if the buffer is reflected on X axis, the pixel must be re= ad from right to left + * to be written from left to right on the CRTC. + */ +static enum pixel_read_direction direction_for_rotation(unsigned int rotat= ion) +{ + struct drm_rect tmp_a, tmp_b; + int x, y; + + /* + * Points A and B are depicted as zero-size rectangles on the CRTC. + * The CRTC writing direction is from A to B. The plane reading direction + * is discovered by inverse-transforming A and B. + * The reading direction is computed by rotating the vector AB (top-left = to top-right) in a + * 1x1 square. + */ + + tmp_a =3D DRM_RECT_INIT(0, 0, 0, 0); + tmp_b =3D DRM_RECT_INIT(1, 0, 0, 0); + drm_rect_rotate_inv(&tmp_a, 1, 1, rotation); + drm_rect_rotate_inv(&tmp_b, 1, 1, rotation); + + x =3D tmp_b.x1 - tmp_a.x1; + y =3D tmp_b.y1 - tmp_a.y1; + + if (x =3D=3D 1 && y =3D=3D 0) + return READ_LEFT_TO_RIGHT; + else if (x =3D=3D -1 && y =3D=3D 0) + return READ_RIGHT_TO_LEFT; + else if (y =3D=3D 1 && x =3D=3D 0) + return READ_TOP_TO_BOTTOM; + else if (y =3D=3D -1 && x =3D=3D 0) + return READ_BOTTOM_TO_TOP; + + WARN_ONCE(true, "The inverse of the rotation gives an incorrect direction= ."); + return READ_LEFT_TO_RIGHT; +} + /** * blend - blend the pixels from all planes and compute crc * @wb: The writeback frame buffer metadata diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index a3020c49d1b3..b3e53b607039 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -69,6 +69,17 @@ struct vkms_writeback_job { pixel_write_t pixel_write; }; =20 +/** + * enum pixel_read_direction - Enum used internaly by VKMS to represent a = reading direction in a + * plane. + */ +enum pixel_read_direction { + READ_BOTTOM_TO_TOP, + READ_TOP_TO_BOTTOM, + READ_RIGHT_TO_LEFT, + READ_LEFT_TO_RIGHT +}; + /** * typedef pixel_read_t - These functions are used to read a pixel in the = source frame, * convert it to `struct pixel_argb_u16` and write it to @out_pixel. diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 7f932d42394d..d0e7dfc1f0d3 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -79,6 +79,38 @@ static void packed_pixels_addr(const struct vkms_frame_i= nfo *frame_info, *addr =3D (u8 *)frame_info->map[0].vaddr + offset; } =20 +/** + * get_block_step_bytes() - Common helper to compute the correct step valu= e between each pixel block + * to read in a certain direction. + * + * @fb: Framebuffer to iter on + * @direction: Direction of the reading + * @plane_index: Plane to get the step from + * + * As the returned count is the number of bytes between two consecutive bl= ocks in a direction, + * the caller may have to read multiple pixels before using the next one (= for example, to read from + * left to right in a DRM_FORMAT_R1 plane, each block contains 8 pixels, s= o the step must be used + * only every 8 pixels). + */ +static int get_block_step_bytes(struct drm_framebuffer *fb, enum pixel_rea= d_direction direction, + int plane_index) +{ + switch (direction) { + case READ_LEFT_TO_RIGHT: + return fb->format->char_per_block[plane_index]; + case READ_RIGHT_TO_LEFT: + return -fb->format->char_per_block[plane_index]; + case READ_TOP_TO_BOTTOM: + return (int)fb->pitches[plane_index] * drm_format_info_block_width(fb->f= ormat, + plane_index); + case READ_BOTTOM_TO_TOP: + return -(int)fb->pitches[plane_index] * drm_format_info_block_width(fb->= format, + plane_index); + } + + return 0; +} + /** * packed_pixels_addr_1x1() - Get the pointer to the block containing the = pixel at the given * coordinates --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 EC504199EB8; Mon, 30 Sep 2024 15:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710374; cv=none; b=ug3mrsDbaX9hCkvAL3ceK0DJq09kcRD9mYep6OSn22LDNSCGk02IthkaCLAAzShEuGPomRxBi95+DVv3TN09gVdwNBDw0I5BzTrM0lAflwwsUvVSxzz/WNIky4da2u3zmXdlPfI5Vi66hPf2PDZW4BPgKowDy6auaU9aHlyE2aI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710374; c=relaxed/simple; bh=f3TbPgxlelOttXti8hPZLCwJpZjCQO/TZTgk5ec9z60=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pBVcvUEUhrNfdZV1CyJq7eBhnedEkdIqAs8qGc4DOF+fyW5D2HUZ9K6J9Gr/XzAYU/HsiMKK8q78YEBfdyhvgUZNjCu8iCsA7tg9bo5Efh52LEI/XYCDAS4cnSD61A9IcW5ZeUwQFK7fjekviTpZ8byxv87fdSijkNWC6UQpWIA= 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=PGd9nGog; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="PGd9nGog" Received: by mail.gandi.net (Postfix) with ESMTPSA id 0206740009; Mon, 30 Sep 2024 15:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710370; 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=jwpLfhdt+pxuL+KLWtUp5xEJoU3EBfGr5nEp1otN8ps=; b=PGd9nGogpw4gGuazhaEKQjcPifckq3vOHYYxLL5fb2FpIAPxfLE8MLzryso80NUeKyQCXK gxSsn/eVDYP/w3Y12myx+NmmmvS6DQ79lNBF0X1jLQBo+WRRF338dRsou5+8kn2T/aO8oZ mtUXIH45Y7+BDMIqA4JE7RJsygwQML+gTXhIGmz2Yp6GL1nNU5RSNH4MqBxEUEJ/BV91ws L+OjsIWSecVBWfi7GLQkCc73nvqEh0tjF/fYIx6qVSTBHHjSPlOY6RYIDuORBYzwBqokBS B8dfmoGs6uUZV5auy9lORriQQREQze1M/x2LBhMNvR25mXitPt6raucTO+7dAw== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:48 +0200 Subject: [PATCH v11 08/15] drm/vkms: Re-introduce line-per-line composition algorithm 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: quoted-printable Message-Id: <20240930-yuv-v11-8-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=30219; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=f3TbPgxlelOttXti8hPZLCwJpZjCQO/TZTgk5ec9z60=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRvYfJlJ/s41SygKrGI4NswztljOaVZu7XOT N0Vfcrg0nmJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbwAKCRAgrS7GWxAs 4vQcEACCCCypXsDT9ntvaY8i3hPll0T01VLm7xV5V8O4gL2JmnjifXDNdyceipD5PhjXUbJwBqV Ce9SyNhh2Mf1fYcA4tc7LGHUtrGW46nXOQNOS1Kbr4/C8uyKceNxgruYqVlB0pqIAI3Phh4Lbiw JAq7QPahX30xCcktgTfEG03p1x9zEyAO0faGmIqn2hCtALTtdDRavAqVsQ5rR21Lu5saawmjaGV dlEehZxx1LyQjCz3v9FsF2h0olUWpbBwz7E8e11kDxZa1p/QmbilbIOfo3Bitr2jyZrsc9ExQGh CiSeNH2hEmI54eoleEKkDKAuAZTaMR3gFP6L7T/Bz0ZHpMPQj9ndHKZkNYML+B3KkWm74VWvj+i 2ma5Pq1oIby6tb4JwyIJeXmpw5ZBWKtryuFIyi8osL0o9bsbWEezinL/UFRoOh80SNrOvWtCmeb c9vbcMHIFLsOUv6kGXIBYj+FRwuD6r3WgoNAwqxPfLTOcI9nuz7JBDLP3v0m2D00O/tCfvk5iVX 3A/Lmj6csr0bEPvKZStlVXyzDxYCkNbDrDjTcqHH6VBndqsJcEYQodwsF2/FQwhJsyWKcDu8Zb2 sTOtBL2M/BmCe6E17bSNLsbiH4QVxwydIvFTAxvFx2xtzi8ykF4uLDl9U01k2OTRZQGayQHw0zS TvajXnORVlECk0Q== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Re-introduce a line-by-line composition algorithm for each pixel format. This allows more performance by not requiring an indirection per pixel read. This patch is focused on readability of the code. Line-by-line composition was introduced by [1] but rewritten back to pixel-by-pixel algorithm in [2]. At this time, nobody noticed the impact on performance, and it was merged. This patch is almost a revert of [2], but in addition efforts have been made to increase readability and maintainability of the rotation handling. The blend function is now divided in two parts: - Transformation of coordinates from the output referential to the source referential - Line conversion and blending Most of the complexity of the rotation management is avoided by using drm_rect_* helpers. The remaining complexity is around the clipping, to avoid reading/writing outside source/destination buffers. The pixel conversion is now done line-by-line, so the read_pixel_t was replaced with read_pixel_line_t callback. This way the indirection is only required once per line and per plane, instead of once per pixel and per plane. The read_line_t callbacks are very similar for most pixel format, but it is required to avoid performance impact. Some helpers for color conversion were introduced to avoid code repetition: - *_to_argb_u16: perform colors conversion. They should be inlined by the compiler, and they are used to avoid repetition between multiple variants of the same format (argb/xrgb and maybe in the future for formats like bgr formats). This new algorithm was tested with: - kms_plane (for color conversions) - kms_rotation_crc (for rotations of planes) - kms_cursor_crc (for translations of planes) - kms_rotation (for all rotations and formats combinations) [3] The performance gain was mesured with kms_fb_stress [4] with some modification to fix the writeback format. The performance improvement is around 5 to 10%. [1]: commit 8ba1648567e2 ("drm: vkms: Refactor the plane composer to accept new formats") https://lore.kernel.org/all/20220905190811.25024-7-igormtorrente@gmail= .com/ [2]: commit 322d716a3e8a ("drm/vkms: isolate pixel conversion functionality") https://lore.kernel.org/all/20230418130525.128733-2-mcanal@igalia.com/ [3]: https://lore.kernel.org/igt-dev/20240313-new_rotation-v2-0-6230fd5cae5= 9@bootlin.com/ [4]: https://lore.kernel.org/all/20240422-kms_fb_stress-dev-v5-0-0c577163dc= 88@riseup.net/ Signed-off-by: Louis Chauvet Acked-by: Pekka Paalanen --- drivers/gpu/drm/vkms/vkms_composer.c | 234 ++++++++++++++++++++++++++++---= ---- drivers/gpu/drm/vkms/vkms_drv.h | 28 +++-- drivers/gpu/drm/vkms/vkms_formats.c | 224 ++++++++++++++++++++-----------= -- drivers/gpu/drm/vkms/vkms_formats.h | 2 +- drivers/gpu/drm/vkms/vkms_plane.c | 5 +- 5 files changed, 344 insertions(+), 149 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vk= ms_composer.c index 4ebeaf58fa75..76d4aa8a0ef6 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -29,8 +29,8 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 al= pha) * @x_start: The start offset * @pixel_count: The number of pixels to blend * - * The pixels 0..@pixel_count in stage_buffer are blended at @x_start..@x_= start+@pixel_count in - * output_buffer. + * The pixels @x_start..@x_start+@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 @@ -41,7 +41,7 @@ static void pre_mul_alpha_blend(const struct line_buffer = *stage_buffer, struct line_buffer *output_buffer, int x_start, int pixel_count) { struct pixel_argb_u16 *out =3D &output_buffer->pixels[x_start]; - const struct pixel_argb_u16 *in =3D stage_buffer->pixels; + const struct pixel_argb_u16 *in =3D &stage_buffer->pixels[x_start]; =20 for (int i =3D 0; i < pixel_count; i++) { out[i].a =3D (u16)0xffff; @@ -51,33 +51,6 @@ static void pre_mul_alpha_blend(const struct line_buffer= *stage_buffer, } } =20 -static int get_y_pos(struct vkms_frame_info *frame_info, int y) -{ - if (frame_info->rotation & DRM_MODE_REFLECT_Y) - return drm_rect_height(&frame_info->rotated) - y - 1; - - switch (frame_info->rotation & DRM_MODE_ROTATE_MASK) { - case DRM_MODE_ROTATE_90: - return frame_info->rotated.x2 - y - 1; - case DRM_MODE_ROTATE_270: - return y + frame_info->rotated.x1; - default: - return y; - } -} - -static bool check_limit(struct vkms_frame_info *frame_info, int pos) -{ - if (drm_rotation_90_or_270(frame_info->rotation)) { - if (pos >=3D 0 && pos < drm_rect_width(&frame_info->rotated)) - return true; - } else { - if (pos >=3D frame_info->rotated.y1 && pos < frame_info->rotated.y2) - return true; - } - - return false; -} =20 static void fill_background(const struct pixel_argb_u16 *background_color, struct line_buffer *output_buffer) @@ -203,6 +176,182 @@ static enum pixel_read_direction direction_for_rotati= on(unsigned int rotation) return READ_LEFT_TO_RIGHT; } =20 +/** + * clamp_line_coordinates() - Compute and clamp the coordinate to read and= write during the blend + * process. + * + * @direction: direction of the reading + * @current_plane: current plane blended + * @src_line: source line of the reading. Only the top-left coordinate is = used. This rectangle + * must be rotated and have a shape of 1*pixel_count if @direction is vert= ical and a shape of + * pixel_count*1 if @direction is horizontal. + * @src_x_start: x start coordinate for the line reading + * @src_y_start: y start coordinate for the line reading + * @dst_x_start: x coordinate to blend the read line + * @pixel_count: number of pixels to blend + * + * This function is mainly a safety net to avoid reading outside the sourc= e buffer. As the + * userspace should never ask to read outside the source plane, all the ca= ses covered here should + * be dead code. + */ +static void clamp_line_coordinates(enum pixel_read_direction direction, + const struct vkms_plane_state *current_plane, + const struct drm_rect *src_line, int *src_x_start, + int *src_y_start, int *dst_x_start, int *pixel_count) +{ + /* By default the start points are correct */ + *src_x_start =3D src_line->x1; + *src_y_start =3D src_line->y1; + *dst_x_start =3D current_plane->frame_info->dst.x1; + + /* Get the correct number of pixel to blend, it depends of the direction = */ + switch (direction) { + case READ_LEFT_TO_RIGHT: + case READ_RIGHT_TO_LEFT: + *pixel_count =3D drm_rect_width(src_line); + break; + case READ_BOTTOM_TO_TOP: + case READ_TOP_TO_BOTTOM: + *pixel_count =3D drm_rect_height(src_line); + break; + } + + /* + * Clamp the coordinates to avoid reading outside the buffer + * + * This is mainly a security to avoid reading outside the buffer, the use= rspace should + * never request to read outside the source buffer. + */ + switch (direction) { + case READ_LEFT_TO_RIGHT: + case READ_RIGHT_TO_LEFT: + if (*src_x_start < 0) { + *pixel_count +=3D *src_x_start; + *dst_x_start -=3D *src_x_start; + *src_x_start =3D 0; + } + if (*src_x_start + *pixel_count > current_plane->frame_info->fb->width) + *pixel_count =3D max(0, (int)current_plane->frame_info->fb->width - + *src_x_start); + break; + case READ_BOTTOM_TO_TOP: + case READ_TOP_TO_BOTTOM: + if (*src_y_start < 0) { + *pixel_count +=3D *src_y_start; + *dst_x_start -=3D *src_y_start; + *src_y_start =3D 0; + } + if (*src_y_start + *pixel_count > current_plane->frame_info->fb->height) + *pixel_count =3D max(0, (int)current_plane->frame_info->fb->height - + *src_y_start); + break; + } +} + +/** + * blend_line() - Blend a line from a plane to the output buffer + * + * @current_plane: current plane to work on + * @y: line to write in the output buffer + * @crtc_x_limit: width of the output buffer + * @stage_buffer: temporary buffer to convert the pixel line from the sour= ce buffer + * @output_buffer: buffer to blend the read line into. + */ +static void blend_line(struct vkms_plane_state *current_plane, int y, + int crtc_x_limit, struct line_buffer *stage_buffer, + struct line_buffer *output_buffer) +{ + int src_x_start, src_y_start, dst_x_start, pixel_count; + struct drm_rect dst_line, tmp_src, src_line; + + /* Avoid rendering useless lines */ + if (y < current_plane->frame_info->dst.y1 || + y >=3D current_plane->frame_info->dst.y2) + return; + + /* + * dst_line is the line to copy. The initial coordinates are inside the + * destination framebuffer, and then drm_rect_* helpers are used to + * compute the correct position into the source framebuffer. + */ + dst_line =3D DRM_RECT_INIT(current_plane->frame_info->dst.x1, y, + drm_rect_width(¤t_plane->frame_info->dst), + 1); + + drm_rect_fp_to_int(&tmp_src, ¤t_plane->frame_info->src); + + /* + * [1]: Clamping src_line to the crtc_x_limit to avoid writing outside of + * the destination buffer + */ + dst_line.x1 =3D max_t(int, dst_line.x1, 0); + dst_line.x2 =3D min_t(int, dst_line.x2, crtc_x_limit); + /* The destination is completely outside of the crtc. */ + if (dst_line.x2 <=3D dst_line.x1) + return; + + src_line =3D dst_line; + + /* + * Transform the coordinate x/y from the crtc to coordinates into + * coordinates for the src buffer. + * + * - Cancel the offset of the dst buffer. + * - Invert the rotation. This assumes that + * dst =3D drm_rect_rotate(src, rotation) (dst and src have the + * same size, but can be rotated). + * - Apply the offset of the source rectangle to the coordinate. + */ + drm_rect_translate(&src_line, -current_plane->frame_info->dst.x1, + -current_plane->frame_info->dst.y1); + drm_rect_rotate_inv(&src_line, drm_rect_width(&tmp_src), + drm_rect_height(&tmp_src), + current_plane->frame_info->rotation); + drm_rect_translate(&src_line, tmp_src.x1, tmp_src.y1); + + /* Get the correct reading direction in the source buffer. */ + + enum pixel_read_direction direction =3D + direction_for_rotation(current_plane->frame_info->rotation); + + /* [2]: Compute and clamp the number of pixel to read */ + clamp_line_coordinates(direction, current_plane, &src_line, &src_x_start,= &src_y_start, + &dst_x_start, &pixel_count); + + if (pixel_count <=3D 0) { + /* Nothing to read, so avoid multiple function calls */ + return; + } + + /* + * Modify the starting point to take in account the rotation + * + * src_line is the top-left corner, so when reading READ_RIGHT_TO_LEFT or + * READ_BOTTOM_TO_TOP, it must be changed to the top-right/bottom-left + * corner. + */ + if (direction =3D=3D READ_RIGHT_TO_LEFT) { + // src_x_start is now the right point + src_x_start +=3D pixel_count - 1; + } else if (direction =3D=3D READ_BOTTOM_TO_TOP) { + // src_y_start is now the bottom point + src_y_start +=3D pixel_count - 1; + } + + /* + * Perform the conversion and the blending + * + * Here we know that the read line (x_start, y_start, pixel_count) is + * inside the source buffer [2] and we don't write outside the stage + * buffer [1]. + */ + current_plane->pixel_read_line(current_plane, src_x_start, src_y_start, d= irection, + pixel_count, &stage_buffer->pixels[dst_x_start]); + + pre_mul_alpha_blend(stage_buffer, output_buffer, + dst_x_start, pixel_count); +} + /** * blend - blend the pixels from all planes and compute crc * @wb: The writeback frame buffer metadata @@ -223,34 +372,25 @@ static void blend(struct vkms_writeback_job *wb, { struct vkms_plane_state **plane =3D crtc_state->active_planes; u32 n_active_planes =3D crtc_state->num_active_planes; - int y_pos, x_dst, pixel_count; =20 const struct pixel_argb_u16 background_color =3D { .a =3D 0xffff }; =20 - size_t crtc_y_limit =3D crtc_state->base.crtc->mode.vdisplay; + int crtc_y_limit =3D crtc_state->base.crtc->mode.vdisplay; + int crtc_x_limit =3D crtc_state->base.crtc->mode.hdisplay; =20 /* * The planes are composed line-by-line to avoid heavy memory usage. It i= s a necessary * complexity to avoid poor blending performance. * - * The function vkms_compose_row() is used to read a line, pixel-by-pixel= , into the staging - * buffer. + * The function pixel_read_line callback is used to read a line, using an= efficient + * algorithm for a specific format, into the staging buffer. */ - for (size_t y =3D 0; y < crtc_y_limit; y++) { + for (int y =3D 0; y < crtc_y_limit; y++) { fill_background(&background_color, output_buffer); =20 /* The active planes are composed associatively in z-order. */ for (size_t i =3D 0; i < n_active_planes; i++) { - x_dst =3D plane[i]->frame_info->dst.x1; - pixel_count =3D min_t(int, drm_rect_width(&plane[i]->frame_info->dst), - (int)stage_buffer->n_pixels); - y_pos =3D 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(stage_buffer, output_buffer, x_dst, pixel_count); + blend_line(plane[i], y, crtc_x_limit, stage_buffer, output_buffer); } =20 apply_lut(crtc_state, output_buffer); @@ -258,7 +398,7 @@ static void blend(struct vkms_writeback_job *wb, *crc32 =3D crc32_le(*crc32, (void *)output_buffer->pixels, row_size); =20 if (wb) - vkms_writeback_row(wb, output_buffer, y_pos); + vkms_writeback_row(wb, output_buffer, y); } } =20 @@ -269,7 +409,7 @@ static int check_format_funcs(struct vkms_crtc_state *c= rtc_state, u32 n_active_planes =3D crtc_state->num_active_planes; =20 for (size_t i =3D 0; i < n_active_planes; i++) - if (!planes[i]->pixel_read) + if (!planes[i]->pixel_read_line) return -1; =20 if (active_wb && !active_wb->pixel_write) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index b3e53b607039..e91cfbf3ce0a 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -39,7 +39,6 @@ struct vkms_frame_info { struct drm_framebuffer *fb; struct drm_rect src, dst; - struct drm_rect rotated; struct iosys_map map[DRM_FORMAT_MAX_PLANES]; unsigned int rotation; }; @@ -80,26 +79,38 @@ enum pixel_read_direction { READ_LEFT_TO_RIGHT }; =20 +struct vkms_plane_state; + /** - * typedef pixel_read_t - These functions are used to read a pixel in the = source frame, + * typedef pixel_read_line_t - These functions are used to read a pixel li= ne in the source frame, * convert it to `struct pixel_argb_u16` and write it to @out_pixel. * - * @in_pixel: pointer to the pixel to read - * @out_pixel: pointer to write the converted pixel + * @plane: plane used as source for the pixel value + * @x_start: X (width) coordinate of the first pixel to copy. The caller m= ust ensure that x_start + * is non-negative and smaller than @plane->frame_info->fb->width. + * @y_start: Y (height) coordinate of the first pixel to copy. The caller = must ensure that y_start + * is non-negative and smaller than @plane->frame_info->fb->height. + * @direction: direction to use for the copy, starting at @x_start/@y_start + * @count: number of pixels to copy + * @out_pixel: pointer where to write the pixel values. They will be writt= en from @out_pixel[0] + * (included) to @out_pixel[@count] (excluded). The caller must ensure tha= t out_pixel have a + * length of at least @count. */ -typedef void (*pixel_read_t)(const u8 *in_pixel, struct pixel_argb_u16 *ou= t_pixel); +typedef void (*pixel_read_line_t)(const struct vkms_plane_state *plane, in= t x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]); =20 /** * struct vkms_plane_state - Driver specific plane state * @base: base plane state * @frame_info: data required for composing computation - * @pixel_read: function to read a pixel in this plane. The creator of a s= truct vkms_plane_state - * must ensure that this pointer is valid + * @pixel_read_line: function to read a pixel line in this plane. The crea= tor of a + * struct vkms_plane_state must ensure that this pointer is valid */ struct vkms_plane_state { struct drm_shadow_plane_state base; struct vkms_frame_info *frame_info; - pixel_read_t pixel_read; + pixel_read_line_t pixel_read_line; }; =20 struct vkms_plane { @@ -265,7 +276,6 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const= char *source_name, /* Composer Support */ void vkms_composer_worker(struct work_struct *work); void vkms_set_composer(struct vkms_output *out, bool enabled); -void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_= state *plane, int y); void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_b= uffer *src_buffer, int y); =20 /* Writeback */ diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index d0e7dfc1f0d3..0f6678420a11 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -140,83 +140,51 @@ static void packed_pixels_addr_1x1(const struct vkms_= frame_info *frame_info, *addr =3D (u8 *)frame_info->map[0].vaddr + offset; } =20 -static void *get_packed_src_addr(const struct vkms_frame_info *frame_info,= int y, - int plane_index) -{ - int x_src =3D frame_info->src.x1 >> 16; - int y_src =3D 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= ) !=3D 1, - "%s() only support formats with block_w =3D=3D 1", __func__); - WARN_ONCE(drm_format_info_block_height(frame_info->fb->format, plane_inde= x) !=3D 1, - "%s() only support formats with block_h =3D=3D 1", __func__); - - 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 li= mit, int x) -{ - if (frame_info->rotation & (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_270)) - return limit - x - 1; - return x; -} - /* - * The following functions take pixel data from the buffer and convert the= m to the format - * ARGB16161616 in @out_pixel. + * The following functions take pixel data (a, r, g, b, pixel, ...) and co= nvert them to + * &struct pixel_argb_u16 * - * They are used in the vkms_compose_row() function to handle multiple for= mats. + * They are used in the `read_line`s functions to avoid duplicate work for= some pixel formats. */ =20 -static void ARGB8888_to_argb_u16(const u8 *in_pixel, struct pixel_argb_u16= *out_pixel) +static struct pixel_argb_u16 argb_u16_from_u8888(u8 a, u8 r, u8 g, u8 b) { + struct pixel_argb_u16 out_pixel; /* * The 257 is the "conversion ratio". This number is obtained by the * (2^16 - 1) / (2^8 - 1) division. Which, in this case, tries to get * the best color value in a pixel format with more possibilities. * A similar idea applies to others RGB color conversions. */ - out_pixel->a =3D (u16)in_pixel[3] * 257; - out_pixel->r =3D (u16)in_pixel[2] * 257; - out_pixel->g =3D (u16)in_pixel[1] * 257; - out_pixel->b =3D (u16)in_pixel[0] * 257; -} + out_pixel.a =3D (u16)a * 257; + out_pixel.r =3D (u16)r * 257; + out_pixel.g =3D (u16)g * 257; + out_pixel.b =3D (u16)b * 257; =20 -static void XRGB8888_to_argb_u16(const u8 *in_pixel, struct pixel_argb_u16= *out_pixel) -{ - out_pixel->a =3D (u16)0xffff; - out_pixel->r =3D (u16)in_pixel[2] * 257; - out_pixel->g =3D (u16)in_pixel[1] * 257; - out_pixel->b =3D (u16)in_pixel[0] * 257; + return out_pixel; } =20 -static void ARGB16161616_to_argb_u16(const u8 *in_pixel, struct pixel_argb= _u16 *out_pixel) +static struct pixel_argb_u16 argb_u16_from_u16161616(u16 a, u16 r, u16 g, = u16 b) { - __le16 *pixel =3D (__le16 *)in_pixel; + struct pixel_argb_u16 out_pixel; + + out_pixel.a =3D a; + out_pixel.r =3D r; + out_pixel.g =3D g; + out_pixel.b =3D b; =20 - out_pixel->a =3D le16_to_cpu(pixel[3]); - out_pixel->r =3D le16_to_cpu(pixel[2]); - out_pixel->g =3D le16_to_cpu(pixel[1]); - out_pixel->b =3D le16_to_cpu(pixel[0]); + return out_pixel; } =20 -static void XRGB16161616_to_argb_u16(const u8 *in_pixel, struct pixel_argb= _u16 *out_pixel) +static struct pixel_argb_u16 argb_u16_from_le16161616(__le16 a, __le16 r, = __le16 g, __le16 b) { - __le16 *pixel =3D (__le16 *)in_pixel; - - out_pixel->a =3D (u16)0xffff; - out_pixel->r =3D le16_to_cpu(pixel[2]); - out_pixel->g =3D le16_to_cpu(pixel[1]); - out_pixel->b =3D le16_to_cpu(pixel[0]); + return argb_u16_from_u16161616(le16_to_cpu(a), le16_to_cpu(r), le16_to_cp= u(g), + le16_to_cpu(b)); } =20 -static void RGB565_to_argb_u16(const u8 *in_pixel, struct pixel_argb_u16 *= out_pixel) +static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel) { - __le16 *pixel =3D (__le16 *)in_pixel; + struct pixel_argb_u16 out_pixel; =20 s64 fp_rb_ratio =3D drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31)); s64 fp_g_ratio =3D drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63)); @@ -226,40 +194,120 @@ static void RGB565_to_argb_u16(const u8 *in_pixel, s= truct pixel_argb_u16 *out_pi s64 fp_g =3D drm_int2fixp((rgb_565 >> 5) & 0x3f); s64 fp_b =3D drm_int2fixp(rgb_565 & 0x1f); =20 - out_pixel->a =3D (u16)0xffff; - out_pixel->r =3D drm_fixp2int_round(drm_fixp_mul(fp_r, fp_rb_ratio)); - out_pixel->g =3D drm_fixp2int_round(drm_fixp_mul(fp_g, fp_g_ratio)); - out_pixel->b =3D drm_fixp2int_round(drm_fixp_mul(fp_b, fp_rb_ratio)); + out_pixel.a =3D (u16)0xffff; + out_pixel.r =3D drm_fixp2int_round(drm_fixp_mul(fp_r, fp_rb_ratio)); + out_pixel.g =3D drm_fixp2int_round(drm_fixp_mul(fp_g, fp_g_ratio)); + out_pixel.b =3D drm_fixp2int_round(drm_fixp_mul(fp_b, fp_rb_ratio)); + + return out_pixel; } =20 -/** - * vkms_compose_row - compose a single row of a plane - * @stage_buffer: output line with the composed pixels - * @plane: state of the plane that is being composed - * @y: y coordinate of the row +/* + * The following functions are read_line function for each pixel format su= pported by VKMS. + * + * They read a line starting at the point @x_start,@y_start following the = @direction. The result + * is stored in @out_pixel and in the format ARGB16161616. + * + * These functions are very repetitive, but the innermost pixel loops must= be kept inside these + * functions for performance reasons. Some benchmarking was done in [1] wh= ere having the innermost + * loop factored out of these functions showed a slowdown by a factor of t= hree. * - * This function composes a single row of a plane. It gets the source pixe= ls - * through the y coordinate (see get_packed_src_addr()) and goes linearly - * through the source pixel, reading the pixels and converting it to - * ARGB16161616 (see the pixel_read() callback). For rotate-90 and rotate-= 270, - * the source pixels are not traversed linearly. The source pixels are que= ried - * on each iteration in order to traverse the pixels vertically. + * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33= b3a3@riseup.net/ */ -void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_= state *plane, int y) + +static void ARGB8888_read_line(const struct vkms_plane_state *plane, int x= _start, int y_start, + enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) { - struct pixel_argb_u16 *out_pixels =3D stage_buffer->pixels; - struct vkms_frame_info *frame_info =3D plane->frame_info; - u8 *src_pixels =3D get_packed_src_addr(frame_info, y, 0); - int limit =3D min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffe= r->n_pixels); + struct pixel_argb_u16 *end =3D out_pixel + count; + u8 *src_pixels; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); + + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + + while (out_pixel < end) { + u8 *px =3D (u8 *)src_pixels; + *out_pixel =3D argb_u16_from_u8888(px[3], px[2], px[1], px[0]); + out_pixel +=3D 1; + src_pixels +=3D step; + } +} + +static void XRGB8888_read_line(const struct vkms_plane_state *plane, int x= _start, int y_start, + enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end =3D out_pixel + count; + u8 *src_pixels; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); + + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + + while (out_pixel < end) { + u8 *px =3D (u8 *)src_pixels; + *out_pixel =3D argb_u16_from_u8888(255, px[2], px[1], px[0]); + out_pixel +=3D 1; + src_pixels +=3D step; + } +} + +static void ARGB16161616_read_line(const struct vkms_plane_state *plane, i= nt x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end =3D out_pixel + count; + u8 *src_pixels; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); + + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + + while (out_pixel < end) { + u16 *px =3D (u16 *)src_pixels; + *out_pixel =3D argb_u16_from_u16161616(px[3], px[2], px[1], px[0]); + out_pixel +=3D 1; + src_pixels +=3D step; + } +} + +static void XRGB16161616_read_line(const struct vkms_plane_state *plane, i= nt x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end =3D out_pixel + count; + u8 *src_pixels; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); + + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + + while (out_pixel < end) { + __le16 *px =3D (__le16 *)src_pixels; + *out_pixel =3D argb_u16_from_le16161616(cpu_to_le16(0xFFFF), px[2], px[1= ], px[0]); + out_pixel +=3D 1; + src_pixels +=3D step; + } +} + +static void RGB565_read_line(const struct vkms_plane_state *plane, int x_s= tart, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end =3D out_pixel + count; + u8 *src_pixels; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); =20 - for (size_t x =3D 0; x < limit; x++, src_pixels +=3D frame_info->fb->form= at->cpp[0]) { - int x_pos =3D get_x_position(frame_info, limit, x); + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); =20 - if (drm_rotation_90_or_270(frame_info->rotation)) - src_pixels =3D get_packed_src_addr(frame_info, x + frame_info->rotated.= y1, 0) - + frame_info->fb->format->cpp[0] * y; + while (out_pixel < end) { + __le16 *px =3D (__le16 *)src_pixels; =20 - plane->pixel_read(src_pixels, &out_pixels[x_pos]); + *out_pixel =3D argb_u16_from_RGB565(px); + out_pixel +=3D 1; + src_pixels +=3D step; } } =20 @@ -359,25 +407,25 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, } =20 /** - * get_pixel_read_function() - Retrieve the correct read_pixel function fo= r a specific + * get_pixel_read_line_function() - Retrieve the correct read_line functio= n for a specific * format. The returned pointer is NULL for unsupported pixel formats. The= caller must ensure that * the pointer is valid before using it in a vkms_plane_state. * * @format: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) */ -pixel_read_t get_pixel_read_function(u32 format) +pixel_read_line_t get_pixel_read_line_function(u32 format) { switch (format) { case DRM_FORMAT_ARGB8888: - return &ARGB8888_to_argb_u16; + return &ARGB8888_read_line; case DRM_FORMAT_XRGB8888: - return &XRGB8888_to_argb_u16; + return &XRGB8888_read_line; case DRM_FORMAT_ARGB16161616: - return &ARGB16161616_to_argb_u16; + return &ARGB16161616_read_line; case DRM_FORMAT_XRGB16161616: - return &XRGB16161616_to_argb_u16; + return &XRGB16161616_read_line; case DRM_FORMAT_RGB565: - return &RGB565_to_argb_u16; + return &RGB565_read_line; default: /* * This is a bug in vkms_plane_atomic_check(). All the supported diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkm= s_formats.h index 3ecea4563254..8d2bef95ff79 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -5,7 +5,7 @@ =20 #include "vkms_drv.h" =20 -pixel_read_t get_pixel_read_function(u32 format); +pixel_read_line_t get_pixel_read_line_function(u32 format); =20 pixel_write_t get_pixel_write_function(u32 format); =20 diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index 10e9b23dab28..8875bed76410 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -112,7 +112,6 @@ static void vkms_plane_atomic_update(struct drm_plane *= plane, frame_info =3D vkms_plane_state->frame_info; memcpy(&frame_info->src, &new_state->src, sizeof(struct drm_rect)); memcpy(&frame_info->dst, &new_state->dst, sizeof(struct drm_rect)); - memcpy(&frame_info->rotated, &new_state->dst, sizeof(struct drm_rect)); frame_info->fb =3D fb; memcpy(&frame_info->map, &shadow_plane_state->data, sizeof(frame_info->ma= p)); drm_framebuffer_get(frame_info->fb); @@ -122,10 +121,8 @@ static void vkms_plane_atomic_update(struct drm_plane = *plane, DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y); =20 - drm_rect_rotate(&frame_info->rotated, drm_rect_width(&frame_info->rotated= ), - drm_rect_height(&frame_info->rotated), frame_info->rotation); =20 - vkms_plane_state->pixel_read =3D get_pixel_read_function(fmt); + vkms_plane_state->pixel_read_line =3D get_pixel_read_line_function(fmt); } =20 static int vkms_plane_atomic_check(struct drm_plane *plane, --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 0988519B3D3; Mon, 30 Sep 2024 15:32:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710377; cv=none; b=NT3EkjetlJd7uM6OueK/vAVloHpns62WMdbpYzAX2wqGTyYhrM7iAQfSuhyGvgAg4zgK7xa1Bp26bUNveV5LQf9bGklhPQpwwYebM3lBSoI6rjHggAGvpMl3B5a2J1UP36BZQUYruabFgOZuU5HydbcSO/GvEmbQGtY7vLLW8sA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710377; c=relaxed/simple; bh=PFGhswxeEmLZHlnqofeGdDJ2SDZWzjkoeeHK9t5I21Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fsX3mAaIN7VmG8h5pN7+VIwbNJM6CbxmmCfGmLoAFK4rYSZexuh00HUq6rq5Ar/zcD6kROs58a6W5/k1Q/sj+m5qQD0o4U+zEo3HuWv1S8EGnsgIBX050zDExW86sfs9V2nrwj46YaO32aIjls4lJ+6lSEb1Qq3td+/c602JbjE= 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=lURCSA1H; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="lURCSA1H" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8F51A40005; Mon, 30 Sep 2024 15:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710374; 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=0BsU4INOE1CHTascqSt5xwkugSRCgOxTbOYvghbcOx8=; b=lURCSA1HRcGwdcAmfvs9INlcPYq4R+x16i0Ao6iyv1A8mCp51UDhLUNFOFYeh+j2vDVWKT 6KISbWCpekVlZg9B1uFSq8xICR44Md/EmNVEUO5k83kvTTN8Vg+DHy2AUKRSOjtM76OElT YJsjUOaOsK3a6YyMS/9nCpM6VhtXZULckwCEGKdysiV4Ov31wOrvKIYr5S34Czjlcoac7Q +QPVfVt1Z0g0VMVLMxLIBnYHyHBAHfu8fEJsC26yTTTXqoAMLc88KGL9lX3kODm4z86Rfd pscjWCwhDOYOve2BExY+2skHgn5ZpqVYShcfOfQhQ2g60/VdFMf+OAafmZ0xRQ== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:49 +0200 Subject: [PATCH v11 09/15] drm/vkms: Remove useless drm_rotation_simplify 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: quoted-printable Message-Id: <20240930-yuv-v11-9-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1084; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=PFGhswxeEmLZHlnqofeGdDJ2SDZWzjkoeeHK9t5I21Y=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRvrp5toRNt9ZbuVGMYE/HWgSlWWN2L53xZK UFT/cuxTN2JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEbwAKCRAgrS7GWxAs 4pjbD/99I/P4K3aEzp0gCAXgr4/Qt9FGXrK0D0GqMwJgCCi4bA8avu2lDrG86/GBNTPP207zRVx 2j+OPNryais+TjpGqDgWBGCk2Ysi9pXNAT4NOfWw8mrqUrMdFGse2pYlvC2XAcWkc7uYQxIjcMX exWTbjlmxwDm8FlytYWBnX6qaUXdUzqjc3yQ7dptSA1+h9KpyxhumfEmebxoZEJwIanzujyEroC ezSYkgC9uB+01+jo62OXllGLhW1O5nwEDsKVPluAGsMbsiQYRYVDs+7pi+B5Y9Y57xrs1hQ7G5+ ALciwo7vladTKgPt5WmMXDRoCHM8qTo5u5mIidBgyKwwRIBcaGgL7FtLxM63PEMJyTGqnkObYRS nae0A8FecUFq1H3ex3l42ymq7VtPoqCSx8MsY1K+8NJvQRHfAEY7nBA9SVBrCIpO8iNn7MRQ6uD ILQ93AO9NcisRuVOF2oVW28k5rknWPcgR4VeNhWMT8MrvSJHgIwvf8PmG9/MV9lQF40vrRgmWPt dW+DUqeo0nAMqVqaRekXLmJxTriuQCe75HkxI5YjYhF5BW0nRKrCcebAIyZoJGT/1ba8TU6kOvn Ghf7dkbxJnfdEU/GZTEu4YRcy5gG/PXAbPRGq/5LW4ggzjsiRE30R1X2QUSf9sBAntCWoYSOerd VU9Xtrokju31fbQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com As all the rotation are now supported by VKMS, this simplification does not make sense anymore, so remove it. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_plane.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index 8875bed76410..5a028ee96c91 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -115,12 +115,7 @@ static void vkms_plane_atomic_update(struct drm_plane = *plane, frame_info->fb =3D fb; memcpy(&frame_info->map, &shadow_plane_state->data, sizeof(frame_info->ma= p)); drm_framebuffer_get(frame_info->fb); - frame_info->rotation =3D drm_rotation_simplify(new_state->rotation, DRM_M= ODE_ROTATE_0 | - DRM_MODE_ROTATE_90 | - DRM_MODE_ROTATE_270 | - DRM_MODE_REFLECT_X | - DRM_MODE_REFLECT_Y); - + frame_info->rotation =3D new_state->rotation; =20 vkms_plane_state->pixel_read_line =3D get_pixel_read_line_function(fmt); } --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 71CBF19C54E; Mon, 30 Sep 2024 15:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710383; cv=none; b=kVoDEuJB1eyjDA1LIc9+M+BpPTgQ88EWhItVbbCoOEdu3pqQLqszu9gxYf3l3q4t6J56u578c9wJ6x8Qvr6twzRSEqq+X5/hThIcjvRyqXElMtJKj93jY2hkAhJBPn0hdAW46uC5sEu+LK9FCu9qJq/I/CXJ4EfRbrcMzS3r2IM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710383; c=relaxed/simple; bh=WUsDb2HNEnCfebF22Xo+4/nOH2JDGw7ABGlTpNxVnwo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BT0bofk6Va2AWM/kiM0s/3NkZsTig+lgjlBBXZvCtHjic5mQvswzzYO1eE67dIIKWGDUL4wswos0v+uuFTn+D1JJ6LFn1FKD8x6JrsWBJHwQtUtlP9GPSPLWrqsbZ9ZlkT1ewhllsNir0P4hAZzi4CBvvWfzDR6MN0gPsI54uWo= 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=Yw7DtuMl; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Yw7DtuMl" Received: by mail.gandi.net (Postfix) with ESMTPSA id B4C4E40006; Mon, 30 Sep 2024 15:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710379; 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=D+u5WDSMAoArr9z+jCiZC0cJ0ZqIJpY8pYD8TJF4NMw=; b=Yw7DtuMl96zhRYTms2+b97MNjoIkISfFYDADA+miTN4hTPVEhgWBin8kSYZW3IcNVjEsVM 5FRd19ug/R5nr/JiOFBBS2DPwpKYPplhA09/UIbAfFvCEaQryZ9rmYLsmW6uYem8Jm0quv ndwBjTmgwqq3N6V2AuxinKteLJZOuDJo17mVSHYIHiqjU+gSZYk9ZqNx7DNITsagGAzWPD BuQVYZQoP9FU1QAqsRg6xo+lWW4iesb2Jsilc2+INMnAh9u4kG0uxSWDBEjECSL9XPlGhu Vqf9JfJce5xy2mWP07VV8ZwWfL+FjhOe1BgYmXg0aHtzQrmoi97m8hB8LgoKXQ== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:50 +0200 Subject: [PATCH v11 10/15] drm/vkms: Add YUV support 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: quoted-printable Message-Id: <20240930-yuv-v11-10-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=18658; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=cnsoiEnz5vFf4682+kcv4n3DBQ0AJbDIZKsyLaP0jKQ=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRwURtGOYxr1Obo83HK0cwKRKLcIduyMX0OE +zaeHes1pmJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEcAAKCRAgrS7GWxAs 4saWEADMVj/dEVSS1Bb3tV0/AMC/26f456a8ee5MyTl01CWnMuHUfUJcdjJq/QaLMRW2LiHj7Mg U2letQjvNMa6TelA9im2CqQVZw/f+8GafmDofttMQf0nc25O0rFdwzJB9eWUZDR8bpUy7YC/M4Z NMm+GkP4T//ruTbOCqWmoAu25PHCwruQ4m9/u5Rl1OvTYsxbe/rufqYA2deANs70zeeutWIMOpn oUPRHd45Os06T/Pm+QunKxaYVQvOYMnFaaV2rLuDWUak5PUgJ2kne9Sd2A327mvpc9xh0G4Q2/f q6Vbpk0cE76Kbs3XxSGu/thvQyopmuluRrbtvxVOfAmD67XKRgBj3fcD81r+2o9snq9bOAh71MT LAAK+rc6Dk2tYMurS0MJvrbmLkMSJvfLBu4R70tmW0mxow3iZnsT+Eg98PbeK6oQtZZGvM2MCyX doRyjkVK2CNn8GdZcOVO88sLxm5oX34qfgXa/h1VHPUGk/uOh+NtHq3hj/iWbDdadWX97Q/XYMr BULLmK0qMqgpL1b3yW9U+XaONdaDg+x5sn8K60nfBEdHRrTt2xAFVWy+0hpz3kUx8UOJAKzijZD o7ytsRbjmKTATThG+c63BlrUWUGJ+gbsZgwwXmZP45mfiBWXhr30ZamhUhjHVvacWyVV7x3GqsB +1aureeLrulYBYg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Add support to the YUV formats bellow: - NV12/NV16/NV24 - NV21/NV61/NV42 - YUV420/YUV422/YUV444 - YVU420/YVU422/YVU444 The conversion from yuv to rgb is done with fixed-point arithmetic, using 32.32 fixed-point numbers and the drm_fixed helpers. To do the conversion, a specific matrix must be used for each color range (DRM_COLOR_*_RANGE) and encoding (DRM_COLOR_*). This matrix is stored in the `conversion_matrix` struct, along with the specific y_offset needed. This matrix is queried only once, in `vkms_plane_atomic_update` and stored in a `vkms_plane_state`. Those conversion matrices of each encoding and range were obtained by rounding the values of the original conversion matrices multiplied by 2^32. This is done to avoid the use of floating point operations. The same reading function is used for YUV and YVU formats. As the only difference between those two category of formats is the order of field, a simple swap in conversion matrix columns allows using the same function. Signed-off-by: Arthur Grillo [Louis Chauvet: - Adapted Arthur's work - Implemented the read_line_t callbacks for yuv - add struct conversion_matrix - store the whole conversion_matrix in the plane state - remove struct pixel_yuv_u8 - update the commit message - Merge the modifications from Arthur] Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.h | 18 ++ drivers/gpu/drm/vkms/vkms_formats.c | 353 ++++++++++++++++++++++++++++++++= ++++ drivers/gpu/drm/vkms/vkms_formats.h | 4 + drivers/gpu/drm/vkms/vkms_plane.c | 16 +- 4 files changed, 390 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index e91cfbf3ce0a..f31d4257fa2f 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -100,17 +100,35 @@ typedef void (*pixel_read_line_t)(const struct vkms_p= lane_state *plane, int x_st int y_start, enum pixel_read_direction direction, int count, struct pixel_argb_u16 out_pixel[]); =20 +/** + * struct conversion_matrix - Matrix to use for a specific encoding and ra= nge + * + * @matrix: Conversion matrix from yuv to rgb. The matrix is stored in a r= ow-major manner and is + * used to compute rgb values from yuv values: + * [[r],[g],[b]] =3D @matrix * [[y],[u],[v]] + * OR for yvu formats: + * [[r],[g],[b]] =3D @matrix * [[y],[v],[u]] + * The values of the matrix are signed fixed-point values with 32 bits fr= actional part. + * @y_offset: Offset to apply on the y value. + */ +struct conversion_matrix { + s64 matrix[3][3]; + int y_offset; +}; + /** * struct vkms_plane_state - Driver specific plane state * @base: base plane state * @frame_info: data required for composing computation * @pixel_read_line: function to read a pixel line in this plane. The crea= tor of a * struct vkms_plane_state must ensure that this pointer is valid + * @conversion_matrix: matrix used for yuv formats to convert to rgb */ struct vkms_plane_state { struct drm_shadow_plane_state base; struct vkms_frame_info *frame_info; pixel_read_line_t pixel_read_line; + struct conversion_matrix conversion_matrix; }; =20 struct vkms_plane { diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 0f6678420a11..adb1228e5201 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -140,6 +140,51 @@ static void packed_pixels_addr_1x1(const struct vkms_f= rame_info *frame_info, *addr =3D (u8 *)frame_info->map[0].vaddr + offset; } =20 +/** + * get_subsampling() - Get the subsampling divisor value on a specific dir= ection + * + * @format: format to extarct the subsampling from + * @direction: direction of the subsampling requested + */ +static int get_subsampling(const struct drm_format_info *format, + enum pixel_read_direction direction) +{ + switch (direction) { + case READ_BOTTOM_TO_TOP: + case READ_TOP_TO_BOTTOM: + return format->vsub; + case READ_RIGHT_TO_LEFT: + case READ_LEFT_TO_RIGHT: + return format->hsub; + } + WARN_ONCE(true, "Invalid direction for pixel reading: %d\n", direction); + return 1; +} + +/** + * get_subsampling_offset() - An offset for keeping the chroma siting cons= istent regardless of + * x_start and y_start values + * + * @direction: direction of the reading to properly compute this offset + * @x_start: x coordinate of the starting point of the readed line + * @y_start: y coordinate of the starting point of the readed line + */ +static int get_subsampling_offset(enum pixel_read_direction direction, int= x_start, int y_start) +{ + switch (direction) { + case READ_BOTTOM_TO_TOP: + return -y_start - 1; + case READ_TOP_TO_BOTTOM: + return y_start; + case READ_RIGHT_TO_LEFT: + return -x_start - 1; + case READ_LEFT_TO_RIGHT: + return x_start; + } + WARN_ONCE(true, "Invalid direction for pixel reading: %d\n", direction); + return 0; +} + /* * The following functions take pixel data (a, r, g, b, pixel, ...) and co= nvert them to * &struct pixel_argb_u16 @@ -202,6 +247,38 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(cons= t __le16 *pixel) return out_pixel; } =20 +static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 c= hannel_2, + const struct conversion_matrix *matrix) +{ + u16 r, g, b; + s64 fp_y, fp_channel_1, fp_channel_2; + s64 fp_r, fp_g, fp_b; + + fp_y =3D drm_int2fixp(((int)y - matrix->y_offset) * 257); + fp_channel_1 =3D drm_int2fixp(((int)channel_1 - 128) * 257); + fp_channel_2 =3D drm_int2fixp(((int)channel_2 - 128) * 257); + + fp_r =3D drm_fixp_mul(matrix->matrix[0][0], fp_y) + + drm_fixp_mul(matrix->matrix[0][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[0][2], fp_channel_2); + fp_g =3D drm_fixp_mul(matrix->matrix[1][0], fp_y) + + drm_fixp_mul(matrix->matrix[1][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[1][2], fp_channel_2); + fp_b =3D drm_fixp_mul(matrix->matrix[2][0], fp_y) + + drm_fixp_mul(matrix->matrix[2][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[2][2], fp_channel_2); + + fp_r =3D drm_fixp2int_round(fp_r); + fp_g =3D drm_fixp2int_round(fp_g); + fp_b =3D drm_fixp2int_round(fp_b); + + r =3D clamp(fp_r, 0, 0xffff); + g =3D clamp(fp_g, 0, 0xffff); + b =3D clamp(fp_b, 0, 0xffff); + + return argb_u16_from_u16161616(0xffff, r, g, b); +} + /* * The following functions are read_line function for each pixel format su= pported by VKMS. * @@ -311,6 +388,92 @@ static void RGB565_read_line(const struct vkms_plane_s= tate *plane, int x_start, } } =20 +/* + * This callback can be used for YUV formats where U and V values are + * stored in the same plane (often called semi-planar formats). It will + * correctly handle subsampling as described in the drm_format_info of the= plane. + * + * The conversion matrix stored in the @plane is used to: + * - Apply the correct color range and encoding + * - Convert YUV and YVU with the same function (a column swap is needed w= hen setting up + * plane->conversion_matrix) + */ +static void semi_planar_yuv_read_line(const struct vkms_plane_state *plane= , int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + u8 *y_plane; + u8 *uv_plane; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, + &y_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 1, + &uv_plane); + int step_y =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int step_uv =3D get_block_step_bytes(plane->frame_info->fb, direction, 1); + int subsampling =3D get_subsampling(plane->frame_info->fb->format, direct= ion); + int subsampling_offset =3D get_subsampling_offset(direction, x_start, y_s= tart); + const struct conversion_matrix *conversion_matrix =3D &plane->conversion_= matrix; + + for (int i =3D 0; i < count; i++) { + *out_pixel =3D argb_u16_from_yuv888(y_plane[0], uv_plane[0], uv_plane[1], + conversion_matrix); + out_pixel +=3D 1; + y_plane +=3D step_y; + if ((i + subsampling_offset + 1) % subsampling =3D=3D 0) + uv_plane +=3D step_uv; + } +} + +/* + * This callback can be used for YUV format where each color component is + * stored in a different plane (often called planar formats). It will + * correctly handle subsampling as described in the drm_format_info of the= plane. + * + * The conversion matrix stored in the @plane is used to: + * - Apply the correct color range and encoding + * - Convert YUV and YVU with the same function (a column swap is needed w= hen setting up + * plane->conversion_matrix) + */ +static void planar_yuv_read_line(const struct vkms_plane_state *plane, int= x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + u8 *y_plane; + u8 *channel_1_plane; + u8 *channel_2_plane; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, + &y_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 1, + &channel_1_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 2, + &channel_2_plane); + int step_y =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int step_channel_1 =3D get_block_step_bytes(plane->frame_info->fb, direct= ion, 1); + int step_channel_2 =3D get_block_step_bytes(plane->frame_info->fb, direct= ion, 2); + int subsampling =3D get_subsampling(plane->frame_info->fb->format, direct= ion); + int subsampling_offset =3D get_subsampling_offset(direction, x_start, y_s= tart); + const struct conversion_matrix *conversion_matrix =3D &plane->conversion_= matrix; + + for (int i =3D 0; i < count; i++) { + *out_pixel =3D argb_u16_from_yuv888(*y_plane, *channel_1_plane, *channel= _2_plane, + conversion_matrix); + out_pixel +=3D 1; + y_plane +=3D step_y; + if ((i + subsampling_offset + 1) % subsampling =3D=3D 0) { + channel_1_plane +=3D step_channel_1; + channel_2_plane +=3D step_channel_2; + } + } +} + /* * The following functions take one &struct pixel_argb_u16 and convert it = to a specific format. * The result is stored in @out_pixel. @@ -426,6 +589,20 @@ pixel_read_line_t get_pixel_read_line_function(u32 for= mat) return &XRGB16161616_read_line; case DRM_FORMAT_RGB565: return &RGB565_read_line; + case DRM_FORMAT_NV12: + case DRM_FORMAT_NV16: + case DRM_FORMAT_NV24: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV61: + case DRM_FORMAT_NV42: + return &semi_planar_yuv_read_line; + case DRM_FORMAT_YUV420: + case DRM_FORMAT_YUV422: + case DRM_FORMAT_YUV444: + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YVU444: + return &planar_yuv_read_line; default: /* * This is a bug in vkms_plane_atomic_check(). All the supported @@ -439,6 +616,182 @@ pixel_read_line_t get_pixel_read_line_function(u32 fo= rmat) } } =20 +/* + * Those matrices were generated using the colour python framework + * + * Below are the function calls used to generate each matrix, go to + * https://colour.readthedocs.io/en/develop/generated/colour.matrix_YCbCr.= html + * for more info: + * + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601= "], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix no_operation =3D { + .matrix =3D { + { 4294967296, 0, 0, }, + { 0, 4294967296, 0, }, + { 0, 0, 4294967296, }, + }, + .y_offset =3D 0, +}; + +static const struct conversion_matrix yuv_bt601_full =3D { + .matrix =3D { + { 4294967296, 0, 6021544149 }, + { 4294967296, -1478054095, -3067191994 }, + { 4294967296, 7610682049, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601= "], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt601_limited =3D { + .matrix =3D { + { 5020601039, 0, 6881764740 }, + { 5020601039, -1689204679, -3505362278 }, + { 5020601039, 8697922339, 0 }, + }, + .y_offset =3D 16, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709= "], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt709_full =3D { + .matrix =3D { + { 4294967296, 0, 6763714498 }, + { 4294967296, -804551626, -2010578443 }, + { 4294967296, 7969741314, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709= "], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt709_limited =3D { + .matrix =3D { + { 5020601039, 0, 7729959424 }, + { 5020601039, -919487572, -2297803934 }, + { 5020601039, 9108275786, 0 }, + }, + .y_offset =3D 16, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.202= 0"], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt2020_full =3D { + .matrix =3D { + { 4294967296, 0, 6333358775 }, + { 4294967296, -706750298, -2453942994 }, + { 4294967296, 8080551471, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.202= 0"], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt2020_limited =3D { + .matrix =3D { + { 5020601039, 0, 7238124312 }, + { 5020601039, -807714626, -2804506279 }, + { 5020601039, 9234915964, 0 }, + }, + .y_offset =3D 16, +}; + +/** + * swap_uv_columns() - Swap u and v column of a given matrix + * + * @matrix: Matrix in which column are swapped + */ +static void swap_uv_columns(struct conversion_matrix *matrix) +{ + swap(matrix->matrix[0][2], matrix->matrix[0][1]); + swap(matrix->matrix[1][2], matrix->matrix[1][1]); + swap(matrix->matrix[2][2], matrix->matrix[2][1]); +} + +/** + * get_conversion_matrix_to_argb_u16() - Retrieve the correct yuv to rgb c= onversion matrix for a + * given encoding and range. + * + * @format: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) + * @encoding: DRM_COLOR_* value for which to obtain a conversion matrix + * @range: DRM_COLOR_*_RANGE value for which to obtain a conversion matrix + * @matrix: Pointer to store the value into + */ +void get_conversion_matrix_to_argb_u16(u32 format, + enum drm_color_encoding encoding, + enum drm_color_range range, + struct conversion_matrix *matrix) +{ + const struct conversion_matrix *matrix_to_copy; + bool limited_range; + + switch (range) { + case DRM_COLOR_YCBCR_LIMITED_RANGE: + limited_range =3D true; + break; + case DRM_COLOR_YCBCR_FULL_RANGE: + limited_range =3D false; + break; + case DRM_COLOR_RANGE_MAX: + limited_range =3D false; + WARN_ONCE(true, "The requested range is not supported."); + break; + } + + switch (encoding) { + case DRM_COLOR_YCBCR_BT601: + matrix_to_copy =3D limited_range ? &yuv_bt601_limited : + &yuv_bt601_full; + break; + case DRM_COLOR_YCBCR_BT709: + matrix_to_copy =3D limited_range ? &yuv_bt709_limited : + &yuv_bt709_full; + break; + case DRM_COLOR_YCBCR_BT2020: + matrix_to_copy =3D limited_range ? &yuv_bt2020_limited : + &yuv_bt2020_full; + break; + case DRM_COLOR_ENCODING_MAX: + matrix_to_copy =3D &no_operation; + WARN_ONCE(true, "The requested encoding is not supported."); + break; + } + + memcpy(matrix, matrix_to_copy, sizeof(*matrix_to_copy)); + + switch (format) { + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YVU444: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV61: + case DRM_FORMAT_NV42: + swap_uv_columns(matrix); + break; + default: + break; + } +} + /** * get_pixel_write_function() - Retrieve the correct write_pixel function = for a specific format. * The returned pointer is NULL for unsupported pixel formats. The caller = must ensure that the diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkm= s_formats.h index 8d2bef95ff79..d583855cb320 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -9,4 +9,8 @@ pixel_read_line_t get_pixel_read_line_function(u32 format); =20 pixel_write_t get_pixel_write_function(u32 format); =20 +void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding= encoding, + enum drm_color_range range, + struct conversion_matrix *matrix); + #endif /* _VKMS_FORMATS_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index 5a028ee96c91..d4e375913122 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -17,7 +17,19 @@ static const u32 vkms_formats[] =3D { DRM_FORMAT_XRGB8888, DRM_FORMAT_XRGB16161616, DRM_FORMAT_ARGB16161616, - DRM_FORMAT_RGB565 + DRM_FORMAT_RGB565, + DRM_FORMAT_NV12, + DRM_FORMAT_NV16, + DRM_FORMAT_NV24, + DRM_FORMAT_NV21, + DRM_FORMAT_NV61, + DRM_FORMAT_NV42, + DRM_FORMAT_YUV420, + DRM_FORMAT_YUV422, + DRM_FORMAT_YUV444, + DRM_FORMAT_YVU420, + DRM_FORMAT_YVU422, + DRM_FORMAT_YVU444, }; =20 static struct drm_plane_state * @@ -118,6 +130,8 @@ static void vkms_plane_atomic_update(struct drm_plane *= plane, frame_info->rotation =3D new_state->rotation; =20 vkms_plane_state->pixel_read_line =3D get_pixel_read_line_function(fmt); + get_conversion_matrix_to_argb_u16(fmt, new_state->color_encoding, new_sta= te->color_range, + &vkms_plane_state->conversion_matrix); } =20 static int vkms_plane_atomic_check(struct drm_plane *plane, --=20 2.46.2 From nobody Thu Nov 28 16:48:11 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 32FED19AA68; Mon, 30 Sep 2024 15:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710388; cv=none; b=gJf+wSKLaQSP8i+g5F0hyAAHcTWgMdRIvbiLQRemsE6dC6KHNa1mfCjKjH7sDv8eJ6CbICKyaKOlpuep0fK4rIlJXqFesrTCIk5OmzjNqtfqWTNTY0hTocfl5OmDmzKtp9wAZZLV+PcjpsSCXSyiZ8jvncV6GilkwhYYOTYqnow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710388; c=relaxed/simple; bh=gkogr80zC9IT6ygCMxlP62nYp/y4G1vFYorCtQOD8gE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bN5lN4X9gY1dMe0aioExnGpGcAqypCAFJRZXp3MRqIatw6mDNOwSt0wBFwdpOs+ZiBt/Rbk815fDWgNFN5WuukQLVHx4mVUZgg+fGQ0MpO+M6RQe4Yq4upQ+JcmgLb997qUeQvun/grE5gPIAwxI+h8Ln8ARmHVcSK8IrNuXWqw= 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=prTV6ARJ; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="prTV6ARJ" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9FECE40003; Mon, 30 Sep 2024 15:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710384; 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=LZZXCAOt96HKPNadssGl+s0w7QDIgwJlOE/lg2YiDu4=; b=prTV6ARJcXBFFXjrSbDkag4zYRA9VqLogczeMYVoaEQoDWV+FRdX8CHiblbkEne713WIzD P2X11qZKmezvHXMZj5DQCVic5WcwG1+eHuAWel5JyoxPsSujzqvBqq6TQ5gR2N+aU3ov9M VrKLgI0mDbwKgEEH7iPfaFFt4YIXFJvGhwosEmCdVWIalujoieT7daeI/HjxKlydcDPW4b 5GePnn6iiwfgmM65YrFBJSWuSYDfz3S19xr35a04hlwV4nWdH1teVFitme8rHi2xZVa01R Z74tWy6zpP9YsYO+Q7xqLxuqfbl3JAuhWA0Sjvuu1nrnrpEz5I0f0agzGGJZoA== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:51 +0200 Subject: [PATCH v11 11/15] drm/vkms: Add range and encoding properties to the plane 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: quoted-printable Message-Id: <20240930-yuv-v11-11-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1253; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=VB/TChUFVIfTCJz1NYTIIebS+nzvAngxAg3Yry+8p1o=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRwhH7a6V7XPIvJplFcV8V9Grv/RfSfJM5Rz uV/c1IJ77uJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEcAAKCRAgrS7GWxAs 4rFtD/4mYYJxPNfaLXGp6MtcaCKNr2kZBN6VJmVrHVWXLp8zwu84l5ef32rOdWYpiBkkwLF6wj3 K7nxdLzoyNQ9HUnPDniwpzzadlXvOjWhOoIOcR8V9C2I7pDa3uY7it2r4/rWJyQKhrMV6+sPz+h DdhmXOdN4+L+rFch71KdTLk3OZlhjJhgqvdqJfKi+rPBheetz+UQloxF10rnyIstvXVQNUbCbTl NUfybTV9okcYT4D6Bt6eOTJBSSJFQHRY/IinDnEayKkVtDJ+FAPPLvNJv/1LS7EcI/OQ3UqUl4I CSbjCFqOTgQyjVxcP+Hgqqqr/yhf1cNbSI5DMDqSAt8hj7lxlIrAkRsrrmrxvk4n5tnEbuHs1bj Attp1HcSWlzmrvsYQ7yAdcSNcHvGSS2ihinzfYK2BjARk2cycI4ojU9xQwDwg0kKO82IhuSfTUT 5p36Yi566PtZe5yz11xM/QObvl9qLFG4i/jBZyphhHt9oGIy1v/KqvUBZDTyeqaa64VgCJvZnef eDHkCQC9OkHhQts+K37Nh8AKw2qaO/P2W2B5KJT40sps47xZmL0Ok7R/KyuUUi2sKTHaJdALpn5 gYPzaR3IV1F85IsyaEC8P1LYlXXJhRS1jL1y9m6HwuWmF3wvqDh+RAS2yRex+FnDlyS9ugJhd8z WmkX48lrx9mx5eQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Now that the driver internally handles these quantization ranges and YUV encoding matrices, expose the UAPI for setting them. Signed-off-by: Arthur Grillo [Louis Chauvet: retained only relevant parts, updated the commit message] Acked-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_plane.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index d4e375913122..8f764a108b00 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -218,5 +218,14 @@ struct vkms_plane *vkms_plane_init(struct vkms_device = *vkmsdev, drm_plane_create_rotation_property(&plane->base, DRM_MODE_ROTATE_0, DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK); =20 + drm_plane_create_color_properties(&plane->base, + BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020), + BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE), + DRM_COLOR_YCBCR_BT601, + DRM_COLOR_YCBCR_FULL_RANGE); + return plane; } --=20 2.46.2 From nobody Thu Nov 28 16:48:12 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 EFBEE19C574; Mon, 30 Sep 2024 15:33:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710392; cv=none; b=LVvUaGuO6cqjw21KJ2VDiY8IlnuqnuLMHcVHf1TdPvrVyQeeWjun6i1cZwjbPC4bRHnLNvz1mo5R3nh9mp9TzZm4zpCvMEw8Vm4LtOLVitkgD36p+KOqlWhGaxZgZVnA5M7rtJJ3j83DTD35dmMkqSHUk2txVq/IeQXnRx3p9oQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710392; c=relaxed/simple; bh=OY3WebhRv0aeGADgqvUb4/UTEnKrmR0RzKDlWJXZa2E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U21u7QXJcVpPoLtf/jW0U7P4J9/6AFkY6LXcMVfux6ZX+ySQiMRyUiBaQw3iVSMHiSVVe6M+i9TZBqEfMJDf2T0o7dtThGG/bMU/TguEs70Uq/4VYGMSiiLaoTDf8GMcfHnkD6y12P3QPGDgkWwABiuXKS3pPD2toeiK4mMmZQ8= 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=Oa6Stl64; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Oa6Stl64" Received: by mail.gandi.net (Postfix) with ESMTPSA id DAF6240002; Mon, 30 Sep 2024 15:33:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710389; 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=hsQ2CTA2pljllkiENrEWMPdAOoEF3CDQQvjJFAj8G3E=; b=Oa6Stl64jTk6jv2DwNuaOnzTX59OBAhDQLe1mZGTedF0TAYJz/yQJahT1PFe1VgtUkaY5L 08Zaj/VXhKj64j1EIbzmWJ5jgxu6K7wfbVnPDzDwS8Nj2rEUpLQswOlSiaBqHQl4JUbeK+ hx/1yhragi8D4polubNgmU1+hqZQm/nBogSKsWaldW9VjFrrMOZM558/WvBvKAPG1FmgQN aLwsZaLueES58huOq9V4/pExRcrEsEXGUEZ3W4XOVD0g0qwpoUHMGAUQnsOGWYx+KPpBOL cbq3/5yi7d1hJ7gVmXlLGwqYXEoRUra0UEPnOSDJX3FWNKHOxkpvX4zoYrar6g== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:52 +0200 Subject: [PATCH v11 12/15] drm/vkms: Drop YUV formats TODO 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: quoted-printable Message-Id: <20240930-yuv-v11-12-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=881; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=P2BW0rn/HzAIDwl58Rwi6B7V7fHRrzFFCT1b251G+Ng=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRw343Vaj2Iumq11WgviSJGj3zkNoVfohiNT qdz9KVUqRaJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEcAAKCRAgrS7GWxAs 4glKD/4mZuw+3SRXem2zT235pwvh8vL/tWupHQ5xcG+H/jViTi0aqn5mI3MmpUeGHFD0yTetFIy 70kg08BsCX2H5IwLTJlKX9wHqmzUljMSYjTz//T+Orv8rXL2wnwcDcAAIn18nwOuNcU2REtWEJx p3OYXxXwi04HIgOLMql/Z3HEN+0RzGFWcPh/Kns7SCKUVJxmg4yQ/00qYafkWcyYNuQsU58h6ew Y1yBWlYloCnBlCIIbzf9fUtN8OPqTq+cHJYta08qRNv0M9YMoH8AXkEGMM+StTzjVMCjT1IJcvy //UbwRZ3xhtjHfhQdXRnlEHpQpf+mQC0+ojnPJwVlNjaTI1utKRhfygBAZQGM4B7/RVqGwW90q6 zGj0qRimkcE6YSF3zQpFEy9ncWdvI9TuLytfN1PhSlmFDk4EYxfCaeqbkFRwvl4AXfK0nPF0iIc h1Mbz84DqopKw9pikv6Srj+oEQcA7YJrVBI43BEgIuzWQYxsf56IKGg0ht1oeb+bZM0QI+hsfdn 7qWmKaqtrVGtY+uNlIWgcqPej3HrHkN0vR39azOHXkDclXgGk7ivq9nwBCdaoWCn5tDDwA+1Siq J//1osRl3D8Q6Ok6Ke+QdchMVlmeIZHjswd6zYpPrismQh4KhpdoMGTEPCleWL/Ssodk41L6v0k vvhNxKmwfFG2HDw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo VKMS has support for YUV formats now. Remove the task from the TODO list. Signed-off-by: Arthur Grillo Signed-off-by: Louis Chauvet --- Documentation/gpu/vkms.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst index ba04ac7c2167..13b866c3617c 100644 --- a/Documentation/gpu/vkms.rst +++ b/Documentation/gpu/vkms.rst @@ -122,8 +122,7 @@ There's lots of plane features we could add support for: =20 - Scaling. =20 -- Additional buffer formats, especially YUV formats for video like NV12. - Low/high bpp RGB formats would also be interesting. +- Additional buffer formats. Low/high bpp RGB formats would be interesting. =20 - Async updates (currently only possible on cursor plane using the legacy cursor api). --=20 2.46.2 From nobody Thu Nov 28 16:48:12 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 392BB19C574; Mon, 30 Sep 2024 15:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710398; cv=none; b=dlzLACoy96R3FGC7XwHN9kFYyPLhC+GzGoVch+kTxnaUFilht2J1SCh3KfaWFxJocMKKp+LGHZCh1X6MBBlf91ea1Z8NDTSJ8FGZEoOV3JyZOpRaG9Zb7eA6Fn3XpGf/Ep8IAVfrd+RUdqeMYAEo9fp2fGxujejyXbsNSq3ENEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710398; c=relaxed/simple; bh=7WBJVN1QAr8lG0/+0RdSMap6FQJ5gbyfNXmzUgQYjhM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RlcWRUD72c5I2SOgYPYdjVp2itFChrp6amnIjz1k3b137QxMTJ8uPvAJrNLcVsq1HujRW/giwMh1qEAh/6BM5AxdGrE5xRpOs/ZbtenFWWIOfu9pEXlnoTTVF1XfGXw6olKyQS0jHI0yGH0bqWJHqoIBF8jGhmCKBaIM43BWVJA= 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=F90zYObd; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="F90zYObd" Received: by mail.gandi.net (Postfix) with ESMTPSA id B88E040009; Mon, 30 Sep 2024 15:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710394; 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=iNGCbk5CvGMHOsDGwmLSr2ahX9fjiT+q42SPjgA0nrY=; b=F90zYObdPzjEjfeURyI4FWOikyp6M2uumMtvDs7f6qRWDOa+l75mmwU1zrycFe+QflzyTQ wYIbENevcGpDDK7er7IIGsGv7ADGq4OKEJCtYPjQ+bi6Ww5skqJqQdf5vNN3z0gsiNRcB2 eDG1Ea3SwwHeyM0iuthZDMvpEpunozqvV93mnSDS+PfDn98Ex6dFVxf6iVNVfCwXh2GU6B DPeaWh8s3MR1t75HhXeruiRKeK2UarSyvrMR+SHKMhGq9uDPqoIZWBCHxIUu+2RRkF6er4 wsfgI9resHG5Te4nDCPGfafFBlYiV6UEI6D+ZxVTFhiEotyzbh6NmUzBow/Qiw== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:53 +0200 Subject: [PATCH v11 13/15] drm/vkms: Create KUnit tests for YUV conversions 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: quoted-printable Message-Id: <20240930-yuv-v11-13-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=13761; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=uNqEYTopJejl+TyhGF8EeftCxfeA8VlyYahjLwUsBGk=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRxAv2sgsuEdauyeZhsW4saUg3lkGIwNm+m6 rqM8V1QaUmJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEcQAKCRAgrS7GWxAs 4vxND/0VI01KBnQO6ynUgkbG9MoPQM1jvMTsgR/MqHpA5MUy7ECltw9Ab2HKSOAiSO+u/v41L+2 pEqjoaA8ozUUncfkBMzYvZzIXFnNOtFWMH9SQ57wpUr3ILCS0mr1/KvtXxw9/33XmYvG6R8cbjg ERwd+B5DE+Om1Co8+ZcNoFIA6tjR8li4EA9CyAJ5gplWQeTErsGiUXHbCfHFXirAZTLFJk1n8UV 57DNFrNq4bZ5hVhpT0HL1rZLVsO6bf5XIJIrOhQRrr7lVromFpj7W2XQyTJltwgoeJ6uG2UsxpJ be9Z9bAhoFlNr2Fkc1jrXnGCrHqrGhVUZUqAGzozGYSd+wBF9TZaC2+cm+S/7tq8fAOx+G5CR/x hMm68+59PLxv5HinRK2kUsqvFVmuid0ZFiAf/Ou4oSBGF31tKHv6ULPXteRhLO4VvkHckJ69urN Wj9E/3vaGGPpbGHEYwIehkQ3OZRx8jCPX3nN2N9QajB7KQ+2JoniKTCSF9BIfzwKgjTdLYgcrCb 3ZWdvHzrXLMjR8z5WscozLwMsNqDYRZiMOcrpotMM/2cZHbda5p4EDJHDu5pl3xgMb3DJg0dNAQ IBTj+0PkA8Irw+12zdWRJUkORdOFWQfwYwDUmqLUcJ4d5u+nFZsjDW/GG6zhk7+eJn2TeOQ/afR 8RMy5duXzGU1n8g== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Create KUnit tests to test the conversion between YUV and RGB. Test each conversion and range combination with some common colors. The code used to compute the expected result can be found in comment. [Louis Chauvet: - fix minor formating issues (whitespace, double line) - change expected alpha from 0x0000 to 0xffff - adapt to the new get_conversion_matrix usage - apply the changes from Arthur - move struct pixel_yuv_u8 to the test itself] Signed-off-by: Arthur Grillo Acked-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/Kconfig | 15 ++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/Makefile | 3 + drivers/gpu/drm/vkms/tests/vkms_format_test.c | 232 ++++++++++++++++++++++= ++++ drivers/gpu/drm/vkms/vkms_formats.c | 7 +- drivers/gpu/drm/vkms/vkms_formats.h | 5 + 7 files changed, 265 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/Kconfig b/drivers/gpu/drm/vkms/Kconfig index 9def079f685b..98ecfce929f3 100644 --- a/drivers/gpu/drm/vkms/Kconfig +++ b/drivers/gpu/drm/vkms/Kconfig @@ -14,3 +14,18 @@ config DRM_VKMS a VKMS. =20 If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "KUnit tests for VKMS." if !KUNIT_ALL_TESTS + depends on DRM_VKMS=3Dy && KUNIT + default KUNIT_ALL_TESTS + help + This builds unit tests for VKMS. This option is not useful for + distributions or general kernels, but only for kernel + developers working on VKMS. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N". diff --git a/drivers/gpu/drm/vkms/Makefile b/drivers/gpu/drm/vkms/Makefile index 1b28a6a32948..8d3e46dde635 100644 --- a/drivers/gpu/drm/vkms/Makefile +++ b/drivers/gpu/drm/vkms/Makefile @@ -9,3 +9,4 @@ vkms-y :=3D \ vkms_writeback.o =20 obj-$(CONFIG_DRM_VKMS) +=3D vkms.o +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) +=3D tests/ diff --git a/drivers/gpu/drm/vkms/tests/.kunitconfig b/drivers/gpu/drm/vkms= /tests/.kunitconfig new file mode 100644 index 000000000000..70e378228cbd --- /dev/null +++ b/drivers/gpu/drm/vkms/tests/.kunitconfig @@ -0,0 +1,4 @@ +CONFIG_KUNIT=3Dy +CONFIG_DRM=3Dy +CONFIG_DRM_VKMS=3Dy +CONFIG_DRM_VKMS_KUNIT_TESTS=3Dy diff --git a/drivers/gpu/drm/vkms/tests/Makefile b/drivers/gpu/drm/vkms/tes= ts/Makefile new file mode 100644 index 000000000000..2d1df668569e --- /dev/null +++ b/drivers/gpu/drm/vkms/tests/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) +=3D vkms_format_test.o diff --git a/drivers/gpu/drm/vkms/tests/vkms_format_test.c b/drivers/gpu/dr= m/vkms/tests/vkms_format_test.c new file mode 100644 index 000000000000..351409897ca3 --- /dev/null +++ b/drivers/gpu/drm/vkms/tests/vkms_format_test.c @@ -0,0 +1,232 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include +#include + +#include "../../drm_crtc_internal.h" + +#include "../vkms_formats.h" + +#define TEST_BUFF_SIZE 50 + +MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING); + +struct pixel_yuv_u8 { + u8 y, u, v; +}; + +struct yuv_u8_to_argb_u16_case { + enum drm_color_encoding encoding; + enum drm_color_range range; + size_t n_colors; + struct format_pair { + char *name; + struct pixel_yuv_u8 yuv; + struct pixel_argb_u16 argb; + } colors[TEST_BUFF_SIZE]; +}; + +/* + * The YUV color representation were acquired via the colour python framew= ork. + * Below are the function calls used for generating each case. + * + * For more information got to the docs: + * https://colour.readthedocs.io/en/master/generated/colour.RGB_to_YCbCr.h= tml + */ +static struct yuv_u8_to_argb_u16_case yuv_u8_to_argb_u16_cases[] =3D { + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D False, + * out_int =3D True) + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT601, + .range =3D DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors =3D 6, + .colors =3D { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x4c, 0x55, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x96, 0x2c, 0x15 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d, 0xff, 0x6b }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D True, + * out_int =3D True) + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT601, + .range =3D DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors =3D 6, + .colors =3D { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x51, 0x5a, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x91, 0x36, 0x22 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x29, 0xf0, 0x6e }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D False, + * out_int =3D True) + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT709, + .range =3D DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors =3D 4, + .colors =3D { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x36, 0x63, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xb6, 0x1e, 0x0c }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x12, 0xff, 0x74 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709"], + * in_bits =3D 16, + * int_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D True, + * out_int =3D True) + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT709, + .range =3D DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors =3D 4, + .colors =3D { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x3f, 0x66, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xad, 0x2a, 0x1a }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x20, 0xf0, 0x76 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.2020"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D False, + * out_int =3D True) + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT2020, + .range =3D DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors =3D 4, + .colors =3D { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x43, 0x5c, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xad, 0x24, 0x0b }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x0f, 0xff, 0x76 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.2020"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D True, + * out_int =3D True) + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT2020, + .range =3D DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors =3D 4, + .colors =3D { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x4a, 0x61, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xa4, 0x2f, 0x19 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d, 0xf0, 0x77 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +}; + +static void vkms_format_test_yuv_u8_to_argb_u16(struct kunit *test) +{ + const struct yuv_u8_to_argb_u16_case *param =3D test->param_value; + struct pixel_argb_u16 argb; + + for (size_t i =3D 0; i < param->n_colors; i++) { + const struct format_pair *color =3D ¶m->colors[i]; + struct conversion_matrix matrix; + + get_conversion_matrix_to_argb_u16 + (DRM_FORMAT_NV12, param->encoding, param->range, &matrix); + + argb =3D argb_u16_from_yuv888(color->yuv.y, color->yuv.u, color->yuv.v, = &matrix); + + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.a, color->argb.a), 257, + "On the A channel of the color %s expected 0x%04x, got 0x%04x", + color->name, color->argb.a, argb.a); + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.r, color->argb.r), 257, + "On the R channel of the color %s expected 0x%04x, got 0x%04x", + color->name, color->argb.r, argb.r); + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.g, color->argb.g), 257, + "On the G channel of the color %s expected 0x%04x, got 0x%04x", + color->name, color->argb.g, argb.g); + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.b, color->argb.b), 257, + "On the B channel of the color %s expected 0x%04x, got 0x%04x", + color->name, color->argb.b, argb.b); + } +} + +static void vkms_format_test_yuv_u8_to_argb_u16_case_desc(struct yuv_u8_to= _argb_u16_case *t, + char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s - %s", + drm_get_color_encoding_name(t->encoding), drm_get_color_range_name(t->r= ange)); +} + +KUNIT_ARRAY_PARAM(yuv_u8_to_argb_u16, yuv_u8_to_argb_u16_cases, + vkms_format_test_yuv_u8_to_argb_u16_case_desc +); + +static struct kunit_case vkms_format_test_cases[] =3D { + KUNIT_CASE_PARAM(vkms_format_test_yuv_u8_to_argb_u16, yuv_u8_to_argb_u16_= gen_params), + {} +}; + +static struct kunit_suite vkms_format_test_suite =3D { + .name =3D "vkms-format", + .test_cases =3D vkms_format_test_cases, +}; + +kunit_test_suite(vkms_format_test_suite); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Kunit test for vkms format conversion"); diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index adb1228e5201..0b201185eae7 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -7,6 +7,8 @@ #include #include =20 +#include + #include "vkms_formats.h" =20 /** @@ -247,8 +249,8 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const= __le16 *pixel) return out_pixel; } =20 -static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 c= hannel_2, - const struct conversion_matrix *matrix) +VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 chann= el_1, u8 channel_2, + const struct conversion_matrix *matrix) { u16 r, g, b; s64 fp_y, fp_channel_1, fp_channel_2; @@ -278,6 +280,7 @@ static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y,= u8 channel_1, u8 channel =20 return argb_u16_from_u16161616(0xffff, r, g, b); } +EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); =20 /* * The following functions are read_line function for each pixel format su= pported by VKMS. diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkm= s_formats.h index d583855cb320..b4fe62ab9c65 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -13,4 +13,9 @@ void get_conversion_matrix_to_argb_u16(u32 format, enum d= rm_color_encoding encod enum drm_color_range range, struct conversion_matrix *matrix); =20 +#if IS_ENABLED(CONFIG_KUNIT) +struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel_= 2, + const struct conversion_matrix *matrix); +#endif + #endif /* _VKMS_FORMATS_H_ */ --=20 2.46.2 From nobody Thu Nov 28 16:48:12 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 3189219CD17; Mon, 30 Sep 2024 15:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710404; cv=none; b=boUGu3b4og3rUZr6zey3Jj4er9CVNjFXBRgvZyNZ6L9ZVME2YQcA90FUfbgfqoCDdPglb75dEdGeUJ4k8AsRk0PjQ3oji4ZXUbJJp38gkVv33v1MdFi+9XyKUt3kefLfoiNDNgVvvzurtUFO5igB02BDOCjS5yFbgQtqwrIdDso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710404; c=relaxed/simple; bh=L2eAww3XB8bl9Sxnoiq/z6nn2Apw5rKlRY7sfjjDvWY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bhx3OuvvaOqKNP/JJ2t7It2ftA1Gun6Ju7twnvDlsysb9Bjd4TRlRAFHonfArjxYMOv2NTW2363LrEFXcItIo/IJhaApk1KfQf4np89qzIWuW7L6NMKI4TnP7tuFGC6rGr5hGmpqZvSG5Pe8oWzCKafUJVZCDGpL65VH/GM7d8g= 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=hhs871b6; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="hhs871b6" Received: by mail.gandi.net (Postfix) with ESMTPSA id E92A340004; Mon, 30 Sep 2024 15:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710400; 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=4dr23WBAY8ZlBbMVkhnAU+t1UPEWAWhnUCz8S7CEndk=; b=hhs871b6yomt3aiEOQLzbAETgn3FPHlVA+c+wddMHiE+PICwyWkbL9cn8G9eC9d1oTpvU2 FnHOVhDUJW8yIRbjDQu1SR/QcLLnJ8DQr+sE6MOvedMOBV9B2B695uM16AesCqARR5E28H +wlDEzWi4jByXxZ48jFYERgGCmaqeEdOYb8uNpcP4W0hK9RHkZ0uikDJemky8n8qUjeWpo l7XORrkM/LoDPdSXdpSkxVxtdiW5Z5cFj77mI6Qb3qpkHQd2WfBkZuGf9GuOZG0G1oGfdT YkvyTl3xF/CDwD3RvIRFJ9k3ZOH8NxTalFubongesTVM3S2sQTltzBRkbmtc1w== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:54 +0200 Subject: [PATCH v11 14/15] drm/vkms: Add how to run the Kunit tests 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: quoted-printable Message-Id: <20240930-yuv-v11-14-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1115; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=cnp5oJy7nuzGGG9ERF9CFtbtr9GkJcMMWvS4L3S4Vps=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRxxPH8PrtvYnvsiETBjlH2karQ9lUU50ydp BI9qSNHKoWJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEcQAKCRAgrS7GWxAs 4kPIEACLPurbVFYWDcJD0z0ykYTymbh7Qp+oh/k/+1nKtC9zb//wF9oKwkJvktl1LD34crsEq0T RWeKdWGwwS5BuYVwW6SRYNLElT9NRZQJf9Uc/p0DZ+/M1tL3bGveEFSF5mLYiKpw1WeKa4E37Bj ve5ZRlAAJ5s7/r02vUnzaP0lpifngW5ujXJb6b5rSKTXV+eSJ0AWyOfzV47eVCWzHush9Ici8k1 HLQ+gHL1S4r3lCDJnVhnL1SIxmvNqOlDCU2+fR2s6QzXTZKZUkjj5SCgDgVQnRBU9cAFfKkel7M wg0gmOIFANGCoWaoMGfWLhZrrnTDuorfAODPSVHcTQMuJn5ov1MaKv03y97qVHuf1fnxxGL4jpR 2u6PHvpMbwATAJbJnTmwUwHvW6Xxykhozgh6uCTAbUHSSz0HXH59SQh68fbKGPz0eJhAZNVLfgK oujTlEt3QYV+MlElfnGxDZKsY8uDzOP/RwoKHfUR+b1wDX7bfz7KSr2kGMOpktrwa3B5kqzYLqD izZyQ7gRFKHVYBTFu34L+OcpgsqT44vSYDnwMeUuzaW9TQzK6MgiVKp0VumxmtyF2daDPz+X9sC TmzNmrIPoX3bxuW2HG1vboBcE0P/u+jnGQj4trqWZRSYcMfvv8cRQA0ul4jZCfi3RPLE6Eyi3Pm gUoYGrAoXjX5oIg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Now that we have KUnit tests, add instructions on how to run them. Signed-off-by: Arthur Grillo Signed-off-by: Louis Chauvet --- Documentation/gpu/vkms.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst index 13b866c3617c..5ef5ef2e6a21 100644 --- a/Documentation/gpu/vkms.rst +++ b/Documentation/gpu/vkms.rst @@ -89,6 +89,17 @@ You can also run subtests if you do not want to run the = entire test:: sudo ./build/tests/kms_flip --run-subtest basic-plain-flip --device "sys= :/sys/devices/platform/vkms" sudo IGT_DEVICE=3D"sys:/sys/devices/platform/vkms" ./build/tests/kms_fli= p --run-subtest basic-plain-flip =20 +Testing With KUnit +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +KUnit (Kernel unit testing framework) provides a common framework for unit= tests +within the Linux kernel. +More information in ../dev-tools/kunit/index.rst . + +To run the VKMS KUnit tests:: + + tools/testing/kunit/kunit.py run --kunitconfig=3Ddrivers/gpu/drm/vkms/te= sts + TODO =3D=3D=3D=3D =20 --=20 2.46.2 From nobody Thu Nov 28 16:48:12 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 12BEC19AD87; Mon, 30 Sep 2024 15:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710410; cv=none; b=oq533FWKGNt2R09Z26bFo7UqmjPek3kPDFYC8KkJ23/45QJ3egAlJJeU4/TgsyB0vEldgjtTvvC1ch9PojlQ0jsFBmJ6ssyPLnSfTyLcRd+bhSKh35bhYACBuIcFziZO9BYmfeUnv93UjOkZJ7gf6pIQbw4ArplBEnWa+M950hE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710410; c=relaxed/simple; bh=XA5++UHB22P8byetvVhtzmOdqkragW9YoMtVdS2c/kE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CSONef9aZMqnGczAydlm2cu/lAYolc1LpEb5mx25AjOQ8gAEaYgiX/6z/Be8QjC3TwGGOuHvFbb3myBTrfmLJW9G/ZG7u/NxJXRYx077dkGQ9nYBYUf0yz3FSqvNtY1NC82RxrCBCqhFczG8bq8eqDAv94BAMQvBBvzCGAkmkJg= 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=KEDZy4To; arc=none smtp.client-ip=217.70.183.194 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="KEDZy4To" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8D85A4000D; Mon, 30 Sep 2024 15:33:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727710406; 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=bYBVsTbvX0Vvhdgtk3+NNjlF1mcR2qZl1/lxJqF5EiU=; b=KEDZy4To1wDReMvJJZnoDXhYaI3eMl7u+xZ7HC2Y+AUYvowVSFmImmt7Xm0vJnT/y0Y/JM vfttmlXo1MGTHCZuFskAsNQf3NBL+lcLiGC+iSW22K8eEDUk3s5KnjO2cYGeBby6RAuvSz ECcNc85o9zCD+ha2PU6sWt0VnpWBl2KVS5c/kWfkWL72YCetlNXbOYxbDAMUGKSrq6TuTh jGX3VX7gxbHV+YPAM+wfM5uDJwwAL3EJjC4HnmdMrKpsHBlsSoZUzopoDAStLTlv3KLN8R 1bFLBZwGarOGWmt5aqCD3NV/hfyOBRPUDZ+ecUt8AWpXxxmAwE6tcRf9UGNkNg== From: Louis Chauvet Date: Mon, 30 Sep 2024 17:31:55 +0200 Subject: [PATCH v11 15/15] drm/vkms: Add support for DRM_FORMAT_R* 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: quoted-printable Message-Id: <20240930-yuv-v11-15-4b1a26bcfc96@bootlin.com> References: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> In-Reply-To: <20240930-yuv-v11-0-4b1a26bcfc96@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=6383; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=XA5++UHB22P8byetvVhtzmOdqkragW9YoMtVdS2c/kE=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm+sRxslpqJAhX4maJHCF8NUspIRb2MkwvIHXyK vPeFPjJyROJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZvrEcQAKCRAgrS7GWxAs 4jB6D/0SwCgBy/5Qg2V5Y2dFTXJRG+u/p5Hyv1qLu/8p+zBBY751uzSTyz8+jCSyh2B69njlZxw 4xKajdPgMA5H9ekfn0PDfUOFiYOiekKHkQAXymRJtoFsQvwAP41hNIT9zsJSfIxkW+9bt0iS/3t 4jv06zlx0VXaneW8Xeppu9nrFTTlCQK1cxZIVl3kSYqIeE4qlItsHqEou7sjTTtiF1SBpp06mIw nsbsBH4zl+bslMlVe1K1BnP3n7/qJvxab/t5eBUJiVSDZqJRDw73VdJLW2nWm+45GjQ48kEtfNH uYWuXHgfFkri+VB18ODCMP5jotB+LppXtoSX3Yw39p8ylCOXPQ4ZmllGT9UgD/xG9yhN78yrc+h mSHtmSKT3y/TF0d9bckA2oJwRV3IKxQTjA80/8IO7GopAYtADys10TIAWqZ5nigBKmrNA31POcK mKwXylkvpXexJfSh7hIenZrW4PG+PGlDhdKrktxnqJt+RF8MOIFn+vWt29anm7b4FvhiKK2WL+y FzmSOKQDC/qbhFe3oIfMQpzMEnrJLJ/oXkMzM42Aem/+jLmYEsfv+UUdGN6/oAe5fV648UIGL8d iv+tyBpdHqIfKlWjgJb4XtOg1ywSLiZi+/soY+HEn8bry4G0hu84UyjFojQWlWk+3AZyDucvQ7j DQKZa1zDudAfNRw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com This add the support for: - R1/R2/R4/R8 R1 format was tested with [1] and [2]. [1]: https://lore.kernel.org/r/20240313-new_rotation-v2-0-6230fd5cae59@boot= lin.com [2]: https://lore.kernel.org/igt-dev/20240306-b4-kms_tests-v1-0-8fe451efd2a= c@bootlin.com/ Reviewed-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_formats.c | 110 ++++++++++++++++++++++++++++++++= +++- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 0b201185eae7..f9841b8000c4 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -249,6 +249,16 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(cons= t __le16 *pixel) return out_pixel; } =20 +static struct pixel_argb_u16 argb_u16_from_gray8(u16 gray) +{ + return argb_u16_from_u8888(255, gray, gray, gray); +} + +static struct pixel_argb_u16 argb_u16_from_grayu16(u16 gray) +{ + return argb_u16_from_u16161616(0xFFFF, gray, gray, gray); +} + VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 chann= el_1, u8 channel_2, const struct conversion_matrix *matrix) { @@ -286,7 +296,7 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); * The following functions are read_line function for each pixel format su= pported by VKMS. * * They read a line starting at the point @x_start,@y_start following the = @direction. The result - * is stored in @out_pixel and in the format ARGB16161616. + * is stored in @out_pixel and in a 64 bits format, see struct pixel_argb_= u16. * * These functions are very repetitive, but the innermost pixel loops must= be kept inside these * functions for performance reasons. Some benchmarking was done in [1] wh= ere having the innermost @@ -295,6 +305,96 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33= b3a3@riseup.net/ */ =20 +static void Rx_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end =3D out_pixel + count; + int bits_per_pixel =3D drm_format_info_bpp(plane->frame_info->fb->format,= 0); + u8 *src_pixels; + int rem_x, rem_y; + + WARN_ONCE(drm_format_info_block_height(plane->frame_info->fb->format, 0) = !=3D 1, + "%s() only support formats with block_h =3D=3D 1", __func__); + + packed_pixels_addr(plane->frame_info, x_start, y_start, 0, &src_pixels, &= rem_x, &rem_y); + int bit_offset =3D (8 - bits_per_pixel) - rem_x * bits_per_pixel; + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int mask =3D (0x1 << bits_per_pixel) - 1; + int lum_per_level =3D 0xFFFF / mask; + + if (direction =3D=3D READ_LEFT_TO_RIGHT || direction =3D=3D READ_RIGHT_TO= _LEFT) { + int restart_bit_offset; + int step_bit_offset; + + if (direction =3D=3D READ_LEFT_TO_RIGHT) { + restart_bit_offset =3D 8 - bits_per_pixel; + step_bit_offset =3D -bits_per_pixel; + } else { + restart_bit_offset =3D 0; + step_bit_offset =3D bits_per_pixel; + } + + while (out_pixel < end) { + u8 val =3D ((*src_pixels) >> bit_offset) & mask; + + *out_pixel =3D argb_u16_from_grayu16((int)val * lum_per_level); + + bit_offset +=3D step_bit_offset; + if (bit_offset < 0 || 8 <=3D bit_offset) { + bit_offset =3D restart_bit_offset; + src_pixels +=3D step; + } + out_pixel +=3D 1; + } + } else if (direction =3D=3D READ_TOP_TO_BOTTOM || direction =3D=3D READ_B= OTTOM_TO_TOP) { + while (out_pixel < end) { + u8 val =3D (*src_pixels >> bit_offset) & mask; + *out_pixel =3D argb_u16_from_grayu16((int)val * lum_per_level); + src_pixels +=3D step; + out_pixel +=3D 1; + } + } +} + +static void R1_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R2_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R4_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R8_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end =3D out_pixel + count; + u8 *src_pixels; + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); + + while (out_pixel < end) { + *out_pixel =3D argb_u16_from_gray8(*src_pixels); + src_pixels +=3D step; + out_pixel +=3D 1; + } +} + static void ARGB8888_read_line(const struct vkms_plane_state *plane, int x= _start, int y_start, enum pixel_read_direction direction, int count, struct pixel_argb_u16 out_pixel[]) @@ -606,6 +706,14 @@ pixel_read_line_t get_pixel_read_line_function(u32 for= mat) case DRM_FORMAT_YVU422: case DRM_FORMAT_YVU444: return &planar_yuv_read_line; + case DRM_FORMAT_R1: + return &R1_read_line; + case DRM_FORMAT_R2: + return &R2_read_line; + case DRM_FORMAT_R4: + return &R4_read_line; + case DRM_FORMAT_R8: + return &R8_read_line; default: /* * This is a bug in vkms_plane_atomic_check(). All the supported diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index 8f764a108b00..67f891e7ac58 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -30,6 +30,10 @@ static const u32 vkms_formats[] =3D { DRM_FORMAT_YVU420, DRM_FORMAT_YVU422, DRM_FORMAT_YVU444, + DRM_FORMAT_R1, + DRM_FORMAT_R2, + DRM_FORMAT_R4, + DRM_FORMAT_R8, }; =20 static struct drm_plane_state * --=20 2.46.2