ilo: move command builder to core
[mesa.git] / src / gallium / drivers / ilo / ilo_render_gen.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #ifndef ILO_RENDER_GEN_H
29 #define ILO_RENDER_GEN_H
30
31 #include "core/ilo_builder.h"
32 #include "core/ilo_builder_3d.h"
33 #include "core/ilo_builder_render.h"
34
35 #include "ilo_common.h"
36 #include "ilo_state.h"
37 #include "ilo_render.h"
38
39 struct ilo_bo;
40 struct ilo_blitter;
41 struct ilo_render;
42 struct ilo_state_vector;
43
44 /**
45 * Render Engine.
46 */
47 struct ilo_render {
48 const struct ilo_dev *dev;
49 struct ilo_builder *builder;
50
51 struct intel_bo *workaround_bo;
52
53 uint32_t sample_pattern_1x;
54 uint32_t sample_pattern_2x;
55 uint32_t sample_pattern_4x;
56 uint32_t sample_pattern_8x[2];
57 uint32_t sample_pattern_16x[4];
58
59 bool hw_ctx_changed;
60
61 /*
62 * Any state that involves resources needs to be re-emitted when the
63 * batch bo changed. This is because we do not pin the resources and
64 * their offsets (or existence) may change between batch buffers.
65 */
66 bool batch_bo_changed;
67 bool state_bo_changed;
68 bool instruction_bo_changed;
69
70 /**
71 * HW states.
72 */
73 struct ilo_render_state {
74 /*
75 * When a WA is needed before some command, we always emit the WA right
76 * before the command. Knowing what have already been done since last
77 * 3DPRIMITIVE allows us to skip some WAs.
78 */
79 uint32_t current_pipe_control_dw1;
80
81 /*
82 * When a WA is needed after some command, we may have the WA follow the
83 * command immediately or defer it. If this is non-zero, a PIPE_CONTROL
84 * will be emitted before 3DPRIMITIVE.
85 */
86 uint32_t deferred_pipe_control_dw1;
87
88 bool primitive_restart;
89 int reduced_prim;
90 int so_max_vertices;
91
92 uint32_t SF_VIEWPORT;
93 uint32_t CLIP_VIEWPORT;
94 uint32_t SF_CLIP_VIEWPORT; /* GEN7+ */
95 uint32_t CC_VIEWPORT;
96
97 uint32_t COLOR_CALC_STATE;
98 uint32_t BLEND_STATE;
99 uint32_t DEPTH_STENCIL_STATE;
100
101 uint32_t SCISSOR_RECT;
102
103 struct {
104 uint32_t BINDING_TABLE_STATE;
105 uint32_t SURFACE_STATE[ILO_MAX_SURFACES];
106 uint32_t SAMPLER_STATE;
107 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
108 uint32_t PUSH_CONSTANT_BUFFER;
109 int PUSH_CONSTANT_BUFFER_size;
110 } vs;
111
112 struct {
113 uint32_t BINDING_TABLE_STATE;
114 uint32_t SURFACE_STATE[ILO_MAX_SURFACES];
115 bool active;
116 } gs;
117
118 struct {
119 uint32_t BINDING_TABLE_STATE;
120 uint32_t SURFACE_STATE[ILO_MAX_SURFACES];
121 uint32_t SAMPLER_STATE;
122 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
123 uint32_t PUSH_CONSTANT_BUFFER;
124 int PUSH_CONSTANT_BUFFER_size;
125 } wm;
126
127 struct {
128 uint32_t BINDING_TABLE_STATE;
129 uint32_t SURFACE_STATE[ILO_MAX_SURFACES];
130 uint32_t SAMPLER_STATE;
131 uint32_t SAMPLER_BORDER_COLOR_STATE[ILO_MAX_SAMPLERS];
132 uint32_t PUSH_CONSTANT_BUFFER;
133 int PUSH_CONSTANT_BUFFER_size;
134 } cs;
135 } state;
136 };
137
138 struct ilo_render_draw_session {
139 uint32_t pipe_dirty;
140
141 /* commands */
142 int reduced_prim;
143
144 bool prim_changed;
145 bool primitive_restart_changed;
146
147 /* dynamic states */
148 bool viewport_changed;
149 bool scissor_changed;
150
151 bool cc_changed;
152 bool dsa_changed;
153 bool blend_changed;
154
155 bool sampler_vs_changed;
156 bool sampler_gs_changed;
157 bool sampler_fs_changed;
158
159 bool pcb_vs_changed;
160 bool pcb_gs_changed;
161 bool pcb_fs_changed;
162
163 /* surface states */
164 bool binding_table_vs_changed;
165 bool binding_table_gs_changed;
166 bool binding_table_fs_changed;
167 };
168
169 struct ilo_render_rectlist_session {
170 uint32_t vb_start;
171 uint32_t vb_end;
172 };
173
174 struct ilo_render_launch_grid_session {
175 const unsigned *thread_group_offset;
176 const unsigned *thread_group_dim;
177 unsigned thread_group_size;
178 const struct pipe_constant_buffer *input;
179 uint32_t pc;
180
181 uint32_t idrt;
182 int idrt_size;
183 };
184
185 int
186 ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
187 const struct ilo_state_vector *vec);
188
189 int
190 ilo_render_get_draw_commands_len_gen7(const struct ilo_render *render,
191 const struct ilo_state_vector *vec);
192
193 int
194 ilo_render_get_draw_commands_len_gen8(const struct ilo_render *render,
195 const struct ilo_state_vector *vec);
196
197 static inline int
198 ilo_render_get_draw_commands_len(const struct ilo_render *render,
199 const struct ilo_state_vector *vec)
200 {
201 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
202 return ilo_render_get_draw_commands_len_gen8(render, vec);
203 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
204 return ilo_render_get_draw_commands_len_gen7(render, vec);
205 else
206 return ilo_render_get_draw_commands_len_gen6(render, vec);
207 }
208
209 void
210 ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
211 const struct ilo_state_vector *vec,
212 struct ilo_render_draw_session *session);
213
214 void
215 ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
216 const struct ilo_state_vector *vec,
217 struct ilo_render_draw_session *session);
218
219 void
220 ilo_render_emit_draw_commands_gen8(struct ilo_render *render,
221 const struct ilo_state_vector *vec,
222 struct ilo_render_draw_session *session);
223
224 static inline void
225 ilo_render_emit_draw_commands(struct ilo_render *render,
226 const struct ilo_state_vector *vec,
227 struct ilo_render_draw_session *session)
228 {
229 const unsigned batch_used = ilo_builder_batch_used(render->builder);
230
231 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
232 ilo_render_emit_draw_commands_gen8(render, vec, session);
233 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
234 ilo_render_emit_draw_commands_gen7(render, vec, session);
235 else
236 ilo_render_emit_draw_commands_gen6(render, vec, session);
237
238 assert(ilo_builder_batch_used(render->builder) <= batch_used +
239 ilo_render_get_draw_commands_len(render, vec));
240 }
241
242 int
243 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render *render,
244 const struct ilo_blitter *blitter);
245
246 int
247 ilo_render_get_rectlist_commands_len_gen8(const struct ilo_render *render,
248 const struct ilo_blitter *blitter);
249
250 static inline int
251 ilo_render_get_rectlist_commands_len(const struct ilo_render *render,
252 const struct ilo_blitter *blitter)
253 {
254 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
255 return ilo_render_get_rectlist_commands_len_gen8(render, blitter);
256 else
257 return ilo_render_get_rectlist_commands_len_gen6(render, blitter);
258 }
259
260 void
261 ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
262 const struct ilo_blitter *blitter,
263 const struct ilo_render_rectlist_session *session);
264
265 void
266 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
267 const struct ilo_blitter *blitter,
268 const struct ilo_render_rectlist_session *session);
269
270 void
271 ilo_render_emit_rectlist_commands_gen8(struct ilo_render *r,
272 const struct ilo_blitter *blitter,
273 const struct ilo_render_rectlist_session *session);
274
275 static inline void
276 ilo_render_emit_rectlist_commands(struct ilo_render *render,
277 const struct ilo_blitter *blitter,
278 const struct ilo_render_rectlist_session *session)
279 {
280 const unsigned batch_used = ilo_builder_batch_used(render->builder);
281
282 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
283 ilo_render_emit_rectlist_commands_gen8(render, blitter, session);
284 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
285 ilo_render_emit_rectlist_commands_gen7(render, blitter, session);
286 else
287 ilo_render_emit_rectlist_commands_gen6(render, blitter, session);
288
289 assert(ilo_builder_batch_used(render->builder) <= batch_used +
290 ilo_render_get_rectlist_commands_len(render, blitter));
291 }
292
293 int
294 ilo_render_get_launch_grid_commands_len(const struct ilo_render *render,
295 const struct ilo_state_vector *vec);
296
297 void
298 ilo_render_emit_launch_grid_commands(struct ilo_render *render,
299 const struct ilo_state_vector *vec,
300 const struct ilo_render_launch_grid_session *session);
301
302 int
303 ilo_render_get_draw_dynamic_states_len(const struct ilo_render *render,
304 const struct ilo_state_vector *vec);
305
306 void
307 ilo_render_emit_draw_dynamic_states(struct ilo_render *render,
308 const struct ilo_state_vector *vec,
309 struct ilo_render_draw_session *session);
310
311 int
312 ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render *render,
313 const struct ilo_blitter *blitter);
314
315 void
316 ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
317 const struct ilo_blitter *blitter,
318 struct ilo_render_rectlist_session *session);
319
320 int
321 ilo_render_get_launch_grid_dynamic_states_len(const struct ilo_render *render,
322 const struct ilo_state_vector *vec);
323
324 void
325 ilo_render_emit_launch_grid_dynamic_states(struct ilo_render *render,
326 const struct ilo_state_vector *vec,
327 struct ilo_render_launch_grid_session *session);
328
329 int
330 ilo_render_get_draw_surface_states_len(const struct ilo_render *render,
331 const struct ilo_state_vector *vec);
332
333 void
334 ilo_render_emit_draw_surface_states(struct ilo_render *render,
335 const struct ilo_state_vector *vec,
336 struct ilo_render_draw_session *session);
337
338 int
339 ilo_render_get_launch_grid_surface_states_len(const struct ilo_render *render,
340 const struct ilo_state_vector *vec);
341
342 void
343 ilo_render_emit_launch_grid_surface_states(struct ilo_render *render,
344 const struct ilo_state_vector *vec,
345 struct ilo_render_launch_grid_session *session);
346
347 /**
348 * A convenient wrapper for gen6_PIPE_CONTROL(). This should be enough for
349 * our needs everywhere except for queries.
350 */
351 static inline void
352 ilo_render_pipe_control(struct ilo_render *r, uint32_t dw1)
353 {
354 const uint32_t write_mask = (dw1 & GEN6_PIPE_CONTROL_WRITE__MASK);
355 struct intel_bo *bo = (write_mask) ? r->workaround_bo : NULL;
356
357 ILO_DEV_ASSERT(r->dev, 6, 8);
358
359 if (write_mask)
360 assert(write_mask == GEN6_PIPE_CONTROL_WRITE_IMM);
361
362 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
363 /* CS stall cannot be set alone */
364 const uint32_t mask = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
365 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
366 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
367 GEN6_PIPE_CONTROL_DEPTH_STALL |
368 GEN6_PIPE_CONTROL_WRITE__MASK;
369 if (!(dw1 & mask))
370 dw1 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
371 }
372
373 gen6_PIPE_CONTROL(r->builder, dw1, bo, 0, 0);
374
375 r->state.current_pipe_control_dw1 |= dw1;
376 r->state.deferred_pipe_control_dw1 &= ~dw1;
377 }
378
379 /**
380 * A convenient wrapper for gen{6,7}_3DPRIMITIVE().
381 */
382 static inline void
383 ilo_render_3dprimitive(struct ilo_render *r,
384 const struct pipe_draw_info *info,
385 const struct ilo_ib_state *ib)
386 {
387 ILO_DEV_ASSERT(r->dev, 6, 8);
388
389 if (r->state.deferred_pipe_control_dw1)
390 ilo_render_pipe_control(r, r->state.deferred_pipe_control_dw1);
391
392 /* 3DPRIMITIVE */
393 if (ilo_dev_gen(r->dev) >= ILO_GEN(7))
394 gen7_3DPRIMITIVE(r->builder, info, ib);
395 else
396 gen6_3DPRIMITIVE(r->builder, info, ib);
397
398 r->state.current_pipe_control_dw1 = 0;
399 assert(!r->state.deferred_pipe_control_dw1);
400 }
401
402 void
403 gen6_wa_pre_pipe_control(struct ilo_render *r, uint32_t dw1);
404
405 void
406 gen6_draw_common_select(struct ilo_render *r,
407 const struct ilo_state_vector *ilo,
408 struct ilo_render_draw_session *session);
409
410 void
411 gen6_draw_common_sip(struct ilo_render *r,
412 const struct ilo_state_vector *ilo,
413 struct ilo_render_draw_session *session);
414
415 void
416 gen6_draw_common_base_address(struct ilo_render *r,
417 const struct ilo_state_vector *ilo,
418 struct ilo_render_draw_session *session);
419
420 void
421 gen6_draw_vf(struct ilo_render *r,
422 const struct ilo_state_vector *ilo,
423 struct ilo_render_draw_session *session);
424
425 void
426 gen6_draw_vf_statistics(struct ilo_render *r,
427 const struct ilo_state_vector *ilo,
428 struct ilo_render_draw_session *session);
429
430 void
431 gen6_draw_vs(struct ilo_render *r,
432 const struct ilo_state_vector *ilo,
433 struct ilo_render_draw_session *session);
434
435 void
436 gen6_draw_clip(struct ilo_render *r,
437 const struct ilo_state_vector *ilo,
438 struct ilo_render_draw_session *session);
439
440 void
441 gen6_draw_sf_rect(struct ilo_render *r,
442 const struct ilo_state_vector *ilo,
443 struct ilo_render_draw_session *session);
444
445 void
446 gen6_draw_wm_raster(struct ilo_render *r,
447 const struct ilo_state_vector *ilo,
448 struct ilo_render_draw_session *session);
449
450 void
451 gen7_draw_common_pcb_alloc(struct ilo_render *r,
452 const struct ilo_state_vector *vec,
453 struct ilo_render_draw_session *session);
454
455 void
456 gen7_draw_common_pointers_1(struct ilo_render *r,
457 const struct ilo_state_vector *vec,
458 struct ilo_render_draw_session *session);
459
460 void
461 gen7_draw_common_urb(struct ilo_render *r,
462 const struct ilo_state_vector *vec,
463 struct ilo_render_draw_session *session);
464
465 void
466 gen7_draw_common_pointers_2(struct ilo_render *r,
467 const struct ilo_state_vector *vec,
468 struct ilo_render_draw_session *session);
469
470 void
471 gen7_draw_vs(struct ilo_render *r,
472 const struct ilo_state_vector *vec,
473 struct ilo_render_draw_session *session);
474
475 void
476 gen7_draw_ds(struct ilo_render *r,
477 const struct ilo_state_vector *vec,
478 struct ilo_render_draw_session *session);
479
480 void
481 gen7_draw_te(struct ilo_render *r,
482 const struct ilo_state_vector *vec,
483 struct ilo_render_draw_session *session);
484
485 void
486 gen7_draw_hs(struct ilo_render *r,
487 const struct ilo_state_vector *vec,
488 struct ilo_render_draw_session *session);
489
490 void
491 gen7_draw_gs(struct ilo_render *r,
492 const struct ilo_state_vector *vec,
493 struct ilo_render_draw_session *session);
494
495 void
496 gen7_draw_sol(struct ilo_render *r,
497 const struct ilo_state_vector *vec,
498 struct ilo_render_draw_session *session);
499
500 #endif /* ILO_RENDER_GEN_H */