Merge remote-tracking branch 'public/master' into vulkan
[mesa.git] / src / gallium / drivers / nouveau / nvc0 / nvc0_screen.h
1 #ifndef __NVC0_SCREEN_H__
2 #define __NVC0_SCREEN_H__
3
4 #include "nouveau_screen.h"
5 #include "nouveau_mm.h"
6 #include "nouveau_fence.h"
7 #include "nouveau_heap.h"
8
9 #include "nv_object.xml.h"
10
11 #include "nvc0/nvc0_winsys.h"
12 #include "nvc0/nvc0_stateobj.h"
13
14 #define NVC0_TIC_MAX_ENTRIES 2048
15 #define NVC0_TSC_MAX_ENTRIES 2048
16
17 /* doesn't count reserved slots (for auxiliary constants, immediates, etc.) */
18 #define NVC0_MAX_PIPE_CONSTBUFS 14
19
20 #define NVC0_MAX_SURFACE_SLOTS 16
21
22 #define NVC0_MAX_VIEWPORTS 16
23
24 #define NVC0_MAX_BUFFERS 32
25
26
27 struct nvc0_context;
28
29 struct nvc0_blitter;
30
31 struct nvc0_graph_state {
32 bool flushed;
33 bool rasterizer_discard;
34 bool early_z_forced;
35 bool prim_restart;
36 uint32_t instance_elts; /* bitmask of per-instance elements */
37 uint32_t instance_base;
38 uint32_t constant_vbos;
39 uint32_t constant_elts;
40 int32_t index_bias;
41 uint16_t scissor;
42 bool flatshade;
43 uint8_t patch_vertices;
44 uint8_t vbo_mode; /* 0 = normal, 1 = translate, 3 = translate, forced */
45 uint8_t num_vtxbufs;
46 uint8_t num_vtxelts;
47 uint8_t num_textures[6];
48 uint8_t num_samplers[6];
49 uint8_t tls_required; /* bitmask of shader types using l[] */
50 uint8_t c14_bound; /* whether immediate array constbuf is bound */
51 uint8_t clip_enable;
52 uint32_t clip_mode;
53 uint32_t uniform_buffer_bound[6];
54 struct nvc0_transform_feedback_state *tfb;
55 bool seamless_cube_map;
56 };
57
58 struct nvc0_screen {
59 struct nouveau_screen base;
60
61 struct nvc0_context *cur_ctx;
62 struct nvc0_graph_state save_state;
63
64 int num_occlusion_queries_active;
65
66 struct nouveau_bo *text;
67 struct nouveau_bo *parm; /* for COMPUTE */
68 struct nouveau_bo *uniform_bo;
69 struct nouveau_bo *tls;
70 struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
71 struct nouveau_bo *poly_cache;
72
73 uint8_t gpc_count;
74 uint16_t mp_count;
75 uint16_t mp_count_compute; /* magic reg can make compute use fewer MPs */
76
77 struct nouveau_heap *text_heap;
78 struct nouveau_heap *lib_code; /* allocated from text_heap */
79
80 struct nvc0_blitter *blitter;
81
82 struct {
83 void **entries;
84 int next;
85 uint32_t lock[NVC0_TIC_MAX_ENTRIES / 32];
86 bool maxwell;
87 } tic;
88
89 struct {
90 void **entries;
91 int next;
92 uint32_t lock[NVC0_TSC_MAX_ENTRIES / 32];
93 } tsc;
94
95 struct {
96 struct nouveau_bo *bo;
97 uint32_t *map;
98 } fence;
99
100 struct {
101 struct nvc0_program *prog; /* compute state object to read MP counters */
102 struct nvc0_hw_sm_query *mp_counter[8]; /* counter to query allocation */
103 uint8_t num_hw_sm_active[2];
104 bool mp_counters_enabled;
105 } pm;
106
107 struct nouveau_object *eng3d; /* sqrt(1/2)|kepler> + sqrt(1/2)|fermi> */
108 struct nouveau_object *eng2d;
109 struct nouveau_object *m2mf;
110 struct nouveau_object *compute;
111 struct nouveau_object *nvsw;
112 };
113
114 static inline struct nvc0_screen *
115 nvc0_screen(struct pipe_screen *screen)
116 {
117 return (struct nvc0_screen *)screen;
118 }
119
120 int nvc0_screen_get_driver_query_info(struct pipe_screen *, unsigned,
121 struct pipe_driver_query_info *);
122
123 int nvc0_screen_get_driver_query_group_info(struct pipe_screen *, unsigned,
124 struct pipe_driver_query_group_info *);
125
126 bool nvc0_blitter_create(struct nvc0_screen *);
127 void nvc0_blitter_destroy(struct nvc0_screen *);
128
129 void nvc0_screen_make_buffers_resident(struct nvc0_screen *);
130
131 int nvc0_screen_tic_alloc(struct nvc0_screen *, void *);
132 int nvc0_screen_tsc_alloc(struct nvc0_screen *, void *);
133
134 int nve4_screen_compute_setup(struct nvc0_screen *, struct nouveau_pushbuf *);
135 int nvc0_screen_compute_setup(struct nvc0_screen *, struct nouveau_pushbuf *);
136
137 bool nvc0_screen_resize_tls_area(struct nvc0_screen *, uint32_t lpos,
138 uint32_t lneg, uint32_t cstack);
139
140 static inline void
141 nvc0_resource_fence(struct nv04_resource *res, uint32_t flags)
142 {
143 struct nvc0_screen *screen = nvc0_screen(res->base.screen);
144
145 if (res->mm) {
146 nouveau_fence_ref(screen->base.fence.current, &res->fence);
147 if (flags & NOUVEAU_BO_WR)
148 nouveau_fence_ref(screen->base.fence.current, &res->fence_wr);
149 }
150 }
151
152 static inline void
153 nvc0_resource_validate(struct nv04_resource *res, uint32_t flags)
154 {
155 if (likely(res->bo)) {
156 if (flags & NOUVEAU_BO_WR)
157 res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
158 NOUVEAU_BUFFER_STATUS_DIRTY;
159 if (flags & NOUVEAU_BO_RD)
160 res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
161
162 nvc0_resource_fence(res, flags);
163 }
164 }
165
166 struct nvc0_format {
167 uint32_t rt;
168 struct {
169 unsigned format:7;
170 unsigned type_r:3;
171 unsigned type_g:3;
172 unsigned type_b:3;
173 unsigned type_a:3;
174 unsigned src_x:3;
175 unsigned src_y:3;
176 unsigned src_z:3;
177 unsigned src_w:3;
178 } tic;
179 uint32_t usage;
180 };
181
182 struct nvc0_vertex_format {
183 uint32_t vtx;
184 uint32_t usage;
185 };
186
187 extern const struct nvc0_format nvc0_format_table[];
188 extern const struct nvc0_vertex_format nvc0_vertex_format[];
189
190 static inline void
191 nvc0_screen_tic_unlock(struct nvc0_screen *screen, struct nv50_tic_entry *tic)
192 {
193 if (tic->id >= 0)
194 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
195 }
196
197 static inline void
198 nvc0_screen_tsc_unlock(struct nvc0_screen *screen, struct nv50_tsc_entry *tsc)
199 {
200 if (tsc->id >= 0)
201 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
202 }
203
204 static inline void
205 nvc0_screen_tic_free(struct nvc0_screen *screen, struct nv50_tic_entry *tic)
206 {
207 if (tic->id >= 0) {
208 screen->tic.entries[tic->id] = NULL;
209 screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
210 }
211 }
212
213 static inline void
214 nvc0_screen_tsc_free(struct nvc0_screen *screen, struct nv50_tsc_entry *tsc)
215 {
216 if (tsc->id >= 0) {
217 screen->tsc.entries[tsc->id] = NULL;
218 screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
219 }
220 }
221
222 #endif