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