Squashed commit of the following:
[profile/ivi/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_inlines.h"
35 #include "util/u_simple_list.h"
36
37 #include "brw_context.h"
38 #include "brw_draw.h"
39 #include "brw_state.h"
40 #include "brw_batchbuffer.h"
41 #include "brw_winsys.h"
42 #include "brw_resource.h"
43 #include "brw_screen.h"
44
45
46 static void brw_destroy_context( struct pipe_context *pipe )
47 {
48    struct brw_context *brw = brw_context(pipe);
49    int i;
50
51    brw_context_flush( brw );
52    brw_batchbuffer_free( brw->batch );
53    brw_destroy_state(brw);
54
55    brw_draw_cleanup( brw );
56
57    brw_pipe_blend_cleanup( brw );
58    brw_pipe_depth_stencil_cleanup( brw );
59    brw_pipe_framebuffer_cleanup( brw );
60    brw_pipe_flush_cleanup( brw );
61    brw_pipe_misc_cleanup( brw );
62    brw_pipe_query_cleanup( brw );
63    brw_pipe_rast_cleanup( brw );
64    brw_pipe_sampler_cleanup( brw );
65    brw_pipe_shader_cleanup( brw );
66    brw_pipe_vertex_cleanup( brw );
67    brw_pipe_clear_cleanup( brw );
68
69    brw_hw_cc_cleanup( brw );
70
71
72    FREE(brw->wm.compile_data);
73
74    for (i = 0; i < brw->curr.fb.nr_cbufs; i++)
75       pipe_surface_reference(&brw->curr.fb.cbufs[i], NULL);
76    brw->curr.fb.nr_cbufs = 0;
77    pipe_surface_reference(&brw->curr.fb.zsbuf, NULL);
78
79    bo_reference(&brw->curbe.curbe_bo, NULL);
80    bo_reference(&brw->vs.prog_bo, NULL);
81    bo_reference(&brw->vs.state_bo, NULL);
82    bo_reference(&brw->vs.bind_bo, NULL);
83    bo_reference(&brw->gs.prog_bo, NULL);
84    bo_reference(&brw->gs.state_bo, NULL);
85    bo_reference(&brw->clip.prog_bo, NULL);
86    bo_reference(&brw->clip.state_bo, NULL);
87    bo_reference(&brw->clip.vp_bo, NULL);
88    bo_reference(&brw->sf.prog_bo, NULL);
89    bo_reference(&brw->sf.state_bo, NULL);
90    bo_reference(&brw->sf.vp_bo, NULL);
91
92    for (i = 0; i < Elements(brw->wm.sdc_bo); i++)
93       bo_reference(&brw->wm.sdc_bo[i], NULL);
94
95    bo_reference(&brw->wm.bind_bo, NULL);
96
97    for (i = 0; i < Elements(brw->wm.surf_bo); i++)
98       bo_reference(&brw->wm.surf_bo[i], NULL);
99
100    bo_reference(&brw->wm.sampler_bo, NULL);
101    bo_reference(&brw->wm.prog_bo, NULL);
102    bo_reference(&brw->wm.state_bo, NULL);
103 }
104
105
106 struct pipe_context *brw_create_context(struct pipe_screen *screen,
107                                         void *priv)
108 {
109    struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
110
111    if (!brw) {
112       debug_printf("%s: failed to alloc context\n", __FUNCTION__);
113       return NULL;
114    }
115
116    brw->base.screen = screen;
117    brw->base.priv = priv;
118    brw->base.destroy = brw_destroy_context;
119    brw->sws = brw_screen(screen)->sws;
120    brw->chipset = brw_screen(screen)->chipset;
121
122    brw_init_resource_functions( brw );
123    brw_pipe_blend_init( brw );
124    brw_pipe_depth_stencil_init( brw );
125    brw_pipe_framebuffer_init( brw );
126    brw_pipe_flush_init( brw );
127    brw_pipe_misc_init( brw );
128    brw_pipe_query_init( brw );
129    brw_pipe_rast_init( brw );
130    brw_pipe_sampler_init( brw );
131    brw_pipe_shader_init( brw );
132    brw_pipe_vertex_init( brw );
133    brw_pipe_clear_init( brw );
134
135    brw_hw_cc_init( brw );
136
137    brw_init_state( brw );
138    brw_draw_init( brw );
139
140    brw->state.dirty.mesa = ~0;
141    brw->state.dirty.brw = ~0;
142
143    brw->flags.always_emit_state = 0;
144
145    make_empty_list(&brw->query.active_head);
146
147    brw->batch = brw_batchbuffer_alloc( brw->sws, brw->chipset );
148    if (brw->batch == NULL)
149       goto fail;
150
151    return &brw->base;
152
153 fail:
154    if (brw->batch)
155       brw_batchbuffer_free( brw->batch );
156    return NULL;
157 }
158