render/vulkan: accept negative DRM FD to select software rendering

This commit is contained in:
Simon Ser 2024-10-03 19:03:43 +02:00
parent b4ce0d8b39
commit 24232e8e98
2 changed files with 17 additions and 16 deletions

View file

@ -2513,11 +2513,6 @@ struct wlr_renderer *wlr_vk_renderer_create_with_drm_fd(int drm_fd) {
// Do not use the drm_fd that was passed in: we should prefer the render // Do not use the drm_fd that was passed in: we should prefer the render
// node even if a primary node was provided // node even if a primary node was provided
dev->drm_fd = vulkan_open_phdev_drm_fd(phdev); dev->drm_fd = vulkan_open_phdev_drm_fd(phdev);
if (dev->drm_fd < 0) {
vulkan_device_destroy(dev);
vulkan_instance_destroy(ini);
return NULL;
}
return vulkan_renderer_create_for_device(dev); return vulkan_renderer_create_for_device(dev);
} }

View file

@ -274,7 +274,7 @@ VkPhysicalDevice vulkan_find_drm_phdev(struct wlr_vk_instance *ini, int drm_fd)
} }
struct stat drm_stat = {0}; struct stat drm_stat = {0};
if (fstat(drm_fd, &drm_stat) != 0) { if (drm_fd >= 0 && fstat(drm_fd, &drm_stat) != 0) {
wlr_log_errno(WLR_ERROR, "fstat failed"); wlr_log_errno(WLR_ERROR, "fstat failed");
return VK_NULL_HANDLE; return VK_NULL_HANDLE;
} }
@ -344,17 +344,23 @@ VkPhysicalDevice vulkan_find_drm_phdev(struct wlr_vk_instance *ini, int drm_fd)
wlr_log(WLR_INFO, " Driver name: %s (%s)", driver_props.driverName, driver_props.driverInfo); wlr_log(WLR_INFO, " Driver name: %s (%s)", driver_props.driverName, driver_props.driverInfo);
} }
if (!has_drm_props) { bool found;
wlr_log(WLR_DEBUG, " Ignoring physical device \"%s\": " if (drm_fd >= 0) {
"VK_EXT_physical_device_drm not supported", if (!has_drm_props) {
phdev_props.deviceName); wlr_log(WLR_DEBUG, " Ignoring physical device \"%s\": "
continue; "VK_EXT_physical_device_drm not supported",
phdev_props.deviceName);
continue;
}
dev_t primary_devid = makedev(drm_props.primaryMajor, drm_props.primaryMinor);
dev_t render_devid = makedev(drm_props.renderMajor, drm_props.renderMinor);
found = primary_devid == drm_stat.st_rdev || render_devid == drm_stat.st_rdev;
} else {
found = phdev_props.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU;
} }
dev_t primary_devid = makedev(drm_props.primaryMajor, drm_props.primaryMinor); if (found) {
dev_t render_devid = makedev(drm_props.renderMajor, drm_props.renderMinor);
if (primary_devid == drm_stat.st_rdev ||
render_devid == drm_stat.st_rdev) {
wlr_log(WLR_INFO, "Found matching Vulkan physical device: %s", wlr_log(WLR_INFO, "Found matching Vulkan physical device: %s",
phdev_props.deviceName); phdev_props.deviceName);
return phdev; return phdev;
@ -382,7 +388,7 @@ int vulkan_open_phdev_drm_fd(VkPhysicalDevice phdev) {
} else if (drm_props.hasPrimary) { } else if (drm_props.hasPrimary) {
devid = makedev(drm_props.primaryMajor, drm_props.primaryMinor); devid = makedev(drm_props.primaryMajor, drm_props.primaryMinor);
} else { } else {
wlr_log(WLR_ERROR, "Physical device is missing both render and primary nodes"); wlr_log(WLR_INFO, "Physical device is missing both render and primary nodes");
return -1; return -1;
} }