i965g: add some missing texture creation code
[mesa.git] / src / gallium / drivers / i965 / brw_context.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 #include "pipe/p_context.h"
34 #include "util/u_simple_list.h"
35
36 #include "brw_context.h"
37 #include "brw_defines.h"
38 #include "brw_draw.h"
39 #include "brw_state.h"
40 #include "brw_batchbuffer.h"
41 #include "brw_winsys.h"
42
43
44 static void brw_destroy_context( struct pipe_context *pipe )
45 {
46 struct brw_context *brw = brw_context(pipe);
47 int i;
48
49 brw_destroy_state(brw);
50
51 brw_draw_cleanup( brw );
52
53 brw_pipe_blend_cleanup( brw );
54 brw_pipe_depth_stencil_cleanup( brw );
55 brw_pipe_framebuffer_cleanup( brw );
56 brw_pipe_flush_cleanup( brw );
57 brw_pipe_misc_cleanup( brw );
58 brw_pipe_query_cleanup( brw );
59 brw_pipe_rast_cleanup( brw );
60 brw_pipe_sampler_cleanup( brw );
61 brw_pipe_shader_cleanup( brw );
62 brw_pipe_vertex_cleanup( brw );
63
64 FREE(brw->wm.compile_data);
65
66 for (i = 0; i < brw->curr.fb.nr_cbufs; i++)
67 pipe_surface_reference(&brw->curr.fb.cbufs[i], NULL);
68 brw->curr.fb.nr_cbufs = 0;
69 pipe_surface_reference(&brw->curr.fb.zsbuf, NULL);
70
71 brw->sws->bo_unreference(brw->curbe.curbe_bo);
72 brw->sws->bo_unreference(brw->vs.prog_bo);
73 brw->sws->bo_unreference(brw->vs.state_bo);
74 brw->sws->bo_unreference(brw->vs.bind_bo);
75 brw->sws->bo_unreference(brw->gs.prog_bo);
76 brw->sws->bo_unreference(brw->gs.state_bo);
77 brw->sws->bo_unreference(brw->clip.prog_bo);
78 brw->sws->bo_unreference(brw->clip.state_bo);
79 brw->sws->bo_unreference(brw->clip.vp_bo);
80 brw->sws->bo_unreference(brw->sf.prog_bo);
81 brw->sws->bo_unreference(brw->sf.state_bo);
82 brw->sws->bo_unreference(brw->sf.vp_bo);
83 for (i = 0; i < BRW_MAX_TEX_UNIT; i++)
84 brw->sws->bo_unreference(brw->wm.sdc_bo[i]);
85 brw->sws->bo_unreference(brw->wm.bind_bo);
86 for (i = 0; i < BRW_WM_MAX_SURF; i++)
87 brw->sws->bo_unreference(brw->wm.surf_bo[i]);
88 brw->sws->bo_unreference(brw->wm.sampler_bo);
89 brw->sws->bo_unreference(brw->wm.prog_bo);
90 brw->sws->bo_unreference(brw->wm.state_bo);
91 brw->sws->bo_unreference(brw->cc.prog_bo);
92 brw->sws->bo_unreference(brw->cc.state_bo);
93 brw->sws->bo_unreference(brw->cc.vp_bo);
94 }
95
96
97 struct pipe_context *brw_create_context(struct pipe_screen *screen)
98 {
99 struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
100
101 if (!brw) {
102 debug_printf("%s: failed to alloc context\n", __FUNCTION__);
103 return GL_FALSE;
104 }
105
106 /* We want the GLSL compiler to emit code that uses condition codes */
107 //ctx->Shader.EmitCondCodes = GL_TRUE;
108 //ctx->Shader.EmitNVTempInitialization = GL_TRUE;
109
110 brw->base.screen = screen;
111 brw->base.destroy = brw_destroy_context;
112
113 brw_pipe_blend_init( brw );
114 brw_pipe_depth_stencil_init( brw );
115 brw_pipe_framebuffer_init( brw );
116 brw_pipe_flush_init( brw );
117 brw_pipe_misc_init( brw );
118 brw_pipe_query_init( brw );
119 brw_pipe_rast_init( brw );
120 brw_pipe_sampler_init( brw );
121 brw_pipe_shader_init( brw );
122 brw_pipe_vertex_init( brw );
123
124 brw_init_state( brw );
125 brw_draw_init( brw );
126
127 brw->state.dirty.mesa = ~0;
128 brw->state.dirty.brw = ~0;
129
130 brw->flags.always_emit_state = 0;
131
132 make_empty_list(&brw->query.active_head);
133
134
135 return &brw->base;
136 }
137