From patchwork Tue Aug 15 18:57:05 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: 135711 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:3f2:4152:657d with SMTP id x8csp824856vqo; Tue, 15 Aug 2023 19:27:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQKJqjFTRIQxbNNVrCumHK0rHOJMjGcls/uQYKLNmgCKfcEll4yFhhsk/R9PO1hAjCoCZH X-Received: by 2002:a05:620a:1107:b0:76c:b527:1e38 with SMTP id o7-20020a05620a110700b0076cb5271e38mr577541qkk.46.1692152865199; Tue, 15 Aug 2023 19:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692152865; cv=none; d=google.com; s=arc-20160816; b=UKAmZyawTiAvzttAmhJsE6ZZtIYAuehEAI+WEV2H6Za3SKGstNWQjcDKL4kIFQ7Grl JCbYqRRmqpUXfE2X9rj+l+TonKBcPPhkWDmXT0kMJhEYWm/UTPUdyZ5LFyS5mJ5DUPkW r+kFtmzLv3ly0hG2DFv45W9/73XuBcmFh62IwWobaGfCYU4pzcuHE7bWOQgiYiJDWqVm 4IPrlKuJTOtj6AK2IKc45G6tqkCYX1OAAO5vIHRSg8ROFQTpVVMMeAm+nzi06mahdlqe XaFWe3jR3tdpjkNAwSTCDsct6JeUe0ExCMLGQX0RpDh3Ydl2ga4eAdCY+yqIJkFOAWT9 +xkA== 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=TVMdAoDdkx9jLjKJOYRYZPm8RW3qIM+jfzlkYz40wQ8=; fh=qbfaDyBg+GqerSAvcu3kFTx3mMThVk/CBXk9qNOf42k=; b=GLQcD6joAVL6V8X80iw3wR94zJREpxrrCUkudNiJUGJE9//UF3h5dSlDshDpkaUsV4 /PRG3W92sNQjqyPHvdIIWDe2hBFq6myyGTwvbGuRKptaKPCKwnwcMwFalXo/zqt1Wg+O w3Lh2OJIsHZ3jUnS7oUm4HHTLU7zANMkz4odlWP7Omf6ngF4Rut72yMF+RJHGRXbonhR CDGJwOpjOeFEmRIBJIiNdKqcca76dftagHZz/sQrvYBRd8fswkmnz+8frYYAb1cXQOMO HI2K/8DPkAlREmF22ASxM3KDwFSd+udCSu0Q78w/z0FmHpseFDqLJOekveeNouOOJjgT G2LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=QXaH3Hsu; 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 r27-20020a63fc5b000000b0055adfd70273si10456511pgk.538.2023.08.15.19.27.32; Tue, 15 Aug 2023 19:27:45 -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=QXaH3Hsu; 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 S239562AbjHOS6c (ORCPT + 99 others); Tue, 15 Aug 2023 14:58:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239516AbjHOS56 (ORCPT ); Tue, 15 Aug 2023 14:57:58 -0400 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 808BA210A for ; Tue, 15 Aug 2023 11:57:35 -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=TVMdAoDdkx9jLjKJOYRYZPm8RW3qIM+jfzlkYz40wQ8=; b=QXaH3HsuFEQMcEH7GwbLvUlIeA jJ0j5AKmwUd1XurOLY6yuEvOSakJrm0CjrwJzb+64pKDrA+Sq+yXcubkzP32SMWUPWPjCSFkupSiy +3gHY3qRyZHPKbITVtk+FRM9d/PR9R9nkF197oA8cIOQ4BdMgTm0NKorAalH1RCtRpps78Ld629Cw Bq90dEtNKgWVPMW9RRZdQuOg1zasQ4WNOD88bxfOBJKpHb3378LaRRjeemWuADci/+CUUHw+oPvMH TG6l7tZgqdaavl3RdrwRJIpDskql9COE7Pfxi4sjT5fmN+LDnXPDLeEIBk/lbimFYB4AipO8fge3b JZ1jQpPQ==; Received: from [191.193.179.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 1qVzES-001Ca3-7o; Tue, 15 Aug 2023 20:57:32 +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?= , Randy Dunlap , hwentlan@amd.com, joshua@froggi.es, ville.syrjala@linux.intel.com, =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v6 1/6] drm: allow DRM_MODE_PAGE_FLIP_ASYNC for atomic commits Date: Tue, 15 Aug 2023 15:57:05 -0300 Message-ID: <20230815185710.159779-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230815185710.159779-1-andrealmeid@igalia.com> References: <20230815185710.159779-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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,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: INBOX X-GMAIL-THRID: 1774350882839788449 X-GMAIL-MSGID: 1774350882839788449 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 --- v5: no changes 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 98d3b10c08ae..a15121e75a0a 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -1323,6 +1323,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) { @@ -1363,9 +1375,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. */ @@ -1468,6 +1487,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 ea1b639bcb28..04e6a3caa675 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -957,6 +957,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