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