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 "core/ilo_builder.h"
32 #include "core/ilo_builder_3d.h"
33 #include "core/ilo_builder_render.h"
35 #include "ilo_common.h"
36 #include "ilo_state.h"
37 #include "ilo_render.h"
42 struct ilo_state_vector
;
48 const struct ilo_dev
*dev
;
49 struct ilo_builder
*builder
;
51 struct intel_bo
*workaround_bo
;
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];
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.
66 bool batch_bo_changed
;
67 bool state_bo_changed
;
68 bool instruction_bo_changed
;
73 struct ilo_render_state
{
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.
79 uint32_t current_pipe_control_dw1
;
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.
86 uint32_t deferred_pipe_control_dw1
;
88 bool primitive_restart
;
93 uint32_t CLIP_VIEWPORT
;
94 uint32_t SF_CLIP_VIEWPORT
; /* GEN7+ */
97 uint32_t COLOR_CALC_STATE
;
99 uint32_t DEPTH_STENCIL_STATE
;
101 uint32_t SCISSOR_RECT
;
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
;
113 uint32_t BINDING_TABLE_STATE
;
114 uint32_t SURFACE_STATE
[ILO_MAX_SURFACES
];
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
;
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
;
138 struct ilo_render_draw_session
{
145 bool primitive_restart_changed
;
147 struct ilo_state_viewport_delta vp_delta
;
150 bool viewport_changed
;
151 bool scissor_changed
;
157 bool sampler_vs_changed
;
158 bool sampler_gs_changed
;
159 bool sampler_fs_changed
;
166 bool binding_table_vs_changed
;
167 bool binding_table_gs_changed
;
168 bool binding_table_fs_changed
;
171 struct ilo_render_rectlist_session
{
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
;
188 ilo_render_get_draw_commands_len_gen6(const struct ilo_render
*render
,
189 const struct ilo_state_vector
*vec
);
192 ilo_render_get_draw_commands_len_gen7(const struct ilo_render
*render
,
193 const struct ilo_state_vector
*vec
);
196 ilo_render_get_draw_commands_len_gen8(const struct ilo_render
*render
,
197 const struct ilo_state_vector
*vec
);
200 ilo_render_get_draw_commands_len(const struct ilo_render
*render
,
201 const struct ilo_state_vector
*vec
)
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
);
208 return ilo_render_get_draw_commands_len_gen6(render
, vec
);
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
);
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
);
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
);
227 ilo_render_emit_draw_commands(struct ilo_render
*render
,
228 const struct ilo_state_vector
*vec
,
229 struct ilo_render_draw_session
*session
)
231 const unsigned batch_used
= ilo_builder_batch_used(render
->builder
);
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
);
238 ilo_render_emit_draw_commands_gen6(render
, vec
, session
);
240 assert(ilo_builder_batch_used(render
->builder
) <= batch_used
+
241 ilo_render_get_draw_commands_len(render
, vec
));
245 ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render
*render
,
246 const struct ilo_blitter
*blitter
);
249 ilo_render_get_rectlist_commands_len_gen8(const struct ilo_render
*render
,
250 const struct ilo_blitter
*blitter
);
253 ilo_render_get_rectlist_commands_len(const struct ilo_render
*render
,
254 const struct ilo_blitter
*blitter
)
256 if (ilo_dev_gen(render
->dev
) >= ILO_GEN(8))
257 return ilo_render_get_rectlist_commands_len_gen8(render
, blitter
);
259 return ilo_render_get_rectlist_commands_len_gen6(render
, blitter
);
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
);
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
);
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
);
278 ilo_render_emit_rectlist_commands(struct ilo_render
*render
,
279 const struct ilo_blitter
*blitter
,
280 const struct ilo_render_rectlist_session
*session
)
282 const unsigned batch_used
= ilo_builder_batch_used(render
->builder
);
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
);
289 ilo_render_emit_rectlist_commands_gen6(render
, blitter
, session
);
291 assert(ilo_builder_batch_used(render
->builder
) <= batch_used
+
292 ilo_render_get_rectlist_commands_len(render
, blitter
));
296 ilo_render_get_launch_grid_commands_len(const struct ilo_render
*render
,
297 const struct ilo_state_vector
*vec
);
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
);
305 ilo_render_get_draw_dynamic_states_len(const struct ilo_render
*render
,
306 const struct ilo_state_vector
*vec
);
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
);
314 ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render
*render
,
315 const struct ilo_blitter
*blitter
);
318 ilo_render_emit_rectlist_dynamic_states(struct ilo_render
*render
,
319 const struct ilo_blitter
*blitter
,
320 struct ilo_render_rectlist_session
*session
);
323 ilo_render_get_launch_grid_dynamic_states_len(const struct ilo_render
*render
,
324 const struct ilo_state_vector
*vec
);
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
);
332 ilo_render_get_draw_surface_states_len(const struct ilo_render
*render
,
333 const struct ilo_state_vector
*vec
);
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
);
341 ilo_render_get_launch_grid_surface_states_len(const struct ilo_render
*render
,
342 const struct ilo_state_vector
*vec
);
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
);
350 * A convenient wrapper for gen6_PIPE_CONTROL(). This should be enough for
351 * our needs everywhere except for queries.
354 ilo_render_pipe_control(struct ilo_render
*r
, uint32_t dw1
)
356 const uint32_t write_mask
= (dw1
& GEN6_PIPE_CONTROL_WRITE__MASK
);
357 struct intel_bo
*bo
= (write_mask
) ? r
->workaround_bo
: NULL
;
359 ILO_DEV_ASSERT(r
->dev
, 6, 8);
362 assert(write_mask
== GEN6_PIPE_CONTROL_WRITE_IMM
);
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
;
372 dw1
|= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL
;
375 gen6_PIPE_CONTROL(r
->builder
, dw1
, bo
, 0, 0);
377 r
->state
.current_pipe_control_dw1
|= dw1
;
378 r
->state
.deferred_pipe_control_dw1
&= ~dw1
;
382 * A convenient wrapper for gen{6,7}_3DPRIMITIVE().
385 ilo_render_3dprimitive(struct ilo_render
*r
,
386 const struct pipe_draw_info
*info
,
387 const struct ilo_ib_state
*ib
)
389 ILO_DEV_ASSERT(r
->dev
, 6, 8);
391 if (r
->state
.deferred_pipe_control_dw1
)
392 ilo_render_pipe_control(r
, r
->state
.deferred_pipe_control_dw1
);
395 if (ilo_dev_gen(r
->dev
) >= ILO_GEN(7))
396 gen7_3DPRIMITIVE(r
->builder
, info
, ib
);
398 gen6_3DPRIMITIVE(r
->builder
, info
, ib
);
400 r
->state
.current_pipe_control_dw1
= 0;
401 assert(!r
->state
.deferred_pipe_control_dw1
);
405 gen6_wa_pre_pipe_control(struct ilo_render
*r
, uint32_t dw1
);
408 gen6_draw_common_select(struct ilo_render
*r
,
409 const struct ilo_state_vector
*ilo
,
410 struct ilo_render_draw_session
*session
);
413 gen6_draw_common_sip(struct ilo_render
*r
,
414 const struct ilo_state_vector
*ilo
,
415 struct ilo_render_draw_session
*session
);
418 gen6_draw_common_base_address(struct ilo_render
*r
,
419 const struct ilo_state_vector
*ilo
,
420 struct ilo_render_draw_session
*session
);
423 gen6_draw_vf(struct ilo_render
*r
,
424 const struct ilo_state_vector
*ilo
,
425 struct ilo_render_draw_session
*session
);
428 gen6_draw_vf_statistics(struct ilo_render
*r
,
429 const struct ilo_state_vector
*ilo
,
430 struct ilo_render_draw_session
*session
);
433 gen6_draw_vs(struct ilo_render
*r
,
434 const struct ilo_state_vector
*ilo
,
435 struct ilo_render_draw_session
*session
);
438 gen6_draw_clip(struct ilo_render
*r
,
439 const struct ilo_state_vector
*ilo
,
440 struct ilo_render_draw_session
*session
);
443 gen6_draw_sf_rect(struct ilo_render
*r
,
444 const struct ilo_state_vector
*ilo
,
445 struct ilo_render_draw_session
*session
);
448 gen6_draw_wm_raster(struct ilo_render
*r
,
449 const struct ilo_state_vector
*ilo
,
450 struct ilo_render_draw_session
*session
);
453 gen7_draw_common_pcb_alloc(struct ilo_render
*r
,
454 const struct ilo_state_vector
*vec
,
455 struct ilo_render_draw_session
*session
);
458 gen7_draw_common_pointers_1(struct ilo_render
*r
,
459 const struct ilo_state_vector
*vec
,
460 struct ilo_render_draw_session
*session
);
463 gen7_draw_common_urb(struct ilo_render
*r
,
464 const struct ilo_state_vector
*vec
,
465 struct ilo_render_draw_session
*session
);
468 gen7_draw_common_pointers_2(struct ilo_render
*r
,
469 const struct ilo_state_vector
*vec
,
470 struct ilo_render_draw_session
*session
);
473 gen7_draw_vs(struct ilo_render
*r
,
474 const struct ilo_state_vector
*vec
,
475 struct ilo_render_draw_session
*session
);
478 gen7_draw_ds(struct ilo_render
*r
,
479 const struct ilo_state_vector
*vec
,
480 struct ilo_render_draw_session
*session
);
483 gen7_draw_te(struct ilo_render
*r
,
484 const struct ilo_state_vector
*vec
,
485 struct ilo_render_draw_session
*session
);
488 gen7_draw_hs(struct ilo_render
*r
,
489 const struct ilo_state_vector
*vec
,
490 struct ilo_render_draw_session
*session
);
493 gen7_draw_gs(struct ilo_render
*r
,
494 const struct ilo_state_vector
*vec
,
495 struct ilo_render_draw_session
*session
);
498 gen7_draw_sol(struct ilo_render
*r
,
499 const struct ilo_state_vector
*vec
,
500 struct ilo_render_draw_session
*session
);
502 #endif /* ILO_RENDER_GEN_H */