Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2096519yba; Fri, 19 Apr 2019 12:03:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6uIfAIXcJCi55L98d4Or2g92Bi9gshg42B8USkylBtOqSI0B14YLyz/SU+5NrFuPaiyNz X-Received: by 2002:a17:902:b089:: with SMTP id p9mr5402108plr.185.1555700629823; Fri, 19 Apr 2019 12:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555700629; cv=none; d=google.com; s=arc-20160816; b=plIFLm9DK3hTch9BvYBj1LacmUiDahnZpWVG5Ze/CLTjhLgaXuxuYW/8Zk3tXtU403 UK8QKs4DnY7fROXNnLlKgxE8D5LqXDJqdslH7to62mVGVrwZKcyesj5rzS2fEJEckXXg aLwRUJIDMz09EiQorm59OjDO6K07toqxXYIgVq8fHhnxRB+jGpa6dKzQ0JOMEWJi/68v 6QX31hzs3RUPBNuj8V1we+35DpHxB35BqYK6Vkw0U/SfYmaPXZK6Mt2HC1Ta92ijjalZ E+3zxbWpgrXcHpVwSoyHQcss1gZAgfOKqa6w8iik/DQiOgRVLvJj7YXC6Ji6H1fZAltL 1ADA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=0zzdA5wwix6TSO5wGGaNDkZk0Nv2+5FWFmMZ5h6wDTI=; b=yz/kT338y9eQJUYSnvHjO+ERHvIVeCPyOn2tNzVjQIEvmvQS8BTsm3rl/M2LyRF8p+ vRBf/0gDzdRLZ2YNmVSQlMMuFGzHsDwsQMOG6DsDQwbOwRznVuS4EpvxklEt7arTFOkW dHq7t8yr+r/cb/D2b6/BfOSKHySJ+SPKKDSRK3wirA+e6lZbxz1TprfL/pfE9EDMjl+y VMyHMHrFgsntw1bZ5DWUedK1Ep7bAdR49V0/I8tvbWIR2s2M2vizjrFkgkV+sxXUDcZF uNGt6CxaqLpHhqnSdb7m5JGVbkcnrHr429o7T6yzJub5j4zyQtwZDQ8bT3AlRXcCduF1 YpAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h36si1544136plb.50.2019.04.19.12.03.31; Fri, 19 Apr 2019 12:03:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728852AbfDSTBR (ORCPT + 99 others); Fri, 19 Apr 2019 15:01:17 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:38388 "EHLO mslow2.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727665AbfDSTBQ (ORCPT ); Fri, 19 Apr 2019 15:01:16 -0400 Received: from relay1-d.mail.gandi.net (unknown [217.70.183.193]) by mslow2.mail.gandi.net (Postfix) with ESMTP id 627D03AA160; Fri, 19 Apr 2019 08:38:26 +0000 (UTC) X-Originating-IP: 90.88.160.238 Received: from aptenodytes (aaubervilliers-681-1-42-238.w90-88.abo.wanadoo.fr [90.88.160.238]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id A7ED1240013; Fri, 19 Apr 2019 08:38:20 +0000 (UTC) Message-ID: <987372acff18f4c66191ee52fa69dc2917e4a605.camel@bootlin.com> Subject: Re: Support for 2D engines/blitters in V4L2 and DRM From: Paul Kocialkowski To: Nicolas Dufresne , Daniel Vetter Cc: linux-kernel@vger.kernel.org, Alexandre Courbot , Tomasz Figa , Maxime Ripard , Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, Thomas Petazzoni , Eric Anholt , Rob Clark , Dave Airlie , Maarten Lankhorst Date: Fri, 19 Apr 2019 10:38:20 +0200 In-Reply-To: <8265f098722d0cd5aae606d7ee6d955f168ac8f3.camel@ndufresne.ca> References: <0df3d4b5178d8a37b67b275e0771741c6c268de3.camel@bootlin.com> <20190418081816.GO13337@phenom.ffwll.local> <8265f098722d0cd5aae606d7ee6d955f168ac8f3.camel@ndufresne.ca> Organization: Bootlin Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, 2019-04-18 at 20:30 -0400, Nicolas Dufresne wrote: > Le jeudi 18 avril 2019 à 10:18 +0200, Daniel Vetter a écrit : > > > It would be cool if both could be used concurrently and not just return > > > -EBUSY when the device is used with the other subsystem. > > > > We live in this world already :-) I think there's even patches (or merged > > already) to add fences to v4l, for Android. > > This work is currently suspended. It will require some feature on DRM > display to really make this useful, but there is also a lot of > challanges in V4L2. In GFX space, most of the use case are about > rendering as soon as possible. Though, in multimedia we have two > problems, we need to synchronize the frame rendering with the audio, > and output buffers may comes out of order due to how video CODECs are > made. Definitely, it feels like the DRM display side is currently a good fit for render use cases, but not so much for precise display cases where we want to try and display a buffer at a given vblank target instead of "as soon as possible". I have a userspace project where I've implemented a page flip queue, which only schedules the next flip when relevant and keeps ready buffers in the queue until then. This requires explicit vblank syncronisation (which DRM offsers, but pretty much all other display APIs, that are higher-level don't, so I'm just using a refresh-rate timer for them) and flip done notification. I haven't looked too much at how to flip with a target vblank with DRM directly but maybe the atomic API already has the bits in for that (but I haven't heard of such a thing as a buffer queue, so that makes me doubt it). Well, I need to handle stuff like SDL in my userspace project, so I have to have all that queuing stuff in software anyway, but it would be good if each project didn't have to implement that. Worst case, it could be in libdrm too. > In the first, we'd need a mechanism where we can schedule a render at a > specific time or vblank. We can of course already implement this in > software, but with fences, the scheduling would need to be done in the > driver. Then if the fence is signalled earlier, the driver should hold > on until the delay is met. If the fence got signalled late, we also > need to think of a workflow. As we can't schedule more then one render > in DRM at one time, I don't really see yet how to make that work. Indeed, that's also one of the main issues I've spotted. Before using an implicit fence, we basically have to make sure the frame is due for display at the next vblank. Otherwise, we need to refrain from using the fence and schedule the flip later, which is kind of counter- productive. So maybe adding this queue in DRM directly would make everyone's life much easier for non-render applications. I feel like specifying a target vblank would be a good unit for that, since it's our native granularity after all (while a timestamp is not). > For the second, it's complicated on V4L2 side. Currently we signal > buffers when they are ready in the display order. With fences, we > receive early pairs buffer and fence (in decoding order). There exist > cases where reordering is done by the driver (stateful CODEC). We > cannot schedule these immediately we would need a new mechanism to know > which one come next. If we just reuse current mechnism, it would void > the fence usage since the fence will always be signalled by the time it > reaches DRM or other v4l2 component. Well, our v4l2 buffers do have a timestamp and fences expose it too, so we'd need DRM to convert that to a target vblank and add it to the internal queue mentioned above. That seems doable. I think we only gave a vague meaning to the v4l2 timestamp for the decoding case and it could be any number, the timestamp when submitting decoding or the target timestamp for the frame. I think we should aim for the latter, but not sure it's always doable to know beforehand. Perhaps you have a clear idea of this? > There also other issues, for video capture pipeline, if you are not > rendering ASAP, you need the HW timestamp in order to schedule. Again, > we'd get the fence early, but the actual timestamp will be signalled at > the very last minutes, so we also risk of turning the fence into pure > overhead. Note that as we speak, I have colleagues who are > experimenting with frame timestamp prediction that slaves to the > effective timestamp (catching up over time). But we still have issues > when the capture driver skipped a frame (missed a capture window). > > I hope this is useful reflection data, It is definitely very useful and there seems to be a few things that could be improved already without too much effort. Cheers, Paul -- Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com