Skip to content

Commit

Permalink
Use NVD_GPU to control which DRM node to open in direct backend mode
Browse files Browse the repository at this point in the history
When running in direct backend mode, we need to open the DRM node
ourselves, and the first node may not be the right one.

We will iterate through the DRM nodes looking for NVIDIA GPUs and will
use the first one found or the one identified by NVD_GPU if set.
  • Loading branch information
philipl committed Dec 11, 2022
1 parent 4aa66f2 commit ea63f1a
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/direct/direct-export-buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,44 @@ bool direct_initExporter(NVDriver *drv) {

//make sure we have a drm fd
if (drv->drmFd == -1) {
//TODO make this configurable
drv->drmFd = open("/dev/dri/renderD128", O_RDWR|O_CLOEXEC);
LOG("Manually opened DRM device");
uint8_t nvdGpu = 0;
char *nvdGpuStr = getenv("NVD_GPU");
if (nvdGpuStr != NULL) {
nvdGpu = atoi(nvdGpuStr);
}

int fd = -1;
uint8_t drmIdx = 128;
uint8_t nvIdx = 0;
char node[20] = {0, };
do {
snprintf(node, 20, "/dev/dri/renderD%d", drmIdx++);
fd = open(node, O_RDWR|O_CLOEXEC);
if (fd == -1) {
LOG("Unable to find NVIDIA GPU %d", nvdGpu);
return false;
}

char name[16] = {0};
struct drm_version ver = {
.name = name,
.name_len = 15
};
int ret = ioctl(fd, DRM_IOCTL_VERSION, &ver);
if (ret || strncmp(name, "nvidia-drm", 10)) {
close(fd);
continue;
}
if (nvIdx != nvdGpu) {
close(fd);
nvIdx++;
continue;
}
break;
} while (fd != -1);

drv->drmFd = fd;
LOG("Found NVIDIA GPU %d at %s", nvdGpu, node);
} else {
//dup it so we can close it later and not effect firefox
drv->drmFd = dup(drv->drmFd);
Expand Down

0 comments on commit ea63f1a

Please sign in to comment.