Debian Codegraph @

src/gallium/drivers/nouveau/nvc0/nvc0_context.h

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