nvc0: rename 3d dirty flags to NVC0_NEW_3D_XXX
[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
62 #define NVC0_NEW_CP_PROGRAM (1 << 0)
63 #define NVC0_NEW_CP_SURFACES (1 << 1)
64 #define NVC0_NEW_CP_TEXTURES (1 << 2)
65 #define NVC0_NEW_CP_SAMPLERS (1 << 3)
66 #define NVC0_NEW_CP_CONSTBUF (1 << 4)
67 #define NVC0_NEW_CP_GLOBALS (1 << 5)
68 #define NVC0_NEW_CP_DRIVERCONST (1 << 6)
69 #define NVC0_NEW_CP_BUFFERS (1 << 7)
70
71 /* 3d bufctx (during draw_vbo, blit_3d) */
72 #define NVC0_BIND_FB 0
73 #define NVC0_BIND_VTX 1
74 #define NVC0_BIND_VTX_TMP 2
75 #define NVC0_BIND_IDX 3
76 #define NVC0_BIND_TEX(s, i) ( 4 + 32 * (s) + (i))
77 #define NVC0_BIND_CB(s, i) (164 + 16 * (s) + (i))
78 #define NVC0_BIND_TFB 244
79 #define NVC0_BIND_SUF 245
80 #define NVC0_BIND_BUF 246
81 #define NVC0_BIND_SCREEN 247
82 #define NVC0_BIND_TLS 249
83 #define NVC0_BIND_3D_COUNT 250
84
85 /* compute bufctx (during launch_grid) */
86 #define NVC0_BIND_CP_CB(i) ( 0 + (i))
87 #define NVC0_BIND_CP_TEX(i) ( 16 + (i))
88 #define NVC0_BIND_CP_SUF 48
89 #define NVC0_BIND_CP_GLOBAL 49
90 #define NVC0_BIND_CP_DESC 50
91 #define NVC0_BIND_CP_SCREEN 51
92 #define NVC0_BIND_CP_QUERY 52
93 #define NVC0_BIND_CP_BUF 53
94 #define NVC0_BIND_CP_COUNT 54
95
96 /* bufctx for other operations */
97 #define NVC0_BIND_2D 0
98 #define NVC0_BIND_M2MF 0
99 #define NVC0_BIND_FENCE 1
100
101
102 struct nvc0_blitctx;
103
104 bool nvc0_blitctx_create(struct nvc0_context *);
105 void nvc0_blitctx_destroy(struct nvc0_context *);
106
107 struct nvc0_context {
108 struct nouveau_context base;
109
110 struct nouveau_bufctx *bufctx_3d;
111 struct nouveau_bufctx *bufctx;
112 struct nouveau_bufctx *bufctx_cp;
113
114 struct nvc0_screen *screen;
115
116 void (*m2mf_copy_rect)(struct nvc0_context *,
117 const struct nv50_m2mf_rect *dst,
118 const struct nv50_m2mf_rect *src,
119 uint32_t nblocksx, uint32_t nblocksy);
120
121 uint32_t dirty_3d; /* dirty flags for 3d state */
122 uint32_t dirty_cp; /* dirty flags for compute state */
123
124 struct nvc0_graph_state state;
125
126 struct nvc0_blend_stateobj *blend;
127 struct nvc0_rasterizer_stateobj *rast;
128 struct nvc0_zsa_stateobj *zsa;
129 struct nvc0_vertex_stateobj *vertex;
130
131 struct nvc0_program *vertprog;
132 struct nvc0_program *tctlprog;
133 struct nvc0_program *tevlprog;
134 struct nvc0_program *gmtyprog;
135 struct nvc0_program *fragprog;
136 struct nvc0_program *compprog;
137
138 struct nvc0_program *tcp_empty;
139
140 struct nvc0_constbuf constbuf[6][NVC0_MAX_PIPE_CONSTBUFS];
141 uint16_t constbuf_dirty[6];
142 uint16_t constbuf_valid[6];
143 uint16_t constbuf_coherent[6];
144 bool cb_dirty;
145
146 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
147 unsigned num_vtxbufs;
148 uint32_t vtxbufs_coherent;
149 struct pipe_index_buffer idxbuf;
150 uint32_t constant_vbos;
151 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
152 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
153 uint32_t vb_elt_limit; /* max - min element (count - 1) */
154 uint32_t instance_off; /* current base vertex for instanced arrays */
155 uint32_t instance_max; /* last instance for current draw call */
156
157 struct pipe_sampler_view *textures[6][PIPE_MAX_SAMPLERS];
158 unsigned num_textures[6];
159 uint32_t textures_dirty[6];
160 uint32_t textures_coherent[6];
161 struct nv50_tsc_entry *samplers[6][PIPE_MAX_SAMPLERS];
162 unsigned num_samplers[6];
163 uint16_t samplers_dirty[6];
164 bool seamless_cube_map;
165
166 uint32_t tex_handles[6][PIPE_MAX_SAMPLERS]; /* for nve4 */
167
168 struct pipe_framebuffer_state framebuffer;
169 struct pipe_blend_color blend_colour;
170 struct pipe_stencil_ref stencil_ref;
171 struct pipe_poly_stipple stipple;
172 struct pipe_scissor_state scissors[NVC0_MAX_VIEWPORTS];
173 unsigned scissors_dirty;
174 struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS];
175 unsigned viewports_dirty;
176 struct pipe_clip_state clip;
177
178 unsigned sample_mask;
179 unsigned min_samples;
180
181 float default_tess_outer[4];
182 float default_tess_inner[2];
183
184 bool vbo_push_hint;
185
186 uint8_t tfbbuf_dirty;
187 struct pipe_stream_output_target *tfbbuf[4];
188 unsigned num_tfbbufs;
189
190 struct pipe_query *cond_query;
191 bool cond_cond; /* inverted rendering condition */
192 uint cond_mode;
193 uint32_t cond_condmode; /* the calculated condition */
194
195 struct nvc0_blitctx *blit;
196
197 /* NOTE: some of these surfaces may reference buffers */
198 struct pipe_surface *surfaces[2][NVC0_MAX_SURFACE_SLOTS];
199 uint16_t surfaces_dirty[2];
200 uint16_t surfaces_valid[2];
201
202 struct pipe_shader_buffer buffers[6][NVC0_MAX_BUFFERS];
203 uint32_t buffers_dirty[6];
204 uint32_t buffers_valid[6];
205
206 struct util_dynarray global_residents;
207 };
208
209 static inline struct nvc0_context *
210 nvc0_context(struct pipe_context *pipe)
211 {
212 return (struct nvc0_context *)pipe;
213 }
214
215 static inline unsigned
216 nvc0_shader_stage(unsigned pipe)
217 {
218 switch (pipe) {
219 case PIPE_SHADER_VERTEX: return 0;
220 case PIPE_SHADER_TESS_CTRL: return 1;
221 case PIPE_SHADER_TESS_EVAL: return 2;
222 case PIPE_SHADER_GEOMETRY: return 3;
223 case PIPE_SHADER_FRAGMENT: return 4;
224 case PIPE_SHADER_COMPUTE: return 5;
225 default:
226 assert(!"invalid PIPE_SHADER type");
227 return 0;
228 }
229 }
230
231
232 /* nvc0_context.c */
233 struct pipe_context *nvc0_create(struct pipe_screen *, void *, unsigned flags);
234 void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
235 bool on_flush);
236 void nvc0_default_kick_notify(struct nouveau_pushbuf *);
237
238 /* nvc0_draw.c */
239 extern struct draw_stage *nvc0_draw_render_stage(struct nvc0_context *);
240
241 /* nvc0_program.c */
242 bool nvc0_program_translate(struct nvc0_program *, uint16_t chipset,
243 struct pipe_debug_callback *);
244 bool nvc0_program_upload_code(struct nvc0_context *, struct nvc0_program *);
245 void nvc0_program_destroy(struct nvc0_context *, struct nvc0_program *);
246 void nvc0_program_library_upload(struct nvc0_context *);
247 uint32_t nvc0_program_symbol_offset(const struct nvc0_program *,
248 uint32_t label);
249 void nvc0_program_init_tcp_empty(struct nvc0_context *);
250
251 /* nvc0_shader_state.c */
252 void nvc0_vertprog_validate(struct nvc0_context *);
253 void nvc0_tctlprog_validate(struct nvc0_context *);
254 void nvc0_tevlprog_validate(struct nvc0_context *);
255 void nvc0_gmtyprog_validate(struct nvc0_context *);
256 void nvc0_fragprog_validate(struct nvc0_context *);
257
258 void nvc0_tfb_validate(struct nvc0_context *);
259
260 /* nvc0_state.c */
261 extern void nvc0_init_state_functions(struct nvc0_context *);
262
263 /* nvc0_state_validate.c */
264 void nvc0_validate_global_residents(struct nvc0_context *,
265 struct nouveau_bufctx *, int bin);
266 bool nvc0_state_validate(struct nvc0_context *, uint32_t state_mask);
267
268 /* nvc0_surface.c */
269 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
270 const union pipe_color_union *color,
271 double depth, unsigned stencil);
272 extern void nvc0_init_surface_functions(struct nvc0_context *);
273
274 /* nvc0_tex.c */
275 bool nvc0_validate_tic(struct nvc0_context *nvc0, int s);
276 bool nvc0_validate_tsc(struct nvc0_context *nvc0, int s);
277 bool nve4_validate_tsc(struct nvc0_context *nvc0, int s);
278 void nvc0_validate_textures(struct nvc0_context *);
279 void nvc0_validate_samplers(struct nvc0_context *);
280 void nve4_set_tex_handles(struct nvc0_context *);
281 void nvc0_validate_surfaces(struct nvc0_context *);
282 void nve4_set_surface_info(struct nouveau_pushbuf *, struct pipe_surface *,
283 struct nvc0_screen *);
284
285 struct pipe_sampler_view *
286 nvc0_create_texture_view(struct pipe_context *,
287 struct pipe_resource *,
288 const struct pipe_sampler_view *,
289 uint32_t flags,
290 enum pipe_texture_target);
291 struct pipe_sampler_view *
292 nvc0_create_sampler_view(struct pipe_context *,
293 struct pipe_resource *,
294 const struct pipe_sampler_view *);
295
296 /* nvc0_transfer.c */
297 void
298 nvc0_init_transfer_functions(struct nvc0_context *);
299
300 void
301 nvc0_m2mf_push_linear(struct nouveau_context *nv,
302 struct nouveau_bo *dst, unsigned offset, unsigned domain,
303 unsigned size, const void *data);
304 void
305 nve4_p2mf_push_linear(struct nouveau_context *nv,
306 struct nouveau_bo *dst, unsigned offset, unsigned domain,
307 unsigned size, const void *data);
308 void
309 nvc0_cb_bo_push(struct nouveau_context *,
310 struct nouveau_bo *bo, unsigned domain,
311 unsigned base, unsigned size,
312 unsigned offset, unsigned words, const uint32_t *data);
313
314 /* nvc0_vbo.c */
315 void nvc0_draw_vbo(struct pipe_context *, const struct pipe_draw_info *);
316
317 void *
318 nvc0_vertex_state_create(struct pipe_context *pipe,
319 unsigned num_elements,
320 const struct pipe_vertex_element *elements);
321 void
322 nvc0_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
323
324 void nvc0_vertex_arrays_validate(struct nvc0_context *);
325
326 void nvc0_idxbuf_validate(struct nvc0_context *);
327
328 /* nvc0_video.c */
329 struct pipe_video_codec *
330 nvc0_create_decoder(struct pipe_context *context,
331 const struct pipe_video_codec *templ);
332
333 struct pipe_video_buffer *
334 nvc0_video_buffer_create(struct pipe_context *pipe,
335 const struct pipe_video_buffer *templat);
336
337 /* nvc0_push.c */
338 void nvc0_push_vbo(struct nvc0_context *, const struct pipe_draw_info *);
339
340 /* nve4_compute.c */
341 void nve4_launch_grid(struct pipe_context *, const struct pipe_grid_info *);
342
343 /* nvc0_compute.c */
344 void nvc0_launch_grid(struct pipe_context *, const struct pipe_grid_info *);
345
346 #endif