From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B19191DED55; Mon, 18 Nov 2024 18:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954512; cv=none; b=PM6JXKtxSFl/F9+vTntCZlJ+4SYNG4yWFCoAubqcCyTu1wuIyrYaOpj7dovstnOmkuLZiobbNVwcnZrcdRS9QGFuKl1dIkWS8ifSgxHyF7rhyoAx6eKbCgqXHQHKW8vKW7jdl1psUbDR/yOtH0mcJhbg1rvO7DwsDq/xoDwCkrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954512; c=relaxed/simple; bh=1nOox+NnkLPXHXT7FxAvq5Q+dBSkjutSPhQDbmS3n9g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qdNTu6eGtSgXOLFNa2AP6s+Te2OdXrXaTXS+eLszmukUVEVsCk7VPrvvDK7zFHnI1YbKObTwc6RSn9n/EB7PSi6ZUpjzzzH0CHNitVEj83VVzPl+klH1mCuBjISjE97W34AKWkulXix6d7keU/9fl4m7ILF/BtlbOXSit7pDoSE= 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=cTc+c+NK; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="cTc+c+NK" Received: by mail.gandi.net (Postfix) with ESMTPSA id 6508DE0009; Mon, 18 Nov 2024 18:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954507; 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=I+uY8kKAdNig6XHWYB23un73hZMbuMCUmBzpFTZRlug=; b=cTc+c+NKfDE1WYxA0DXLMkbhWp9PUU0uMfbRcyBblaNO0GAPJ0Pb/JmaizZH5U4yIgIWWM I1ZMXhgjSw5FTEnMekLwx7hZRT1RouS5T0CcJfdNJ9nrVSP8jFv6zqFa5G+tedo+HRgJzi CHi+CNv5BeYdkn5U8GtxYZPAwxSm342spvw8I8PnmoD8TN1jVGzfFNEaccIKlsEGSZ7dBf ElKYUqDFRIJKP4j0jmlrCct9RkVbayX175+fQ80TiFdVRHyfFyL27OVyWrmbziP0vkBowK diIu4zvBT4WVjqGp7NgG28UJOTnax7qRPOIzgSXU4XGzLdiN5+E1qRgY3Vfq/Q== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:16 +0100 Subject: [PATCH v14 1/9] 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: <20241118-yuv-v14-1-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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?= , =?utf-8?q?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5223; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=1nOox+NnkLPXHXT7FxAvq5Q+dBSkjutSPhQDbmS3n9g=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dEvoUy2e0XlZfi9s7MigGG91+qu97CEB581 1/P3WeBgyOJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRAAKCRAgrS7GWxAs 4lHLD/9dqgXQsgMeLKzpQMYfqw3CesxtutKVVSgavQuh3qQmh+/L1U5Z+1kYv9TLPtTaF55xfHI wMQMNwlOVU2y8qqYWDkwSApm6cZz8OAIQHnuK6gTlVwCAvEEAYgAXHmKxazCP3dg0t9m25dgeWU dPu0o0xz7MSSj1MgZh81YFZG/xIZDtELdnhv3njxZi2WPZU4gO4ouYdVdl9Byd4xPXvlGe8n0rl jDMdNBT9D8xszRI200qd1txvbWgE3PLz5R/CKIhuk0tPgde6hGjHt4CpIqZmYOxLUGEZ23r/PWV lXN8xsZXbkaEFlkFgLi2HmgGfd7NfyA1jRFPXIxyffxoK17Tn9pEifgkoTyWllfy5fUnW1qwhh6 P1nRw8vyRx2OJKAlOOJUytEuGqlkp83bSCzh1kKsWF3AB6BYPRTg91+U4fH7471QLavwSn+Zg+E ra1gk6L6wayd8tZ7ucNl6pyBXMJPo3CaoJ5shD71mHEduFIUJ4s0UO5siezwsx5wsAyCUO+KI7F gcQlwx14Mv8thUxK6RZzVjiar/RGJudxPoIugG+Y1hlH8He38B2x3jDNgVUXMWDnoKs7Q1wlR7i vanwIEgKA8zSSYj0efTuzSyFzkfbz+Iq8y1z3vvjdJoljspMBFAo6WIhPK0U+yl6s5yB5ogPOZq 6DxMhDQHe5OIhnA== 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 Reviewed-by: Jos=C3=A9 Exp=C3=B3sito 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 3f0977d746beebe20b05a1567dcfee4b673808d6..9d1ec06b986fd81949a09e67136= dd9bd5c76bf46 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 bbf080d32d2caad7dbb1198b63d875a216f969c0..28a57ae109fcc05af3fe74f9451= 8c462c09119e3 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -186,8 +186,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) @@ -203,8 +202,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 bab13943d8e0085bed85092d7bc8727d834768a9..f1ada7610376295a1b598f4a950= 5d41610b2daa2 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 e5c625ab8e3e06cb95f468c59bc3b06ef85eab6f..5a8d295e65f28cac821e4e51916= c4dd242705780 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.47.0 From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B03F1E0DF0; Mon, 18 Nov 2024 18:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954513; cv=none; b=OGr1xxzlJ37qow7XkZsxXvkNnEoo2mmWPadW/MquZNXI3cWnuMTPnDgw7Hlw1cwoimD4dzUA2O+eU6/fgQNfmk5BOUdjT9ti3QjEJ4oRkUTEn3D9crlwtPFJSCDxg2fCgSYbS9wWzbTwM5HDTSzeyKsacPI+9ghyX/lz/LkON3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954513; c=relaxed/simple; bh=c+521gWmleKYABh5f8YcpwubLVO5Tnc20Il3tE0BqE0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YC7P7Ph9uNIEmPakmRPdSrlUd99eUnPwuklwQNz873gb+xAop0EMuJwPuHvxgpIqgR8DVCNB3bzI8r+e2Oo3Oun87KTdbn0E2Hk38CVIgJRbzRR8ecYMBCNQXr2sH0UTBXYrgfzJu6mDbJ7h+swFt+zWgZHt8m3Yn0n5OWK4gaM= 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=UkWcFQnG; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="UkWcFQnG" Received: by mail.gandi.net (Postfix) with ESMTPSA id D9DD5E000A; Mon, 18 Nov 2024 18:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954509; 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=7tx86Se0JzmN2wSkI9tFn0o5J/f8HMRA8ufnfCJfwK4=; b=UkWcFQnGIwb7eTPJwAvMUxgFAVzrDmbLcUjHAeA8Fz+HIr7A7B/aT7zMV3qIHmx3eqEKTU blQOCfLM0F3QfLPbI/kaPTHSV9wPrChWv8wkujBpqGfdo7j5kXT+SramCV+NZKhlcwIU7h JqBZhY3DSLQHqKg7PsAM4zHyknV7u8CpQP6CtSEKeacMh/sfzIRdlP5oMb0UNiREBEhUAt yP8Cend90nLrEBC+dAYuiQPuYlkXMAF8DTxchnlyl8a+xlT2ZOfHuEhYtoV+a+uPmKlqLg +mNSNQf2SUFHJ5l/8J7h615eSt0Gh74tT7NIkQK0HC8ti+G/6SrM8+6mLXwsaA== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:17 +0100 Subject: [PATCH v14 2/9] 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: <20241118-yuv-v14-2-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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?= , =?utf-8?q?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4558; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=/DceU0FhaHM8eO1eSHLkINqQHmSp53P75JRctvnQQIA=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dFDJZsaHFe4r+M6Q0QuujjfglOTw+R4mFty dviIiCPICKJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRQAKCRAgrS7GWxAs 4hwAEADABpAQvIzknPdzDYb+z1ak+cZUTvfsO9ZMDvE97uCQc5Fp4Hd5hWMBL2sRCOjyhh7aNiR KGFCu5nOwzegZU4Zg18TCcVMVSSk6oSNSBiLeArj7XBVEcyui+CWHQ3bhtuB4++xSp1OQ9GLQlG j1CzBhlHl1aDZuwKpbji7hR4kml0+xjDAFAbztYpiMwiYAae2OZ5uzia5SZkWdYutJtV6it2hHh +gfemWzljUV1yAMP+OCbUQyCNALT/ig3dgidrdywlk1S9F3FuvX1Rxkb39gDGkQPseA4abOYuVj Z3lWqwzuvS1qOPCDvXRH+GM5FORMboOjrl0mHLTAqeDMCWDP1XJSovUooM9394BktFg4I63sq2t 0FIdCxzcOXTTftD+YiIFu0b8/XYcyhN/ac/62hHAKTb3B0/tj8wYFERlhLGi/g3rz+aLg8MP9QO kU2HngcDWV6C/ax6N80IemAnEYGE+RxJADPk3S1Mv10bn1v1ArR5uSrTwtqLavL7Swje8PqidzN VarZwmGAEuMGT+IYySh4A6Epl/e7Niundh6KXLkj9TPp0dr4jwJAh6UvAeacF/dOAcGqeNU+zy/ 0Rz4deR1huFKjuA9MmuSQix9nD2GrPUL5zzN+ehIEjWI8NKLUYEOVo05iApJnOeyie2+GmHsUVU 0VnJDXLvuPMj2Rw== 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: Jos=C3=A9 Exp=C3=B3sito 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 672fe191e239c03e7358d43eb19215361417a781..fcb5a5ff7df7123073f027d4773= f1a515480441a 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 e8a5cc235ebb7195340292ce71efed8435ff2748..2a0fbe27d8b28e7e9e8a12ad08a= 2cac4ba7277e7 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 5a8d295e65f28cac821e4e51916c4dd242705780..21b5adfb44aa584e1acd6697954= aabeb4e905c3c 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 999d5c01ea8116b2f3de285a79a8922901d82a7d..79918b44fedd7ae2451d1d530fc= 6d5aabf2d99a3 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.47.0 From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61B1E1E0DFD; Mon, 18 Nov 2024 18:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954515; cv=none; b=nAxJJoy+MTDfpf5DUWWQiWkWuiVi+GD/YCJxOhmFeV1Dbz2tM/Hbw4mLKTQ1Nf21RxH2WER2E9lVsFqtdhLHaapB5pH1WO0FpW0tt5hBtZbQ46iG2uRsKUiyscOQT/Os2ElzJfRr/4YzkSIGVu+2QBxz4gZtLJdcZLJi0kUAhgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954515; c=relaxed/simple; bh=T4b2XViUHvvR4aWwH5u1KViQJmrbml7Z40DA74YpBVo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bQp59hfhqTwUMQh9PYoLNoj+kwY8I7WYHTJo3li113eq8Q4hS/E85LsTJomK+rqni+1rMac5vZ1vJ2ofEL622FB69MWieZ8ChK4boCWeR+RJ72Qe76cPdJBTajpeOJUv4OgrPj5yLELHl+oHT4fVhq6Te7w8Of+OrM+wPXZ3agc= 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=ePai41CX; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ePai41CX" Received: by mail.gandi.net (Postfix) with ESMTPSA id 56F68E000B; Mon, 18 Nov 2024 18:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954510; 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=6P2Mfz9IGThFtsXlZmLSLzWykq8tqEnih/NIQDAUqUc=; b=ePai41CXaAeNPVsgN6srQyUPLiWHO6evtWHTiU8nZX8u9pFgvZXUSmTndMxVJP3UmZRnm9 Bh/bvpfqcfLlRLtAPnSQRaPWDtAquWmPeoj1gKHsFOpvr6grIr6L2HqCg8vT1gz/CUjJ0a PM7N3QOM+OjazQEpftK4JqW1IrjLS04wjFREOz712KoPQyN/YD0CJhgNuFPaFKmyuZOyhL T92+rm8fw7Pnw2nKx40ysYKiIiTcrBOdOJFBlLPjHkRuyns74Qs3IatCpR1XrIAwBn7jkU ft2aOedcVyyW55/gQDn08C6keObjcvbPo1rBSlTDP3Sl5ItfvYb9UJKsNQoxSQ== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:18 +0100 Subject: [PATCH v14 3/9] 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: <20241118-yuv-v14-3-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=13465; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=T4b2XViUHvvR4aWwH5u1KViQJmrbml7Z40DA74YpBVo=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dFtirgwgL1++aZqqF7xZfjH4D27ceqK7y/n bnuan0/T7aJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRQAKCRAgrS7GWxAs 4vtQD/sFuaLLwxJtc85YPQbmi6KnDwRbsD92a+vyhT0FoxZusEyf8n+jX+766xm31dzuRnJ1TjY nxUrFqPYixQpH0zN9kE+CBcar4lYXhRNQnj14ZIFNa32tmLWcTN/JJlAuNV7o1svCFCkKfhnI+A hsOnhO1pq+U9p8yxdpQIJXknfsTW/dFdJJNbR6MP2Qdv3YoOX1IHgjhl1MSCz7Tn33BukUAMyjG oX9JJzEamSlfJAfsjGCxaqQ8AW2+mZkqBdYWYLtha7u8hmsXDJx8cIcAe15NRzpM2CZRgWfa1N+ zNdkXOKB8+rb5H5/eNZsXwKKqqNa0LJgoxHXRMCDQIFQd7hqqvu8Drn3Mje8xSWgJkUtDwhBF42 FNYxToPO7tZp+/TK75MQF8sRlwBzEIcmVRfvYFCS93nJyfb15m/kSh8HxriOQckR1YUy61H5kI7 G7Yahtenx2Ot7c4c79y0TDfI85i87S7HHT7aUOezBL6MLYLonQ4/wQpVtX3lTmRodRQbqSqJm+O wWVsBtuFw0fWeJ/bU/ygHyhPzr6myBcIIWsR5wyVKBZd44k8iv/jvszloX55j/y7xQXwTUHgge0 GUKagT1ujgVNbk1Lmzi6Ve4CNzMTnr1YP8zqRaMsnPi0Hz39YU0JjgMnQGdX7Nljm2pBvujM7PT VYvrk0BO9O9DAHg== 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 Reviewed-by: Jos=C3=A9 Exp=C3=B3sito 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 fcb5a5ff7df7123073f027d4773f1a515480441a..e0d46defed835e5670dc1665da9= 917f807ad0c07 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 @out_pixel + * 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 2a0fbe27d8b28e7e9e8a12ad08a2cac4ba7277e7..b9544e67cd4fad7fdd4707527a6= ff8ea8f2c35be 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 cf59c2ed8e9af06c9838635e3f7819a9169494b5..3ecea456325490f41fecf35ba2d= b2676252013a6 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 21b5adfb44aa584e1acd6697954aabeb4e905c3c..10e9b23dab28359235ee0375aa1= 95fc2a4abda73 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.47.0 From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEBEF1E1025; Mon, 18 Nov 2024 18:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954516; cv=none; b=LrJbPwcCSuJclXvxIZYlcNErYR//oBEl4M/5Tzdcu4YhOGFppR1GgHfADM5D8mShXhe2AcfFXjFb47HJ6/bsTg5kcqSp05PtkF6jOJgEAN0OnqZUqESGPZKh8vtiz48LW+xxivJ+AYU3AZGYMjmq/zp9ZDLf0tZ3ztrvEU3c4Gc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954516; c=relaxed/simple; bh=OQHoOsCktDa4JPtAf7ru0Af9BSk72HJjl/EfV7gZnK8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eOaEGijS3+77SD5DMzDVloUmGey9spUKIG71+GKxOVEjWPMzq4PzNYHNRRUSABMobnYVNjQgz/1wE1kYFuvIFYUQapJu5pvAcbcye1P8YWYLF2gJb0FV48kH4GhbZyje1DS8dUwDBBRsdKMbV6Rpq+OeGmXInHCuQrR0cYDLvSk= 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=mLso3S1d; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="mLso3S1d" Received: by mail.gandi.net (Postfix) with ESMTPSA id C1809E0006; Mon, 18 Nov 2024 18:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954512; 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=hLe98ZpQwO7lx+w4LLlsZA+XPkoOuh/i6X5IcUl6w3s=; b=mLso3S1djVeNMqa2gCpS4XoKHTZTms1VIOYRL17B6HfOsvoH30d4ZoIc4s4M+aSUiz3OsU Kn1CT8/1pEUaH5sD62KRnDzwBdS6ly1HFuyhRDvb1bEL7REj/8NA3f4uyv7LCPiUy3+gUi WJLKC2dMaroZFkYIPOTI3Ofamt2GjY/WreZN9sxX1Fn1GKMCXQoRiA3FeGSo2pEDVYY5dr fRgLGfjce3myfb1+nxbfVtyWhYZc086w1+CN3+RWlhhYSU1ZfVejeM0lIr6Thnakry4z7c JylsFODBBodsiknvovCVi2xirweZKk8IIq8WIxExsMR1Fwk3rwWJ/+XxvNzMeQ== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:19 +0100 Subject: [PATCH v14 4/9] 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: <20241118-yuv-v14-4-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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?= , =?utf-8?q?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5810; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=OQHoOsCktDa4JPtAf7ru0Af9BSk72HJjl/EfV7gZnK8=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dFLJ6ckM6uHnkWUEE5S81OcClBK4Gvtt4e6 FMPptjhjOyJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRQAKCRAgrS7GWxAs 4sJ8EAC+KHeIsdr8vJUlvfKLxdnFMjj0Ru6ygUFtriBOX7JdoZj1heYZyjBzt7Rh1/ruXoT5zf5 yq/HX+LfSjMWsdBBaPv0EdJlsk1keStw0aFFwxKn2VBUAgi8awkNgg5d5GHO2uPhXjcumPhtl4m Bo+PfWhRrf9UHJpjh0wLPkpAd75PFFQMdNSnIHXEkMue7/IhAaQeFmkv4bthZ+rhlbadnSdsX7H 0otkH6Qx4kJR7G2L2/rarKhh05i4+cO9m2IdQ7eh6UcfgI1FmoCDUkwemq4nCJ027Dd7WV6YbQY rK8K1jAnj0p+njssywuo0ZUYalkPOYO6kebi72Cjw4WyLMYb7+siehmhZaJR2N1GmhHT6nbW2tK lF066v3bsrMrWmTiRuR8Xnfg23+oiKCHqPSrJLUiJLyZ2fFI6wEAItTo2yykTdsMJpeupp5BY/f KEDFOZwGuFu++iiaqSKJgk8iXS4WU2srnv61RGXoYOuqGWqDSpxZAV5tL+lkdmHIJK8roHLAtBE U6AMYze0ECg5g2i2FU1idmrvP77mj6hFiLabqVsE9psut3f3qTWVzLvbN3dNVgALW4ayssaHsLN pYLVnkA9J2smQFDeNbppuGhxQxUmu075w5T0IQ5JqKyGhDztxEK7dBOj+t3C8YFcLogD83bfRaI 0Wx0vjtPrZavq9w== 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 Reviewed-by: Jos=C3=A9 Exp=C3=B3sito 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 e0d46defed835e5670dc1665da9917f807ad0c07..3f45290a0c5d5ae8c38b79970a2= 1deea6a61a0f1 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 b9544e67cd4fad7fdd4707527a6ff8ea8f2c35be..06aef516252956eb43e111c0e16= 9f21c1ab5b482 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.47.0 From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3459B1E1045; Mon, 18 Nov 2024 18:28:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954517; cv=none; b=hSVt/6NCZwzSghfkGKzyY3SLUkrZOEtyrVOzUNpN8Kafi853ViuWI9gcQmZbE9yQf6zqr8XvEVRk7xwjjKP3OvZbxEL60kxMvNCAm5AQvx6M9E3yG7NaJWOaK8Lt46QitBirhAM7VNTE60iQoooFwb8HExHaLJuUKFD7dLDLL7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954517; c=relaxed/simple; bh=1Kj960b4ZdpGhGT0z0Y0xoNuaNBh0bRjc5MLBWSl4RQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PkBFSLsb5lYQBk91grI6xHSVW3imjF51fHyN2L/P8DLyZXY+NGfGx2ul3q0z5+mveB7Hp3lIdS6l7vmn8fk45badsHN4GRFPk6z3/DSufcpDgs+Od8Vbgdmi8SBERkzd9xtLPWlLw8wt0TNPEX25vjW+smNyEqIyZx0NJlyWDBE= 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=NC5gycjj; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="NC5gycjj" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4A0FAE000D; Mon, 18 Nov 2024 18:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954513; 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=w8vi7d1yJfeVlVH8r9QdmAldZszanwqP5SwlTzGZcXg=; b=NC5gycjjILEACgEWA8PQWetfxpyxzlVBhiLjkt4cx1m4MuGNtGY5v65Z4o1B/Tg3SCk6Vp rfdgDD4LZwn6BGnQTlj9s97S0k9xQbRElf9jbmco+VmBJxcJ+uoqag67OfnSzM6SR1VJQg GNYXRayj+FNj+atYSXai9w668BRmXGpPlDWMXW3/n9hWwDyW0H3GgnICGbdeB2i8kEDGyK zUi0SpwlfwphZePAn7q5QaUcwR/Kiec1604wNgGOOL4TYxrq8DQZWzQ6MfkrOjB6XDzo5d fA5ZUWXhL2nI2QIzNVly8tuFADrYGNCOEwrkXh1w9iazPSdeXW+rFA2UnI/0PQ== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:20 +0100 Subject: [PATCH v14 5/9] 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: <20241118-yuv-v14-5-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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, =?utf-8?q?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8956; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=1Kj960b4ZdpGhGT0z0Y0xoNuaNBh0bRjc5MLBWSl4RQ=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dGlvxvhoLib3V29k5nJ7H84oPUhzw3lGaeU QxmM5/c09KJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRgAKCRAgrS7GWxAs 4hqXD/9MOmzTy1fQ621mx4B9LwJm+3rsnrwnCf+/0ktMKd7xz/6vCw4cwoLG4piDatLChh2iKwX ho4qIjskeQQHCe1OW1sA1UZMcUpND/jK0skSaXXCv0v7RIq/ESf+qIanA3MNXs6F+5CFXVCjM+N eXAikpfjNofOrndV6yfgQMdAULdqXDIyW58EDOl53MXEW+NXnwf5FcCohN4cZpA+UMZVKR2rXLT GmhhUYhl2Vp1hbqs7H/f/wn6SF/d0Xn1eiJ/5V2gme1A8gse3fzZayTeffmvKmUdKC0Apkvbss5 w/cDOjTT+FNP+i3GPFPMkOffuH0YdWFs9AGYaqCiE8BvwozdqCSngGmvfumrhHbkwxtorwAyIVQ xCMTxsNiGqsi4RlVwRjJg/u3KDj6Pj/xZlcRU1L2WHelFNT+X4ZIXIm2WaYY1b5mMnYSHrh2npj jS2MSY5X0WLAitGMMm8hCwan/RIYGRfBwF4TxoxAkMBal4LCIL+hMNQNRLq5r3LnF4Zyw+vKRD0 QFmw/3eGbuR67BFJBW1qD8YTf6JdOFeTdzlaGCFz0kiFg1Zx1tlalmN9a9Wqk1yvcCNvFMN8Vnq PKdw3MyHjVjvUu1x3PpQ/gI8i1iQPU0/oYsAOpRUocJAaqioYuOgH9ixNPhivqMtmyEHADB5RRy f5vX8mLiRB5RFNg== 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. Acked-by: Ma=C3=ADra Canal Reviewed-by: Jos=C3=A9 Exp=C3=B3sito 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 06aef516252956eb43e111c0e169f21c1ab5b482..f9045a80aceba941568db014fec= f548d59e14a5a 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_pixels_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.47.0 From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A027F1E1338; Mon, 18 Nov 2024 18:28:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954518; cv=none; b=hXCJMFfVXDS0BJk6qLD6OZSHeRnSYqj5hHQwMzQBbEOeiU0N/SAGqrBbuki8OcBH/DPjUqbt9Uj+byTdV/mH7GnA0v8NbtJwVqJlw9MBuOZ1HDjbabSMAM+lmr2JNt7PBGxcNdLbKNBkGP5EpVFdV+kUjpOht8mn9gV/kpJkI4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954518; c=relaxed/simple; bh=U2uuDNXylIww1C2iIse1SldLLFIaLgZgPM9EJr7nGnE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k8grkDJlaei2DHoNMb198hR4Wr84bQn4+TCwNlLMfseq2AsZnxZH2fks3hesOdiy+jdEJOjSDooOWAsADjUdOnzWUCgY8EpbCK3pDU22aTBrywwhpao5x7znHFU3y68WJSNbdKXss+M5WH+LmhGLhNbXpnvDn3cv9WJlZDW/ipM= 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=TBMYDuoG; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="TBMYDuoG" Received: by mail.gandi.net (Postfix) with ESMTPSA id AA23DE000C; Mon, 18 Nov 2024 18:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954515; 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=vK9ytFaaPEDEsPnjBisZ9VIJq0X6SRCq0EddMMj7WU4=; b=TBMYDuoGbQoeVBnULviy+mtXVC8BC09/y9jGZ/Qi16zaoMy55a8uWW/R8a7arxKjxErm7O 7yoiG4UOn64wvyXbh6NofF4JCEmBElgshnsqjmuJPP9snixKuZWy83KLbRdUDOf3AJB6oD pmgEwtcQF9w6YteHZslqGhz0zARYLWmxkSeSf3Umcwgk/2hhsHC6nXypYrfqd43csYTiDs dsvEUiuLICemm6fADxdIRjMm49s1upzss8AFaf5DCcgf1uVqSJkjRuslepuKZgmuTKhDST omROF2kHxqa62BeuS5puhFHC4IeQxaAPFJd4YkHs0CRKx8IjnNQUtFgJhnDG/g== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:21 +0100 Subject: [PATCH v14 6/9] 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: <20241118-yuv-v14-6-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4191; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=U2uuDNXylIww1C2iIse1SldLLFIaLgZgPM9EJr7nGnE=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dGYi25stMLgzG6NcF6PvkI30j0f4DVCPcYp OJw5/OExf6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRgAKCRAgrS7GWxAs 4p9qEACeMh6xi7K2/oh8ZWR7VasIaub/cbx97/MVcFtuJyKpz00B1DFzNF7lCKJmjru9ysx6jQn XM/zMWDtVL7Kp6cyMvdgrVtH11+xfc5nV9vOJChvQDk0D/erxq7zCCWsWXE64nVwcmZRqIZZvn3 Y0A9HG5by2N3YrUGyWPmBswX8cGTpbO2BcaBodXQtj2gVA1Dx8ozpiT0J4yN546IGe9K+afOCwX s8zRfV/NAZbu20BQB8mKRt0epha/xGnk8QkVu8ypDn/tXkrOaQjvsWllW3nTWt6bvG/NWIkHZSx RNaHR/k303oFz12cVa0d87YQF7Mm12oB3SX3BUSdDEHmHL8GobwpCQwB/pDocnC6ws4JGfPqR1z GAKW8cu3TFEakeeIoI56Xi2PL+iL8klG27OyDGoAl950Z1JPTABkqQ6fLwi4+rjEMNOdvKXMUrD s7l+JoP+t8RAfvVVYZUfDCyY8YfIHsQB/KFYvUB+LvzAUXlWeqpii0IX3pab8vnwVWIdo5yHwnj jzEX7TYZGQpmLTAj/CLEdftMri5/zd/a9YQiGu87Rni4LvbLO+duUkYL1MrRMpt6pcuDoiD0g2S 7e9ISQ3u8aTXkktEU7X12WUFXvR2nc+05AUsE9hAWEDssyhJ91p8hgvFlr3Aner65Hv1EedUHfR DN/X0gwjAxa0+ag== 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 Reviewed-by: Jos=C3=A9 Exp=C3=B3sito 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 9d1ec06b986fd81949a09e67136dd9bd5c76bf46..e406ab4b14fd4288816565b3cab= ec93cea5834ae 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.47.0 From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE2AC1E1C0B; Mon, 18 Nov 2024 18:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954520; cv=none; b=iSK8glWRQ9gCCGq8z6v+Xr8CPd5fhSFc/nLL97xANSdIYWnOY9+e1mFg8FOtEKmw484MpZuOdTtuDF4yn8pFukGSa8zBsJSmF4phD3ACsXFWM4WgQLmK09fjJwFDXLi0naBEhs1zLU17AdXw+we+3zcJS3m9G3K8zvO0FvP87fQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954520; c=relaxed/simple; bh=qbjaHG+NidWunNkmzPOAIgCl2msJvK+z2zAIp2OEYEw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qblgBJ9Qx2GwoTVQxuIkMMwggehrgq4RIuAXC44XxsAcQG5mOsTpmHwZKsIZSmCcip/olfIfYUkKmX5z5VJLB7LGE0uMKUvB443/UK1+n6sIq0bqhfuJdvhK0K6e9p9pth4YCZLcQLxwjrh19Oq9UKmOM8WMhnXl4Xzo0S5JCGc= 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=T6Iy3vml; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="T6Iy3vml" Received: by mail.gandi.net (Postfix) with ESMTPSA id 1A034E0004; Mon, 18 Nov 2024 18:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954516; 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=gKPnlq5Kx3o1lb/orvuSMbuFeIQYveAbU0i2p2Pu0r0=; b=T6Iy3vmlSy57fIHp1p18P4USCQ8KwwpmpyD+JKpK3IsJeQMNRLFr2mSGlpUt2Cn+Rw/e9m D3CcH91qbbq+GT08dMd3G8mKQGqynShsXHFxHIsbPAlo0mQ7p0spUZ0mzd3+3vv+TKmG57 HoC6q8KKSon+Wyf+2buDAMeyG+1qMqQ6GIz5jABkQI/Sh+B08UtnilHKyxqMEboR9+bfw8 mfCnvrxTaVyRVDKYP8KEndi4V+yy5oKU4E90vHIEAIaFGMghhkM8O3vzR0kEnP93vmyPFz RrSlBjd82DRt4ct2tjWDg/qj31UNGKGDKoSg6gseQ33wxdU6wIFD41cP5ceYdw== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:22 +0100 Subject: [PATCH v14 7/9] 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: <20241118-yuv-v14-7-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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, =?utf-8?q?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5441; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=qbjaHG+NidWunNkmzPOAIgCl2msJvK+z2zAIp2OEYEw=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dGDuYVyblJnk/sKUip2s6x+zTzVNw9sKtV5 g90id+ewhSJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRgAKCRAgrS7GWxAs 4uWzD/4zPjazlNeALvc5PHev9XgvkODzcDqiaE0LGpvEl62DXMMnsdQsUKJeLTqbNmq39pm+YQd ETZ/EUlwrP8Xp51RDE5g2oix/IiiDDZ5WZaie/oEW8J7YeL2/BBNpNfkHZQTdvIqjXEdj5dcBVN /c7krEpFFwsXs95RLxNX8YLS9kSBd1jdaNbkC5xvj0D3QTvz6DOWPsuFMQ1ckX8Vf5x8QO4fk73 a66Z5IoKES4klLppz1ioF2AhOg7mgUi4TPvhK5moKWitembsOlppZEKu5wxkwDvc/CNoTDMGwUh Dq6Buy2nkUkle54zh4Z47w/wVafZ8k8GzHvRqDK3LdvOouS/3WBIYynbN/egbot8w8OMCwTArs9 LnyMGHSIhvU7/N2Mcpl1D4xZCcnE3vX89NBwqh+VPAVwJS7Nsb3sDKO/cHUI84xJdzF4jLDtNf/ Kcfje7nqKTugz0zc8EnYKWXPwY6fr6tebV2ZCY3XuGhfP6z/HRAmBpmOw97CO8gDNKjzrKdSTYk eCj3XVk9UXG0M7rt7n+rw6KAjO9c72755nQfzKMo6AATs9mPuMuR92b/McugflF/VzKWlQyttpV d5WhuC/BdQ95vNLDG4vBLh96FGoczn/Uljo4JuVOpTqs13Qt7It3sl4Cf62IUQdAyRWHF3UvTdp nTSbhKpLgfNIZ4w== 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. Acked-by: Ma=C3=ADra Canal Reviewed-by: Jos=C3=A9 Exp=C3=B3sito 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 e406ab4b14fd4288816565b3cabec93cea5834ae..c2181afa41216c38a52656bfb49= e8210c69a9e58 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 3f45290a0c5d5ae8c38b79970a21deea6a61a0f1..1ebdf5da9e6ea0224b593b4d140= 7ada4b300a85e 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 internally 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 f9045a80aceba941568db014fecf548d59e14a5a..5dad7bcec0a67b8b36fa3e8916c= 8b8bafd7b3523 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.47.0 From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FDE31E1C3E; Mon, 18 Nov 2024 18:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954522; cv=none; b=BLZZftw3SDsCfKXtTH/GRGPeCy7GLQUoqlwtzY6Eibi9uqGEdsTymzJuMSFLg1rQAq7MYvDez8V6LEwDYWV1FUbg8NiVhTiO0fSgJcjDSjN1+SayjeTF4n7qIi2c575KMvtv7veXfuIbD5gJwg0w2v3LLjrCVS/3Z3gXI8nKVfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954522; c=relaxed/simple; bh=C7UPewlmdZbZiuD9aM9QaHMIOCkYUv5u/BCjR+nTocA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a2/xJHkcFVAtJeX0QsdDpLUqQyPprBibYnv82oyN0b9hbY+cvPRncmjM+qMA6FvQxkNvoElliooCMMrV2zFwSdzHkeFzOYeyJr4Hb13+1K0eigv/YYBpxjh56KD0K1K8eYoYPnbfaVVYwZVdsQnM60LlLz1o1lhFp9nILoaT2Jw= 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=YhRaOzCj; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YhRaOzCj" Received: by mail.gandi.net (Postfix) with ESMTPSA id 6C813E0009; Mon, 18 Nov 2024 18:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954517; 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=C6WtWSSbbqjArEKEgnF1kexeE5DyX6Zr2310CpWWrf8=; b=YhRaOzCjaM4jcf0dbS373JQ81YXZACdA1tkvZowy0fZZNB0RZJim4s89YcidhRzAPO916Y p/aj51xbIDhhkv1gloYE40jZVMNdLUNOPhCif/2R8vhoU9KH6hXvd+luCJb+YDnq3f1flG haRqNWyOEcKyybxZuqGlD4cDE1G+GcxCNJTg9P2dR57vdV4lGykWdXdltt9GdOfEatYJ/6 4IfqLK2oVQMBtsg0F6rqAvZ6utUI1G5YlHIoKBI7fFrWTaaVrKheGKy/4RJaMMpvhPkkQd Oy7zt+Y0z2w4XnFj7mu6pL2YpmhWS/Y31kmwa6a2atawpYGJRHW4LRr9am98Og== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:23 +0100 Subject: [PATCH v14 8/9] 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: <20241118-yuv-v14-8-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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, =?utf-8?q?Jos=C3=A9_Exp=C3=B3sito?= , Pekka Paalanen X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=30549; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=C7UPewlmdZbZiuD9aM9QaHMIOCkYUv5u/BCjR+nTocA=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dHEP2VibEfGGko2H2sSYFnruADWV3d5hliy qm4MLUqyTOJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRwAKCRAgrS7GWxAs 4tvdEADFfVcFZbszMnc0U1MghxwIHTwEak3zSwqHuEk7aTsFVYqB/4Khm7AKlzni6cIgnkba7tZ vJzPcFkIHQDLPtSZ2V5S3i3jiSaieCKhk9yRAjHbRbaWMf1V1v1j0YgV9b+eh4vRgF6GyAZk5vs jUQpUDBh8YfS18JF82YEab/RxnysKiGN70ch8lDBwa4uetgng8AgmzZV5Vwd+FZATN4aXfmGjk3 lqNQPq2ZUE0OaRIZncmnY3/huZbMHyUdLNHGXgGC5BY6kvo9Z1Se+sNM1p7Oan08uOGMhDu4peE PWhdmPcKU5Vu4xG9BOENN1KXbfGNmKDlNrkY4G/0bcGpj3UD1D+j4RuOlOrTpjDSPBI44Gqx9zE jELPD22Lj92f2Tsi+2fUWkCF2FRYseItCPqiFFHzadNIcvSjHRgSzdBuM+s+NZjCaYutBcXxRby S1dXSA92EP9SRHcFtZ7zlGK+uCFl9dX5zFUGpPy93IxeW8BgPw5lg6WcEgFW0Q+IqQ3HYRFVmcb YOsA0RQE2c/6onUGaB10G0aOr7ycebKiXYGSL6cV0XzGoZ1O6WiScVx0hYLg1eTWduK9JlvltpR WZGWlZQu3le9XDQiqF7DhAcYCqVHQdb9XMVapoldV0Ymgv+8IzESYEqEuAkqI8MDXXnSYutlz0+ v4CavOLKkPf4e2w== 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 Reviewed-by: Jos=C3=A9 Exp=C3=B3sito 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 c2181afa41216c38a52656bfb49e8210c69a9e58..b20ac170572622b34ba76b1a9c5= dd626ca5da6fa 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 check to avoid reading outside the buffer, t= he userspace + * 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.mode.vdisplay; + int crtc_y_limit =3D crtc_state->base.mode.vdisplay; + int crtc_x_limit =3D crtc_state->base.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 1ebdf5da9e6ea0224b593b4d1407ada4b300a85e..2fb9c582a446d629920cab451e2= c9a6a218ee248 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 5dad7bcec0a67b8b36fa3e8916c8b8bafd7b3523..39b1d7c97d454dfa1420990d35e= 455ed47e57c0c 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 3ecea456325490f41fecf35ba2db2676252013a6..8d2bef95ff7974a5c852dbaf3bf= 3f45c3ac32047 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 10e9b23dab28359235ee0375aa195fc2a4abda73..8875bed7641043862fe933547be= 9f68fb4e2f59a 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.47.0 From nobody Thu Nov 21 22:01:44 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB6521E0DFB; Mon, 18 Nov 2024 18:28:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954523; cv=none; b=ocjdp7zUi1FKz6NLtGPa7EhM2x+s79ZVGbCdUWdxIqDgFs3Z29ggptd5ni9WlYSaRl0IlAmcHaDwM83L34NB0369lAKzkvCo+FGVrv8Bs6aEL88a+HCIqiuKZYcnWReDp+XzLkO6BJBnJTFjEYwycYVcK77pLgdMS3S4lJ06E6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954523; c=relaxed/simple; bh=xjvTGjXfgFXj5LQtobz7nAEZ20B22QpuW/oNRtKaDz8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=STeDZPZY6fScN1RNw3GZY2w94qqUB6rensopL5RLDcSg0rQtsWSu4QEU7rdOUcqcIgb26NiCAa1o8/fF+W3Luy0QPgebbXdMhJjPHPBBzL/5gUWXxVHMau7vO0LgUDYJG8Ko6H7m3Sz7Z3oT9LAn4Q5NJ5ngLGLvwDZ9yhp0ao4= 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=lfkJ/Jbg; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="lfkJ/Jbg" Received: by mail.gandi.net (Postfix) with ESMTPSA id D89C0E0006; Mon, 18 Nov 2024 18:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954519; 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=bqvaGMl+KmIs6tRIGUSSlJtXdl/yiooo7tTRfYyTRYw=; b=lfkJ/Jbg0A1ZknOB0R4gQXE0mAIm4oKSecHm/9Fxzrgw58Gl9tMMHEYttG7EIRlMo7Ffqw tJs5HVLFB0gpcPJ765PFzWmrtxyjFWjaoDdl3XIGSRRFhTzB8rAKrMB/4tXQk79nvyyTcZ fX4Bl4gcqL7o6lnGVKGOACMN2GABS1yHCySaj9pPYgBPxY+AtLEfqK0uy7gwYEOdJ+vQPE SdkVSZMt9w5IX6FQVDktyyjxvKeT1rB03+0PtR5t+P2pt4yxHTob+/BOzcz2Mczjep/pkz BzoDuxvJulMGYrAa28JgIK3t376oSIqDKlR6tHrCLZengZHAkJePUf9Mvg6o7g== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:24 +0100 Subject: [PATCH v14 9/9] 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: <20241118-yuv-v14-9-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@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 , Helen Koike , 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, =?utf-8?q?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1246; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=xjvTGjXfgFXj5LQtobz7nAEZ20B22QpuW/oNRtKaDz8=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dHISRrsvT6mZ5YkWlIznnL4TCKn3c633X/p +YpCshqo+mJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRwAKCRAgrS7GWxAs 4oOKEACMTXGXTZKbxHwRGWbUslBEUkGW4NaV+vJnQ8YWIdlB/lc4yNEb+mtRFnieqd54Fr9uIMu qLfCk3tK6GjDwkgZDANNcMdrEh0mXpliTXo+yITgEO1VUXRVE0lb0UNEj1mmVN9h1dc25+jF+8k HCALbMMJLVXPZILqLrM/zkSP6IBS1v870btMgxBO3aRILUgMxSBOQAjNibKfNGBcSJopei98ZmQ zvzR9gGTDe5hX87Lntkmr9hIMORq+YwUrN7uzjlVUxxU604oOl5w1CssB6jQ/jUXX7wLYAn6kgc DEUTKfojrgdnGsfSE3M+4CPU54fvT+UqWMybQ1u/XqVPr2rxENxtawtTQ8gSpttS3hlD0km5Mpc cwjGrEUQhA68/pvygGiVVqQs1+1DAfxMZnhTlDy/zRbhRBzj7N7ZYBwCjuHjJE/ZPyoo9K5Kqkc MPILhiX3222eUtYCIR7aUh7HI/n6tjCZIlQ0+7hlV0X+SQr9jxQPSm5nk3ZgETpO+CM0warFN2Z qMYQQqs5DJEIVWvnejrtaW7M9wKtOG11OMdXaxoDF2OuZWdnJ+dNoNo9RIX/D62QJIiQdKUwOlw W72phss7lLaKf5EFsXKuO0eE0it5lnVOUsvk2RZ6gEtAcL68N7DuJd5zy5HNpIXESMAj+8vWVeq WM7pBmuvpNPGHjQ== 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. Acked-by: Ma=C3=ADra Canal Reviewed-by: Jos=C3=A9 Exp=C3=B3sito 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 8875bed7641043862fe933547be9f68fb4e2f59a..5a028ee96c9143709337abc7dad= 0ec608efb3ab4 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.47.0