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