From 97b6851815acee2115bd1caff8e7edde23f3f7c5 Mon Sep 17 00:00:00 2001 From: "duncan.hopkins" Date: Fri, 27 Oct 2023 16:13:40 +0100 Subject: [PATCH] apple: Extended Apple feature support using GLX_USE_APPLE. On MacOS/Apple/Dawin you can only get MESA to forward the GL funtions to the systems OpenGL.framework or run SWRast directly. There is no way to use a gallium driver, even if they have been compiled. The two gallium drivers of interest are SWRast and Zink, as the rest are hardware drivers and not relavent on MacOS. The code changes add a new define GLX_USE_APPLE. This is used in combination with the existing GLX_USE_APPLEGL. GLX_USE_APPLEGL calls the systems OpenGL.framework, Apple's OpenGL. GLX_USE_APPLE calls the non-system OpenGL code, i.e. Gallium, hence the subtle naming difference. Apple systems are still used, just not the GL ones. When GLX_USE_APPLE is defined the code will use the DRI/gallium driver sub-system so SWRast and Zink can selected at runtime on MacOS. This also allows Zink to be run on MacOS, once it is fixed up. Part-of: --- src/gallium/targets/dri/target.c | 2 +- src/glx/clientattrib.c | 2 +- src/glx/dri2.c | 4 +++- src/glx/dri2_glx.c | 2 +- src/glx/dri_common.c | 2 +- src/glx/dri_common_interop.c | 2 +- src/glx/dri_common_query_renderer.c | 2 +- src/glx/drisw_glx.c | 2 +- src/glx/glx_pbuffer.c | 2 +- src/glx/glxclient.h | 10 +++++----- src/glx/glxcmds.c | 8 ++++---- src/glx/glxext.c | 14 ++++++++++---- src/glx/indirect_glx.c | 2 +- src/glx/render2.c | 2 +- src/glx/vertarr.c | 2 +- src/mapi/glapi/gen/glX_proto_send.py | 2 +- src/mapi/glapi/gen/gl_gentable.py | 3 ++- 17 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/gallium/targets/dri/target.c b/src/gallium/targets/dri/target.c index 4e42e003ef2..972d1d24166 100644 --- a/src/gallium/targets/dri/target.c +++ b/src/gallium/targets/dri/target.c @@ -141,7 +141,7 @@ DEFINE_LOADER_DRM_ENTRYPOINT(zynqmp_dpsub) DEFINE_LOADER_DRM_ENTRYPOINT(lima) #endif -#if defined(GALLIUM_ZINK) && !defined(__APPLE__) +#if defined(GALLIUM_ZINK) #if DETECT_OS_ANDROID DEFINE_LOADER_DRM_ENTRYPOINT(zink); #else diff --git a/src/glx/clientattrib.c b/src/glx/clientattrib.c index e0ff579471a..611d98f799e 100644 --- a/src/glx/clientattrib.c +++ b/src/glx/clientattrib.c @@ -12,7 +12,7 @@ /*****************************************************************************/ -#ifndef GLX_USE_APPLEGL +#if !defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE) static void do_enable_disable(GLenum array, GLboolean val) { diff --git a/src/glx/dri2.c b/src/glx/dri2.c index a6b7e9e759f..20568dab704 100644 --- a/src/glx/dri2.c +++ b/src/glx/dri2.c @@ -31,7 +31,7 @@ */ -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) #include #include @@ -96,6 +96,7 @@ static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay, static Bool DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire) { +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) XExtDisplayInfo *info = DRI2FindDisplay(dpy); struct glx_drawable *glxDraw; @@ -162,6 +163,7 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire) /* client doesn't support server event */ break; } +#endif return False; } diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 81314c0feea..634546f046d 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -30,7 +30,7 @@ * Kristian Høgsberg (krh@redhat.com) */ -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) #include #include diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 15b0e0fc328..40bbcfffb15 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -33,7 +33,7 @@ * Kristian Høgsberg (krh@redhat.com) */ -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) #include #include diff --git a/src/glx/dri_common_interop.c b/src/glx/dri_common_interop.c index c8038d60846..ab7596d7938 100644 --- a/src/glx/dri_common_interop.c +++ b/src/glx/dri_common_interop.c @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) #include "glxclient.h" #include "glx_error.h" diff --git a/src/glx/dri_common_query_renderer.c b/src/glx/dri_common_query_renderer.c index 6d2a06689a9..0ca75a2b058 100644 --- a/src/glx/dri_common_query_renderer.c +++ b/src/glx/dri_common_query_renderer.c @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) #include "glxclient.h" #include "glx_error.h" diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 47cdec8a185..3295941b7c6 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) #include #include diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c index d95a3e90c24..dc64ab64701 100644 --- a/src/glx/glx_pbuffer.c +++ b/src/glx/glx_pbuffer.c @@ -48,7 +48,7 @@ #include "glx_error.h" -#ifndef GLX_USE_APPLEGL +#if !defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE) /** * Change a drawable's attribute. * diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index e4eb3b41451..52fcd1c40a2 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -68,7 +68,7 @@ extern void DRI_glXUseXFont(struct glx_context *ctx, #endif -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) /** * Display dependent methods. This structure is initialized during the @@ -512,7 +512,7 @@ struct glx_screen bool allow_invalid_glx_destroy_window; bool keep_native_window_glx_drawable; -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) /** * Per screen direct rendering interface functions and data. */ @@ -579,7 +579,7 @@ struct glx_display __glxHashTable *glXDrawHash; -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) __glxHashTable *drawHash; /** @@ -613,7 +613,7 @@ glx_screen_init(struct glx_screen *psc, extern void glx_screen_cleanup(struct glx_screen *psc); -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) extern __GLXDRIdrawable * dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id); #endif @@ -732,7 +732,7 @@ extern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, int32_t * numerator, int32_t * denominator); -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) extern GLboolean __glxGetMscRate(struct glx_screen *psc, int32_t * numerator, int32_t * denominator); diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 295fd1836c7..561d4c82924 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -33,7 +33,7 @@ #include #include "GL/mesa_glinterop.h" -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) /** * Get the __DRIdrawable for the drawable associated with a GLXContext @@ -315,7 +315,7 @@ CreateContext(Display *dpy, int generic_id, struct glx_config *config, } gc = NULL; -#ifdef GLX_USE_APPLEGL +#if defined(GLX_USE_APPLEGL) && !defined(GLX_USE_APPLE) gc = applegl_create_context(psc, config, shareList, renderType); #else if (allowDirect && psc->vtable->create_context) @@ -652,7 +652,7 @@ glXIsDirect(Display * dpy, GLXContext gc_user) _GLX_PUBLIC void glXSwapBuffers(Display * dpy, GLXDrawable drawable) { -#ifdef GLX_USE_APPLEGL +#if defined(GLX_USE_APPLEGL) && !defined(GLX_USE_APPLE) struct glx_context * gc = __glXGetCurrentContext(); if(gc != &dummyContext && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) { apple_glx_swap_buffers(gc->driContext); @@ -667,7 +667,7 @@ glXSwapBuffers(Display * dpy, GLXDrawable drawable) gc = __glXGetCurrentContext(); -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) { __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); diff --git a/src/glx/glxext.c b/src/glx/glxext.c index eebdfceeb4c..6a9ba8b5975 100644 --- a/src/glx/glxext.c +++ b/src/glx/glxext.c @@ -798,9 +798,15 @@ AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv, Bool zink) psc = priv->driswDisplay->createScreen(i, priv); #endif /* GLX_DIRECT_RENDERING && !GLX_USE_APPLEGL */ +#if defined(GLX_USE_APPLE) + if (psc == NULL && priv->driswDisplay) { + psc = priv->driswDisplay->createScreen(i, priv); + } +#endif + bool indirect = false; -#if defined(GLX_USE_APPLEGL) +#if defined(GLX_USE_APPLEGL) && !defined(GLX_USE_APPLE) if (psc == NULL) psc = applegl_create_screen(i, priv); #else @@ -880,7 +886,7 @@ __glXInitialize(Display * dpy) Bool zink = False; Bool try_zink = False; -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) Bool glx_direct = !debug_get_bool_option("LIBGL_ALWAYS_INDIRECT", false); Bool glx_accel = !debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false); const char *env = getenv("MESA_LOADER_DRIVER_OVERRIDE"); @@ -927,7 +933,7 @@ __glXInitialize(Display * dpy) #endif #endif /* GLX_DIRECT_RENDERING && !GLX_USE_APPLEGL */ -#ifdef GLX_USE_APPLEGL +#if defined(GLX_USE_APPLEGL) && !defined(GLX_USE_APPLE) if (!applegl_create_display(dpyPriv)) { free(dpyPriv); return NULL; @@ -936,7 +942,7 @@ __glXInitialize(Display * dpy) if (!AllocAndFetchScreenConfigs(dpy, dpyPriv, zink | try_zink)) { Bool fail = True; -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) if (try_zink) { free(dpyPriv->screens); dpyPriv->driswDisplay->destroyDisplay(dpyPriv->driswDisplay); diff --git a/src/glx/indirect_glx.c b/src/glx/indirect_glx.c index 16dacc35227..9d7b25ccca7 100644 --- a/src/glx/indirect_glx.c +++ b/src/glx/indirect_glx.c @@ -37,7 +37,7 @@ #include "indirect.h" #include "util/u_debug.h" -#ifndef GLX_USE_APPLEGL +#if !defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE) extern struct _glapi_table *__glXNewIndirectAPI(void); diff --git a/src/glx/render2.c b/src/glx/render2.c index 372c7e45e7c..4dbcd53a54e 100644 --- a/src/glx/render2.c +++ b/src/glx/render2.c @@ -5,7 +5,7 @@ * SPDX-License-Identifier: SGI-B-2.0 */ -#ifndef GLX_USE_APPLEGL +#if !defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE) #include "packrender.h" #include "indirect.h" diff --git a/src/glx/vertarr.c b/src/glx/vertarr.c index a30b17fbb07..9cae6e18e97 100644 --- a/src/glx/vertarr.c +++ b/src/glx/vertarr.c @@ -9,7 +9,7 @@ #include "indirect.h" #include "indirect_vertex_array.h" -#ifndef GLX_USE_APPLEGL +#if !defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE) /*****************************************************************************/ diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py index 1e01d5d9a2f..f1cabdfabf0 100644 --- a/src/mapi/glapi/gen/glX_proto_send.py +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -928,7 +928,7 @@ class PrintGlxProtoInit_c(gl_XML.gl_print_base): #include "glapi.h" #include -#ifndef GLX_USE_APPLEGL +#if !defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE) /** * No-op function used to initialize functions that have no GLX protocol diff --git a/src/mapi/glapi/gen/gl_gentable.py b/src/mapi/glapi/gen/gl_gentable.py index 8cd470f148d..a88dae8a8e8 100644 --- a/src/mapi/glapi/gen/gl_gentable.py +++ b/src/mapi/glapi/gen/gl_gentable.py @@ -83,6 +83,7 @@ __glapi_gentable_set_remaining_noop(struct _glapi_table *disp) { """ footer = """ +#if defined(GLX_USE_APPLEGL) || defined(GLX_USE_WINDOWSGL) struct _glapi_table * _glapi_create_table_from_handle(void *handle, const char *symbol_prefix) { struct _glapi_table *disp = calloc(_glapi_get_dispatch_table_size(), sizeof(_glapi_proc)); @@ -124,7 +125,7 @@ void } fprintf(stderr, "could not patch %s in dispatch table\\n", name); } - +#endif """