gallium/radeon: add h264 performance HW decoder support
[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 struct ilo_state_sample_pattern sample_pattern;
55
56 bool hw_ctx_changed;
57
58 /*
59 * Any state that involves resources needs to be re-emitted when the
60 * batch bo changed. This is because we do not pin the resources and
61 * their offsets (or existence) may change between batch buffers.
62 */
63 bool batch_bo_changed;
64 bool state_bo_changed;
65 bool instruction_bo_changed;
66
67 /**
68 * HW states.
69 */
70 struct ilo_render_state {
71 /*
72 * When a WA is needed before some command, we always emit the WA right
73 * before the command. Knowing what have already been done since last
74 * 3DPRIMITIVE allows us to skip some WAs.
75 */
76 uint32_t current_pipe_control_dw1;
77
78 /*
79 * When a WA is needed after some command, we may have the WA follow the
80 * command immediately or defer it. If this is non-zero, a PIPE_CONTROL
81 * will be emitted before 3DPRIMITIVE.
82 */
83 uint32_t deferred_pipe_control_dw1;
84
85 int reduced_prim;
86 int so_max_vertices;
87
88 struct ilo_state_urb urb;
89 struct ilo_state_raster rs;
90 struct ilo_state_cc cc;
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
146 struct ilo_state_urb_delta urb_delta;
147 struct ilo_state_vf_delta vf_delta;
148 struct ilo_state_raster_delta rs_delta;
149 struct ilo_state_viewport_delta vp_delta;
150 struct ilo_state_cc_delta cc_delta;
151
152 /* dynamic states */
153 bool viewport_changed;
154 bool scissor_changed;
155
156 bool cc_changed;
157 bool dsa_changed;
158 bool blend_changed;
159
160 bool sampler_vs_changed;
161 bool sampler_gs_changed;
162 bool sampler_fs_changed;
163
164 bool pcb_vs_changed;
165 bool pcb_gs_changed;
166 bool pcb_fs_changed;
167
168 /* surface states */
169 bool binding_table_vs_changed;
170 bool binding_table_gs_changed;
171 bool binding_table_fs_changed;
172 };
173
174 struct ilo_render_rectlist_session {
175 uint32_t vb_start;
176 uint32_t vb_end;
177 };
178
179 struct ilo_render_launch_grid_session {
180 const unsigned *thread_group_offset;
181 const unsigned *thread_group_dim;
182 unsigned thread_group_size;
183 const struct pipe_constant_buffer *input;
184 uint32_t pc;
185
186 uint32_t idrt;
187 int idrt_size;
188
189 uint32_t compute_data[6];
190 struct ilo_state_compute compute;
191 };
192
193 int
194 ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
195 const struct ilo_state_vector *vec);
196
197 int
198 ilo_render_get_draw_commands_len_gen7(const struct ilo_render *render,
199 const struct ilo_state_vector *vec);
200
201 int
202 ilo_render_get_draw_commands_len_gen8(const struct ilo_render *render,
203 const struct ilo_state_vector *vec);
204
205 static inline int
206 ilo_render_get_draw_commands_len(const struct ilo_render *render,
207 const struct ilo_state_vector *vec)
208 {
209 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
210 return ilo_render_get_draw_commands_len_gen8(render, vec);
211 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
212 return ilo_render_get_draw_commands_len_gen7(render, vec);
213 else
214 return ilo_render_get_draw_commands_len_gen6(render, vec);
215 }
216
217 void
218 ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
219 const struct ilo_state_vector *vec,
220 struct ilo_render_draw_session *session);
221
222 void
223 ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
224 const struct ilo_state_vector *vec,
225 struct ilo_render_draw_session *session);
226
227 void
228 ilo_render_emit_draw_commands_gen8(struct ilo_render *render,
229 const struct ilo_state_vector *vec,
230 struct ilo_render_draw_session *session);
231
232 static inline void
233 ilo_render_emit_draw_commands(struct ilo_render *render,
234 const struct ilo_state_vector *vec,
235 struct ilo_render_draw_session *session)
236 {
237 const unsigned batch_used = ilo_builder_batch_used(render->builder);
238
239 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
240 ilo_render_emit_draw_commands_gen8(render, vec, session);
241 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
242 ilo_render_emit_draw_commands_gen7(render, vec, session);
243 else
244 ilo_render_emit_draw_commands_gen6(render, vec, session);
245
246 assert(ilo_builder_batch_used(render->builder) <= batch_used +
247 ilo_render_get_draw_commands_len(render, vec));
248 }
249
250 int
251 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render *render,
252 const struct ilo_blitter *blitter);
253
254 int
255 ilo_render_get_rectlist_commands_len_gen8(const struct ilo_render *render,
256 const struct ilo_blitter *blitter);
257
258 static inline int
259 ilo_render_get_rectlist_commands_len(const struct ilo_render *render,
260 const struct ilo_blitter *blitter)
261 {
262 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
263 return ilo_render_get_rectlist_commands_len_gen8(render, blitter);
264 else
265 return ilo_render_get_rectlist_commands_len_gen6(render, blitter);
266 }
267
268 void
269 ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
270 const struct ilo_blitter *blitter,
271 const struct ilo_render_rectlist_session *session);
272
273 void
274 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
275 const struct ilo_blitter *blitter,
276 const struct ilo_render_rectlist_session *session);
277
278 void
279 ilo_render_emit_rectlist_commands_gen8(struct ilo_render *r,
280 const struct ilo_blitter *blitter,
281 const struct ilo_render_rectlist_session *session);
282
283 static inline void
284 ilo_render_emit_rectlist_commands(struct ilo_render *render,
285 const struct ilo_blitter *blitter,
286 const struct ilo_render_rectlist_session *session)
287 {
288 const unsigned batch_used = ilo_builder_batch_used(render->builder);
289
290 if (ilo_dev_gen(render->dev) >= ILO_GEN(8))
291 ilo_render_emit_rectlist_commands_gen8(render, blitter, session);
292 else if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
293 ilo_render_emit_rectlist_commands_gen7(render, blitter, session);
294 else
295 ilo_render_emit_rectlist_commands_gen6(render, blitter, session);
296
297 assert(ilo_builder_batch_used(render->builder) <= batch_used +
298 ilo_render_get_rectlist_commands_len(render, blitter));
299 }
300
301 int
302 ilo_render_get_launch_grid_commands_len(const struct ilo_render *render,
303 const struct ilo_state_vector *vec);
304
305 void
306 ilo_render_emit_launch_grid_commands(struct ilo_render *render,
307 const struct ilo_state_vector *vec,
308 const struct ilo_render_launch_grid_session *session);
309
310 int
311 ilo_render_get_draw_dynamic_states_len(const struct ilo_render *render,
312 const struct ilo_state_vector *vec);
313
314 void
315 ilo_render_emit_draw_dynamic_states(struct ilo_render *render,
316 const struct ilo_state_vector *vec,
317 struct ilo_render_draw_session *session);
318
319 int
320 ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render *render,
321 const struct ilo_blitter *blitter);
322
323 void
324 ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
325 const struct ilo_blitter *blitter,
326 struct ilo_render_rectlist_session *session);
327
328 int
329 ilo_render_get_launch_grid_dynamic_states_len(const struct ilo_render *render,
330 const struct ilo_state_vector *vec);
331
332 void
333 ilo_render_emit_launch_grid_dynamic_states(struct ilo_render *render,
334 const struct ilo_state_vector *vec,
335 struct ilo_render_launch_grid_session *session);
336
337 int
338 ilo_render_get_draw_surface_states_len(const struct ilo_render *render,
339 const struct ilo_state_vector *vec);
340
341 void
342 ilo_render_emit_draw_surface_states(struct ilo_render *render,
343 const struct ilo_state_vector *vec,
344 struct ilo_render_draw_session *session);
345
346 int
347 ilo_render_get_launch_grid_surface_states_len(const struct ilo_render *render,
348 const struct ilo_state_vector *vec);
349
350 void
351 ilo_render_emit_launch_grid_surface_states(struct ilo_render *render,
352 const struct ilo_state_vector *vec,
353 struct ilo_render_launch_grid_session *session);
354
355 /**
356 * A convenient wrapper for gen6_PIPE_CONTROL(). This should be enough for
357 * our needs everywhere except for queries.
358 */
359 static inline void
360 ilo_render_pipe_control(struct ilo_render *r, uint32_t dw1)
361 {
362 const uint32_t write_mask = (dw1 & GEN6_PIPE_CONTROL_WRITE__MASK);
363 struct intel_bo *bo = (write_mask) ? r->workaround_bo : NULL;
364
365 ILO_DEV_ASSERT(r->dev, 6, 8);
366
367 if (write_mask)
368 assert(write_mask == GEN6_PIPE_CONTROL_WRITE_IMM);
369
370 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
371 /* CS stall cannot be set alone */
372 const uint32_t mask = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
373 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
374 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
375 GEN6_PIPE_CONTROL_DEPTH_STALL |
376 GEN6_PIPE_CONTROL_WRITE__MASK;
377 if (!(dw1 & mask))
378 dw1 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
379 }
380
381 gen6_PIPE_CONTROL(r->builder, dw1, bo, 0, 0);
382
383 r->state.current_pipe_control_dw1 |= dw1;
384 r->state.deferred_pipe_control_dw1 &= ~dw1;
385 }
386
387 /**
388 * A convenient wrapper for gen{6,7}_3DPRIMITIVE().
389 */
390 static inline void
391 ilo_render_3dprimitive(struct ilo_render *r,
392 const struct gen6_3dprimitive_info *info)
393 {
394 ILO_DEV_ASSERT(r->dev, 6, 8);
395
396 if (r->state.deferred_pipe_control_dw1)
397 ilo_render_pipe_control(r, r->state.deferred_pipe_control_dw1);
398
399 /* 3DPRIMITIVE */
400 if (ilo_dev_gen(r->dev) >= ILO_GEN(7))
401 gen7_3DPRIMITIVE(r->builder, info);
402 else
403 gen6_3DPRIMITIVE(r->builder, info);
404
405 r->state.current_pipe_control_dw1 = 0;
406 assert(!r->state.deferred_pipe_control_dw1);
407 }
408
409 void
410 gen6_wa_pre_pipe_control(struct ilo_render *r, uint32_t dw1);
411
412 void
413 gen6_draw_common_select(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_sip(struct ilo_render *r,
419 const struct ilo_state_vector *ilo,
420 struct ilo_render_draw_session *session);
421
422 void
423 gen6_draw_common_base_address(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(struct ilo_render *r,
429 const struct ilo_state_vector *ilo,
430 struct ilo_render_draw_session *session);
431
432 void
433 gen6_draw_vf_statistics(struct ilo_render *r,
434 const struct ilo_state_vector *ilo,
435 struct ilo_render_draw_session *session);
436
437 void
438 gen6_draw_vs(struct ilo_render *r,
439 const struct ilo_state_vector *ilo,
440 struct ilo_render_draw_session *session);
441
442 void
443 gen6_draw_clip(struct ilo_render *r,
444 const struct ilo_state_vector *ilo,
445 struct ilo_render_draw_session *session);
446
447 void
448 gen6_draw_sf_rect(struct ilo_render *r,
449 const struct ilo_state_vector *ilo,
450 struct ilo_render_draw_session *session);
451
452 void
453 gen6_draw_wm_raster(struct ilo_render *r,
454 const struct ilo_state_vector *ilo,
455 struct ilo_render_draw_session *session);
456
457 void
458 gen7_draw_common_pcb_alloc(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_pointers_1(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_urb(struct ilo_render *r,
469 const struct ilo_state_vector *vec,
470 struct ilo_render_draw_session *session);
471
472 void
473 gen7_draw_common_pointers_2(struct ilo_render *r,
474 const struct ilo_state_vector *vec,
475 struct ilo_render_draw_session *session);
476
477 void
478 gen7_draw_vs(struct ilo_render *r,
479 const struct ilo_state_vector *vec,
480 struct ilo_render_draw_session *session);
481
482 void
483 gen7_draw_ds(struct ilo_render *r,
484 const struct ilo_state_vector *vec,
485 struct ilo_render_draw_session *session);
486
487 void
488 gen7_draw_te(struct ilo_render *r,
489 const struct ilo_state_vector *vec,
490 struct ilo_render_draw_session *session);
491
492 void
493 gen7_draw_hs(struct ilo_render *r,
494 const struct ilo_state_vector *vec,
495 struct ilo_render_draw_session *session);
496
497 void
498 gen7_draw_gs(struct ilo_render *r,
499 const struct ilo_state_vector *vec,
500 struct ilo_render_draw_session *session);
501
502 void
503 gen7_draw_sol(struct ilo_render *r,
504 const struct ilo_state_vector *vec,
505 struct ilo_render_draw_session *session);
506
507 #endif /* ILO_RENDER_GEN_H */