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
00033 #include "brw_context.h"
00034 #include "brw_state.h"
00035
00036 #include "util/u_memory.h"
00037
00038
00039
00040
00041
00042
00043
00044 const struct brw_tracked_state *atoms[] =
00045 {
00046 &brw_vs_prog,
00047 &brw_gs_prog,
00048 &brw_clip_prog,
00049 &brw_sf_prog,
00050 &brw_wm_prog,
00051
00052
00053
00054
00055
00056 &brw_curbe_offsets,
00057 &brw_recalculate_urb_fence,
00058
00059
00060 &brw_cc_vp,
00061 &brw_cc_unit,
00062
00063 &brw_wm_surfaces,
00064 &brw_wm_samplers,
00065
00066 &brw_wm_unit,
00067 &brw_sf_vp,
00068 &brw_sf_unit,
00069 &brw_vs_unit,
00070 &brw_clip_unit,
00071 &brw_gs_unit,
00072
00073
00074
00075 &brw_invarient_state,
00076 &brw_state_base_address,
00077 &brw_pipe_control,
00078
00079 &brw_binding_table_pointers,
00080 &brw_blend_constant_color,
00081
00082 &brw_drawing_rect,
00083 &brw_depthbuffer,
00084
00085 &brw_polygon_stipple,
00086 &brw_line_stipple,
00087
00088 &brw_psp_urb_cbs,
00089
00090 &brw_constant_buffer
00091 };
00092
00093
00094 void brw_init_state( struct brw_context *brw )
00095 {
00096 brw_init_pools(brw);
00097 brw_init_caches(brw);
00098
00099 brw->state.dirty.brw = ~0;
00100 brw->emit_state_always = 0;
00101 }
00102
00103
00104 void brw_destroy_state( struct brw_context *brw )
00105 {
00106 brw_destroy_caches(brw);
00107 brw_destroy_batch_cache(brw);
00108 brw_destroy_pools(brw);
00109 }
00110
00111
00112
00113
00114 static boolean check_state( const struct brw_state_flags *a,
00115 const struct brw_state_flags *b )
00116 {
00117 return ((a->brw & b->brw) ||
00118 (a->cache & b->cache));
00119 }
00120
00121 static void accumulate_state( struct brw_state_flags *a,
00122 const struct brw_state_flags *b )
00123 {
00124 a->brw |= b->brw;
00125 a->cache |= b->cache;
00126 }
00127
00128
00129 static void xor_states( struct brw_state_flags *result,
00130 const struct brw_state_flags *a,
00131 const struct brw_state_flags *b )
00132 {
00133 result->brw = a->brw ^ b->brw;
00134 result->cache = a->cache ^ b->cache;
00135 }
00136
00137
00138
00139
00140
00141 void brw_validate_state( struct brw_context *brw )
00142 {
00143 struct brw_state_flags *state = &brw->state.dirty;
00144 unsigned i;
00145
00146 if (brw->emit_state_always)
00147 state->brw |= ~0;
00148
00149 if (state->cache == 0 &&
00150 state->brw == 0)
00151 return;
00152
00153 if (brw->state.dirty.brw & BRW_NEW_SCENE)
00154 brw_clear_batch_cache_flush(brw);
00155
00156 if (BRW_DEBUG) {
00157
00158
00159
00160
00161 struct brw_state_flags examined, prev;
00162 memset(&examined, 0, sizeof(examined));
00163 prev = *state;
00164
00165 for (i = 0; i < Elements(atoms); i++) {
00166 const struct brw_tracked_state *atom = atoms[i];
00167 struct brw_state_flags generated;
00168
00169 assert(atom->dirty.brw ||
00170 atom->dirty.cache);
00171 assert(atom->update);
00172
00173 if (check_state(state, &atom->dirty)) {
00174 atom->update( brw );
00175 }
00176
00177 accumulate_state(&examined, &atom->dirty);
00178
00179
00180
00181
00182
00183 xor_states(&generated, &prev, state);
00184 assert(!check_state(&examined, &generated));
00185 prev = *state;
00186 }
00187 }
00188 else {
00189 for (i = 0; i < Elements(atoms); i++) {
00190 const struct brw_tracked_state *atom = atoms[i];
00191
00192 assert(atom->dirty.brw ||
00193 atom->dirty.cache);
00194 assert(atom->update);
00195
00196 if (check_state(state, &atom->dirty))
00197 atom->update( brw );
00198 }
00199 }
00200
00201 memset(state, 0, sizeof(*state));
00202 }