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
;
41 struct r300_winsys_cs
{
42 uint32_t *ptr
; /* Pointer to the beginning of the CS. */
43 unsigned cdw
; /* Number of used dwords. */
44 unsigned ndw
; /* Size of the CS in dwords. */
51 R300_VID_SQUARE_TILING_SUPPORT
,
57 enum r300_reference_domain
{ /* bitfield */
62 struct r300_winsys_screen
{
64 * Destroy this winsys.
66 * \param ws The winsys this function is called from.
68 void (*destroy
)(struct r300_winsys_screen
*ws
);
71 * Query a system value from a winsys.
73 * \param ws The winsys this function is called from.
74 * \param vid One of the R300_VID_* enums.
76 uint32_t (*get_value
)(struct r300_winsys_screen
*ws
,
77 enum r300_value_id vid
);
79 /**************************************************************************
80 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
82 * Remember that gallium gets to choose the interface it needs, and the
83 * window systems must then implement that interface (rather than the
84 * other way around...).
85 *************************************************************************/
88 * Create a buffer object.
90 * \param ws The winsys this function is called from.
91 * \param size The size to allocate.
92 * \param alignment An alignment of the buffer in memory.
93 * \param bind A bitmask of the PIPE_BIND_* flags.
94 * \param usage A bitmask of the PIPE_USAGE_* flags.
95 * \param domain A bitmask of the R300_DOMAIN_* flags.
96 * \return The created buffer object.
98 struct r300_winsys_buffer
*(*buffer_create
)(struct r300_winsys_screen
*ws
,
103 enum r300_buffer_domain domain
);
106 * Reference a buffer object (assign with reference counting).
108 * \param ws The winsys this function is called from.
109 * \param pdst A destination pointer to set the source buffer to.
110 * \param src A source buffer object.
112 void (*buffer_reference
)(struct r300_winsys_screen
*ws
,
113 struct r300_winsys_buffer
**pdst
,
114 struct r300_winsys_buffer
*src
);
117 * Map the entire data store of a buffer object into the client's address
120 * \param ws The winsys this function is called from.
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.
126 void *(*buffer_map
)(struct r300_winsys_screen
*ws
,
127 struct r300_winsys_buffer
*buf
,
128 struct r300_winsys_cs
*cs
,
129 enum pipe_transfer_usage usage
);
132 * Unmap a buffer object from the client's address space.
134 * \param ws The winsys this function is called from.
135 * \param buf A winsys buffer object to unmap.
137 void (*buffer_unmap
)(struct r300_winsys_screen
*ws
,
138 struct r300_winsys_buffer
*buf
);
141 * Wait for a buffer object until it is not used by a GPU. This is
142 * equivalent to a fence placed after the last command using the buffer,
143 * and synchronizing to the fence.
145 * \param ws The winsys this function is called from.
146 * \param buf A winsys buffer object to wait for.
148 void (*buffer_wait
)(struct r300_winsys_screen
*ws
,
149 struct r300_winsys_buffer
*buf
);
152 * Return tiling flags describing a memory layout of a buffer object.
154 * \param ws The winsys this function is called from.
155 * \param buf A winsys buffer object to get the flags from.
156 * \param macrotile A pointer to the return value of the microtile flag.
157 * \param microtile A pointer to the return value of the macrotile flag.
159 * \note microtile and macrotile are not bitmasks!
161 void (*buffer_get_tiling
)(struct r300_winsys_screen
*ws
,
162 struct r300_winsys_buffer
*buf
,
163 enum r300_buffer_tiling
*microtile
,
164 enum r300_buffer_tiling
*macrotile
);
167 * Set tiling flags describing a memory layout of a buffer object.
169 * \param ws The winsys this function is called from.
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.
175 * \note microtile and macrotile are not bitmasks!
177 void (*buffer_set_tiling
)(struct r300_winsys_screen
*ws
,
178 struct r300_winsys_buffer
*buf
,
179 enum r300_buffer_tiling microtile
,
180 enum r300_buffer_tiling macrotile
,
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.
187 * \param ws The winsys this function is called from.
188 * \param whandle A winsys handle pointer as was received from a state
190 * \param stride The returned buffer stride in bytes.
191 * \param size The returned buffer size.
193 struct r300_winsys_buffer
*(*buffer_from_handle
)(struct r300_winsys_screen
*ws
,
194 struct winsys_handle
*whandle
,
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.
202 * \param ws The winsys this function is called from.
203 * \param buf A winsys buffer object to get the handle from.
204 * \param whandle A winsys handle pointer.
205 * \param stride A stride of the buffer in bytes, for texturing.
206 * \return TRUE on success.
208 boolean (*buffer_get_handle
)(struct r300_winsys_screen
*ws
,
209 struct r300_winsys_buffer
*buf
,
211 struct winsys_handle
*whandle
);
213 /**************************************************************************
214 * Command submission.
216 * Each pipe context should create its own command stream and submit
217 * commands independently of other contexts.
218 *************************************************************************/
221 * Create a command stream.
223 * \param ws The winsys this function is called from.
225 struct r300_winsys_cs
*(*cs_create
)(struct r300_winsys_screen
*ws
);
228 * Destroy a command stream.
230 * \param cs A command stream to destroy.
232 void (*cs_destroy
)(struct r300_winsys_cs
*cs
);
235 * Add a buffer object to the list of buffers to validate.
237 * \param cs A command stream to add buffer for validation against.
238 * \param buf A winsys buffer to validate.
239 * \param rd A read domain containing a bitmask
240 * of the R300_DOMAIN_* flags.
241 * \param wd A write domain containing a bitmask
242 * of the R300_DOMAIN_* flags.
244 void (*cs_add_buffer
)(struct r300_winsys_cs
*cs
,
245 struct r300_winsys_buffer
*buf
,
246 enum r300_buffer_domain rd
,
247 enum r300_buffer_domain wd
);
250 * Revalidate all currently set up winsys buffers.
251 * Returns TRUE if a flush is required.
253 * \param cs A command stream to validate.
255 boolean (*cs_validate
)(struct r300_winsys_cs
*cs
);
258 * Write a relocated dword to a command buffer.
260 * \param cs A command stream the relocation is written to.
261 * \param buf A winsys buffer to write the relocation for.
262 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
263 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
265 void (*cs_write_reloc
)(struct r300_winsys_cs
*cs
,
266 struct r300_winsys_buffer
*buf
,
267 enum r300_buffer_domain rd
,
268 enum r300_buffer_domain wd
);
271 * Flush a command stream.
273 * \param cs A command stream to flush.
275 void (*cs_flush
)(struct r300_winsys_cs
*cs
);
278 * Set a flush callback which is called from winsys when flush is
281 * \param cs A command stream to set the callback for.
282 * \param flush A flush callback function associated with the command stream.
283 * \param user A user pointer that will be passed to the flush callback.
285 void (*cs_set_flush
)(struct r300_winsys_cs
*cs
,
286 void (*flush
)(void *),
290 * Reset the list of buffer objects to validate, usually called
291 * prior to adding buffer objects for validation.
293 * \param cs A command stream to reset buffers for.
295 void (*cs_reset_buffers
)(struct r300_winsys_cs
*cs
);
298 * Return TRUE if a buffer is referenced by a command stream or by hardware
299 * (i.e. is busy), based on the domain parameter.
301 * \param cs A command stream.
302 * \param buf A winsys buffer.
303 * \param domain A bitmask of the R300_REF_* enums.
305 boolean (*cs_is_buffer_referenced
)(struct r300_winsys_cs
*cs
,
306 struct r300_winsys_buffer
*buf
,
307 enum r300_reference_domain domain
);
310 #endif /* R300_WINSYS_H */