From ba141b95a7934a553b341222786d12a7c89ae519 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Fri, 19 Feb 2021 14:55:57 -0800 Subject: [PATCH] glapi: Support "ELF" TLS on Windows To avoid a massive rename, I'm leaving this as a misnomer, it's not really ELF TLS, but it's the same concept. Note that Windows doesn't support thread-local variables imported or exported between modules, so we can only support this when we're not using a shared glapi. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4050 Reviewed-by: Jose Fonseca Part-of: --- meson.build | 4 +++- src/mapi/glapi/glapi.h | 5 +++++ src/mapi/u_current.c | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 9d59158e941..142f3839e91 100644 --- a/meson.build +++ b/meson.build @@ -449,7 +449,9 @@ endif # Android uses emutls for versions <= P/28. For USE_ELF_TLS we need ELF TLS. use_elf_tls = false -if not ['windows', 'freebsd', 'openbsd', 'haiku'].contains(host_machine.system()) and (not with_platform_android or get_option('platform-sdk-version') >= 29) +if (not ['freebsd', 'openbsd', 'haiku'].contains(host_machine.system()) and + (not with_platform_android or get_option('platform-sdk-version') >= 29) and + (not with_platform_windows or not with_shared_glapi)) pre_args += '-DUSE_ELF_TLS' use_elf_tls = true endif diff --git a/src/mapi/glapi/glapi.h b/src/mapi/glapi/glapi.h index b11fe46107b..da3d4524931 100644 --- a/src/mapi/glapi/glapi.h +++ b/src/mapi/glapi/glapi.h @@ -78,11 +78,16 @@ struct _glapi_table; #if defined (USE_ELF_TLS) +#ifdef _WIN32 +extern __declspec(thread) struct _glapi_table * _glapi_tls_Dispatch; +extern __declspec(thread) void * _glapi_tls_Context; +#else _GLAPI_EXPORT extern __thread struct _glapi_table * _glapi_tls_Dispatch __attribute__((tls_model("initial-exec"))); _GLAPI_EXPORT extern __thread void * _glapi_tls_Context __attribute__((tls_model("initial-exec"))); +#endif _GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch; _GLAPI_EXPORT extern const void *_glapi_Context; diff --git a/src/mapi/u_current.c b/src/mapi/u_current.c index 0e133e0e419..0a749ec87d2 100644 --- a/src/mapi/u_current.c +++ b/src/mapi/u_current.c @@ -99,12 +99,18 @@ extern void (*__glapi_noop_table[])(void); /*@{*/ #if defined(USE_ELF_TLS) +#ifdef _WIN32 +__declspec(thread) struct _glapi_table *u_current_table + = (struct _glapi_table *) table_noop_array; +__declspec(thread) void *u_current_context; +#else __thread struct _glapi_table *u_current_table __attribute__((tls_model("initial-exec"))) = (struct _glapi_table *) table_noop_array; __thread void *u_current_context __attribute__((tls_model("initial-exec"))); +#endif #else