gallium: Make sure we flush before some texture / buffer operations.
[mesa.git] / src / gallium / drivers / i965simple / 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 "brw_context.h"
34 #include "brw_defines.h"
35 #include "brw_draw.h"
36 #include "brw_vs.h"
37 #include "brw_tex_layout.h"
38 #include "brw_winsys.h"
39
40 #include "pipe/internal/p_winsys_screen.h"
41 #include "pipe/p_context.h"
42 #include "util/u_memory.h"
43 #include "pipe/p_screen.h"
44
45
46 #ifndef BRW_DEBUG
47 int BRW_DEBUG = (0);
48 #endif
49
50
51 static void brw_destroy(struct pipe_context *pipe)
52 {
53 struct brw_context *brw = brw_context(pipe);
54
55 if(brw->winsys->destroy)
56 brw->winsys->destroy(brw->winsys);
57
58 FREE(brw);
59 }
60
61
62 static void brw_clear(struct pipe_context *pipe, struct pipe_surface *ps,
63 unsigned clearValue)
64 {
65 int x, y, w, h;
66 /* FIXME: corny... */
67
68 x = 0;
69 y = 0;
70 w = ps->width;
71 h = ps->height;
72
73 pipe->surface_fill(pipe, ps, x, y, w, h, clearValue);
74 }
75
76 static unsigned int
77 brw_is_texture_referenced( struct pipe_context *pipe,
78 struct pipe_texture *texture,
79 unsigned face, unsigned level)
80 {
81 /**
82 * FIXME: Optimize.
83 */
84
85 return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
86 }
87
88 static unsigned int
89 brw_is_buffer_referenced( struct pipe_context *pipe,
90 struct pipe_buffer *buf)
91 {
92 /**
93 * FIXME: Optimize.
94 */
95
96 return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
97 }
98
99 struct pipe_context *brw_create(struct pipe_screen *screen,
100 struct brw_winsys *brw_winsys,
101 unsigned pci_id)
102 {
103 struct brw_context *brw;
104
105 debug_printf("%s: creating brw_context with pci id 0x%x\n",
106 __FUNCTION__, pci_id);
107
108 brw = CALLOC_STRUCT(brw_context);
109 if (brw == NULL)
110 return NULL;
111
112 brw->winsys = brw_winsys;
113 brw->pipe.winsys = screen->winsys;
114 brw->pipe.screen = screen;
115
116 brw->pipe.destroy = brw_destroy;
117 brw->pipe.clear = brw_clear;
118
119 brw->pipe.is_texture_referenced = brw_is_texture_referenced;
120 brw->pipe.is_buffer_referenced = brw_is_buffer_referenced;
121
122 brw_init_surface_functions(brw);
123 brw_init_texture_functions(brw);
124 brw_init_state_functions(brw);
125 brw_init_flush_functions(brw);
126 brw_init_draw_functions( brw );
127
128
129 brw_init_state( brw );
130
131 brw->pci_id = pci_id;
132 brw->dirty = ~0;
133 brw->hardware_dirty = ~0;
134
135 memset(&brw->wm.bind, ~0, sizeof(brw->wm.bind));
136
137 return &brw->pipe;
138 }
139