r300g: import the last bits of libdrm and cleanup the whole thing
[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 "r300_defines.h"
32
33 #include "pipebuffer/pb_bufmgr.h"
34 #include "pipe/p_defines.h"
35 #include "pipe/p_state.h"
36
37 #define R300_MAX_CMDBUF_DWORDS (16 * 1024)
38
39 struct winsys_handle;
40 struct r300_winsys_screen;
41
42 #define r300_winsys_bo pb_buffer
43 #define r300_winsys_bo_reference(pdst, src) pb_reference(pdst, src)
44
45 struct r300_winsys_cs_handle; /* for write_reloc etc. */
46
47 struct r300_winsys_cs {
48 unsigned cdw; /* Number of used dwords. */
49 uint32_t buf[R300_MAX_CMDBUF_DWORDS]; /* The command buffer. */
50 };
51
52 enum r300_value_id {
53 R300_VID_PCI_ID,
54 R300_VID_GB_PIPES,
55 R300_VID_Z_PIPES,
56 R300_VID_GART_SIZE,
57 R300_VID_VRAM_SIZE,
58 R300_VID_DRM_MAJOR,
59 R300_VID_DRM_MINOR,
60 R300_VID_DRM_PATCHLEVEL,
61
62 /* These should probably go away: */
63 R300_VID_DRM_2_1_0, /* Square tiling. */
64 R300_VID_DRM_2_3_0, /* R500 VAP regs, MSPOS regs, fixed tex3D size checking */
65 R300_VID_DRM_2_6_0, /* Hyper-Z, GB_Z_PEQ_CONFIG on rv350->r4xx, R500 FG_ALPHA_VALUE */
66 R300_VID_DRM_2_8_0, /* R500 US_FORMAT regs, R500 ARGB2101010 colorbuffer, CMask */
67
68 R300_CAN_HYPERZ, /* ZMask + HiZ */
69 R300_CAN_AACOMPRESS, /* CMask */
70 };
71
72 struct r300_winsys_screen {
73 /**
74 * Destroy this winsys.
75 *
76 * \param ws The winsys this function is called from.
77 */
78 void (*destroy)(struct r300_winsys_screen *ws);
79
80 /**
81 * Query a system value from a winsys.
82 *
83 * \param ws The winsys this function is called from.
84 * \param vid One of the R300_VID_* enums.
85 */
86 uint32_t (*get_value)(struct r300_winsys_screen *ws,
87 enum r300_value_id vid);
88
89 /**************************************************************************
90 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
91 *
92 * Remember that gallium gets to choose the interface it needs, and the
93 * window systems must then implement that interface (rather than the
94 * other way around...).
95 *************************************************************************/
96
97 /**
98 * Create a buffer object.
99 *
100 * \param ws The winsys this function is called from.
101 * \param size The size to allocate.
102 * \param alignment An alignment of the buffer in memory.
103 * \param bind A bitmask of the PIPE_BIND_* flags.
104 * \param usage A bitmask of the PIPE_USAGE_* flags.
105 * \param domain A bitmask of the R300_DOMAIN_* flags.
106 * \return The created buffer object.
107 */
108 struct r300_winsys_bo *(*buffer_create)(struct r300_winsys_screen *ws,
109 unsigned size,
110 unsigned alignment,
111 unsigned bind,
112 unsigned usage,
113 enum r300_buffer_domain domain);
114
115 struct r300_winsys_cs_handle *(*buffer_get_cs_handle)(
116 struct r300_winsys_bo *buf);
117
118 /**
119 * Map the entire data store of a buffer object into the client's address
120 * space.
121 *
122 * \param buf A winsys buffer object to map.
123 * \param cs A command stream to flush if the buffer is referenced by it.
124 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
125 * \return The pointer at the beginning of the buffer.
126 */
127 void *(*buffer_map)(struct r300_winsys_bo *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 buf A winsys buffer object to unmap.
135 */
136 void (*buffer_unmap)(struct r300_winsys_bo *buf);
137
138 /**
139 * Return TRUE if a buffer object is being used by the GPU.
140 *
141 * \param buf A winsys buffer object.
142 */
143 boolean (*buffer_is_busy)(struct r300_winsys_bo *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 buf A winsys buffer object to wait for.
151 */
152 void (*buffer_wait)(struct r300_winsys_bo *buf);
153
154 /**
155 * Return tiling flags describing a memory layout of a buffer object.
156 *
157 * \param buf A winsys buffer object to get the flags from.
158 * \param macrotile A pointer to the return value of the microtile flag.
159 * \param microtile A pointer to the return value of the macrotile flag.
160 *
161 * \note microtile and macrotile are not bitmasks!
162 */
163 void (*buffer_get_tiling)(struct r300_winsys_bo *buf,
164 enum r300_buffer_tiling *microtile,
165 enum r300_buffer_tiling *macrotile);
166
167 /**
168 * Set tiling flags describing a memory layout of a buffer object.
169 *
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_bo *buf,
178 enum r300_buffer_tiling microtile,
179 enum r300_buffer_tiling macrotile,
180 unsigned stride);
181
182 /**
183 * Get a winsys buffer from a winsys handle. The internal structure
184 * of the handle is platform-specific and only a winsys should access it.
185 *
186 * \param ws The winsys this function is called from.
187 * \param whandle A winsys handle pointer as was received from a state
188 * tracker.
189 * \param stride The returned buffer stride in bytes.
190 * \param size The returned buffer size.
191 */
192 struct r300_winsys_bo *(*buffer_from_handle)(struct r300_winsys_screen *ws,
193 struct winsys_handle *whandle,
194 unsigned *stride,
195 unsigned *size);
196
197 /**
198 * Get a winsys handle from a winsys buffer. The internal structure
199 * of the handle is platform-specific and only a winsys should access it.
200 *
201 * \param buf A winsys buffer object to get the handle from.
202 * \param whandle A winsys handle pointer.
203 * \param stride A stride of the buffer in bytes, for texturing.
204 * \return TRUE on success.
205 */
206 boolean (*buffer_get_handle)(struct r300_winsys_bo *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 new buffer relocation. Every relocation must first be added
233 * before it can be written.
234 *
235 * \param cs A command stream to add buffer for validation against.
236 * \param buf A winsys buffer to validate.
237 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
238 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
239 */
240 void (*cs_add_reloc)(struct r300_winsys_cs *cs,
241 struct r300_winsys_cs_handle *buf,
242 enum r300_buffer_domain rd,
243 enum r300_buffer_domain wd);
244
245 /**
246 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
247 * added so far.
248 *
249 * \param cs A command stream to validate.
250 */
251 boolean (*cs_validate)(struct r300_winsys_cs *cs);
252
253 /**
254 * Write a relocated dword to a command buffer.
255 *
256 * \param cs A command stream the relocation is written to.
257 * \param buf A winsys buffer to write the relocation for.
258 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
259 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
260 */
261 void (*cs_write_reloc)(struct r300_winsys_cs *cs,
262 struct r300_winsys_cs_handle *buf);
263
264 /**
265 * Flush a command stream.
266 *
267 * \param cs A command stream to flush.
268 */
269 void (*cs_flush)(struct r300_winsys_cs *cs);
270
271 /**
272 * Set a flush callback which is called from winsys when flush is
273 * required.
274 *
275 * \param cs A command stream to set the callback for.
276 * \param flush A flush callback function associated with the command stream.
277 * \param user A user pointer that will be passed to the flush callback.
278 */
279 void (*cs_set_flush)(struct r300_winsys_cs *cs,
280 void (*flush)(void *),
281 void *user);
282
283 /**
284 * Return TRUE if a buffer is referenced by a command stream.
285 *
286 * \param cs A command stream.
287 * \param buf A winsys buffer.
288 */
289 boolean (*cs_is_buffer_referenced)(struct r300_winsys_cs *cs,
290 struct r300_winsys_cs_handle *buf);
291 };
292
293 #endif /* R300_WINSYS_H */