brw_state_pool.c

Go to the documentation of this file.
00001 /*
00002  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
00003  Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
00004  develop this 3D driver.
00005 
00006  Permission is hereby granted, free of charge, to any person obtaining
00007  a 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, sublicense, 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
00016  portions of the Software.
00017 
00018  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00021  IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
00022  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00023  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00024  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025 
00026  **********************************************************************/
00027  /*
00028   * Authors:
00029   *   Keith Whitwell <keith@tungstengraphics.com>
00030   */
00031 
00045 #include "pipe/p_winsys.h"
00046 #include "util/u_math.h"
00047 #include "util/u_memory.h"
00048 #include "pipe/p_inlines.h"
00049 #include "brw_context.h"
00050 #include "brw_state.h"
00051 
00052 boolean brw_pool_alloc( struct brw_mem_pool *pool,
00053                           unsigned size,
00054                           unsigned alignment,
00055                           unsigned *offset_return)
00056 {
00057    unsigned fixup = align(pool->offset, alignment) - pool->offset;
00058 
00059    size = align(size, 4);
00060 
00061    if (pool->offset + fixup + size >= pool->size) {
00062       debug_printf("%s failed\n", __FUNCTION__);
00063       assert(0);
00064       exit(0);
00065    }
00066 
00067    pool->offset += fixup;
00068    *offset_return = pool->offset;
00069    pool->offset += size;
00070 
00071    return TRUE;
00072 }
00073 
00074 static
00075 void brw_invalidate_pool( struct brw_mem_pool *pool )
00076 {
00077    if (BRW_DEBUG & DEBUG_STATE)
00078       debug_printf("\n\n\n %s \n\n\n", __FUNCTION__);
00079 
00080    pool->offset = 0;
00081 
00082    brw_clear_all_caches(pool->brw);
00083 }
00084 
00085 
00086 static void brw_init_pool( struct brw_context *brw,
00087                            unsigned pool_id,
00088                            unsigned size )
00089 {
00090    struct brw_mem_pool *pool = &brw->pool[pool_id];
00091 
00092    pool->size = size;
00093    pool->brw = brw;
00094 
00095    pool->buffer = pipe_buffer_create(brw->pipe.screen,
00096                                      4096,
00097                                      0 /*  DRM_BO_FLAG_MEM_TT */,
00098                                      size);
00099 }
00100 
00101 static void brw_destroy_pool( struct brw_context *brw,
00102                               unsigned pool_id )
00103 {
00104    struct brw_mem_pool *pool = &brw->pool[pool_id];
00105 
00106    pipe_buffer_reference( pool->brw->pipe.screen,
00107                           &pool->buffer,
00108                           NULL );
00109 }
00110 
00111 
00112 void brw_pool_check_wrap( struct brw_context *brw,
00113                           struct brw_mem_pool *pool )
00114 {
00115    if (pool->offset > (pool->size * 3) / 4) {
00116       brw->state.dirty.brw |= BRW_NEW_SCENE;
00117    }
00118 
00119 }
00120 
00121 void brw_init_pools( struct brw_context *brw )
00122 {
00123    brw_init_pool(brw, BRW_GS_POOL, 0x80000);
00124    brw_init_pool(brw, BRW_SS_POOL, 0x80000);
00125 }
00126 
00127 void brw_destroy_pools( struct brw_context *brw )
00128 {
00129    brw_destroy_pool(brw, BRW_GS_POOL);
00130    brw_destroy_pool(brw, BRW_SS_POOL);
00131 }
00132 
00133 
00134 void brw_invalidate_pools( struct brw_context *brw )
00135 {
00136    brw_invalidate_pool(&brw->pool[BRW_GS_POOL]);
00137    brw_invalidate_pool(&brw->pool[BRW_SS_POOL]);
00138 }

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