Merge branch 'mesa_7_6_branch'
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vtbl.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
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:
13
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.
17
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.
25
26 **********************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33 #include "main/glheader.h"
34 #include "main/mtypes.h"
35 #include "main/imports.h"
36 #include "main/macros.h"
37 #include "main/colormac.h"
38
39 #include "intel_batchbuffer.h"
40 #include "intel_regions.h"
41
42 #include "brw_context.h"
43 #include "brw_defines.h"
44 #include "brw_state.h"
45 #include "brw_draw.h"
46 #include "brw_state.h"
47 #include "brw_fallback.h"
48 #include "brw_vs.h"
49
50
51 static void
52 dri_bo_release(dri_bo **bo)
53 {
54 dri_bo_unreference(*bo);
55 *bo = NULL;
56 }
57
58
59 /**
60 * called from intelDestroyContext()
61 */
62 static void brw_destroy_context( struct intel_context *intel )
63 {
64 struct brw_context *brw = brw_context(&intel->ctx);
65 int i;
66
67 brw_destroy_state(brw);
68 brw_draw_destroy( brw );
69
70 _mesa_free(brw->wm.compile_data);
71
72 for (i = 0; i < brw->state.nr_color_regions; i++)
73 intel_region_release(&brw->state.color_regions[i]);
74 brw->state.nr_color_regions = 0;
75 intel_region_release(&brw->state.depth_region);
76
77 dri_bo_release(&brw->curbe.curbe_bo);
78 dri_bo_release(&brw->vs.prog_bo);
79 dri_bo_release(&brw->vs.state_bo);
80 dri_bo_release(&brw->vs.bind_bo);
81 dri_bo_release(&brw->gs.prog_bo);
82 dri_bo_release(&brw->gs.state_bo);
83 dri_bo_release(&brw->clip.prog_bo);
84 dri_bo_release(&brw->clip.state_bo);
85 dri_bo_release(&brw->clip.vp_bo);
86 dri_bo_release(&brw->sf.prog_bo);
87 dri_bo_release(&brw->sf.state_bo);
88 dri_bo_release(&brw->sf.vp_bo);
89 for (i = 0; i < BRW_MAX_TEX_UNIT; i++)
90 dri_bo_release(&brw->wm.sdc_bo[i]);
91 dri_bo_release(&brw->wm.bind_bo);
92 for (i = 0; i < BRW_WM_MAX_SURF; i++)
93 dri_bo_release(&brw->wm.surf_bo[i]);
94 dri_bo_release(&brw->wm.sampler_bo);
95 dri_bo_release(&brw->wm.prog_bo);
96 dri_bo_release(&brw->wm.state_bo);
97 dri_bo_release(&brw->cc.prog_bo);
98 dri_bo_release(&brw->cc.state_bo);
99 dri_bo_release(&brw->cc.vp_bo);
100 }
101
102
103 /**
104 * called from intelDrawBuffer()
105 */
106 static void brw_set_draw_region( struct intel_context *intel,
107 struct intel_region *color_regions[],
108 struct intel_region *depth_region,
109 GLuint num_color_regions)
110 {
111 struct brw_context *brw = brw_context(&intel->ctx);
112 GLuint i;
113
114 /* release old color/depth regions */
115 if (brw->state.depth_region != depth_region)
116 brw->state.dirty.brw |= BRW_NEW_DEPTH_BUFFER;
117 for (i = 0; i < brw->state.nr_color_regions; i++)
118 intel_region_release(&brw->state.color_regions[i]);
119 intel_region_release(&brw->state.depth_region);
120
121 /* reference new color/depth regions */
122 for (i = 0; i < num_color_regions; i++)
123 intel_region_reference(&brw->state.color_regions[i], color_regions[i]);
124 intel_region_reference(&brw->state.depth_region, depth_region);
125 brw->state.nr_color_regions = num_color_regions;
126 }
127
128
129 /**
130 * called from intel_batchbuffer_flush and children before sending a
131 * batchbuffer off.
132 */
133 static void brw_finish_batch(struct intel_context *intel)
134 {
135 struct brw_context *brw = brw_context(&intel->ctx);
136 brw_emit_query_end(brw);
137 }
138
139
140 /**
141 * called from intelFlushBatchLocked
142 */
143 static void brw_new_batch( struct intel_context *intel )
144 {
145 struct brw_context *brw = brw_context(&intel->ctx);
146
147 /* Check that we didn't just wrap our batchbuffer at a bad time. */
148 assert(!brw->no_batch_wrap);
149
150 brw->curbe.need_new_bo = GL_TRUE;
151
152 /* Mark all context state as needing to be re-emitted.
153 * This is probably not as severe as on 915, since almost all of our state
154 * is just in referenced buffers.
155 */
156 brw->state.dirty.brw |= BRW_NEW_CONTEXT;
157
158 brw->state.dirty.mesa |= ~0;
159 brw->state.dirty.brw |= ~0;
160 brw->state.dirty.cache |= ~0;
161
162 /* Move to the end of the current upload buffer so that we'll force choosing
163 * a new buffer next time.
164 */
165 if (brw->vb.upload.bo != NULL) {
166 dri_bo_unreference(brw->vb.upload.bo);
167 brw->vb.upload.bo = NULL;
168 brw->vb.upload.offset = 0;
169 }
170 }
171
172
173 static void brw_note_fence( struct intel_context *intel, GLuint fence )
174 {
175 brw_context(&intel->ctx)->state.dirty.brw |= BRW_NEW_FENCE;
176 }
177
178 /* called from intelWaitForIdle() and intelFlush()
179 *
180 * For now, just flush everything. Could be smarter later.
181 */
182 static GLuint brw_flush_cmd( void )
183 {
184 struct brw_mi_flush flush;
185 flush.opcode = CMD_MI_FLUSH;
186 flush.pad = 0;
187 flush.flags = BRW_FLUSH_STATE_CACHE;
188 return *(GLuint *)&flush;
189 }
190
191
192 static void brw_invalidate_state( struct intel_context *intel, GLuint new_state )
193 {
194 /* nothing */
195 }
196
197
198 void brwInitVtbl( struct brw_context *brw )
199 {
200 brw->intel.vtbl.check_vertex_size = 0;
201 brw->intel.vtbl.emit_state = 0;
202 brw->intel.vtbl.reduced_primitive_state = 0;
203 brw->intel.vtbl.render_start = 0;
204 brw->intel.vtbl.update_texture_state = 0;
205
206 brw->intel.vtbl.invalidate_state = brw_invalidate_state;
207 brw->intel.vtbl.note_fence = brw_note_fence;
208 brw->intel.vtbl.new_batch = brw_new_batch;
209 brw->intel.vtbl.finish_batch = brw_finish_batch;
210 brw->intel.vtbl.destroy = brw_destroy_context;
211 brw->intel.vtbl.set_draw_region = brw_set_draw_region;
212 brw->intel.vtbl.flush_cmd = brw_flush_cmd;
213 brw->intel.vtbl.debug_batch = brw_debug_batch;
214 }