Debian Codegraph @

src/gallium/drivers/nouveau/nv50/nv50_context.h

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