Bug 236933 - graphics/libdrm: drmGetNodeTypeFromFd always fails
Summary: graphics/libdrm: drmGetNodeTypeFromFd always fails
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-x11 mailing list
URL:
Keywords: needs-patch
Depends on:
Blocks:
 
Reported: 2019-04-01 14:38 UTC by Jan Beich
Modified: 2019-06-30 17:40 UTC (History)
6 users (show)

See Also:
bugzilla: maintainer-feedback? (x11)
jbeich: merge-quarterly?


Attachments
test case (426 bytes, text/plain)
2019-04-01 14:38 UTC, Jan Beich
no flags Details
fix (1.49 KB, patch)
2019-04-03 12:31 UTC, Jan Beich
no flags Details | Diff
fix, v2 (1.16 KB, patch)
2019-04-03 14:37 UTC, Jan Beich
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer 2019-04-01 14:38:19 UTC
Created attachment 203295 [details]
test case

For libva DRM backend to reliably support headless transcoding I need a way to check if the opened device is a render node. drmGetNodeTypeFromFd() == DRM_NODE_RENDER appears to be the correct way but it doesn't work on FreeBSD.

$ pkg install libdrm pkgconf
$ cc test.c -o test $(pkg-config --cflags --libs libdrm)
$ ./test
unknown (-1) node
Comment 1 Jan Beich freebsd_committer 2019-04-01 15:08:30 UTC
Nevermind. I've found a workaround.
https://github.com/intel/libva/pull/292
Comment 2 Jan Beich freebsd_committer 2019-04-03 12:31:51 UTC
Created attachment 203343 [details]
fix

Nah, libva cannot get rid of Linux-specific check without drmGetNodeTypeFromFd. Mesa also wants to check DRM_NODE_RENDER.
https://gitlab.freedesktop.org/mesa/mesa/blob/mesa-18.3.2/src/egl/drivers/dri2/platform_wayland.c#L1135
https://gitlab.freedesktop.org/mesa/mesa/blob/mesa-18.3.2/src/egl/drivers/dri2/platform_wayland.c#L1409
Comment 3 Emmanuel Vadot freebsd_committer 2019-04-03 13:15:30 UTC
Damn, this file is a mess for FreeBSD ...
Anyway I would prefer to have strrchr instead of a for loop and strtok :
int type = drmGetNodeType(strrchr(name, '/') + 1);

Do you plan to submit that upstream ?
Comment 4 Jan Beich freebsd_committer 2019-04-03 14:33:34 UTC
(In reply to Emmanuel Vadot from comment #3)
> int type = drmGetNodeType(strrchr(name, '/') + 1);

Works for me.

> Do you plan to submit that upstream ?

Where? drmGetNodeTypeFromFd doesn't support devfs-based systems upstream.
https://gitlab.freedesktop.org/mesa/drm/blob/libdrm-2.4.96/xf86drm.c#L2784-2804

General libdrm upstreaming is outside of scope for this bug. Figuring it out is the maintainer's job. I'm only responsible for libva atm but even there slow upstream feedback doesn't look exciting.
Comment 5 Emmanuel Vadot freebsd_committer 2019-04-03 14:35:00 UTC
Yeah I saw after that none of that is upstreamed yet.
I may do it but not for now.
Comment 6 Jan Beich freebsd_committer 2019-04-03 14:37:28 UTC
Created attachment 203347 [details]
fix, v2

Switch to strrchr() per comment 3. Uploading mainly to avoid ambiguity what was tested.
Comment 7 Emmanuel Vadot freebsd_committer 2019-04-03 14:39:58 UTC
Looks good to me, let's wait for X11 now.
Comment 8 commit-hook freebsd_committer 2019-06-30 17:39:47 UTC
A commit references this bug:

Author: zeising
Date: Sun Jun 30 17:39:05 UTC 2019
New revision: 505442
URL: https://svnweb.freebsd.org/changeset/ports/505442

Log:
  graphics/libdrm: fix drmGetNodeTypeFromFd

  Fix drmGetNodeTypeFromFd, this should have been part of r505441

  PR:		236933
  Submitted by:	jbeich
  Reviewed by:	manu

Changes:
  head/graphics/libdrm/files/patch-xf86drm.c
Comment 9 Niclas Zeising freebsd_committer 2019-06-30 17:40:32 UTC
Committed.  No need to merge to quarterly, new branch tonight.