dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Stone <daniel@fooishbar.org>
To: Simon Ser <contact@emersion.fr>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Emil Velikov <emil.l.velikov@gmail.com>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	wayland <wayland-devel@lists.freedesktop.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: Re: Split render/display SoCs, Mesa's renderonly, and Wayland dmabuf hints
Date: Tue, 20 Apr 2021 11:17:26 +0100	[thread overview]
Message-ID: <CAPj87rO_DJtq6_XO400FK2u97CWXDo5Px21Q+svAPg8r+WEuCg@mail.gmail.com> (raw)
In-Reply-To: <a28f2wvjsZ0pMcKjyC4C5DgvT59Bn32JORf1DdTei3818_ZXYRGV19m5IpaWqELPeDNPSj2SRbMznfuCrCYmO0mLtpaxN5MprB3QRk3Isww=@emersion.fr>


[-- Attachment #1.1: Type: text/plain, Size: 7457 bytes --]

Hi,

On Mon, 19 Apr 2021 at 13:06, Simon Ser <contact@emersion.fr> wrote:

> I'm working on a Wayland extension [1] that, among other things, allows
> compositors to advertise the preferred device to be used by Wayland
> clients.
>
> In general, compositors will send a render node. However, in the case
> of split render/display SoCs, things get a little bit complicated.
>
> [...]
>

Thanks for the write-up Simon!


> There are a few solutions:
>
> 1. Require compositors to discover the render device by trying to import
>    a buffer. For each available render device, the compositor would
>    allocate a buffer, export it as a DMA-BUF, import it to the
>    display-only device, then try to drmModeAddFB.
>

I don't think this is actually tractable? Assuming that 'allocate a buffer'
means 'obtain a gbm_device for the render node directly and allocate a
gbm_bo from it', even with compatible formats and modifiers this will fail
for more restrictive display hardware. imx-drm and pl111 (combined with vc4
on some Raspberry Pis) will fail this, since they'll take different
allocation paths when they're bound through kmsro vs. directly, accounting
for things like contiguous allocation. So we'd get false negatives on at
least some platforms.


> 2. Allow compositors to query the render device magically opened by
>    kmsro. This could be done either via EGL_EXT_device_drm, or via a
>    new EGL extension.
>

This would be my strong preference, and I don't entirely understand
anholt's pushback here. The way I see it, GBM is about allocation for
scanout, and EGL is about rendering. If, on a split GPU/display system, we
create a gbm_device from a KMS display-only device node, then creating an
EGLDisplay from that magically binds us to a completely different DRM GPU
node, and anything using that EGLDisplay will use that GPU device to render.

Being able to discover the GPU device node through the device query is
really useful, because it tells us exactly what implicit magic EGL did
under the hood, and about the device that EGL will use. Being able to
discover the display node is much less useful; it does tell us how GBM will
allocate buffers, but the user already knows which device is in use because
they supplied it to GBM. I see the display node as a property of GBM, and
the GPU node as a property of EGL, even if EGL does do (*waves hands*)
stuff under the hood to ensure the two are compatible.

If we had EGL_EXT_explicit_device, things get even more weird, I think;
would the device query on an EGLDisplay created with a combination of a
gbm_device native display handle and an explicit EGLDevice handle return
the scanout device from GBM or the GPU device from EGL? On my reading, I'd
expect it to be the latter; if the queries returned very different things
based on whether GPU device selection was implicit (returning the KMS node)
or explicit (GPU node), that would definitely violate the principle of
least surprise.


> 3. Allow compositors to query the kernel drivers to know which devices
>    are compatible with each other. Some uAPI to query a compatible
>    display device from a render-only device, or vice-versa, has been
>    suggested in the past.
>

What does 'compatible' mean? Would an Intel iGPU and and AMD dGPU be
compatible with each other? Would a Mali GPU bound to system memory through
AMBA be as compatible with the display controller as it would with an AMD
GPU on PCIE? I think a query which only exposed whether or not devices
could share dmabufs with each other is far too generic to be helpful for
the actual usecase we have, as well as not being useful enough for other
usecases ('well you _can_ use dmabufs from your AMD GPU on your Mali GPU,
but only if they were allocated in the right domain').


> (1) has a number of limitations and gotchas. It requires allocating
> real buffers, this has a rather big cost for something done at
> compositor initialization time. It requires to select a buffer format
> and modifier compatible with both devices, so it can't be isolated in
> a simple function (and e.g. shared between all compositors in libdrm).
>

We're already going to have to do throwaway allocations to make Intel's
tiled modes work; I'd rather not extend this out to doing throwaway
allocations across device combinations as well as modifier lists.


> Some drivers will allow to drmModeAddFB buffers that can't be scanned
> out, and will only reject the buffer at atomic commit time.
>

This is 100% a KMS driver bug and should be fixed there. It's not
catastrophic, since commits can fail for any reason or none at all and
compositors are expected to handle this, but they should absolutely be
rejecting buffers which can never be scanned out at all at AddFB time.


> (2) wouldn't work with non-EGL APIs such as Vulkan. Eric Anholt seemed
> pretty opposed to this idea, but I didn't fully understood why.
>

Well, Vulkan doesn't have GBM in the same way, right? In the Vulkan case,
we already know exactly what the GPU is, because it's the VkPhysicalDevice
you had to explicitly select to create the VkDevice etc; if you're using
GBM it's because you've _also_ created a gbm_device for the KMS node and
are allocating gbm_bos to import to VkDeviceMemory/VkImage, so you already
have both pieces of information. (If you're creating VkDeviceMemory/VkImage
in Vulkan then exporting dmabuf from there, since there's no way to specify
a target device, it's a blind guess as to whether it'll actually work for
KMS. Maybe it will! But maybe not.)


> I don't know how feasible (3) is. The kernel drivers must be able to
> decide whether buffers coming from another driver can be scanned out,
> but how early can they give an answer? Can they give an answer solely
> based on a DRM node, and not a DMA-BUF?
>

Maybe! But maybe not.


> Feedback is welcome. Do you agree with the premise that compositors
> need access to the render node?


Yes, strongly. Compositors may optimise for direct paths (e.g. direct
scanout of client buffers through KMS, directly providing client buffers to
media codecs for streaming) where possible. But they must always have a
'device of last resort': if these optimal paths are not possible (your
codec doesn't like your client buffers, you can't do direct scanout because
a notification occluded your client content and you've run out of overlay
planes, you're on Intel and your display FIFO size is measured in bits),
the compositor needs to know that it can access the client buffers somehow.

This is done by always importing into a GPU device - for most current
compositors as an EGLImage, for some others as a VkImage - and falling back
to GL composition paths, or GL blits, or even ReadPixels if strictly
necessary, so your client content continues to be accessible.

There is no way to do this without telling the client what that GPU device
node is, so it can allocate accordingly. Thanks to the implicit device
selection performed when creating an EGLDisplay from a gbm_device, we
cannot currently discover what that device node is.


> Do you have any other potential solution in mind?


I can't think of any right now, but am open to hearing them.


> Which solution would you prefer?


For all the reasons above, strongly #2, i.e. that querying the DRM device
node from the EGLDevice returned by querying an EGLDisplay created from a
gbm_device, returns the GPU device's render node and not the KMS device's
primary node.

Cheers,
Daniel

[-- Attachment #1.2: Type: text/html, Size: 9891 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2021-04-20 10:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 12:05 Split render/display SoCs, Mesa's renderonly, and Wayland dmabuf hints Simon Ser
2021-04-20 10:17 ` Daniel Stone [this message]
2021-04-20 11:14   ` Daniel Vetter
2021-04-26  9:47     ` Simon Ser
2021-04-20 23:11   ` Eric Anholt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPj87rO_DJtq6_XO400FK2u97CWXDo5Px21Q+svAPg8r+WEuCg@mail.gmail.com \
    --to=daniel@fooishbar.org \
    --cc=contact@emersion.fr \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.l.velikov@gmail.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=wayland-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).