Merge remote-tracking branch 'origin/master' into pipe-video
[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_vs.h"
47 #include "brw_wm.h"
48
49 static void
50 dri_bo_release(drm_intel_bo **bo)
51 {
52 drm_intel_bo_unreference(*bo);
53 *bo = NULL;
54 }
55
56
57 /**
58 * called from intelDestroyContext()
59 */
60 static void brw_destroy_context( struct intel_context *intel )
61 {
62 struct brw_context *brw = brw_context(&intel->ctx);
63
64 brw_destroy_state(brw);
65 brw_draw_destroy( brw );
66 brw_clear_validated_bos(brw);
67 if (brw->wm.compile_data) {
68 free(brw->wm.compile_data->instruction);
69 free(brw->wm.compile_data->vreg);
70 free(brw->wm.compile_data->refs);
71 free(brw->wm.compile_data->prog_instructions);
72 free(brw->wm.compile_data);
73 }
74
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.const_bo);
80 dri_bo_release(&brw->gs.prog_bo);
81 dri_bo_release(&brw->clip.prog_bo);
82 dri_bo_release(&brw->sf.prog_bo);
83 dri_bo_release(&brw->wm.prog_bo);
84 dri_bo_release(&brw->wm.const_bo);
85 dri_bo_release(&brw->cc.prog_bo);
86
87 free(brw->curbe.last_buf);
88 free(brw->curbe.next_buf);
89 }
90
91
92 /**
93 * called from intelDrawBuffer()
94 */
95 static void brw_set_draw_region( struct intel_context *intel,
96 struct intel_region *color_regions[],
97 struct intel_region *depth_region,
98 GLuint num_color_regions)
99 {
100 struct brw_context *brw = brw_context(&intel->ctx);
101
102 if (brw->state.depth_region != depth_region) {
103 brw->state.dirty.brw |= BRW_NEW_DEPTH_BUFFER;
104 intel_region_release(&brw->state.depth_region);
105 intel_region_reference(&brw->state.depth_region, depth_region);
106 }
107 }
108
109
110 /**
111 * called from intel_batchbuffer_flush and children before sending a
112 * batchbuffer off.
113 */
114 static void brw_finish_batch(struct intel_context *intel)
115 {
116 struct brw_context *brw = brw_context(&intel->ctx);
117 brw_emit_query_end(brw);
118
119 if (brw->curbe.curbe_bo) {
120 drm_intel_gem_bo_unmap_gtt(brw->curbe.curbe_bo);
121 drm_intel_bo_unreference(brw->curbe.curbe_bo);
122 brw->curbe.curbe_bo = NULL;
123 }
124 }
125
126
127 /**
128 * called from intelFlushBatchLocked
129 */
130 static void brw_new_batch( struct intel_context *intel )
131 {
132 struct brw_context *brw = brw_context(&intel->ctx);
133
134 /* Mark all context state as needing to be re-emitted.
135 * This is probably not as severe as on 915, since almost all of our state
136 * is just in referenced buffers.
137 */
138 brw->state.dirty.brw |= BRW_NEW_CONTEXT;
139
140 brw->state.dirty.mesa |= ~0;
141 brw->state.dirty.brw |= ~0;
142 brw->state.dirty.cache |= ~0;
143
144 brw->vb.nr_current_buffers = 0;
145 }
146
147 static void brw_invalidate_state( struct intel_context *intel, GLuint new_state )
148 {
149 /* nothing */
150 }
151
152
153 void brwInitVtbl( struct brw_context *brw )
154 {
155 brw->intel.vtbl.check_vertex_size = 0;
156 brw->intel.vtbl.emit_state = 0;
157 brw->intel.vtbl.reduced_primitive_state = 0;
158 brw->intel.vtbl.render_start = 0;
159 brw->intel.vtbl.update_texture_state = 0;
160
161 brw->intel.vtbl.invalidate_state = brw_invalidate_state;
162 brw->intel.vtbl.new_batch = brw_new_batch;
163 brw->intel.vtbl.finish_batch = brw_finish_batch;
164 brw->intel.vtbl.destroy = brw_destroy_context;
165 brw->intel.vtbl.set_draw_region = brw_set_draw_region;
166 brw->intel.vtbl.debug_batch = brw_debug_batch;
167 brw->intel.vtbl.render_target_supported = brw_render_target_supported;
168 }