diff options
author | Emma Anholt <emma@anholt.net> | 2022-11-28 16:44:28 -0800 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2022-12-05 19:26:41 +0000 |
commit | 3ae6ec9f60651dd5b57c05c8e35b83dbdde66eec (patch) | |
tree | ae20d4c4ec722e12d7165c938218926350844cff /src/glx | |
parent | e864047f971d17aa11db406083dbc9eaf2cc5956 (diff) | |
download | mesa-3ae6ec9f60651dd5b57c05c8e35b83dbdde66eec.tar.gz mesa-3ae6ec9f60651dd5b57c05c8e35b83dbdde66eec.tar.bz2 mesa-3ae6ec9f60651dd5b57c05c8e35b83dbdde66eec.zip |
glx: Use loader_bind_extensions().
This adds more consistent logging on failure and gives us a spot for
version checks.
Reviewed-by: Adam Jackson <ajax@redhat.com>
Acked-by: Eric Engestrom <eric@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20069>
Diffstat (limited to 'src/glx')
-rw-r--r-- | src/glx/dri2_glx.c | 70 | ||||
-rw-r--r-- | src/glx/dri3_glx.c | 67 | ||||
-rw-r--r-- | src/glx/drisw_glx.c | 63 |
3 files changed, 83 insertions, 117 deletions
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 2f56629f7c8..553ba1dba77 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -976,45 +976,39 @@ dri2BindExtensions(struct dri2_screen *psc, struct glx_display * priv, "GLX_EXT_create_context_es2_profile"); } + static const struct dri_extension_match exts[] = { + { __DRI_TEX_BUFFER, 1, offsetof(struct dri2_screen, texBuffer), true }, + { __DRI2_FLUSH, 1, offsetof(struct dri2_screen, f), true }, + { __DRI2_CONFIG_QUERY, 1, offsetof(struct dri2_screen, config), true }, + { __DRI2_THROTTLE, 1, offsetof(struct dri2_screen, throttle), true }, + { __DRI2_RENDERER_QUERY, 1, offsetof(struct dri2_screen, rendererQuery), true }, + { __DRI2_INTEROP, 1, offsetof(struct dri2_screen, interop), true }, + }; + loader_bind_extensions(psc, exts, ARRAY_SIZE(exts), extensions); + + /* Extensions where we don't care about the extension struct */ for (i = 0; extensions[i]; i++) { - if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0)) { - psc->texBuffer = (__DRItexBufferExtension *) extensions[i]; - __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap"); - } - - if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0)) { - psc->f = (__DRI2flushExtension *) extensions[i]; - /* internal driver extension, no GL extension exposed */ - } - - if ((strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0)) - psc->config = (__DRI2configQueryExtension *) extensions[i]; - - if (((strcmp(extensions[i]->name, __DRI2_THROTTLE) == 0))) - psc->throttle = (__DRI2throttleExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI2_ROBUSTNESS) == 0) __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context_robustness"); - if (strcmp(extensions[i]->name, __DRI2_RENDERER_QUERY) == 0) { - psc->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i]; - __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer"); - unsigned int no_error = 0; - if (psc->rendererQuery->queryInteger(psc->driScreen, - __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT, - &no_error) == 0 && no_error) - __glXEnableDirectExtension(&psc->base, - "GLX_ARB_create_context_no_error"); - } - - if (strcmp(extensions[i]->name, __DRI2_INTEROP) == 0) - psc->interop = (__DRI2interopExtension*)extensions[i]; - if (strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0) __glXEnableDirectExtension(&psc->base, "GLX_ARB_context_flush_control"); } + + if (psc->texBuffer) + __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap"); + + if (psc->rendererQuery) { + __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer"); + unsigned int no_error = 0; + if (psc->rendererQuery->queryInteger(psc->driScreen, + __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT, + &no_error) == 0 && no_error) + __glXEnableDirectExtension(&psc->base, + "GLX_ARB_create_context_no_error"); + } } static char * @@ -1045,7 +1039,6 @@ dri2CreateScreen(int screen, struct glx_display * priv) struct glx_config *configs = NULL, *visuals = NULL; char *driverName = NULL, *loader_driverName, *deviceName, *tmp; drm_magic_t magic; - int i; psc = calloc(1, sizeof *psc); if (psc == NULL) @@ -1096,17 +1089,12 @@ dri2CreateScreen(int screen, struct glx_display * priv) if (extensions == NULL) goto handle_error; - for (i = 0; extensions[i]; i++) { - if (strcmp(extensions[i]->name, __DRI_CORE) == 0) - psc->core = (__DRIcoreExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI_DRI2) == 0) - psc->dri2 = (__DRIdri2Extension *) extensions[i]; - } - - if (psc->core == NULL || psc->dri2 == NULL || psc->dri2->base.version < 4) { - ErrorMessageF("core dri or dri2 extension not found\n"); + static const struct dri_extension_match exts[] = { + { __DRI_CORE, 1, offsetof(struct dri2_screen, core), false }, + { __DRI_DRI2, 4, offsetof(struct dri2_screen, dri2), false }, + }; + if (!loader_bind_extensions(psc, exts, ARRAY_SIZE(exts), extensions)) goto handle_error; - } psc->driScreen = psc->dri2->createNewScreen2(screen, psc->fd, diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index 71b02d9c3e2..3754bf15533 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -750,6 +750,15 @@ dri3_bind_extensions(struct dri3_screen *psc, struct glx_display * priv, "GLX_EXT_create_context_es2_profile"); } + static const struct dri_extension_match exts[] = { + { __DRI2_RENDERER_QUERY, 1, offsetof(struct dri3_screen, rendererQuery), true }, + { __DRI2_FLUSH, 1, offsetof(struct dri3_screen, f), true }, + { __DRI_IMAGE, 1, offsetof(struct dri3_screen, image), true }, + { __DRI2_INTEROP, 1, offsetof(struct dri3_screen, interop), true }, + { __DRI2_CONFIG_QUERY, 1, offsetof(struct dri3_screen, config), true }, + }; + loader_bind_extensions(psc, exts, ARRAY_SIZE(exts), extensions); + for (i = 0; extensions[i]; i++) { /* when on a different gpu than the server, the server pixmaps * can have a tiling mode we can't read. Thus we can't create @@ -761,39 +770,25 @@ dri3_bind_extensions(struct dri3_screen *psc, struct glx_display * priv, __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap"); } - if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0)) { - psc->f = (__DRI2flushExtension *) extensions[i]; - /* internal driver extension, no GL extension exposed */ - } - - if (strcmp(extensions[i]->name, __DRI_IMAGE) == 0) - psc->image = (__DRIimageExtension *) extensions[i]; - - if ((strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0)) - psc->config = (__DRI2configQueryExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI2_ROBUSTNESS) == 0) __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context_robustness"); - if (strcmp(extensions[i]->name, __DRI2_RENDERER_QUERY) == 0) { - psc->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i]; - __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer"); - unsigned int no_error = 0; - if (psc->rendererQuery->queryInteger(psc->driScreen, - __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT, - &no_error) == 0 && no_error) - __glXEnableDirectExtension(&psc->base, - "GLX_ARB_create_context_no_error"); - } - - if (strcmp(extensions[i]->name, __DRI2_INTEROP) == 0) - psc->interop = (__DRI2interopExtension*)extensions[i]; - if (strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0) __glXEnableDirectExtension(&psc->base, "GLX_ARB_context_flush_control"); } + + if (psc->rendererQuery) { + __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer"); + unsigned int no_error = 0; + if (psc->rendererQuery->queryInteger(psc->driScreen, + __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT, + &no_error) == 0 && no_error) { + __glXEnableDirectExtension(&psc->base, + "GLX_ARB_create_context_no_error"); + } + } } static char * @@ -836,7 +831,6 @@ dri3_create_screen(int screen, struct glx_display * priv) __GLXDRIscreen *psp; struct glx_config *configs = NULL, *visuals = NULL; char *driverName, *driverNameDisplayGPU, *tmp; - int i; psc = calloc(1, sizeof *psc); if (psc == NULL) @@ -881,23 +875,12 @@ dri3_create_screen(int screen, struct glx_display * priv) if (extensions == NULL) goto handle_error; - for (i = 0; extensions[i]; i++) { - if (strcmp(extensions[i]->name, __DRI_CORE) == 0) - psc->core = (__DRIcoreExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI_IMAGE_DRIVER) == 0) - psc->image_driver = (__DRIimageDriverExtension *) extensions[i]; - } - - - if (psc->core == NULL) { - ErrorMessageF("core dri driver extension not found\n"); - goto handle_error; - } - - if (psc->image_driver == NULL) { - ErrorMessageF("image driver extension not found\n"); + static const struct dri_extension_match exts[] = { + { __DRI_CORE, 1, offsetof(struct dri3_screen, core), false }, + { __DRI_IMAGE_DRIVER, 1, offsetof(struct dri3_screen, image_driver), false }, + }; + if (!loader_bind_extensions(psc, exts, ARRAY_SIZE(exts), extensions)) goto handle_error; - } if (psc->is_different_gpu) { driverNameDisplayGPU = loader_get_driver_for_fd(psc->fd_display_gpu); diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 775d52b83b7..e760cedde91 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -823,22 +823,16 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions) __glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer"); /* FIXME: Figure out what other extensions can be ported here from dri2. */ + static const struct dri_extension_match exts[] = { + { __DRI_TEX_BUFFER, 1, offsetof(struct drisw_screen, texBuffer), true }, + { __DRI2_RENDERER_QUERY, 1, offsetof(struct drisw_screen, rendererQuery), true }, + { __DRI2_FLUSH, 1, offsetof(struct drisw_screen, f), true }, + { __DRI2_CONFIG_QUERY, 1, offsetof(struct drisw_screen, config), true }, + }; + loader_bind_extensions(psc, exts, ARRAY_SIZE(exts), extensions); + + /* Extensions where we don't care about the extension struct */ for (i = 0; extensions[i]; i++) { - if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0)) { - psc->texBuffer = (__DRItexBufferExtension *) extensions[i]; - __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap"); - } - if (strcmp(extensions[i]->name, __DRI2_RENDERER_QUERY) == 0) { - psc->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i]; - __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer"); - unsigned int no_error = 0; - if (psc->rendererQuery->queryInteger(psc->driScreen, - __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT, - &no_error) == 0 && no_error) - __glXEnableDirectExtension(&psc->base, - "GLX_ARB_create_context_no_error"); - } - if (strcmp(extensions[i]->name, __DRI2_ROBUSTNESS) == 0) __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context_robustness"); @@ -847,11 +841,20 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions) __glXEnableDirectExtension(&psc->base, "GLX_ARB_context_flush_control"); } - if (strcmp(extensions[i]->name, __DRI2_FLUSH) == 0) - psc->f = (__DRI2flushExtension *) extensions[i]; - if ((strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0)) - psc->config = (__DRI2configQueryExtension *) extensions[i]; + } + if (psc->texBuffer) + __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap"); + + if (psc->rendererQuery) { + __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer"); + unsigned int no_error = 0; + if (psc->rendererQuery->queryInteger(psc->driScreen, + __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT, + &no_error) == 0 && no_error) { + __glXEnableDirectExtension(&psc->base, + "GLX_ARB_create_context_no_error"); + } } if (psc->kopper) { @@ -928,7 +931,6 @@ driswCreateScreenDriver(int screen, struct glx_display *priv, const __DRIextension **extensions; struct drisw_screen *psc; struct glx_config *configs = NULL, *visuals = NULL; - int i; const __DRIextension **loader_extensions_local; const struct drisw_display *pdpyp = (struct drisw_display *)priv->driswDisplay; @@ -953,21 +955,14 @@ driswCreateScreenDriver(int screen, struct glx_display *priv, else loader_extensions_local = loader_extensions_shm; - for (i = 0; extensions[i]; i++) { - if (strcmp(extensions[i]->name, __DRI_CORE) == 0) - psc->core = (__DRIcoreExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI_SWRAST) == 0) - psc->swrast = (__DRIswrastExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI_KOPPER) == 0) - psc->kopper = (__DRIkopperExtension *) extensions[i]; - if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) - psc->copySubBuffer = (__DRIcopySubBufferExtension *) extensions[i]; - } - - if (psc->core == NULL || psc->swrast == NULL || psc->swrast->base.version < 4) { - ErrorMessageF("core dri extension not found\n"); + static const struct dri_extension_match exts[] = { + { __DRI_CORE, 1, offsetof(struct drisw_screen, core), false }, + { __DRI_SWRAST, 4, offsetof(struct drisw_screen, swrast), false }, + { __DRI_KOPPER, 1, offsetof(struct drisw_screen, kopper), true }, + { __DRI_COPY_SUB_BUFFER, 1, offsetof(struct drisw_screen, copySubBuffer), true }, + }; + if (!loader_bind_extensions(psc, exts, ARRAY_SIZE(exts), extensions)) goto handle_error; - } psc->driScreen = psc->swrast->createNewScreen2(screen, loader_extensions_local, |