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