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