From patchwork Sat Jul 1 02:09:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 114938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10789596vqr; Fri, 30 Jun 2023 19:38:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45mPU3kwtHR774L3gb1o9QT+28TL/caFbR5L3ZOHJjM67nT0HzT0XtTwK+y1QZRK8GzXiW X-Received: by 2002:a05:6a20:7d99:b0:12b:f44f:bc98 with SMTP id v25-20020a056a207d9900b0012bf44fbc98mr5025252pzj.21.1688179082825; Fri, 30 Jun 2023 19:38:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688179082; cv=none; d=google.com; s=arc-20160816; b=KJjOXYUqCWAV7VeJS8zAqbnH45CHdB8gVa9zmAu9LHdjnkDfVLoK7YQeIm9aGYidgM 4v5t5GyCPxh0rrewgXVdwUZkKIRJznGbpPHeesvoQwsKcsxODPnjii2OCOFgI4mQ9E4Q VYUbq8Bk9dbrowFqeAS1Vjq3ecNKmES8rtutlFUzXNidpAifEVtV/XUMXTLlH8VWhe6W KsLUGWpDvdpWEPhzvBnsqIQLrFkZPDA0y7yR5wvubxrxvocXUGbsrw7E6ITnUz7A3Il0 AI8Csv5THmJEjW2RGWS5QKN4W41TPh+/GJFgmRQexgmRgPUWbUB8eSLtXfc+yXO1AWd1 nYdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lbvpM8EakHHy+USxQroX9eqPrbtC1pudfZEWMIGGBk8=; fh=yJKnCMONMPDb5DcRuNlFPqebkFeNCW1ydpZFk0usg5k=; b=aGljBSYSG8/L8kFa7OatJGPG+8qLD9L9eoqWDh/sweLIy/pe8U1osJR480kokxViQs Kg7K9V+5ZPN/EaIzZPNB3frd8IA3Qc0iHWSNA7EekDr0aBKjV1e8Y2uDrSmtcr1Fwn1J l3//PoMz5RQjHTBT35UVSVLUea/vbnb4wg2lcnTFJ4KDYfCC6x9DhRqCeUts699vEqpG w6ySP9WbPog/bfHKMG5X3pk0FglliJYt+7PiW/kear6t801TaMn9hKsAqeYwf9g66aKw QNqoQHiHX0DVceXnBGGpfzMspuN0yCTipk+pWIuMuLttTHTpSv7OrCzinM6zlfWIFprk 55JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=jAChnC3X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv125-20020a632e83000000b0055b7171f869si1493562pgb.189.2023.06.30.19.37.41; Fri, 30 Jun 2023 19:38:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=jAChnC3X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbjGACJn (ORCPT + 99 others); Fri, 30 Jun 2023 22:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbjGACJg (ORCPT ); Fri, 30 Jun 2023 22:09:36 -0400 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D2484212 for ; Fri, 30 Jun 2023 19:09:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=lbvpM8EakHHy+USxQroX9eqPrbtC1pudfZEWMIGGBk8=; b=jAChnC3XqO7clZ/D2UTM1bk7V+ ACA7rfSqiHtTvJaIgmVDgk55VAkxAmI4Bd7QI32sJhjL308zVBz4J4IlNor6WNWW00oZLLbfGBSkX 6JRw0ro4uj+GBUCsCqs2QnCZ0Jvrq9aeuo96lkILj4+NSjsOfbGF201fbt0bZYA+sf/EOsxAv1+f/ 70ko7KOkjMmY9XOMJ/KXVTjWIdL84rd1IBnKsIZNAWqJvhUxrPh+wZY0PmVfNFp4Zes3hcRRny7dU 8abbZpMs1sj9rvGQYi/7XPm5PAMc95/orFVitWvHu7U8c2Ev3vIfFWyIEh2TcoldMRj28N38oUMgY ZDTUbvwg==; Received: from [187.74.70.209] (helo=steammachine.lan) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1qFQ3G-006abr-R6; Sat, 01 Jul 2023 04:09:31 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, wayland-devel@lists.freedesktop.org Cc: kernel-dev@igalia.com, alexander.deucher@amd.com, christian.koenig@amd.com, pierre-eric.pelloux-prayer@amd.com, Simon Ser , Rob Clark , Pekka Paalanen , Daniel Vetter , Daniel Stone , =?utf-8?b?J01hcmVrIE9sxaHDoWsn?= , Dave Airlie , =?utf-8?q?Michel_D=C3=A4nzer?= , Italo Nicola , Randy Dunlap , hwentlan@amd.com, joshua@froggi.es, ville.syrjala@linux.intel.com, =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v4 1/6] drm: allow DRM_MODE_PAGE_FLIP_ASYNC for atomic commits Date: Fri, 30 Jun 2023 23:09:12 -0300 Message-ID: <20230701020917.143394-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230701020917.143394-1-andrealmeid@igalia.com> References: <20230701020917.143394-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770184069995305676?= X-GMAIL-MSGID: =?utf-8?q?1770184069995305676?= From: Simon Ser If the driver supports it, allow user-space to supply the DRM_MODE_PAGE_FLIP_ASYNC flag to request an async page-flip. Set drm_crtc_state.async_flip accordingly. Document that drivers will reject atomic commits if an async flip isn't possible. This allows user-space to fall back to something else. For instance, Xorg falls back to a blit. Another option is to wait as close to the next vblank as possible before performing the page-flip to reduce latency. Signed-off-by: Simon Ser Reviewed-by: Alex Deucher Co-developed-by: André Almeida Signed-off-by: André Almeida --- v4: no changes --- drivers/gpu/drm/drm_atomic_uapi.c | 28 +++++++++++++++++++++++++--- include/uapi/drm/drm_mode.h | 9 +++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index d867e7f9f2cd..dfd4cf7169df 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -1286,6 +1286,18 @@ static void complete_signaling(struct drm_device *dev, kfree(fence_state); } +static void +set_async_flip(struct drm_atomic_state *state) +{ + struct drm_crtc *crtc; + struct drm_crtc_state *crtc_state; + int i; + + for_each_new_crtc_in_state(state, crtc, crtc_state, i) { + crtc_state->async_flip = true; + } +} + int drm_mode_atomic_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { @@ -1326,9 +1338,16 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, } if (arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) { - drm_dbg_atomic(dev, - "commit failed: invalid flag DRM_MODE_PAGE_FLIP_ASYNC\n"); - return -EINVAL; + if (!dev->mode_config.async_page_flip) { + drm_dbg_atomic(dev, + "commit failed: DRM_MODE_PAGE_FLIP_ASYNC not supported\n"); + return -EINVAL; + } + if (dev->mode_config.atomic_async_page_flip_not_supported) { + drm_dbg_atomic(dev, + "commit failed: DRM_MODE_PAGE_FLIP_ASYNC not supported with atomic\n"); + return -EINVAL; + } } /* can't test and expect an event at the same time. */ @@ -1426,6 +1445,9 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, if (ret) goto out; + if (arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) + set_async_flip(state); + if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) { ret = drm_atomic_check_only(state); } else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) { diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h index 46becedf5b2f..56342ba2c11a 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -949,6 +949,15 @@ struct hdr_output_metadata { * Request that the page-flip is performed as soon as possible, ie. with no * delay due to waiting for vblank. This may cause tearing to be visible on * the screen. + * + * When used with atomic uAPI, the driver will return an error if the hardware + * doesn't support performing an asynchronous page-flip for this update. + * User-space should handle this, e.g. by falling back to a regular page-flip. + * + * Note, some hardware might need to perform one last synchronous page-flip + * before being able to switch to asynchronous page-flips. As an exception, + * the driver will return success even though that first page-flip is not + * asynchronous. */ #define DRM_MODE_PAGE_FLIP_ASYNC 0x02 #define DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE 0x4