xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/panfrost/pan_screen.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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    /* Initialize/cleanup a Gallium context */
74    int (*context_init)(struct panfrost_context *ctx);
75    void (*context_cleanup)(struct panfrost_context *ctx);
76 
77    /* Device-dependent initialization/cleanup of a panfrost_batch */
78    void (*init_batch)(struct panfrost_batch *batch);
79    void (*cleanup_batch)(struct panfrost_batch *batch);
80 
81    /* Device-dependent submission of a panfrost_batch */
82    int (*submit_batch)(struct panfrost_batch *batch, struct pan_fb_info *fb);
83 
84    /* Get blend shader */
85    struct pan_blend_shader_variant *(*get_blend_shader)(
86       struct pan_blend_shader_cache *cache, const struct pan_blend_state *,
87       nir_alu_type, nir_alu_type, unsigned rt);
88 
89    /* Shader compilation methods */
90    const nir_shader_compiler_options *(*get_compiler_options)(void);
91    void (*compile_shader)(nir_shader *s, struct panfrost_compile_inputs *inputs,
92                           struct util_dynarray *binary,
93                           struct pan_shader_info *info);
94 
95    /* Run a compute shader to get the compressed size of each superblock */
96    void (*afbc_size)(struct panfrost_batch *batch,
97                      struct panfrost_resource *src,
98                      struct panfrost_bo *metadata, unsigned offset,
99                      unsigned level);
100 
101    /* Run a compute shader to compact a sparse layout afbc resource */
102    void (*afbc_pack)(struct panfrost_batch *batch,
103                      struct panfrost_resource *src, struct panfrost_bo *dst,
104                      struct pan_image_slice_layout *slice,
105                      struct panfrost_bo *metadata, unsigned metadata_offset,
106                      unsigned level);
107 
108    void (*emit_write_timestamp)(struct panfrost_batch *batch,
109                                 struct panfrost_resource *dst, unsigned offset);
110 };
111 
112 struct panfrost_screen {
113    struct pipe_screen base;
114    struct panfrost_device dev;
115    struct {
116       struct panfrost_pool bin_pool;
117       struct panfrost_pool desc_pool;
118    } blitter;
119 
120    struct panfrost_vtable vtbl;
121    struct disk_cache *disk_cache;
122    unsigned max_afbc_packing_ratio;
123    bool force_afbc_packing;
124    int force_afrc_rate;
125 
126    struct {
127       unsigned chunk_size;
128       unsigned initial_chunks;
129       unsigned max_chunks;
130    } csf_tiler_heap;
131 };
132 
133 static inline struct panfrost_screen *
pan_screen(struct pipe_screen * p)134 pan_screen(struct pipe_screen *p)
135 {
136    return (struct panfrost_screen *)p;
137 }
138 
139 static inline struct panfrost_device *
pan_device(struct pipe_screen * p)140 pan_device(struct pipe_screen *p)
141 {
142    return &(pan_screen(p)->dev);
143 }
144 
145 int panfrost_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,
146                                    struct pipe_driver_query_info *info);
147 
148 void panfrost_cmdstream_screen_init_v4(struct panfrost_screen *screen);
149 void panfrost_cmdstream_screen_init_v5(struct panfrost_screen *screen);
150 void panfrost_cmdstream_screen_init_v6(struct panfrost_screen *screen);
151 void panfrost_cmdstream_screen_init_v7(struct panfrost_screen *screen);
152 void panfrost_cmdstream_screen_init_v9(struct panfrost_screen *screen);
153 void panfrost_cmdstream_screen_init_v10(struct panfrost_screen *screen);
154 
155 #define perf_debug(ctx, ...)                                                   \
156    do {                                                                        \
157       if (unlikely(pan_device((ctx)->base.screen)->debug & PAN_DBG_PERF))      \
158          mesa_logw(__VA_ARGS__);                                               \
159       util_debug_message(&ctx->base.debug, PERF_INFO, __VA_ARGS__);            \
160    } while (0)
161 
162 #endif /* PAN_SCREEN_H */
163