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,
gl_type(gl_type),
base_type(base_type), sampled_type(GLSL_TYPE_VOID),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- interface_packing(0), interface_row_major(row_major),
+ interface_packing(0), interface_row_major(row_major), packed(0),
vector_elements(vector_elements), matrix_columns(matrix_columns),
length(0), explicit_stride(explicit_stride)
{
base_type(base_type), sampled_type(type),
sampler_dimensionality(dim), sampler_shadow(shadow),
sampler_array(array), interface_packing(0),
- interface_row_major(0),
+ interface_row_major(0), packed(0),
length(0), explicit_stride(0)
{
this->mem_ctx = ralloc_context(NULL);
base_type(GLSL_TYPE_INTERFACE), sampled_type(GLSL_TYPE_VOID),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
interface_packing((unsigned) packing),
- interface_row_major((unsigned) row_major),
+ interface_row_major((unsigned) row_major), packed(0),
vector_elements(0), matrix_columns(0),
length(num_fields), explicit_stride(0)
{
gl_type(0),
base_type(GLSL_TYPE_FUNCTION), sampled_type(GLSL_TYPE_VOID),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- interface_packing(0), interface_row_major(0),
+ interface_packing(0), interface_row_major(0), packed(0),
vector_elements(0), matrix_columns(0),
length(num_params), explicit_stride(0)
{
gl_type(0),
base_type(GLSL_TYPE_SUBROUTINE), sampled_type(GLSL_TYPE_VOID),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- interface_packing(0), interface_row_major(0),
+ interface_packing(0), interface_row_major(0), packed(0),
vector_elements(1), matrix_columns(1),
length(0), explicit_stride(0)
{
}
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);
}
unsigned explicit_stride) :
base_type(GLSL_TYPE_ARRAY), sampled_type(GLSL_TYPE_VOID),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- interface_packing(0), interface_row_major(0),
+ interface_packing(0), interface_row_major(0), packed(0),
vector_elements(0), matrix_columns(0),
length(length), name(NULL), explicit_stride(explicit_stride)
{