radeon_winsys.h revision fdd37af3f76ea3ac32f21e9a9c41979a9b33cc5c
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#include "pipebuffer/pb_bufmgr.h"
30#include "pipe/p_defines.h"
31#include "pipe/p_state.h"
32
33#define RADEON_MAX_CMDBUF_DWORDS (16 * 1024)
34#define RADEON_FLUSH_ASYNC       (1 << 0)
35
36/* Tiling flags. */
37enum radeon_bo_layout {
38    RADEON_LAYOUT_LINEAR = 0,
39    RADEON_LAYOUT_TILED,
40    RADEON_LAYOUT_SQUARETILED,
41
42    RADEON_LAYOUT_UNKNOWN
43};
44
45enum radeon_bo_domain { /* bitfield */
46    RADEON_DOMAIN_GTT  = 2,
47    RADEON_DOMAIN_VRAM = 4
48};
49
50struct winsys_handle;
51struct radeon_winsys_cs_handle;   /* for write_reloc etc. */
52
53struct radeon_winsys_cs {
54    unsigned cdw;  /* Number of used dwords. */
55    uint32_t *buf; /* The command buffer. */
56};
57
58enum radeon_value_id {
59    RADEON_VID_PCI_ID,
60    RADEON_VID_R300_GB_PIPES,
61    RADEON_VID_R300_Z_PIPES,
62    RADEON_VID_GART_SIZE,
63    RADEON_VID_VRAM_SIZE,
64    RADEON_VID_DRM_MAJOR,
65    RADEON_VID_DRM_MINOR,
66    RADEON_VID_DRM_PATCHLEVEL,
67
68    /* These should probably go away: */
69
70    /* R300 features:
71     * - Hyper-Z
72     * - GB_Z_PEQ_CONFIG on rv350->r4xx
73     * - R500 FG_ALPHA_VALUE
74     *
75     * R600 features:
76     * - TBD
77     */
78    RADEON_VID_DRM_2_6_0,
79
80    /* R300 features:
81     * - R500 US_FORMAT regs
82     * - R500 ARGB2101010 colorbuffer
83     * - CMask and AA regs
84     * - R16F/RG16F
85     *
86     * R600 features:
87     * - TBD
88     */
89    RADEON_VID_DRM_2_8_0,
90};
91
92enum radeon_feature_id {
93    RADEON_FID_HYPERZ_RAM_ACCESS,     /* ZMask + HiZ */
94    RADEON_FID_CMASK_RAM_ACCESS,
95};
96
97struct 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 a system value from a winsys.
107     *
108     * \param ws        The winsys this function is called from.
109     * \param vid       One of the RADEON_VID_* enums.
110     */
111    uint32_t (*get_value)(struct radeon_winsys *ws,
112                          enum radeon_value_id vid);
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 usage     A bitmask of the PIPE_USAGE_* flags.
130     * \param domain    A bitmask of the RADEON_DOMAIN_* flags.
131     * \return          The created buffer object.
132     */
133    struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws,
134                                       unsigned size,
135                                       unsigned alignment,
136                                       unsigned bind,
137                                       unsigned usage,
138                                       enum radeon_bo_domain domain);
139
140    struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)(
141            struct pb_buffer *buf);
142
143    /**
144     * Map the entire data store of a buffer object into the client's address
145     * space.
146     *
147     * \param buf       A winsys buffer object to map.
148     * \param cs        A command stream to flush if the buffer is referenced by it.
149     * \param usage     A bitmask of the PIPE_TRANSFER_* flags.
150     * \return          The pointer at the beginning of the buffer.
151     */
152    void *(*buffer_map)(struct pb_buffer *buf,
153                        struct radeon_winsys_cs *cs,
154                        enum pipe_transfer_usage usage);
155
156    /**
157     * Unmap a buffer object from the client's address space.
158     *
159     * \param buf       A winsys buffer object to unmap.
160     */
161    void (*buffer_unmap)(struct pb_buffer *buf);
162
163    /**
164     * Return TRUE if a buffer object is being used by the GPU.
165     *
166     * \param buf       A winsys buffer object.
167     */
168    boolean (*buffer_is_busy)(struct pb_buffer *buf);
169
170    /**
171     * Wait for a buffer object until it is not used by a GPU. This is
172     * equivalent to a fence placed after the last command using the buffer,
173     * and synchronizing to the fence.
174     *
175     * \param buf       A winsys buffer object to wait for.
176     */
177    void (*buffer_wait)(struct pb_buffer *buf);
178
179    /**
180     * Return tiling flags describing a memory layout of a buffer object.
181     *
182     * \param buf       A winsys buffer object to get the flags from.
183     * \param macrotile A pointer to the return value of the microtile flag.
184     * \param microtile A pointer to the return value of the macrotile flag.
185     *
186     * \note microtile and macrotile are not bitmasks!
187     */
188    void (*buffer_get_tiling)(struct pb_buffer *buf,
189                              enum radeon_bo_layout *microtile,
190                              enum radeon_bo_layout *macrotile);
191
192    /**
193     * Set tiling flags describing a memory layout of a buffer object.
194     *
195     * \param buf       A winsys buffer object to set the flags for.
196     * \param cs        A command stream to flush if the buffer is referenced by it.
197     * \param macrotile A macrotile flag.
198     * \param microtile A microtile flag.
199     * \param stride    A stride of the buffer in bytes, for texturing.
200     *
201     * \note microtile and macrotile are not bitmasks!
202     */
203    void (*buffer_set_tiling)(struct pb_buffer *buf,
204                              struct radeon_winsys_cs *cs,
205                              enum radeon_bo_layout microtile,
206                              enum radeon_bo_layout macrotile,
207                              unsigned stride);
208
209    /**
210     * Get a winsys buffer from a winsys handle. The internal structure
211     * of the handle is platform-specific and only a winsys should access it.
212     *
213     * \param ws        The winsys this function is called from.
214     * \param whandle   A winsys handle pointer as was received from a state
215     *                  tracker.
216     * \param stride    The returned buffer stride in bytes.
217     * \param size      The returned buffer size.
218     */
219    struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws,
220                                            struct winsys_handle *whandle,
221                                            unsigned *stride,
222                                            unsigned *size);
223
224    /**
225     * Get a winsys handle from a winsys buffer. The internal structure
226     * of the handle is platform-specific and only a winsys should access it.
227     *
228     * \param buf       A winsys buffer object to get the handle from.
229     * \param whandle   A winsys handle pointer.
230     * \param stride    A stride of the buffer in bytes, for texturing.
231     * \return          TRUE on success.
232     */
233    boolean (*buffer_get_handle)(struct pb_buffer *buf,
234                                 unsigned stride,
235                                 struct winsys_handle *whandle);
236
237    /**************************************************************************
238     * Command submission.
239     *
240     * Each pipe context should create its own command stream and submit
241     * commands independently of other contexts.
242     *************************************************************************/
243
244    /**
245     * Create a command stream.
246     *
247     * \param ws        The winsys this function is called from.
248     */
249    struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws);
250
251    /**
252     * Destroy a command stream.
253     *
254     * \param cs        A command stream to destroy.
255     */
256    void (*cs_destroy)(struct radeon_winsys_cs *cs);
257
258    /**
259     * Add a new buffer relocation. Every relocation must first be added
260     * before it can be written.
261     *
262     * \param cs  A command stream to add buffer for validation against.
263     * \param buf A winsys buffer to validate.
264     * \param rd  A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
265     * \param wd  A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
266     */
267    void (*cs_add_reloc)(struct radeon_winsys_cs *cs,
268                         struct radeon_winsys_cs_handle *buf,
269                         enum radeon_bo_domain rd,
270                         enum radeon_bo_domain wd);
271
272    /**
273     * Return TRUE if there is enough memory in VRAM and GTT for the relocs
274     * added so far.
275     *
276     * \param cs        A command stream to validate.
277     */
278    boolean (*cs_validate)(struct radeon_winsys_cs *cs);
279
280    /**
281     * Write a relocated dword to a command buffer.
282     *
283     * \param cs        A command stream the relocation is written to.
284     * \param buf       A winsys buffer to write the relocation for.
285     * \param rd        A read domain containing a bitmask of the RADEON_DOMAIN_* flags.
286     * \param wd        A write domain containing a bitmask of the RADEON_DOMAIN_* flags.
287     */
288    void (*cs_write_reloc)(struct radeon_winsys_cs *cs,
289                           struct radeon_winsys_cs_handle *buf);
290
291    /**
292     * Flush a command stream.
293     *
294     * \param cs        A command stream to flush.
295     * \param flags,    RADEON_FLUSH_ASYNC or 0.
296     */
297    void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags);
298
299    /**
300     * Set a flush callback which is called from winsys when flush is
301     * required.
302     *
303     * \param cs        A command stream to set the callback for.
304     * \param flush     A flush callback function associated with the command stream.
305     * \param user      A user pointer that will be passed to the flush callback.
306     */
307    void (*cs_set_flush)(struct radeon_winsys_cs *cs,
308                         void (*flush)(void *ctx, unsigned flags),
309                         void *user);
310
311    /**
312     * Return TRUE if a buffer is referenced by a command stream.
313     *
314     * \param cs        A command stream.
315     * \param buf       A winsys buffer.
316     */
317    boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
318                                       struct radeon_winsys_cs_handle *buf);
319
320    /**
321     * Request access to a feature for a command stream.
322     *
323     * \param cs        A command stream.
324     * \param fid       A winsys buffer.
325     */
326    boolean (*cs_request_feature)(struct radeon_winsys_cs *cs,
327                                  enum radeon_feature_id fid,
328                                  boolean enable);
329};
330
331#endif
332