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