Mesa (master): llvmpipe: use global llvm context for PIPE_SUBSYSTEM_EMBEDDED

Roland Scheidegger sroland at kemper.freedesktop.org
Sat Mar 21 00:52:25 UTC 2015


Module: Mesa
Branch: master
Commit: e8039208c4a771b0c1fb8a44623bcf0261508f87
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e8039208c4a771b0c1fb8a44623bcf0261508f87

Author: Roland Scheidegger <sroland at vmware.com>
Date:   Sat Mar 21 01:13:54 2015 +0100

llvmpipe: use global llvm context for PIPE_SUBSYSTEM_EMBEDDED

There's 2 reasons why we'd want to use the global context:
1) There still seems to be one memory "leak" left when using multiple llvm
contexts (it is not a true leak as the memory disappears into some still
addressable pool but nevertheless the memory consumption grows). See
http://cgit.freedesktop.org/~jrfonseca/llvm-jitstress/
2) These contexts get kinda big - even when disposing modules etc. after
compiling a shader the LLVMContext can easily be over 100kB. So when there's
lots of llvm contexts arounds it adds up.

The downside is that at least right now this is absolutely not thread safe,
so this only works safely in environments where multiple pipe contexts are not
used concurrently.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

---

 src/gallium/drivers/llvmpipe/lp_context.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c
index 06cc820..80cb657 100644
--- a/src/gallium/drivers/llvmpipe/lp_context.c
+++ b/src/gallium/drivers/llvmpipe/lp_context.c
@@ -46,6 +46,10 @@
 #include "lp_query.h"
 #include "lp_setup.h"
 
+/* This is only safe if there's just one concurrent context */
+#ifdef PIPE_SUBSYSTEM_EMBEDDED
+#define USE_GLOBAL_LLVM_CONTEXT
+#endif
 
 static void llvmpipe_destroy( struct pipe_context *pipe )
 {
@@ -93,7 +97,9 @@ static void llvmpipe_destroy( struct pipe_context *pipe )
 
    lp_delete_setup_variants(llvmpipe);
 
+#ifndef USE_GLOBAL_LLVM_CONTEXT
    LLVMContextDispose(llvmpipe->context);
+#endif
    llvmpipe->context = NULL;
 
    align_free( llvmpipe );
@@ -164,7 +170,12 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv )
    llvmpipe_init_context_resource_funcs( &llvmpipe->pipe );
    llvmpipe_init_surface_functions(llvmpipe);
 
+#ifdef USE_GLOBAL_LLVM_CONTEXT
+   llvmpipe->context = LLVMGetGlobalContext();
+#else
    llvmpipe->context = LLVMContextCreate();
+#endif
+
    if (!llvmpipe->context)
       goto fail;
 




More information about the mesa-commit mailing list