From 8b3d36d56378355f188dd419e35676b2e4086a73 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 30 Aug 2010 12:20:25 -0700 Subject: glsl: Clear the static values of builtin function profiles at release. When releasing the builtin functions, we were just freeing the memory, not telling the builtin function loader that we had freed its memory. I wish I had done ARB_ES2_compatibility so we had regression testing of this path. Fixes segfault on changing video options in nexuiz. --- src/glsl/builtins/tools/generate_builtins.py | 56 ++++++++++++++++++---------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'src/glsl/builtins') diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py index ab5b3777cb7..5accc1b1208 100755 --- a/src/glsl/builtins/tools/generate_builtins.py +++ b/src/glsl/builtins/tools/generate_builtins.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- import re from glob import glob @@ -168,27 +168,54 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne write_function_definitions() write_profiles() + profiles = get_profile_list() + + print 'static gl_shader *builtin_profiles[%d];' % len(profiles) + print """ void *builtin_mem_ctx = NULL; void _mesa_glsl_release_functions(void) { - talloc_free(builtin_mem_ctx); - builtin_mem_ctx = NULL; + talloc_free(builtin_mem_ctx); + builtin_mem_ctx = NULL; +} + +static void +_mesa_read_profile(struct _mesa_glsl_parse_state *state, + exec_list *instructions, + int profile_index, + const char *prototypes, + const char **functions, + int count) +{ + gl_shader *sh = builtin_profiles[profile_index]; + + if (sh == NULL) { + sh = read_builtins(GL_VERTEX_SHADER, prototypes, functions, count); + talloc_steal(builtin_mem_ctx, sh); + builtin_profiles[profile_index] = sh; + } + + import_prototypes(sh->ir, instructions, state->symbols, state); + state->builtins_to_link[state->num_builtins_to_link] = sh; + state->num_builtins_to_link++; } void _mesa_glsl_initialize_functions(exec_list *instructions, struct _mesa_glsl_parse_state *state) { - if (builtin_mem_ctx == NULL) + if (builtin_mem_ctx == NULL) { builtin_mem_ctx = talloc_init("GLSL built-in functions"); + memset(&builtin_profiles, 0, sizeof(builtin_profiles)); + } state->num_builtins_to_link = 0; """ - profiles = get_profile_list() + i=0 for (filename, profile) in profiles: if profile.endswith('_vert'): check = 'state->target == vertex_shader && ' @@ -202,21 +229,12 @@ _mesa_glsl_initialize_functions(exec_list *instructions, check += 'state->' + version + '_enable' print ' if (' + check + ') {' - print ' static gl_shader *sh = NULL;' - print ' if (sh == NULL) {' - print ' sh = read_builtins(GL_VERTEX_SHADER,' - print ' prototypes_for_' + profile + ',' - print ' functions_for_' + profile + ',' - print ' Elements(functions_for_' + profile, - print '));' - print ' talloc_steal(builtin_mem_ctx, sh);' - print ' }' - print - print ' import_prototypes(sh->ir, instructions, state->symbols,' - print ' state);' - print ' state->builtins_to_link[state->num_builtins_to_link] = sh;' - print ' state->num_builtins_to_link++;' + print ' _mesa_read_profile(state, instructions, %d,' % i + print ' prototypes_for_' + profile + ',' + print ' functions_for_' + profile + ',' + print ' Elements(functions_for_' + profile + '));' print ' }' print + i = i + 1 print '}' -- cgit v1.2.3