radeon_winsys.h revision f170555a18a742ed8ecb9e04cd02a5cb414c27ea
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. */
51enum radeon_bo_layout {
52    RADEON_LAYOUT_LINEAR = 0,
53    RADEON_LAYOUT_TILED,
54    RADEON_LAYOUT_SQUARETILED,
55
56    RADEON_LAYOUT_UNKNOWN
57};
58
59enum radeon_bo_domain { /* bitfield */
60    RADEON_DOMAIN_GTT  = 2,
61    RADEON_DOMAIN_VRAM = 4
62};
63
64struct winsys_handle;
65struct radeon_winsys_cs_handle;   /* for write_reloc etc. */
66
67struct radeon_winsys_cs {
68    unsigned cdw;  /* Number of used dwords. */
69    uint32_t *buf; /* The command buffer. */
70};
71
72struct 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
85enum radeon_feature_id {
86    RADEON_FID_R300_HYPERZ_ACCESS,     /* ZMask + HiZ */
87    RADEON_FID_R300_CMASK_ACCESS,
88};
89
90struct radeon_winsys {
91    /**
92     * Destroy this winsys.
93     *
94     * \param ws        The winsys this function is called from.
95     */
96    void (*destroy)(struct radeon_winsys *ws);
97
98    /**
99     * Query an info structure from winsys.
100     *
101     * \param ws        The winsys this function is called from.
102     * \param info      Return structure
103     */
104    void (*query_info)(struct radeon_winsys *ws,
105                       struct radeon_info *info);
106
107    /**************************************************************************
108     * Buffer management. Buffer attributes are mostly fixed over its lifetime.
109     *
110     * Remember that gallium gets to choose the interface it needs, and the
111     * window systems must then implement that interface (rather than the
112     * other way around...).
113     *************************************************************************/
114
115    /**
116     * Create a buffer object.
117     *
118     * \param ws        The winsys this function is called from.
119     * \param size      The size to allocate.
120     * \param alignment An alignment of the buffer in memory.
121     * \param bind      A bitmask of the PIPE_BIND_* flags.
122     * \param domain    A bitmask of the RADEON_DOMAIN_* flags.
123     * \return          The created buffer object.
124     */
125    struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws,
126                                       unsigned size,
127                                       unsigned alignment,
128                                       unsigned bind,
129                                       enum radeon_bo_domain domain);
130
131    struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)(
132            struct pb_buffer *buf);
133
134    /**
135     * Map the entire data store of a buffer object into the client's address
136     * space.
137     *
138     * \param buf       A winsys buffer object to map.
139     * \param cs        A command stream to flush if the buffer is referenced by it.
140     * \param usage     A bitmask of the PIPE_TRANSFER_* flags.
141     * \return          The pointer at the beginning of the buffer.
142     */
143    void *(*buffer_map)(struct pb_buffer *buf,
144                        struct radeon_winsys_cs *cs,
145                        enum pipe_transfer_usage usage);
146
147    /**
148     * Unmap a buffer object from the client's address space.
149     *
150     * \param buf       A winsys buffer object to unmap.
151     */
152    void (*buffer_unmap)(struct pb_buffer *buf);
153
154    /**
155     * Return TRUE if a buffer object is being used by the GPU.
156     *
157     * \param buf       A winsys buffer object.
158     */
159    boolean (*buffer_is_busy)(struct pb_buffer *buf);
160
161    /**
162     * Wait for a buffer object until it is not used by a GPU. This is
163     * equivalent to a fence placed after the last command using the buffer,
164     * and synchronizing to the fence.
165     *
166     * \param buf       A winsys buffer object to wait for.
167     */
168    void (*buffer_wait)(struct pb_buffer *buf);
169
170    /**
171     * Return tiling flags describing a memory layout of a buffer object.
172     *
173     * \param buf       A winsys buffer object to get the flags from.
174     * \param macrotile A pointer to the return value of the microtile flag.
175     * \param microtile A pointer to the return value of the macrotile flag.
176     *
177     * \note microtile and macrotile are not bitmasks!
178     */
179    void (*buffer_get_tiling)(struct pb_buffer *buf,
180                              enum radeon_bo_layout *microtile,
181                              enum radeon_bo_layout *macrotile);
182
183    /**
184     * Set tiling flags describing a memory layout of a buffer object.
185     *
186     * \param buf       A winsys buffer object to set the flags for.
187     * \param cs        A command stream to flush if the buffer is referenced by it.
188     * \param macrotile A macrotile flag.
189     * \param microtile A microtile flag.
190     * \param stride    A stride of the buffer in bytes, for texturing.
191     *
192     * \note microtile and macrotile are not bitmasks!
193     */
194    void (*buffer_set_tiling)(struct pb_buffer *buf,
195                              struct radeon_winsys_cs *cs,
196                              enum radeon_bo_layout microtile,
197                              enum radeon_bo_layout macrotile,
198                              unsigned stride);
199
200    /**
201     * Get a winsys buffer from a winsys handle. The internal structure
202     * of the handle is platform-specific and only a winsys should access it.
203     *
204     * \param ws        The winsys this function is called from.
205     * \param whandle   A winsys handle pointer as was received from a state
206     *                  tracker.
207     * \param stride    The returned buffer stride in bytes.
208     * \param size      The returned buffer size.
209     */
210    struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws,
211                                            struct winsys_handle *whandle,
212                                            unsigned *stride,
213                                            unsigned *size);
214
215    /**
216     * Get a winsys handle from a winsys buffer. The internal structure
217     * of the handle is platform-specific and only a winsys should access it.
218     *
219     * \param buf       A winsys buffer object to get the handle from.
220     * \param whandle   A winsys handle pointer.
221     * \param stride    A stride of the buffer in bytes, for texturing.
222     * \return          TRUE on success.
223     */
224    boolean (*buffer_get_handle)(struct pb_buffer *buf,
225                                 unsigned stride,
226                                 struct winsys_handle *whandle);
227
228    /**************************************************************************
229     * Command submission.
230     *
231     * Each pipe context should create its own command stream and submit
232     * commands independently of other contexts.
233     *************************************************************************/
234
235    /**
236     * Create a command stream.
237     *
238     * \param ws        The winsys this function is called from.
239     */
240    struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws);
241
242    /**
243     * Destroy a command stream.
244     *
245     * \param cs        A command stream to destroy.
246     */
247    void (*cs_destroy)(struct radeon_winsys_cs *cs);
248
249    /**
250     * Add a new buffer relocation. Every relocation must first be added
251     * before it can be written.
252     *
253     * \param cs  A command stream to add buffer for validation against.
254     * \param buf A winsys buffer to validate.
255     * \param rd  A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
256     * \param wd  A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
257     */
258    void (*cs_add_reloc)(struct radeon_winsys_cs *cs,
259                         struct radeon_winsys_cs_handle *buf,
260                         enum radeon_bo_domain rd,
261                         enum radeon_bo_domain wd);
262
263    /**
264     * Return TRUE if there is enough memory in VRAM and GTT for the relocs
265     * added so far.
266     *
267     * \param cs        A command stream to validate.
268     */
269    boolean (*cs_validate)(struct radeon_winsys_cs *cs);
270
271    /**
272     * Write a relocated dword to a command buffer.
273     *
274     * \param cs        A command stream the relocation is written to.
275     * \param buf       A winsys buffer to write the relocation for.
276     * \param rd        A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
277     * \param wd        A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
278     */
279    void (*cs_write_reloc)(struct radeon_winsys_cs *cs,
280                           struct radeon_winsys_cs_handle *buf);
281
282    /**
283     * Flush a command stream.
284     *
285     * \param cs        A command stream to flush.
286     * \param flags,    RADEON_FLUSH_ASYNC or 0.
287     */
288    void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags);
289
290    /**
291     * Set a flush callback which is called from winsys when flush is
292     * required.
293     *
294     * \param cs        A command stream to set the callback for.
295     * \param flush     A flush callback function associated with the command stream.
296     * \param user      A user pointer that will be passed to the flush callback.
297     */
298    void (*cs_set_flush)(struct radeon_winsys_cs *cs,
299                         void (*flush)(void *ctx, unsigned flags),
300                         void *ctx);
301
302    /**
303     * Return TRUE if a buffer is referenced by a command stream.
304     *
305     * \param cs        A command stream.
306     * \param buf       A winsys buffer.
307     */
308    boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
309                                       struct radeon_winsys_cs_handle *buf);
310
311    /**
312     * Request access to a feature for a command stream.
313     *
314     * \param cs        A command stream.
315     * \param fid       Feature ID, one of RADEON_FID_*
316     * \param enable	Whether to enable or disable the feature.
317     */
318    boolean (*cs_request_feature)(struct radeon_winsys_cs *cs,
319                                  enum radeon_feature_id fid,
320                                  boolean enable);
321};
322
323#endif
324