diff options
author | Tapani Pälli <tapani.palli@intel.com> | 2019-03-15 09:47:49 +0200 |
---|---|---|
committer | Tapani Pälli <tapani.palli@intel.com> | 2019-04-16 12:58:00 +0300 |
commit | 624789e3708c87ea2a4c8d2266266b489b421cba (patch) | |
tree | c59e3a43f0d8e7f0196237d4868046681c46fce6 /src/compiler/glsl_types.cpp | |
parent | 04508f57d1d36587f3cc048f0f5dae0611f9330c (diff) |
compiler/glsl: handle case where we have multiple users for types
Both Vulkan and OpenGL might be using glsl_types simultaneously or we
can also have multiple concurrent Vulkan instances using glsl_types.
Patch adds a one time init to track number of users and will release
types only when last user calls _glsl_type_singleton_decref().
This change fixes glsl_type memory leaks we have with anv driver.
v2: reuse hash_mutex, cleanup, apply fix also to radv driver and
rename helper functions (Jason)
v3: move init, destroy to happen on GL context init and destroy
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Diffstat (limited to 'src/compiler/glsl_types.cpp')
-rw-r--r-- | src/compiler/glsl_types.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index 66241b34281..9938b3df450 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -37,6 +37,12 @@ hash_table *glsl_type::interface_types = NULL; 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, @@ -469,12 +475,26 @@ hash_free_type_function(struct hash_entry *entry) } 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); @@ -505,6 +525,8 @@ _mesa_glsl_release_types(void) _mesa_hash_table_destroy(glsl_type::subroutine_types, hash_free_type_function); glsl_type::subroutine_types = NULL; } + + mtx_unlock(&glsl_type::hash_mutex); } |