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>
41 #include "intel_batchbuffer.h"
42 #include "intel_regions.h"
44 #include "brw_context.h"
45 #include "brw_defines.h"
46 #include "brw_state.h"
49 #include "brw_state.h"
50 #include "brw_fallback.h"
55 /* called from intelDestroyContext()
57 static void brw_destroy_context( struct intel_context
*intel
)
59 GLcontext
*ctx
= &intel
->ctx
;
60 struct brw_context
*brw
= brw_context(&intel
->ctx
);
62 brw_destroy_metaops(brw
);
63 brw_destroy_state(brw
);
64 brw_draw_destroy( brw
);
66 brw_ProgramCacheDestroy( ctx
);
67 brw_FrameBufferTexDestroy( brw
);
70 /* called from intelDrawBuffer()
72 static void brw_set_draw_region( struct intel_context
*intel
,
73 struct intel_region
*draw_region
,
74 struct intel_region
*depth_region
)
76 struct brw_context
*brw
= brw_context(&intel
->ctx
);
78 intel_region_release(intel
, &brw
->state
.draw_region
);
79 intel_region_release(intel
, &brw
->state
.depth_region
);
80 intel_region_reference(&brw
->state
.draw_region
, draw_region
);
81 intel_region_reference(&brw
->state
.depth_region
, depth_region
);
85 /* called from intelFlushBatchLocked
87 static void brw_lost_hardware( struct intel_context
*intel
)
89 struct brw_context
*brw
= brw_context(&intel
->ctx
);
91 /* Note that we effectively lose the context after this.
93 * Setting this flag provokes a state buffer wrap and also flushes
94 * the hardware caches.
96 brw
->state
.dirty
.brw
|= BRW_NEW_CONTEXT
;
98 /* Which means there shouldn't be any commands already queued:
100 assert(intel
->batch
->ptr
== intel
->batch
->map
);
102 brw
->state
.dirty
.mesa
|= ~0;
103 brw
->state
.dirty
.brw
|= ~0;
104 brw
->state
.dirty
.cache
|= ~0;
107 static void brw_note_fence( struct intel_context
*intel
,
110 brw_context(&intel
->ctx
)->state
.dirty
.brw
|= BRW_NEW_FENCE
;
113 static void brw_note_unlock( struct intel_context
*intel
)
115 struct brw_context
*brw
= brw_context(&intel
->ctx
);
117 brw_pool_check_wrap(brw
, &brw
->pool
[BRW_GS_POOL
]);
118 brw_pool_check_wrap(brw
, &brw
->pool
[BRW_SS_POOL
]);
120 brw_context(&intel
->ctx
)->state
.dirty
.brw
|= BRW_NEW_LOCK
;
124 void brw_do_flush( struct brw_context
*brw
,
127 struct brw_mi_flush flush
;
128 memset(&flush
, 0, sizeof(flush
));
129 flush
.opcode
= CMD_MI_FLUSH
;
131 BRW_BATCH_STRUCT(brw
, &flush
);
135 static void brw_emit_flush( struct intel_context
*intel
,
138 brw_do_flush(brw_context(&intel
->ctx
),
139 BRW_FLUSH_STATE_CACHE
|BRW_FLUSH_READ_CACHE
);
143 /* called from intelWaitForIdle() and intelFlush()
145 * For now, just flush everything. Could be smarter later.
147 static GLuint
brw_flush_cmd( void )
149 struct brw_mi_flush flush
;
150 flush
.opcode
= CMD_MI_FLUSH
;
152 flush
.flags
= BRW_FLUSH_READ_CACHE
| BRW_FLUSH_STATE_CACHE
;
153 return *(GLuint
*)&flush
;
156 static void brw_invalidate_state( struct intel_context
*intel
, GLuint new_state
)
162 void brwInitVtbl( struct brw_context
*brw
)
164 brw
->intel
.vtbl
.check_vertex_size
= 0;
165 brw
->intel
.vtbl
.emit_state
= 0;
166 brw
->intel
.vtbl
.reduced_primitive_state
= 0;
167 brw
->intel
.vtbl
.render_start
= 0;
168 brw
->intel
.vtbl
.update_texture_state
= 0;
170 brw
->intel
.vtbl
.invalidate_state
= brw_invalidate_state
;
171 brw
->intel
.vtbl
.note_fence
= brw_note_fence
;
172 brw
->intel
.vtbl
.note_unlock
= brw_note_unlock
;
173 brw
->intel
.vtbl
.lost_hardware
= brw_lost_hardware
;
174 brw
->intel
.vtbl
.destroy
= brw_destroy_context
;
175 brw
->intel
.vtbl
.set_draw_region
= brw_set_draw_region
;
176 brw
->intel
.vtbl
.flush_cmd
= brw_flush_cmd
;
177 brw
->intel
.vtbl
.emit_flush
= brw_emit_flush
;
178 brw
->intel
.vtbl
.debug_batch
= brw_debug_batch
;