#include "util/build_id.h"
#include "util/debug.h"
#include "util/mesa-sha1.h"
+#include "compiler/glsl_types.h"
static int
radv_device_get_cache_uuid(enum radeon_family family, void *uuid)
}
_mesa_locale_init();
+ glsl_type_singleton_init_or_ref();
VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
VG(VALGRIND_DESTROY_MEMPOOL(instance));
+ glsl_type_singleton_decref();
_mesa_locale_fini();
vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
extern "C" {
+/**
+ * To be called at GL context ctor.
+ */
+void
+_mesa_init_shader_compiler_types(void)
+{
+ glsl_type_singleton_init_or_ref();
+}
+
+/**
+ * To be called at GL context dtor.
+ */
+void
+_mesa_destroy_shader_compiler_types(void)
+{
+ glsl_type_singleton_decref();
+}
+
/**
* To be called at GL teardown time, this frees compiler datastructures.
*
_mesa_destroy_shader_compiler(void)
{
_mesa_destroy_shader_compiler_caches();
-
- _mesa_glsl_release_types();
}
/**
struct _mesa_glsl_parse_state *state,
struct gl_context *gl_ctx);
+extern void _mesa_init_shader_compiler_types(void);
+extern void _mesa_destroy_shader_compiler_types(void);
extern void _mesa_destroy_shader_compiler(void);
extern void _mesa_destroy_shader_compiler_caches(void);
initialize_context(struct gl_context *ctx, gl_api api)
{
initialize_context_to_defaults(ctx, api);
+ glsl_type_singleton_init_or_ref();
/* The standalone compiler needs to claim support for almost
* everything in order to compile the built-in functions.
delete whole_program->FragDataIndexBindings;
ralloc_free(whole_program);
- _mesa_glsl_release_types();
+ glsl_type_singleton_decref();
_mesa_glsl_release_builtin_functions();
}
hash_table *glsl_type::function_types = NULL;
hash_table *glsl_type::subroutine_types = NULL;
+/* There might be multiple users for types (e.g. application using OpenGL
+ * and Vulkan simultanously or app using multiple Vulkan instances). Counter
+ * is used to make sure we don't release the types if a user is still present.
+ */
+static uint32_t glsl_type_users = 0;
+
glsl_type::glsl_type(GLenum gl_type,
glsl_base_type base_type, unsigned vector_elements,
unsigned matrix_columns, const char *name,
}
void
-_mesa_glsl_release_types(void)
+glsl_type_singleton_init_or_ref()
{
- /* Should only be called during atexit (either when unloading shared
- * object, or if process terminates), so no mutex-locking should be
- * necessary.
- */
+ mtx_lock(&glsl_type::hash_mutex);
+ glsl_type_users++;
+ mtx_unlock(&glsl_type::hash_mutex);
+}
+
+void
+glsl_type_singleton_decref()
+{
+ mtx_lock(&glsl_type::hash_mutex);
+
+ assert(glsl_type_users > 0);
+
+ /* Do not release glsl_types if they are still used. */
+ if (--glsl_type_users) {
+ mtx_unlock(&glsl_type::hash_mutex);
+ return;
+ }
+
if (glsl_type::explicit_matrix_types != NULL) {
_mesa_hash_table_destroy(glsl_type::explicit_matrix_types,
hash_free_type_function);
_mesa_hash_table_destroy(glsl_type::subroutine_types, hash_free_type_function);
glsl_type::subroutine_types = NULL;
}
+
+ mtx_unlock(&glsl_type::hash_mutex);
}
struct glsl_symbol_table;
extern void
-_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
+glsl_type_singleton_init_or_ref();
+
+extern void
+glsl_type_singleton_decref();
extern void
-_mesa_glsl_release_types(void);
+_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
void encode_type_to_blob(struct blob *blob, const struct glsl_type *type);
* data.
*/
/*@{*/
+ friend void glsl_type_singleton_init_or_ref(void);
+ friend void glsl_type_singleton_decref(void);
friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *);
- friend void _mesa_glsl_release_types(void);
/*@}*/
};
#include "git_sha1.h"
#include "vk_util.h"
#include "common/gen_defines.h"
+#include "compiler/glsl_types.h"
#include "genxml/gen7_pack.h"
env_var_as_boolean("ANV_ENABLE_PIPELINE_CACHE", true);
_mesa_locale_init();
+ glsl_type_singleton_init_or_ref();
VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
+ glsl_type_singleton_decref();
_mesa_locale_fini();
vk_free(&instance->alloc, instance);
/* misc one-time initializations */
one_time_init(ctx);
+ _mesa_init_shader_compiler_types();
+
/* Plug in driver functions and context pointer here.
* This is important because when we call alloc_shared_state() below
* we'll call ctx->Driver.NewTextureObject() to create the default
free(ctx->VersionString);
+ _mesa_destroy_shader_compiler_types();
+
/* unbind the context if it's currently bound */
if (ctx == _mesa_get_current_context()) {
_mesa_make_current(NULL, NULL, NULL);