summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/llvmpipe/lp_context.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2010-11-30 16:07:52 -0700
committerBrian Paul <[email protected]>2010-11-30 16:35:12 -0700
commitefc82aef35a2aac5d2ed9774f6d28f2626796416 (patch)
tree72fe4482d72dbeb8e41b15793b21f38de62ef834 /src/gallium/drivers/llvmpipe/lp_context.c
parent1f1375d4d876c2c85156e02a177254684446040b (diff)
gallivm/llvmpipe: squash merge of the llvm-context branch
This branch defines a gallivm_state structure which contains the LLVMBuilderRef, LLVMContextRef, etc. All data structures built with this object can be periodically freed during a "garbage collection" operation. The gallivm_state object has to be passed to most of the builder functions where LLVMBuilderRef used to be used. Conflicts: src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c src/gallium/drivers/llvmpipe/lp_state_setup.c
Diffstat (limited to 'src/gallium/drivers/llvmpipe/lp_context.c')
-rw-r--r--src/gallium/drivers/llvmpipe/lp_context.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c
index 763432ed712..2de20d6e9a3 100644
--- a/src/gallium/drivers/llvmpipe/lp_context.c
+++ b/src/gallium/drivers/llvmpipe/lp_context.c
@@ -50,6 +50,46 @@
DEBUG_GET_ONCE_BOOL_OPTION(lp_no_rast, "LP_NO_RAST", FALSE)
+/** shared by all contexts */
+unsigned llvmpipe_variant_count;
+
+
+/**
+ * This function is called by the gallivm "garbage collector" when
+ * the LLVM global data structures are freed. We must free all LLVM-related
+ * data. Specifically, all JIT'd shader variants.
+ */
+static void
+garbage_collect_callback(void *cb_data)
+{
+ struct llvmpipe_context *lp = (struct llvmpipe_context *) cb_data;
+ struct lp_fs_variant_list_item *li;
+
+ /* Free all the context's shader variants */
+ li = first_elem(&lp->fs_variants_list);
+ while (!at_end(&lp->fs_variants_list, li)) {
+ struct lp_fs_variant_list_item *next = next_elem(li);
+ llvmpipe_remove_shader_variant(lp, li->base);
+ li = next;
+ }
+
+ /* Free all the context's primitive setup variants */
+ lp_delete_setup_variants(lp);
+
+ /* release references to setup variants, shaders */
+ lp_setup_set_setup_variant(lp->setup, NULL);
+ lp_setup_set_fs_variant(lp->setup, NULL);
+ lp_setup_reset(lp->setup);
+
+ /* This type will be recreated upon demand */
+ lp->jit_context_ptr_type = NULL;
+
+ /* mark all state as dirty to ensure new shaders are jit'd, etc. */
+ lp->dirty = ~0;
+}
+
+
+
static void llvmpipe_destroy( struct pipe_context *pipe )
{
struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
@@ -57,6 +97,9 @@ static void llvmpipe_destroy( struct pipe_context *pipe )
lp_print_counters();
+ gallivm_remove_garbage_collector_callback(garbage_collect_callback,
+ llvmpipe);
+
/* This will also destroy llvmpipe->setup:
*/
if (llvmpipe->draw)
@@ -82,7 +125,7 @@ static void llvmpipe_destroy( struct pipe_context *pipe )
}
}
- lp_delete_setup_variants(llvmpipe);
+ gallivm_destroy(llvmpipe->gallivm);
align_free( llvmpipe );
}
@@ -110,8 +153,10 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv )
memset(llvmpipe, 0, sizeof *llvmpipe);
make_empty_list(&llvmpipe->fs_variants_list);
+
make_empty_list(&llvmpipe->setup_variants_list);
+
llvmpipe->pipe.winsys = screen->winsys;
llvmpipe->pipe.screen = screen;
llvmpipe->pipe.priv = priv;
@@ -136,10 +181,12 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv )
llvmpipe_init_context_resource_funcs( &llvmpipe->pipe );
llvmpipe_init_surface_functions(llvmpipe);
+ llvmpipe->gallivm = gallivm_create();
+
/*
* Create drawing context and plug our rendering stage into it.
*/
- llvmpipe->draw = draw_create(&llvmpipe->pipe);
+ llvmpipe->draw = draw_create_gallivm(&llvmpipe->pipe, llvmpipe->gallivm);
if (!llvmpipe->draw)
goto fail;
@@ -173,6 +220,9 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv )
lp_reset_counters();
+ gallivm_register_garbage_collector_callback(garbage_collect_callback,
+ llvmpipe);
+
return &llvmpipe->pipe;
fail: