Hi,

attached a change to llvmpipe fixing a long standing problem with 
multithreaded OpenGL applications.

Please review!
thanks!

Mathias
>From 7e85383c4a23e19e739eb3df574c8062c381beee Mon Sep 17 00:00:00 2001
Message-Id: <7e85383c4a23e19e739eb3df574c8062c381beee.1395945410.git.mathias.froehl...@gmx.net>
From: =?UTF-8?q?Mathias=20Fr=C3=B6hlich?= <mathias.froehl...@gmx.net>
Date: Mon, 24 Mar 2014 19:10:00 +0100
Subject: [PATCH] llvmpipe: Use a LLVMContext for each llvmpipe OpenGL context.

This fixes a long standing problem with multithreaded programs
creating multiple contexts for use in seperate threads.
Currently these different threads concurrently access this
single LLVMContext that is used for all llvmpipe OpenGL
contexts.
This change uses a private LLVMContext for each OpenGL context.
It is tested with a regression free llvmpipe piglit run using
llvm from todays 3.4 release branch.
Since it is unclear to me what really went wrong in the first
place, the change is guarded with a LLVM version conditional
that enables the private LLVMContext only on the tested llvm
version and newer.

Signed-off-by: Mathias Froehlich <mathias.froehl...@gmx.net>
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 61b561f..c251e3a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -229,7 +229,7 @@ free_gallivm_state(struct gallivm_state *gallivm)
 
    /* Never free the LLVM context.
     */
-#if 0
+#if HAVE_LLVM >= 0x0304
    if (gallivm->context)
       LLVMContextDispose(gallivm->context);
 #endif
@@ -316,6 +316,7 @@ fail:
 }
 
 
+#if HAVE_LLVM < 0x0304
 /**
  * Singleton
  *
@@ -327,6 +328,7 @@ fail:
  * context per thread, and put them in a pool when threads are destroyed.
  */
 static LLVMContextRef gallivm_context = NULL;
+#endif
 
 
 /**
@@ -342,10 +344,14 @@ init_gallivm_state(struct gallivm_state *gallivm)
 
    lp_build_init();
 
+#if HAVE_LLVM < 0x0304
    if (!gallivm_context) {
       gallivm_context = LLVMContextCreate();
    }
    gallivm->context = gallivm_context;
+#else
+   gallivm->context = LLVMContextCreate();
+#endif
    if (!gallivm->context)
       goto fail;
 
-- 
1.9.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to