2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
25 * Chia-I Wu <olv@lunarg.com>
28 #ifndef ILO_RENDER_GEN_H
29 #define ILO_RENDER_GEN_H
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"
41 struct ilo_state_vector
;
47 const struct ilo_dev
*dev
;
48 struct ilo_builder
*builder
;
50 struct intel_bo
*workaround_bo
;
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];
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.
65 bool batch_bo_changed
;
66 bool state_bo_changed
;
67 bool instruction_bo_changed
;
72 struct ilo_render_state
{
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.
78 uint32_t current_pipe_control_dw1
;
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.
85 uint32_t deferred_pipe_control_dw1
;
87 bool primitive_restart
;
92 uint32_t CLIP_VIEWPORT
;
93 uint32_t SF_CLIP_VIEWPORT
; /* GEN7+ */
96 uint32_t COLOR_CALC_STATE
;
98 uint32_t DEPTH_STENCIL_STATE
;
100 uint32_t SCISSOR_RECT
;
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
;
112 uint32_t BINDING_TABLE_STATE
;
113 uint32_t SURFACE_STATE
[ILO_MAX_SURFACES
];
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
;
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
;
137 struct ilo_render_draw_session
{
144 bool primitive_restart_changed
;
147 bool viewport_changed
;
148 bool scissor_changed
;
154 bool sampler_vs_changed
;
155 bool sampler_gs_changed
;
156 bool sampler_fs_changed
;
163 bool binding_table_vs_changed
;
164 bool binding_table_gs_changed
;
165 bool binding_table_fs_changed
;
168 struct ilo_render_rectlist_session
{
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
;
185 ilo_render_get_draw_commands_len_gen6(const struct ilo_render
*render
,
186 const struct ilo_state_vector
*vec
);
189 ilo_render_get_draw_commands_len_gen7(const struct ilo_render
*render
,
190 const struct ilo_state_vector
*vec
);
193 ilo_render_get_draw_commands_len_gen8(const struct ilo_render
*render
,
194 const struct ilo_state_vector
*vec
);
197 ilo_render_get_draw_commands_len(const struct ilo_render
*render
,
198 const struct ilo_state_vector
*vec
)
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
);
205 return ilo_render_get_draw_commands_len_gen6(render
, vec
);
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
);
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
);
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
);
224 ilo_render_emit_draw_commands(struct ilo_render
*render
,
225 const struct ilo_state_vector
*vec
,
226 struct ilo_render_draw_session
*session
)
228 const unsigned batch_used
= ilo_builder_batch_used(render
->builder
);
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
);
235 ilo_render_emit_draw_commands_gen6(render
, vec
, session
);
237 assert(ilo_builder_batch_used(render
->builder
) <= batch_used
+
238 ilo_render_get_draw_commands_len(render
, vec
));
242 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render
*render
,
243 const struct ilo_blitter
*blitter
);
246 ilo_render_get_rectlist_commands_len_gen8(const struct ilo_render
*render
,
247 const struct ilo_blitter
*blitter
);
250 ilo_render_get_rectlist_commands_len(const struct ilo_render
*render
,
251 const struct ilo_blitter
*blitter
)
253 if (ilo_dev_gen(render
->dev
) >= ILO_GEN(8))
254 return ilo_render_get_rectlist_commands_len_gen8(render
, blitter
);
256 return ilo_render_get_rectlist_commands_len_gen6(render
, blitter
);
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
);
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
);
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
);
275 ilo_render_emit_rectlist_commands(struct ilo_render
*render
,
276 const struct ilo_blitter
*blitter
,
277 const struct ilo_render_rectlist_session
*session
)
279 const unsigned batch_used
= ilo_builder_batch_used(render
->builder
);
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
);
286 ilo_render_emit_rectlist_commands_gen6(render
, blitter
, session
);
288 assert(ilo_builder_batch_used(render
->builder
) <= batch_used
+
289 ilo_render_get_rectlist_commands_len(render
, blitter
));
293 ilo_render_get_launch_grid_commands_len(const struct ilo_render
*render
,
294 const struct ilo_state_vector
*vec
);
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
);
302 ilo_render_get_draw_dynamic_states_len(const struct ilo_render
*render
,
303 const struct ilo_state_vector
*vec
);
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
);
311 ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render
*render
,
312 const struct ilo_blitter
*blitter
);
315 ilo_render_emit_rectlist_dynamic_states(struct ilo_render
*render
,
316 const struct ilo_blitter
*blitter
,
317 struct ilo_render_rectlist_session
*session
);
320 ilo_render_get_launch_grid_dynamic_states_len(const struct ilo_render
*render
,
321 const struct ilo_state_vector
*vec
);
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
);
329 ilo_render_get_draw_surface_states_len(const struct ilo_render
*render
,
330 const struct ilo_state_vector
*vec
);
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
);
338 ilo_render_get_launch_grid_surface_states_len(const struct ilo_render
*render
,
339 const struct ilo_state_vector
*vec
);
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
);
347 * A convenient wrapper for gen6_PIPE_CONTROL(). This should be enough for
348 * our needs everywhere except for queries.
351 ilo_render_pipe_control(struct ilo_render
*r
, uint32_t dw1
)
353 const uint32_t write_mask
= (dw1
& GEN6_PIPE_CONTROL_WRITE__MASK
);
354 struct intel_bo
*bo
= (write_mask
) ? r
->workaround_bo
: NULL
;
356 ILO_DEV_ASSERT(r
->dev
, 6, 8);
359 assert(write_mask
== GEN6_PIPE_CONTROL_WRITE_IMM
);
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
;
369 dw1
|= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL
;
372 gen6_PIPE_CONTROL(r
->builder
, dw1
, bo
, 0, 0);
374 r
->state
.current_pipe_control_dw1
|= dw1
;
375 r
->state
.deferred_pipe_control_dw1
&= ~dw1
;
379 * A convenient wrapper for gen{6,7}_3DPRIMITIVE().
382 ilo_render_3dprimitive(struct ilo_render
*r
,
383 const struct pipe_draw_info
*info
,
384 const struct ilo_ib_state
*ib
)
386 ILO_DEV_ASSERT(r
->dev
, 6, 8);
388 if (r
->state
.deferred_pipe_control_dw1
)
389 ilo_render_pipe_control(r
, r
->state
.deferred_pipe_control_dw1
);
392 if (ilo_dev_gen(r
->dev
) >= ILO_GEN(7))
393 gen7_3DPRIMITIVE(r
->builder
, info
, ib
);
395 gen6_3DPRIMITIVE(r
->builder
, info
, ib
);
397 r
->state
.current_pipe_control_dw1
= 0;
398 assert(!r
->state
.deferred_pipe_control_dw1
);
402 gen6_wa_pre_pipe_control(struct ilo_render
*r
, uint32_t dw1
);
405 gen6_draw_common_select(struct ilo_render
*r
,
406 const struct ilo_state_vector
*ilo
,
407 struct ilo_render_draw_session
*session
);
410 gen6_draw_common_sip(struct ilo_render
*r
,
411 const struct ilo_state_vector
*ilo
,
412 struct ilo_render_draw_session
*session
);
415 gen6_draw_common_base_address(struct ilo_render
*r
,
416 const struct ilo_state_vector
*ilo
,
417 struct ilo_render_draw_session
*session
);
420 gen6_draw_vf(struct ilo_render
*r
,
421 const struct ilo_state_vector
*ilo
,
422 struct ilo_render_draw_session
*session
);
425 gen6_draw_vf_statistics(struct ilo_render
*r
,
426 const struct ilo_state_vector
*ilo
,
427 struct ilo_render_draw_session
*session
);
430 gen6_draw_vs(struct ilo_render
*r
,
431 const struct ilo_state_vector
*ilo
,
432 struct ilo_render_draw_session
*session
);
435 gen6_draw_clip(struct ilo_render
*r
,
436 const struct ilo_state_vector
*ilo
,
437 struct ilo_render_draw_session
*session
);
440 gen6_draw_sf_rect(struct ilo_render
*r
,
441 const struct ilo_state_vector
*ilo
,
442 struct ilo_render_draw_session
*session
);
445 gen6_draw_wm_raster(struct ilo_render
*r
,
446 const struct ilo_state_vector
*ilo
,
447 struct ilo_render_draw_session
*session
);
450 gen7_draw_common_pcb_alloc(struct ilo_render
*r
,
451 const struct ilo_state_vector
*vec
,
452 struct ilo_render_draw_session
*session
);
455 gen7_draw_common_pointers_1(struct ilo_render
*r
,
456 const struct ilo_state_vector
*vec
,
457 struct ilo_render_draw_session
*session
);
460 gen7_draw_common_urb(struct ilo_render
*r
,
461 const struct ilo_state_vector
*vec
,
462 struct ilo_render_draw_session
*session
);
465 gen7_draw_common_pointers_2(struct ilo_render
*r
,
466 const struct ilo_state_vector
*vec
,
467 struct ilo_render_draw_session
*session
);
470 gen7_draw_vs(struct ilo_render
*r
,
471 const struct ilo_state_vector
*vec
,
472 struct ilo_render_draw_session
*session
);
475 gen7_draw_ds(struct ilo_render
*r
,
476 const struct ilo_state_vector
*vec
,
477 struct ilo_render_draw_session
*session
);
480 gen7_draw_te(struct ilo_render
*r
,
481 const struct ilo_state_vector
*vec
,
482 struct ilo_render_draw_session
*session
);
485 gen7_draw_hs(struct ilo_render
*r
,
486 const struct ilo_state_vector
*vec
,
487 struct ilo_render_draw_session
*session
);
490 gen7_draw_gs(struct ilo_render
*r
,
491 const struct ilo_state_vector
*vec
,
492 struct ilo_render_draw_session
*session
);
495 gen7_draw_sol(struct ilo_render
*r
,
496 const struct ilo_state_vector
*vec
,
497 struct ilo_render_draw_session
*session
);
499 #endif /* ILO_RENDER_GEN_H */