Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp516224yba; Wed, 24 Apr 2019 05:22:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpLNd6NPyaHaTy0ik/Fj2RCqEoe4MvkfuzsNFj3bZdPstjGuRCG7vygjAglX8bUU1oQh95 X-Received: by 2002:a62:e301:: with SMTP id g1mr1625052pfh.221.1556108540025; Wed, 24 Apr 2019 05:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556108540; cv=none; d=google.com; s=arc-20160816; b=AyqMNYIkgjgR+TEIdWb7INXVohhRAEmqbAgDvBCtAsF7Lzn6LQVFYgjJdzb5szLJs+ uosA2w9LviHs6IIZqB5fg460rRZxD9o4doB0dtcw8JMxkQ+sWiV4mZApFuoPIgpS/7/d zHxUB/59uRj4usx4EbboQGpaka0q5/R2uHkHN2nDHj0KtTC6UfuwIXr6YlABslIcYnUw xGyuZe5f5H3MGXEdOlhQK+AwzJDLQssgH3giYsNEGe+KX3h4ru79M5d7poJCSBvE3qfX nxDcBNPwJrq7wnTjPR4l/UOY+Pizxz2OFTTPwGjFMbT3+xQGncNr+aJctBAZw0wRaAQA pgXA== 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=G0Rvyn3SMfh/9Z2d00rZsyXrGOM6LPXqxH9xfklxcsA=; b=e7QKy1X6E8EUsgWb/+A5p/scsW8KZHpqyolo/iarA/Y8VarelkiEj2+nMZHsnp1Jmv ZAs1ewl71SxPDhf3r/Qv97VrF8UDLOCNniiwRsMQqmd7gOf0Hzr8QjDN6yqLDkOvDp6p L4oqsFWwumGWk2ODnIYaMyoT4z/bnPqw7ylausb6Zr9YbI7JeUQ++YZhblZifT5NPI9q rKTKjipnvAUb62rX3zpr58ebtuf96rcc3qkv3RDgQJ/TK9yDttK0p/MLlmsQmsUjkqo6 I+XPUctzu0vg/iHzOtt080UzKzVKB7FKOsxsbNEkWbhmaBP5L0RgKOjWViGba+lWdFQs YRoQ== 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 e14si18781621pfn.203.2019.04.24.05.22.04; Wed, 24 Apr 2019 05:22:20 -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 S1729571AbfDXMTR (ORCPT + 99 others); Wed, 24 Apr 2019 08:19:17 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:58581 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726880AbfDXMTR (ORCPT ); Wed, 24 Apr 2019 08:19:17 -0400 X-Originating-IP: 90.88.147.33 Received: from aptenodytes (aaubervilliers-681-1-27-33.w90-88.abo.wanadoo.fr [90.88.147.33]) (Authenticated sender: paul.kocialkowski@bootlin.com) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id B826B1C0004; Wed, 24 Apr 2019 12:19:12 +0000 (UTC) Message-ID: Subject: Re: Support for 2D engines/blitters in V4L2 and DRM From: Paul Kocialkowski To: Michel =?ISO-8859-1?Q?D=E4nzer?= , Nicolas Dufresne , Daniel Vetter Cc: Alexandre Courbot , Maxime Ripard , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Tomasz Figa , Hans Verkuil , Thomas Petazzoni , Dave Airlie , Mauro Carvalho Chehab , linux-media@vger.kernel.org Date: Wed, 24 Apr 2019 14:19:11 +0200 In-Reply-To: <1d6fb659-0516-41db-257b-258e6116a4f2@daenzer.net> References: <0df3d4b5178d8a37b67b275e0771741c6c268de3.camel@bootlin.com> <20190418081816.GO13337@phenom.ffwll.local> <8265f098722d0cd5aae606d7ee6d955f168ac8f3.camel@ndufresne.ca> <987372acff18f4c66191ee52fa69dc2917e4a605.camel@bootlin.com> <1d6fb659-0516-41db-257b-258e6116a4f2@daenzer.net> 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 Wed, 2019-04-24 at 10:31 +0200, Michel Dänzer wrote: > On 2019-04-19 10:38 a.m., Paul Kocialkowski wrote: > > 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). > > Not directly. What's available is that if userspace waits for vblank n > and then submits a flip, the flip will complete in vblank n+1 (or a > later vblank, depending on when the flip is submitted and when the > fences the flip depends on signal). > > There is reluctance allowing more than one flip to be queued in the > kernel, as it would considerably increase complexity in the kernel. It > would probably only be considered if there was a compelling use-case > which was outright impossible otherwise. Well, I think it's just less boilerplace for userspace. This is indeed quite complex, and I prefer to see that complexity done once and well in Linux rather than duplicated in userspace with more or less reliable implementations. > > 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. > > Usually, this kind of queuing will be handled in a display server such > as Xorg or a Wayland compositor, not by the application such as a video > player itself, or any library in the latter's address space. I'm not > sure there's much potential for sharing code between display servers for > this. This assumes that you are using a display server, which is definitely not always the case (there is e.g. Kodi GBM). Well, I'm not saying it is essential to have it in the kernel, but it would avoid code duplication and lower the complexity in userspace. > > > 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. > > Fences are about signalling that the contents of a frame are "done" and > ready to be presented. They're not about specifying which frame is to be > presented when. Yes, that's precisely the issue I see with them. Once you have scheduled the flip with a buffer, it is too late to schedule a more recent buffer for flip if a more recent buffer is available sooner (see the issue that Nicolas is describing). If you attach a vblank target to the flip, the flip can be skipped when the fence is signaled if a more recent buffer was signaled first. > > I feel like specifying a target vblank would be a good unit for that, > > The mechanism described above works for that. I still don't see any fence-based mechanism that can work to achieve that, but maybe I'm missing your point. > > since it's our native granularity after all (while a timestamp is not). > > Note that variable refresh rate (Adaptive Sync / FreeSync / G-Sync) > changes things in this regard. It makes the vblank length variable, and > if you wait for multiple vblanks between flips, you get the maximum > vblank length corresponding to the minimum refresh rate / timing > granularity. Thus, it would be useful to allow userspace to specify a > timestamp corresponding to the earliest time when the flip is to > complete. The kernel could then try to hit that as closely as possible. I'm not very familiar with how this works, but I don't really see what it changes. Does it mean we can flip multiple times per vblank? If so, how can userspace be aware of that and deal with it properly? Unless I'm missing something, I think flip scheduling should still work on vblank granularity in that case. And I really like a vblank count over a timestamp, as one is the native unit at hand and the other one only correleates to it. Cheers, Paul -- Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com