nvc0: add a memory barrier when there are persistent UBOs
[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 #ifdef NVC0_WITH_DRAW_MODULE
14 #include "draw/draw_vertex.h"
15 #endif
16
17 #include "nvc0/nvc0_winsys.h"
18 #include "nvc0/nvc0_stateobj.h"
19 #include "nvc0/nvc0_screen.h"
20 #include "nvc0/nvc0_program.h"
21 #include "nvc0/nvc0_resource.h"
22
23 #include "nv50/nv50_transfer.h"
24
25 #include "nouveau_context.h"
26 #include "nouveau_debug.h"
27
28 #include "nvc0/nvc0_3ddefs.xml.h"
29 #include "nvc0/nvc0_3d.xml.h"
30 #include "nvc0/nvc0_2d.xml.h"
31 #include "nvc0/nvc0_m2mf.xml.h"
32 #include "nvc0/nve4_p2mf.xml.h"
33
34 /* NOTE: must keep NVC0_NEW_...PROG in consecutive bits in this order */
35 #define NVC0_NEW_BLEND (1 << 0)
36 #define NVC0_NEW_RASTERIZER (1 << 1)
37 #define NVC0_NEW_ZSA (1 << 2)
38 #define NVC0_NEW_VERTPROG (1 << 3)
39 #define NVC0_NEW_TCTLPROG (1 << 4)
40 #define NVC0_NEW_TEVLPROG (1 << 5)
41 #define NVC0_NEW_GMTYPROG (1 << 6)
42 #define NVC0_NEW_FRAGPROG (1 << 7)
43 #define NVC0_NEW_BLEND_COLOUR (1 << 8)
44 #define NVC0_NEW_STENCIL_REF (1 << 9)
45 #define NVC0_NEW_CLIP (1 << 10)
46 #define NVC0_NEW_SAMPLE_MASK (1 << 11)
47 #define NVC0_NEW_FRAMEBUFFER (1 << 12)
48 #define NVC0_NEW_STIPPLE (1 << 13)
49 #define NVC0_NEW_SCISSOR (1 << 14)
50 #define NVC0_NEW_VIEWPORT (1 << 15)
51 #define NVC0_NEW_ARRAYS (1 << 16)
52 #define NVC0_NEW_VERTEX (1 << 17)
53 #define NVC0_NEW_CONSTBUF (1 << 18)
54 #define NVC0_NEW_TEXTURES (1 << 19)
55 #define NVC0_NEW_SAMPLERS (1 << 20)
56 #define NVC0_NEW_TFB_TARGETS (1 << 21)
57 #define NVC0_NEW_IDXBUF (1 << 22)
58 #define NVC0_NEW_SURFACES (1 << 23)
59 #define NVC0_NEW_MIN_SAMPLES (1 << 24)
60
61 #define NVC0_NEW_CP_PROGRAM (1 << 0)
62 #define NVC0_NEW_CP_SURFACES (1 << 1)
63 #define NVC0_NEW_CP_TEXTURES (1 << 2)
64 #define NVC0_NEW_CP_SAMPLERS (1 << 3)
65 #define NVC0_NEW_CP_CONSTBUF (1 << 4)
66 #define NVC0_NEW_CP_GLOBALS (1 << 5)
67
68 /* 3d bufctx (during draw_vbo, blit_3d) */
69 #define NVC0_BIND_FB 0
70 #define NVC0_BIND_VTX 1
71 #define NVC0_BIND_VTX_TMP 2
72 #define NVC0_BIND_IDX 3
73 #define NVC0_BIND_TEX(s, i) ( 4 + 32 * (s) + (i))
74 #define NVC0_BIND_CB(s, i) (164 + 16 * (s) + (i))
75 #define NVC0_BIND_TFB 244
76 #define NVC0_BIND_SUF 245
77 #define NVC0_BIND_SCREEN 246
78 #define NVC0_BIND_TLS 247
79 #define NVC0_BIND_3D_COUNT 248
80
81 /* compute bufctx (during launch_grid) */
82 #define NVC0_BIND_CP_CB(i) ( 0 + (i))
83 #define NVC0_BIND_CP_TEX(i) ( 16 + (i))
84 #define NVC0_BIND_CP_SUF 48
85 #define NVC0_BIND_CP_GLOBAL 49
86 #define NVC0_BIND_CP_DESC 50
87 #define NVC0_BIND_CP_SCREEN 51
88 #define NVC0_BIND_CP_QUERY 52
89 #define NVC0_BIND_CP_COUNT 53
90
91 /* bufctx for other operations */
92 #define NVC0_BIND_2D 0
93 #define NVC0_BIND_M2MF 0
94 #define NVC0_BIND_FENCE 1
95
96
97 struct nvc0_blitctx;
98
99 boolean nvc0_blitctx_create(struct nvc0_context *);
100 void nvc0_blitctx_destroy(struct nvc0_context *);
101
102 struct nvc0_context {
103 struct nouveau_context base;
104
105 struct nouveau_bufctx *bufctx_3d;
106 struct nouveau_bufctx *bufctx;
107 struct nouveau_bufctx *bufctx_cp;
108
109 struct nvc0_screen *screen;
110
111 void (*m2mf_copy_rect)(struct nvc0_context *,
112 const struct nv50_m2mf_rect *dst,
113 const struct nv50_m2mf_rect *src,
114 uint32_t nblocksx, uint32_t nblocksy);
115
116 uint32_t dirty;
117 uint32_t dirty_cp; /* dirty flags for compute state */
118
119 struct {
120 boolean flushed;
121 boolean rasterizer_discard;
122 boolean early_z_forced;
123 boolean prim_restart;
124 uint32_t instance_elts; /* bitmask of per-instance elements */
125 uint32_t instance_base;
126 uint32_t constant_vbos;
127 uint32_t constant_elts;
128 int32_t index_bias;
129 uint16_t scissor;
130 uint8_t vbo_mode; /* 0 = normal, 1 = translate, 3 = translate, forced */
131 uint8_t num_vtxbufs;
132 uint8_t num_vtxelts;
133 uint8_t num_textures[6];
134 uint8_t num_samplers[6];
135 uint8_t tls_required; /* bitmask of shader types using l[] */
136 uint8_t c14_bound; /* whether immediate array constbuf is bound */
137 uint8_t clip_enable;
138 uint32_t clip_mode;
139 uint32_t uniform_buffer_bound[5];
140 struct nvc0_transform_feedback_state *tfb;
141 } state;
142
143 struct nvc0_blend_stateobj *blend;
144 struct nvc0_rasterizer_stateobj *rast;
145 struct nvc0_zsa_stateobj *zsa;
146 struct nvc0_vertex_stateobj *vertex;
147
148 struct nvc0_program *vertprog;
149 struct nvc0_program *tctlprog;
150 struct nvc0_program *tevlprog;
151 struct nvc0_program *gmtyprog;
152 struct nvc0_program *fragprog;
153 struct nvc0_program *compprog;
154
155 struct nvc0_constbuf constbuf[6][NVC0_MAX_PIPE_CONSTBUFS];
156 uint16_t constbuf_dirty[6];
157 uint16_t constbuf_valid[6];
158 boolean cb_dirty;
159
160 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
161 unsigned num_vtxbufs;
162 struct pipe_index_buffer idxbuf;
163 uint32_t constant_vbos;
164 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
165 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
166 uint32_t vb_elt_limit; /* max - min element (count - 1) */
167 uint32_t instance_off; /* current base vertex for instanced arrays */
168 uint32_t instance_max; /* last instance for current draw call */
169
170 struct pipe_sampler_view *textures[6][PIPE_MAX_SAMPLERS];
171 unsigned num_textures[6];
172 uint32_t textures_dirty[6];
173 struct nv50_tsc_entry *samplers[6][PIPE_MAX_SAMPLERS];
174 unsigned num_samplers[6];
175 uint16_t samplers_dirty[6];
176
177 uint32_t tex_handles[6][PIPE_MAX_SAMPLERS]; /* for nve4 */
178
179 struct pipe_framebuffer_state framebuffer;
180 struct pipe_blend_color blend_colour;
181 struct pipe_stencil_ref stencil_ref;
182 struct pipe_poly_stipple stipple;
183 struct pipe_scissor_state scissors[NVC0_MAX_VIEWPORTS];
184 unsigned scissors_dirty;
185 struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS];
186 unsigned viewports_dirty;
187 struct pipe_clip_state clip;
188
189 unsigned sample_mask;
190 unsigned min_samples;
191
192 boolean vbo_push_hint;
193
194 uint8_t tfbbuf_dirty;
195 struct pipe_stream_output_target *tfbbuf[4];
196 unsigned num_tfbbufs;
197
198 struct pipe_query *cond_query;
199 boolean cond_cond;
200 uint cond_mode;
201
202 struct nvc0_blitctx *blit;
203
204 struct pipe_surface *surfaces[2][NVC0_MAX_SURFACE_SLOTS];
205 uint16_t surfaces_dirty[2];
206 uint16_t surfaces_valid[2];
207
208 struct util_dynarray global_residents;
209
210 #ifdef NVC0_WITH_DRAW_MODULE
211 struct draw_context *draw;
212 #endif
213 };
214
215 static INLINE struct nvc0_context *
216 nvc0_context(struct pipe_context *pipe)
217 {
218 return (struct nvc0_context *)pipe;
219 }
220
221 static INLINE unsigned
222 nvc0_shader_stage(unsigned pipe)
223 {
224 switch (pipe) {
225 case PIPE_SHADER_VERTEX: return 0;
226 /* case PIPE_SHADER_TESSELLATION_CONTROL: return 1; */
227 /* case PIPE_SHADER_TESSELLATION_EVALUATION: return 2; */
228 case PIPE_SHADER_GEOMETRY: return 3;
229 case PIPE_SHADER_FRAGMENT: return 4;
230 case PIPE_SHADER_COMPUTE: return 5;
231 default:
232 assert(!"invalid PIPE_SHADER type");
233 return 0;
234 }
235 }
236
237
238 /* nvc0_context.c */
239 struct pipe_context *nvc0_create(struct pipe_screen *, void *);
240 void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
241 boolean on_flush);
242 void nvc0_default_kick_notify(struct nouveau_pushbuf *);
243
244 /* nvc0_draw.c */
245 extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
246
247 /* nvc0_program.c */
248 boolean nvc0_program_translate(struct nvc0_program *, uint16_t chipset);
249 boolean nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
250 void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
251 void nvc0_program_library_upload(struct nvc0_context *);
252 uint32_t nvc0_program_symbol_offset(const struct nvc0_program *,
253 uint32_t label);
254
255 /* nvc0_query.c */
256 void nvc0_init_query_functions(struct nvc0_context *);
257 void nvc0_query_pushbuf_submit(struct nouveau_pushbuf *,
258 struct pipe_query *, unsigned result_offset);
259 void nvc0_query_fifo_wait(struct nouveau_pushbuf *, struct pipe_query *);
260 void nvc0_so_target_save_offset(struct pipe_context *,
261 struct pipe_stream_output_target *, unsigned i,
262 boolean *serialize);
263
264 #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
265
266 /* nvc0_shader_state.c */
267 void nvc0_vertprog_validate(struct nvc0_context *);
268 void nvc0_tctlprog_validate(struct nvc0_context *);
269 void nvc0_tevlprog_validate(struct nvc0_context *);
270 void nvc0_gmtyprog_validate(struct nvc0_context *);
271 void nvc0_fragprog_validate(struct nvc0_context *);
272
273 void nvc0_tfb_validate(struct nvc0_context *);
274
275 /* nvc0_state.c */
276 extern void nvc0_init_state_functions(struct nvc0_context *);
277
278 /* nvc0_state_validate.c */
279 void nvc0_validate_global_residents(struct nvc0_context *,
280 struct nouveau_bufctx *, int bin);
281 extern boolean nvc0_state_validate(struct nvc0_context *, uint32_t state_mask,
282 unsigned space_words);
283
284 /* nvc0_surface.c */
285 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
286 const union pipe_color_union *color,
287 double depth, unsigned stencil);
288 extern void nvc0_init_surface_functions(struct nvc0_context *);
289
290 /* nvc0_tex.c */
291 boolean nve4_validate_tsc(struct nvc0_context *nvc0, int s);
292 void nvc0_validate_textures(struct nvc0_context *);
293 void nvc0_validate_samplers(struct nvc0_context *);
294 void nve4_set_tex_handles(struct nvc0_context *);
295 void nvc0_validate_surfaces(struct nvc0_context *);
296 void nve4_set_surface_info(struct nouveau_pushbuf *, struct pipe_surface *,
297 struct nvc0_screen *);
298
299 struct pipe_sampler_view *
300 nvc0_create_texture_view(struct pipe_context *,
301 struct pipe_resource *,
302 const struct pipe_sampler_view *,
303 uint32_t flags,
304 enum pipe_texture_target);
305 struct pipe_sampler_view *
306 nvc0_create_sampler_view(struct pipe_context *,
307 struct pipe_resource *,
308 const struct pipe_sampler_view *);
309
310 /* nvc0_transfer.c */
311 void
312 nvc0_init_transfer_functions(struct nvc0_context *);
313
314 void
315 nvc0_m2mf_push_linear(struct nouveau_context *nv,
316 struct nouveau_bo *dst, unsigned offset, unsigned domain,
317 unsigned size, const void *data);
318 void
319 nve4_p2mf_push_linear(struct nouveau_context *nv,
320 struct nouveau_bo *dst, unsigned offset, unsigned domain,
321 unsigned size, const void *data);
322 void
323 nvc0_cb_push(struct nouveau_context *,
324 struct nouveau_bo *bo, unsigned domain,
325 unsigned base, unsigned size,
326 unsigned offset, unsigned words, const uint32_t *data);
327
328 /* nvc0_vbo.c */
329 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
330
331 void *
332 nvc0_vertex_state_create(struct pipe_context *pipe,
333 unsigned num_elements,
334 const struct pipe_vertex_element *elements);
335 void
336 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
337
338 void nvc0_vertex_arrays_validate(struct nvc0_context *);
339
340 void nvc0_idxbuf_validate(struct nvc0_context *);
341
342 /* nvc0_video.c */
343 struct pipe_video_codec *
344 nvc0_create_decoder(struct pipe_context *context,
345 const struct pipe_video_codec *templ);
346
347 struct pipe_video_buffer *
348 nvc0_video_buffer_create(struct pipe_context *pipe,
349 const struct pipe_video_buffer *templat);
350
351 /* nvc0_push.c */
352 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
353
354 /* nve4_compute.c */
355 void nve4_launch_grid(struct pipe_context *,
356 const uint *, const uint *, uint32_t, const void *);
357
358 /* nvc0_compute.c */
359 void nvc0_launch_grid(struct pipe_context *,
360 const uint *, const uint *, uint32_t, const void *);
361
362 #endif