[Mesa-dev] [PATCH 2/2] anv: release spirv_to_nir glsl_type allocations

Grazvydas Ignotas notasas at gmail.com
Tue May 2 18:01:08 UTC 2017


Add a spirv_to_nir_fini() helper to clean up glsl_type allocations
resulting from spirv_to_nir() calls and call it on exit. This resolves
many reports from valgrind and should be helpful for application
developers that use valgrind.

Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
---
 src/compiler/spirv/nir_spirv.h    | 2 ++
 src/compiler/spirv/spirv_to_nir.c | 6 ++++++
 src/intel/vulkan/anv_device.c     | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h
index 1779d1c..c440ebc 100644
--- a/src/compiler/spirv/nir_spirv.h
+++ b/src/compiler/spirv/nir_spirv.h
@@ -57,10 +57,12 @@ nir_function *spirv_to_nir(const uint32_t *words, size_t word_count,
                            unsigned num_specializations,
                            gl_shader_stage stage, const char *entry_point_name,
                            const struct nir_spirv_supported_extensions *ext,
                            const nir_shader_compiler_options *options);
 
+void spirv_to_nir_fini(void);
+
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* _NIR_SPIRV_H_ */
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index d3ad2d1..08120d4 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3312,5 +3312,11 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
 
    ralloc_free(b);
 
    return entry_point;
 }
+
+void
+spirv_to_nir_fini(void)
+{
+   _mesa_glsl_release_types();
+}
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 92bd255..e539a5e 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -34,10 +34,11 @@
 #include "util/strtod.h"
 #include "util/debug.h"
 #include "util/build_id.h"
 #include "util/mesa-sha1.h"
 #include "util/vk_util.h"
+#include "spirv/nir_spirv.h"
 
 #include "genxml/gen7_pack.h"
 
 static void
 compiler_debug_log(void *data, const char *fmt, ...)
@@ -403,10 +404,11 @@ static pthread_once_t anv_one_time_init_control = PTHREAD_ONCE_INIT;
 
 static void
 anv_one_time_fini(void)
 {
    _mesa_locale_fini();
+   spirv_to_nir_fini();
 }
 
 static void
 anv_one_time_init(void)
 {
-- 
2.7.4



More information about the mesa-dev mailing list