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
,
54 enum r300_reference_domain
{ /* bitfield */
59 struct r300_winsys_screen
{
61 * Destroy this winsys.
63 * \param ws The winsys this function is called from.
65 void (*destroy
)(struct r300_winsys_screen
*ws
);
68 * Query a system value from a winsys.
70 * \param ws The winsys this function is called from.
71 * \param vid One of the R300_VID_* enums.
73 uint32_t (*get_value
)(struct r300_winsys_screen
*ws
,
74 enum r300_value_id vid
);
76 /**************************************************************************
77 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
79 * Remember that gallium gets to choose the interface it needs, and the
80 * window systems must then implement that interface (rather than the
81 * other way around...).
82 *************************************************************************/
85 * Create a buffer object.
87 * \param ws The winsys this function is called from.
88 * \param size The size to allocate.
89 * \param alignment An alignment of the buffer in memory.
90 * \param bind A bitmask of the PIPE_BIND_* flags.
91 * \param usage A bitmask of the PIPE_USAGE_* flags.
92 * \param domain A bitmask of the R300_DOMAIN_* flags.
93 * \return The created buffer object.
95 struct r300_winsys_buffer
*(*buffer_create
)(struct r300_winsys_screen
*ws
,
100 enum r300_buffer_domain domain
);
103 * Reference a buffer object (assign with reference counting).
105 * \param ws The winsys this function is called from.
106 * \param pdst A destination pointer to set the source buffer to.
107 * \param src A source buffer object.
109 void (*buffer_reference
)(struct r300_winsys_screen
*ws
,
110 struct r300_winsys_buffer
**pdst
,
111 struct r300_winsys_buffer
*src
);
114 * Map the entire data store of a buffer object into the client's address
117 * \param ws The winsys this function is called from.
118 * \param buf A winsys buffer object to map.
119 * \param cs A command stream to flush if the buffer is referenced by it.
120 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
121 * \return The pointer at the beginning of the buffer.
123 void *(*buffer_map
)(struct r300_winsys_screen
*ws
,
124 struct r300_winsys_buffer
*buf
,
125 struct r300_winsys_cs
*cs
,
126 enum pipe_transfer_usage usage
);
129 * Unmap a buffer object from the client's address space.
131 * \param ws The winsys this function is called from.
132 * \param buf A winsys buffer object to unmap.
134 void (*buffer_unmap
)(struct r300_winsys_screen
*ws
,
135 struct r300_winsys_buffer
*buf
);
138 * Wait for a buffer object until it is not used by a GPU. This is
139 * equivalent to a fence placed after the last command using the buffer,
140 * and synchronizing to the fence.
142 * \param ws The winsys this function is called from.
143 * \param buf A winsys buffer object to wait for.
145 void (*buffer_wait
)(struct r300_winsys_screen
*ws
,
146 struct r300_winsys_buffer
*buf
);
149 * Return tiling flags describing a memory layout of a buffer object.
151 * \param ws The winsys this function is called from.
152 * \param buf A winsys buffer object to get the flags from.
153 * \param macrotile A pointer to the return value of the microtile flag.
154 * \param microtile A pointer to the return value of the macrotile flag.
156 * \note microtile and macrotile are not bitmasks!
158 void (*buffer_get_tiling
)(struct r300_winsys_screen
*ws
,
159 struct r300_winsys_buffer
*buf
,
160 enum r300_buffer_tiling
*microtile
,
161 enum r300_buffer_tiling
*macrotile
);
164 * Set tiling flags describing a memory layout of a buffer object.
166 * \param ws The winsys this function is called from.
167 * \param buf A winsys buffer object to set the flags for.
168 * \param macrotile A macrotile flag.
169 * \param microtile A microtile flag.
170 * \param stride A stride of the buffer in bytes, for texturing.
172 * \note microtile and macrotile are not bitmasks!
174 void (*buffer_set_tiling
)(struct r300_winsys_screen
*ws
,
175 struct r300_winsys_buffer
*buf
,
176 enum r300_buffer_tiling microtile
,
177 enum r300_buffer_tiling macrotile
,
181 * Get a winsys buffer from a winsys handle. The internal structure
182 * of the handle is platform-specific and only a winsys should access it.
184 * \param ws The winsys this function is called from.
185 * \param whandle A winsys handle pointer as was received from a state
187 * \param stride A pointer to the stride return variable.
188 * The stride is in bytes.
190 struct r300_winsys_buffer
*(*buffer_from_handle
)(struct r300_winsys_screen
*ws
,
191 struct winsys_handle
*whandle
,
195 * Get a winsys handle from a winsys buffer. The internal structure
196 * of the handle is platform-specific and only a winsys should access it.
198 * \param ws The winsys this function is called from.
199 * \param buf A winsys buffer object to get the handle from.
200 * \param whandle A winsys handle pointer.
201 * \param stride A stride of the buffer in bytes, for texturing.
202 * \return TRUE on success.
204 boolean (*buffer_get_handle
)(struct r300_winsys_screen
*ws
,
205 struct r300_winsys_buffer
*buf
,
207 struct winsys_handle
*whandle
);
209 /**************************************************************************
210 * Command submission.
212 * Each pipe context should create its own command stream and submit
213 * commands independently of other contexts.
214 *************************************************************************/
217 * Create a command stream.
219 * \param ws The winsys this function is called from.
221 struct r300_winsys_cs
*(*cs_create
)(struct r300_winsys_screen
*ws
);
224 * Destroy a command stream.
226 * \param cs A command stream to destroy.
228 void (*cs_destroy
)(struct r300_winsys_cs
*cs
);
231 * Add a buffer object to the list of buffers to validate.
233 * \param cs A command stream to add buffer for validation against.
234 * \param buf A winsys buffer to validate.
235 * \param rd A read domain containing a bitmask
236 * of the R300_DOMAIN_* flags.
237 * \param wd A write domain containing a bitmask
238 * of the R300_DOMAIN_* flags.
240 void (*cs_add_buffer
)(struct r300_winsys_cs
*cs
,
241 struct r300_winsys_buffer
*buf
,
242 enum r300_buffer_domain rd
,
243 enum r300_buffer_domain wd
);
246 * Revalidate all currently set up winsys buffers.
247 * Returns TRUE if a flush is required.
249 * \param cs A command stream to validate.
251 boolean (*cs_validate
)(struct r300_winsys_cs
*cs
);
254 * Write a relocated dword to a command buffer.
256 * \param cs A command stream the relocation is written to.
257 * \param buf A winsys buffer to write the relocation for.
258 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
259 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
261 void (*cs_write_reloc
)(struct r300_winsys_cs
*cs
,
262 struct r300_winsys_buffer
*buf
,
263 enum r300_buffer_domain rd
,
264 enum r300_buffer_domain wd
);
267 * Flush a command stream.
269 * \param cs A command stream to flush.
271 void (*cs_flush
)(struct r300_winsys_cs
*cs
);
274 * Set a flush callback which is called from winsys when flush is
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.
281 void (*cs_set_flush
)(struct r300_winsys_cs
*cs
,
282 void (*flush
)(void *),
286 * Reset the list of buffer objects to validate, usually called
287 * prior to adding buffer objects for validation.
289 * \param cs A command stream to reset buffers for.
291 void (*cs_reset_buffers
)(struct r300_winsys_cs
*cs
);
294 * Return TRUE if a buffer is referenced by a command stream or by hardware
295 * (i.e. is busy), based on the domain parameter.
297 * \param cs A command stream.
298 * \param buf A winsys buffer.
299 * \param domain A bitmask of the R300_REF_* enums.
301 boolean (*cs_is_buffer_referenced
)(struct r300_winsys_cs
*cs
,
302 struct r300_winsys_buffer
*buf
,
303 enum r300_reference_domain domain
);
306 #endif /* R300_WINSYS_H */