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