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

Author: Mathias Fröhlich <[email protected]>
Date:   Sun Sep 21 08:54:00 2014 +0200

llvmpipe: Reuse llvmpipes LLVMContext in the draw context.

Reuse the LLVMContext already allocated in llvmpipe_context
for draw_llvm if ppossible. This should decrease the memory
footprint of an llvmpipe context.

v2: Fix compile with llvm disabled.

Reviewed-by: Jose Fonseca <[email protected]>
Signed-off-by: Mathias Froehlich <[email protected]>

---

 src/gallium/auxiliary/draw/draw_context.c |   18 ++++++++++++++----
 src/gallium/auxiliary/draw/draw_context.h |    5 +++++
 src/gallium/auxiliary/draw/draw_llvm.c    |   11 ++++++++---
 src/gallium/auxiliary/draw/draw_llvm.h    |    3 ++-
 src/gallium/drivers/llvmpipe/lp_context.c |    3 ++-
 5 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_context.c 
b/src/gallium/auxiliary/draw/draw_context.c
index 85f8e26..b0f4ca2 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -81,7 +81,8 @@ draw_get_option_use_llvm(void)
  * Create new draw module context with gallivm state for LLVM JIT.
  */
 static struct draw_context *
-draw_create_context(struct pipe_context *pipe, boolean try_llvm)
+draw_create_context(struct pipe_context *pipe, void *context,
+                    boolean try_llvm)
 {
    struct draw_context *draw = CALLOC_STRUCT( draw_context );
    if (draw == NULL)
@@ -92,7 +93,7 @@ draw_create_context(struct pipe_context *pipe, boolean 
try_llvm)
 
 #if HAVE_LLVM
    if (try_llvm && draw_get_option_use_llvm()) {
-      draw->llvm = draw_llvm_create(draw);
+      draw->llvm = draw_llvm_create(draw, (LLVMContextRef)context);
    }
 #endif
 
@@ -120,17 +121,26 @@ err_out:
 struct draw_context *
 draw_create(struct pipe_context *pipe)
 {
-   return draw_create_context(pipe, TRUE);
+   return draw_create_context(pipe, NULL, TRUE);
 }
 
 
+#if HAVE_LLVM
+struct draw_context *
+draw_create_with_llvm_context(struct pipe_context *pipe,
+                              void *context)
+{
+   return draw_create_context(pipe, context, TRUE);
+}
+#endif
+
 /**
  * Create a new draw context, without LLVM JIT.
  */
 struct draw_context *
 draw_create_no_llvm(struct pipe_context *pipe)
 {
-   return draw_create_context(pipe, FALSE);
+   return draw_create_context(pipe, NULL, FALSE);
 }
 
 
diff --git a/src/gallium/auxiliary/draw/draw_context.h 
b/src/gallium/auxiliary/draw/draw_context.h
index 48549fe..a5a6df5 100644
--- a/src/gallium/auxiliary/draw/draw_context.h
+++ b/src/gallium/auxiliary/draw/draw_context.h
@@ -64,6 +64,11 @@ struct draw_so_target {
 
 struct draw_context *draw_create( struct pipe_context *pipe );
 
+#if HAVE_LLVM
+struct draw_context *draw_create_with_llvm_context(struct pipe_context *pipe,
+                                                   void *context);
+#endif
+
 struct draw_context *draw_create_no_llvm(struct pipe_context *pipe);
 
 void draw_destroy( struct draw_context *draw );
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index 8469d69..14c802b 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -480,7 +480,7 @@ get_vertex_header_ptr_type(struct draw_llvm_variant 
*variant)
  * Create per-context LLVM info.
  */
 struct draw_llvm *
-draw_llvm_create(struct draw_context *draw)
+draw_llvm_create(struct draw_context *draw, LLVMContextRef context)
 {
    struct draw_llvm *llvm;
 
@@ -493,7 +493,11 @@ draw_llvm_create(struct draw_context *draw)
 
    llvm->draw = draw;
 
-   llvm->context = LLVMContextCreate();
+   llvm->context = context;
+   if (!llvm->context) {
+      llvm->context = LLVMContextCreate();
+      llvm->context_owned = true;
+   }
    if (!llvm->context)
       goto fail;
 
@@ -517,7 +521,8 @@ fail:
 void
 draw_llvm_destroy(struct draw_llvm *llvm)
 {
-   LLVMContextDispose(llvm->context);
+   if (llvm->context_owned)
+      LLVMContextDispose(llvm->context);
    llvm->context = NULL;
 
    /* XXX free other draw_llvm data? */
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h 
b/src/gallium/auxiliary/draw/draw_llvm.h
index a4bd1ed..54a7da2 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -462,6 +462,7 @@ struct draw_llvm {
    struct draw_context *draw;
 
    LLVMContextRef context;
+   boolean context_owned;
 
    struct draw_jit_context jit_context;
    struct draw_gs_jit_context gs_jit_context;
@@ -490,7 +491,7 @@ llvm_geometry_shader(struct draw_geometry_shader *gs)
 
 
 struct draw_llvm *
-draw_llvm_create(struct draw_context *draw);
+draw_llvm_create(struct draw_context *draw, LLVMContextRef llvm_context);
 
 void
 draw_llvm_destroy(struct draw_llvm *llvm);
diff --git a/src/gallium/drivers/llvmpipe/lp_context.c 
b/src/gallium/drivers/llvmpipe/lp_context.c
index 3a9b4c2..37b1ff4 100644
--- a/src/gallium/drivers/llvmpipe/lp_context.c
+++ b/src/gallium/drivers/llvmpipe/lp_context.c
@@ -171,7 +171,8 @@ llvmpipe_create_context( struct pipe_screen *screen, void 
*priv )
    /*
     * Create drawing context and plug our rendering stage into it.
     */
-   llvmpipe->draw = draw_create(&llvmpipe->pipe);
+   llvmpipe->draw = draw_create_with_llvm_context(&llvmpipe->pipe,
+                                                  llvmpipe->context);
    if (!llvmpipe->draw)
       goto fail;
 

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to