goto cleanup;
}
- dri2_dpy->fd_display_gpu = fcntl(dri2_dpy->fd_render_gpu, F_DUPFD_CLOEXEC, 3);
- dri2_dpy->fd_render_gpu = loader_get_user_preferred_fd(dri2_dpy->fd_render_gpu,
- &dri2_dpy->is_different_gpu);
- if (!dri2_dpy->is_different_gpu) {
- close(dri2_dpy->fd_display_gpu);
- dri2_dpy->fd_display_gpu = -1;
- }
+ dri2_dpy->is_different_gpu =
+ loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu, &dri2_dpy->fd_display_gpu);
dev = _eglAddDevice(dri2_dpy->fd_render_gpu, false);
if (!dev) {
return EGL_FALSE;
}
- dri2_dpy->fd_display_gpu = fcntl(dri2_dpy->fd_render_gpu, F_DUPFD_CLOEXEC, 3);
- dri2_dpy->fd_render_gpu = loader_get_user_preferred_fd(dri2_dpy->fd_render_gpu,
- &dri2_dpy->is_different_gpu);
- if (!dri2_dpy->is_different_gpu) {
- close(dri2_dpy->fd_display_gpu);
- dri2_dpy->fd_display_gpu = -1;
- }
+ dri2_dpy->is_different_gpu =
+ loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu, &dri2_dpy->fd_display_gpu);
dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd_render_gpu);
if (!dri2_dpy->driver_name) {
fcntl(fd, F_SETFD, FD_CLOEXEC);
free(open_reply);
- fd = loader_get_user_preferred_fd(fd, &scrn->is_different_gpu);
+ scrn->is_different_gpu = loader_get_user_preferred_fd(&fd, NULL);
geom_cookie = xcb_get_geometry(scrn->conn, RootWindow(display, screen));
geom_reply = xcb_get_geometry_reply(scrn->conn, geom_cookie, NULL);
/* Although the fd is provided from external source, mesa/nine
* takes ownership of it. */
- fd = loader_get_user_preferred_fd(fd, &different_device);
+ different_device = loader_get_user_preferred_fd(&fd, NULL);
ctx->fd = fd;
ctx->base.linear_framebuffer = different_device;
return NULL;
}
- psc->fd_display_gpu = fcntl(psc->fd_render_gpu, F_DUPFD_CLOEXEC, 3);
- psc->fd_render_gpu = loader_get_user_preferred_fd(psc->fd_render_gpu, &psc->is_different_gpu);
- if (!psc->is_different_gpu) {
- close(psc->fd_display_gpu);
- psc->fd_display_gpu = -1;
- }
+ psc->is_different_gpu =
+ loader_get_user_preferred_fd(&psc->fd_render_gpu, &psc->fd_display_gpu);
driverName = loader_get_driver_for_fd(psc->fd_render_gpu);
if (!driverName) {
return tag;
}
-int loader_get_user_preferred_fd(int default_fd, bool *different_device)
+bool loader_get_user_preferred_fd(int *fd_render_gpu, int *original_fd)
{
const char *dri_prime = getenv("DRI_PRIME");
char *default_tag, *prime = NULL;
prime = loader_get_dri_config_device_id();
#endif
- if (prime == NULL) {
- *different_device = false;
- return default_fd;
- } else {
+ if (prime == NULL)
+ goto no_prime_gpu_offloading;
+ else
prime_is_vid_did = sscanf(prime, "%hx:%hx", &vendor_id, &device_id) == 2;
- }
- default_tag = drm_get_id_path_tag_for_fd(default_fd);
+ default_tag = drm_get_id_path_tag_for_fd(*fd_render_gpu);
if (default_tag == NULL)
goto err;
if (fd < 0)
goto err;
- close(default_fd);
-
- *different_device = !!strcmp(default_tag, prime);
+ bool is_render_and_display_gpu_diff = !!strcmp(default_tag, prime);
+ if (original_fd) {
+ if (is_render_and_display_gpu_diff) {
+ *original_fd = *fd_render_gpu;
+ *fd_render_gpu = fd;
+ } else {
+ *original_fd = *fd_render_gpu;
+ close(fd);
+ }
+ } else {
+ close(*fd_render_gpu);
+ *fd_render_gpu = fd;
+ }
free(default_tag);
free(prime);
- return fd;
-
+ return is_render_and_display_gpu_diff;
err:
- *different_device = false;
-
free(default_tag);
free(prime);
- return default_fd;
+ no_prime_gpu_offloading:
+ if (original_fd)
+ *original_fd = *fd_render_gpu;
+ return false;
}
#else
int
return NULL;
}
-int loader_get_user_preferred_fd(int default_fd, bool *different_device)
-{
- *different_device = false;
- return default_fd;
+bool loader_get_user_preferred_fd(int *fd_render_gpu, int *original_fd)
+ if (original_fd)
+ *original_fd = *fd_render_gpu;
+ return false;
}
#endif
char *
loader_get_device_name_for_fd(int fd);
-/* Function to get a different device than the one we are to use by default,
- * if the user requests so and it is possible. The initial fd will be closed
- * if necessary. The returned fd is potentially a render-node.
+/* For dri prime gpu offloading this function will take current render fd and possibly
+ * update it with new prime gpu offloading fd. For dri prime gpu offloading optionally
+ * this function can return the original fd. Also this function returns true/false based
+ * on render gpu is different from display gpu.
*/
-int
-loader_get_user_preferred_fd(int default_fd, bool *different_device);
+bool
+loader_get_user_preferred_fd(int *fd_render_gpu, int *original_fd);
/* for logging.. keep this aligned with egllog.h so we can just use
* _eglLog directly.