From 1c476098880a8fa54a7b32a20eb2a80538661404 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Tue, 28 Feb 2023 15:37:14 -0800 Subject: [PATCH] glsl/standalone: Pull program create/destroy out to a public function. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For reuse with unit tests. Reviewed-by: Marek Olšák Part-of: --- src/compiler/glsl/standalone.cpp | 25 ++----------------- src/compiler/glsl/standalone_scaffolding.cpp | 36 ++++++++++++++++++++++++++++ src/compiler/glsl/standalone_scaffolding.h | 4 ++++ 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp index d33d507..2820b08 100644 --- a/src/compiler/glsl/standalone.cpp +++ b/src/compiler/glsl/standalone.cpp @@ -35,7 +35,6 @@ #include "program.h" #include "standalone_scaffolding.h" #include "standalone.h" -#include "string_to_uint_map.h" #include "util/set.h" #include "linker.h" #include "glsl_parser_extras.h" @@ -441,18 +440,7 @@ standalone_compile_shader(const struct standalone_options *_options, } } - struct gl_shader_program *whole_program; - - whole_program = rzalloc (NULL, struct gl_shader_program); - assert(whole_program != NULL); - whole_program->data = rzalloc(whole_program, struct gl_shader_program_data); - assert(whole_program->data != NULL); - whole_program->data->InfoLog = ralloc_strdup(whole_program->data, ""); - - /* Created just to avoid segmentation faults */ - whole_program->AttributeBindings = new string_to_uint_map; - whole_program->FragDataBindings = new string_to_uint_map; - whole_program->FragDataIndexBindings = new string_to_uint_map; + struct gl_shader_program *whole_program = standalone_create_shader_program(); for (unsigned i = 0; i < num_files; i++) { whole_program->Shaders = @@ -604,16 +592,7 @@ fail: extern "C" void standalone_compiler_cleanup(struct gl_shader_program *whole_program) { - for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { - if (whole_program->_LinkedShaders[i]) - _mesa_delete_linked_shader(NULL, whole_program->_LinkedShaders[i]); - } - - delete whole_program->AttributeBindings; - delete whole_program->FragDataBindings; - delete whole_program->FragDataIndexBindings; - delete whole_program->UniformHash; + standalone_destroy_shader_program(whole_program); - ralloc_free(whole_program); _mesa_glsl_builtin_functions_decref(); } diff --git a/src/compiler/glsl/standalone_scaffolding.cpp b/src/compiler/glsl/standalone_scaffolding.cpp index 5cd52e6..d3e7190 100644 --- a/src/compiler/glsl/standalone_scaffolding.cpp +++ b/src/compiler/glsl/standalone_scaffolding.cpp @@ -35,6 +35,7 @@ #include "util/ralloc.h" #include "util/strtod.h" #include "main/mtypes.h" +#include "string_to_uint_map.h" void _mesa_warning(struct gl_context *ctx, const char *fmt, ...) @@ -271,3 +272,38 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api) _mesa_locale_init(); } + +struct gl_shader_program * +standalone_create_shader_program(void) +{ + struct gl_shader_program *whole_program; + + whole_program = rzalloc (NULL, struct gl_shader_program); + assert(whole_program != NULL); + whole_program->data = rzalloc(whole_program, struct gl_shader_program_data); + assert(whole_program->data != NULL); + whole_program->data->InfoLog = ralloc_strdup(whole_program->data, ""); + + /* Created just to avoid segmentation faults */ + whole_program->AttributeBindings = new string_to_uint_map; + whole_program->FragDataBindings = new string_to_uint_map; + whole_program->FragDataIndexBindings = new string_to_uint_map; + + return whole_program; +} + +void +standalone_destroy_shader_program(struct gl_shader_program *whole_program) +{ + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + if (whole_program->_LinkedShaders[i]) + _mesa_delete_linked_shader(NULL, whole_program->_LinkedShaders[i]); + } + + delete whole_program->AttributeBindings; + delete whole_program->FragDataBindings; + delete whole_program->FragDataIndexBindings; + delete whole_program->UniformHash; + + ralloc_free(whole_program); +} diff --git a/src/compiler/glsl/standalone_scaffolding.h b/src/compiler/glsl/standalone_scaffolding.h index 40429764..3221259 100644 --- a/src/compiler/glsl/standalone_scaffolding.h +++ b/src/compiler/glsl/standalone_scaffolding.h @@ -109,5 +109,9 @@ _mesa_shader_enum_to_shader_stage(GLenum v) */ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api); +struct gl_shader_program * +standalone_create_shader_program(void); +void +standalone_destroy_shader_program(struct gl_shader_program *whole_program); #endif /* STANDALONE_SCAFFOLDING_H */ -- 2.7.4