2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "brw_context.h"
34 #include "brw_state.h"
36 #include "pipe/p_util.h"
38 /* This is used to initialize brw->state.atoms[]. We could use this
39 * list directly except for a single atom, brw_constant_buffer, which
40 * has a .dirty value which changes according to the parameters of the
41 * current fragment and vertex programs, and so cannot be a static
44 const struct brw_tracked_state
*atoms
[] =
52 /* Once all the programs are done, we know how large urb entry
53 * sizes need to be and can decide if we need to change the urb
57 &brw_recalculate_urb_fence
,
63 &brw_wm_surfaces
, /* must do before samplers */
69 &brw_vs_unit
, /* always required, enabled or not */
76 &brw_state_base_address
,
79 &brw_binding_table_pointers
,
80 &brw_blend_constant_color
,
94 void brw_init_state( struct brw_context
*brw
)
99 brw
->state
.dirty
.brw
= ~0;
100 brw
->emit_state_always
= 0;
104 void brw_destroy_state( struct brw_context
*brw
)
106 brw_destroy_caches(brw
);
107 brw_destroy_batch_cache(brw
);
108 brw_destroy_pools(brw
);
111 /***********************************************************************
114 static boolean
check_state( const struct brw_state_flags
*a
,
115 const struct brw_state_flags
*b
)
117 return ((a
->brw
& b
->brw
) ||
118 (a
->cache
& b
->cache
));
121 static void accumulate_state( struct brw_state_flags
*a
,
122 const struct brw_state_flags
*b
)
125 a
->cache
|= b
->cache
;
129 static void xor_states( struct brw_state_flags
*result
,
130 const struct brw_state_flags
*a
,
131 const struct brw_state_flags
*b
)
133 result
->brw
= a
->brw
^ b
->brw
;
134 result
->cache
= a
->cache
^ b
->cache
;
138 /***********************************************************************
141 void brw_validate_state( struct brw_context
*brw
)
143 struct brw_state_flags
*state
= &brw
->state
.dirty
;
146 if (brw
->emit_state_always
)
149 if (state
->cache
== 0 &&
153 if (brw
->state
.dirty
.brw
& BRW_NEW_SCENE
)
154 brw_clear_batch_cache_flush(brw
);
157 /* Debug version which enforces various sanity checks on the
158 * state flags which are generated and checked to help ensure
159 * state atoms are ordered correctly in the list.
161 struct brw_state_flags examined
, prev
;
162 memset(&examined
, 0, sizeof(examined
));
165 for (i
= 0; i
< Elements(atoms
); i
++) {
166 const struct brw_tracked_state
*atom
= atoms
[i
];
167 struct brw_state_flags generated
;
169 assert(atom
->dirty
.brw
||
171 assert(atom
->update
);
173 if (check_state(state
, &atom
->dirty
)) {
177 accumulate_state(&examined
, &atom
->dirty
);
179 /* generated = (prev ^ state)
180 * if (examined & generated)
183 xor_states(&generated
, &prev
, state
);
184 assert(!check_state(&examined
, &generated
));
189 for (i
= 0; i
< Elements(atoms
); i
++) {
190 const struct brw_tracked_state
*atom
= atoms
[i
];
192 assert(atom
->dirty
.brw
||
194 assert(atom
->update
);
196 if (check_state(state
, &atom
->dirty
))
201 memset(state
, 0, sizeof(*state
));