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)
38 #define R300_FLUSH_ASYNC (1 << 0)
41 struct r300_winsys_screen
;
43 #define r300_winsys_bo pb_buffer
44 #define r300_winsys_bo_reference(pdst, src) pb_reference(pdst, src)
46 struct r300_winsys_cs_handle
; /* for write_reloc etc. */
48 struct r300_winsys_cs
{
49 unsigned cdw
; /* Number of used dwords. */
50 uint32_t *buf
; /* The command buffer. */
61 R300_VID_DRM_PATCHLEVEL
,
63 /* These should probably go away: */
64 R300_VID_DRM_2_6_0
, /* Hyper-Z, GB_Z_PEQ_CONFIG on rv350->r4xx, R500 FG_ALPHA_VALUE */
65 R300_VID_DRM_2_8_0
, /* R500 US_FORMAT regs, R500 ARGB2101010 colorbuffer, CMask, R16F/RG16F */
67 R300_CAN_HYPERZ
, /* ZMask + HiZ */
68 R300_CAN_AACOMPRESS
, /* CMask */
71 struct r300_winsys_screen
{
73 * Destroy this winsys.
75 * \param ws The winsys this function is called from.
77 void (*destroy
)(struct r300_winsys_screen
*ws
);
80 * Query a system value from a winsys.
82 * \param ws The winsys this function is called from.
83 * \param vid One of the R300_VID_* enums.
85 uint32_t (*get_value
)(struct r300_winsys_screen
*ws
,
86 enum r300_value_id vid
);
88 /**************************************************************************
89 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
91 * Remember that gallium gets to choose the interface it needs, and the
92 * window systems must then implement that interface (rather than the
93 * other way around...).
94 *************************************************************************/
97 * Create a buffer object.
99 * \param ws The winsys this function is called from.
100 * \param size The size to allocate.
101 * \param alignment An alignment of the buffer in memory.
102 * \param bind A bitmask of the PIPE_BIND_* flags.
103 * \param usage A bitmask of the PIPE_USAGE_* flags.
104 * \param domain A bitmask of the R300_DOMAIN_* flags.
105 * \return The created buffer object.
107 struct r300_winsys_bo
*(*buffer_create
)(struct r300_winsys_screen
*ws
,
112 enum r300_buffer_domain domain
);
114 struct r300_winsys_cs_handle
*(*buffer_get_cs_handle
)(
115 struct r300_winsys_bo
*buf
);
118 * Map the entire data store of a buffer object into the client's address
121 * \param buf A winsys buffer object to map.
122 * \param cs A command stream to flush if the buffer is referenced by it.
123 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
124 * \return The pointer at the beginning of the buffer.
126 void *(*buffer_map
)(struct r300_winsys_bo
*buf
,
127 struct r300_winsys_cs
*cs
,
128 enum pipe_transfer_usage usage
);
131 * Unmap a buffer object from the client's address space.
133 * \param buf A winsys buffer object to unmap.
135 void (*buffer_unmap
)(struct r300_winsys_bo
*buf
);
138 * Return TRUE if a buffer object is being used by the GPU.
140 * \param buf A winsys buffer object.
142 boolean (*buffer_is_busy
)(struct r300_winsys_bo
*buf
);
145 * Wait for a buffer object until it is not used by a GPU. This is
146 * equivalent to a fence placed after the last command using the buffer,
147 * and synchronizing to the fence.
149 * \param buf A winsys buffer object to wait for.
151 void (*buffer_wait
)(struct r300_winsys_bo
*buf
);
154 * Return tiling flags describing a memory layout of a buffer object.
156 * \param buf A winsys buffer object to get the flags from.
157 * \param macrotile A pointer to the return value of the microtile flag.
158 * \param microtile A pointer to the return value of the macrotile flag.
160 * \note microtile and macrotile are not bitmasks!
162 void (*buffer_get_tiling
)(struct r300_winsys_bo
*buf
,
163 enum r300_buffer_tiling
*microtile
,
164 enum r300_buffer_tiling
*macrotile
);
167 * Set tiling flags describing a memory layout of a buffer object.
169 * \param buf A winsys buffer object to set the flags for.
170 * \param cs A command stream to flush if the buffer is referenced by it.
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 struct r300_winsys_cs
*cs
,
179 enum r300_buffer_tiling microtile
,
180 enum r300_buffer_tiling macrotile
,
184 * Get a winsys buffer from a winsys handle. The internal structure
185 * of the handle is platform-specific and only a winsys should access it.
187 * \param ws The winsys this function is called from.
188 * \param whandle A winsys handle pointer as was received from a state
190 * \param stride The returned buffer stride in bytes.
191 * \param size The returned buffer size.
193 struct r300_winsys_bo
*(*buffer_from_handle
)(struct r300_winsys_screen
*ws
,
194 struct winsys_handle
*whandle
,
199 * Get a winsys handle from a winsys buffer. The internal structure
200 * of the handle is platform-specific and only a winsys should access it.
202 * \param buf A winsys buffer object to get the handle from.
203 * \param whandle A winsys handle pointer.
204 * \param stride A stride of the buffer in bytes, for texturing.
205 * \return TRUE on success.
207 boolean (*buffer_get_handle
)(struct r300_winsys_bo
*buf
,
209 struct winsys_handle
*whandle
);
211 /**************************************************************************
212 * Command submission.
214 * Each pipe context should create its own command stream and submit
215 * commands independently of other contexts.
216 *************************************************************************/
219 * Create a command stream.
221 * \param ws The winsys this function is called from.
223 struct r300_winsys_cs
*(*cs_create
)(struct r300_winsys_screen
*ws
);
226 * Destroy a command stream.
228 * \param cs A command stream to destroy.
230 void (*cs_destroy
)(struct r300_winsys_cs
*cs
);
233 * Add a new buffer relocation. Every relocation must first be added
234 * before it can be written.
236 * \param cs A command stream to add buffer for validation against.
237 * \param buf A winsys buffer to validate.
238 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
239 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
241 void (*cs_add_reloc
)(struct r300_winsys_cs
*cs
,
242 struct r300_winsys_cs_handle
*buf
,
243 enum r300_buffer_domain rd
,
244 enum r300_buffer_domain wd
);
247 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
250 * \param cs A command stream to validate.
252 boolean (*cs_validate
)(struct r300_winsys_cs
*cs
);
255 * Write a relocated dword to a command buffer.
257 * \param cs A command stream the relocation is written to.
258 * \param buf A winsys buffer to write the relocation for.
259 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
260 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
262 void (*cs_write_reloc
)(struct r300_winsys_cs
*cs
,
263 struct r300_winsys_cs_handle
*buf
);
266 * Flush a command stream.
268 * \param cs A command stream to flush.
269 * \param flags, R300_FLUSH_ASYNC or 0.
271 void (*cs_flush
)(struct r300_winsys_cs
*cs
, unsigned flags
);
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 *ctx
, unsigned flags
),
286 * Return TRUE if a buffer is referenced by a command stream.
288 * \param cs A command stream.
289 * \param buf A winsys buffer.
291 boolean (*cs_is_buffer_referenced
)(struct r300_winsys_cs
*cs
,
292 struct r300_winsys_cs_handle
*buf
);
295 #endif /* R300_WINSYS_H */