xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/crocus/crocus_screen.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2017 Intel Corporation
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  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef CROCUS_SCREEN_H
24 #define CROCUS_SCREEN_H
25 
26 #include "pipe/p_screen.h"
27 #include "pipe/p_state.h"
28 #include "frontend/drm_driver.h"
29 #include "util/disk_cache.h"
30 #include "util/slab.h"
31 #include "util/u_screen.h"
32 #include "intel/dev/intel_device_info.h"
33 #include "intel/isl/isl.h"
34 #include "crocus_bufmgr.h"
35 #include "compiler/shader_enums.h"
36 
37 struct crocus_resource;
38 struct crocus_context;
39 struct crocus_sampler_state;
40 struct intel_vue_map;
41 struct elk_tcs_prog_key;
42 struct elk_tes_prog_key;
43 struct elk_cs_prog_key;
44 struct elk_wm_prog_key;
45 struct elk_vs_prog_key;
46 struct elk_gs_prog_key;
47 struct shader_info;
48 
49 #define READ_ONCE(x) (*(volatile __typeof__(x) *)&(x))
50 #define WRITE_ONCE(x, v) *(volatile __typeof__(x) *)&(x) = (v)
51 
52 #define CROCUS_MAX_TEXTURE_SAMPLERS 32
53 #define CROCUS_MAX_SOL_BUFFERS 4
54 #define CROCUS_MAP_BUFFER_ALIGNMENT 64
55 
56 
57 /**
58  * Virtual table for generation-specific (genxml) function calls.
59  */
60 struct crocus_vtable {
61    void (*destroy_state)(struct crocus_context *ice);
62    void (*init_render_context)(struct crocus_batch *batch);
63    void (*init_compute_context)(struct crocus_batch *batch);
64    void (*upload_render_state)(struct crocus_context *ice,
65                                struct crocus_batch *batch,
66                                const struct pipe_draw_info *draw,
67                                unsigned drawid_offset,
68                                const struct pipe_draw_indirect_info *indirect,
69                                const struct pipe_draw_start_count_bias *sc);
70    void (*update_surface_base_address)(struct crocus_batch *batch);
71 
72    void (*upload_compute_state)(struct crocus_context *ice,
73                                 struct crocus_batch *batch,
74                                 const struct pipe_grid_info *grid);
75    void (*rebind_buffer)(struct crocus_context *ice,
76                          struct crocus_resource *res);
77    void (*resolve_conditional_render)(struct crocus_context *ice);
78    void (*emit_compute_predicate)(struct crocus_batch *batch);
79    void (*load_register_reg32)(struct crocus_batch *batch, uint32_t dst,
80                                uint32_t src);
81    void (*load_register_reg64)(struct crocus_batch *batch, uint32_t dst,
82                                uint32_t src);
83    void (*load_register_imm32)(struct crocus_batch *batch, uint32_t reg,
84                                uint32_t val);
85    void (*load_register_imm64)(struct crocus_batch *batch, uint32_t reg,
86                                uint64_t val);
87    void (*load_register_mem32)(struct crocus_batch *batch, uint32_t reg,
88                                struct crocus_bo *bo, uint32_t offset);
89    void (*load_register_mem64)(struct crocus_batch *batch, uint32_t reg,
90                                struct crocus_bo *bo, uint32_t offset);
91    void (*store_register_mem32)(struct crocus_batch *batch, uint32_t reg,
92                                 struct crocus_bo *bo, uint32_t offset,
93                                 bool predicated);
94    void (*store_register_mem64)(struct crocus_batch *batch, uint32_t reg,
95                                 struct crocus_bo *bo, uint32_t offset,
96                                 bool predicated);
97    void (*store_data_imm32)(struct crocus_batch *batch,
98                             struct crocus_bo *bo, uint32_t offset,
99                             uint32_t value);
100    void (*store_data_imm64)(struct crocus_batch *batch,
101                             struct crocus_bo *bo, uint32_t offset,
102                             uint64_t value);
103    void (*copy_mem_mem)(struct crocus_batch *batch,
104                         struct crocus_bo *dst_bo, uint32_t dst_offset,
105                         struct crocus_bo *src_bo, uint32_t src_offset,
106                         unsigned bytes);
107    void (*emit_raw_pipe_control)(struct crocus_batch *batch,
108                                  const char *reason, uint32_t flags,
109                                  struct crocus_bo *bo, uint32_t offset,
110                                  uint64_t imm);
111 
112    void (*emit_mi_report_perf_count)(struct crocus_batch *batch,
113                                      struct crocus_bo *bo,
114                                      uint32_t offset_in_bytes,
115                                      uint32_t report_id);
116 
117    uint32_t *(*create_so_decl_list)(const struct pipe_stream_output_info *sol,
118                                     const struct intel_vue_map *vue_map);
119    void (*populate_vs_key)(const struct crocus_context *ice,
120                            const struct shader_info *info,
121                            gl_shader_stage last_stage,
122                            struct elk_vs_prog_key *key);
123    void (*populate_tcs_key)(const struct crocus_context *ice,
124                             struct elk_tcs_prog_key *key);
125    void (*populate_tes_key)(const struct crocus_context *ice,
126                             const struct shader_info *info,
127                             gl_shader_stage last_stage,
128                             struct elk_tes_prog_key *key);
129    void (*populate_gs_key)(const struct crocus_context *ice,
130                            const struct shader_info *info,
131                            gl_shader_stage last_stage,
132                            struct elk_gs_prog_key *key);
133    void (*populate_fs_key)(const struct crocus_context *ice,
134                            const struct shader_info *info,
135                            struct elk_wm_prog_key *key);
136    void (*populate_cs_key)(const struct crocus_context *ice,
137                            struct elk_cs_prog_key *key);
138    void (*fill_clamp_mask)(const struct crocus_sampler_state *state,
139                            int s,
140                            uint32_t *clamp_mask);
141    void (*lost_genx_state)(struct crocus_context *ice, struct crocus_batch *batch);
142 
143    void (*finish_batch)(struct crocus_batch *batch); /* haswell only */
144 
145    void (*upload_urb_fence)(struct crocus_batch *batch); /* gen4/5 only */
146 
147    bool (*blit_blt)(struct crocus_batch *batch,
148                     const struct pipe_blit_info *info);
149    bool (*copy_region_blt)(struct crocus_batch *batch,
150                            struct crocus_resource *dst,
151                            unsigned dst_level,
152                            unsigned dstx, unsigned dsty, unsigned dstz,
153                            struct crocus_resource *src,
154                            unsigned src_level,
155                            const struct pipe_box *src_box);
156    bool (*calculate_urb_fence)(struct crocus_batch *batch, unsigned csize,
157                                unsigned vsize, unsigned sfsize);
158    void (*batch_reset_dirty)(struct crocus_batch *batch);
159    unsigned (*translate_prim_type)(enum mesa_prim prim, uint8_t verts_per_patch);
160 
161    void (*update_so_strides)(struct crocus_context *ice,
162                              uint16_t *strides);
163 
164    uint32_t (*get_so_offset)(struct pipe_stream_output_target *tgt);
165 };
166 
167 struct crocus_screen {
168    struct pipe_screen base;
169 
170    uint32_t refcount;
171 
172    /** Global slab allocator for crocus_transfer_map objects */
173    struct slab_parent_pool transfer_pool;
174 
175    /** drm device file descriptor, shared with bufmgr, do not close. */
176    int fd;
177 
178    /**
179     * drm device file descriptor to used for window system integration, owned
180     * by iris_screen, can be a different DRM instance than fd.
181     */
182    int winsys_fd;
183 
184    /** PCI ID for our GPU device */
185    int pci_id;
186 
187    struct crocus_vtable vtbl;
188 
189    /** Global program_string_id counter (see get_program_string_id()) */
190    unsigned program_id;
191 
192    /** Precompile shaders at link time?  (Can be disabled for debugging.) */
193    bool precompile;
194 
195    /** driconf options and application workarounds */
196    struct {
197       /** Dual color blend by location instead of index (for broken apps) */
198       bool dual_color_blend_by_location;
199       bool disable_throttling;
200       bool always_flush_cache;
201       bool limit_trig_input_range;
202       float lower_depth_range_rate;
203    } driconf;
204 
205    uint64_t aperture_bytes;
206    uint64_t aperture_threshold;
207 
208    struct intel_device_info devinfo;
209    struct isl_device isl_dev;
210    struct crocus_bufmgr *bufmgr;
211    struct elk_compiler *compiler;
212    struct intel_perf_config *perf_cfg;
213 
214    const struct intel_l3_config *l3_config_3d;
215    const struct intel_l3_config *l3_config_cs;
216 
217    struct disk_cache *disk_cache;
218 };
219 
220 struct pipe_screen *
221 crocus_screen_create(int fd, const struct pipe_screen_config *config);
222 
223 void crocus_screen_destroy(struct crocus_screen *screen);
224 
225 UNUSED static inline struct pipe_screen *
crocus_pscreen_ref(struct pipe_screen * pscreen)226 crocus_pscreen_ref(struct pipe_screen *pscreen)
227 {
228    struct crocus_screen *screen = (struct crocus_screen *) pscreen;
229 
230    p_atomic_inc(&screen->refcount);
231    return pscreen;
232 }
233 
234 UNUSED static inline void
crocus_pscreen_unref(struct pipe_screen * pscreen)235 crocus_pscreen_unref(struct pipe_screen *pscreen)
236 {
237    struct crocus_screen *screen = (struct crocus_screen *) pscreen;
238 
239    if (p_atomic_dec_zero(&screen->refcount))
240       crocus_screen_destroy(screen);
241 }
242 
243 bool
244 crocus_is_format_supported(struct pipe_screen *pscreen,
245                            enum pipe_format format,
246                            enum pipe_texture_target target,
247                            unsigned sample_count,
248                            unsigned storage_sample_count,
249                            unsigned usage);
250 
251 void crocus_disk_cache_init(struct crocus_screen *screen);
252 
253 #endif
254