How to render to a second screen without being the DRM master?
Asked Answered
H

1

7

I have an embedded process that renders to a screen directly using DRM & KMS APIs. It's running on a minimal Yocto distribution (no desktop or Wayland). I would like to render to a second screen that is attached to the same GPU from another process. The first process opens '/dev/dri/card0' and becomes the de-facto DRM master and it can do drmModeSetCrtc & drmModePageFlip on the primary screen to display the framebuffer. However, if I call drmDropMaster it can't do the page flip anymore. Therefore the second process cannot become the DRM master and render to the other display using the same technique.

There's plenty of examples on how to render to one screen using the Direct Rendering Manager (DRM) and Kernel Mode Setting (KMS), but I found none that can render to a second screen from another process.

I would like to not have a master if possible once the display mode is set, but the page flip is also a restricted API. If this cannot be achieved, maybe an example on how to grant the second process permission using drmAuthMagic?

Hornbeck answered 10/12, 2018 at 20:4 Comment(5)
How is this related to OpenGL? I mean, if you use Mesa, then some glX context functions will help you attaching each Display to a context.Chanachance
@Ripi2: GLX assumes X11, which is not running here. And for most pure KMS+GBM environments, OpenGL is the de-facto standard graphics API being used. So while not entirely OpenGL related, it's close enough, that readers of the opengl tag might know the answer.Hysterectomize
@Fritz: Ever looked into DRM leases? x.org/wiki/Events/XDC2017/packard_drm_lease.pdfkeithp.com/blogs/DRM-lease - keithp.com/blogs/DRM-lease-2keithp.com/blogs/DRM-lease-3keithp.com/blogs/DRM-lease-4Hysterectomize
@Ripi2: There is no tags for DRM or KMS. OpenGL is what I ultimately want to use once I get passed the kernel security. I was hoping there might be a kernel patch that bypassed it completely.Hornbeck
@datenwolf: Thanks for the interesting read. I didn't think of it, but VR is very closely related to my application in the sense that latency is a main concern and it needs to drive external displays. I realize that my question is very specific and there might not be an easy solution.Hornbeck
H
7

It isn't possible to do a page flip without being the DRM master. The IOCTL is protected in drm_ioctl.c:

DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED)
DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, DRM_ROOT_ONLY),
DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_ROOT_ONLY),

So I decided to put the flip into a critical section where the application calls drmSetMaster, schedules the flip, and calls drmDropMaster. It's heavy handed and both processes need to be root, but it works well enough for an embedded platform. The process has to authorize itself however using drmGetMagic and drmAuthMagic in order for it to be able to render while it isn't the master and to grab mastership again. I do this when it first becomes master and does the mode set.

Hornbeck answered 14/12, 2018 at 21:46 Comment(1)
I think you can run that without being a root. At least on my Linux, the card0/card1 files allow access to members of video security group, and renderD128 file allows permissions to render security group. Add yourself to these groups, and it should work without root.Diplegia

© 2022 - 2024 — McMap. All rights reserved.