sp_context.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 /* Author:
00029  *    Keith Whitwell <keith@tungstengraphics.com>
00030  */
00031 
00032 #include "draw/draw_context.h"
00033 #include "pipe/p_defines.h"
00034 #include "pipe/p_inlines.h"
00035 #include "util/u_math.h"
00036 #include "util/u_memory.h"
00037 #include "sp_clear.h"
00038 #include "sp_context.h"
00039 #include "sp_flush.h"
00040 #include "sp_prim_setup.h"
00041 #include "sp_prim_vbuf.h"
00042 #include "sp_state.h"
00043 #include "sp_surface.h"
00044 #include "sp_tile_cache.h"
00045 #include "sp_texture.h"
00046 #include "sp_winsys.h"
00047 #include "sp_query.h"
00048 
00049 
00050 
00054 void
00055 softpipe_map_surfaces(struct softpipe_context *sp)
00056 {
00057    unsigned i;
00058 
00059    for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
00060       sp_tile_cache_map_surfaces(sp->cbuf_cache[i]);
00061    }
00062 
00063    sp_tile_cache_map_surfaces(sp->zsbuf_cache);
00064 }
00065 
00066 
00070 void
00071 softpipe_unmap_surfaces(struct softpipe_context *sp)
00072 {
00073    uint i;
00074 
00075    for (i = 0; i < sp->framebuffer.num_cbufs; i++)
00076       sp_flush_tile_cache(sp, sp->cbuf_cache[i]);
00077    sp_flush_tile_cache(sp, sp->zsbuf_cache);
00078 
00079    for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
00080       sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]);
00081    }
00082    sp_tile_cache_unmap_surfaces(sp->zsbuf_cache);
00083 }
00084 
00085 
00086 static void softpipe_destroy( struct pipe_context *pipe )
00087 {
00088    struct softpipe_context *softpipe = softpipe_context( pipe );
00089    struct pipe_winsys *ws = pipe->winsys;
00090    uint i;
00091 
00092    if (softpipe->draw)
00093       draw_destroy( softpipe->draw );
00094 
00095    for (i = 0; i < SP_NUM_QUAD_THREADS; i++) {
00096       softpipe->quad[i].polygon_stipple->destroy( softpipe->quad[i].polygon_stipple );
00097       softpipe->quad[i].earlyz->destroy( softpipe->quad[i].earlyz );
00098       softpipe->quad[i].shade->destroy( softpipe->quad[i].shade );
00099       softpipe->quad[i].alpha_test->destroy( softpipe->quad[i].alpha_test );
00100       softpipe->quad[i].depth_test->destroy( softpipe->quad[i].depth_test );
00101       softpipe->quad[i].stencil_test->destroy( softpipe->quad[i].stencil_test );
00102       softpipe->quad[i].occlusion->destroy( softpipe->quad[i].occlusion );
00103       softpipe->quad[i].coverage->destroy( softpipe->quad[i].coverage );
00104       softpipe->quad[i].blend->destroy( softpipe->quad[i].blend );
00105       softpipe->quad[i].colormask->destroy( softpipe->quad[i].colormask );
00106       softpipe->quad[i].output->destroy( softpipe->quad[i].output );
00107    }
00108 
00109    for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
00110       sp_destroy_tile_cache(softpipe->cbuf_cache[i]);
00111    sp_destroy_tile_cache(softpipe->zsbuf_cache);
00112 
00113    for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
00114       sp_destroy_tile_cache(softpipe->tex_cache[i]);
00115 
00116    for (i = 0; i < Elements(softpipe->constants); i++) {
00117       if (softpipe->constants[i].buffer) {
00118          winsys_buffer_reference(ws, &softpipe->constants[i].buffer, NULL);
00119       }
00120    }
00121 
00122    FREE( softpipe );
00123 }
00124 
00125 
00126 struct pipe_context *
00127 softpipe_create( struct pipe_screen *screen,
00128                  struct pipe_winsys *pipe_winsys,
00129                  void *unused )
00130 {
00131    struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
00132    uint i;
00133 
00134    util_init_math();
00135 
00136 #ifdef PIPE_ARCH_X86
00137    softpipe->use_sse = !debug_get_bool_option( "GALLIUM_NOSSE", FALSE );
00138 #else
00139    softpipe->use_sse = FALSE;
00140 #endif
00141 
00142    softpipe->dump_fs = debug_get_bool_option( "GALLIUM_DUMP_FS", FALSE );
00143 
00144    softpipe->pipe.winsys = pipe_winsys;
00145    softpipe->pipe.screen = screen;
00146    softpipe->pipe.destroy = softpipe_destroy;
00147 
00148    /* state setters */
00149    softpipe->pipe.create_blend_state = softpipe_create_blend_state;
00150    softpipe->pipe.bind_blend_state   = softpipe_bind_blend_state;
00151    softpipe->pipe.delete_blend_state = softpipe_delete_blend_state;
00152 
00153    softpipe->pipe.create_sampler_state = softpipe_create_sampler_state;
00154    softpipe->pipe.bind_sampler_states  = softpipe_bind_sampler_states;
00155    softpipe->pipe.delete_sampler_state = softpipe_delete_sampler_state;
00156 
00157    softpipe->pipe.create_depth_stencil_alpha_state = softpipe_create_depth_stencil_state;
00158    softpipe->pipe.bind_depth_stencil_alpha_state   = softpipe_bind_depth_stencil_state;
00159    softpipe->pipe.delete_depth_stencil_alpha_state = softpipe_delete_depth_stencil_state;
00160 
00161    softpipe->pipe.create_rasterizer_state = softpipe_create_rasterizer_state;
00162    softpipe->pipe.bind_rasterizer_state   = softpipe_bind_rasterizer_state;
00163    softpipe->pipe.delete_rasterizer_state = softpipe_delete_rasterizer_state;
00164 
00165    softpipe->pipe.create_fs_state = softpipe_create_fs_state;
00166    softpipe->pipe.bind_fs_state   = softpipe_bind_fs_state;
00167    softpipe->pipe.delete_fs_state = softpipe_delete_fs_state;
00168 
00169    softpipe->pipe.create_vs_state = softpipe_create_vs_state;
00170    softpipe->pipe.bind_vs_state   = softpipe_bind_vs_state;
00171    softpipe->pipe.delete_vs_state = softpipe_delete_vs_state;
00172 
00173    softpipe->pipe.set_blend_color = softpipe_set_blend_color;
00174    softpipe->pipe.set_clip_state = softpipe_set_clip_state;
00175    softpipe->pipe.set_constant_buffer = softpipe_set_constant_buffer;
00176    softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;
00177    softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
00178    softpipe->pipe.set_scissor_state = softpipe_set_scissor_state;
00179    softpipe->pipe.set_sampler_textures = softpipe_set_sampler_textures;
00180    softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;
00181 
00182    softpipe->pipe.set_vertex_buffers = softpipe_set_vertex_buffers;
00183    softpipe->pipe.set_vertex_elements = softpipe_set_vertex_elements;
00184 
00185    softpipe->pipe.draw_arrays = softpipe_draw_arrays;
00186    softpipe->pipe.draw_elements = softpipe_draw_elements;
00187    softpipe->pipe.draw_range_elements = softpipe_draw_range_elements;
00188    softpipe->pipe.set_edgeflags = softpipe_set_edgeflags;
00189 
00190 
00191    softpipe->pipe.clear = softpipe_clear;
00192    softpipe->pipe.flush = softpipe_flush;
00193 
00194    softpipe_init_query_funcs( softpipe );
00195    softpipe_init_texture_funcs( softpipe );
00196 
00197    /*
00198     * Alloc caches for accessing drawing surfaces and textures.
00199     * Must be before quad stage setup!
00200     */
00201    for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
00202       softpipe->cbuf_cache[i] = sp_create_tile_cache( screen );
00203    softpipe->zsbuf_cache = sp_create_tile_cache( screen );
00204 
00205    for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
00206       softpipe->tex_cache[i] = sp_create_tile_cache( screen );
00207 
00208 
00209    /* setup quad rendering stages */
00210    for (i = 0; i < SP_NUM_QUAD_THREADS; i++) {
00211       softpipe->quad[i].polygon_stipple = sp_quad_polygon_stipple_stage(softpipe);
00212       softpipe->quad[i].earlyz = sp_quad_earlyz_stage(softpipe);
00213       softpipe->quad[i].shade = sp_quad_shade_stage(softpipe);
00214       softpipe->quad[i].alpha_test = sp_quad_alpha_test_stage(softpipe);
00215       softpipe->quad[i].depth_test = sp_quad_depth_test_stage(softpipe);
00216       softpipe->quad[i].stencil_test = sp_quad_stencil_test_stage(softpipe);
00217       softpipe->quad[i].occlusion = sp_quad_occlusion_stage(softpipe);
00218       softpipe->quad[i].coverage = sp_quad_coverage_stage(softpipe);
00219       softpipe->quad[i].blend = sp_quad_blend_stage(softpipe);
00220       softpipe->quad[i].colormask = sp_quad_colormask_stage(softpipe);
00221       softpipe->quad[i].output = sp_quad_output_stage(softpipe);
00222    }
00223 
00224    /*
00225     * Create drawing context and plug our rendering stage into it.
00226     */
00227    softpipe->draw = draw_create();
00228    if (!softpipe->draw) 
00229       goto fail;
00230 
00231    softpipe->setup = sp_draw_render_stage(softpipe);
00232    if (!softpipe->setup)
00233       goto fail;
00234 
00235    if (debug_get_bool_option( "SP_NO_RAST", FALSE ))
00236       softpipe->no_rast = TRUE;
00237 
00238    if (debug_get_bool_option( "SP_NO_VBUF", FALSE )) {
00239       /* Deprecated path -- vbuf is the intended interface to the draw module:
00240        */
00241       draw_set_rasterize_stage(softpipe->draw, softpipe->setup);
00242    }
00243    else {
00244       sp_init_vbuf(softpipe);
00245    }
00246 
00247    /* plug in AA line/point stages */
00248    draw_install_aaline_stage(softpipe->draw, &softpipe->pipe);
00249    draw_install_aapoint_stage(softpipe->draw, &softpipe->pipe);
00250 
00251 #if USE_DRAW_STAGE_PSTIPPLE
00252    /* Do polygon stipple w/ texture map + frag prog? */
00253    draw_install_pstipple_stage(softpipe->draw, &softpipe->pipe);
00254 #endif
00255 
00256    sp_init_surface_functions(softpipe);
00257 
00258    return &softpipe->pipe;
00259 
00260  fail:
00261    softpipe_destroy(&softpipe->pipe);
00262    return NULL;
00263 }
00264 

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4