egl/glx: fallback to software when Zink is forced and fails
authorJosé Expósito <jexposit@redhat.com>
Tue, 14 Nov 2023 08:23:23 +0000 (09:23 +0100)
committerEric Engestrom <eric@engestrom.ch>
Wed, 20 Dec 2023 00:05:03 +0000 (00:05 +0000)
commitab4a2e97a9ae8340f755193f8d0b4f8cfa929b23
treef0065caf945e689d73db6ef258b6f943d67c3683
parent684d11421c30c0f8230ccbcc8dcc94a457eb5f44
egl/glx: fallback to software when Zink is forced and fails

When `MESA_LOADER_DRIVER_OVERRIDE` is set to `zink` and the display
initialization fails, fallback to software rendering.

The error was reported in #10123 and it can be reproduced with:

    $ MESA_LOADER_DRIVER_OVERRIDE=zink eglinfo

`eglinfo` would crash in `dri2_display_release()` because of
`assert(dri2_dpy->ref_count > 0)`.

After bisecting the error to commit 8cd44b884387 ("egl/glx: add
autoloading for zink"), I found out that, before this change, the
display was set to initialized even when `_eglDriver.Initialize(disp)`
failed:

    disp->Options.Zink = env && !strcmp(env, "zink");
    // disp->Options.Zink is true

    if (!_eglDriver.Initialize(disp)) {
       [...]
       // Zink initialization has failed at this point
       // However, success is set to true:
       bool success = disp->Options.Zink;
       if (!disp->Options.Zink && !getenv("GALLIUM_DRIVER")) {
          [...]
       }
       // Software initialization is ignored because success is true
       if (!success) {
          [...]
       }
    }

    // The display is set as initialized even though it shouldn't
    disp->Initialized = EGL_TRUE;

Resolves: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10123
Fixes: 8cd44b884387 ("egl/glx: add autoloading for zink")
Signed-off-by: José Expósito <jexposit@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26184>
(cherry picked from commit d913927fe9201f0fea71ef0e614b9c400c122d49)
.pick_status.json
src/egl/main/eglapi.c