1 #ifndef __NVC0_CONTEXT_H__
2 #define __NVC0_CONTEXT_H__
3
4 #include "pipe/p_context.h"
5 #include "pipe/p_defines.h"
6 #include "pipe/p_state.h"
7
8 #include "util/list.h"
9 #include "util/u_memory.h"
10 #include "util/u_math.h"
11 #include "util/u_inlines.h"
12 #include "util/u_dynarray.h"
13
14 #include "nvc0/nvc0_winsys.h"
15 #include "nvc0/nvc0_stateobj.h"
16 #include "nvc0/nvc0_screen.h"
17 #include "nvc0/nvc0_program.h"
18 #include "nvc0/nvc0_resource.h"
19 #include "nvc0/nvc0_query.h"
20
21 #include "nv50/nv50_transfer.h"
22
23 #include "nouveau_context.h"
24 #include "nouveau_debug.h"
25
26 #include "nv50/nv50_3ddefs.xml.h"
27 #include "nvc0/nvc0_3d.xml.h"
28 #include "nv50/nv50_2d.xml.h"
29 #include "nvc0/nvc0_m2mf.xml.h"
30 #include "nvc0/nve4_copy.xml.h"
31 #include "nvc0/nve4_p2mf.xml.h"
32 #include "nvc0/nvc0_compute.xml.h"
33 #include "nvc0/nvc0_macros.h"
34
35 /* NOTE: must keep NVC0_NEW_3D_...PROG in consecutive bits in this order */
36 #define NVC0_NEW_3D_BLEND (1 << 0)
37 #define NVC0_NEW_3D_RASTERIZER (1 << 1)
38 #define NVC0_NEW_3D_ZSA (1 << 2)
39 #define NVC0_NEW_3D_VERTPROG (1 << 3)
40 #define NVC0_NEW_3D_TCTLPROG (1 << 4)
41 #define NVC0_NEW_3D_TEVLPROG (1 << 5)
42 #define NVC0_NEW_3D_GMTYPROG (1 << 6)
43 #define NVC0_NEW_3D_FRAGPROG (1 << 7)
44 #define NVC0_NEW_3D_BLEND_COLOUR (1 << 8)
45 #define NVC0_NEW_3D_STENCIL_REF (1 << 9)
46 #define NVC0_NEW_3D_CLIP (1 << 10)
47 #define NVC0_NEW_3D_SAMPLE_MASK (1 << 11)
48 #define NVC0_NEW_3D_FRAMEBUFFER (1 << 12)
49 #define NVC0_NEW_3D_STIPPLE (1 << 13)
50 #define NVC0_NEW_3D_SCISSOR (1 << 14)
51 #define NVC0_NEW_3D_VIEWPORT (1 << 15)
52 #define NVC0_NEW_3D_ARRAYS (1 << 16)
53 #define NVC0_NEW_3D_VERTEX (1 << 17)
54 #define NVC0_NEW_3D_CONSTBUF (1 << 18)
55 #define NVC0_NEW_3D_TEXTURES (1 << 19)
56 #define NVC0_NEW_3D_SAMPLERS (1 << 20)
57 #define NVC0_NEW_3D_TFB_TARGETS (1 << 21)
58
59 #define NVC0_NEW_3D_SURFACES (1 << 23)
60 #define NVC0_NEW_3D_MIN_SAMPLES (1 << 24)
61 #define NVC0_NEW_3D_TESSFACTOR (1 << 25)
62 #define NVC0_NEW_3D_BUFFERS (1 << 26)
63 #define NVC0_NEW_3D_DRIVERCONST (1 << 27)
64 #define NVC0_NEW_3D_WINDOW_RECTS (1 << 28)
65
66 #define NVC0_NEW_3D_SAMPLE_LOCATIONS (1 << 29)
67
68 #define NVC0_NEW_CP_PROGRAM (1 << 0)
69 #define NVC0_NEW_CP_SURFACES (1 << 1)
70 #define NVC0_NEW_CP_TEXTURES (1 << 2)
71 #define NVC0_NEW_CP_SAMPLERS (1 << 3)
72 #define NVC0_NEW_CP_CONSTBUF (1 << 4)
73 #define NVC0_NEW_CP_GLOBALS (1 << 5)
74 #define NVC0_NEW_CP_DRIVERCONST (1 << 6)
75 #define NVC0_NEW_CP_BUFFERS (1 << 7)
76
77 /* 3d bufctx (during draw_vbo, blit_3d) */
78 #define NVC0_BIND_3D_FB 0
79 #define NVC0_BIND_3D_VTX 1
80 #define NVC0_BIND_3D_VTX_TMP 2
81 #define NVC0_BIND_3D_IDX 3
82 #define NVC0_BIND_3D_TEX(s, i) ( 4 + 32 * (s) + (i))
83 #define NVC0_BIND_3D_CB(s, i) (164 + 16 * (s) + (i))
84 #define NVC0_BIND_3D_TFB 244
85 #define NVC0_BIND_3D_SUF 245
86 #define NVC0_BIND_3D_BUF 246
87 #define NVC0_BIND_3D_SCREEN 247
88 #define NVC0_BIND_3D_BINDLESS 248
89 #define NVC0_BIND_3D_TLS 249
90 #define NVC0_BIND_3D_TEXT 250
91 #define NVC0_BIND_3D_COUNT 251
92
93 /* compute bufctx (during launch_grid) */
94 #define NVC0_BIND_CP_CB(i) ( 0 + (i))
95 #define NVC0_BIND_CP_TEX(i) ( 16 + (i))
96 #define NVC0_BIND_CP_SUF 48
97 #define NVC0_BIND_CP_GLOBAL 49
98 #define NVC0_BIND_CP_DESC 50
99 #define NVC0_BIND_CP_SCREEN 51
100 #define NVC0_BIND_CP_QUERY 52
101 #define NVC0_BIND_CP_BUF 53
102 #define NVC0_BIND_CP_TEXT 54
103 #define NVC0_BIND_CP_BINDLESS 55
104 #define NVC0_BIND_CP_COUNT 56
105
106 /* bufctx for other operations */
107 #define NVC0_BIND_2D 0
108 #define NVC0_BIND_M2MF 0
109 #define NVC0_BIND_FENCE 1
110
111 /* 6 user uniform buffers, at 64K each */
112 #define NVC0_CB_USR_INFO(s) (s << 16)
113 #define NVC0_CB_USR_SIZE (6 << 16)
114 /* 6 driver constbuts, at 64K each */
115 #define NVC0_CB_AUX_INFO(s) NVC0_CB_USR_SIZE + (s << 16)
116 #define NVC0_CB_AUX_SIZE (1 << 16)
117 /* XXX: Figure out what this UNK data is. */
118 #define NVC0_CB_AUX_UNK_INFO 0x000
119 #define NVC0_CB_AUX_UNK_SIZE (8 * 4)
120 /* 40 textures handles (8 for GM107+ images only), at 1 32-bits integer each */
121 #define NVC0_CB_AUX_TEX_INFO(i) 0x020 + (i) * 4
122 #define NVC0_CB_AUX_TEX_SIZE (40 * 4)
123 /* 8 sets of 32-bits coordinate offsets */
124 #define NVC0_CB_AUX_MS_INFO 0x0c0
125 #define NVC0_CB_AUX_MS_SIZE (8 * 2 * 4)
126 /* block/grid size, at 3 32-bits integers each, gridid and work_dim */
127 #define NVC0_CB_AUX_GRID_INFO(i) 0x100 + (i) * 4 /* CP */
128 #define NVC0_CB_AUX_GRID_SIZE (8 * 4)
129 /* FB texture handle */
130 #define NVC0_CB_AUX_FB_TEX_INFO 0x100 /* FP */
131 #define NVC0_CB_AUX_FB_TEX_SIZE (4)
132 /* 8 user clip planes, at 4 32-bits floats each */
133 #define NVC0_CB_AUX_UCP_INFO 0x120
134 #define NVC0_CB_AUX_UCP_SIZE (PIPE_MAX_CLIP_PLANES * 4 * 4)
135 /* 13 ubos, at 4 32-bits integer each */
136 #define NVC0_CB_AUX_UBO_INFO(i) 0x120 + (i) * 4 * 4 /* CP */
137 #define NVC0_CB_AUX_UBO_SIZE ((NVC0_MAX_PIPE_CONSTBUFS - 1) * 4 * 4)
138 /* 8 sets of 32-bits integer pairs sample offsets */
139 #define NVC0_CB_AUX_SAMPLE_INFO 0x1a0 /* FP */
140 /* 256 bytes, though only 64 bytes used before GM200 */
141 #define NVC0_CB_AUX_SAMPLE_SIZE (8 * 2 * 4 * 4)
142 /* draw parameters (index bias, base instance, drawid)
143 * be sure to update the indirect draw macros in com9097.mme when changing this
144 */
145 #define NVC0_CB_AUX_DRAW_INFO 0x1a0 /* VP */
146 /* 32 user buffers, at 4 32-bits integers each */
147 #define NVC0_CB_AUX_BUF_INFO(i) 0x2a0 + (i) * 4 * 4
148 #define NVC0_CB_AUX_BUF_SIZE (NVC0_MAX_BUFFERS * 4 * 4)
149 /* 8 surfaces, at 16 32-bits integers each */
150 #define NVC0_CB_AUX_SU_INFO(i) 0x4a0 + (i) * 16 * 4
151 #define NVC0_CB_AUX_SU_SIZE (NVC0_MAX_IMAGES * 16 * 4)
152 /* 1 64-bits address and 1 32-bits sequence
153 * be sure to update the shaders in nvc0_query_hw_sm.c when changing this
154 */
155 #define NVC0_CB_AUX_MP_INFO 0x6a0
156 #define NVC0_CB_AUX_MP_SIZE 3 * 4
157 /* 512 64-byte blocks for bindless image handles */
158 #define NVC0_CB_AUX_BINDLESS_INFO(i) 0x6b0 + (i) * 16 * 4
159 #define NVC0_CB_AUX_BINDLESS_SIZE (NVE4_IMG_MAX_HANDLES * 16 * 4)
160 /* 4 32-bits floats for the vertex runout, put at the end */
161 #define NVC0_CB_AUX_RUNOUT_INFO NVC0_CB_USR_SIZE + (NVC0_CB_AUX_SIZE * 6)
162
163 struct nvc0_blitctx;
164
165 bool nvc0_blitctx_create(struct nvc0_context *);
166 void nvc0_blitctx_destroy(struct nvc0_context *);
167
168 struct nvc0_resident {
169 struct list_head list;
170 uint64_t handle;
171 struct nv04_resource *buf;
172 uint32_t flags;
173 };
174
175 struct nvc0_context {
176 struct nouveau_context base;
177
178 struct nouveau_bufctx *bufctx_3d;
179 struct nouveau_bufctx *bufctx;
180 struct nouveau_bufctx *bufctx_cp;
181
182 struct nvc0_screen *screen;
183
184 void (*m2mf_copy_rect)(struct nvc0_context *,
185 const struct nv50_m2mf_rect *dst,
186 const struct nv50_m2mf_rect *src,
187 uint32_t nblocksx, uint32_t nblocksy);
188
189 uint32_t dirty_3d; /* dirty flags for 3d state */
190 uint32_t dirty_cp; /* dirty flags for compute state */
191
192 struct nvc0_graph_state state;
193
194 struct nvc0_blend_stateobj *blend;
195 struct nvc0_rasterizer_stateobj *rast;
196 struct nvc0_zsa_stateobj *zsa;
197 struct nvc0_vertex_stateobj *vertex;
198
199 struct nvc0_program *vertprog;
200 struct nvc0_program *tctlprog;
201 struct nvc0_program *tevlprog;
202 struct nvc0_program *gmtyprog;
203 struct nvc0_program *fragprog;
204 struct nvc0_program *compprog;
205
206 struct nvc0_program *tcp_empty;
207
208 struct nvc0_constbuf constbuf[6][NVC0_MAX_PIPE_CONSTBUFS];
209 uint16_t constbuf_dirty[6];
210 uint16_t constbuf_valid[6];
211 uint16_t constbuf_coherent[6];
212 bool cb_dirty;
213
214 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
215 unsigned num_vtxbufs;
216 uint32_t vtxbufs_coherent;
217 uint32_t constant_vbos;
218 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
219 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
220 uint32_t vb_elt_limit; /* max - min element (count - 1) */
221 uint32_t instance_off; /* current base vertex for instanced arrays */
222 uint32_t instance_max; /* last instance for current draw call */
223
224 struct pipe_sampler_view *textures[6][PIPE_MAX_SAMPLERS];
225 unsigned num_textures[6];
226 uint32_t textures_dirty[6];
227 uint32_t textures_coherent[6];
228 struct nv50_tsc_entry *samplers[6][PIPE_MAX_SAMPLERS];
229 unsigned num_samplers[6];
230 uint32_t samplers_dirty[6];
231 bool seamless_cube_map;
232 struct pipe_sampler_view *fbtexture;
233
234 uint32_t tex_handles[6][PIPE_MAX_SAMPLERS]; /* for nve4 */
235
236 struct list_head tex_head;
237 struct list_head img_head;
238
239 struct pipe_framebuffer_state framebuffer;
240 bool sample_locations_enabled;
241 uint8_t sample_locations[2 * 4 * 8];
242 struct pipe_blend_color blend_colour;
243 struct pipe_stencil_ref stencil_ref;
244 struct pipe_poly_stipple stipple;
245 struct pipe_scissor_state scissors[NVC0_MAX_VIEWPORTS];
246 unsigned scissors_dirty;
247 struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS];
248 unsigned viewports_dirty;
249 struct pipe_clip_state clip;
250 struct nvc0_window_rect_stateobj window_rect;
251
252 unsigned sample_mask;
253 unsigned min_samples;
254
255 float default_tess_outer[4];
256 float default_tess_inner[2];
257 uint8_t patch_vertices;
258
259 bool vbo_push_hint;
260
261 uint8_t tfbbuf_dirty;
262 struct pipe_stream_output_target *tfbbuf[4];
263 unsigned num_tfbbufs;
264
265 struct pipe_query *cond_query;
266 bool cond_cond; /* inverted rendering condition */
267 uint cond_mode;
268 uint32_t cond_condmode; /* the calculated condition */
269
270 struct nvc0_blitctx *blit;
271
272 /* NOTE: some of these surfaces may reference buffers */
273 struct pipe_surface *surfaces[2][NVC0_MAX_SURFACE_SLOTS];
274 uint16_t surfaces_dirty[2];
275 uint16_t surfaces_valid[2];
276
277 struct pipe_shader_buffer buffers[6][NVC0_MAX_BUFFERS];
278 uint32_t buffers_dirty[6];
279 uint32_t buffers_valid[6];
280
281 struct pipe_image_view images[6][NVC0_MAX_IMAGES];
282 struct pipe_sampler_view *images_tic[6][NVC0_MAX_IMAGES]; /* GM107+ */
283 uint16_t images_dirty[6];
284 uint16_t images_valid[6];
285
286 struct util_dynarray global_residents;
287
288 uint64_t compute_invocations;
289 };
290
291 static inline struct nvc0_context *
nvc0_context(struct pipe_context * pipe)292 nvc0_context(struct pipe_context *pipe)
293 {
294 return (struct nvc0_context *)pipe;
295 }
296
297 static inline unsigned
nvc0_shader_stage(unsigned pipe)298 nvc0_shader_stage(unsigned pipe)
299 {
300 switch (pipe) {
301 case PIPE_SHADER_VERTEX: return 0;
302 case PIPE_SHADER_TESS_CTRL: return 1;
303 case PIPE_SHADER_TESS_EVAL: return 2;
304 case PIPE_SHADER_GEOMETRY: return 3;
305 case PIPE_SHADER_FRAGMENT: return 4;
306 case PIPE_SHADER_COMPUTE: return 5;
307 default:
308 assert(!"invalid PIPE_SHADER type");
309 return 0;
310 }
311 }
312
313
314 /* nvc0_context.c */
315 struct pipe_context *nvc0_create(struct pipe_screen *, void *, unsigned flags);
316 void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
317 bool on_flush);
318 void nvc0_default_kick_notify(struct nouveau_pushbuf *);
319 const void *nvc0_get_sample_locations(unsigned);
320
321 /* nvc0_draw.c */
322 extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
323
324 /* nvc0_program.c */
325 bool nvc0_program_translate(struct nvc0_program *, uint16_t chipset,
326 struct disk_cache *,
327 struct pipe_debug_callback *);
328 bool nvc0_program_upload(struct nvc0_context *, struct nvc0_program *);
329 void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
330 void nvc0_program_library_upload(struct nvc0_context *);
331 void nvc0_program_init_tcp_empty(struct nvc0_context *);
332
333 /* nvc0_shader_state.c */
334 void nvc0_vertprog_validate(struct nvc0_context *);
335 void nvc0_tctlprog_validate(struct nvc0_context *);
336 void nvc0_tevlprog_validate(struct nvc0_context *);
337 void nvc0_gmtyprog_validate(struct nvc0_context *);
338 void nvc0_fragprog_validate(struct nvc0_context *);
339 void nvc0_compprog_validate(struct nvc0_context *);
340
341 void nvc0_tfb_validate(struct nvc0_context *);
342 void nvc0_layer_validate(struct nvc0_context *);
343
344 /* nvc0_state.c */
345 extern void nvc0_init_state_functions(struct nvc0_context *);
346
347 /* nvc0_state_validate.c */
348 struct nvc0_state_validate {
349 void (*func)(struct nvc0_context *);
350 uint32_t states;
351 };
352
353 bool nvc0_state_validate(struct nvc0_context *, uint32_t,
354 struct nvc0_state_validate *, int, uint32_t *,
355 struct nouveau_bufctx *);
356 bool nvc0_state_validate_3d(struct nvc0_context *, uint32_t);
357
358 /* nvc0_surface.c */
359 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
360 const struct pipe_scissor_state *scissor_state,
361 const union pipe_color_union *color,
362 double depth, unsigned stencil);
363 extern void nvc0_init_surface_functions(struct nvc0_context *);
364
365 /* nvc0_tex.c */
366 bool nvc0_validate_tic(struct nvc0_context *nvc0, int s);
367 bool nvc0_validate_tsc(struct nvc0_context *nvc0, int s);
368 bool nve4_validate_tsc(struct nvc0_context *nvc0, int s);
369 void nvc0_validate_suf(struct nvc0_context *nvc0, int s);
370 void nvc0_validate_textures(struct nvc0_context *);
371 void nvc0_validate_samplers(struct nvc0_context *);
372 void nvc0_upload_tsc0(struct nvc0_context *);
373 void nve4_set_tex_handles(struct nvc0_context *);
374 void nvc0_validate_surfaces(struct nvc0_context *);
375 void nve4_set_surface_info(struct nouveau_pushbuf *,
376 const struct pipe_image_view *,
377 struct nvc0_context *);
378 void nvc0_mark_image_range_valid(const struct pipe_image_view *);
379 bool nvc0_update_tic(struct nvc0_context *, struct nv50_tic_entry *,
380 struct nv04_resource *);
381
382 struct pipe_sampler_view *
383 nvc0_create_texture_view(struct pipe_context *,
384 struct pipe_resource *,
385 const struct pipe_sampler_view *,
386 uint32_t flags);
387 struct pipe_sampler_view *
388 nvc0_create_sampler_view(struct pipe_context *,
389 struct pipe_resource *,
390 const struct pipe_sampler_view *);
391 struct pipe_sampler_view *
392 gm107_create_texture_view_from_image(struct pipe_context *,
393 const struct pipe_image_view *);
394
395 void nvc0_init_bindless_functions(struct pipe_context *);
396
397 /* nvc0_transfer.c */
398 void
399 nvc0_init_transfer_functions(struct nvc0_context *);
400
401 void
402 nvc0_m2mf_push_linear(struct nouveau_context *nv,
403 struct nouveau_bo *dst, unsigned offset, unsigned domain,
404 unsigned size, const void *data);
405 void
406 nve4_p2mf_push_linear(struct nouveau_context *nv,
407 struct nouveau_bo *dst, unsigned offset, unsigned domain,
408 unsigned size, const void *data);
409 void
410 nvc0_cb_bo_push(struct nouveau_context *,
411 struct nouveau_bo *bo, unsigned domain,
412 unsigned base, unsigned size,
413 unsigned offset, unsigned words, const uint32_t *data);
414
415 /* nvc0_vbo.c */
416 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *, unsigned,
417 const struct pipe_draw_indirect_info *indirect,
418 const struct pipe_draw_start_count_bias *draws,
419 unsigned num_draws);
420
421 void *
422 nvc0_vertex_state_create(struct pipe_context *pipe,
423 unsigned num_elements,
424 const struct pipe_vertex_element *elements);
425 void
426 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
427
428 void nvc0_vertex_arrays_validate(struct nvc0_context *);
429
430 void nvc0_idxbuf_validate(struct nvc0_context *);
431
432 /* nvc0_video.c */
433 struct pipe_video_codec *
434 nvc0_create_decoder(struct pipe_context *context,
435 const struct pipe_video_codec *templ);
436
437 struct pipe_video_buffer *
438 nvc0_video_buffer_create(struct pipe_context *pipe,
439 const struct pipe_video_buffer *templat);
440
441 /* nvc0_push.c */
442 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *,
443 const struct pipe_draw_indirect_info *indirect,
444 const struct pipe_draw_start_count_bias *draw);
445 void nvc0_push_vbo_indirect(struct nvc0_context *, const struct pipe_draw_info *,
446 unsigned drawid_offset,
447 const struct pipe_draw_indirect_info *indirect,
448 const struct pipe_draw_start_count_bias *draw);
449
450 /* nve4_compute.c */
451 void nve4_launch_grid(struct pipe_context *, const struct pipe_grid_info *);
452
453 /* nvc0_compute.c */
454 void nvc0_launch_grid(struct pipe_context *, const struct pipe_grid_info *);
455 void nvc0_compute_validate_globals(struct nvc0_context *);
456 void nvc0_update_compute_invocations_counter(struct nvc0_context *nvc0,
457 const struct pipe_grid_info *info);
458
459 #endif
460