glsl: Remove the need of _MTX_INITIALIZER_NP by using simple_mtx_t/SIMPLE_MTX_INITIALIZER
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Acked-by: Jesse Natalie <jenatali@microsoft.com> Acked-by: David Heidelberg <david.heidelberg@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18493>
This commit is contained in:
@@ -75,6 +75,7 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "util/simple_mtx.h"
|
||||||
#include "main/consts_exts.h"
|
#include "main/consts_exts.h"
|
||||||
#include "main/shader_types.h"
|
#include "main/shader_types.h"
|
||||||
#include "main/shaderobj.h"
|
#include "main/shaderobj.h"
|
||||||
@@ -97,7 +98,7 @@
|
|||||||
|
|
||||||
using namespace ir_builder;
|
using namespace ir_builder;
|
||||||
|
|
||||||
static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
|
static simple_mtx_t builtins_lock = SIMPLE_MTX_INITIALIZER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Availability predicates:
|
* Availability predicates:
|
||||||
@@ -1388,7 +1389,7 @@ builtin_builder::builtin_builder()
|
|||||||
|
|
||||||
builtin_builder::~builtin_builder()
|
builtin_builder::~builtin_builder()
|
||||||
{
|
{
|
||||||
mtx_lock(&builtins_lock);
|
simple_mtx_lock(&builtins_lock);
|
||||||
|
|
||||||
ralloc_free(mem_ctx);
|
ralloc_free(mem_ctx);
|
||||||
mem_ctx = NULL;
|
mem_ctx = NULL;
|
||||||
@@ -1396,7 +1397,7 @@ builtin_builder::~builtin_builder()
|
|||||||
ralloc_free(shader);
|
ralloc_free(shader);
|
||||||
shader = NULL;
|
shader = NULL;
|
||||||
|
|
||||||
mtx_unlock(&builtins_lock);
|
simple_mtx_unlock(&builtins_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_function_signature *
|
ir_function_signature *
|
||||||
@@ -8510,20 +8511,20 @@ static uint32_t builtin_users = 0;
|
|||||||
extern "C" void
|
extern "C" void
|
||||||
_mesa_glsl_builtin_functions_init_or_ref()
|
_mesa_glsl_builtin_functions_init_or_ref()
|
||||||
{
|
{
|
||||||
mtx_lock(&builtins_lock);
|
simple_mtx_lock(&builtins_lock);
|
||||||
if (builtin_users++ == 0)
|
if (builtin_users++ == 0)
|
||||||
builtins.initialize();
|
builtins.initialize();
|
||||||
mtx_unlock(&builtins_lock);
|
simple_mtx_unlock(&builtins_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
_mesa_glsl_builtin_functions_decref()
|
_mesa_glsl_builtin_functions_decref()
|
||||||
{
|
{
|
||||||
mtx_lock(&builtins_lock);
|
simple_mtx_lock(&builtins_lock);
|
||||||
assert(builtin_users != 0);
|
assert(builtin_users != 0);
|
||||||
if (--builtin_users == 0)
|
if (--builtin_users == 0)
|
||||||
builtins.release();
|
builtins.release();
|
||||||
mtx_unlock(&builtins_lock);
|
simple_mtx_unlock(&builtins_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_function_signature *
|
ir_function_signature *
|
||||||
@@ -8531,9 +8532,9 @@ _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
|
|||||||
const char *name, exec_list *actual_parameters)
|
const char *name, exec_list *actual_parameters)
|
||||||
{
|
{
|
||||||
ir_function_signature *s;
|
ir_function_signature *s;
|
||||||
mtx_lock(&builtins_lock);
|
simple_mtx_lock(&builtins_lock);
|
||||||
s = builtins.find(state, name, actual_parameters);
|
s = builtins.find(state, name, actual_parameters);
|
||||||
mtx_unlock(&builtins_lock);
|
simple_mtx_unlock(&builtins_lock);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -8543,7 +8544,7 @@ _mesa_glsl_has_builtin_function(_mesa_glsl_parse_state *state, const char *name)
|
|||||||
{
|
{
|
||||||
ir_function *f;
|
ir_function *f;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
mtx_lock(&builtins_lock);
|
simple_mtx_lock(&builtins_lock);
|
||||||
f = builtins.shader->symbols->get_function(name);
|
f = builtins.shader->symbols->get_function(name);
|
||||||
if (f != NULL) {
|
if (f != NULL) {
|
||||||
foreach_in_list(ir_function_signature, sig, &f->signatures) {
|
foreach_in_list(ir_function_signature, sig, &f->signatures) {
|
||||||
@@ -8553,7 +8554,7 @@ _mesa_glsl_has_builtin_function(_mesa_glsl_parse_state *state, const char *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mtx_unlock(&builtins_lock);
|
simple_mtx_unlock(&builtins_lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
#include "util/u_string.h"
|
#include "util/u_string.h"
|
||||||
|
|
||||||
|
|
||||||
mtx_t glsl_type::hash_mutex = _MTX_INITIALIZER_NP;
|
simple_mtx_t glsl_type::hash_mutex = SIMPLE_MTX_INITIALIZER;
|
||||||
hash_table *glsl_type::explicit_matrix_types = NULL;
|
hash_table *glsl_type::explicit_matrix_types = NULL;
|
||||||
hash_table *glsl_type::array_types = NULL;
|
hash_table *glsl_type::array_types = NULL;
|
||||||
hash_table *glsl_type::struct_types = NULL;
|
hash_table *glsl_type::struct_types = NULL;
|
||||||
@@ -519,20 +519,20 @@ hash_free_type_function(struct hash_entry *entry)
|
|||||||
void
|
void
|
||||||
glsl_type_singleton_init_or_ref()
|
glsl_type_singleton_init_or_ref()
|
||||||
{
|
{
|
||||||
mtx_lock(&glsl_type::hash_mutex);
|
simple_mtx_lock(&glsl_type::hash_mutex);
|
||||||
glsl_type_users++;
|
glsl_type_users++;
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
glsl_type_singleton_decref()
|
glsl_type_singleton_decref()
|
||||||
{
|
{
|
||||||
mtx_lock(&glsl_type::hash_mutex);
|
simple_mtx_lock(&glsl_type::hash_mutex);
|
||||||
assert(glsl_type_users > 0);
|
assert(glsl_type_users > 0);
|
||||||
|
|
||||||
/* Do not release glsl_types if they are still used. */
|
/* Do not release glsl_types if they are still used. */
|
||||||
if (--glsl_type_users) {
|
if (--glsl_type_users) {
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,7 +567,7 @@ glsl_type_singleton_decref()
|
|||||||
glsl_type::subroutine_types = NULL;
|
glsl_type::subroutine_types = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -687,7 +687,7 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns,
|
|||||||
snprintf(name, sizeof(name), "%sx%ua%uB%s", bare_type->name,
|
snprintf(name, sizeof(name), "%sx%ua%uB%s", bare_type->name,
|
||||||
explicit_stride, explicit_alignment, row_major ? "RM" : "");
|
explicit_stride, explicit_alignment, row_major ? "RM" : "");
|
||||||
|
|
||||||
mtx_lock(&glsl_type::hash_mutex);
|
simple_mtx_lock(&glsl_type::hash_mutex);
|
||||||
assert(glsl_type_users > 0);
|
assert(glsl_type_users > 0);
|
||||||
|
|
||||||
if (explicit_matrix_types == NULL) {
|
if (explicit_matrix_types == NULL) {
|
||||||
@@ -717,7 +717,7 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns,
|
|||||||
|
|
||||||
const glsl_type *t = (const glsl_type *) entry->data;
|
const glsl_type *t = (const glsl_type *) entry->data;
|
||||||
|
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@@ -1241,7 +1241,7 @@ glsl_type::get_array_instance(const glsl_type *base,
|
|||||||
snprintf(key, sizeof(key), "%p[%u]x%uB", (void *) base, array_size,
|
snprintf(key, sizeof(key), "%p[%u]x%uB", (void *) base, array_size,
|
||||||
explicit_stride);
|
explicit_stride);
|
||||||
|
|
||||||
mtx_lock(&glsl_type::hash_mutex);
|
simple_mtx_lock(&glsl_type::hash_mutex);
|
||||||
assert(glsl_type_users > 0);
|
assert(glsl_type_users > 0);
|
||||||
|
|
||||||
if (array_types == NULL) {
|
if (array_types == NULL) {
|
||||||
@@ -1264,7 +1264,7 @@ glsl_type::get_array_instance(const glsl_type *base,
|
|||||||
|
|
||||||
glsl_type *t = (glsl_type *) entry->data;
|
glsl_type *t = (glsl_type *) entry->data;
|
||||||
|
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@@ -1453,7 +1453,7 @@ glsl_type::get_struct_instance(const glsl_struct_field *fields,
|
|||||||
{
|
{
|
||||||
const glsl_type key(fields, num_fields, name, packed, explicit_alignment);
|
const glsl_type key(fields, num_fields, name, packed, explicit_alignment);
|
||||||
|
|
||||||
mtx_lock(&glsl_type::hash_mutex);
|
simple_mtx_lock(&glsl_type::hash_mutex);
|
||||||
assert(glsl_type_users > 0);
|
assert(glsl_type_users > 0);
|
||||||
|
|
||||||
if (struct_types == NULL) {
|
if (struct_types == NULL) {
|
||||||
@@ -1478,7 +1478,7 @@ glsl_type::get_struct_instance(const glsl_struct_field *fields,
|
|||||||
|
|
||||||
glsl_type *t = (glsl_type *) entry->data;
|
glsl_type *t = (glsl_type *) entry->data;
|
||||||
|
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@@ -1493,7 +1493,7 @@ glsl_type::get_interface_instance(const glsl_struct_field *fields,
|
|||||||
{
|
{
|
||||||
const glsl_type key(fields, num_fields, packing, row_major, block_name);
|
const glsl_type key(fields, num_fields, packing, row_major, block_name);
|
||||||
|
|
||||||
mtx_lock(&glsl_type::hash_mutex);
|
simple_mtx_lock(&glsl_type::hash_mutex);
|
||||||
assert(glsl_type_users > 0);
|
assert(glsl_type_users > 0);
|
||||||
|
|
||||||
if (interface_types == NULL) {
|
if (interface_types == NULL) {
|
||||||
@@ -1516,7 +1516,7 @@ glsl_type::get_interface_instance(const glsl_struct_field *fields,
|
|||||||
|
|
||||||
glsl_type *t = (glsl_type *) entry->data;
|
glsl_type *t = (glsl_type *) entry->data;
|
||||||
|
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@@ -1526,7 +1526,7 @@ glsl_type::get_subroutine_instance(const char *subroutine_name)
|
|||||||
{
|
{
|
||||||
const glsl_type key(subroutine_name);
|
const glsl_type key(subroutine_name);
|
||||||
|
|
||||||
mtx_lock(&glsl_type::hash_mutex);
|
simple_mtx_lock(&glsl_type::hash_mutex);
|
||||||
assert(glsl_type_users > 0);
|
assert(glsl_type_users > 0);
|
||||||
|
|
||||||
if (subroutine_types == NULL) {
|
if (subroutine_types == NULL) {
|
||||||
@@ -1547,7 +1547,7 @@ glsl_type::get_subroutine_instance(const char *subroutine_name)
|
|||||||
|
|
||||||
glsl_type *t = (glsl_type *) entry->data;
|
glsl_type *t = (glsl_type *) entry->data;
|
||||||
|
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
@@ -1582,7 +1582,7 @@ glsl_type::get_function_instance(const glsl_type *return_type,
|
|||||||
{
|
{
|
||||||
const glsl_type key(return_type, params, num_params);
|
const glsl_type key(return_type, params, num_params);
|
||||||
|
|
||||||
mtx_lock(&glsl_type::hash_mutex);
|
simple_mtx_lock(&glsl_type::hash_mutex);
|
||||||
assert(glsl_type_users > 0);
|
assert(glsl_type_users > 0);
|
||||||
|
|
||||||
if (function_types == NULL) {
|
if (function_types == NULL) {
|
||||||
@@ -1602,7 +1602,7 @@ glsl_type::get_function_instance(const glsl_type *return_type,
|
|||||||
assert(t->base_type == GLSL_TYPE_FUNCTION);
|
assert(t->base_type == GLSL_TYPE_FUNCTION);
|
||||||
assert(t->length == num_params);
|
assert(t->length == num_params);
|
||||||
|
|
||||||
mtx_unlock(&glsl_type::hash_mutex);
|
simple_mtx_unlock(&glsl_type::hash_mutex);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include "util/blob.h"
|
#include "util/blob.h"
|
||||||
#include "util/format/u_format.h"
|
#include "util/format/u_format.h"
|
||||||
#include "util/macros.h"
|
#include "util/macros.h"
|
||||||
|
#include "util/simple_mtx.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "mesa/main/config.h"
|
#include "mesa/main/config.h"
|
||||||
@@ -1289,7 +1290,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static mtx_t hash_mutex;
|
static simple_mtx_t hash_mutex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ralloc context for the type itself.
|
* ralloc context for the type itself.
|
||||||
|
Reference in New Issue
Block a user