From 9b09655a587f03b4096df0a4314e98a267816cfa Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Mon, 4 Oct 2021 11:18:47 +0200 Subject: [PATCH 1/4] vbo/dlist: free copied.buffer if no vertices were copied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Other parts of the code asserts that copied.buffer is NULL if there are no vertices to copy. Cc: mesa-stable Reviewed-by: Marek Olšák Part-of: --- src/mesa/vbo/vbo_save_api.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c index 6bcd3e965f20..e71613c93cff 100644 --- a/src/mesa/vbo/vbo_save_api.c +++ b/src/mesa/vbo/vbo_save_api.c @@ -168,8 +168,13 @@ copy_vertices(struct gl_context *ctx, assert(save->copied.buffer == NULL); save->copied.buffer = malloc(sizeof(fi_type) * sz * prim->count); - return vbo_copy_vertices(ctx, prim->mode, prim->start, &prim->count, - prim->begin, sz, true, save->copied.buffer, src); + unsigned r = vbo_copy_vertices(ctx, prim->mode, prim->start, &prim->count, + prim->begin, sz, true, save->copied.buffer, src); + if (!r) { + free(save->copied.buffer); + save->copied.buffer = NULL; + } + return r; } -- GitLab From fc3ef76eec61c97ba7c53622e4bca8e518749b09 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 7 Oct 2021 12:14:44 +0200 Subject: [PATCH 2/4] glx/drirc: add a force_direct_glx_context option Some applications may request an indirect context but this feature is disabled by default on Xorg and thus context creation will fail. This commit adds a drirc setting to force the creation of direct glx context, regardless of what the app is requesting. Reviewed-by: Adam Jackson Part-of: --- src/gallium/auxiliary/pipe-loader/driinfo_gallium.h | 1 + src/glx/create_context.c | 9 +++++++++ src/glx/dri2_glx.c | 8 ++++++++ src/glx/dri3_glx.c | 8 ++++++++ src/glx/glxclient.h | 1 + src/glx/glxcmds.c | 8 ++++++++ src/glx/tests/fake_glx_screen.h | 1 + src/util/driconf.h | 4 ++++ src/util/xmlconfig.c | 2 +- 9 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h index 5a15388291b2..e3bf517b6d59 100644 --- a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h +++ b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h @@ -44,6 +44,7 @@ DRI_CONF_SECTION_DEBUG DRI_CONF_INDIRECT_GL_EXTENSION_OVERRIDE() DRI_CONF_DISABLE_PROTECTED_CONTENT_CHECK(false) DRI_CONF_IGNORE_MAP_UNSYNCHRONIZED(false) + DRI_CONF_FORCE_DIRECT_GLX_CONTEXT(false) DRI_CONF_SECTION_END DRI_CONF_SECTION_MISCELLANEOUS diff --git a/src/glx/create_context.c b/src/glx/create_context.c index 7e1cec98c647..c44d579c9545 100644 --- a/src/glx/create_context.c +++ b/src/glx/create_context.c @@ -92,6 +92,15 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config, assert(screen == psc->scr); + /* Some application may request an indirect context but we may want to force a direct + * one because Xorg only allows indirect contexts if they were enabled. + */ + if (!direct && + psc->force_direct_context) { + direct = true; + } + + if (direct && psc->vtable->create_context_attribs) { /* GLX drops the error returned by the driver. The expectation is that * an error will also be returned by the server. The server's error diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index fbbfe1f6d57e..4092842cccdf 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -1280,6 +1280,14 @@ dri2CreateScreen(int screen, struct glx_display * priv) &tmp) == 0) __IndirectGlParseExtensionOverride(&psc->base, tmp); + if (psc->config->base.version > 1) { + uint8_t force = false; + if (psc->config->configQueryb(psc->driScreen, "force_direct_glx_context", + &force) == 0) { + psc->base.force_direct_context = force; + } + } + /* DRI2 supports SubBuffer through DRI2CopyRegion, so it's always * available.*/ psp->copySubBuffer = dri2CopySubBuffer; diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index 3b3918cf6c1e..3c0d60bdf213 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -1014,6 +1014,14 @@ dri3_create_screen(int screen, struct glx_display * priv) &tmp) == 0) __IndirectGlParseExtensionOverride(&psc->base, tmp); + if (psc->config->base.version > 1) { + uint8_t force = false; + if (psc->config->configQueryb(psc->driScreen, "force_direct_glx_context", + &force) == 0) { + psc->base.force_direct_context = force; + } + } + free(driverName); tmp = getenv("LIBGL_SHOW_FPS"); diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index 50aa4d892cb3..880f4fbaefa1 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -521,6 +521,7 @@ struct glx_screen Display *dpy; int scr; + bool force_direct_context; #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) /** diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index ecf94eeb04c6..901de99f9425 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -339,6 +339,14 @@ CreateContext(Display *dpy, int generic_id, struct glx_config *config, if (generic_id == None) return NULL; + /* Some application may request an indirect context but we may want to force a direct + * one because Xorg only allows indirect contexts if they were enabled. + */ + if (!allowDirect && + psc->force_direct_context) { + allowDirect = 1; + } + gc = NULL; #ifdef GLX_USE_APPLEGL gc = applegl_create_context(psc, config, shareList, renderType); diff --git a/src/glx/tests/fake_glx_screen.h b/src/glx/tests/fake_glx_screen.h index 39b250ffc8fa..02b212ad7ecf 100644 --- a/src/glx/tests/fake_glx_screen.h +++ b/src/glx/tests/fake_glx_screen.h @@ -34,6 +34,7 @@ public: this->scr = num; this->visuals = 0; this->configs = 0; + this->force_direct_context = false; this->display = glx_dpy; this->dpy = (glx_dpy != NULL) ? glx_dpy->dpy : NULL; diff --git a/src/util/driconf.h b/src/util/driconf.h index 77e5aa8b2226..c514bd93f023 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -234,6 +234,10 @@ DRI_CONF_OPT_B(force_compat_profile, def, \ "Force an OpenGL compatibility context") +#define DRI_CONF_FORCE_DIRECT_GLX_CONTEXT(def) \ + DRI_CONF_OPT_B(force_direct_glx_context, def, \ + "Force direct GLX context (even if indirect is requested)") + #define DRI_CONF_OVERRIDE_VRAM_SIZE() \ DRI_CONF_OPT_I(override_vram_size, -1, -1, 2147483647, \ "Override the VRAM size advertised to the application in MiB (-1 = default)") diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c index 609081586604..8614497ac3fb 100644 --- a/src/util/xmlconfig.c +++ b/src/util/xmlconfig.c @@ -320,7 +320,7 @@ driParseOptionInfo(driOptionCache *info, /* Make the hash table big enough to fit more than the maximum number of * config options we've ever seen in a driver. */ - info->tableSize = 6; + info->tableSize = 7; info->info = calloc((size_t)1 << info->tableSize, sizeof(driOptionInfo)); info->values = calloc((size_t)1 << info->tableSize, sizeof(driOptionValue)); if (info->info == NULL || info->values == NULL) { -- GitLab From a21c0f531ec3a88003f5dce86c8b3d0ad4ea406a Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Wed, 6 Oct 2021 14:49:01 +0200 Subject: [PATCH 3/4] mesa: enable force_direct_glx_context for DiscoveryStudio2020 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This app uses Qt4.8 which uses an indirect context to save a GL scene to a pixmap. Reviewed-by: Marek Olšák Part-of: --- src/util/00-mesa-defaults.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf index 295e95744a91..a30abbb9ced3 100644 --- a/src/util/00-mesa-defaults.conf +++ b/src/util/00-mesa-defaults.conf @@ -341,6 +341,10 @@ TODO: document the other workarounds.