ilo: embed ilo_state_viewport in ilo_viewport_state
[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 struct ilo_state_viewport_delta vp_delta;
148
149 /* dynamic states */
150 bool viewport_changed;
151 bool scissor_changed;
152
153 bool cc_changed;
154 bool dsa_changed;
155 bool blend_changed;
156
157 bool sampler_vs_changed;
158 bool sampler_gs_changed;
159 bool sampler_fs_changed;
160
161 bool pcb_vs_changed;
162 bool pcb_gs_changed;
163 bool pcb_fs_changed;
164
165 /* surface states */
166 bool binding_table_vs_changed;
167 bool binding_table_gs_changed;
168 bool binding_table_fs_changed;
169 };
170
171 struct ilo_render_rectlist_session {
172 uint32_t vb_start;
173 uint32_t vb_end;
174 };
175
176 struct ilo_render_launch_grid_session {
177 const unsigned *thread_group_offset;
178 const unsigned *thread_group_dim;
179 unsigned thread_group_size;
180 const struct pipe_constant_buffer *input;
181 uint32_t pc;
182
183 uint32_t idrt;
184 int idrt_size;
185 };
186
187 int
188 ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
189 const struct ilo_state_vector *vec);
190
191 int
192 ilo_render_get_draw_commands_len_gen7(const struct ilo_render *render,
193 const struct ilo_state_vector *vec);
194
195 int
196 ilo_render_get_draw_commands_len_gen8(const struct ilo_render *render,
197 const struct ilo_state_vector *vec);
198
199 static inline int
200 ilo_render_get_draw_commands_len(const struct ilo_render *render,
201 const struct ilo_state_vector *vec)
202 {
203 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
204 return ilo_render_get_draw_commands_len_gen8(render, vec);
205 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
206 return ilo_render_get_draw_commands_len_gen7(render, vec);
207 else
208 return ilo_render_get_draw_commands_len_gen6(render, vec);
209 }
210
211 void
212 ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
213 const struct ilo_state_vector *vec,
214 struct ilo_render_draw_session *session);
215
216 void
217 ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
218 const struct ilo_state_vector *vec,
219 struct ilo_render_draw_session *session);
220
221 void
222 ilo_render_emit_draw_commands_gen8(struct ilo_render *render,
223 const struct ilo_state_vector *vec,
224 struct ilo_render_draw_session *session);
225
226 static inline void
227 ilo_render_emit_draw_commands(struct ilo_render *render,
228 const struct ilo_state_vector *vec,
229 struct ilo_render_draw_session *session)
230 {
231 const unsigned batch_used = ilo_builder_batch_used(render->builder);
232
233 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
234 ilo_render_emit_draw_commands_gen8(render, vec, session);
235 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
236 ilo_render_emit_draw_commands_gen7(render, vec, session);
237 else
238 ilo_render_emit_draw_commands_gen6(render, vec, session);
239
240 assert(ilo_builder_batch_used(render->builder) <= batch_used +
241 ilo_render_get_draw_commands_len(render, vec));
242 }
243
244 int
245 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render *render,
246 const struct ilo_blitter *blitter);
247
248 int
249 ilo_render_get_rectlist_commands_len_gen8(const struct ilo_render *render,
250 const struct ilo_blitter *blitter);
251
252 static inline int
253 ilo_render_get_rectlist_commands_len(const struct ilo_render *render,
254 const struct ilo_blitter *blitter)
255 {
256 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
257 return ilo_render_get_rectlist_commands_len_gen8(render, blitter);
258 else
259 return ilo_render_get_rectlist_commands_len_gen6(render, blitter);
260 }
261
262 void
263 ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
264 const struct ilo_blitter *blitter,
265 const struct ilo_render_rectlist_session *session);
266
267 void
268 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
269 const struct ilo_blitter *blitter,
270 const struct ilo_render_rectlist_session *session);
271
272 void
273 ilo_render_emit_rectlist_commands_gen8(struct ilo_render *r,
274 const struct ilo_blitter *blitter,
275 const struct ilo_render_rectlist_session *session);
276
277 static inline void
278 ilo_render_emit_rectlist_commands(struct ilo_render *render,
279 const struct ilo_blitter *blitter,
280 const struct ilo_render_rectlist_session *session)
281 {
282 const unsigned batch_used = ilo_builder_batch_used(render->builder);
283
284 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
285 ilo_render_emit_rectlist_commands_gen8(render, blitter, session);
286 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
287 ilo_render_emit_rectlist_commands_gen7(render, blitter, session);
288 else
289 ilo_render_emit_rectlist_commands_gen6(render, blitter, session);
290
291 assert(ilo_builder_batch_used(render->builder) <= batch_used +
292 ilo_render_get_rectlist_commands_len(render, blitter));
293 }
294
295 int
296 ilo_render_get_launch_grid_commands_len(const struct ilo_render *render,
297 const struct ilo_state_vector *vec);
298
299 void
300 ilo_render_emit_launch_grid_commands(struct ilo_render *render,
301 const struct ilo_state_vector *vec,
302 const struct ilo_render_launch_grid_session *session);
303
304 int
305 ilo_render_get_draw_dynamic_states_len(const struct ilo_render *render,
306 const struct ilo_state_vector *vec);
307
308 void
309 ilo_render_emit_draw_dynamic_states(struct ilo_render *render,
310 const struct ilo_state_vector *vec,
311 struct ilo_render_draw_session *session);
312
313 int
314 ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render *render,
315 const struct ilo_blitter *blitter);
316
317 void
318 ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
319 const struct ilo_blitter *blitter,
320 struct ilo_render_rectlist_session *session);
321
322 int
323 ilo_render_get_launch_grid_dynamic_states_len(const struct ilo_render *render,
324 const struct ilo_state_vector *vec);
325
326 void
327 ilo_render_emit_launch_grid_dynamic_states(struct ilo_render *render,
328 const struct ilo_state_vector *vec,
329 struct ilo_render_launch_grid_session *session);
330
331 int
332 ilo_render_get_draw_surface_states_len(const struct ilo_render *render,
333 const struct ilo_state_vector *vec);
334
335 void
336 ilo_render_emit_draw_surface_states(struct ilo_render *render,
337 const struct ilo_state_vector *vec,
338 struct ilo_render_draw_session *session);
339
340 int
341 ilo_render_get_launch_grid_surface_states_len(const struct ilo_render *render,
342 const struct ilo_state_vector *vec);
343
344 void
345 ilo_render_emit_launch_grid_surface_states(struct ilo_render *render,
346 const struct ilo_state_vector *vec,
347 struct ilo_render_launch_grid_session *session);
348
349 /**
350 * A convenient wrapper for gen6_PIPE_CONTROL(). This should be enough for
351 * our needs everywhere except for queries.
352 */
353 static inline void
354 ilo_render_pipe_control(struct ilo_render *r, uint32_t dw1)
355 {
356 const uint32_t write_mask = (dw1 & GEN6_PIPE_CONTROL_WRITE__MASK);
357 struct intel_bo *bo = (write_mask) ? r->workaround_bo : NULL;
358
359 ILO_DEV_ASSERT(r->dev, 6, 8);
360
361 if (write_mask)
362 assert(write_mask == GEN6_PIPE_CONTROL_WRITE_IMM);
363
364 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
365 /* CS stall cannot be set alone */
366 const uint32_t mask = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
367 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
368 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
369 GEN6_PIPE_CONTROL_DEPTH_STALL |
370 GEN6_PIPE_CONTROL_WRITE__MASK;
371 if (!(dw1 & mask))
372 dw1 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
373 }
374
375 gen6_PIPE_CONTROL(r->builder, dw1, bo, 0, 0);
376
377 r->state.current_pipe_control_dw1 |= dw1;
378 r->state.deferred_pipe_control_dw1 &= ~dw1;
379 }
380
381 /**
382 * A convenient wrapper for gen{6,7}_3DPRIMITIVE().
383 */
384 static inline void
385 ilo_render_3dprimitive(struct ilo_render *r,
386 const struct pipe_draw_info *info,
387 const struct ilo_ib_state *ib)
388 {
389 ILO_DEV_ASSERT(r->dev, 6, 8);
390
391 if (r->state.deferred_pipe_control_dw1)
392 ilo_render_pipe_control(r, r->state.deferred_pipe_control_dw1);
393
394 /* 3DPRIMITIVE */
395 if (ilo_dev_gen(r->dev) >= ILO_GEN(7))
396 gen7_3DPRIMITIVE(r->builder, info, ib);
397 else
398 gen6_3DPRIMITIVE(r->builder, info, ib);
399
400 r->state.current_pipe_control_dw1 = 0;
401 assert(!r->state.deferred_pipe_control_dw1);
402 }
403
404 void
405 gen6_wa_pre_pipe_control(struct ilo_render *r, uint32_t dw1);
406
407 void
408 gen6_draw_common_select(struct ilo_render *r,
409 const struct ilo_state_vector *ilo,
410 struct ilo_render_draw_session *session);
411
412 void
413 gen6_draw_common_sip(struct ilo_render *r,
414 const struct ilo_state_vector *ilo,
415 struct ilo_render_draw_session *session);
416
417 void
418 gen6_draw_common_base_address(struct ilo_render *r,
419 const struct ilo_state_vector *ilo,
420 struct ilo_render_draw_session *session);
421
422 void
423 gen6_draw_vf(struct ilo_render *r,
424 const struct ilo_state_vector *ilo,
425 struct ilo_render_draw_session *session);
426
427 void
428 gen6_draw_vf_statistics(struct ilo_render *r,
429 const struct ilo_state_vector *ilo,
430 struct ilo_render_draw_session *session);
431
432 void
433 gen6_draw_vs(struct ilo_render *r,
434 const struct ilo_state_vector *ilo,
435 struct ilo_render_draw_session *session);
436
437 void
438 gen6_draw_clip(struct ilo_render *r,
439 const struct ilo_state_vector *ilo,
440 struct ilo_render_draw_session *session);
441
442 void
443 gen6_draw_sf_rect(struct ilo_render *r,
444 const struct ilo_state_vector *ilo,
445 struct ilo_render_draw_session *session);
446
447 void
448 gen6_draw_wm_raster(struct ilo_render *r,
449 const struct ilo_state_vector *ilo,
450 struct ilo_render_draw_session *session);
451
452 void
453 gen7_draw_common_pcb_alloc(struct ilo_render *r,
454 const struct ilo_state_vector *vec,
455 struct ilo_render_draw_session *session);
456
457 void
458 gen7_draw_common_pointers_1(struct ilo_render *r,
459 const struct ilo_state_vector *vec,
460 struct ilo_render_draw_session *session);
461
462 void
463 gen7_draw_common_urb(struct ilo_render *r,
464 const struct ilo_state_vector *vec,
465 struct ilo_render_draw_session *session);
466
467 void
468 gen7_draw_common_pointers_2(struct ilo_render *r,
469 const struct ilo_state_vector *vec,
470 struct ilo_render_draw_session *session);
471
472 void
473 gen7_draw_vs(struct ilo_render *r,
474 const struct ilo_state_vector *vec,
475 struct ilo_render_draw_session *session);
476
477 void
478 gen7_draw_ds(struct ilo_render *r,
479 const struct ilo_state_vector *vec,
480 struct ilo_render_draw_session *session);
481
482 void
483 gen7_draw_te(struct ilo_render *r,
484 const struct ilo_state_vector *vec,
485 struct ilo_render_draw_session *session);
486
487 void
488 gen7_draw_hs(struct ilo_render *r,
489 const struct ilo_state_vector *vec,
490 struct ilo_render_draw_session *session);
491
492 void
493 gen7_draw_gs(struct ilo_render *r,
494 const struct ilo_state_vector *vec,
495 struct ilo_render_draw_session *session);
496
497 void
498 gen7_draw_sol(struct ilo_render *r,
499 const struct ilo_state_vector *vec,
500 struct ilo_render_draw_session *session);
501
502 #endif /* ILO_RENDER_GEN_H */