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