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 **********************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
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"
39 #include "intel_batchbuffer.h"
40 #include "intel_regions.h"
42 #include "brw_context.h"
43 #include "brw_defines.h"
44 #include "brw_state.h"
46 #include "brw_state.h"
51 dri_bo_release(drm_intel_bo
**bo
)
53 drm_intel_bo_unreference(*bo
);
59 * called from intelDestroyContext()
61 static void brw_destroy_context( struct intel_context
*intel
)
63 struct brw_context
*brw
= brw_context(&intel
->ctx
);
66 brw_destroy_state(brw
);
67 brw_draw_destroy( brw
);
68 brw_clear_validated_bos(brw
);
69 if (brw
->wm
.compile_data
) {
70 free(brw
->wm
.compile_data
->instruction
);
71 free(brw
->wm
.compile_data
->vreg
);
72 free(brw
->wm
.compile_data
->refs
);
73 free(brw
->wm
.compile_data
->prog_instructions
);
74 free(brw
->wm
.compile_data
);
77 for (i
= 0; i
< brw
->state
.nr_color_regions
; i
++)
78 intel_region_release(&brw
->state
.color_regions
[i
]);
79 brw
->state
.nr_color_regions
= 0;
80 intel_region_release(&brw
->state
.depth_region
);
82 dri_bo_release(&brw
->curbe
.curbe_bo
);
83 dri_bo_release(&brw
->vs
.prog_bo
);
84 dri_bo_release(&brw
->vs
.state_bo
);
85 dri_bo_release(&brw
->vs
.bind_bo
);
86 dri_bo_release(&brw
->vs
.const_bo
);
87 dri_bo_release(&brw
->gs
.prog_bo
);
88 dri_bo_release(&brw
->gs
.state_bo
);
89 dri_bo_release(&brw
->clip
.prog_bo
);
90 dri_bo_release(&brw
->clip
.state_bo
);
91 dri_bo_release(&brw
->clip
.vp_bo
);
92 dri_bo_release(&brw
->sf
.prog_bo
);
93 dri_bo_release(&brw
->sf
.state_bo
);
94 dri_bo_release(&brw
->sf
.vp_bo
);
95 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++)
96 dri_bo_release(&brw
->wm
.sdc_bo
[i
]);
97 dri_bo_release(&brw
->wm
.bind_bo
);
98 for (i
= 0; i
< BRW_WM_MAX_SURF
; i
++)
99 dri_bo_release(&brw
->wm
.surf_bo
[i
]);
100 dri_bo_release(&brw
->wm
.sampler_bo
);
101 dri_bo_release(&brw
->wm
.prog_bo
);
102 dri_bo_release(&brw
->wm
.state_bo
);
103 dri_bo_release(&brw
->wm
.const_bo
);
104 dri_bo_release(&brw
->wm
.push_const_bo
);
105 dri_bo_release(&brw
->cc
.prog_bo
);
106 dri_bo_release(&brw
->cc
.state_bo
);
107 dri_bo_release(&brw
->cc
.vp_bo
);
108 dri_bo_release(&brw
->cc
.blend_state_bo
);
109 dri_bo_release(&brw
->cc
.depth_stencil_state_bo
);
110 dri_bo_release(&brw
->cc
.color_calc_state_bo
);
112 free(brw
->curbe
.last_buf
);
113 free(brw
->curbe
.next_buf
);
118 * called from intelDrawBuffer()
120 static void brw_set_draw_region( struct intel_context
*intel
,
121 struct intel_region
*color_regions
[],
122 struct intel_region
*depth_region
,
123 GLuint num_color_regions
)
125 struct brw_context
*brw
= brw_context(&intel
->ctx
);
128 /* release old color/depth regions */
129 if (brw
->state
.depth_region
!= depth_region
)
130 brw
->state
.dirty
.brw
|= BRW_NEW_DEPTH_BUFFER
;
131 for (i
= 0; i
< brw
->state
.nr_color_regions
; i
++)
132 intel_region_release(&brw
->state
.color_regions
[i
]);
133 intel_region_release(&brw
->state
.depth_region
);
135 /* reference new color/depth regions */
136 for (i
= 0; i
< num_color_regions
; i
++)
137 intel_region_reference(&brw
->state
.color_regions
[i
], color_regions
[i
]);
138 intel_region_reference(&brw
->state
.depth_region
, depth_region
);
139 brw
->state
.nr_color_regions
= num_color_regions
;
144 * called from intel_batchbuffer_flush and children before sending a
147 static void brw_finish_batch(struct intel_context
*intel
)
149 struct brw_context
*brw
= brw_context(&intel
->ctx
);
150 brw_emit_query_end(brw
);
152 if (brw
->curbe
.curbe_bo
) {
153 drm_intel_gem_bo_unmap_gtt(brw
->curbe
.curbe_bo
);
154 drm_intel_bo_unreference(brw
->curbe
.curbe_bo
);
155 brw
->curbe
.curbe_bo
= NULL
;
161 * called from intelFlushBatchLocked
163 static void brw_new_batch( struct intel_context
*intel
)
165 struct brw_context
*brw
= brw_context(&intel
->ctx
);
167 /* Mark all context state as needing to be re-emitted.
168 * This is probably not as severe as on 915, since almost all of our state
169 * is just in referenced buffers.
171 brw
->state
.dirty
.brw
|= BRW_NEW_CONTEXT
;
173 brw
->state
.dirty
.mesa
|= ~0;
174 brw
->state
.dirty
.brw
|= ~0;
175 brw
->state
.dirty
.cache
|= ~0;
177 /* Move to the end of the current upload buffer so that we'll force choosing
178 * a new buffer next time.
180 if (brw
->vb
.upload
.bo
!= NULL
) {
181 drm_intel_bo_unreference(brw
->vb
.upload
.bo
);
182 brw
->vb
.upload
.bo
= NULL
;
183 brw
->vb
.upload
.offset
= 0;
187 static void brw_invalidate_state( struct intel_context
*intel
, GLuint new_state
)
193 void brwInitVtbl( struct brw_context
*brw
)
195 brw
->intel
.vtbl
.check_vertex_size
= 0;
196 brw
->intel
.vtbl
.emit_state
= 0;
197 brw
->intel
.vtbl
.reduced_primitive_state
= 0;
198 brw
->intel
.vtbl
.render_start
= 0;
199 brw
->intel
.vtbl
.update_texture_state
= 0;
201 brw
->intel
.vtbl
.invalidate_state
= brw_invalidate_state
;
202 brw
->intel
.vtbl
.new_batch
= brw_new_batch
;
203 brw
->intel
.vtbl
.finish_batch
= brw_finish_batch
;
204 brw
->intel
.vtbl
.destroy
= brw_destroy_context
;
205 brw
->intel
.vtbl
.set_draw_region
= brw_set_draw_region
;
206 brw
->intel
.vtbl
.debug_batch
= brw_debug_batch
;