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