r600: don't enable depth test if there is no depth buffer
[mesa.git] / src / gallium / winsys / xlib / xlib_brw_context.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 *
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Keith Whitwell
32 * Brian Paul
33 */
34
35
36 /* #include "glxheader.h" */
37 /* #include "xmesaP.h" */
38
39 #include "util/u_simple_screen.h"
40 #include "util/u_inlines.h"
41 #include "util/u_math.h"
42 #include "util/u_memory.h"
43 #include "i965simple/brw_winsys.h"
44 #include "xlib_brw_aub.h"
45 #include "xlib_brw.h"
46
47
48
49
50 #define XBCWS_BATCHBUFFER_SIZE 1024
51
52
53 /* The backend to the brw driver (ie struct brw_winsys) is actually a
54 * per-context entity.
55 */
56 struct xlib_brw_context_winsys {
57 struct brw_winsys brw_context_winsys; /**< batch buffer funcs */
58 struct aub_context *aub;
59
60 struct pipe_winsys *pipe_winsys;
61
62 unsigned batch_data[XBCWS_BATCHBUFFER_SIZE];
63 unsigned batch_nr;
64 unsigned batch_size;
65 unsigned batch_alloc;
66 };
67
68
69 /* Turn a brw_winsys into an xlib_brw_context_winsys:
70 */
71 static inline struct xlib_brw_context_winsys *
72 xlib_brw_context_winsys( struct brw_winsys *sws )
73 {
74 return (struct xlib_brw_context_winsys *)sws;
75 }
76
77
78 /* Simple batchbuffer interface:
79 */
80
81 static unsigned *xbcws_batch_start( struct brw_winsys *sws,
82 unsigned dwords,
83 unsigned relocs )
84 {
85 struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);
86
87 if (xbcws->batch_size < xbcws->batch_nr + dwords)
88 return NULL;
89
90 xbcws->batch_alloc = xbcws->batch_nr + dwords;
91 return (void *)1; /* not a valid pointer! */
92 }
93
94 static void xbcws_batch_dword( struct brw_winsys *sws,
95 unsigned dword )
96 {
97 struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);
98
99 assert(xbcws->batch_nr < xbcws->batch_alloc);
100 xbcws->batch_data[xbcws->batch_nr++] = dword;
101 }
102
103 static void xbcws_batch_reloc( struct brw_winsys *sws,
104 struct pipe_buffer *buf,
105 unsigned access_flags,
106 unsigned delta )
107 {
108 struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);
109
110 assert(xbcws->batch_nr < xbcws->batch_alloc);
111 xbcws->batch_data[xbcws->batch_nr++] =
112 ( xlib_brw_get_buffer_offset( NULL, buf, access_flags ) +
113 delta );
114 }
115
116 static void xbcws_batch_end( struct brw_winsys *sws )
117 {
118 struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);
119
120 assert(xbcws->batch_nr <= xbcws->batch_alloc);
121 xbcws->batch_alloc = 0;
122 }
123
124 static void xbcws_batch_flush( struct brw_winsys *sws,
125 struct pipe_fence_handle **fence )
126 {
127 struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);
128 assert(xbcws->batch_nr <= xbcws->batch_size);
129
130 if (xbcws->batch_nr) {
131 xlib_brw_commands_aub( xbcws->pipe_winsys,
132 xbcws->batch_data,
133 xbcws->batch_nr );
134 }
135
136 xbcws->batch_nr = 0;
137 }
138
139
140
141 /* Really a per-device function, just pass through:
142 */
143 static unsigned xbcws_get_buffer_offset( struct brw_winsys *sws,
144 struct pipe_buffer *buf,
145 unsigned access_flags )
146 {
147 struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);
148
149 return xlib_brw_get_buffer_offset( xbcws->pipe_winsys,
150 buf,
151 access_flags );
152 }
153
154
155 /* Really a per-device function, just pass through:
156 */
157 static void xbcws_buffer_subdata_typed( struct brw_winsys *sws,
158 struct pipe_buffer *buf,
159 unsigned long offset,
160 unsigned long size,
161 const void *data,
162 unsigned data_type )
163 {
164 struct xlib_brw_context_winsys *xbcws = xlib_brw_context_winsys(sws);
165
166 xlib_brw_buffer_subdata_typed( xbcws->pipe_winsys,
167 buf,
168 offset,
169 size,
170 data,
171 data_type );
172 }
173
174
175 /**
176 * Create i965 hardware rendering context, but plugged into a
177 * dump-to-aubfile backend.
178 */
179 struct pipe_context *
180 xlib_create_brw_context( struct pipe_screen *screen,
181 void *unused )
182 {
183 struct xlib_brw_context_winsys *xbcws = CALLOC_STRUCT( xlib_brw_context_winsys );
184
185 /* Fill in this struct with callbacks that i965simple will need to
186 * communicate with the window system, buffer manager, etc.
187 */
188 xbcws->brw_context_winsys.batch_start = xbcws_batch_start;
189 xbcws->brw_context_winsys.batch_dword = xbcws_batch_dword;
190 xbcws->brw_context_winsys.batch_reloc = xbcws_batch_reloc;
191 xbcws->brw_context_winsys.batch_end = xbcws_batch_end;
192 xbcws->brw_context_winsys.batch_flush = xbcws_batch_flush;
193 xbcws->brw_context_winsys.buffer_subdata_typed = xbcws_buffer_subdata_typed;
194 xbcws->brw_context_winsys.get_buffer_offset = xbcws_get_buffer_offset;
195
196 xbcws->pipe_winsys = screen->winsys; /* redundant */
197
198 xbcws->batch_size = XBCWS_BATCHBUFFER_SIZE;
199
200 /* Create the i965simple context:
201 */
202 #ifdef GALLIUM_CELL
203 return NULL;
204 #else
205 return brw_create( screen,
206 &xbcws->brw_context_winsys,
207 0 );
208 #endif
209 }