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