3a6798a54233addd2bb77ad0a05dfd32738e622d
[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 #define R300_FLUSH_ASYNC (1 << 0)
39
40 struct winsys_handle;
41 struct r300_winsys_screen;
42
43 #define r300_winsys_bo pb_buffer
44 #define r300_winsys_bo_reference(pdst, src) pb_reference(pdst, src)
45
46 struct r300_winsys_cs_handle; /* for write_reloc etc. */
47
48 struct r300_winsys_cs {
49 unsigned cdw; /* Number of used dwords. */
50 uint32_t *buf; /* The command buffer. */
51 };
52
53 enum r300_value_id {
54 R300_VID_PCI_ID,
55 R300_VID_GB_PIPES,
56 R300_VID_Z_PIPES,
57 R300_VID_GART_SIZE,
58 R300_VID_VRAM_SIZE,
59 R300_VID_DRM_MAJOR,
60 R300_VID_DRM_MINOR,
61 R300_VID_DRM_PATCHLEVEL,
62
63 /* These should probably go away: */
64 R300_VID_DRM_2_6_0, /* Hyper-Z, GB_Z_PEQ_CONFIG on rv350->r4xx, R500 FG_ALPHA_VALUE */
65 R300_VID_DRM_2_8_0, /* R500 US_FORMAT regs, R500 ARGB2101010 colorbuffer, CMask, R16F/RG16F */
66
67 R300_CAN_HYPERZ, /* ZMask + HiZ */
68 R300_CAN_AACOMPRESS, /* CMask */
69 };
70
71 struct r300_winsys_screen {
72 /**
73 * Destroy this winsys.
74 *
75 * \param ws The winsys this function is called from.
76 */
77 void (*destroy)(struct r300_winsys_screen *ws);
78
79 /**
80 * Query a system value from a winsys.
81 *
82 * \param ws The winsys this function is called from.
83 * \param vid One of the R300_VID_* enums.
84 */
85 uint32_t (*get_value)(struct r300_winsys_screen *ws,
86 enum r300_value_id vid);
87
88 /**************************************************************************
89 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
90 *
91 * Remember that gallium gets to choose the interface it needs, and the
92 * window systems must then implement that interface (rather than the
93 * other way around...).
94 *************************************************************************/
95
96 /**
97 * Create a buffer object.
98 *
99 * \param ws The winsys this function is called from.
100 * \param size The size to allocate.
101 * \param alignment An alignment of the buffer in memory.
102 * \param bind A bitmask of the PIPE_BIND_* flags.
103 * \param usage A bitmask of the PIPE_USAGE_* flags.
104 * \param domain A bitmask of the R300_DOMAIN_* flags.
105 * \return The created buffer object.
106 */
107 struct r300_winsys_bo *(*buffer_create)(struct r300_winsys_screen *ws,
108 unsigned size,
109 unsigned alignment,
110 unsigned bind,
111 unsigned usage,
112 enum r300_buffer_domain domain);
113
114 struct r300_winsys_cs_handle *(*buffer_get_cs_handle)(
115 struct r300_winsys_bo *buf);
116
117 /**
118 * Map the entire data store of a buffer object into the client's address
119 * space.
120 *
121 * \param buf A winsys buffer object to map.
122 * \param cs A command stream to flush if the buffer is referenced by it.
123 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
124 * \return The pointer at the beginning of the buffer.
125 */
126 void *(*buffer_map)(struct r300_winsys_bo *buf,
127 struct r300_winsys_cs *cs,
128 enum pipe_transfer_usage usage);
129
130 /**
131 * Unmap a buffer object from the client's address space.
132 *
133 * \param buf A winsys buffer object to unmap.
134 */
135 void (*buffer_unmap)(struct r300_winsys_bo *buf);
136
137 /**
138 * Return TRUE if a buffer object is being used by the GPU.
139 *
140 * \param buf A winsys buffer object.
141 */
142 boolean (*buffer_is_busy)(struct r300_winsys_bo *buf);
143
144 /**
145 * Wait for a buffer object until it is not used by a GPU. This is
146 * equivalent to a fence placed after the last command using the buffer,
147 * and synchronizing to the fence.
148 *
149 * \param buf A winsys buffer object to wait for.
150 */
151 void (*buffer_wait)(struct r300_winsys_bo *buf);
152
153 /**
154 * Return tiling flags describing a memory layout of a buffer object.
155 *
156 * \param buf A winsys buffer object to get the flags from.
157 * \param macrotile A pointer to the return value of the microtile flag.
158 * \param microtile A pointer to the return value of the macrotile flag.
159 *
160 * \note microtile and macrotile are not bitmasks!
161 */
162 void (*buffer_get_tiling)(struct r300_winsys_bo *buf,
163 enum r300_buffer_tiling *microtile,
164 enum r300_buffer_tiling *macrotile);
165
166 /**
167 * Set tiling flags describing a memory layout of a buffer object.
168 *
169 * \param buf A winsys buffer object to set the flags for.
170 * \param cs A command stream to flush if the buffer is referenced by it.
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 struct r300_winsys_cs *cs,
179 enum r300_buffer_tiling microtile,
180 enum r300_buffer_tiling macrotile,
181 unsigned stride);
182
183 /**
184 * Get a winsys buffer from a winsys handle. The internal structure
185 * of the handle is platform-specific and only a winsys should access it.
186 *
187 * \param ws The winsys this function is called from.
188 * \param whandle A winsys handle pointer as was received from a state
189 * tracker.
190 * \param stride The returned buffer stride in bytes.
191 * \param size The returned buffer size.
192 */
193 struct r300_winsys_bo *(*buffer_from_handle)(struct r300_winsys_screen *ws,
194 struct winsys_handle *whandle,
195 unsigned *stride,
196 unsigned *size);
197
198 /**
199 * Get a winsys handle from a winsys buffer. The internal structure
200 * of the handle is platform-specific and only a winsys should access it.
201 *
202 * \param buf A winsys buffer object to get the handle from.
203 * \param whandle A winsys handle pointer.
204 * \param stride A stride of the buffer in bytes, for texturing.
205 * \return TRUE on success.
206 */
207 boolean (*buffer_get_handle)(struct r300_winsys_bo *buf,
208 unsigned stride,
209 struct winsys_handle *whandle);
210
211 /**************************************************************************
212 * Command submission.
213 *
214 * Each pipe context should create its own command stream and submit
215 * commands independently of other contexts.
216 *************************************************************************/
217
218 /**
219 * Create a command stream.
220 *
221 * \param ws The winsys this function is called from.
222 */
223 struct r300_winsys_cs *(*cs_create)(struct r300_winsys_screen *ws);
224
225 /**
226 * Destroy a command stream.
227 *
228 * \param cs A command stream to destroy.
229 */
230 void (*cs_destroy)(struct r300_winsys_cs *cs);
231
232 /**
233 * Add a new buffer relocation. Every relocation must first be added
234 * before it can be written.
235 *
236 * \param cs A command stream to add buffer for validation against.
237 * \param buf A winsys buffer to validate.
238 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
239 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
240 */
241 void (*cs_add_reloc)(struct r300_winsys_cs *cs,
242 struct r300_winsys_cs_handle *buf,
243 enum r300_buffer_domain rd,
244 enum r300_buffer_domain wd);
245
246 /**
247 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
248 * added so far.
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_cs_handle *buf);
264
265 /**
266 * Flush a command stream.
267 *
268 * \param cs A command stream to flush.
269 * \param flags, R300_FLUSH_ASYNC or 0.
270 */
271 void (*cs_flush)(struct r300_winsys_cs *cs, unsigned flags);
272
273 /**
274 * Set a flush callback which is called from winsys when flush is
275 * required.
276 *
277 * \param cs A command stream to set the callback for.
278 * \param flush A flush callback function associated with the command stream.
279 * \param user A user pointer that will be passed to the flush callback.
280 */
281 void (*cs_set_flush)(struct r300_winsys_cs *cs,
282 void (*flush)(void *ctx, unsigned flags),
283 void *user);
284
285 /**
286 * Return TRUE if a buffer is referenced by a command stream.
287 *
288 * \param cs A command stream.
289 * \param buf A winsys buffer.
290 */
291 boolean (*cs_is_buffer_referenced)(struct r300_winsys_cs *cs,
292 struct r300_winsys_cs_handle *buf);
293 };
294
295 #endif /* R300_WINSYS_H */