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 IRIS_SCREEN_H
24bf215546Sopenharmony_ci#define IRIS_SCREEN_H
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#include "pipe/p_screen.h"
27bf215546Sopenharmony_ci#include "frontend/drm_driver.h"
28bf215546Sopenharmony_ci#include "util/disk_cache.h"
29bf215546Sopenharmony_ci#include "util/slab.h"
30bf215546Sopenharmony_ci#include "util/u_screen.h"
31bf215546Sopenharmony_ci#include "intel/dev/intel_device_info.h"
32bf215546Sopenharmony_ci#include "intel/isl/isl.h"
33bf215546Sopenharmony_ci#include "iris_bufmgr.h"
34bf215546Sopenharmony_ci#include "iris_binder.h"
35bf215546Sopenharmony_ci#include "iris_measure.h"
36bf215546Sopenharmony_ci#include "iris_resource.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistruct intel_l3_config;
39bf215546Sopenharmony_cistruct brw_vue_map;
40bf215546Sopenharmony_cistruct iris_vs_prog_key;
41bf215546Sopenharmony_cistruct iris_tcs_prog_key;
42bf215546Sopenharmony_cistruct iris_tes_prog_key;
43bf215546Sopenharmony_cistruct iris_gs_prog_key;
44bf215546Sopenharmony_cistruct iris_fs_prog_key;
45bf215546Sopenharmony_cistruct iris_cs_prog_key;
46bf215546Sopenharmony_cienum iris_program_cache_id;
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_cistruct u_trace;
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 IRIS_MAX_TEXTURE_SAMPLERS 32
54bf215546Sopenharmony_ci#define IRIS_MAX_SOL_BUFFERS 4
55bf215546Sopenharmony_ci#define IRIS_MAP_BUFFER_ALIGNMENT 64
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci/**
58bf215546Sopenharmony_ci * Virtual table for generation-specific (genxml) function calls.
59bf215546Sopenharmony_ci */
60bf215546Sopenharmony_cistruct iris_vtable {
61bf215546Sopenharmony_ci   void (*destroy_state)(struct iris_context *ice);
62bf215546Sopenharmony_ci   void (*init_render_context)(struct iris_batch *batch);
63bf215546Sopenharmony_ci   void (*init_compute_context)(struct iris_batch *batch);
64bf215546Sopenharmony_ci   void (*upload_render_state)(struct iris_context *ice,
65bf215546Sopenharmony_ci                               struct iris_batch *batch,
66bf215546Sopenharmony_ci                               const struct pipe_draw_info *draw,
67bf215546Sopenharmony_ci                               unsigned drawid_offset,
68bf215546Sopenharmony_ci                               const struct pipe_draw_indirect_info *indirect,
69bf215546Sopenharmony_ci                               const struct pipe_draw_start_count_bias *sc);
70bf215546Sopenharmony_ci   void (*update_binder_address)(struct iris_batch *batch,
71bf215546Sopenharmony_ci                                 struct iris_binder *binder);
72bf215546Sopenharmony_ci   void (*upload_compute_state)(struct iris_context *ice,
73bf215546Sopenharmony_ci                                struct iris_batch *batch,
74bf215546Sopenharmony_ci                                const struct pipe_grid_info *grid);
75bf215546Sopenharmony_ci   void (*rebind_buffer)(struct iris_context *ice,
76bf215546Sopenharmony_ci                         struct iris_resource *res);
77bf215546Sopenharmony_ci   void (*load_register_reg32)(struct iris_batch *batch, uint32_t dst,
78bf215546Sopenharmony_ci                               uint32_t src);
79bf215546Sopenharmony_ci   void (*load_register_reg64)(struct iris_batch *batch, uint32_t dst,
80bf215546Sopenharmony_ci                               uint32_t src);
81bf215546Sopenharmony_ci   void (*load_register_imm32)(struct iris_batch *batch, uint32_t reg,
82bf215546Sopenharmony_ci                               uint32_t val);
83bf215546Sopenharmony_ci   void (*load_register_imm64)(struct iris_batch *batch, uint32_t reg,
84bf215546Sopenharmony_ci                               uint64_t val);
85bf215546Sopenharmony_ci   void (*load_register_mem32)(struct iris_batch *batch, uint32_t reg,
86bf215546Sopenharmony_ci                               struct iris_bo *bo, uint32_t offset);
87bf215546Sopenharmony_ci   void (*load_register_mem64)(struct iris_batch *batch, uint32_t reg,
88bf215546Sopenharmony_ci                               struct iris_bo *bo, uint32_t offset);
89bf215546Sopenharmony_ci   void (*store_register_mem32)(struct iris_batch *batch, uint32_t reg,
90bf215546Sopenharmony_ci                                struct iris_bo *bo, uint32_t offset,
91bf215546Sopenharmony_ci                                bool predicated);
92bf215546Sopenharmony_ci   void (*store_register_mem64)(struct iris_batch *batch, uint32_t reg,
93bf215546Sopenharmony_ci                                struct iris_bo *bo, uint32_t offset,
94bf215546Sopenharmony_ci                                bool predicated);
95bf215546Sopenharmony_ci   void (*store_data_imm32)(struct iris_batch *batch,
96bf215546Sopenharmony_ci                            struct iris_bo *bo, uint32_t offset,
97bf215546Sopenharmony_ci                            uint32_t value);
98bf215546Sopenharmony_ci   void (*store_data_imm64)(struct iris_batch *batch,
99bf215546Sopenharmony_ci                            struct iris_bo *bo, uint32_t offset,
100bf215546Sopenharmony_ci                            uint64_t value);
101bf215546Sopenharmony_ci   void (*copy_mem_mem)(struct iris_batch *batch,
102bf215546Sopenharmony_ci                        struct iris_bo *dst_bo, uint32_t dst_offset,
103bf215546Sopenharmony_ci                        struct iris_bo *src_bo, uint32_t src_offset,
104bf215546Sopenharmony_ci                        unsigned bytes);
105bf215546Sopenharmony_ci   void (*emit_raw_pipe_control)(struct iris_batch *batch,
106bf215546Sopenharmony_ci                                 const char *reason, uint32_t flags,
107bf215546Sopenharmony_ci                                 struct iris_bo *bo, uint32_t offset,
108bf215546Sopenharmony_ci                                 uint64_t imm);
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   void (*emit_mi_report_perf_count)(struct iris_batch *batch,
111bf215546Sopenharmony_ci                                     struct iris_bo *bo,
112bf215546Sopenharmony_ci                                     uint32_t offset_in_bytes,
113bf215546Sopenharmony_ci                                     uint32_t report_id);
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci   unsigned (*derived_program_state_size)(enum iris_program_cache_id id);
116bf215546Sopenharmony_ci   void (*store_derived_program_state)(const struct intel_device_info *devinfo,
117bf215546Sopenharmony_ci                                       enum iris_program_cache_id cache_id,
118bf215546Sopenharmony_ci                                       struct iris_compiled_shader *shader);
119bf215546Sopenharmony_ci   uint32_t *(*create_so_decl_list)(const struct pipe_stream_output_info *sol,
120bf215546Sopenharmony_ci                                    const struct brw_vue_map *vue_map);
121bf215546Sopenharmony_ci   void (*populate_vs_key)(const struct iris_context *ice,
122bf215546Sopenharmony_ci                           const struct shader_info *info,
123bf215546Sopenharmony_ci                           gl_shader_stage last_stage,
124bf215546Sopenharmony_ci                           struct iris_vs_prog_key *key);
125bf215546Sopenharmony_ci   void (*populate_tcs_key)(const struct iris_context *ice,
126bf215546Sopenharmony_ci                            struct iris_tcs_prog_key *key);
127bf215546Sopenharmony_ci   void (*populate_tes_key)(const struct iris_context *ice,
128bf215546Sopenharmony_ci                            const struct shader_info *info,
129bf215546Sopenharmony_ci                            gl_shader_stage last_stage,
130bf215546Sopenharmony_ci                            struct iris_tes_prog_key *key);
131bf215546Sopenharmony_ci   void (*populate_gs_key)(const struct iris_context *ice,
132bf215546Sopenharmony_ci                           const struct shader_info *info,
133bf215546Sopenharmony_ci                           gl_shader_stage last_stage,
134bf215546Sopenharmony_ci                           struct iris_gs_prog_key *key);
135bf215546Sopenharmony_ci   void (*populate_fs_key)(const struct iris_context *ice,
136bf215546Sopenharmony_ci                           const struct shader_info *info,
137bf215546Sopenharmony_ci                           struct iris_fs_prog_key *key);
138bf215546Sopenharmony_ci   void (*populate_cs_key)(const struct iris_context *ice,
139bf215546Sopenharmony_ci                           struct iris_cs_prog_key *key);
140bf215546Sopenharmony_ci   void (*lost_genx_state)(struct iris_context *ice, struct iris_batch *batch);
141bf215546Sopenharmony_ci   void (*disable_rhwo_optimization)(struct iris_batch *batch, bool disable);
142bf215546Sopenharmony_ci};
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_cistruct iris_address {
145bf215546Sopenharmony_ci   struct iris_bo *bo;
146bf215546Sopenharmony_ci   uint64_t offset;
147bf215546Sopenharmony_ci   enum iris_domain access;
148bf215546Sopenharmony_ci};
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_cistruct iris_screen {
151bf215546Sopenharmony_ci   struct pipe_screen base;
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci   uint32_t refcount;
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci   /** Global slab allocator for iris_transfer_map objects */
156bf215546Sopenharmony_ci   struct slab_parent_pool transfer_pool;
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci   /** drm device file descriptor, shared with bufmgr, do not close. */
159bf215546Sopenharmony_ci   int fd;
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci   /**
162bf215546Sopenharmony_ci    * drm device file descriptor to used for window system integration, owned
163bf215546Sopenharmony_ci    * by iris_screen, can be a different DRM instance than fd.
164bf215546Sopenharmony_ci    */
165bf215546Sopenharmony_ci   int winsys_fd;
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ci   /** PCI ID for our GPU device */
168bf215546Sopenharmony_ci   int pci_id;
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci   struct iris_vtable vtbl;
171bf215546Sopenharmony_ci
172bf215546Sopenharmony_ci   /** Global program_string_id counter (see get_program_string_id()) */
173bf215546Sopenharmony_ci   unsigned program_id;
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci   /** Precompile shaders at link time?  (Can be disabled for debugging.) */
176bf215546Sopenharmony_ci   bool precompile;
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ci   /** driconf options and application workarounds */
179bf215546Sopenharmony_ci   struct {
180bf215546Sopenharmony_ci      /** Dual color blend by location instead of index (for broken apps) */
181bf215546Sopenharmony_ci      bool dual_color_blend_by_location;
182bf215546Sopenharmony_ci      bool disable_throttling;
183bf215546Sopenharmony_ci      bool always_flush_cache;
184bf215546Sopenharmony_ci      bool sync_compile;
185bf215546Sopenharmony_ci      bool limit_trig_input_range;
186bf215546Sopenharmony_ci   } driconf;
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ci   /** Does the kernel support various features (KERNEL_HAS_* bitfield)? */
189bf215546Sopenharmony_ci   unsigned kernel_features;
190bf215546Sopenharmony_ci#define KERNEL_HAS_WAIT_FOR_SUBMIT (1<<0)
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci   /**
193bf215546Sopenharmony_ci    * Last sequence number allocated by the cache tracking mechanism.
194bf215546Sopenharmony_ci    *
195bf215546Sopenharmony_ci    * These are used for synchronization and are expected to identify a single
196bf215546Sopenharmony_ci    * section of a batch, so they should be monotonically increasing and
197bf215546Sopenharmony_ci    * unique across a single pipe_screen.
198bf215546Sopenharmony_ci    */
199bf215546Sopenharmony_ci   uint64_t last_seqno;
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_ci   struct intel_device_info devinfo;
202bf215546Sopenharmony_ci   struct isl_device isl_dev;
203bf215546Sopenharmony_ci   struct iris_bufmgr *bufmgr;
204bf215546Sopenharmony_ci   struct brw_compiler *compiler;
205bf215546Sopenharmony_ci   struct intel_perf_config *perf_cfg;
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_ci   const struct intel_l3_config *l3_config_3d;
208bf215546Sopenharmony_ci   const struct intel_l3_config *l3_config_cs;
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci   /**
211bf215546Sopenharmony_ci    * A buffer containing a marker + description of the driver. This buffer is
212bf215546Sopenharmony_ci    * added to all execbufs syscalls so that we can identify the driver that
213bf215546Sopenharmony_ci    * generated a hang by looking at the content of the buffer in the error
214bf215546Sopenharmony_ci    * state. It is also used for hardware workarounds that require scratch
215bf215546Sopenharmony_ci    * writes or reads from some unimportant memory. To avoid overriding the
216bf215546Sopenharmony_ci    * debug data, use the workaround_address field for workarounds.
217bf215546Sopenharmony_ci    */
218bf215546Sopenharmony_ci   struct iris_bo *workaround_bo;
219bf215546Sopenharmony_ci   struct iris_address workaround_address;
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_ci   struct util_queue shader_compiler_queue;
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ci   struct disk_cache *disk_cache;
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ci   struct intel_measure_device measure;
226bf215546Sopenharmony_ci
227bf215546Sopenharmony_ci   /** Every screen on a bufmgr has an unique ID assigned by the bufmgr. */
228bf215546Sopenharmony_ci   int id;
229bf215546Sopenharmony_ci};
230bf215546Sopenharmony_ci
231bf215546Sopenharmony_cistruct pipe_screen *
232bf215546Sopenharmony_ciiris_screen_create(int fd, const struct pipe_screen_config *config);
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_civoid iris_screen_destroy(struct iris_screen *screen);
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ciUNUSED static inline struct pipe_screen *
237bf215546Sopenharmony_ciiris_pscreen_ref(struct pipe_screen *pscreen)
238bf215546Sopenharmony_ci{
239bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *) pscreen;
240bf215546Sopenharmony_ci
241bf215546Sopenharmony_ci   p_atomic_inc(&screen->refcount);
242bf215546Sopenharmony_ci   return pscreen;
243bf215546Sopenharmony_ci}
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ciUNUSED static inline void
246bf215546Sopenharmony_ciiris_pscreen_unref(struct pipe_screen *pscreen)
247bf215546Sopenharmony_ci{
248bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *) pscreen;
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ci   if (p_atomic_dec_zero(&screen->refcount))
251bf215546Sopenharmony_ci      iris_screen_destroy(screen);
252bf215546Sopenharmony_ci}
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_cibool
255bf215546Sopenharmony_ciiris_is_format_supported(struct pipe_screen *pscreen,
256bf215546Sopenharmony_ci                         enum pipe_format format,
257bf215546Sopenharmony_ci                         enum pipe_texture_target target,
258bf215546Sopenharmony_ci                         unsigned sample_count,
259bf215546Sopenharmony_ci                         unsigned storage_sample_count,
260bf215546Sopenharmony_ci                         unsigned usage);
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_civoid iris_disk_cache_init(struct iris_screen *screen);
263bf215546Sopenharmony_ci
264bf215546Sopenharmony_ci#endif
265