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