1 /**************************************************************************
2 *
3 * Copyright 2018-2019 Alyssa Rosenzweig
4 * Copyright 2018-2019 Collabora, Ltd.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #ifndef PAN_SCREEN_H
30 #define PAN_SCREEN_H
31
32 #include <xf86drm.h>
33 #include "pipe/p_defines.h"
34 #include "pipe/p_screen.h"
35 #include "renderonly/renderonly.h"
36 #include "util/bitset.h"
37 #include "util/disk_cache.h"
38 #include "util/log.h"
39 #include "util/set.h"
40 #include "util/u_dynarray.h"
41
42 #include "pan_device.h"
43 #include "pan_mempool.h"
44 #include "pan_texture.h"
45
46 #define PAN_QUERY_DRAW_CALLS (PIPE_QUERY_DRIVER_SPECIFIC + 0)
47
48 static const struct pipe_driver_query_info panfrost_driver_query_list[] = {
49 {"draw-calls", PAN_QUERY_DRAW_CALLS, {0}},
50 };
51
52 struct panfrost_batch;
53 struct panfrost_context;
54 struct panfrost_resource;
55 struct panfrost_compiled_shader;
56 struct pan_fb_info;
57 struct pan_blend_state;
58
59 /* Virtual table of per-generation (GenXML) functions */
60
61 struct panfrost_vtable {
62 /* Prepares the renderer state descriptor or shader program descriptor
63 * for a given compiled shader, and if desired uploads it as well */
64 void (*prepare_shader)(struct panfrost_compiled_shader *,
65 struct panfrost_pool *, bool);
66
67 /* General destructor */
68 void (*screen_destroy)(struct pipe_screen *);
69
70 /* Populate context vtable */
71 void (*context_populate_vtbl)(struct pipe_context *pipe);
72
73 /* Device-dependent initialization of a panfrost_batch */
74 void (*init_batch)(struct panfrost_batch *batch);
75
76 /* Device-dependent submission of a panfrost_batch */
77 int (*submit_batch)(struct panfrost_batch *batch, struct pan_fb_info *fb);
78
79 /* Get blend shader */
80 struct pan_blend_shader_variant *(*get_blend_shader)(
81 struct pan_blend_shader_cache *cache, const struct pan_blend_state *,
82 nir_alu_type, nir_alu_type, unsigned rt);
83
84 /* Shader compilation methods */
85 const nir_shader_compiler_options *(*get_compiler_options)(void);
86 void (*compile_shader)(nir_shader *s, struct panfrost_compile_inputs *inputs,
87 struct util_dynarray *binary,
88 struct pan_shader_info *info);
89
90 /* Run a compute shader to get the compressed size of each superblock */
91 void (*afbc_size)(struct panfrost_batch *batch,
92 struct panfrost_resource *src,
93 struct panfrost_bo *metadata, unsigned offset,
94 unsigned level);
95
96 /* Run a compute shader to compact a sparse layout afbc resource */
97 void (*afbc_pack)(struct panfrost_batch *batch,
98 struct panfrost_resource *src, struct panfrost_bo *dst,
99 struct pan_image_slice_layout *slice,
100 struct panfrost_bo *metadata, unsigned metadata_offset,
101 unsigned level);
102 };
103
104 struct panfrost_screen {
105 struct pipe_screen base;
106 struct panfrost_device dev;
107 struct {
108 struct panfrost_pool bin_pool;
109 struct panfrost_pool desc_pool;
110 } blitter;
111
112 struct panfrost_vtable vtbl;
113 struct disk_cache *disk_cache;
114 unsigned max_afbc_packing_ratio;
115 };
116
117 static inline struct panfrost_screen *
pan_screen(struct pipe_screen * p)118 pan_screen(struct pipe_screen *p)
119 {
120 return (struct panfrost_screen *)p;
121 }
122
123 static inline struct panfrost_device *
pan_device(struct pipe_screen * p)124 pan_device(struct pipe_screen *p)
125 {
126 return &(pan_screen(p)->dev);
127 }
128
129 int panfrost_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,
130 struct pipe_driver_query_info *info);
131
132 void panfrost_cmdstream_screen_init_v4(struct panfrost_screen *screen);
133 void panfrost_cmdstream_screen_init_v5(struct panfrost_screen *screen);
134 void panfrost_cmdstream_screen_init_v6(struct panfrost_screen *screen);
135 void panfrost_cmdstream_screen_init_v7(struct panfrost_screen *screen);
136 void panfrost_cmdstream_screen_init_v9(struct panfrost_screen *screen);
137
138 #define perf_debug(dev, ...) \
139 do { \
140 if (unlikely((dev)->debug & PAN_DBG_PERF)) \
141 mesa_logw(__VA_ARGS__); \
142 } while (0)
143
144 #define perf_debug_ctx(ctx, ...) \
145 perf_debug(pan_device((ctx)->base.screen), __VA_ARGS__);
146
147 #endif /* PAN_SCREEN_H */
148