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