egl: fix zink init

* close(fd) requires also resetting the fd=-1 or else boom
* checking just driver_name is broken because loader_get_driver_for_fd()
  uses MESA_LOADER_DRIVER_OVERRIDE, so there's no way to differentiate
  an inferred load

Fixes: b907eb4750 ("egl: don't bind zink under dri2/3")

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30556>
(cherry picked from commit 1a579552af)
This commit is contained in:
Mike Blumenkrantz 2024-08-07 14:55:39 -04:00 committed by Eric Engestrom
parent 07c99c55e1
commit 262e3b3b6f
4 changed files with 8 additions and 7 deletions

View file

@ -2494,7 +2494,7 @@
"description": "egl: fix zink init",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "b907eb475043a25d7d80f81a5d81ddebfa335399",
"notes": null

View file

@ -1578,7 +1578,7 @@ dri2_initialize_x11_swrast(_EGLDisplay *disp)
if (disp->Options.Zink &&
!debug_get_bool_option("LIBGL_DRI3_DISABLE", false) &&
!debug_get_bool_option("LIBGL_KOPPER_DRI2", false))
dri3_x11_connect(dri2_dpy);
dri3_x11_connect(dri2_dpy, disp->Options.Zink);
#endif
if (!dri2_load_driver_swrast(disp))
goto cleanup;
@ -1658,7 +1658,7 @@ dri2_initialize_x11_dri3(_EGLDisplay *disp)
if (!dri2_get_xcb_connection(disp, dri2_dpy))
goto cleanup;
status = dri3_x11_connect(dri2_dpy);
status = dri3_x11_connect(dri2_dpy, disp->Options.Zink);
if (status != DRI2_EGL_DRIVER_LOADED)
goto cleanup;

View file

@ -539,7 +539,7 @@ struct dri2_egl_display_vtbl dri3_x11_display_vtbl = {
#endif
enum dri2_egl_driver_fail
dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
dri3_x11_connect(struct dri2_egl_display *dri2_dpy, bool zink)
{
xcb_dri3_query_version_reply_t *dri3_query;
xcb_dri3_query_version_cookie_t dri3_query_cookie;
@ -635,15 +635,16 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
if (!dri2_dpy->driver_name)
dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd_render_gpu);
if (!strcmp(dri2_dpy->driver_name, "zink") &&
!debug_get_bool_option("LIBGL_KOPPER_DISABLE", false)) {
if (!zink && !strcmp(dri2_dpy->driver_name, "zink")) {
close(dri2_dpy->fd_render_gpu);
dri2_dpy->fd_render_gpu = -1;
return DRI2_EGL_DRIVER_PREFER_ZINK;
}
if (!dri2_dpy->driver_name) {
_eglLog(_EGL_WARNING, "DRI3: No driver found");
close(dri2_dpy->fd_render_gpu);
dri2_dpy->fd_render_gpu = -1;
return DRI2_EGL_DRIVER_FAILED;
}

View file

@ -36,6 +36,6 @@ extern const __DRIimageLoaderExtension dri3_image_loader_extension;
extern struct dri2_egl_display_vtbl dri3_x11_display_vtbl;
enum dri2_egl_driver_fail
dri3_x11_connect(struct dri2_egl_display *dri2_dpy);
dri3_x11_connect(struct dri2_egl_display *dri2_dpy, bool zink);
#endif