1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2010 Marek Olšák <maraeo@gmail.com>
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"),
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * on the rights to use, copy, modify, merge, publish, distribute, sub
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * license, and/or sell copies of the Software, and to permit persons to whom
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the Software is furnished to do so, subject to the following conditions:
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the next
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * paragraph) shall be included in all copies or substantial portions of the
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software.
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef RADEON_WINSYS_H
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define RADEON_WINSYS_H
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* The public winsys interface header for the radeon driver. */
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* R300 features in DRM.
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 2.6.0:
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * - Hyper-Z
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * - GB_Z_PEQ_CONFIG on rv350->r4xx
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * - R500 FG_ALPHA_VALUE
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 2.8.0:
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * - R500 US_FORMAT regs
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * - R500 ARGB2101010 colorbuffer
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * - CMask and AA regs
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * - R16F/RG16F
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipebuffer/pb_buffer.h"
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "libdrm/radeon_surface.h"
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define RADEON_MAX_CMDBUF_DWORDS (16 * 1024)
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define RADEON_FLUSH_ASYNC		(1 << 0)
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define RADEON_FLUSH_KEEP_TILING_FLAGS	(1 << 1) /* needs DRM 2.12.0 */
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define RADEON_FLUSH_COMPUTE		(1 << 2)
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Tiling flags. */
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum radeon_bo_layout {
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_LAYOUT_LINEAR = 0,
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_LAYOUT_TILED,
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_LAYOUT_SQUARETILED,
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_LAYOUT_UNKNOWN
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum radeon_bo_domain { /* bitfield */
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_DOMAIN_GTT  = 2,
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_DOMAIN_VRAM = 4
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum radeon_bo_usage { /* bitfield */
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_USAGE_READ = 2,
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_USAGE_WRITE = 4,
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_USAGE_READWRITE = RADEON_USAGE_READ | RADEON_USAGE_WRITE
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct winsys_handle;
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct radeon_winsys_cs_handle;
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct radeon_winsys_cs {
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    unsigned cdw;  /* Number of used dwords. */
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t *buf; /* The command buffer. */
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct radeon_info {
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t pci_id;
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t gart_size;
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t vram_size;
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t drm_major; /* version */
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t drm_minor;
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t drm_patchlevel;
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r300_num_gb_pipes;
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r300_num_z_pipes;
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r600_num_backends;
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r600_clock_crystal_freq;
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r600_tiling_config;
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r600_num_tile_pipes;
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r600_backend_map;
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    boolean r600_backend_map_valid;
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    boolean r600_virtual_address;
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r600_va_start;
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r600_ib_vm_max_size;
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint32_t r600_max_pipes;
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum radeon_feature_id {
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_FID_R300_HYPERZ_ACCESS,     /* ZMask + HiZ */
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    RADEON_FID_R300_CMASK_ACCESS,
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct radeon_winsys {
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Destroy this winsys.
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param ws        The winsys this function is called from.
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*destroy)(struct radeon_winsys *ws);
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Query an info structure from winsys.
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param ws        The winsys this function is called from.
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param info      Return structure
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*query_info)(struct radeon_winsys *ws,
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       struct radeon_info *info);
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**************************************************************************
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Buffer management. Buffer attributes are mostly fixed over its lifetime.
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Remember that gallium gets to choose the interface it needs, and the
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * window systems must then implement that interface (rather than the
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * other way around...).
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *************************************************************************/
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Create a buffer object.
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param ws        The winsys this function is called from.
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param size      The size to allocate.
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param alignment An alignment of the buffer in memory.
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param bind      A bitmask of the PIPE_BIND_* flags.
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param domain    A bitmask of the RADEON_DOMAIN_* flags.
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \return          The created buffer object.
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws,
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       unsigned size,
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       unsigned alignment,
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       unsigned bind,
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       enum radeon_bo_domain domain);
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)(
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            struct pb_buffer *buf);
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Map the entire data store of a buffer object into the client's address
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * space.
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer object to map.
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream to flush if the buffer is referenced by it.
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param usage     A bitmask of the PIPE_TRANSFER_* flags.
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \return          The pointer at the beginning of the buffer.
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void *(*buffer_map)(struct radeon_winsys_cs_handle *buf,
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        struct radeon_winsys_cs *cs,
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        enum pipe_transfer_usage usage);
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Unmap a buffer object from the client's address space.
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer object to unmap.
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*buffer_unmap)(struct radeon_winsys_cs_handle *buf);
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Return TRUE if a buffer object is being used by the GPU.
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer object.
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param usage     Only check whether the buffer is busy for the given usage.
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    boolean (*buffer_is_busy)(struct pb_buffer *buf,
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              enum radeon_bo_usage usage);
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Wait for a buffer object until it is not used by a GPU. This is
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * equivalent to a fence placed after the last command using the buffer,
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * and synchronizing to the fence.
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer object to wait for.
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param usage     Only wait until the buffer is idle for the given usage,
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *                  but may still be busy for some other usage.
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*buffer_wait)(struct pb_buffer *buf, enum radeon_bo_usage usage);
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Return tiling flags describing a memory layout of a buffer object.
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer object to get the flags from.
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param macrotile A pointer to the return value of the microtile flag.
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param microtile A pointer to the return value of the macrotile flag.
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \note microtile and macrotile are not bitmasks!
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*buffer_get_tiling)(struct pb_buffer *buf,
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              enum radeon_bo_layout *microtile,
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              enum radeon_bo_layout *macrotile,
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned *bankw, unsigned *bankh,
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned *tile_split,
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned *stencil_tile_split,
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned *mtilea);
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Set tiling flags describing a memory layout of a buffer object.
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer object to set the flags for.
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream to flush if the buffer is referenced by it.
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param macrotile A macrotile flag.
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param microtile A microtile flag.
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param stride    A stride of the buffer in bytes, for texturing.
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \note microtile and macrotile are not bitmasks!
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*buffer_set_tiling)(struct pb_buffer *buf,
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              struct radeon_winsys_cs *rcs,
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              enum radeon_bo_layout microtile,
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              enum radeon_bo_layout macrotile,
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned bankw, unsigned bankh,
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned tile_split,
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned stencil_tile_split,
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned mtilea,
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned stride);
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Get a winsys buffer from a winsys handle. The internal structure
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * of the handle is platform-specific and only a winsys should access it.
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param ws        The winsys this function is called from.
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param whandle   A winsys handle pointer as was received from a state
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *                  tracker.
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param stride    The returned buffer stride in bytes.
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws,
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                            struct winsys_handle *whandle,
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                            unsigned *stride);
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Get a winsys handle from a winsys buffer. The internal structure
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * of the handle is platform-specific and only a winsys should access it.
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer object to get the handle from.
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param whandle   A winsys handle pointer.
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param stride    A stride of the buffer in bytes, for texturing.
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \return          TRUE on success.
252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    boolean (*buffer_get_handle)(struct pb_buffer *buf,
254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 unsigned stride,
255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 struct winsys_handle *whandle);
256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Return the virtual address of a buffer.
259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer object
261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \return          virtual address
262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint64_t (*buffer_get_virtual_address)(struct radeon_winsys_cs_handle *buf);
264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**************************************************************************
266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Command submission.
267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Each pipe context should create its own command stream and submit
269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * commands independently of other contexts.
270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *************************************************************************/
271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Create a command stream.
274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param ws        The winsys this function is called from.
276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws);
278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Destroy a command stream.
281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream to destroy.
283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*cs_destroy)(struct radeon_winsys_cs *cs);
285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Add a new buffer relocation. Every relocation must first be added
288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * before it can be written.
289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs  A command stream to add buffer for validation against.
291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf A winsys buffer to validate.
292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param usage   Whether the buffer is used for read and/or write.
293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param domain  Bitmask of the RADEON_DOMAIN_* flags.
294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \return Relocation index.
295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    unsigned (*cs_add_reloc)(struct radeon_winsys_cs *cs,
297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                             struct radeon_winsys_cs_handle *buf,
298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                             enum radeon_bo_usage usage,
299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                             enum radeon_bo_domain domain);
300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Return TRUE if there is enough memory in VRAM and GTT for the relocs
303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * added so far. If the validation fails, all the relocations which have
304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * been added since the last call of cs_validate will be removed and
305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * the CS will be flushed (provided there are still any relocations).
306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream to validate.
308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    boolean (*cs_validate)(struct radeon_winsys_cs *cs);
310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Return TRUE if there is enough memory in VRAM and GTT for the relocs
313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * added so far.
314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream to validate.
316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param vram      VRAM memory size pending to be use
317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param gtt       GTT memory size pending to be use
318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    boolean (*cs_memory_below_limit)(struct radeon_winsys_cs *cs, uint64_t vram, uint64_t gtt);
320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Write a relocated dword to a command buffer.
323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream the relocation is written to.
325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer to write the relocation for.
326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*cs_write_reloc)(struct radeon_winsys_cs *cs,
328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           struct radeon_winsys_cs_handle *buf);
329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Flush a command stream.
332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream to flush.
334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param flags,    RADEON_FLUSH_ASYNC or 0.
335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags);
337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Set a flush callback which is called from winsys when flush is
340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * required.
341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream to set the callback for.
343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param flush     A flush callback function associated with the command stream.
344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param user      A user pointer that will be passed to the flush callback.
345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void (*cs_set_flush_callback)(struct radeon_winsys_cs *cs,
347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  void (*flush)(void *ctx, unsigned flags),
348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  void *ctx);
349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Return TRUE if a buffer is referenced by a command stream.
352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream.
354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param buf       A winsys buffer.
355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       struct radeon_winsys_cs_handle *buf,
358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       enum radeon_bo_usage usage);
359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Request access to a feature for a command stream.
362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param cs        A command stream.
364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param fid       Feature ID, one of RADEON_FID_*
365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param enable    Whether to enable or disable the feature.
366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    boolean (*cs_request_feature)(struct radeon_winsys_cs *cs,
368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  enum radeon_feature_id fid,
369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  boolean enable);
370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Initialize surface
373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param ws        The winsys this function is called from.
375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param surf      Surface structure ptr
376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    int (*surface_init)(struct radeon_winsys *ws,
378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        struct radeon_surface *surf);
379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Find best values for a surface
382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param ws        The winsys this function is called from.
384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param surf      Surface structure ptr
385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    int (*surface_best)(struct radeon_winsys *ws,
387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        struct radeon_surface *surf);
388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * Return the current timestamp (gpu clock) on r600 and later GPUs.
391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \param ws        The winsys this function is called from.
393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    uint64_t (*query_timestamp)(struct radeon_winsys *ws);
395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
398