glsl/standalone: Pull program create/destroy out to a public function.
authorEmma Anholt <emma@anholt.net>
Tue, 28 Feb 2023 23:37:14 +0000 (15:37 -0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 22 Mar 2023 22:52:45 +0000 (22:52 +0000)
For reuse with unit tests.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21886>

src/compiler/glsl/standalone.cpp
src/compiler/glsl/standalone_scaffolding.cpp
src/compiler/glsl/standalone_scaffolding.h

index d33d507..2820b08 100644 (file)
@@ -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();
 }
index 5cd52e6..d3e7190 100644 (file)
@@ -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);
+}
index 4042976..3221259 100644 (file)
@@ -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 */