19f464c52Smaya/*
29f464c52Smaya * Copyright © 2017 Intel Corporation
39f464c52Smaya *
49f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a
59f464c52Smaya * copy of this software and associated documentation files (the "Software"),
69f464c52Smaya * to deal in the Software without restriction, including without limitation
79f464c52Smaya * on the rights to use, copy, modify, merge, publish, distribute, sub
89f464c52Smaya * license, and/or sell copies of the Software, and to permit persons to whom
99f464c52Smaya * the Software is furnished to do so, subject to the following conditions:
109f464c52Smaya *
119f464c52Smaya * The above copyright notice and this permission notice (including the next
129f464c52Smaya * paragraph) shall be included in all copies or substantial portions of the
139f464c52Smaya * Software.
149f464c52Smaya *
159f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
169f464c52Smaya * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
179f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
189f464c52Smaya * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
199f464c52Smaya * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
209f464c52Smaya * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
219f464c52Smaya * USE OR OTHER DEALINGS IN THE SOFTWARE.
229f464c52Smaya */
239f464c52Smaya#ifndef IRIS_SCREEN_H
249f464c52Smaya#define IRIS_SCREEN_H
259f464c52Smaya
269f464c52Smaya#include "pipe/p_screen.h"
277ec681f3Smrg#include "frontend/drm_driver.h"
287ec681f3Smrg#include "util/disk_cache.h"
299f464c52Smaya#include "util/slab.h"
309f464c52Smaya#include "util/u_screen.h"
317ec681f3Smrg#include "intel/dev/intel_device_info.h"
329f464c52Smaya#include "intel/isl/isl.h"
339f464c52Smaya#include "iris_bufmgr.h"
347ec681f3Smrg#include "iris_binder.h"
357ec681f3Smrg#include "iris_measure.h"
367ec681f3Smrg#include "iris_resource.h"
379f464c52Smaya
387ec681f3Smrgstruct intel_l3_config;
397ec681f3Smrgstruct brw_vue_map;
407ec681f3Smrgstruct iris_vs_prog_key;
417ec681f3Smrgstruct iris_tcs_prog_key;
427ec681f3Smrgstruct iris_tes_prog_key;
437ec681f3Smrgstruct iris_gs_prog_key;
447ec681f3Smrgstruct iris_fs_prog_key;
457ec681f3Smrgstruct iris_cs_prog_key;
467ec681f3Smrgenum iris_program_cache_id;
479f464c52Smaya
489f464c52Smaya#define READ_ONCE(x) (*(volatile __typeof__(x) *)&(x))
499f464c52Smaya#define WRITE_ONCE(x, v) *(volatile __typeof__(x) *)&(x) = (v)
509f464c52Smaya
519f464c52Smaya#define IRIS_MAX_TEXTURE_SAMPLERS 32
529f464c52Smaya#define IRIS_MAX_SOL_BUFFERS 4
539f464c52Smaya#define IRIS_MAP_BUFFER_ALIGNMENT 64
549f464c52Smaya
557ec681f3Smrg/**
567ec681f3Smrg * Virtual table for generation-specific (genxml) function calls.
577ec681f3Smrg */
587ec681f3Smrgstruct iris_vtable {
597ec681f3Smrg   void (*destroy_state)(struct iris_context *ice);
607ec681f3Smrg   void (*init_render_context)(struct iris_batch *batch);
617ec681f3Smrg   void (*init_compute_context)(struct iris_batch *batch);
627ec681f3Smrg   void (*upload_render_state)(struct iris_context *ice,
637ec681f3Smrg                               struct iris_batch *batch,
647ec681f3Smrg                               const struct pipe_draw_info *draw,
657ec681f3Smrg                               unsigned drawid_offset,
667ec681f3Smrg                               const struct pipe_draw_indirect_info *indirect,
677ec681f3Smrg                               const struct pipe_draw_start_count_bias *sc);
687ec681f3Smrg   void (*update_surface_base_address)(struct iris_batch *batch,
697ec681f3Smrg                                       struct iris_binder *binder);
707ec681f3Smrg   void (*upload_compute_state)(struct iris_context *ice,
717ec681f3Smrg                                struct iris_batch *batch,
727ec681f3Smrg                                const struct pipe_grid_info *grid);
737ec681f3Smrg   void (*rebind_buffer)(struct iris_context *ice,
747ec681f3Smrg                         struct iris_resource *res);
757ec681f3Smrg   void (*load_register_reg32)(struct iris_batch *batch, uint32_t dst,
767ec681f3Smrg                               uint32_t src);
777ec681f3Smrg   void (*load_register_reg64)(struct iris_batch *batch, uint32_t dst,
787ec681f3Smrg                               uint32_t src);
797ec681f3Smrg   void (*load_register_imm32)(struct iris_batch *batch, uint32_t reg,
807ec681f3Smrg                               uint32_t val);
817ec681f3Smrg   void (*load_register_imm64)(struct iris_batch *batch, uint32_t reg,
827ec681f3Smrg                               uint64_t val);
837ec681f3Smrg   void (*load_register_mem32)(struct iris_batch *batch, uint32_t reg,
847ec681f3Smrg                               struct iris_bo *bo, uint32_t offset);
857ec681f3Smrg   void (*load_register_mem64)(struct iris_batch *batch, uint32_t reg,
867ec681f3Smrg                               struct iris_bo *bo, uint32_t offset);
877ec681f3Smrg   void (*store_register_mem32)(struct iris_batch *batch, uint32_t reg,
887ec681f3Smrg                                struct iris_bo *bo, uint32_t offset,
897ec681f3Smrg                                bool predicated);
907ec681f3Smrg   void (*store_register_mem64)(struct iris_batch *batch, uint32_t reg,
917ec681f3Smrg                                struct iris_bo *bo, uint32_t offset,
927ec681f3Smrg                                bool predicated);
937ec681f3Smrg   void (*store_data_imm32)(struct iris_batch *batch,
947ec681f3Smrg                            struct iris_bo *bo, uint32_t offset,
957ec681f3Smrg                            uint32_t value);
967ec681f3Smrg   void (*store_data_imm64)(struct iris_batch *batch,
977ec681f3Smrg                            struct iris_bo *bo, uint32_t offset,
987ec681f3Smrg                            uint64_t value);
997ec681f3Smrg   void (*copy_mem_mem)(struct iris_batch *batch,
1007ec681f3Smrg                        struct iris_bo *dst_bo, uint32_t dst_offset,
1017ec681f3Smrg                        struct iris_bo *src_bo, uint32_t src_offset,
1027ec681f3Smrg                        unsigned bytes);
1037ec681f3Smrg   void (*emit_raw_pipe_control)(struct iris_batch *batch,
1047ec681f3Smrg                                 const char *reason, uint32_t flags,
1057ec681f3Smrg                                 struct iris_bo *bo, uint32_t offset,
1067ec681f3Smrg                                 uint64_t imm);
1077ec681f3Smrg
1087ec681f3Smrg   void (*emit_mi_report_perf_count)(struct iris_batch *batch,
1097ec681f3Smrg                                     struct iris_bo *bo,
1107ec681f3Smrg                                     uint32_t offset_in_bytes,
1117ec681f3Smrg                                     uint32_t report_id);
1127ec681f3Smrg
1137ec681f3Smrg   unsigned (*derived_program_state_size)(enum iris_program_cache_id id);
1147ec681f3Smrg   void (*store_derived_program_state)(const struct intel_device_info *devinfo,
1157ec681f3Smrg                                       enum iris_program_cache_id cache_id,
1167ec681f3Smrg                                       struct iris_compiled_shader *shader);
1177ec681f3Smrg   uint32_t *(*create_so_decl_list)(const struct pipe_stream_output_info *sol,
1187ec681f3Smrg                                    const struct brw_vue_map *vue_map);
1197ec681f3Smrg   void (*populate_vs_key)(const struct iris_context *ice,
1207ec681f3Smrg                           const struct shader_info *info,
1217ec681f3Smrg                           gl_shader_stage last_stage,
1227ec681f3Smrg                           struct iris_vs_prog_key *key);
1237ec681f3Smrg   void (*populate_tcs_key)(const struct iris_context *ice,
1247ec681f3Smrg                            struct iris_tcs_prog_key *key);
1257ec681f3Smrg   void (*populate_tes_key)(const struct iris_context *ice,
1267ec681f3Smrg                            const struct shader_info *info,
1277ec681f3Smrg                            gl_shader_stage last_stage,
1287ec681f3Smrg                            struct iris_tes_prog_key *key);
1297ec681f3Smrg   void (*populate_gs_key)(const struct iris_context *ice,
1307ec681f3Smrg                           const struct shader_info *info,
1317ec681f3Smrg                           gl_shader_stage last_stage,
1327ec681f3Smrg                           struct iris_gs_prog_key *key);
1337ec681f3Smrg   void (*populate_fs_key)(const struct iris_context *ice,
1347ec681f3Smrg                           const struct shader_info *info,
1357ec681f3Smrg                           struct iris_fs_prog_key *key);
1367ec681f3Smrg   void (*populate_cs_key)(const struct iris_context *ice,
1377ec681f3Smrg                           struct iris_cs_prog_key *key);
1387ec681f3Smrg   void (*lost_genx_state)(struct iris_context *ice, struct iris_batch *batch);
1397ec681f3Smrg};
1407ec681f3Smrg
1417ec681f3Smrgstruct iris_address {
1427ec681f3Smrg   struct iris_bo *bo;
1437ec681f3Smrg   uint64_t offset;
1447ec681f3Smrg   enum iris_domain access;
1457ec681f3Smrg};
1467ec681f3Smrg
1479f464c52Smayastruct iris_screen {
1489f464c52Smaya   struct pipe_screen base;
1499f464c52Smaya
1507ec681f3Smrg   uint32_t refcount;
1517ec681f3Smrg
1529f464c52Smaya   /** Global slab allocator for iris_transfer_map objects */
1539f464c52Smaya   struct slab_parent_pool transfer_pool;
1549f464c52Smaya
1557ec681f3Smrg   /** drm device file descriptor, shared with bufmgr, do not close. */
1569f464c52Smaya   int fd;
1579f464c52Smaya
1587ec681f3Smrg   /**
1597ec681f3Smrg    * drm device file descriptor to used for window system integration, owned
1607ec681f3Smrg    * by iris_screen, can be a different DRM instance than fd.
1617ec681f3Smrg    */
1627ec681f3Smrg   int winsys_fd;
1637ec681f3Smrg
1649f464c52Smaya   /** PCI ID for our GPU device */
1659f464c52Smaya   int pci_id;
1669f464c52Smaya
1677ec681f3Smrg   struct iris_vtable vtbl;
1689f464c52Smaya
1699f464c52Smaya   /** Global program_string_id counter (see get_program_string_id()) */
1709f464c52Smaya   unsigned program_id;
1719f464c52Smaya
1729f464c52Smaya   /** Precompile shaders at link time?  (Can be disabled for debugging.) */
1739f464c52Smaya   bool precompile;
1749f464c52Smaya
1759f464c52Smaya   /** driconf options and application workarounds */
1769f464c52Smaya   struct {
1779f464c52Smaya      /** Dual color blend by location instead of index (for broken apps) */
1789f464c52Smaya      bool dual_color_blend_by_location;
1797ec681f3Smrg      bool disable_throttling;
1807ec681f3Smrg      bool always_flush_cache;
1817ec681f3Smrg      bool sync_compile;
1829f464c52Smaya   } driconf;
1839f464c52Smaya
1847ec681f3Smrg   /** Does the kernel support various features (KERNEL_HAS_* bitfield)? */
1857ec681f3Smrg   unsigned kernel_features;
1867ec681f3Smrg#define KERNEL_HAS_WAIT_FOR_SUBMIT (1<<0)
1877ec681f3Smrg
1887ec681f3Smrg   uint64_t aperture_bytes;
1897ec681f3Smrg
1907ec681f3Smrg   /**
1917ec681f3Smrg    * Last sequence number allocated by the cache tracking mechanism.
1927ec681f3Smrg    *
1937ec681f3Smrg    * These are used for synchronization and are expected to identify a single
1947ec681f3Smrg    * section of a batch, so they should be monotonically increasing and
1957ec681f3Smrg    * unique across a single pipe_screen.
1967ec681f3Smrg    */
1977ec681f3Smrg   uint64_t last_seqno;
1989f464c52Smaya
1997ec681f3Smrg   struct intel_device_info devinfo;
2009f464c52Smaya   struct isl_device isl_dev;
2019f464c52Smaya   struct iris_bufmgr *bufmgr;
2029f464c52Smaya   struct brw_compiler *compiler;
2037ec681f3Smrg   struct intel_perf_config *perf_cfg;
2047ec681f3Smrg
2057ec681f3Smrg   const struct intel_l3_config *l3_config_3d;
2067ec681f3Smrg   const struct intel_l3_config *l3_config_cs;
2079f464c52Smaya
2089f464c52Smaya   /**
2097ec681f3Smrg    * A buffer containing a marker + description of the driver. This buffer is
2107ec681f3Smrg    * added to all execbufs syscalls so that we can identify the driver that
2117ec681f3Smrg    * generated a hang by looking at the content of the buffer in the error
2127ec681f3Smrg    * state. It is also used for hardware workarounds that require scratch
2137ec681f3Smrg    * writes or reads from some unimportant memory. To avoid overriding the
2147ec681f3Smrg    * debug data, use the workaround_address field for workarounds.
2159f464c52Smaya    */
2169f464c52Smaya   struct iris_bo *workaround_bo;
2177ec681f3Smrg   struct iris_address workaround_address;
2187ec681f3Smrg
2197ec681f3Smrg   struct util_queue shader_compiler_queue;
2207ec681f3Smrg
2217ec681f3Smrg   struct disk_cache *disk_cache;
2227ec681f3Smrg
2237ec681f3Smrg   struct intel_measure_device measure;
2247ec681f3Smrg
2257ec681f3Smrg   /** Every screen on a bufmgr has an unique ID assigned by the bufmgr. */
2267ec681f3Smrg   int id;
2279f464c52Smaya};
2289f464c52Smaya
2299f464c52Smayastruct pipe_screen *
2309f464c52Smayairis_screen_create(int fd, const struct pipe_screen_config *config);
2319f464c52Smaya
2327ec681f3Smrgvoid iris_screen_destroy(struct iris_screen *screen);
2337ec681f3Smrg
2347ec681f3SmrgUNUSED static inline struct pipe_screen *
2357ec681f3Smrgiris_pscreen_ref(struct pipe_screen *pscreen)
2367ec681f3Smrg{
2377ec681f3Smrg   struct iris_screen *screen = (struct iris_screen *) pscreen;
2387ec681f3Smrg
2397ec681f3Smrg   p_atomic_inc(&screen->refcount);
2407ec681f3Smrg   return pscreen;
2417ec681f3Smrg}
2427ec681f3Smrg
2437ec681f3SmrgUNUSED static inline void
2447ec681f3Smrgiris_pscreen_unref(struct pipe_screen *pscreen)
2457ec681f3Smrg{
2467ec681f3Smrg   struct iris_screen *screen = (struct iris_screen *) pscreen;
2477ec681f3Smrg
2487ec681f3Smrg   if (p_atomic_dec_zero(&screen->refcount))
2497ec681f3Smrg      iris_screen_destroy(screen);
2507ec681f3Smrg}
2517ec681f3Smrg
2527ec681f3Smrgbool
2539f464c52Smayairis_is_format_supported(struct pipe_screen *pscreen,
2549f464c52Smaya                         enum pipe_format format,
2559f464c52Smaya                         enum pipe_texture_target target,
2569f464c52Smaya                         unsigned sample_count,
2579f464c52Smaya                         unsigned storage_sample_count,
2589f464c52Smaya                         unsigned usage);
2599f464c52Smaya
2607ec681f3Smrgvoid iris_disk_cache_init(struct iris_screen *screen);
2617ec681f3Smrg
2629f464c52Smaya#endif
263