Skip to content

Commit

Permalink
DRI3: Allow specifying "auto" as DRM render node
Browse files Browse the repository at this point in the history
(This works identically to '-rendernode auto' in TigerVNC.)
  • Loading branch information
dcommander committed Jul 29, 2024
1 parent 7e73b72 commit 530b671
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion unix/Xvnc/programs/Xserver/Xvnc.man.in
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ Set the color depth of the virtual X display, in bits per pixel. Must be 8,
Enable the DRI3 X extension, which provides GPU acceleration for OpenGL and
other rendering APIs when using open source GPU drivers. \fIrender-node\fR is
the path of the DRM render node for the GPU that you wish to use (for example,
\fB/dev/dri/renderD128\fR).
\fB/dev/dri/renderD128\fR). If \fIrender-node\fR is \fBauto\fR, then the first
available DRM render node will be used.

.TP
\fB\-geometry\fR \fIwidth\fRx\fIheight\fR
Expand Down
34 changes: 34 additions & 0 deletions unix/Xvnc/programs/Xserver/hw/vnc/dri3.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <errno.h>
#include <fcntl.h>
#include <glob.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -459,6 +460,37 @@ Bool rfbDRI3Initialize(ScreenPtr pScreen)
pScreenPriv->gbm = NULL;
pScreenPriv->fd = -1;

if (strcasecmp(driNode, "auto") == 0) {
glob_t globbuf;
int ret;
size_t i;

ret = glob("/dev/dri/renderD*", 0, NULL, &globbuf);
if (ret == GLOB_NOMATCH) {
ErrorF("Could not find any DRM render nodes\n");
return FALSE;
}
if (ret != 0) {
ErrorF("Could not enumerate DRM render nodes\n");
return FALSE;
}

driNode = NULL;
for (i = 0; i < globbuf.gl_pathc; i++) {
if (access(globbuf.gl_pathv[i], R_OK | W_OK) == 0) {
driNode = strdup(globbuf.gl_pathv[i]);
break;
}
}

globfree(&globbuf);

if (driNode == NULL) {
ErrorF("Could not find any available DRM render nodes\n");
return FALSE;
}
}

pScreenPriv->fd = open(driNode, O_RDWR | O_CLOEXEC);
if (pScreenPriv->fd < 0) {
ErrorF("Failed to open DRM render node %s\n", driNode);
Expand All @@ -474,6 +506,8 @@ Bool rfbDRI3Initialize(ScreenPtr pScreen)
DRI3_WRAP(CloseScreen, rfbDRI3CloseScreen)
DRI3_WRAP(DestroyPixmap, rfbDRI3DestroyPixmap)

rfbLog("Using DRM render node %s for DRI3\n", driNode);

return dri3_screen_init(pScreen, &rfbDRI3ScreenInfo);
}

Expand Down

0 comments on commit 530b671

Please sign in to comment.