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 #define R300_MAX_CMDBUF_DWORDS (16 * 1024)
39 struct r300_winsys_screen
;
41 struct r300_winsys_buffer
; /* for map/unmap etc. */
42 struct r300_winsys_cs_buffer
; /* for write_reloc etc. */
44 struct r300_winsys_cs
{
45 unsigned cdw
; /* Number of used dwords. */
46 uint32_t buf
[R300_MAX_CMDBUF_DWORDS
]; /* The command buffer. */
53 R300_VID_DRM_2_1_0
, /* Square tiling. */
54 R300_VID_DRM_2_3_0
, /* R500 VAP regs, MSPOS regs, fixed tex3D size checking */
55 R300_VID_DRM_2_6_0
, /* Hyper-Z, GB_Z_PEQ_CONFIG on rv350->r4xx, R500 FG_ALPHA_VALUE */
56 R300_VID_DRM_2_8_0
, /* R500 US_FORMAT regs, R500 ARGB2101010 colorbuffer */
60 enum r300_reference_domain
{ /* bitfield */
65 struct r300_winsys_screen
{
67 * Destroy this winsys.
69 * \param ws The winsys this function is called from.
71 void (*destroy
)(struct r300_winsys_screen
*ws
);
74 * Query a system value from a winsys.
76 * \param ws The winsys this function is called from.
77 * \param vid One of the R300_VID_* enums.
79 uint32_t (*get_value
)(struct r300_winsys_screen
*ws
,
80 enum r300_value_id vid
);
82 /**************************************************************************
83 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
85 * Remember that gallium gets to choose the interface it needs, and the
86 * window systems must then implement that interface (rather than the
87 * other way around...).
88 *************************************************************************/
91 * Create a buffer object.
93 * \param ws The winsys this function is called from.
94 * \param size The size to allocate.
95 * \param alignment An alignment of the buffer in memory.
96 * \param bind A bitmask of the PIPE_BIND_* flags.
97 * \param usage A bitmask of the PIPE_USAGE_* flags.
98 * \param domain A bitmask of the R300_DOMAIN_* flags.
99 * \return The created buffer object.
101 struct r300_winsys_buffer
*(*buffer_create
)(struct r300_winsys_screen
*ws
,
106 enum r300_buffer_domain domain
);
108 struct r300_winsys_cs_buffer
*(*buffer_get_cs_handle
)(
109 struct r300_winsys_screen
*ws
,
110 struct r300_winsys_buffer
*buf
);
113 * Reference a buffer object (assign with reference counting).
115 * \param ws The winsys this function is called from.
116 * \param pdst A destination pointer to set the source buffer to.
117 * \param src A source buffer object.
119 void (*buffer_reference
)(struct r300_winsys_screen
*ws
,
120 struct r300_winsys_buffer
**pdst
,
121 struct r300_winsys_buffer
*src
);
124 * Map the entire data store of a buffer object into the client's address
127 * \param ws The winsys this function is called from.
128 * \param buf A winsys buffer object to map.
129 * \param cs A command stream to flush if the buffer is referenced by it.
130 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
131 * \return The pointer at the beginning of the buffer.
133 void *(*buffer_map
)(struct r300_winsys_screen
*ws
,
134 struct r300_winsys_buffer
*buf
,
135 struct r300_winsys_cs
*cs
,
136 enum pipe_transfer_usage usage
);
139 * Unmap a buffer object from the client's address space.
141 * \param ws The winsys this function is called from.
142 * \param buf A winsys buffer object to unmap.
144 void (*buffer_unmap
)(struct r300_winsys_screen
*ws
,
145 struct r300_winsys_buffer
*buf
);
148 * Wait for a buffer object until it is not used by a GPU. This is
149 * equivalent to a fence placed after the last command using the buffer,
150 * and synchronizing to the fence.
152 * \param ws The winsys this function is called from.
153 * \param buf A winsys buffer object to wait for.
155 void (*buffer_wait
)(struct r300_winsys_screen
*ws
,
156 struct r300_winsys_buffer
*buf
);
159 * Return tiling flags describing a memory layout of a buffer object.
161 * \param ws The winsys this function is called from.
162 * \param buf A winsys buffer object to get the flags from.
163 * \param macrotile A pointer to the return value of the microtile flag.
164 * \param microtile A pointer to the return value of the macrotile flag.
166 * \note microtile and macrotile are not bitmasks!
168 void (*buffer_get_tiling
)(struct r300_winsys_screen
*ws
,
169 struct r300_winsys_buffer
*buf
,
170 enum r300_buffer_tiling
*microtile
,
171 enum r300_buffer_tiling
*macrotile
);
174 * Set tiling flags describing a memory layout of a buffer object.
176 * \param ws The winsys this function is called from.
177 * \param buf A winsys buffer object to set the flags for.
178 * \param macrotile A macrotile flag.
179 * \param microtile A microtile flag.
180 * \param stride A stride of the buffer in bytes, for texturing.
182 * \note microtile and macrotile are not bitmasks!
184 void (*buffer_set_tiling
)(struct r300_winsys_screen
*ws
,
185 struct r300_winsys_buffer
*buf
,
186 enum r300_buffer_tiling microtile
,
187 enum r300_buffer_tiling macrotile
,
191 * Get a winsys buffer from a winsys handle. The internal structure
192 * of the handle is platform-specific and only a winsys should access it.
194 * \param ws The winsys this function is called from.
195 * \param whandle A winsys handle pointer as was received from a state
197 * \param stride The returned buffer stride in bytes.
198 * \param size The returned buffer size.
200 struct r300_winsys_buffer
*(*buffer_from_handle
)(struct r300_winsys_screen
*ws
,
201 struct winsys_handle
*whandle
,
206 * Get a winsys handle from a winsys buffer. The internal structure
207 * of the handle is platform-specific and only a winsys should access it.
209 * \param ws The winsys this function is called from.
210 * \param buf A winsys buffer object to get the handle from.
211 * \param whandle A winsys handle pointer.
212 * \param stride A stride of the buffer in bytes, for texturing.
213 * \return TRUE on success.
215 boolean (*buffer_get_handle
)(struct r300_winsys_screen
*ws
,
216 struct r300_winsys_buffer
*buf
,
218 struct winsys_handle
*whandle
);
220 /**************************************************************************
221 * Command submission.
223 * Each pipe context should create its own command stream and submit
224 * commands independently of other contexts.
225 *************************************************************************/
228 * Create a command stream.
230 * \param ws The winsys this function is called from.
232 struct r300_winsys_cs
*(*cs_create
)(struct r300_winsys_screen
*ws
);
235 * Destroy a command stream.
237 * \param cs A command stream to destroy.
239 void (*cs_destroy
)(struct r300_winsys_cs
*cs
);
242 * Add a new buffer relocation. Every relocation must first be added
243 * before it can be written.
245 * \param cs A command stream to add buffer for validation against.
246 * \param buf A winsys buffer to validate.
247 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
248 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
250 void (*cs_add_reloc
)(struct r300_winsys_cs
*cs
,
251 struct r300_winsys_cs_buffer
*buf
,
252 enum r300_buffer_domain rd
,
253 enum r300_buffer_domain wd
);
256 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
259 * \param cs A command stream to validate.
261 boolean (*cs_validate
)(struct r300_winsys_cs
*cs
);
264 * Write a relocated dword to a command buffer.
266 * \param cs A command stream the relocation is written to.
267 * \param buf A winsys buffer to write the relocation for.
268 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
269 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
271 void (*cs_write_reloc
)(struct r300_winsys_cs
*cs
,
272 struct r300_winsys_cs_buffer
*buf
);
275 * Flush a command stream.
277 * \param cs A command stream to flush.
279 void (*cs_flush
)(struct r300_winsys_cs
*cs
);
282 * Set a flush callback which is called from winsys when flush is
285 * \param cs A command stream to set the callback for.
286 * \param flush A flush callback function associated with the command stream.
287 * \param user A user pointer that will be passed to the flush callback.
289 void (*cs_set_flush
)(struct r300_winsys_cs
*cs
,
290 void (*flush
)(void *),
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_cs_buffer
*buf
,
303 enum r300_reference_domain domain
);
306 #endif /* R300_WINSYS_H */