gl: updated glxext.h to version 27
[mesa.git] / src / gallium / drivers / i965 / brw_winsys.h
1 /**************************************************************************
2 *
3 * Copyright © 2009 Jakob Bornecrantz
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 **************************************************************************/
25
26 #ifndef BRW_WINSYS_H
27 #define BRW_WINSYS_H
28
29 #include "pipe/p_compiler.h"
30 #include "pipe/p_defines.h"
31 #include "util/u_inlines.h"
32
33 struct brw_winsys;
34 struct pipe_fence_handle;
35
36 /* Not sure why the winsys needs this:
37 */
38 #define BRW_BATCH_SIZE (32*1024)
39
40 struct brw_winsys_screen;
41
42 /* Need a tiny bit of information inside the abstract buffer struct:
43 */
44 struct brw_winsys_buffer {
45 struct pipe_reference reference;
46 struct brw_winsys_screen *sws;
47 unsigned size;
48 };
49
50
51 /* Should be possible to validate usages above against buffer creation
52 * types, below:
53 */
54 enum brw_buffer_type
55 {
56 BRW_BUFFER_TYPE_TEXTURE,
57 BRW_BUFFER_TYPE_SCANOUT, /**< a texture used for scanning out from */
58 BRW_BUFFER_TYPE_VERTEX,
59 BRW_BUFFER_TYPE_CURBE,
60 BRW_BUFFER_TYPE_QUERY,
61 BRW_BUFFER_TYPE_SHADER_CONSTANTS,
62 BRW_BUFFER_TYPE_SHADER_SCRATCH,
63 BRW_BUFFER_TYPE_BATCH,
64 BRW_BUFFER_TYPE_GENERAL_STATE,
65 BRW_BUFFER_TYPE_SURFACE_STATE,
66 BRW_BUFFER_TYPE_PIXEL, /* image uploads, pbo's, etc */
67 BRW_BUFFER_TYPE_GENERIC, /* unknown */
68 BRW_BUFFER_TYPE_MAX /* Count of possible values */
69 };
70
71
72 /* Describe the usage of a particular buffer in a relocation. The DRM
73 * winsys will translate these back to GEM read/write domain flags.
74 */
75 enum brw_buffer_usage {
76 BRW_USAGE_STATE, /* INSTRUCTION, 0 */
77 BRW_USAGE_QUERY_RESULT, /* INSTRUCTION, INSTRUCTION */
78 BRW_USAGE_RENDER_TARGET, /* RENDER, 0 */
79 BRW_USAGE_DEPTH_BUFFER, /* RENDER, RENDER */
80 BRW_USAGE_BLIT_SOURCE, /* RENDER, 0 */
81 BRW_USAGE_BLIT_DEST, /* RENDER, RENDER */
82 BRW_USAGE_SAMPLER, /* SAMPLER, 0 */
83 BRW_USAGE_VERTEX, /* VERTEX, 0 */
84 BRW_USAGE_SCRATCH, /* 0, 0 */
85 BRW_USAGE_MAX
86 };
87
88 enum brw_buffer_data_type {
89 BRW_DATA_GS_CC_VP,
90 BRW_DATA_GS_CC_UNIT,
91 BRW_DATA_GS_WM_PROG,
92 BRW_DATA_GS_SAMPLER_DEFAULT_COLOR,
93 BRW_DATA_GS_SAMPLER,
94 BRW_DATA_GS_WM_UNIT,
95 BRW_DATA_GS_SF_PROG,
96 BRW_DATA_GS_SF_VP,
97 BRW_DATA_GS_SF_UNIT,
98 BRW_DATA_GS_VS_UNIT,
99 BRW_DATA_GS_VS_PROG,
100 BRW_DATA_GS_GS_UNIT,
101 BRW_DATA_GS_GS_PROG,
102 BRW_DATA_GS_CLIP_VP,
103 BRW_DATA_GS_CLIP_UNIT,
104 BRW_DATA_GS_CLIP_PROG,
105 BRW_DATA_SS_SURFACE,
106 BRW_DATA_SS_SURF_BIND,
107 BRW_DATA_CONSTANT_BUFFER,
108 BRW_DATA_BATCH_BUFFER,
109 BRW_DATA_OTHER,
110 BRW_DATA_MAX
111 };
112
113
114 /* Matches the i915_drm definitions:
115 */
116 #define BRW_TILING_NONE 0
117 #define BRW_TILING_X 1
118 #define BRW_TILING_Y 2
119
120
121 /* Relocations to be applied with subdata in a call to sws->bo_subdata, below.
122 *
123 * Effectively this encodes:
124 *
125 * (unsigned *)(subdata + offset) = bo->offset + delta
126 */
127 struct brw_winsys_reloc {
128 enum brw_buffer_usage usage; /* debug only */
129 unsigned delta;
130 unsigned offset;
131 struct brw_winsys_buffer *bo;
132 };
133
134 static INLINE void make_reloc(struct brw_winsys_reloc *reloc,
135 enum brw_buffer_usage usage,
136 unsigned delta,
137 unsigned offset,
138 struct brw_winsys_buffer *bo)
139 {
140 reloc->usage = usage;
141 reloc->delta = delta;
142 reloc->offset = offset;
143 reloc->bo = bo; /* Note - note taking a reference yet */
144 }
145
146
147
148 struct brw_winsys_screen {
149
150
151 /**
152 * Buffer functions.
153 */
154
155 /*@{*/
156 /**
157 * Create a buffer.
158 */
159 enum pipe_error (*bo_alloc)(struct brw_winsys_screen *sws,
160 enum brw_buffer_type type,
161 unsigned size,
162 unsigned alignment,
163 struct brw_winsys_buffer **bo_out);
164
165 /* Destroy a buffer when our refcount goes to zero:
166 */
167 void (*bo_destroy)(struct brw_winsys_buffer *buffer);
168
169 /* delta -- added to b2->offset, and written into buffer
170 * offset -- location above value is written to within buffer
171 */
172 enum pipe_error (*bo_emit_reloc)(struct brw_winsys_buffer *buffer,
173 enum brw_buffer_usage usage,
174 unsigned delta,
175 unsigned offset,
176 struct brw_winsys_buffer *b2);
177
178 enum pipe_error (*bo_exec)(struct brw_winsys_buffer *buffer,
179 unsigned bytes_used);
180
181 enum pipe_error (*bo_subdata)(struct brw_winsys_buffer *buffer,
182 enum brw_buffer_data_type data_type,
183 size_t offset,
184 size_t size,
185 const void *data,
186 const struct brw_winsys_reloc *reloc,
187 unsigned nr_reloc );
188
189 boolean (*bo_is_busy)(struct brw_winsys_buffer *buffer);
190 boolean (*bo_references)(struct brw_winsys_buffer *a,
191 struct brw_winsys_buffer *b);
192
193 /* XXX: couldn't this be handled by returning true/false on
194 * bo_emit_reloc?
195 */
196 enum pipe_error (*check_aperture_space)(struct brw_winsys_screen *iws,
197 struct brw_winsys_buffer **buffers,
198 unsigned count);
199
200 /**
201 * Map a buffer.
202 */
203 void *(*bo_map)(struct brw_winsys_buffer *buffer,
204 enum brw_buffer_data_type data_type,
205 unsigned offset,
206 unsigned length,
207 boolean write,
208 boolean discard,
209 boolean flush_explicit);
210
211 void (*bo_flush_range)(struct brw_winsys_buffer *buffer,
212 unsigned offset,
213 unsigned length);
214
215 /**
216 * Unmap a buffer.
217 */
218 void (*bo_unmap)(struct brw_winsys_buffer *buffer);
219 /*@}*/
220
221
222 /* Wait for buffer to go idle. Similar to map+unmap, but doesn't
223 * mark buffer contents as dirty.
224 */
225 void (*bo_wait_idle)(struct brw_winsys_buffer *buffer);
226
227 /**
228 * Destroy the winsys.
229 */
230 void (*destroy)(struct brw_winsys_screen *iws);
231 };
232
233 static INLINE void *
234 bo_map_read(struct brw_winsys_screen *sws, struct brw_winsys_buffer *buf)
235 {
236 return sws->bo_map( buf,
237 BRW_DATA_OTHER,
238 0, buf->size,
239 FALSE, FALSE, FALSE );
240 }
241
242 static INLINE void
243 bo_reference(struct brw_winsys_buffer **ptr, struct brw_winsys_buffer *buf)
244 {
245 struct brw_winsys_buffer *old_buf = *ptr;
246
247 if (pipe_reference(&(*ptr)->reference, &buf->reference))
248 old_buf->sws->bo_destroy(old_buf);
249
250 *ptr = buf;
251 }
252
253
254 /**
255 * Create brw pipe_screen.
256 */
257 struct pipe_screen *brw_create_screen(struct brw_winsys_screen *iws, unsigned pci_id);
258
259
260 /**
261 * Get the brw_winsys buffer backing the texture.
262 *
263 * TODO UGLY
264 */
265 struct pipe_texture;
266 boolean brw_texture_get_winsys_buffer(struct pipe_texture *texture,
267 struct brw_winsys_buffer **buffer,
268 unsigned *stride);
269
270 /**
271 * Wrap a brw_winsys buffer with a texture blanket.
272 *
273 * TODO UGLY
274 */
275 struct pipe_texture *
276 brw_texture_blanket_winsys_buffer(struct pipe_screen *screen,
277 const struct pipe_texture *template,
278 unsigned pitch,
279 unsigned tiling,
280 struct brw_winsys_buffer *buffer);
281
282
283 /*************************************************************************
284 * Cooperative dumping between winsys and driver. TODO: make this
285 * driver-only by wrapping calls to winsys->bo_subdata().
286 */
287
288 #ifdef DEBUG
289 extern int BRW_DUMP;
290 #else
291 #define BRW_DUMP 0
292 #endif
293
294 #define DUMP_ASM 0x1
295 #define DUMP_STATE 0x2
296 #define DUMP_BATCH 0x4
297
298 void brw_dump_data( unsigned pci_id,
299 enum brw_buffer_data_type data_type,
300 unsigned offset,
301 const void *data,
302 size_t size );
303
304
305 #endif