1 #ifndef __NV50_CONTEXT_H__
2 #define __NV50_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 "nv50/nv50_winsys.h"
14 #include "nv50/nv50_stateobj.h"
15 #include "nv50/nv50_screen.h"
16 #include "nv50/nv50_program.h"
17 #include "nv50/nv50_resource.h"
18 #include "nv50/nv50_transfer.h"
19 #include "nv50/nv50_query.h"
20
21 #include "nouveau_context.h"
22 #include "nouveau_debug.h"
23 #include "nv_object.xml.h"
24 #include "nv_m2mf.xml.h"
25 #include "nv50/nv50_3ddefs.xml.h"
26 #include "nv50/nv50_3d.xml.h"
27 #include "nv50/nv50_2d.xml.h"
28 #include "nv50/nv50_compute.xml.h"
29
30 // NOTE: the VS/GS/FS order is based on how command methods are laid out for
31 // TSC/TIC setting.
32 #define NV50_SHADER_STAGE_VERTEX 0
33 #define NV50_SHADER_STAGE_GEOMETRY 1
34 #define NV50_SHADER_STAGE_FRAGMENT 2
35 #define NV50_SHADER_STAGE_COMPUTE 3
36 #define NV50_MAX_SHADER_STAGES 4
37
38 #define NV50_MAX_3D_SHADER_STAGES 3
39
40 #define NV50_NEW_3D_BLEND (1 << 0)
41 #define NV50_NEW_3D_RASTERIZER (1 << 1)
42 #define NV50_NEW_3D_ZSA (1 << 2)
43 #define NV50_NEW_3D_VERTPROG (1 << 3)
44 #define NV50_NEW_3D_GMTYPROG (1 << 6)
45 #define NV50_NEW_3D_FRAGPROG (1 << 7)
46 #define NV50_NEW_3D_BLEND_COLOUR (1 << 8)
47 #define NV50_NEW_3D_STENCIL_REF (1 << 9)
48 #define NV50_NEW_3D_CLIP (1 << 10)
49 #define NV50_NEW_3D_SAMPLE_MASK (1 << 11)
50 #define NV50_NEW_3D_FRAMEBUFFER (1 << 12)
51 #define NV50_NEW_3D_STIPPLE (1 << 13)
52 #define NV50_NEW_3D_SCISSOR (1 << 14)
53 #define NV50_NEW_3D_VIEWPORT (1 << 15)
54 #define NV50_NEW_3D_ARRAYS (1 << 16)
55 #define NV50_NEW_3D_VERTEX (1 << 17)
56 #define NV50_NEW_3D_CONSTBUF (1 << 18)
57 #define NV50_NEW_3D_TEXTURES (1 << 19)
58 #define NV50_NEW_3D_SAMPLERS (1 << 20)
59 #define NV50_NEW_3D_STRMOUT (1 << 21)
60 #define NV50_NEW_3D_MIN_SAMPLES (1 << 22)
61 #define NV50_NEW_3D_WINDOW_RECTS (1 << 23)
62
63 #define NV50_NEW_CP_PROGRAM (1 << 0)
64 #define NV50_NEW_CP_SURFACES (1 << 1)
65 #define NV50_NEW_CP_TEXTURES (1 << 2)
66 #define NV50_NEW_CP_SAMPLERS (1 << 3)
67 #define NV50_NEW_CP_CONSTBUF (1 << 4)
68 #define NV50_NEW_CP_GLOBALS (1 << 5)
69 #define NV50_NEW_CP_DRIVERCONST (1 << 6)
70 #define NV50_NEW_CP_BUFFERS (1 << 7)
71
72 /* 3d bufctx (during draw_vbo, blit_3d) */
73 #define NV50_BIND_3D_FB 0
74 #define NV50_BIND_3D_VERTEX 1
75 #define NV50_BIND_3D_VERTEX_TMP 2
76 #define NV50_BIND_3D_INDEX 3
77 #define NV50_BIND_3D_TEXTURES 4
78 #define NV50_BIND_3D_CB(s, i) (5 + 16 * (s) + (i))
79 #define NV50_BIND_3D_SO 53
80 #define NV50_BIND_3D_SCREEN 54
81 #define NV50_BIND_3D_TLS 55
82 #define NV50_BIND_3D_COUNT 56
83
84 /* compute bufctx (during launch_grid) */
85 #define NV50_BIND_CP_CB(i) ( 0 + (i))
86 #define NV50_BIND_CP_TEXTURES 16
87 #define NV50_BIND_CP_SUF 17
88 #define NV50_BIND_CP_BUF 18
89 #define NV50_BIND_CP_GLOBAL 19
90 #define NV50_BIND_CP_SCREEN 20
91 #define NV50_BIND_CP_QUERY 21
92 #define NV50_BIND_CP_COUNT 22
93
94 /* bufctx for other operations */
95 #define NV50_BIND_2D 0
96 #define NV50_BIND_M2MF 0
97 #define NV50_BIND_FENCE 1
98
99 /* fixed constant buffer binding points - low indices for user's constbufs */
100 #define NV50_CB_PVP 123
101 #define NV50_CB_PGP 124
102 #define NV50_CB_PFP 125
103 #define NV50_CB_PCP 126
104 /* constant buffer permanently mapped in as c15[] */
105 #define NV50_CB_AUX 127
106 /* size of the buffer: 64k. not all taken up, can be reduced if needed. */
107 #define NV50_CB_AUX_SIZE (1 << 16)
108 /* 8 user clip planes, at 4 32-bit floats each */
109 #define NV50_CB_AUX_UCP_OFFSET 0x0000
110 #define NV50_CB_AUX_UCP_SIZE (8 * 4 * 4)
111 /* 16 textures * NV50_MAX_SHADER_STAGES shaders, each with ms_x, ms_y u32 pairs */
112 #define NV50_CB_AUX_TEX_MS_OFFSET 0x0080
113 #define NV50_CB_AUX_TEX_MS_SIZE (16 * NV50_MAX_SHADER_STAGES * 2 * 4)
114 /* For each MS level (4), 8 sets of 32-bit integer pairs sample offsets */
115 #define NV50_CB_AUX_MS_OFFSET 0x280
116 #define NV50_CB_AUX_MS_SIZE (4 * 8 * 4 * 2)
117 /* Sample position pairs for the current output MS level */
118 #define NV50_CB_AUX_SAMPLE_OFFSET 0x380
119 #define NV50_CB_AUX_SAMPLE_OFFSET_SIZE (4 * 8 * 2)
120 /* Alpha test ref value */
121 #define NV50_CB_AUX_ALPHATEST_OFFSET 0x3c0
122 #define NV50_CB_AUX_ALPHATEST_SIZE (4)
123 /* Compute buffer info: 16 surfaces, 12 32-bit integers each */
124 #define NV50_CB_AUX_BUF_INFO(i) (0x3c4 + (i) * 12 * 4)
125 #define NV50_CB_AUX_BUF_SIZE (NV50_MAX_GLOBALS * 12 * 4)
126 /* Compute membar mapped area */
127 #define NV50_CB_AUX_MEMBAR_OFFSET 0x6c4
128 /* next spot: 0x6c8 */
129 /* 0x800 from the end for compute shader membars, reads only. */
130 #define NV50_CB_AUX_MEMBAR (NV50_CB_AUX_SIZE - 0x800)
131 /* 4 32-bit floats for the vertex runout, put at the end */
132 #define NV50_CB_AUX_RUNOUT_OFFSET (NV50_CB_AUX_SIZE - 0x10)
133
134
135
136 struct nv50_blitctx;
137
138 bool nv50_blitctx_create(struct nv50_context *);
139
140 struct nv50_context {
141 struct nouveau_context base;
142
143 struct nv50_screen *screen;
144
145 struct nouveau_bufctx *bufctx_3d;
146 struct nouveau_bufctx *bufctx;
147 struct nouveau_bufctx *bufctx_cp;
148
149 uint32_t dirty_3d; /* dirty flags for 3d state */
150 uint32_t dirty_cp; /* dirty flags for compute state */
151 bool cb_dirty;
152
153 struct nv50_graph_state state;
154
155 struct nv50_blend_stateobj *blend;
156 struct nv50_rasterizer_stateobj *rast;
157 struct nv50_zsa_stateobj *zsa;
158 struct nv50_vertex_stateobj *vertex;
159
160 struct nv50_program *vertprog;
161 struct nv50_program *gmtyprog;
162 struct nv50_program *fragprog;
163 struct nv50_program *compprog;
164
165 struct nv50_constbuf constbuf[NV50_MAX_SHADER_STAGES][NV50_MAX_PIPE_CONSTBUFS];
166 uint16_t constbuf_dirty[NV50_MAX_SHADER_STAGES];
167 uint16_t constbuf_valid[NV50_MAX_SHADER_STAGES];
168 uint16_t constbuf_coherent[NV50_MAX_SHADER_STAGES];
169
170 struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
171 unsigned num_vtxbufs;
172 uint32_t vtxbufs_coherent;
173 uint32_t vbo_fifo; /* bitmask of vertex elements to be pushed to FIFO */
174 uint32_t vbo_user; /* bitmask of vertex buffers pointing to user memory */
175 uint32_t vbo_constant; /* bitmask of user buffers with stride 0 */
176 uint32_t vb_elt_first; /* from pipe_draw_info, for vertex upload */
177 uint32_t vb_elt_limit; /* max - min element (count - 1) */
178 uint32_t instance_off; /* base vertex for instanced arrays */
179 uint32_t instance_max; /* max instance for current draw call */
180
181 struct pipe_sampler_view *textures[NV50_MAX_SHADER_STAGES][PIPE_MAX_SAMPLERS];
182 unsigned num_textures[NV50_MAX_SHADER_STAGES];
183 uint32_t textures_coherent[NV50_MAX_SHADER_STAGES];
184 struct nv50_tsc_entry *samplers[NV50_MAX_SHADER_STAGES][PIPE_MAX_SAMPLERS];
185 unsigned num_samplers[NV50_MAX_SHADER_STAGES];
186 bool seamless_cube_map;
187
188 uint8_t num_so_targets;
189 uint8_t so_targets_dirty;
190 struct pipe_stream_output_target *so_target[4];
191 /* keeps track of how much of an SO is used. normally this doesn't work in
192 * the presence of GS, but this only needs to work for ES 3.0 which doesn't
193 * have GS or any other oddities. only used pre-NVA0.
194 */
195 uint32_t so_used[4];
196
197 struct pipe_framebuffer_state framebuffer;
198 struct pipe_blend_color blend_colour;
199 struct pipe_stencil_ref stencil_ref;
200 struct pipe_poly_stipple stipple;
201 struct pipe_scissor_state scissors[NV50_MAX_VIEWPORTS];
202 unsigned scissors_dirty;
203 struct pipe_viewport_state viewports[NV50_MAX_VIEWPORTS];
204 unsigned viewports_dirty;
205 struct pipe_clip_state clip;
206 struct nv50_window_rect_stateobj window_rect;
207
208 unsigned sample_mask;
209 unsigned min_samples;
210
211 bool vbo_push_hint;
212
213 uint32_t rt_array_mode;
214
215 struct pipe_query *cond_query;
216 bool cond_cond; /* inverted rendering condition */
217 uint cond_mode;
218 uint32_t cond_condmode; /* the calculated condition */
219
220 struct nv50_blitctx *blit;
221
222 /* compute stage only */
223 struct pipe_shader_buffer buffers[NV50_MAX_GLOBALS];
224 uint16_t buffers_dirty;
225 uint16_t buffers_valid;
226
227 struct pipe_image_view images[NV50_MAX_GLOBALS];
228 uint16_t images_dirty;
229 uint16_t images_valid;
230
231 struct util_dynarray global_residents;
232
233 uint64_t compute_invocations;
234 };
235
236 static inline struct nv50_context *
nv50_context(struct pipe_context * pipe)237 nv50_context(struct pipe_context *pipe)
238 {
239 return (struct nv50_context *)pipe;
240 }
241
242 /* return index used in nv50_context arrays for a specific shader type */
243 static inline unsigned
nv50_context_shader_stage(unsigned pipe)244 nv50_context_shader_stage(unsigned pipe)
245 {
246 switch (pipe) {
247 case PIPE_SHADER_VERTEX: return NV50_SHADER_STAGE_VERTEX;
248 case PIPE_SHADER_FRAGMENT: return NV50_SHADER_STAGE_FRAGMENT;
249 case PIPE_SHADER_GEOMETRY: return NV50_SHADER_STAGE_GEOMETRY;
250 case PIPE_SHADER_COMPUTE: return NV50_SHADER_STAGE_COMPUTE;
251 default:
252 assert(!"invalid/unhandled shader type");
253 return 0;
254 }
255 }
256
257 /* nv50_context.c */
258 struct pipe_context *nv50_create(struct pipe_screen *, void *, unsigned flags);
259
260 void nv50_bufctx_fence(struct nouveau_bufctx *, bool on_flush);
261
262 void nv50_default_kick_notify(struct nouveau_pushbuf *);
263
264 /* nv50_draw.c */
265 extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *);
266
267 /* nv50_shader_state.c */
268 void nv50_vertprog_validate(struct nv50_context *);
269 void nv50_gmtyprog_validate(struct nv50_context *);
270 void nv50_fragprog_validate(struct nv50_context *);
271 void nv50_compprog_validate(struct nv50_context *);
272 void nv50_fp_linkage_validate(struct nv50_context *);
273 void nv50_gp_linkage_validate(struct nv50_context *);
274 void nv50_constbufs_validate(struct nv50_context *);
275 void nv50_validate_derived_rs(struct nv50_context *);
276 void nv50_stream_output_validate(struct nv50_context *);
277
278 /* nv50_state.c */
279 extern void nv50_init_state_functions(struct nv50_context *);
280
281 /* nv50_state_validate.c */
282 struct nv50_state_validate {
283 void (*func)(struct nv50_context *);
284 uint32_t states;
285 };
286
287 bool nv50_state_validate(struct nv50_context *, uint32_t,
288 struct nv50_state_validate *, int, uint32_t *,
289 struct nouveau_bufctx *);
290 bool nv50_state_validate_3d(struct nv50_context *, uint32_t);
291
292 /* nv50_surface.c */
293 extern void nv50_clear(struct pipe_context *, unsigned buffers,
294 const struct pipe_scissor_state *scissor_state,
295 const union pipe_color_union *color,
296 double depth, unsigned stencil);
297 extern void nv50_init_surface_functions(struct nv50_context *);
298
299 /* nv50_tex.c */
300 bool nv50_validate_tic(struct nv50_context *nv50, int s);
301 void nv50_validate_textures(struct nv50_context *);
302 bool nv50_validate_tsc(struct nv50_context *nv50, int s);
303 void nv50_validate_samplers(struct nv50_context *);
304 void nv50_upload_ms_info(struct nouveau_pushbuf *);
305 void nv50_upload_tsc0(struct nv50_context *);
306
307 struct pipe_sampler_view *
308 nv50_create_texture_view(struct pipe_context *,
309 struct pipe_resource *,
310 const struct pipe_sampler_view *,
311 uint32_t flags);
312 struct pipe_sampler_view *
313 nv50_create_sampler_view(struct pipe_context *,
314 struct pipe_resource *,
315 const struct pipe_sampler_view *);
316
317 /* nv50_transfer.c */
318 void
319 nv50_m2mf_transfer_rect(struct nv50_context *,
320 const struct nv50_m2mf_rect *dst,
321 const struct nv50_m2mf_rect *src,
322 uint32_t nblocksx, uint32_t nblocksy);
323 void
324 nv50_sifc_linear_u8(struct nouveau_context *pipe,
325 struct nouveau_bo *dst, unsigned offset, unsigned domain,
326 unsigned size, const void *data);
327 void
328 nv50_m2mf_copy_linear(struct nouveau_context *pipe,
329 struct nouveau_bo *dst, unsigned dstoff, unsigned dstdom,
330 struct nouveau_bo *src, unsigned srcoff, unsigned srcdom,
331 unsigned size);
332 void
333 nv50_cb_push(struct nouveau_context *nv,
334 struct nv04_resource *res,
335 unsigned offset, unsigned words, const uint32_t *data);
336
337 /* nv50_vbo.c */
338 void nv50_draw_vbo(struct pipe_context *, const struct pipe_draw_info *, unsigned,
339 const struct pipe_draw_indirect_info *indirect,
340 const struct pipe_draw_start_count_bias *draws,
341 unsigned num_draws);
342
343 void *
344 nv50_vertex_state_create(struct pipe_context *pipe,
345 unsigned num_elements,
346 const struct pipe_vertex_element *elements);
347 void
348 nv50_vertex_state_delete(struct pipe_context *pipe, void *hwcso);
349
350 void nv50_vertex_arrays_validate(struct nv50_context *nv50);
351
352 /* nv50_push.c */
353 void nv50_push_vbo(struct nv50_context *, const struct pipe_draw_info *,
354 const struct pipe_draw_indirect_info *indirect,
355 const struct pipe_draw_start_count_bias *draw);
356
357 /* nv84_video.c */
358 struct pipe_video_codec *
359 nv84_create_decoder(struct pipe_context *context,
360 const struct pipe_video_codec *templ);
361
362 struct pipe_video_buffer *
363 nv84_video_buffer_create(struct pipe_context *pipe,
364 const struct pipe_video_buffer *template);
365
366 int
367 nv84_screen_get_video_param(struct pipe_screen *pscreen,
368 enum pipe_video_profile profile,
369 enum pipe_video_entrypoint entrypoint,
370 enum pipe_video_cap param);
371
372 bool
373 nv84_screen_video_supported(struct pipe_screen *screen,
374 enum pipe_format format,
375 enum pipe_video_profile profile,
376 enum pipe_video_entrypoint entrypoint);
377
378 /* nv98_video.c */
379 struct pipe_video_codec *
380 nv98_create_decoder(struct pipe_context *context,
381 const struct pipe_video_codec *templ);
382
383 struct pipe_video_buffer *
384 nv98_video_buffer_create(struct pipe_context *pipe,
385 const struct pipe_video_buffer *template);
386
387 /* nv50_compute.c */
388 void
389 nv50_launch_grid(struct pipe_context *, const struct pipe_grid_info *);
390
391 #endif
392