• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  *    Rob Clark <robclark@freedesktop.org>
25  */
26 
27 #ifndef FREEDRENO_SCREEN_H_
28 #define FREEDRENO_SCREEN_H_
29 
30 #include "common/freedreno_dev_info.h"
31 #include "drm/freedreno_drmif.h"
32 #include "drm/freedreno_ringbuffer.h"
33 #include "perfcntrs/freedreno_perfcntr.h"
34 
35 #include "pipe/p_screen.h"
36 #include "renderonly/renderonly.h"
37 #include "util/u_debug.h"
38 #include "util/simple_mtx.h"
39 #include "util/slab.h"
40 #include "util/u_idalloc.h"
41 #include "util/u_memory.h"
42 #include "util/u_queue.h"
43 
44 #include "freedreno_batch_cache.h"
45 #include "freedreno_gmem.h"
46 #include "freedreno_util.h"
47 
48 struct fd_bo;
49 
50 /* Potential reasons for needing to skip bypass path and use GMEM, the
51  * generation backend can override this with screen->gmem_reason_mask
52  */
53 enum fd_gmem_reason {
54    FD_GMEM_CLEARS_DEPTH_STENCIL = BIT(0),
55    FD_GMEM_DEPTH_ENABLED = BIT(1),
56    FD_GMEM_STENCIL_ENABLED = BIT(2),
57    FD_GMEM_BLEND_ENABLED = BIT(3),
58    FD_GMEM_LOGICOP_ENABLED = BIT(4),
59    FD_GMEM_FB_READ = BIT(5),
60 };
61 
62 struct fd_screen {
63    struct pipe_screen base;
64 
65    struct list_head context_list;
66 
67    simple_mtx_t lock;
68 
69    struct slab_parent_pool transfer_pool;
70 
71    uint64_t gmem_base;
72    uint32_t gmemsize_bytes;
73 
74    const struct fd_dev_id *dev_id;
75    uint8_t gen;      /* GPU (major) generation */
76    uint32_t gpu_id;  /* 220, 305, etc */
77    uint64_t chip_id; /* coreid:8 majorrev:8 minorrev:8 patch:8 */
78    uint32_t max_freq;
79    uint32_t ram_size;
80    uint32_t max_rts; /* max # of render targets */
81    uint32_t priority_mask;
82    unsigned prio_low, prio_norm, prio_high;  /* remap low/norm/high priority to kernel priority */
83    bool has_timestamp;
84    bool has_robustness;
85    bool has_syncobj;
86 
87    struct {
88       /* Conservative LRZ (default true) invalidates LRZ on draws with
89        * blend and depth-write enabled, because this can lead to incorrect
90        * rendering.  Driconf can be used to disable conservative LRZ for
91        * games which do not have the problematic sequence of draws *and*
92        * suffer a performance loss with conservative LRZ.
93        */
94       bool conservative_lrz;
95 
96       /* Enable EGL throttling (default true).
97        */
98       bool enable_throttling;
99    } driconf;
100 
101    struct fd_dev_info dev_info;
102    const struct fd_dev_info *info;
103    uint32_t ccu_offset_gmem;
104    uint32_t ccu_offset_bypass;
105 
106    /* Bitmask of gmem_reasons that do not force GMEM path over bypass
107     * for current generation.
108     */
109    enum fd_gmem_reason gmem_reason_mask;
110 
111    unsigned num_perfcntr_groups;
112    const struct fd_perfcntr_group *perfcntr_groups;
113 
114    /* generated at startup from the perfcntr groups: */
115    unsigned num_perfcntr_queries;
116    struct pipe_driver_query_info *perfcntr_queries;
117 
118    void *compiler;                  /* currently unused for a2xx */
119    struct util_queue compile_queue; /* currently unused for a2xx */
120 
121    struct fd_device *dev;
122 
123    /* NOTE: we still need a pipe associated with the screen in a few
124     * places, like screen->get_timestamp().  For anything context
125     * related, use ctx->pipe instead.
126     */
127    struct fd_pipe *pipe;
128 
129    uint32_t (*setup_slices)(struct fd_resource *rsc);
130    unsigned (*tile_mode)(const struct pipe_resource *prsc);
131    int (*layout_resource_for_modifier)(struct fd_resource *rsc,
132                                        uint64_t modifier);
133    bool (*is_format_supported)(struct pipe_screen *pscreen,
134                                enum pipe_format fmt, uint64_t modifier);
135 
136    /* indirect-branch emit: */
137    void (*emit_ib)(struct fd_ringbuffer *ring, struct fd_ringbuffer *target);
138 
139    /* simple gpu "memcpy": */
140    void (*mem_to_mem)(struct fd_ringbuffer *ring, struct pipe_resource *dst,
141                       unsigned dst_off, struct pipe_resource *src,
142                       unsigned src_off, unsigned sizedwords);
143 
144    int64_t cpu_gpu_time_delta;
145 
146    struct fd_batch_cache batch_cache;
147    struct fd_gmem_cache gmem_cache;
148 
149    bool reorder;
150 
151    seqno_t rsc_seqno;
152    seqno_t ctx_seqno;
153    struct util_idalloc_mt buffer_ids;
154 
155    unsigned num_supported_modifiers;
156    const uint64_t *supported_modifiers;
157 
158    struct renderonly *ro;
159 
160    /* the blob seems to always use 8K factor and 128K param sizes, copy them */
161 #define FD6_TESS_FACTOR_SIZE (8 * 1024)
162 #define FD6_TESS_PARAM_SIZE (128 * 1024)
163 #define FD6_TESS_BO_SIZE (FD6_TESS_FACTOR_SIZE + FD6_TESS_PARAM_SIZE)
164    struct fd_bo *tess_bo;
165 
166    /* table with MESA_PRIM_COUNT+1 entries mapping MESA_PRIM_x to
167     * DI_PT_x value to use for draw initiator.  There are some
168     * slight differences between generation.
169     *
170     * Note that primtypes[PRIM_TYPE_MAX] is used to map to the
171     * internal RECTLIST primtype, if available, used for blits/
172     * clears.
173     */
174    const enum pc_di_primtype *primtypes;
175    uint32_t primtypes_mask;
176 
177    simple_mtx_t aux_ctx_lock;
178    struct pipe_context *aux_ctx;
179 };
180 
181 static inline struct fd_screen *
fd_screen(struct pipe_screen * pscreen)182 fd_screen(struct pipe_screen *pscreen)
183 {
184    return (struct fd_screen *)pscreen;
185 }
186 
187 struct fd_context;
188 struct fd_context * fd_screen_aux_context_get(struct pipe_screen *pscreen);
189 void fd_screen_aux_context_put(struct pipe_screen *pscreen);
190 
191 static inline void
fd_screen_lock(struct fd_screen * screen)192 fd_screen_lock(struct fd_screen *screen)
193 {
194    simple_mtx_lock(&screen->lock);
195 }
196 
197 static inline void
fd_screen_unlock(struct fd_screen * screen)198 fd_screen_unlock(struct fd_screen *screen)
199 {
200    simple_mtx_unlock(&screen->lock);
201 }
202 
203 static inline void
fd_screen_assert_locked(struct fd_screen * screen)204 fd_screen_assert_locked(struct fd_screen *screen)
205 {
206    simple_mtx_assert_locked(&screen->lock);
207 }
208 
209 bool fd_screen_bo_get_handle(struct pipe_screen *pscreen, struct fd_bo *bo,
210                              struct renderonly_scanout *scanout,
211                              unsigned stride, struct winsys_handle *whandle);
212 struct fd_bo *fd_screen_bo_from_handle(struct pipe_screen *pscreen,
213                                        struct winsys_handle *whandle);
214 
215 struct pipe_screen *fd_screen_create(int fd,
216                                      const struct pipe_screen_config *config,
217                                      struct renderonly *ro);
218 
219 static inline bool
is_a20x(struct fd_screen * screen)220 is_a20x(struct fd_screen *screen)
221 {
222    return (screen->gpu_id >= 200) && (screen->gpu_id < 210);
223 }
224 
225 static inline bool
is_a2xx(struct fd_screen * screen)226 is_a2xx(struct fd_screen *screen)
227 {
228    return screen->gen == 2;
229 }
230 
231 /* is a3xx patch revision 0? */
232 /* TODO a306.0 probably doesn't need this.. be more clever?? */
233 static inline bool
is_a3xx_p0(struct fd_screen * screen)234 is_a3xx_p0(struct fd_screen *screen)
235 {
236    return (screen->chip_id & 0xff0000ff) == 0x03000000;
237 }
238 
239 static inline bool
is_a3xx(struct fd_screen * screen)240 is_a3xx(struct fd_screen *screen)
241 {
242    return screen->gen == 3;
243 }
244 
245 static inline bool
is_a4xx(struct fd_screen * screen)246 is_a4xx(struct fd_screen *screen)
247 {
248    return screen->gen == 4;
249 }
250 
251 static inline bool
is_a5xx(struct fd_screen * screen)252 is_a5xx(struct fd_screen *screen)
253 {
254    return screen->gen == 5;
255 }
256 
257 static inline bool
is_a6xx(struct fd_screen * screen)258 is_a6xx(struct fd_screen *screen)
259 {
260    return screen->gen == 6;
261 }
262 
263 /* is it using the ir3 compiler (shader isa introduced with a3xx)? */
264 static inline bool
is_ir3(struct fd_screen * screen)265 is_ir3(struct fd_screen *screen)
266 {
267    return is_a3xx(screen) || is_a4xx(screen) || is_a5xx(screen) ||
268           is_a6xx(screen);
269 }
270 
271 static inline bool
has_compute(struct fd_screen * screen)272 has_compute(struct fd_screen *screen)
273 {
274    return is_a4xx(screen) || is_a5xx(screen) || is_a6xx(screen);
275 }
276 
277 #endif /* FREEDRENO_SCREEN_H_ */
278