Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / gallium / drivers / r300 / r300_winsys.h
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #ifndef R300_WINSYS_H
25 #define R300_WINSYS_H
26
27 /* The public winsys interface header for the r300 pipe driver.
28 * Any winsys hosting this pipe needs to implement r300_winsys_screen and then
29 * call r300_screen_create to start things. */
30
31 #include "pipe/p_defines.h"
32 #include "pipe/p_state.h"
33
34 #include "r300_defines.h"
35
36 struct winsys_handle;
37 struct r300_winsys_screen;
38
39 struct r300_winsys_buffer;
40
41 struct r300_winsys_cs {
42 uint32_t *ptr; /* Pointer to the beginning of the CS. */
43 unsigned cdw; /* Number of used dwords. */
44 unsigned ndw; /* Size of the CS in dwords. */
45 };
46
47 enum r300_value_id {
48 R300_VID_PCI_ID,
49 R300_VID_GB_PIPES,
50 R300_VID_Z_PIPES,
51 R300_VID_SQUARE_TILING_SUPPORT,
52 R300_VID_DRM_2_3_0,
53 R300_VID_DRM_2_6_0,
54 R300_CAN_HYPERZ,
55 };
56
57 enum r300_reference_domain { /* bitfield */
58 R300_REF_CS = 1,
59 R300_REF_HW = 2
60 };
61
62 struct r300_winsys_screen {
63 /**
64 * Destroy this winsys.
65 *
66 * \param ws The winsys this function is called from.
67 */
68 void (*destroy)(struct r300_winsys_screen *ws);
69
70 /**
71 * Query a system value from a winsys.
72 *
73 * \param ws The winsys this function is called from.
74 * \param vid One of the R300_VID_* enums.
75 */
76 uint32_t (*get_value)(struct r300_winsys_screen *ws,
77 enum r300_value_id vid);
78
79 /**************************************************************************
80 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
81 *
82 * Remember that gallium gets to choose the interface it needs, and the
83 * window systems must then implement that interface (rather than the
84 * other way around...).
85 *************************************************************************/
86
87 /**
88 * Create a buffer object.
89 *
90 * \param ws The winsys this function is called from.
91 * \param size The size to allocate.
92 * \param alignment An alignment of the buffer in memory.
93 * \param bind A bitmask of the PIPE_BIND_* flags.
94 * \param usage A bitmask of the PIPE_USAGE_* flags.
95 * \param domain A bitmask of the R300_DOMAIN_* flags.
96 * \return The created buffer object.
97 */
98 struct r300_winsys_buffer *(*buffer_create)(struct r300_winsys_screen *ws,
99 unsigned size,
100 unsigned alignment,
101 unsigned bind,
102 unsigned usage,
103 enum r300_buffer_domain domain);
104
105 /**
106 * Reference a buffer object (assign with reference counting).
107 *
108 * \param ws The winsys this function is called from.
109 * \param pdst A destination pointer to set the source buffer to.
110 * \param src A source buffer object.
111 */
112 void (*buffer_reference)(struct r300_winsys_screen *ws,
113 struct r300_winsys_buffer **pdst,
114 struct r300_winsys_buffer *src);
115
116 /**
117 * Map the entire data store of a buffer object into the client's address
118 * space.
119 *
120 * \param ws The winsys this function is called from.
121 * \param buf A winsys buffer object to map.
122 * \param cs A command stream to flush if the buffer is referenced by it.
123 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
124 * \return The pointer at the beginning of the buffer.
125 */
126 void *(*buffer_map)(struct r300_winsys_screen *ws,
127 struct r300_winsys_buffer *buf,
128 struct r300_winsys_cs *cs,
129 enum pipe_transfer_usage usage);
130
131 /**
132 * Unmap a buffer object from the client's address space.
133 *
134 * \param ws The winsys this function is called from.
135 * \param buf A winsys buffer object to unmap.
136 */
137 void (*buffer_unmap)(struct r300_winsys_screen *ws,
138 struct r300_winsys_buffer *buf);
139
140 /**
141 * Wait for a buffer object until it is not used by a GPU. This is
142 * equivalent to a fence placed after the last command using the buffer,
143 * and synchronizing to the fence.
144 *
145 * \param ws The winsys this function is called from.
146 * \param buf A winsys buffer object to wait for.
147 */
148 void (*buffer_wait)(struct r300_winsys_screen *ws,
149 struct r300_winsys_buffer *buf);
150
151 /**
152 * Return tiling flags describing a memory layout of a buffer object.
153 *
154 * \param ws The winsys this function is called from.
155 * \param buf A winsys buffer object to get the flags from.
156 * \param macrotile A pointer to the return value of the microtile flag.
157 * \param microtile A pointer to the return value of the macrotile flag.
158 *
159 * \note microtile and macrotile are not bitmasks!
160 */
161 void (*buffer_get_tiling)(struct r300_winsys_screen *ws,
162 struct r300_winsys_buffer *buf,
163 enum r300_buffer_tiling *microtile,
164 enum r300_buffer_tiling *macrotile);
165
166 /**
167 * Set tiling flags describing a memory layout of a buffer object.
168 *
169 * \param ws The winsys this function is called from.
170 * \param buf A winsys buffer object to set the flags for.
171 * \param macrotile A macrotile flag.
172 * \param microtile A microtile flag.
173 * \param stride A stride of the buffer in bytes, for texturing.
174 *
175 * \note microtile and macrotile are not bitmasks!
176 */
177 void (*buffer_set_tiling)(struct r300_winsys_screen *ws,
178 struct r300_winsys_buffer *buf,
179 enum r300_buffer_tiling microtile,
180 enum r300_buffer_tiling macrotile,
181 unsigned stride);
182
183 /**
184 * Get a winsys buffer from a winsys handle. The internal structure
185 * of the handle is platform-specific and only a winsys should access it.
186 *
187 * \param ws The winsys this function is called from.
188 * \param whandle A winsys handle pointer as was received from a state
189 * tracker.
190 * \param stride The returned buffer stride in bytes.
191 * \param size The returned buffer size.
192 */
193 struct r300_winsys_buffer *(*buffer_from_handle)(struct r300_winsys_screen *ws,
194 struct winsys_handle *whandle,
195 unsigned *stride,
196 unsigned *size);
197
198 /**
199 * Get a winsys handle from a winsys buffer. The internal structure
200 * of the handle is platform-specific and only a winsys should access it.
201 *
202 * \param ws The winsys this function is called from.
203 * \param buf A winsys buffer object to get the handle from.
204 * \param whandle A winsys handle pointer.
205 * \param stride A stride of the buffer in bytes, for texturing.
206 * \return TRUE on success.
207 */
208 boolean (*buffer_get_handle)(struct r300_winsys_screen *ws,
209 struct r300_winsys_buffer *buf,
210 unsigned stride,
211 struct winsys_handle *whandle);
212
213 /**************************************************************************
214 * Command submission.
215 *
216 * Each pipe context should create its own command stream and submit
217 * commands independently of other contexts.
218 *************************************************************************/
219
220 /**
221 * Create a command stream.
222 *
223 * \param ws The winsys this function is called from.
224 */
225 struct r300_winsys_cs *(*cs_create)(struct r300_winsys_screen *ws);
226
227 /**
228 * Destroy a command stream.
229 *
230 * \param cs A command stream to destroy.
231 */
232 void (*cs_destroy)(struct r300_winsys_cs *cs);
233
234 /**
235 * Add a buffer object to the list of buffers to validate.
236 *
237 * \param cs A command stream to add buffer for validation against.
238 * \param buf A winsys buffer to validate.
239 * \param rd A read domain containing a bitmask
240 * of the R300_DOMAIN_* flags.
241 * \param wd A write domain containing a bitmask
242 * of the R300_DOMAIN_* flags.
243 */
244 void (*cs_add_buffer)(struct r300_winsys_cs *cs,
245 struct r300_winsys_buffer *buf,
246 enum r300_buffer_domain rd,
247 enum r300_buffer_domain wd);
248
249 /**
250 * Revalidate all currently set up winsys buffers.
251 * Returns TRUE if a flush is required.
252 *
253 * \param cs A command stream to validate.
254 */
255 boolean (*cs_validate)(struct r300_winsys_cs *cs);
256
257 /**
258 * Write a relocated dword to a command buffer.
259 *
260 * \param cs A command stream the relocation is written to.
261 * \param buf A winsys buffer to write the relocation for.
262 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
263 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
264 */
265 void (*cs_write_reloc)(struct r300_winsys_cs *cs,
266 struct r300_winsys_buffer *buf,
267 enum r300_buffer_domain rd,
268 enum r300_buffer_domain wd);
269
270 /**
271 * Flush a command stream.
272 *
273 * \param cs A command stream to flush.
274 */
275 void (*cs_flush)(struct r300_winsys_cs *cs);
276
277 /**
278 * Set a flush callback which is called from winsys when flush is
279 * required.
280 *
281 * \param cs A command stream to set the callback for.
282 * \param flush A flush callback function associated with the command stream.
283 * \param user A user pointer that will be passed to the flush callback.
284 */
285 void (*cs_set_flush)(struct r300_winsys_cs *cs,
286 void (*flush)(void *),
287 void *user);
288
289 /**
290 * Reset the list of buffer objects to validate, usually called
291 * prior to adding buffer objects for validation.
292 *
293 * \param cs A command stream to reset buffers for.
294 */
295 void (*cs_reset_buffers)(struct r300_winsys_cs *cs);
296
297 /**
298 * Return TRUE if a buffer is referenced by a command stream or by hardware
299 * (i.e. is busy), based on the domain parameter.
300 *
301 * \param cs A command stream.
302 * \param buf A winsys buffer.
303 * \param domain A bitmask of the R300_REF_* enums.
304 */
305 boolean (*cs_is_buffer_referenced)(struct r300_winsys_cs *cs,
306 struct r300_winsys_buffer *buf,
307 enum r300_reference_domain domain);
308 };
309
310 #endif /* R300_WINSYS_H */