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 #define R300_MAX_CMDBUF_DWORDS (16 * 1024)
39 struct r300_winsys_screen
;
41 struct r300_winsys_buffer
; /* for map/unmap etc. */
42 struct r300_winsys_cs_buffer
; /* for write_reloc etc. */
44 struct r300_winsys_cs
{
45 unsigned cdw
; /* Number of used dwords. */
46 uint32_t *buf
; /* The command buffer. */
53 R300_VID_SQUARE_TILING_SUPPORT
,
59 enum r300_reference_domain
{ /* bitfield */
64 struct r300_winsys_screen
{
66 * Destroy this winsys.
68 * \param ws The winsys this function is called from.
70 void (*destroy
)(struct r300_winsys_screen
*ws
);
73 * Query a system value from a winsys.
75 * \param ws The winsys this function is called from.
76 * \param vid One of the R300_VID_* enums.
78 uint32_t (*get_value
)(struct r300_winsys_screen
*ws
,
79 enum r300_value_id vid
);
81 /**************************************************************************
82 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
84 * Remember that gallium gets to choose the interface it needs, and the
85 * window systems must then implement that interface (rather than the
86 * other way around...).
87 *************************************************************************/
90 * Create a buffer object.
92 * \param ws The winsys this function is called from.
93 * \param size The size to allocate.
94 * \param alignment An alignment of the buffer in memory.
95 * \param bind A bitmask of the PIPE_BIND_* flags.
96 * \param usage A bitmask of the PIPE_USAGE_* flags.
97 * \param domain A bitmask of the R300_DOMAIN_* flags.
98 * \return The created buffer object.
100 struct r300_winsys_buffer
*(*buffer_create
)(struct r300_winsys_screen
*ws
,
105 enum r300_buffer_domain domain
);
107 struct r300_winsys_cs_buffer
*(*buffer_get_cs_handle
)(
108 struct r300_winsys_screen
*ws
,
109 struct r300_winsys_buffer
*buf
);
112 * Reference a buffer object (assign with reference counting).
114 * \param ws The winsys this function is called from.
115 * \param pdst A destination pointer to set the source buffer to.
116 * \param src A source buffer object.
118 void (*buffer_reference
)(struct r300_winsys_screen
*ws
,
119 struct r300_winsys_buffer
**pdst
,
120 struct r300_winsys_buffer
*src
);
123 * Map the entire data store of a buffer object into the client's address
126 * \param ws The winsys this function is called from.
127 * \param buf A winsys buffer object to map.
128 * \param cs A command stream to flush if the buffer is referenced by it.
129 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
130 * \return The pointer at the beginning of the buffer.
132 void *(*buffer_map
)(struct r300_winsys_screen
*ws
,
133 struct r300_winsys_buffer
*buf
,
134 struct r300_winsys_cs
*cs
,
135 enum pipe_transfer_usage usage
);
138 * Unmap a buffer object from the client's address space.
140 * \param ws The winsys this function is called from.
141 * \param buf A winsys buffer object to unmap.
143 void (*buffer_unmap
)(struct r300_winsys_screen
*ws
,
144 struct r300_winsys_buffer
*buf
);
147 * Wait for a buffer object until it is not used by a GPU. This is
148 * equivalent to a fence placed after the last command using the buffer,
149 * and synchronizing to the fence.
151 * \param ws The winsys this function is called from.
152 * \param buf A winsys buffer object to wait for.
154 void (*buffer_wait
)(struct r300_winsys_screen
*ws
,
155 struct r300_winsys_buffer
*buf
);
158 * Return tiling flags describing a memory layout of a buffer object.
160 * \param ws The winsys this function is called from.
161 * \param buf A winsys buffer object to get the flags from.
162 * \param macrotile A pointer to the return value of the microtile flag.
163 * \param microtile A pointer to the return value of the macrotile flag.
165 * \note microtile and macrotile are not bitmasks!
167 void (*buffer_get_tiling
)(struct r300_winsys_screen
*ws
,
168 struct r300_winsys_buffer
*buf
,
169 enum r300_buffer_tiling
*microtile
,
170 enum r300_buffer_tiling
*macrotile
);
173 * Set tiling flags describing a memory layout of a buffer object.
175 * \param ws The winsys this function is called from.
176 * \param buf A winsys buffer object to set the flags for.
177 * \param macrotile A macrotile flag.
178 * \param microtile A microtile flag.
179 * \param stride A stride of the buffer in bytes, for texturing.
181 * \note microtile and macrotile are not bitmasks!
183 void (*buffer_set_tiling
)(struct r300_winsys_screen
*ws
,
184 struct r300_winsys_buffer
*buf
,
185 enum r300_buffer_tiling microtile
,
186 enum r300_buffer_tiling macrotile
,
190 * Get a winsys buffer from a winsys handle. The internal structure
191 * of the handle is platform-specific and only a winsys should access it.
193 * \param ws The winsys this function is called from.
194 * \param whandle A winsys handle pointer as was received from a state
196 * \param stride The returned buffer stride in bytes.
197 * \param size The returned buffer size.
199 struct r300_winsys_buffer
*(*buffer_from_handle
)(struct r300_winsys_screen
*ws
,
200 struct winsys_handle
*whandle
,
205 * Get a winsys handle from a winsys buffer. The internal structure
206 * of the handle is platform-specific and only a winsys should access it.
208 * \param ws The winsys this function is called from.
209 * \param buf A winsys buffer object to get the handle from.
210 * \param whandle A winsys handle pointer.
211 * \param stride A stride of the buffer in bytes, for texturing.
212 * \return TRUE on success.
214 boolean (*buffer_get_handle
)(struct r300_winsys_screen
*ws
,
215 struct r300_winsys_buffer
*buf
,
217 struct winsys_handle
*whandle
);
219 /**************************************************************************
220 * Command submission.
222 * Each pipe context should create its own command stream and submit
223 * commands independently of other contexts.
224 *************************************************************************/
227 * Create a command stream.
229 * \param ws The winsys this function is called from.
231 struct r300_winsys_cs
*(*cs_create
)(struct r300_winsys_screen
*ws
);
234 * Destroy a command stream.
236 * \param cs A command stream to destroy.
238 void (*cs_destroy
)(struct r300_winsys_cs
*cs
);
241 * Add a buffer object to the list of buffers to validate.
243 * \param cs A command stream to add buffer for validation against.
244 * \param buf A winsys buffer to validate.
245 * \param rd A read domain containing a bitmask
246 * of the R300_DOMAIN_* flags.
247 * \param wd A write domain containing a bitmask
248 * of the R300_DOMAIN_* flags.
250 void (*cs_add_buffer
)(struct r300_winsys_cs
*cs
,
251 struct r300_winsys_cs_buffer
*buf
,
252 enum r300_buffer_domain rd
,
253 enum r300_buffer_domain wd
);
256 * Revalidate all currently set up winsys buffers.
257 * Returns TRUE if a flush is required.
259 * \param cs A command stream to validate.
261 boolean (*cs_validate
)(struct r300_winsys_cs
*cs
);
264 * Write a relocated dword to a command buffer.
266 * \param cs A command stream the relocation is written to.
267 * \param buf A winsys buffer to write the relocation for.
268 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
269 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
271 void (*cs_write_reloc
)(struct r300_winsys_cs
*cs
,
272 struct r300_winsys_cs_buffer
*buf
,
273 enum r300_buffer_domain rd
,
274 enum r300_buffer_domain wd
);
277 * Flush a command stream.
279 * \param cs A command stream to flush.
281 void (*cs_flush
)(struct r300_winsys_cs
*cs
);
284 * Set a flush callback which is called from winsys when flush is
287 * \param cs A command stream to set the callback for.
288 * \param flush A flush callback function associated with the command stream.
289 * \param user A user pointer that will be passed to the flush callback.
291 void (*cs_set_flush
)(struct r300_winsys_cs
*cs
,
292 void (*flush
)(void *),
296 * Reset the list of buffer objects to validate, usually called
297 * prior to adding buffer objects for validation.
299 * \param cs A command stream to reset buffers for.
301 void (*cs_reset_buffers
)(struct r300_winsys_cs
*cs
);
304 * Return TRUE if a buffer is referenced by a command stream or by hardware
305 * (i.e. is busy), based on the domain parameter.
307 * \param cs A command stream.
308 * \param buf A winsys buffer.
309 * \param domain A bitmask of the R300_REF_* enums.
311 boolean (*cs_is_buffer_referenced
)(struct r300_winsys_cs
*cs
,
312 struct r300_winsys_cs_buffer
*buf
,
313 enum r300_reference_domain domain
);
316 #endif /* R300_WINSYS_H */