brw_state_batch.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 
00032 #include "brw_state.h"
00033 #include "brw_winsys.h"
00034 
00035 #include "util/u_memory.h"
00036 
00037 /* A facility similar to the data caching code above, which aims to
00038  * prevent identical commands being issued repeatedly.
00039  */
00040 boolean brw_cached_batch_struct( struct brw_context *brw,
00041                                  const void *data,
00042                                  unsigned sz )
00043 {
00044    struct brw_cached_batch_item *item = brw->cached_batch_items;
00045    struct header *newheader = (struct header *)data;
00046 
00047    if (brw->emit_state_always) {
00048       brw_batchbuffer_data(brw->winsys, data, sz);
00049       return TRUE;
00050    }
00051 
00052    while (item) {
00053       if (item->header->opcode == newheader->opcode) {
00054          if (item->sz == sz && memcmp(item->header, newheader, sz) == 0)
00055             return FALSE;
00056          if (item->sz != sz) {
00057             FREE(item->header);
00058             item->header = MALLOC(sz);
00059             item->sz = sz;
00060          }
00061          goto emit;
00062       }
00063       item = item->next;
00064    }
00065 
00066    assert(!item);
00067    item = CALLOC_STRUCT(brw_cached_batch_item);
00068    item->header = MALLOC(sz);
00069    item->sz = sz;
00070    item->next = brw->cached_batch_items;
00071    brw->cached_batch_items = item;
00072 
00073 emit:
00074    memcpy(item->header, newheader, sz);
00075    brw_batchbuffer_data(brw->winsys, data, sz);
00076    return TRUE;
00077 }
00078 
00079 static void clear_batch_cache( struct brw_context *brw )
00080 {
00081    struct brw_cached_batch_item *item = brw->cached_batch_items;
00082 
00083    while (item) {
00084       struct brw_cached_batch_item *next = item->next;
00085       free((void *)item->header);
00086       free(item);
00087       item = next;
00088    }
00089 
00090    brw->cached_batch_items = NULL;
00091 
00092 
00093    brw_clear_all_caches(brw);
00094 
00095    brw_invalidate_pools(brw);
00096 }
00097 
00098 void brw_clear_batch_cache_flush( struct brw_context *brw )
00099 {
00100    clear_batch_cache(brw);
00101 
00102 /*    brw_do_flush(brw, BRW_FLUSH_STATE_CACHE|BRW_FLUSH_READ_CACHE); */
00103 
00104    brw->state.dirty.brw |= ~0;
00105    brw->state.dirty.cache |= ~0;
00106 }
00107 
00108 
00109 
00110 void brw_destroy_batch_cache( struct brw_context *brw )
00111 {
00112    clear_batch_cache(brw);
00113 }

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