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 "r300_defines.h"
33 #include "pipebuffer/pb_bufmgr.h"
34 #include "pipe/p_defines.h"
35 #include "pipe/p_state.h"
37 #define R300_MAX_CMDBUF_DWORDS (16 * 1024)
40 struct r300_winsys_screen
;
42 #define r300_winsys_bo pb_buffer
43 #define r300_winsys_bo_reference(pdst, src) pb_reference(pdst, src)
45 struct r300_winsys_cs_handle
; /* for write_reloc etc. */
47 struct r300_winsys_cs
{
48 unsigned cdw
; /* Number of used dwords. */
49 uint32_t buf
[R300_MAX_CMDBUF_DWORDS
]; /* The command buffer. */
60 R300_VID_DRM_PATCHLEVEL
,
62 /* These should probably go away: */
63 R300_VID_DRM_2_1_0
, /* Square tiling. */
64 R300_VID_DRM_2_3_0
, /* R500 VAP regs, MSPOS regs, fixed tex3D size checking */
65 R300_VID_DRM_2_6_0
, /* Hyper-Z, GB_Z_PEQ_CONFIG on rv350->r4xx, R500 FG_ALPHA_VALUE */
66 R300_VID_DRM_2_8_0
, /* R500 US_FORMAT regs, R500 ARGB2101010 colorbuffer, CMask */
68 R300_CAN_HYPERZ
, /* ZMask + HiZ */
69 R300_CAN_AACOMPRESS
, /* CMask */
72 struct r300_winsys_screen
{
74 * Destroy this winsys.
76 * \param ws The winsys this function is called from.
78 void (*destroy
)(struct r300_winsys_screen
*ws
);
81 * Query a system value from a winsys.
83 * \param ws The winsys this function is called from.
84 * \param vid One of the R300_VID_* enums.
86 uint32_t (*get_value
)(struct r300_winsys_screen
*ws
,
87 enum r300_value_id vid
);
89 /**************************************************************************
90 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
92 * Remember that gallium gets to choose the interface it needs, and the
93 * window systems must then implement that interface (rather than the
94 * other way around...).
95 *************************************************************************/
98 * Create a buffer object.
100 * \param ws The winsys this function is called from.
101 * \param size The size to allocate.
102 * \param alignment An alignment of the buffer in memory.
103 * \param bind A bitmask of the PIPE_BIND_* flags.
104 * \param usage A bitmask of the PIPE_USAGE_* flags.
105 * \param domain A bitmask of the R300_DOMAIN_* flags.
106 * \return The created buffer object.
108 struct r300_winsys_bo
*(*buffer_create
)(struct r300_winsys_screen
*ws
,
113 enum r300_buffer_domain domain
);
115 struct r300_winsys_cs_handle
*(*buffer_get_cs_handle
)(
116 struct r300_winsys_bo
*buf
);
119 * Map the entire data store of a buffer object into the client's address
122 * \param buf A winsys buffer object to map.
123 * \param cs A command stream to flush if the buffer is referenced by it.
124 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
125 * \return The pointer at the beginning of the buffer.
127 void *(*buffer_map
)(struct r300_winsys_bo
*buf
,
128 struct r300_winsys_cs
*cs
,
129 enum pipe_transfer_usage usage
);
132 * Unmap a buffer object from the client's address space.
134 * \param buf A winsys buffer object to unmap.
136 void (*buffer_unmap
)(struct r300_winsys_bo
*buf
);
139 * Return TRUE if a buffer object is being used by the GPU.
141 * \param buf A winsys buffer object.
143 boolean (*buffer_is_busy
)(struct r300_winsys_bo
*buf
);
146 * Wait for a buffer object until it is not used by a GPU. This is
147 * equivalent to a fence placed after the last command using the buffer,
148 * and synchronizing to the fence.
150 * \param buf A winsys buffer object to wait for.
152 void (*buffer_wait
)(struct r300_winsys_bo
*buf
);
155 * Return tiling flags describing a memory layout of a buffer object.
157 * \param buf A winsys buffer object to get the flags from.
158 * \param macrotile A pointer to the return value of the microtile flag.
159 * \param microtile A pointer to the return value of the macrotile flag.
161 * \note microtile and macrotile are not bitmasks!
163 void (*buffer_get_tiling
)(struct r300_winsys_bo
*buf
,
164 enum r300_buffer_tiling
*microtile
,
165 enum r300_buffer_tiling
*macrotile
);
168 * Set tiling flags describing a memory layout of a buffer object.
170 * \param buf A winsys buffer object to set the flags for.
171 * \param macrotile A macrotile flag.
172 * \param microtile A microtile flag.
173 * \param stride A stride of the buffer in bytes, for texturing.
175 * \note microtile and macrotile are not bitmasks!
177 void (*buffer_set_tiling
)(struct r300_winsys_bo
*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_bo
*(*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 buf A winsys buffer object to get the handle from.
202 * \param whandle A winsys handle pointer.
203 * \param stride A stride of the buffer in bytes, for texturing.
204 * \return TRUE on success.
206 boolean (*buffer_get_handle
)(struct r300_winsys_bo
*buf
,
208 struct winsys_handle
*whandle
);
210 /**************************************************************************
211 * Command submission.
213 * Each pipe context should create its own command stream and submit
214 * commands independently of other contexts.
215 *************************************************************************/
218 * Create a command stream.
220 * \param ws The winsys this function is called from.
222 struct r300_winsys_cs
*(*cs_create
)(struct r300_winsys_screen
*ws
);
225 * Destroy a command stream.
227 * \param cs A command stream to destroy.
229 void (*cs_destroy
)(struct r300_winsys_cs
*cs
);
232 * Add a new buffer relocation. Every relocation must first be added
233 * before it can be written.
235 * \param cs A command stream to add buffer for validation against.
236 * \param buf A winsys buffer to validate.
237 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
238 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
240 void (*cs_add_reloc
)(struct r300_winsys_cs
*cs
,
241 struct r300_winsys_cs_handle
*buf
,
242 enum r300_buffer_domain rd
,
243 enum r300_buffer_domain wd
);
246 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
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_cs_handle
*buf
);
265 * Flush a command stream.
267 * \param cs A command stream to flush.
269 void (*cs_flush
)(struct r300_winsys_cs
*cs
);
272 * Set a flush callback which is called from winsys when flush is
275 * \param cs A command stream to set the callback for.
276 * \param flush A flush callback function associated with the command stream.
277 * \param user A user pointer that will be passed to the flush callback.
279 void (*cs_set_flush
)(struct r300_winsys_cs
*cs
,
280 void (*flush
)(void *),
284 * Return TRUE if a buffer is referenced by a command stream.
286 * \param cs A command stream.
287 * \param buf A winsys buffer.
289 boolean (*cs_is_buffer_referenced
)(struct r300_winsys_cs
*cs
,
290 struct r300_winsys_cs_handle
*buf
);
293 #endif /* R300_WINSYS_H */