2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
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:
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
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. */
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. */
31 #include "pipe/p_defines.h"
32 #include "pipe/p_state.h"
34 #include "r300_defines.h"
37 struct r300_winsys_screen
;
39 struct r300_winsys_buffer
; /* for map/unmap etc. */
40 struct r300_winsys_cs_buffer
; /* for write_reloc etc. */
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. */
52 R300_VID_SQUARE_TILING_SUPPORT
,
58 enum r300_reference_domain
{ /* bitfield */
63 struct r300_winsys_screen
{
65 * Destroy this winsys.
67 * \param ws The winsys this function is called from.
69 void (*destroy
)(struct r300_winsys_screen
*ws
);
72 * Query a system value from a winsys.
74 * \param ws The winsys this function is called from.
75 * \param vid One of the R300_VID_* enums.
77 uint32_t (*get_value
)(struct r300_winsys_screen
*ws
,
78 enum r300_value_id vid
);
80 /**************************************************************************
81 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
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 *************************************************************************/
89 * Create a buffer object.
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.
99 struct r300_winsys_buffer
*(*buffer_create
)(struct r300_winsys_screen
*ws
,
104 enum r300_buffer_domain domain
);
106 struct r300_winsys_cs_buffer
*(*buffer_get_cs_handle
)(
107 struct r300_winsys_screen
*ws
,
108 struct r300_winsys_buffer
*buf
);
111 * Reference a buffer object (assign with reference counting).
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.
117 void (*buffer_reference
)(struct r300_winsys_screen
*ws
,
118 struct r300_winsys_buffer
**pdst
,
119 struct r300_winsys_buffer
*src
);
122 * Map the entire data store of a buffer object into the client's address
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.
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
);
137 * Unmap a buffer object from the client's address space.
139 * \param ws The winsys this function is called from.
140 * \param buf A winsys buffer object to unmap.
142 void (*buffer_unmap
)(struct r300_winsys_screen
*ws
,
143 struct r300_winsys_buffer
*buf
);
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.
150 * \param ws The winsys this function is called from.
151 * \param buf A winsys buffer object to wait for.
153 void (*buffer_wait
)(struct r300_winsys_screen
*ws
,
154 struct r300_winsys_buffer
*buf
);
157 * Return tiling flags describing a memory layout of a buffer object.
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.
164 * \note microtile and macrotile are not bitmasks!
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
);
172 * Set tiling flags describing a memory layout of a buffer object.
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.
180 * \note microtile and macrotile are not bitmasks!
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
,
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.
192 * \param ws The winsys this function is called from.
193 * \param whandle A winsys handle pointer as was received from a state
195 * \param stride The returned buffer stride in bytes.
196 * \param size The returned buffer size.
198 struct r300_winsys_buffer
*(*buffer_from_handle
)(struct r300_winsys_screen
*ws
,
199 struct winsys_handle
*whandle
,
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.
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.
213 boolean (*buffer_get_handle
)(struct r300_winsys_screen
*ws
,
214 struct r300_winsys_buffer
*buf
,
216 struct winsys_handle
*whandle
);
218 /**************************************************************************
219 * Command submission.
221 * Each pipe context should create its own command stream and submit
222 * commands independently of other contexts.
223 *************************************************************************/
226 * Create a command stream.
228 * \param ws The winsys this function is called from.
230 struct r300_winsys_cs
*(*cs_create
)(struct r300_winsys_screen
*ws
);
233 * Destroy a command stream.
235 * \param cs A command stream to destroy.
237 void (*cs_destroy
)(struct r300_winsys_cs
*cs
);
240 * Add a buffer object to the list of buffers to validate.
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.
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
);
255 * Revalidate all currently set up winsys buffers.
256 * Returns TRUE if a flush is required.
258 * \param cs A command stream to validate.
260 boolean (*cs_validate
)(struct r300_winsys_cs
*cs
);
263 * Write a relocated dword to a command buffer.
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.
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
);
276 * Flush a command stream.
278 * \param cs A command stream to flush.
280 void (*cs_flush
)(struct r300_winsys_cs
*cs
);
283 * Set a flush callback which is called from winsys when flush is
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.
290 void (*cs_set_flush
)(struct r300_winsys_cs
*cs
,
291 void (*flush
)(void *),
295 * Reset the list of buffer objects to validate, usually called
296 * prior to adding buffer objects for validation.
298 * \param cs A command stream to reset buffers for.
300 void (*cs_reset_buffers
)(struct r300_winsys_cs
*cs
);
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.
306 * \param cs A command stream.
307 * \param buf A winsys buffer.
308 * \param domain A bitmask of the R300_REF_* enums.
310 boolean (*cs_is_buffer_referenced
)(struct r300_winsys_cs
*cs
,
311 struct r300_winsys_cs_buffer
*buf
,
312 enum r300_reference_domain domain
);
315 #endif /* R300_WINSYS_H */