diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index 3cc5eb0495..d7401d2ee7 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -100,7 +100,7 @@ glsl_type::glsl_type(GLenum gl_type, glsl_base_type base_type, } glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, - const char *name) : + const char *name, void *ralloc_ctx) : gl_type(0), base_type(GLSL_TYPE_STRUCT), sampled_type(GLSL_TYPE_VOID), sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), @@ -109,13 +109,14 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, length(num_fields) { unsigned int i; + void *mem_ctx = ralloc_ctx ? ralloc_ctx : this->mem_ctx; mtx_lock(&glsl_type::mem_mutex); init_ralloc_type_ctx(); assert(name != NULL); - this->name = ralloc_strdup(this->mem_ctx, name); - this->fields.structure = ralloc_array(this->mem_ctx, + this->name = ralloc_strdup(mem_ctx, name); + this->fields.structure = ralloc_array(mem_ctx, glsl_struct_field, length); for (i = 0; i < length; i++) { @@ -129,7 +130,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, enum glsl_interface_packing packing, - bool row_major, const char *name) : + bool row_major, const char *name, void *ralloc_ctx) : gl_type(0), base_type(GLSL_TYPE_INTERFACE), sampled_type(GLSL_TYPE_VOID), sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), @@ -139,13 +140,14 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, length(num_fields) { unsigned int i; + void *mem_ctx = ralloc_ctx ? ralloc_ctx : this->mem_ctx; mtx_lock(&glsl_type::mem_mutex); init_ralloc_type_ctx(); assert(name != NULL); - this->name = ralloc_strdup(this->mem_ctx, name); - this->fields.structure = rzalloc_array(this->mem_ctx, + this->name = ralloc_strdup(mem_ctx, name); + this->fields.structure = rzalloc_array(mem_ctx, glsl_struct_field, length); for (i = 0; i < length; i++) { this->fields.structure[i] = fields[i]; @@ -157,7 +159,8 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, } glsl_type::glsl_type(const glsl_type *return_type, - const glsl_function_param *params, unsigned num_params) : + const glsl_function_param *params, unsigned num_params, + void *ralloc_ctx) : gl_type(0), base_type(GLSL_TYPE_FUNCTION), sampled_type(GLSL_TYPE_VOID), sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), @@ -166,12 +169,13 @@ glsl_type::glsl_type(const glsl_type *return_type, length(num_params) { unsigned int i; + void *mem_ctx = ralloc_ctx ? ralloc_ctx : this->mem_ctx; mtx_lock(&glsl_type::mem_mutex); init_ralloc_type_ctx(); - this->fields.parameters = rzalloc_array(this->mem_ctx, + this->fields.parameters = rzalloc_array(mem_ctx, glsl_function_param, num_params + 1); /* We store the return type as the first parameter */ @@ -1108,7 +1112,8 @@ glsl_type::get_record_instance(const glsl_struct_field *fields, unsigned num_fields, const char *name) { - const glsl_type key(fields, num_fields, name); + void *local = ralloc_context(NULL); + const glsl_type key(fields, num_fields, name, local); mtx_lock(&glsl_type::hash_mutex); @@ -1131,6 +1136,8 @@ glsl_type::get_record_instance(const glsl_struct_field *fields, mtx_unlock(&glsl_type::hash_mutex); + ralloc_free(local); + return (glsl_type *) entry->data; } @@ -1142,7 +1149,9 @@ glsl_type::get_interface_instance(const glsl_struct_field *fields, bool row_major, const char *block_name) { - const glsl_type key(fields, num_fields, packing, row_major, block_name); + void *local = ralloc_context(NULL); + const glsl_type key(fields, num_fields, packing, row_major, block_name, + local); mtx_lock(&glsl_type::hash_mutex); @@ -1166,6 +1175,8 @@ glsl_type::get_interface_instance(const glsl_struct_field *fields, mtx_unlock(&glsl_type::hash_mutex); + ralloc_free(local); + return (glsl_type *) entry->data; } @@ -1225,7 +1236,8 @@ glsl_type::get_function_instance(const glsl_type *return_type, const glsl_function_param *params, unsigned num_params) { - const glsl_type key(return_type, params, num_params); + void *local = ralloc_context(NULL); + const glsl_type key(return_type, params, num_params, local); mtx_lock(&glsl_type::hash_mutex); @@ -1248,6 +1260,8 @@ glsl_type::get_function_instance(const glsl_type *return_type, mtx_unlock(&glsl_type::hash_mutex); + ralloc_free(local); + return t; } diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h index ab0b263764..f65ef8417f 100644 --- a/src/compiler/glsl_types.h +++ b/src/compiler/glsl_types.h @@ -899,16 +899,17 @@ private: /** Constructor for record types */ glsl_type(const glsl_struct_field *fields, unsigned num_fields, - const char *name); + const char *name, void *ralloc_ctx = NULL); /** Constructor for interface types */ glsl_type(const glsl_struct_field *fields, unsigned num_fields, enum glsl_interface_packing packing, - bool row_major, const char *name); + bool row_major, const char *name, void *ralloc_ctx = NULL); /** Constructor for interface types */ glsl_type(const glsl_type *return_type, - const glsl_function_param *params, unsigned num_params); + const glsl_function_param *params, unsigned num_params, + void *ralloc_ctx = NULL); /** Constructor for array types */ glsl_type(const glsl_type *array, unsigned length);