00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "brw_state.h"
00033 #include "brw_winsys.h"
00034
00035 #include "util/u_memory.h"
00036
00037
00038
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
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 }