From 05c69752cfda9e66130c64c01f0c8fac613c83ad Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Fri, 24 Apr 2020 14:41:25 +0200 Subject: [PATCH] mesa/main: do not store unrecognized extensions in context MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We process extension overrides only when we initialize the first context, which means that unrecognized extensions only appear in the first context created. Let's instead store them in a global array, so we can apply them to all contexts. This has the added benefit of making the initialization of the first context less special, which allows us to clean up code a bit more. Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/extensions.c | 31 ++++++++++++++++++------------- src/mesa/main/mtypes.h | 6 ------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 2d780c0743c..016a55a2ed7 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -39,8 +39,12 @@ struct gl_extensions _mesa_extension_override_enables; struct gl_extensions _mesa_extension_override_disables; -static char *unrecognized_extensions = NULL; +#define MAX_UNRECOGNIZED_EXTENSIONS 16 +static struct { + char *env; + const char *names[MAX_UNRECOGNIZED_EXTENSIONS]; +} unrecognized_extensions; /** * Given a member \c x of struct gl_extensions, return offset of @@ -213,7 +217,9 @@ set_extension(struct gl_extensions *ext, int i, GLboolean state) static void free_unknown_extensions_strings(void) { - free(unrecognized_extensions); + free(unrecognized_extensions.env); + for (int i = 0; i < MAX_UNRECOGNIZED_EXTENSIONS; ++i) + unrecognized_extensions.names[i] = NULL; } @@ -288,9 +294,8 @@ _mesa_one_time_init_extension_overrides(struct gl_context *ctx) MAX_UNRECOGNIZED_EXTENSIONS); } } else { - ctx->Extensions.unrecognized_extensions[unknown_ext] = ext; + unrecognized_extensions.names[unknown_ext] = ext; unknown_ext++; - _mesa_problem(ctx, "Trying to enable unknown extension: %s", ext); } } @@ -299,7 +304,7 @@ _mesa_one_time_init_extension_overrides(struct gl_context *ctx) if (!unknown_ext) { free(env); } else { - unrecognized_extensions = env; + unrecognized_extensions.env = env; atexit(free_unknown_extensions_strings); } } @@ -411,8 +416,8 @@ _mesa_make_extension_string(struct gl_context *ctx) } } for (k = 0; k < MAX_UNRECOGNIZED_EXTENSIONS; k++) - if (ctx->Extensions.unrecognized_extensions[k]) - length += 1 + strlen(ctx->Extensions.unrecognized_extensions[k]); /* +1 for space */ + if (unrecognized_extensions.names[k]) + length += 1 + strlen(unrecognized_extensions.names[k]); /* +1 for space */ exts = calloc(ALIGN(length + 1, 4), sizeof(char)); if (exts == NULL) { @@ -445,8 +450,8 @@ _mesa_make_extension_string(struct gl_context *ctx) strcat(exts, " "); } for (j = 0; j < MAX_UNRECOGNIZED_EXTENSIONS; j++) { - if (ctx->Extensions.unrecognized_extensions[j]) { - strcat(exts, ctx->Extensions.unrecognized_extensions[j]); + if (unrecognized_extensions.names[j]) { + strcat(exts, unrecognized_extensions.names[j]); strcat(exts, " "); } } @@ -472,8 +477,8 @@ _mesa_get_extension_count(struct gl_context *ctx) } for (k = 0; k < MAX_UNRECOGNIZED_EXTENSIONS; ++k) { - if (ctx->Extensions.unrecognized_extensions[k]) - ctx->Extensions.Count++; + if (unrecognized_extensions.names[k]) + ctx->Extensions.Count++; } return ctx->Extensions.Count; } @@ -497,9 +502,9 @@ _mesa_get_enabled_extension(struct gl_context *ctx, GLuint index) } for (i = 0; i < MAX_UNRECOGNIZED_EXTENSIONS; ++i) { - if (ctx->Extensions.unrecognized_extensions[i]) { + if (unrecognized_extensions.names[i]) { if (n == index) - return (const GLubyte*) ctx->Extensions.unrecognized_extensions[i]; + return (const GLubyte*) unrecognized_extensions.names[i]; else ++n; } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index a8b75b32f52..0a50e929986 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -4439,12 +4439,6 @@ struct gl_extensions * while meta is in progress. */ GLubyte Version; - /** - * Force-enabled, yet unrecognized, extensions. - * See _mesa_one_time_init_extension_overrides() - */ -#define MAX_UNRECOGNIZED_EXTENSIONS 16 - const char *unrecognized_extensions[MAX_UNRECOGNIZED_EXTENSIONS]; }; -- 2.30.2