bf5b144fe2c080eef90b87c32e1b4de643cb530b
[mesa.git] / src / gallium / winsys / radeon / drm / radeon_winsys.h
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
4 *
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:
11 *
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
14 * Software.
15 *
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. */
23
24 #ifndef RADEON_WINSYS_H
25 #define RADEON_WINSYS_H
26
27 /* The public winsys interface header for the radeon driver. */
28
29 /* R300 features in DRM.
30 *
31 * 2.6.0:
32 * - Hyper-Z
33 * - GB_Z_PEQ_CONFIG on rv350->r4xx
34 * - R500 FG_ALPHA_VALUE
35 *
36 * 2.8.0:
37 * - R500 US_FORMAT regs
38 * - R500 ARGB2101010 colorbuffer
39 * - CMask and AA regs
40 * - R16F/RG16F
41 */
42
43 #include "pipebuffer/pb_bufmgr.h"
44 #include "pipe/p_defines.h"
45 #include "pipe/p_state.h"
46
47 #define RADEON_MAX_CMDBUF_DWORDS (16 * 1024)
48 #define RADEON_FLUSH_ASYNC (1 << 0)
49
50 /* Tiling flags. */
51 enum radeon_bo_layout {
52 RADEON_LAYOUT_LINEAR = 0,
53 RADEON_LAYOUT_TILED,
54 RADEON_LAYOUT_SQUARETILED,
55
56 RADEON_LAYOUT_UNKNOWN
57 };
58
59 enum radeon_bo_domain { /* bitfield */
60 RADEON_DOMAIN_GTT = 2,
61 RADEON_DOMAIN_VRAM = 4
62 };
63
64 struct winsys_handle;
65 struct radeon_winsys_cs_handle; /* for write_reloc etc. */
66
67 struct radeon_winsys_cs {
68 unsigned cdw; /* Number of used dwords. */
69 uint32_t *buf; /* The command buffer. */
70 };
71
72 struct radeon_info {
73 uint32_t pci_id;
74 uint32_t gart_size;
75 uint32_t vram_size;
76
77 uint32_t drm_major; /* version */
78 uint32_t drm_minor;
79 uint32_t drm_patchlevel;
80
81 uint32_t r300_num_gb_pipes;
82 uint32_t r300_num_z_pipes;
83
84 uint32_t r600_num_backends;
85 uint32_t r600_clock_crystal_freq;
86 uint32_t r600_tiling_config;
87 uint32_t r600_num_tile_pipes;
88 uint32_t r600_backend_map;
89 boolean r600_backend_map_valid;
90 };
91
92 enum radeon_feature_id {
93 RADEON_FID_R300_HYPERZ_ACCESS, /* ZMask + HiZ */
94 RADEON_FID_R300_CMASK_ACCESS,
95 };
96
97 struct radeon_winsys {
98 /**
99 * Destroy this winsys.
100 *
101 * \param ws The winsys this function is called from.
102 */
103 void (*destroy)(struct radeon_winsys *ws);
104
105 /**
106 * Query an info structure from winsys.
107 *
108 * \param ws The winsys this function is called from.
109 * \param info Return structure
110 */
111 void (*query_info)(struct radeon_winsys *ws,
112 struct radeon_info *info);
113
114 /**************************************************************************
115 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
116 *
117 * Remember that gallium gets to choose the interface it needs, and the
118 * window systems must then implement that interface (rather than the
119 * other way around...).
120 *************************************************************************/
121
122 /**
123 * Create a buffer object.
124 *
125 * \param ws The winsys this function is called from.
126 * \param size The size to allocate.
127 * \param alignment An alignment of the buffer in memory.
128 * \param bind A bitmask of the PIPE_BIND_* flags.
129 * \param domain A bitmask of the RADEON_DOMAIN_* flags.
130 * \return The created buffer object.
131 */
132 struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws,
133 unsigned size,
134 unsigned alignment,
135 unsigned bind,
136 enum radeon_bo_domain domain);
137
138 struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)(
139 struct pb_buffer *buf);
140
141 /**
142 * Map the entire data store of a buffer object into the client's address
143 * space.
144 *
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.
149 */
150 void *(*buffer_map)(struct pb_buffer *buf,
151 struct radeon_winsys_cs *cs,
152 enum pipe_transfer_usage usage);
153
154 /**
155 * Unmap a buffer object from the client's address space.
156 *
157 * \param buf A winsys buffer object to unmap.
158 */
159 void (*buffer_unmap)(struct pb_buffer *buf);
160
161 /**
162 * Return TRUE if a buffer object is being used by the GPU.
163 *
164 * \param buf A winsys buffer object.
165 */
166 boolean (*buffer_is_busy)(struct pb_buffer *buf);
167
168 /**
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.
172 *
173 * \param buf A winsys buffer object to wait for.
174 */
175 void (*buffer_wait)(struct pb_buffer *buf);
176
177 /**
178 * Return tiling flags describing a memory layout of a buffer object.
179 *
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.
183 *
184 * \note microtile and macrotile are not bitmasks!
185 */
186 void (*buffer_get_tiling)(struct pb_buffer *buf,
187 enum radeon_bo_layout *microtile,
188 enum radeon_bo_layout *macrotile);
189
190 /**
191 * Set tiling flags describing a memory layout of a buffer object.
192 *
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.
198 *
199 * \note microtile and macrotile are not bitmasks!
200 */
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,
205 unsigned stride);
206
207 /**
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.
210 *
211 * \param ws The winsys this function is called from.
212 * \param whandle A winsys handle pointer as was received from a state
213 * tracker.
214 * \param stride The returned buffer stride in bytes.
215 * \param size The returned buffer size.
216 */
217 struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws,
218 struct winsys_handle *whandle,
219 unsigned *stride,
220 unsigned *size);
221
222 /**
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.
225 *
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.
230 */
231 boolean (*buffer_get_handle)(struct pb_buffer *buf,
232 unsigned stride,
233 struct winsys_handle *whandle);
234
235 /**************************************************************************
236 * Command submission.
237 *
238 * Each pipe context should create its own command stream and submit
239 * commands independently of other contexts.
240 *************************************************************************/
241
242 /**
243 * Create a command stream.
244 *
245 * \param ws The winsys this function is called from.
246 */
247 struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws);
248
249 /**
250 * Destroy a command stream.
251 *
252 * \param cs A command stream to destroy.
253 */
254 void (*cs_destroy)(struct radeon_winsys_cs *cs);
255
256 /**
257 * Add a new buffer relocation. Every relocation must first be added
258 * before it can be written.
259 *
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.
264 * \return Relocation index.
265 */
266 unsigned (*cs_add_reloc)(struct radeon_winsys_cs *cs,
267 struct radeon_winsys_cs_handle *buf,
268 enum radeon_bo_domain rd,
269 enum radeon_bo_domain wd);
270
271 /**
272 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
273 * added so far. If the validation fails, all the relocations which have
274 * been added since the last call of cs_validate will be removed and
275 * the CS will be flushed (provided there are still any relocations).
276 *
277 * \param cs A command stream to validate.
278 */
279 boolean (*cs_validate)(struct radeon_winsys_cs *cs);
280
281 /**
282 * Write a relocated dword to a command buffer.
283 *
284 * \param cs A command stream the relocation is written to.
285 * \param buf A winsys buffer to write the relocation for.
286 * \param rd A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
287 * \param wd A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
288 */
289 void (*cs_write_reloc)(struct radeon_winsys_cs *cs,
290 struct radeon_winsys_cs_handle *buf);
291
292 /**
293 * Flush a command stream.
294 *
295 * \param cs A command stream to flush.
296 * \param flags, RADEON_FLUSH_ASYNC or 0.
297 */
298 void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags);
299
300 /**
301 * Set a flush callback which is called from winsys when flush is
302 * required.
303 *
304 * \param cs A command stream to set the callback for.
305 * \param flush A flush callback function associated with the command stream.
306 * \param user A user pointer that will be passed to the flush callback.
307 */
308 void (*cs_set_flush_callback)(struct radeon_winsys_cs *cs,
309 void (*flush)(void *ctx, unsigned flags),
310 void *ctx);
311
312 /**
313 * Return TRUE if a buffer is referenced by a command stream.
314 *
315 * \param cs A command stream.
316 * \param buf A winsys buffer.
317 */
318 boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
319 struct radeon_winsys_cs_handle *buf);
320
321 /**
322 * Request access to a feature for a command stream.
323 *
324 * \param cs A command stream.
325 * \param fid Feature ID, one of RADEON_FID_*
326 * \param enable Whether to enable or disable the feature.
327 */
328 boolean (*cs_request_feature)(struct radeon_winsys_cs *cs,
329 enum radeon_feature_id fid,
330 boolean enable);
331 };
332
333 #endif