X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fllvmpipe%2Flp_context.c;h=016416e01163c7f5ed5202a4a0328936456ec39c;hb=e740e7a6f018738b02ce97db172d6749feeadce1;hp=644201ddf7c1580e9aac6d3f22ec466474de95d1;hpb=652901e95b4ed406293d0e1fabee857c054119b1;p=mesa.git diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c index 644201ddf7c..016416e0116 100644 --- a/src/gallium/drivers/llvmpipe/lp_context.c +++ b/src/gallium/drivers/llvmpipe/lp_context.c @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2007 VMware, Inc. * All Rights Reserved. * Copyright 2008 VMware, Inc. All rights reserved. * @@ -19,7 +19,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -27,7 +27,7 @@ **************************************************************************/ /* Author: - * Keith Whitwell + * Keith Whitwell */ #include "draw/draw_context.h" @@ -36,7 +36,8 @@ #include "util/u_inlines.h" #include "util/u_math.h" #include "util/u_memory.h" -#include "util/u_simple_list.h" +#include "util/simple_list.h" +#include "util/u_upload_mgr.h" #include "lp_clear.h" #include "lp_context.h" #include "lp_flush.h" @@ -46,49 +47,10 @@ #include "lp_query.h" #include "lp_setup.h" - -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; -} - - +/* This is only safe if there's just one concurrent context */ +#ifdef EMBEDDED_DEVICE +#define USE_GLOBAL_LLVM_CONTEXT +#endif static void llvmpipe_destroy( struct pipe_context *pipe ) { @@ -97,8 +59,12 @@ static void llvmpipe_destroy( struct pipe_context *pipe ) lp_print_counters(); - gallivm_remove_garbage_collector_callback(garbage_collect_callback, - llvmpipe); + if (llvmpipe->blitter) { + util_blitter_destroy(llvmpipe->blitter); + } + + if (llvmpipe->pipe.stream_uploader) + u_upload_destroy(llvmpipe->pipe.stream_uploader); /* This will also destroy llvmpipe->setup: */ @@ -111,40 +77,63 @@ static void llvmpipe_destroy( struct pipe_context *pipe ) pipe_surface_reference(&llvmpipe->framebuffer.zsbuf, NULL); - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - pipe_sampler_view_reference(&llvmpipe->fragment_sampler_views[i], NULL); + for (i = 0; i < ARRAY_SIZE(llvmpipe->sampler_views[0]); i++) { + pipe_sampler_view_reference(&llvmpipe->sampler_views[PIPE_SHADER_FRAGMENT][i], NULL); } - for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - pipe_sampler_view_reference(&llvmpipe->vertex_sampler_views[i], NULL); + for (i = 0; i < ARRAY_SIZE(llvmpipe->sampler_views[0]); i++) { + pipe_sampler_view_reference(&llvmpipe->sampler_views[PIPE_SHADER_VERTEX][i], NULL); } - for (i = 0; i < Elements(llvmpipe->constants); i++) { - for (j = 0; j < Elements(llvmpipe->constants[i]); j++) { - pipe_resource_reference(&llvmpipe->constants[i][j], NULL); + for (i = 0; i < ARRAY_SIZE(llvmpipe->sampler_views[0]); i++) { + pipe_sampler_view_reference(&llvmpipe->sampler_views[PIPE_SHADER_GEOMETRY][i], NULL); + } + + for (i = 0; i < ARRAY_SIZE(llvmpipe->constants); i++) { + for (j = 0; j < ARRAY_SIZE(llvmpipe->constants[i]); j++) { + pipe_resource_reference(&llvmpipe->constants[i][j].buffer, NULL); } } for (i = 0; i < llvmpipe->num_vertex_buffers; i++) { - pipe_resource_reference(&llvmpipe->vertex_buffer[i].buffer, NULL); + pipe_vertex_buffer_unreference(&llvmpipe->vertex_buffer[i]); } - gallivm_destroy(llvmpipe->gallivm); + lp_delete_setup_variants(llvmpipe); + +#ifndef USE_GLOBAL_LLVM_CONTEXT + LLVMContextDispose(llvmpipe->context); +#endif + llvmpipe->context = NULL; align_free( llvmpipe ); } static void do_flush( struct pipe_context *pipe, - unsigned flags, - struct pipe_fence_handle **fence) + struct pipe_fence_handle **fence, + unsigned flags) { - llvmpipe_flush(pipe, flags, fence, __FUNCTION__); + llvmpipe_flush(pipe, fence, __FUNCTION__); } +static void +llvmpipe_render_condition(struct pipe_context *pipe, + struct pipe_query *query, + bool condition, + enum pipe_render_cond_flag mode) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe ); + + llvmpipe->render_cond_query = query; + llvmpipe->render_cond_mode = mode; + llvmpipe->render_cond_cond = condition; +} + struct pipe_context * -llvmpipe_create_context( struct pipe_screen *screen, void *priv ) +llvmpipe_create_context(struct pipe_screen *screen, void *priv, + unsigned flags) { struct llvmpipe_context *llvmpipe; @@ -161,7 +150,6 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv ) make_empty_list(&llvmpipe->setup_variants_list); - llvmpipe->pipe.winsys = screen->winsys; llvmpipe->pipe.screen = screen; llvmpipe->pipe.priv = priv; @@ -171,6 +159,8 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv ) llvmpipe->pipe.clear = llvmpipe_clear; llvmpipe->pipe.flush = do_flush; + llvmpipe->pipe.render_condition = llvmpipe_render_condition; + llvmpipe_init_blend_funcs(llvmpipe); llvmpipe_init_clip_funcs(llvmpipe); llvmpipe_init_draw_funcs(llvmpipe); @@ -185,25 +175,43 @@ 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(); +#ifdef USE_GLOBAL_LLVM_CONTEXT + llvmpipe->context = LLVMGetGlobalContext(); +#else + llvmpipe->context = LLVMContextCreate(); +#endif + + if (!llvmpipe->context) + goto fail; /* * Create drawing context and plug our rendering stage into it. */ - llvmpipe->draw = draw_create_gallivm(&llvmpipe->pipe, llvmpipe->gallivm); + llvmpipe->draw = draw_create_with_llvm_context(&llvmpipe->pipe, + llvmpipe->context); if (!llvmpipe->draw) goto fail; /* FIXME: devise alternative to draw_texture_samplers */ - if (debug_get_option_lp_no_rast()) - llvmpipe->no_rast = TRUE; - llvmpipe->setup = lp_setup_create( &llvmpipe->pipe, llvmpipe->draw ); if (!llvmpipe->setup) goto fail; + llvmpipe->pipe.stream_uploader = u_upload_create_default(&llvmpipe->pipe); + if (!llvmpipe->pipe.stream_uploader) + goto fail; + llvmpipe->pipe.const_uploader = llvmpipe->pipe.stream_uploader; + + llvmpipe->blitter = util_blitter_create(&llvmpipe->pipe); + if (!llvmpipe->blitter) { + goto fail; + } + + /* must be done before installing Draw stages */ + util_blitter_cache_all_shaders(llvmpipe->blitter); + /* plug in AA line/point stages */ draw_install_aaline_stage(llvmpipe->draw, &llvmpipe->pipe); draw_install_aapoint_stage(llvmpipe->draw, &llvmpipe->pipe); @@ -217,15 +225,13 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv ) draw_wide_point_threshold(llvmpipe->draw, 10000.0); draw_wide_line_threshold(llvmpipe->draw, 10000.0); -#if USE_DRAW_STAGE_PSTIPPLE - /* Do polygon stipple w/ texture map + frag prog? */ - draw_install_pstipple_stage(llvmpipe->draw, &llvmpipe->pipe); -#endif - lp_reset_counters(); - gallivm_register_garbage_collector_callback(garbage_collect_callback, - llvmpipe); + /* If llvmpipe_set_scissor_states() is never called, we still need to + * make sure that derived scissor state is computed. + * See https://bugs.freedesktop.org/show_bug.cgi?id=101709 + */ + llvmpipe->dirty |= LP_NEW_SCISSOR; return &llvmpipe->pipe;