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"
36 struct r300_winsys_screen
;
38 struct r300_winsys_buffer
;
40 struct r300_winsys_cs
{
41 uint32_t *ptr
; /* Pointer to the beginning of the CS. */
42 unsigned cdw
; /* Number of used dwords. */
43 unsigned ndw
; /* Size of the CS in dwords. */
50 R300_VID_SQUARE_TILING_SUPPORT
,
56 enum r300_reference_domain
{ /* bitfield */
61 struct r300_winsys_screen
{
63 * Destroy this winsys.
65 * \param ws The winsys this function is called from.
67 void (*destroy
)(struct r300_winsys_screen
*ws
);
70 * Query a system value from a winsys.
72 * \param ws The winsys this function is called from.
73 * \param vid One of the R300_VID_* enums.
75 uint32_t (*get_value
)(struct r300_winsys_screen
*ws
,
76 enum r300_value_id vid
);
78 /**************************************************************************
79 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
81 * Remember that gallium gets to choose the interface it needs, and the
82 * window systems must then implement that interface (rather than the
83 * other way around...).
84 *************************************************************************/
87 * Create a buffer object.
89 * \param ws The winsys this function is called from.
90 * \param size The size to allocate.
91 * \param alignment An alignment of the buffer in memory.
92 * \param bind A bitmask of the PIPE_BIND_* flags.
93 * \param usage A bitmask of the PIPE_USAGE_* flags.
94 * \param domain A bitmask of the R300_DOMAIN_* flags.
95 * \return The created buffer object.
97 struct r300_winsys_buffer
*(*buffer_create
)(struct r300_winsys_screen
*ws
,
102 enum r300_buffer_domain domain
);
105 * Reference a buffer object (assign with reference counting).
107 * \param ws The winsys this function is called from.
108 * \param pdst A destination pointer to set the source buffer to.
109 * \param src A source buffer object.
111 void (*buffer_reference
)(struct r300_winsys_screen
*ws
,
112 struct r300_winsys_buffer
**pdst
,
113 struct r300_winsys_buffer
*src
);
116 * Map the entire data store of a buffer object into the client's address
119 * \param ws The winsys this function is called from.
120 * \param buf A winsys buffer object to map.
121 * \param cs A command stream to flush if the buffer is referenced by it.
122 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
123 * \return The pointer at the beginning of the buffer.
125 void *(*buffer_map
)(struct r300_winsys_screen
*ws
,
126 struct r300_winsys_buffer
*buf
,
127 struct r300_winsys_cs
*cs
,
128 enum pipe_transfer_usage usage
);
131 * Unmap a buffer object from the client's address space.
133 * \param ws The winsys this function is called from.
134 * \param buf A winsys buffer object to unmap.
136 void (*buffer_unmap
)(struct r300_winsys_screen
*ws
,
137 struct r300_winsys_buffer
*buf
);
140 * Wait for a buffer object until it is not used by a GPU. This is
141 * equivalent to a fence placed after the last command using the buffer,
142 * and synchronizing to the fence.
144 * \param ws The winsys this function is called from.
145 * \param buf A winsys buffer object to wait for.
147 void (*buffer_wait
)(struct r300_winsys_screen
*ws
,
148 struct r300_winsys_buffer
*buf
);
151 * Return tiling flags describing a memory layout of a buffer object.
153 * \param ws The winsys this function is called from.
154 * \param buf A winsys buffer object to get the flags from.
155 * \param macrotile A pointer to the return value of the microtile flag.
156 * \param microtile A pointer to the return value of the macrotile flag.
158 * \note microtile and macrotile are not bitmasks!
160 void (*buffer_get_tiling
)(struct r300_winsys_screen
*ws
,
161 struct r300_winsys_buffer
*buf
,
162 enum r300_buffer_tiling
*microtile
,
163 enum r300_buffer_tiling
*macrotile
);
166 * Set tiling flags describing a memory layout of a buffer object.
168 * \param ws The winsys this function is called from.
169 * \param buf A winsys buffer object to set the flags for.
170 * \param macrotile A macrotile flag.
171 * \param microtile A microtile flag.
172 * \param stride A stride of the buffer in bytes, for texturing.
174 * \note microtile and macrotile are not bitmasks!
176 void (*buffer_set_tiling
)(struct r300_winsys_screen
*ws
,
177 struct r300_winsys_buffer
*buf
,
178 enum r300_buffer_tiling microtile
,
179 enum r300_buffer_tiling macrotile
,
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.
186 * \param ws The winsys this function is called from.
187 * \param whandle A winsys handle pointer as was received from a state
189 * \param stride The returned buffer stride in bytes.
190 * \param size The returned buffer size.
192 struct r300_winsys_buffer
*(*buffer_from_handle
)(struct r300_winsys_screen
*ws
,
193 struct winsys_handle
*whandle
,
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.
201 * \param ws The winsys this function is called from.
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.
207 boolean (*buffer_get_handle
)(struct r300_winsys_screen
*ws
,
208 struct r300_winsys_buffer
*buf
,
210 struct winsys_handle
*whandle
);
212 /**************************************************************************
213 * Command submission.
215 * Each pipe context should create its own command stream and submit
216 * commands independently of other contexts.
217 *************************************************************************/
220 * Create a command stream.
222 * \param ws The winsys this function is called from.
224 struct r300_winsys_cs
*(*cs_create
)(struct r300_winsys_screen
*ws
);
227 * Destroy a command stream.
229 * \param cs A command stream to destroy.
231 void (*cs_destroy
)(struct r300_winsys_cs
*cs
);
234 * Add a buffer object to the list of buffers to validate.
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
239 * of the R300_DOMAIN_* flags.
240 * \param wd A write domain containing a bitmask
241 * of the R300_DOMAIN_* flags.
243 void (*cs_add_buffer
)(struct r300_winsys_cs
*cs
,
244 struct r300_winsys_buffer
*buf
,
245 enum r300_buffer_domain rd
,
246 enum r300_buffer_domain wd
);
249 * Revalidate all currently set up winsys buffers.
250 * Returns TRUE if a flush is required.
252 * \param cs A command stream to validate.
254 boolean (*cs_validate
)(struct r300_winsys_cs
*cs
);
257 * Write a relocated dword to a command buffer.
259 * \param cs A command stream the relocation is written to.
260 * \param buf A winsys buffer to write the relocation for.
261 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
262 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
264 void (*cs_write_reloc
)(struct r300_winsys_cs
*cs
,
265 struct r300_winsys_buffer
*buf
,
266 enum r300_buffer_domain rd
,
267 enum r300_buffer_domain wd
);
270 * Flush a command stream.
272 * \param cs A command stream to flush.
274 void (*cs_flush
)(struct r300_winsys_cs
*cs
);
277 * Set a flush callback which is called from winsys when flush is
280 * \param cs A command stream to set the callback for.
281 * \param flush A flush callback function associated with the command stream.
282 * \param user A user pointer that will be passed to the flush callback.
284 void (*cs_set_flush
)(struct r300_winsys_cs
*cs
,
285 void (*flush
)(void *),
289 * Reset the list of buffer objects to validate, usually called
290 * prior to adding buffer objects for validation.
292 * \param cs A command stream to reset buffers for.
294 void (*cs_reset_buffers
)(struct r300_winsys_cs
*cs
);
297 * Return TRUE if a buffer is referenced by a command stream or by hardware
298 * (i.e. is busy), based on the domain parameter.
300 * \param cs A command stream.
301 * \param buf A winsys buffer.
302 * \param domain A bitmask of the R300_REF_* enums.
304 boolean (*cs_is_buffer_referenced
)(struct r300_winsys_cs
*cs
,
305 struct r300_winsys_buffer
*buf
,
306 enum r300_reference_domain domain
);
309 #endif /* R300_WINSYS_H */