Mesa (glsl2): glsl2: talloc the glsl_struct_field[] we use to look up structure types.
Eric Anholt
anholt at kemper.freedesktop.org
Wed Jul 21 00:30:27 UTC 2010
Module: Mesa
Branch: glsl2
Commit: 21b0dbd79937e9d6787f045af7d60d4b6c649ec8
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=21b0dbd79937e9d6787f045af7d60d4b6c649ec8
Author: Eric Anholt <eric at anholt.net>
Date: Tue Jul 20 16:47:25 2010 -0700
glsl2: talloc the glsl_struct_field[] we use to look up structure types.
Since the types are singletons across the lifetime of the compiler,
repeatedly compiling a program with the same structure type defined
would drop a copy of the array on the floor per compile.
This is a bit tricky because the static GLSL types are not called with
the talloc-based new, so we have to use the global type context, which
may not be initialized yet.
---
src/glsl/ast_to_hir.cpp | 4 ++--
src/glsl/glsl_types.cpp | 15 ++++++++++++++-
src/glsl/glsl_types.h | 2 +-
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 41371e7..f20c7ea 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2471,8 +2471,8 @@ ast_struct_specifier::hir(exec_list *instructions,
* the types to HIR. This ensures that structure definitions embedded in
* other structure definitions are processed.
*/
- glsl_struct_field *const fields = (glsl_struct_field *)
- malloc(sizeof(*fields) * decl_count);
+ glsl_struct_field *const fields = talloc_array(state, glsl_struct_field,
+ decl_count);
unsigned i = 0;
foreach_list_typed (ast_declarator_list, decl_list, link,
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 6ca141e..77c591e 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -75,7 +75,20 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
name(name),
length(num_fields)
{
- this->fields.structure = fields;
+ unsigned int i;
+
+ if (glsl_type::ctx == NULL) {
+ glsl_type::ctx = talloc_init("glsl_type");
+ assert(glsl_type::ctx != NULL);
+ }
+
+ this->fields.structure = talloc_array(glsl_type::ctx,
+ glsl_struct_field, length);
+ for (i = 0; i < length; i++) {
+ this->fields.structure[i].type = fields[i].type;
+ this->fields.structure[i].name = talloc_strdup(this->fields.structure,
+ fields[i].name);
+ }
}
static void
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index e869071..8ba9b5f 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -136,7 +136,7 @@ struct glsl_type {
union {
const struct glsl_type *array; /**< Type of array elements. */
const struct glsl_type *parameters; /**< Parameters to function. */
- const struct glsl_struct_field *structure;/**< List of struct fields. */
+ struct glsl_struct_field *structure; /**< List of struct fields. */
} fields;
More information about the mesa-commit
mailing list