summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/gallivm
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2014-08-28 19:49:35 +0200
committerMathias Fröhlich <[email protected]>2014-09-30 20:45:19 +0200
commit83c62597fc8eb38bf274fa1a3ca03c6adafb4bf9 (patch)
tree512da771be3fa564311d151785c62eb06ad40a64 /src/gallium/auxiliary/gallivm
parent98d00d664009c74ac0c827b3c41c15e3fe1993d4 (diff)
llvmpipe: Use two LLVMContexts per OpenGL context instead of a global one.
This is one step to make llvmpipe thread safe as mandated by the OpenGL standard. Using the global LLVMContext is obviously a problem for that kind of use pattern. The patch introduces two LLVMContext instances that are private to an OpenGL context and used for all compiles. One is put into struct draw_llvm and the other one into struct llvmpipe_context. Reviewed-by: Jose Fonseca <[email protected]> Signed-off-by: Mathias Froehlich <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/gallivm')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_init.c28
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_init.h2
2 files changed, 8 insertions, 22 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 75ef935eb22..8a484978f1e 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -78,17 +78,6 @@
void LLVMLinkInMCJIT();
#endif
-/*
- * LLVM has several global caches which pointing/derived from objects
- * owned by the context, so if we freeing contexts causes
- * memory leaks and false cache hits when these objects are destroyed.
- *
- * TODO: For thread safety on multi-threaded OpenGL we should use one LLVM
- * context per thread, and put them in a pool when threads are destroyed.
- */
-#define USE_GLOBAL_CONTEXT 1
-
-
#ifdef DEBUG
unsigned gallivm_debug = 0;
@@ -209,8 +198,7 @@ gallivm_free_ir(struct gallivm_state *gallivm)
if (gallivm->builder)
LLVMDisposeBuilder(gallivm->builder);
- if (!USE_GLOBAL_CONTEXT && gallivm->context)
- LLVMContextDispose(gallivm->context);
+ /* The LLVMContext should be owned by the parent of gallivm. */
gallivm->engine = NULL;
gallivm->target = NULL;
@@ -301,7 +289,8 @@ fail:
* \return TRUE for success, FALSE for failure
*/
static boolean
-init_gallivm_state(struct gallivm_state *gallivm, const char *name)
+init_gallivm_state(struct gallivm_state *gallivm, const char *name,
+ LLVMContextRef context)
{
assert(!gallivm->context);
assert(!gallivm->module);
@@ -309,11 +298,8 @@ init_gallivm_state(struct gallivm_state *gallivm, const char *name)
if (!lp_build_init())
return FALSE;
- if (USE_GLOBAL_CONTEXT) {
- gallivm->context = LLVMGetGlobalContext();
- } else {
- gallivm->context = LLVMContextCreate();
- }
+ gallivm->context = context;
+
if (!gallivm->context)
goto fail;
@@ -495,13 +481,13 @@ lp_build_init(void)
* Create a new gallivm_state object.
*/
struct gallivm_state *
-gallivm_create(const char *name)
+gallivm_create(const char *name, LLVMContextRef context)
{
struct gallivm_state *gallivm;
gallivm = CALLOC_STRUCT(gallivm_state);
if (gallivm) {
- if (!init_gallivm_state(gallivm, name)) {
+ if (!init_gallivm_state(gallivm, name, context)) {
FREE(gallivm);
gallivm = NULL;
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index 64c5278c24e..6e9f52554a3 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -54,7 +54,7 @@ lp_build_init(void);
struct gallivm_state *
-gallivm_create(const char *name);
+gallivm_create(const char *name, LLVMContextRef context);
void
gallivm_destroy(struct gallivm_state *gallivm);