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. */
24 #ifndef RADEON_WINSYS_H
25 #define RADEON_WINSYS_H
27 /* The public winsys interface header for the radeon driver. */
29 #include "pipebuffer/pb_bufmgr.h"
30 #include "pipe/p_defines.h"
31 #include "pipe/p_state.h"
33 #define RADEON_MAX_CMDBUF_DWORDS (16 * 1024)
34 #define RADEON_FLUSH_ASYNC (1 << 0)
37 enum radeon_bo_layout
{
38 RADEON_LAYOUT_LINEAR
= 0,
40 RADEON_LAYOUT_SQUARETILED
,
45 enum radeon_bo_domain
{ /* bitfield */
46 RADEON_DOMAIN_GTT
= 2,
47 RADEON_DOMAIN_VRAM
= 4
51 struct radeon_winsys_cs_handle
; /* for write_reloc etc. */
53 struct radeon_winsys_cs
{
54 unsigned cdw
; /* Number of used dwords. */
55 uint32_t *buf
; /* The command buffer. */
58 enum radeon_value_id
{
60 RADEON_VID_R300_GB_PIPES
,
61 RADEON_VID_R300_Z_PIPES
,
66 RADEON_VID_DRM_PATCHLEVEL
,
68 /* These should probably go away: */
72 * - GB_Z_PEQ_CONFIG on rv350->r4xx
73 * - R500 FG_ALPHA_VALUE
81 * - R500 US_FORMAT regs
82 * - R500 ARGB2101010 colorbuffer
91 RADEON_VID_CAN_HYPERZ
, /* ZMask + HiZ */
92 RADEON_VID_CAN_AACOMPRESS
, /* CMask */
95 struct radeon_winsys
{
97 * Destroy this winsys.
99 * \param ws The winsys this function is called from.
101 void (*destroy
)(struct radeon_winsys
*ws
);
104 * Query a system value from a winsys.
106 * \param ws The winsys this function is called from.
107 * \param vid One of the RADEON_VID_* enums.
109 uint32_t (*get_value
)(struct radeon_winsys
*ws
,
110 enum radeon_value_id vid
);
112 /**************************************************************************
113 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
115 * Remember that gallium gets to choose the interface it needs, and the
116 * window systems must then implement that interface (rather than the
117 * other way around...).
118 *************************************************************************/
121 * Create a buffer object.
123 * \param ws The winsys this function is called from.
124 * \param size The size to allocate.
125 * \param alignment An alignment of the buffer in memory.
126 * \param bind A bitmask of the PIPE_BIND_* flags.
127 * \param usage A bitmask of the PIPE_USAGE_* flags.
128 * \param domain A bitmask of the RADEON_DOMAIN_* flags.
129 * \return The created buffer object.
131 struct pb_buffer
*(*buffer_create
)(struct radeon_winsys
*ws
,
136 enum radeon_bo_domain domain
);
138 struct radeon_winsys_cs_handle
*(*buffer_get_cs_handle
)(
139 struct pb_buffer
*buf
);
142 * Map the entire data store of a buffer object into the client's address
145 * \param buf A winsys buffer object to map.
146 * \param cs A command stream to flush if the buffer is referenced by it.
147 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
148 * \return The pointer at the beginning of the buffer.
150 void *(*buffer_map
)(struct pb_buffer
*buf
,
151 struct radeon_winsys_cs
*cs
,
152 enum pipe_transfer_usage usage
);
155 * Unmap a buffer object from the client's address space.
157 * \param buf A winsys buffer object to unmap.
159 void (*buffer_unmap
)(struct pb_buffer
*buf
);
162 * Return TRUE if a buffer object is being used by the GPU.
164 * \param buf A winsys buffer object.
166 boolean (*buffer_is_busy
)(struct pb_buffer
*buf
);
169 * Wait for a buffer object until it is not used by a GPU. This is
170 * equivalent to a fence placed after the last command using the buffer,
171 * and synchronizing to the fence.
173 * \param buf A winsys buffer object to wait for.
175 void (*buffer_wait
)(struct pb_buffer
*buf
);
178 * Return tiling flags describing a memory layout of a buffer object.
180 * \param buf A winsys buffer object to get the flags from.
181 * \param macrotile A pointer to the return value of the microtile flag.
182 * \param microtile A pointer to the return value of the macrotile flag.
184 * \note microtile and macrotile are not bitmasks!
186 void (*buffer_get_tiling
)(struct pb_buffer
*buf
,
187 enum radeon_bo_layout
*microtile
,
188 enum radeon_bo_layout
*macrotile
);
191 * Set tiling flags describing a memory layout of a buffer object.
193 * \param buf A winsys buffer object to set the flags for.
194 * \param cs A command stream to flush if the buffer is referenced by it.
195 * \param macrotile A macrotile flag.
196 * \param microtile A microtile flag.
197 * \param stride A stride of the buffer in bytes, for texturing.
199 * \note microtile and macrotile are not bitmasks!
201 void (*buffer_set_tiling
)(struct pb_buffer
*buf
,
202 struct radeon_winsys_cs
*cs
,
203 enum radeon_bo_layout microtile
,
204 enum radeon_bo_layout macrotile
,
208 * Get a winsys buffer from a winsys handle. The internal structure
209 * of the handle is platform-specific and only a winsys should access it.
211 * \param ws The winsys this function is called from.
212 * \param whandle A winsys handle pointer as was received from a state
214 * \param stride The returned buffer stride in bytes.
215 * \param size The returned buffer size.
217 struct pb_buffer
*(*buffer_from_handle
)(struct radeon_winsys
*ws
,
218 struct winsys_handle
*whandle
,
223 * Get a winsys handle from a winsys buffer. The internal structure
224 * of the handle is platform-specific and only a winsys should access it.
226 * \param buf A winsys buffer object to get the handle from.
227 * \param whandle A winsys handle pointer.
228 * \param stride A stride of the buffer in bytes, for texturing.
229 * \return TRUE on success.
231 boolean (*buffer_get_handle
)(struct pb_buffer
*buf
,
233 struct winsys_handle
*whandle
);
235 /**************************************************************************
236 * Command submission.
238 * Each pipe context should create its own command stream and submit
239 * commands independently of other contexts.
240 *************************************************************************/
243 * Create a command stream.
245 * \param ws The winsys this function is called from.
247 struct radeon_winsys_cs
*(*cs_create
)(struct radeon_winsys
*ws
);
250 * Destroy a command stream.
252 * \param cs A command stream to destroy.
254 void (*cs_destroy
)(struct radeon_winsys_cs
*cs
);
257 * Add a new buffer relocation. Every relocation must first be added
258 * before it can be written.
260 * \param cs A command stream to add buffer for validation against.
261 * \param buf A winsys buffer to validate.
262 * \param rd A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
263 * \param wd A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
265 void (*cs_add_reloc
)(struct radeon_winsys_cs
*cs
,
266 struct radeon_winsys_cs_handle
*buf
,
267 enum radeon_bo_domain rd
,
268 enum radeon_bo_domain wd
);
271 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
274 * \param cs A command stream to validate.
276 boolean (*cs_validate
)(struct radeon_winsys_cs
*cs
);
279 * Write a relocated dword to a command buffer.
281 * \param cs A command stream the relocation is written to.
282 * \param buf A winsys buffer to write the relocation for.
283 * \param rd A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
284 * \param wd A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
286 void (*cs_write_reloc
)(struct radeon_winsys_cs
*cs
,
287 struct radeon_winsys_cs_handle
*buf
);
290 * Flush a command stream.
292 * \param cs A command stream to flush.
293 * \param flags, RADEON_FLUSH_ASYNC or 0.
295 void (*cs_flush
)(struct radeon_winsys_cs
*cs
, unsigned flags
);
298 * Set a flush callback which is called from winsys when flush is
301 * \param cs A command stream to set the callback for.
302 * \param flush A flush callback function associated with the command stream.
303 * \param user A user pointer that will be passed to the flush callback.
305 void (*cs_set_flush
)(struct radeon_winsys_cs
*cs
,
306 void (*flush
)(void *ctx
, unsigned flags
),
310 * Return TRUE if a buffer is referenced by a command stream.
312 * \param cs A command stream.
313 * \param buf A winsys buffer.
315 boolean (*cs_is_buffer_referenced
)(struct radeon_winsys_cs
*cs
,
316 struct radeon_winsys_cs_handle
*buf
);