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