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 /* R300 features in DRM.
33 * - GB_Z_PEQ_CONFIG on rv350->r4xx
34 * - R500 FG_ALPHA_VALUE
37 * - R500 US_FORMAT regs
38 * - R500 ARGB2101010 colorbuffer
43 #include "pipebuffer/pb_bufmgr.h"
44 #include "pipe/p_defines.h"
45 #include "pipe/p_state.h"
47 #define RADEON_MAX_CMDBUF_DWORDS (16 * 1024)
48 #define RADEON_FLUSH_ASYNC (1 << 0)
51 enum radeon_bo_layout
{
52 RADEON_LAYOUT_LINEAR
= 0,
54 RADEON_LAYOUT_SQUARETILED
,
59 enum radeon_bo_domain
{ /* bitfield */
60 RADEON_DOMAIN_GTT
= 2,
61 RADEON_DOMAIN_VRAM
= 4
65 struct radeon_winsys_cs_handle
; /* for write_reloc etc. */
67 struct radeon_winsys_cs
{
68 unsigned cdw
; /* Number of used dwords. */
69 uint32_t *buf
; /* The command buffer. */
76 uint32_t fd
; /* XXX transitional */
78 uint32_t drm_major
; /* version */
80 uint32_t drm_patchlevel
;
82 uint32_t r300_num_gb_pipes
;
83 uint32_t r300_num_z_pipes
;
85 uint32_t r600_num_backends
;
86 uint32_t r600_clock_crystal_freq
;
87 uint32_t r600_tiling_config
;
88 uint32_t r600_num_tile_pipes
;
89 uint32_t r600_backend_map
;
90 boolean r600_backend_map_valid
;
93 enum radeon_feature_id
{
94 RADEON_FID_R300_HYPERZ_ACCESS
, /* ZMask + HiZ */
95 RADEON_FID_R300_CMASK_ACCESS
,
98 struct radeon_winsys
{
100 * Destroy this winsys.
102 * \param ws The winsys this function is called from.
104 void (*destroy
)(struct radeon_winsys
*ws
);
107 * Query an info structure from winsys.
109 * \param ws The winsys this function is called from.
110 * \param info Return structure
112 void (*query_info
)(struct radeon_winsys
*ws
,
113 struct radeon_info
*info
);
115 /**************************************************************************
116 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
118 * Remember that gallium gets to choose the interface it needs, and the
119 * window systems must then implement that interface (rather than the
120 * other way around...).
121 *************************************************************************/
124 * Create a buffer object.
126 * \param ws The winsys this function is called from.
127 * \param size The size to allocate.
128 * \param alignment An alignment of the buffer in memory.
129 * \param bind A bitmask of the PIPE_BIND_* flags.
130 * \param domain A bitmask of the RADEON_DOMAIN_* flags.
131 * \return The created buffer object.
133 struct pb_buffer
*(*buffer_create
)(struct radeon_winsys
*ws
,
137 enum radeon_bo_domain domain
);
139 struct radeon_winsys_cs_handle
*(*buffer_get_cs_handle
)(
140 struct pb_buffer
*buf
);
143 * Map the entire data store of a buffer object into the client's address
146 * \param buf A winsys buffer object to map.
147 * \param cs A command stream to flush if the buffer is referenced by it.
148 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
149 * \return The pointer at the beginning of the buffer.
151 void *(*buffer_map
)(struct pb_buffer
*buf
,
152 struct radeon_winsys_cs
*cs
,
153 enum pipe_transfer_usage usage
);
156 * Unmap a buffer object from the client's address space.
158 * \param buf A winsys buffer object to unmap.
160 void (*buffer_unmap
)(struct pb_buffer
*buf
);
163 * Return TRUE if a buffer object is being used by the GPU.
165 * \param buf A winsys buffer object.
167 boolean (*buffer_is_busy
)(struct pb_buffer
*buf
);
170 * Wait for a buffer object until it is not used by a GPU. This is
171 * equivalent to a fence placed after the last command using the buffer,
172 * and synchronizing to the fence.
174 * \param buf A winsys buffer object to wait for.
176 void (*buffer_wait
)(struct pb_buffer
*buf
);
179 * Return tiling flags describing a memory layout of a buffer object.
181 * \param buf A winsys buffer object to get the flags from.
182 * \param macrotile A pointer to the return value of the microtile flag.
183 * \param microtile A pointer to the return value of the macrotile flag.
185 * \note microtile and macrotile are not bitmasks!
187 void (*buffer_get_tiling
)(struct pb_buffer
*buf
,
188 enum radeon_bo_layout
*microtile
,
189 enum radeon_bo_layout
*macrotile
);
192 * Set tiling flags describing a memory layout of a buffer object.
194 * \param buf A winsys buffer object to set the flags for.
195 * \param cs A command stream to flush if the buffer is referenced by it.
196 * \param macrotile A macrotile flag.
197 * \param microtile A microtile flag.
198 * \param stride A stride of the buffer in bytes, for texturing.
200 * \note microtile and macrotile are not bitmasks!
202 void (*buffer_set_tiling
)(struct pb_buffer
*buf
,
203 struct radeon_winsys_cs
*cs
,
204 enum radeon_bo_layout microtile
,
205 enum radeon_bo_layout macrotile
,
209 * Get a winsys buffer from a winsys handle. The internal structure
210 * of the handle is platform-specific and only a winsys should access it.
212 * \param ws The winsys this function is called from.
213 * \param whandle A winsys handle pointer as was received from a state
215 * \param stride The returned buffer stride in bytes.
216 * \param size The returned buffer size.
218 struct pb_buffer
*(*buffer_from_handle
)(struct radeon_winsys
*ws
,
219 struct winsys_handle
*whandle
,
224 * Get a winsys handle from a winsys buffer. The internal structure
225 * of the handle is platform-specific and only a winsys should access it.
227 * \param buf A winsys buffer object to get the handle from.
228 * \param whandle A winsys handle pointer.
229 * \param stride A stride of the buffer in bytes, for texturing.
230 * \return TRUE on success.
232 boolean (*buffer_get_handle
)(struct pb_buffer
*buf
,
234 struct winsys_handle
*whandle
);
236 /**************************************************************************
237 * Command submission.
239 * Each pipe context should create its own command stream and submit
240 * commands independently of other contexts.
241 *************************************************************************/
244 * Create a command stream.
246 * \param ws The winsys this function is called from.
248 struct radeon_winsys_cs
*(*cs_create
)(struct radeon_winsys
*ws
);
251 * Destroy a command stream.
253 * \param cs A command stream to destroy.
255 void (*cs_destroy
)(struct radeon_winsys_cs
*cs
);
258 * Add a new buffer relocation. Every relocation must first be added
259 * before it can be written.
261 * \param cs A command stream to add buffer for validation against.
262 * \param buf A winsys buffer to validate.
263 * \param rd A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
264 * \param wd A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
265 * \return Relocation index.
267 unsigned (*cs_add_reloc
)(struct radeon_winsys_cs
*cs
,
268 struct radeon_winsys_cs_handle
*buf
,
269 enum radeon_bo_domain rd
,
270 enum radeon_bo_domain wd
);
273 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
274 * added so far. If the validation fails, all the relocations which have
275 * been added since the last call of cs_validate will be removed and
276 * the CS will be flushed (provided there are still any relocations).
278 * \param cs A command stream to validate.
280 boolean (*cs_validate
)(struct radeon_winsys_cs
*cs
);
283 * Write a relocated dword to a command buffer.
285 * \param cs A command stream the relocation is written to.
286 * \param buf A winsys buffer to write the relocation for.
287 * \param rd A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
288 * \param wd A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
290 void (*cs_write_reloc
)(struct radeon_winsys_cs
*cs
,
291 struct radeon_winsys_cs_handle
*buf
);
294 * Flush a command stream.
296 * \param cs A command stream to flush.
297 * \param flags, RADEON_FLUSH_ASYNC or 0.
299 void (*cs_flush
)(struct radeon_winsys_cs
*cs
, unsigned flags
);
302 * Set a flush callback which is called from winsys when flush is
305 * \param cs A command stream to set the callback for.
306 * \param flush A flush callback function associated with the command stream.
307 * \param user A user pointer that will be passed to the flush callback.
309 void (*cs_set_flush
)(struct radeon_winsys_cs
*cs
,
310 void (*flush
)(void *ctx
, unsigned flags
),
314 * Return TRUE if a buffer is referenced by a command stream.
316 * \param cs A command stream.
317 * \param buf A winsys buffer.
319 boolean (*cs_is_buffer_referenced
)(struct radeon_winsys_cs
*cs
,
320 struct radeon_winsys_cs_handle
*buf
);
323 * Request access to a feature for a command stream.
325 * \param cs A command stream.
326 * \param fid Feature ID, one of RADEON_FID_*
327 * \param enable Whether to enable or disable the feature.
329 boolean (*cs_request_feature
)(struct radeon_winsys_cs
*cs
,
330 enum radeon_feature_id fid
,
334 /* Transitional functions for r600g when moving to winsys/radeon */
335 unsigned (*trans_get_buffer_handle
)(struct pb_buffer
*buf
);