1bf215546Sopenharmony_ci#ifndef __NOUVEAU_SCREEN_H__
2bf215546Sopenharmony_ci#define __NOUVEAU_SCREEN_H__
3bf215546Sopenharmony_ci
4bf215546Sopenharmony_ci#include "pipe/p_screen.h"
5bf215546Sopenharmony_ci#include "util/disk_cache.h"
6bf215546Sopenharmony_ci#include "util/u_atomic.h"
7bf215546Sopenharmony_ci#include "util/u_memory.h"
8bf215546Sopenharmony_ci
9bf215546Sopenharmony_ci#ifndef NDEBUG
10bf215546Sopenharmony_ci# define NOUVEAU_ENABLE_DRIVER_STATISTICS
11bf215546Sopenharmony_ci#endif
12bf215546Sopenharmony_ci
13bf215546Sopenharmony_citypedef uint32_t u32;
14bf215546Sopenharmony_citypedef uint16_t u16;
15bf215546Sopenharmony_ci
16bf215546Sopenharmony_ciextern int nouveau_mesa_debug;
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_cistruct nouveau_bo;
19bf215546Sopenharmony_ci
20bf215546Sopenharmony_ci#define NOUVEAU_SHADER_CACHE_FLAGS_IR_TGSI 0 << 0
21bf215546Sopenharmony_ci#define NOUVEAU_SHADER_CACHE_FLAGS_IR_NIR  1 << 0
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_cistruct nouveau_screen {
24bf215546Sopenharmony_ci   struct pipe_screen base;
25bf215546Sopenharmony_ci   struct nouveau_drm *drm;
26bf215546Sopenharmony_ci   struct nouveau_device *device;
27bf215546Sopenharmony_ci   struct nouveau_object *channel;
28bf215546Sopenharmony_ci   struct nouveau_client *client;
29bf215546Sopenharmony_ci   struct nouveau_pushbuf *pushbuf;
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci   char chipset_name[8];
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci   int refcount;
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci   unsigned transfer_pushbuf_threshold;
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci   unsigned vidmem_bindings; /* PIPE_BIND_* where VRAM placement is desired */
38bf215546Sopenharmony_ci   unsigned sysmem_bindings; /* PIPE_BIND_* where GART placement is desired */
39bf215546Sopenharmony_ci   unsigned lowmem_bindings; /* PIPE_BIND_* that require an address < 4 GiB */
40bf215546Sopenharmony_ci   /*
41bf215546Sopenharmony_ci    * For bindings with (vidmem & sysmem) bits set, PIPE_USAGE_* decides
42bf215546Sopenharmony_ci    * placement.
43bf215546Sopenharmony_ci    */
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci   uint16_t class_3d;
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci   struct {
48bf215546Sopenharmony_ci      struct nouveau_fence *head;
49bf215546Sopenharmony_ci      struct nouveau_fence *tail;
50bf215546Sopenharmony_ci      struct nouveau_fence *current;
51bf215546Sopenharmony_ci      u32 sequence;
52bf215546Sopenharmony_ci      u32 sequence_ack;
53bf215546Sopenharmony_ci      void (*emit)(struct pipe_screen *, u32 *sequence);
54bf215546Sopenharmony_ci      u32  (*update)(struct pipe_screen *);
55bf215546Sopenharmony_ci   } fence;
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   struct nouveau_mman *mm_VRAM;
58bf215546Sopenharmony_ci   struct nouveau_mman *mm_GART;
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci   int64_t cpu_gpu_time_delta;
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   bool hint_buf_keep_sysmem_copy;
63bf215546Sopenharmony_ci   bool tegra_sector_layout;
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci   unsigned vram_domain;
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci   struct {
68bf215546Sopenharmony_ci      unsigned profiles_checked;
69bf215546Sopenharmony_ci      unsigned profiles_present;
70bf215546Sopenharmony_ci   } firmware_info;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   struct disk_cache *disk_shader_cache;
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci   bool prefer_nir;
75bf215546Sopenharmony_ci   bool force_enable_cl;
76bf215546Sopenharmony_ci   bool has_svm;
77bf215546Sopenharmony_ci   bool disable_fences;
78bf215546Sopenharmony_ci   void *svm_cutout;
79bf215546Sopenharmony_ci   size_t svm_cutout_size;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
82bf215546Sopenharmony_ci   union {
83bf215546Sopenharmony_ci      uint64_t v[29];
84bf215546Sopenharmony_ci      struct {
85bf215546Sopenharmony_ci         uint64_t tex_obj_current_count;
86bf215546Sopenharmony_ci         uint64_t tex_obj_current_bytes;
87bf215546Sopenharmony_ci         uint64_t buf_obj_current_count;
88bf215546Sopenharmony_ci         uint64_t buf_obj_current_bytes_vid;
89bf215546Sopenharmony_ci         uint64_t buf_obj_current_bytes_sys;
90bf215546Sopenharmony_ci         uint64_t tex_transfers_rd;
91bf215546Sopenharmony_ci         uint64_t tex_transfers_wr;
92bf215546Sopenharmony_ci         uint64_t tex_copy_count;
93bf215546Sopenharmony_ci         uint64_t tex_blit_count;
94bf215546Sopenharmony_ci         uint64_t tex_cache_flush_count;
95bf215546Sopenharmony_ci         uint64_t buf_transfers_rd;
96bf215546Sopenharmony_ci         uint64_t buf_transfers_wr;
97bf215546Sopenharmony_ci         uint64_t buf_read_bytes_staging_vid;
98bf215546Sopenharmony_ci         uint64_t buf_write_bytes_direct;
99bf215546Sopenharmony_ci         uint64_t buf_write_bytes_staging_vid;
100bf215546Sopenharmony_ci         uint64_t buf_write_bytes_staging_sys;
101bf215546Sopenharmony_ci         uint64_t buf_copy_bytes;
102bf215546Sopenharmony_ci         uint64_t buf_non_kernel_fence_sync_count;
103bf215546Sopenharmony_ci         uint64_t any_non_kernel_fence_sync_count;
104bf215546Sopenharmony_ci         uint64_t query_sync_count;
105bf215546Sopenharmony_ci         uint64_t gpu_serialize_count;
106bf215546Sopenharmony_ci         uint64_t draw_calls_array;
107bf215546Sopenharmony_ci         uint64_t draw_calls_indexed;
108bf215546Sopenharmony_ci         uint64_t draw_calls_fallback_count;
109bf215546Sopenharmony_ci         uint64_t user_buffer_upload_bytes;
110bf215546Sopenharmony_ci         uint64_t constbuf_upload_count;
111bf215546Sopenharmony_ci         uint64_t constbuf_upload_bytes;
112bf215546Sopenharmony_ci         uint64_t pushbuf_count;
113bf215546Sopenharmony_ci         uint64_t resource_validate_count;
114bf215546Sopenharmony_ci      } named;
115bf215546Sopenharmony_ci   } stats;
116bf215546Sopenharmony_ci#endif
117bf215546Sopenharmony_ci};
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci#define NV_VRAM_DOMAIN(screen) ((screen)->vram_domain)
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
122bf215546Sopenharmony_ci# define NOUVEAU_DRV_STAT(s, n, v) do {         \
123bf215546Sopenharmony_ci      p_atomic_add(&(s)->stats.named.n, (v));   \
124bf215546Sopenharmony_ci   } while(0)
125bf215546Sopenharmony_ci# define NOUVEAU_DRV_STAT_RES(r, n, v) do {                                \
126bf215546Sopenharmony_ci      p_atomic_add(&nouveau_screen((r)->base.screen)->stats.named.n, v);   \
127bf215546Sopenharmony_ci   } while(0)
128bf215546Sopenharmony_ci# define NOUVEAU_DRV_STAT_IFD(x) x
129bf215546Sopenharmony_ci#else
130bf215546Sopenharmony_ci# define NOUVEAU_DRV_STAT(s, n, v)     do { } while(0)
131bf215546Sopenharmony_ci# define NOUVEAU_DRV_STAT_RES(r, n, v) do { } while(0)
132bf215546Sopenharmony_ci# define NOUVEAU_DRV_STAT_IFD(x)
133bf215546Sopenharmony_ci#endif
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_cistatic inline struct nouveau_screen *
136bf215546Sopenharmony_cinouveau_screen(struct pipe_screen *pscreen)
137bf215546Sopenharmony_ci{
138bf215546Sopenharmony_ci   return (struct nouveau_screen *)pscreen;
139bf215546Sopenharmony_ci}
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_cibool nouveau_drm_screen_unref(struct nouveau_screen *screen);
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_cibool
144bf215546Sopenharmony_cinouveau_screen_bo_get_handle(struct pipe_screen *pscreen,
145bf215546Sopenharmony_ci                             struct nouveau_bo *bo,
146bf215546Sopenharmony_ci                             unsigned stride,
147bf215546Sopenharmony_ci                             struct winsys_handle *whandle);
148bf215546Sopenharmony_cistruct nouveau_bo *
149bf215546Sopenharmony_cinouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
150bf215546Sopenharmony_ci                              struct winsys_handle *whandle,
151bf215546Sopenharmony_ci                              unsigned *out_stride);
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ciint nouveau_screen_init(struct nouveau_screen *, struct nouveau_device *);
155bf215546Sopenharmony_civoid nouveau_screen_fini(struct nouveau_screen *);
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_civoid nouveau_screen_init_vdec(struct nouveau_screen *);
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci#endif
160