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