2 * Mesa 3-D graphics library
4 * Copyright (C) 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 #include "genhw/genhw.h"
29 #include "util/u_dual_blend.h"
31 #include "ilo_blitter.h"
32 #include "ilo_builder_3d.h"
33 #include "ilo_builder_render.h"
34 #include "ilo_shader.h"
35 #include "ilo_state.h"
36 #include "ilo_render.h"
37 #include "ilo_render_gen.h"
38 #include "ilo_render_gen7.h"
41 * A wrapper for gen6_PIPE_CONTROL().
44 gen7_pipe_control(struct ilo_render
*r
, uint32_t dw1
)
46 struct intel_bo
*bo
= (dw1
& GEN6_PIPE_CONTROL_WRITE__MASK
) ?
47 r
->workaround_bo
: NULL
;
49 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
51 if (dw1
& GEN6_PIPE_CONTROL_CS_STALL
) {
52 /* CS stall cannot be set alone */
53 const uint32_t mask
= GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH
|
54 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
55 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL
|
56 GEN6_PIPE_CONTROL_DEPTH_STALL
|
57 GEN6_PIPE_CONTROL_WRITE__MASK
;
59 dw1
|= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL
;
62 gen6_PIPE_CONTROL(r
->builder
, dw1
, bo
, 0, false);
65 r
->state
.current_pipe_control_dw1
|= dw1
;
66 r
->state
.deferred_pipe_control_dw1
&= ~dw1
;
70 gen7_wa_post_3dstate_push_constant_alloc_ps(struct ilo_render
*r
)
73 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
75 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
76 * in the ring after this instruction
77 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
79 const uint32_t dw1
= GEN6_PIPE_CONTROL_CS_STALL
;
81 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
83 r
->state
.deferred_pipe_control_dw1
|= dw1
;
87 gen7_wa_pre_vs(struct ilo_render
*r
)
90 * From the Ivy Bridge PRM, volume 2 part 1, page 106:
92 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
93 * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
94 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
95 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
96 * needs to be sent before any combination of VS associated 3DSTATE."
98 const uint32_t dw1
= GEN6_PIPE_CONTROL_DEPTH_STALL
|
99 GEN6_PIPE_CONTROL_WRITE_IMM
;
101 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
103 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
104 gen7_pipe_control(r
, dw1
);
108 gen7_wa_pre_3dstate_sf_depth_bias(struct ilo_render
*r
)
111 * From the Ivy Bridge PRM, volume 2 part 1, page 258:
113 * "Due to an HW issue driver needs to send a pipe control with stall
114 * when ever there is state change in depth bias related state (in
117 const uint32_t dw1
= GEN6_PIPE_CONTROL_CS_STALL
;
119 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
121 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
122 gen7_pipe_control(r
, dw1
);
126 gen7_wa_pre_3dstate_multisample(struct ilo_render
*r
)
129 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
131 * "Driver must ierarchi that all the caches in the depth pipe are
132 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
133 * requires driver to send a PIPE_CONTROL with a CS stall along with a
134 * Depth Flush prior to this command.
136 const uint32_t dw1
= GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
137 GEN6_PIPE_CONTROL_CS_STALL
;
139 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
141 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
142 gen7_pipe_control(r
, dw1
);
146 gen7_wa_pre_depth(struct ilo_render
*r
)
149 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
151 * "Driver must send a least one PIPE_CONTROL command with CS Stall and
152 * a post sync operation prior to the group of depth
153 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
154 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
156 const uint32_t dw1
= GEN6_PIPE_CONTROL_CS_STALL
|
157 GEN6_PIPE_CONTROL_WRITE_IMM
;
159 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
161 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
162 gen7_pipe_control(r
, dw1
);
165 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
167 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
168 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
169 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
170 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
171 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
172 * Depth Flush Bit set, followed by another pipelined depth stall
173 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
174 * guarantee that the pipeline from WM onwards is already flushed
175 * (e.g., via a preceding MI_FLUSH)."
177 gen7_pipe_control(r
, GEN6_PIPE_CONTROL_DEPTH_STALL
);
178 gen7_pipe_control(r
, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
);
179 gen7_pipe_control(r
, GEN6_PIPE_CONTROL_DEPTH_STALL
);
183 gen7_wa_pre_3dstate_ps_max_threads(struct ilo_render
*r
)
186 * From the Ivy Bridge PRM, volume 2 part 1, page 286:
188 * "If this field (Maximum Number of Threads in 3DSTATE_PS) is changed
189 * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at
190 * Pixel Scoreboard set is required to be issued."
192 const uint32_t dw1
= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL
;
194 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
196 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
197 gen7_pipe_control(r
, dw1
);
201 gen7_wa_post_ps_and_later(struct ilo_render
*r
)
204 * From the Ivy Bridge PRM, volume 2 part 1, page 276:
206 * "The driver must make sure a PIPE_CONTROL with the Depth Stall
207 * Enable bit set after all the following states are programmed:
210 * - 3DSTATE_VIEWPORT_STATE_POINTERS_CC
211 * - 3DSTATE_CONSTANT_PS
212 * - 3DSTATE_BINDING_TABLE_POINTERS_PS
213 * - 3DSTATE_SAMPLER_STATE_POINTERS_PS
214 * - 3DSTATE_CC_STATE_POINTERS
215 * - 3DSTATE_BLEND_STATE_POINTERS
216 * - 3DSTATE_DEPTH_STENCIL_STATE_POINTERS"
218 const uint32_t dw1
= GEN6_PIPE_CONTROL_DEPTH_STALL
;
220 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
222 r
->state
.deferred_pipe_control_dw1
|= dw1
;
225 #define DIRTY(state) (session->pipe_dirty & ILO_DIRTY_ ## state)
228 gen7_draw_common_urb(struct ilo_render
*r
,
229 const struct ilo_state_vector
*vec
,
230 struct gen6_draw_session
*session
)
232 /* 3DSTATE_URB_{VS,GS,HS,DS} */
233 if (DIRTY(VE
) || DIRTY(VS
)) {
234 /* the first 16KB are reserved for VS and PS PCBs */
235 const int offset
= (ilo_dev_gen(r
->dev
) == ILO_GEN(7.5) &&
236 r
->dev
->gt
== 3) ? 32768 : 16384;
237 int vs_entry_size
, vs_total_size
;
239 vs_entry_size
= (vec
->vs
) ?
240 ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_OUTPUT_COUNT
) : 0;
243 * From the Ivy Bridge PRM, volume 2 part 1, page 35:
245 * "Programming Restriction: As the VS URB entry serves as both the
246 * per-vertex input and output of the VS shader, the VS URB
247 * Allocation Size must be sized to the maximum of the vertex input
248 * and output structures."
250 if (vs_entry_size
< vec
->ve
->count
)
251 vs_entry_size
= vec
->ve
->count
;
253 vs_entry_size
*= sizeof(float) * 4;
254 vs_total_size
= r
->dev
->urb_size
- offset
;
258 gen7_3DSTATE_URB_VS(r
->builder
,
259 offset
, vs_total_size
, vs_entry_size
);
261 gen7_3DSTATE_URB_GS(r
->builder
, offset
, 0, 0);
262 gen7_3DSTATE_URB_HS(r
->builder
, offset
, 0, 0);
263 gen7_3DSTATE_URB_DS(r
->builder
, offset
, 0, 0);
268 gen7_draw_common_pcb_alloc(struct ilo_render
*r
,
269 const struct ilo_state_vector
*vec
,
270 struct gen6_draw_session
*session
)
272 /* 3DSTATE_PUSH_CONSTANT_ALLOC_{VS,PS} */
273 if (r
->hw_ctx_changed
) {
275 * Push constant buffers are only allowed to take up at most the first
276 * 16KB of the URB. Split the space evenly for VS and FS.
278 const int max_size
= (ilo_dev_gen(r
->dev
) == ILO_GEN(7.5) &&
279 r
->dev
->gt
== 3) ? 32768 : 16384;
280 const int size
= max_size
/ 2;
283 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(r
->builder
, offset
, size
);
286 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(r
->builder
, offset
, size
);
288 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7))
289 gen7_wa_post_3dstate_push_constant_alloc_ps(r
);
294 gen7_draw_common_pointers_1(struct ilo_render
*r
,
295 const struct ilo_state_vector
*vec
,
296 struct gen6_draw_session
*session
)
298 /* 3DSTATE_VIEWPORT_STATE_POINTERS_{CC,SF_CLIP} */
299 if (session
->viewport_state_changed
) {
300 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(r
->builder
,
301 r
->state
.CC_VIEWPORT
);
303 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(r
->builder
,
304 r
->state
.SF_CLIP_VIEWPORT
);
309 gen7_draw_common_pointers_2(struct ilo_render
*r
,
310 const struct ilo_state_vector
*vec
,
311 struct gen6_draw_session
*session
)
313 /* 3DSTATE_BLEND_STATE_POINTERS */
314 if (session
->cc_state_blend_changed
) {
315 gen7_3DSTATE_BLEND_STATE_POINTERS(r
->builder
,
316 r
->state
.BLEND_STATE
);
319 /* 3DSTATE_CC_STATE_POINTERS */
320 if (session
->cc_state_cc_changed
) {
321 gen7_3DSTATE_CC_STATE_POINTERS(r
->builder
,
322 r
->state
.COLOR_CALC_STATE
);
325 /* 3DSTATE_DEPTH_STENCIL_STATE_POINTERS */
326 if (session
->cc_state_dsa_changed
) {
327 gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(r
->builder
,
328 r
->state
.DEPTH_STENCIL_STATE
);
333 gen7_draw_vs(struct ilo_render
*r
,
334 const struct ilo_state_vector
*vec
,
335 struct gen6_draw_session
*session
)
337 const bool emit_3dstate_binding_table
= session
->binding_table_vs_changed
;
338 const bool emit_3dstate_sampler_state
= session
->sampler_state_vs_changed
;
339 /* see gen6_draw_vs() */
340 const bool emit_3dstate_constant_vs
= session
->pcb_state_vs_changed
;
341 const bool emit_3dstate_vs
= (DIRTY(VS
) || DIRTY(SAMPLER_VS
) ||
342 r
->instruction_bo_changed
);
344 /* emit depth stall before any of the VS commands */
345 if (emit_3dstate_binding_table
|| emit_3dstate_sampler_state
||
346 emit_3dstate_constant_vs
|| emit_3dstate_vs
)
349 /* 3DSTATE_BINDING_TABLE_POINTERS_VS */
350 if (emit_3dstate_binding_table
) {
351 gen7_3DSTATE_BINDING_TABLE_POINTERS_VS(r
->builder
,
352 r
->state
.vs
.BINDING_TABLE_STATE
);
355 /* 3DSTATE_SAMPLER_STATE_POINTERS_VS */
356 if (emit_3dstate_sampler_state
) {
357 gen7_3DSTATE_SAMPLER_STATE_POINTERS_VS(r
->builder
,
358 r
->state
.vs
.SAMPLER_STATE
);
361 /* 3DSTATE_CONSTANT_VS */
362 if (emit_3dstate_constant_vs
) {
363 gen7_3DSTATE_CONSTANT_VS(r
->builder
,
364 &r
->state
.vs
.PUSH_CONSTANT_BUFFER
,
365 &r
->state
.vs
.PUSH_CONSTANT_BUFFER_size
,
370 if (emit_3dstate_vs
) {
371 const int num_samplers
= vec
->sampler
[PIPE_SHADER_VERTEX
].count
;
373 gen6_3DSTATE_VS(r
->builder
, vec
->vs
, num_samplers
);
378 gen7_draw_hs(struct ilo_render
*r
,
379 const struct ilo_state_vector
*vec
,
380 struct gen6_draw_session
*session
)
382 /* 3DSTATE_CONSTANT_HS and 3DSTATE_HS */
383 if (r
->hw_ctx_changed
) {
384 gen7_3DSTATE_CONSTANT_HS(r
->builder
, 0, 0, 0);
385 gen7_3DSTATE_HS(r
->builder
, NULL
, 0);
388 /* 3DSTATE_BINDING_TABLE_POINTERS_HS */
389 if (r
->hw_ctx_changed
)
390 gen7_3DSTATE_BINDING_TABLE_POINTERS_HS(r
->builder
, 0);
394 gen7_draw_te(struct ilo_render
*r
,
395 const struct ilo_state_vector
*vec
,
396 struct gen6_draw_session
*session
)
399 if (r
->hw_ctx_changed
)
400 gen7_3DSTATE_TE(r
->builder
);
404 gen7_draw_ds(struct ilo_render
*r
,
405 const struct ilo_state_vector
*vec
,
406 struct gen6_draw_session
*session
)
408 /* 3DSTATE_CONSTANT_DS and 3DSTATE_DS */
409 if (r
->hw_ctx_changed
) {
410 gen7_3DSTATE_CONSTANT_DS(r
->builder
, 0, 0, 0);
411 gen7_3DSTATE_DS(r
->builder
, NULL
, 0);
414 /* 3DSTATE_BINDING_TABLE_POINTERS_DS */
415 if (r
->hw_ctx_changed
)
416 gen7_3DSTATE_BINDING_TABLE_POINTERS_DS(r
->builder
, 0);
421 gen7_draw_gs(struct ilo_render
*r
,
422 const struct ilo_state_vector
*vec
,
423 struct gen6_draw_session
*session
)
425 /* 3DSTATE_CONSTANT_GS and 3DSTATE_GS */
426 if (r
->hw_ctx_changed
) {
427 gen7_3DSTATE_CONSTANT_GS(r
->builder
, 0, 0, 0);
428 gen7_3DSTATE_GS(r
->builder
, NULL
, 0);
431 /* 3DSTATE_BINDING_TABLE_POINTERS_GS */
432 if (session
->binding_table_gs_changed
) {
433 gen7_3DSTATE_BINDING_TABLE_POINTERS_GS(r
->builder
,
434 r
->state
.gs
.BINDING_TABLE_STATE
);
439 gen7_draw_sol(struct ilo_render
*r
,
440 const struct ilo_state_vector
*vec
,
441 struct gen6_draw_session
*session
)
443 const struct pipe_stream_output_info
*so_info
;
444 const struct ilo_shader_state
*shader
;
445 bool dirty_sh
= false;
449 dirty_sh
= DIRTY(GS
);
453 dirty_sh
= DIRTY(VS
);
456 so_info
= ilo_shader_get_kernel_so_info(shader
);
458 /* 3DSTATE_SO_BUFFER */
459 if ((DIRTY(SO
) || dirty_sh
|| r
->batch_bo_changed
) &&
463 for (i
= 0; i
< vec
->so
.count
; i
++) {
464 const int stride
= so_info
->stride
[i
] * 4; /* in bytes */
467 gen7_3DSTATE_SO_BUFFER(r
->builder
, i
, base
, stride
,
472 gen7_3DSTATE_SO_BUFFER(r
->builder
, i
, 0, 0, NULL
);
475 /* 3DSTATE_SO_DECL_LIST */
476 if (dirty_sh
&& vec
->so
.enabled
)
477 gen7_3DSTATE_SO_DECL_LIST(r
->builder
, so_info
);
479 /* 3DSTATE_STREAMOUT */
480 if (DIRTY(SO
) || DIRTY(RASTERIZER
) || dirty_sh
) {
481 const unsigned buffer_mask
= (1 << vec
->so
.count
) - 1;
482 const int output_count
= ilo_shader_get_kernel_param(shader
,
483 ILO_KERNEL_OUTPUT_COUNT
);
485 gen7_3DSTATE_STREAMOUT(r
->builder
, buffer_mask
, output_count
,
486 vec
->rasterizer
->state
.rasterizer_discard
);
491 gen7_draw_sf(struct ilo_render
*r
,
492 const struct ilo_state_vector
*vec
,
493 struct gen6_draw_session
*session
)
496 if (DIRTY(RASTERIZER
) || DIRTY(FS
))
497 gen7_3DSTATE_SBE(r
->builder
, vec
->rasterizer
, vec
->fs
);
500 if (DIRTY(RASTERIZER
) || DIRTY(FB
)) {
501 struct pipe_surface
*zs
= vec
->fb
.state
.zsbuf
;
503 gen7_wa_pre_3dstate_sf_depth_bias(r
);
504 gen7_3DSTATE_SF(r
->builder
, vec
->rasterizer
,
505 (zs
) ? zs
->format
: PIPE_FORMAT_NONE
);
510 gen7_draw_wm(struct ilo_render
*r
,
511 const struct ilo_state_vector
*vec
,
512 struct gen6_draw_session
*session
)
515 if (DIRTY(FS
) || DIRTY(BLEND
) || DIRTY(DSA
) || DIRTY(RASTERIZER
)) {
516 const bool cc_may_kill
= (vec
->dsa
->dw_alpha
||
517 vec
->blend
->alpha_to_coverage
);
519 gen7_3DSTATE_WM(r
->builder
, vec
->fs
,
520 vec
->rasterizer
, cc_may_kill
, 0);
523 /* 3DSTATE_BINDING_TABLE_POINTERS_PS */
524 if (session
->binding_table_fs_changed
) {
525 gen7_3DSTATE_BINDING_TABLE_POINTERS_PS(r
->builder
,
526 r
->state
.wm
.BINDING_TABLE_STATE
);
529 /* 3DSTATE_SAMPLER_STATE_POINTERS_PS */
530 if (session
->sampler_state_fs_changed
) {
531 gen7_3DSTATE_SAMPLER_STATE_POINTERS_PS(r
->builder
,
532 r
->state
.wm
.SAMPLER_STATE
);
535 /* 3DSTATE_CONSTANT_PS */
536 if (session
->pcb_state_fs_changed
) {
537 gen7_3DSTATE_CONSTANT_PS(r
->builder
,
538 &r
->state
.wm
.PUSH_CONSTANT_BUFFER
,
539 &r
->state
.wm
.PUSH_CONSTANT_BUFFER_size
,
544 if (DIRTY(FS
) || DIRTY(SAMPLER_FS
) || DIRTY(BLEND
) ||
545 r
->instruction_bo_changed
) {
546 const int num_samplers
= vec
->sampler
[PIPE_SHADER_FRAGMENT
].count
;
547 const bool dual_blend
= vec
->blend
->dual_blend
;
549 if ((ilo_dev_gen(r
->dev
) == ILO_GEN(7) ||
550 ilo_dev_gen(r
->dev
) == ILO_GEN(7.5)) &&
552 gen7_wa_pre_3dstate_ps_max_threads(r
);
554 gen7_3DSTATE_PS(r
->builder
, vec
->fs
, num_samplers
, dual_blend
);
557 /* 3DSTATE_SCISSOR_STATE_POINTERS */
558 if (session
->scissor_state_changed
) {
559 gen6_3DSTATE_SCISSOR_STATE_POINTERS(r
->builder
,
560 r
->state
.SCISSOR_RECT
);
563 /* XXX what is the best way to know if this workaround is needed? */
565 const bool emit_3dstate_ps
=
566 (DIRTY(FS
) || DIRTY(SAMPLER_FS
) || DIRTY(BLEND
));
567 const bool emit_3dstate_depth_buffer
=
568 (DIRTY(FB
) || DIRTY(DSA
) || r
->state_bo_changed
);
570 if (emit_3dstate_ps
||
571 session
->pcb_state_fs_changed
||
572 session
->viewport_state_changed
||
573 session
->binding_table_fs_changed
||
574 session
->sampler_state_fs_changed
||
575 session
->cc_state_cc_changed
||
576 session
->cc_state_blend_changed
||
577 session
->cc_state_dsa_changed
)
578 gen7_wa_post_ps_and_later(r
);
580 if (emit_3dstate_depth_buffer
)
581 gen7_wa_pre_depth(r
);
584 /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
585 if (DIRTY(FB
) || r
->batch_bo_changed
) {
586 const struct ilo_zs_surface
*zs
;
587 uint32_t clear_params
;
589 if (vec
->fb
.state
.zsbuf
) {
590 const struct ilo_surface_cso
*surface
=
591 (const struct ilo_surface_cso
*) vec
->fb
.state
.zsbuf
;
592 const struct ilo_texture_slice
*slice
=
593 ilo_texture_get_slice(ilo_texture(surface
->base
.texture
),
594 surface
->base
.u
.tex
.level
, surface
->base
.u
.tex
.first_layer
);
596 assert(!surface
->is_rt
);
598 clear_params
= slice
->clear_value
;
601 zs
= &vec
->fb
.null_zs
;
605 gen6_3DSTATE_DEPTH_BUFFER(r
->builder
, zs
);
606 gen6_3DSTATE_HIER_DEPTH_BUFFER(r
->builder
, zs
);
607 gen6_3DSTATE_STENCIL_BUFFER(r
->builder
, zs
);
608 gen7_3DSTATE_CLEAR_PARAMS(r
->builder
, clear_params
);
613 gen7_draw_wm_multisample(struct ilo_render
*r
,
614 const struct ilo_state_vector
*vec
,
615 struct gen6_draw_session
*session
)
617 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
618 if (DIRTY(SAMPLE_MASK
) || DIRTY(FB
)) {
619 const uint32_t *packed_sample_pos
;
621 gen7_wa_pre_3dstate_multisample(r
);
624 (vec
->fb
.num_samples
> 4) ? r
->packed_sample_position_8x
:
625 (vec
->fb
.num_samples
> 1) ? &r
->packed_sample_position_4x
:
626 &r
->packed_sample_position_1x
;
628 gen6_3DSTATE_MULTISAMPLE(r
->builder
,
629 vec
->fb
.num_samples
, packed_sample_pos
,
630 vec
->rasterizer
->state
.half_pixel_center
);
632 gen7_3DSTATE_SAMPLE_MASK(r
->builder
,
633 (vec
->fb
.num_samples
> 1) ? vec
->sample_mask
: 0x1,
634 vec
->fb
.num_samples
);
639 gen7_draw_vf_draw(struct ilo_render
*r
,
640 const struct ilo_state_vector
*vec
,
641 struct gen6_draw_session
*session
)
643 if (r
->state
.deferred_pipe_control_dw1
)
644 gen7_pipe_control(r
, r
->state
.deferred_pipe_control_dw1
);
647 gen7_3DPRIMITIVE(r
->builder
, vec
->draw
, &vec
->ib
);
649 r
->state
.current_pipe_control_dw1
= 0;
650 r
->state
.deferred_pipe_control_dw1
= 0;
654 gen7_draw_commands(struct ilo_render
*render
,
655 const struct ilo_state_vector
*vec
,
656 struct gen6_draw_session
*session
)
659 * We try to keep the order of the commands match, as closely as possible,
660 * that of the classic i965 driver. It allows us to compare the command
663 gen6_draw_common_select(render
, vec
, session
);
664 gen6_draw_common_sip(render
, vec
, session
);
665 gen6_draw_vf_statistics(render
, vec
, session
);
666 gen7_draw_common_pcb_alloc(render
, vec
, session
);
667 gen6_draw_common_base_address(render
, vec
, session
);
668 gen7_draw_common_pointers_1(render
, vec
, session
);
669 gen7_draw_common_urb(render
, vec
, session
);
670 gen7_draw_common_pointers_2(render
, vec
, session
);
671 gen7_draw_wm_multisample(render
, vec
, session
);
672 gen7_draw_gs(render
, vec
, session
);
673 gen7_draw_hs(render
, vec
, session
);
674 gen7_draw_te(render
, vec
, session
);
675 gen7_draw_ds(render
, vec
, session
);
676 gen7_draw_vs(render
, vec
, session
);
677 gen7_draw_sol(render
, vec
, session
);
678 gen6_draw_clip(render
, vec
, session
);
679 gen7_draw_sf(render
, vec
, session
);
680 gen7_draw_wm(render
, vec
, session
);
681 gen6_draw_wm_raster(render
, vec
, session
);
682 gen6_draw_sf_rect(render
, vec
, session
);
683 gen6_draw_vf(render
, vec
, session
);
684 gen7_draw_vf_draw(render
, vec
, session
);
688 ilo_render_emit_draw_gen7(struct ilo_render
*render
,
689 const struct ilo_state_vector
*vec
)
691 struct gen6_draw_session session
;
693 gen6_draw_prepare(render
, vec
, &session
);
695 session
.emit_draw_states
= gen6_draw_states
;
696 session
.emit_draw_commands
= gen7_draw_commands
;
698 gen6_draw_emit(render
, vec
, &session
);
699 gen6_draw_end(render
, vec
, &session
);
703 gen7_rectlist_pcb_alloc(struct ilo_render
*r
,
704 const struct ilo_blitter
*blitter
,
705 struct gen6_rectlist_session
*session
)
708 * Push constant buffers are only allowed to take up at most the first
709 * 16KB of the URB. Split the space evenly for VS and FS.
712 (ilo_dev_gen(r
->dev
) == ILO_GEN(7.5) && r
->dev
->gt
== 3) ? 32768 : 16384;
713 const int size
= max_size
/ 2;
716 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(r
->builder
, offset
, size
);
719 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(r
->builder
, offset
, size
);
721 gen7_wa_post_3dstate_push_constant_alloc_ps(r
);
725 gen7_rectlist_urb(struct ilo_render
*r
,
726 const struct ilo_blitter
*blitter
,
727 struct gen6_rectlist_session
*session
)
729 /* the first 16KB are reserved for VS and PS PCBs */
731 (ilo_dev_gen(r
->dev
) == ILO_GEN(7.5) && r
->dev
->gt
== 3) ? 32768 : 16384;
733 gen7_3DSTATE_URB_VS(r
->builder
, offset
, r
->dev
->urb_size
- offset
,
734 blitter
->ve
.count
* 4 * sizeof(float));
736 gen7_3DSTATE_URB_GS(r
->builder
, offset
, 0, 0);
737 gen7_3DSTATE_URB_HS(r
->builder
, offset
, 0, 0);
738 gen7_3DSTATE_URB_DS(r
->builder
, offset
, 0, 0);
742 gen7_rectlist_vs_to_sf(struct ilo_render
*r
,
743 const struct ilo_blitter
*blitter
,
744 struct gen6_rectlist_session
*session
)
746 gen7_3DSTATE_CONSTANT_VS(r
->builder
, NULL
, NULL
, 0);
747 gen6_3DSTATE_VS(r
->builder
, NULL
, 0);
749 gen7_3DSTATE_CONSTANT_HS(r
->builder
, NULL
, NULL
, 0);
750 gen7_3DSTATE_HS(r
->builder
, NULL
, 0);
752 gen7_3DSTATE_TE(r
->builder
);
754 gen7_3DSTATE_CONSTANT_DS(r
->builder
, NULL
, NULL
, 0);
755 gen7_3DSTATE_DS(r
->builder
, NULL
, 0);
757 gen7_3DSTATE_CONSTANT_GS(r
->builder
, NULL
, NULL
, 0);
758 gen7_3DSTATE_GS(r
->builder
, NULL
, 0);
760 gen7_3DSTATE_STREAMOUT(r
->builder
, 0x0, 0, false);
762 gen6_3DSTATE_CLIP(r
->builder
, NULL
, NULL
, false, 0);
764 gen7_wa_pre_3dstate_sf_depth_bias(r
);
766 gen7_3DSTATE_SF(r
->builder
, NULL
, blitter
->fb
.dst
.base
.format
);
767 gen7_3DSTATE_SBE(r
->builder
, NULL
, NULL
);
771 gen7_rectlist_wm(struct ilo_render
*r
,
772 const struct ilo_blitter
*blitter
,
773 struct gen6_rectlist_session
*session
)
777 switch (blitter
->op
) {
778 case ILO_BLITTER_RECTLIST_CLEAR_ZS
:
779 hiz_op
= GEN7_WM_DW1_DEPTH_CLEAR
;
781 case ILO_BLITTER_RECTLIST_RESOLVE_Z
:
782 hiz_op
= GEN7_WM_DW1_DEPTH_RESOLVE
;
784 case ILO_BLITTER_RECTLIST_RESOLVE_HIZ
:
785 hiz_op
= GEN7_WM_DW1_HIZ_RESOLVE
;
792 gen7_3DSTATE_WM(r
->builder
, NULL
, NULL
, false, hiz_op
);
794 gen7_3DSTATE_CONSTANT_PS(r
->builder
, NULL
, NULL
, 0);
796 gen7_wa_pre_3dstate_ps_max_threads(r
);
797 gen7_3DSTATE_PS(r
->builder
, NULL
, 0, false);
801 gen7_rectlist_wm_depth(struct ilo_render
*r
,
802 const struct ilo_blitter
*blitter
,
803 struct gen6_rectlist_session
*session
)
805 gen7_wa_pre_depth(r
);
807 if (blitter
->uses
& (ILO_BLITTER_USE_FB_DEPTH
|
808 ILO_BLITTER_USE_FB_STENCIL
)) {
809 gen6_3DSTATE_DEPTH_BUFFER(r
->builder
,
810 &blitter
->fb
.dst
.u
.zs
);
813 if (blitter
->uses
& ILO_BLITTER_USE_FB_DEPTH
) {
814 gen6_3DSTATE_HIER_DEPTH_BUFFER(r
->builder
,
815 &blitter
->fb
.dst
.u
.zs
);
818 if (blitter
->uses
& ILO_BLITTER_USE_FB_STENCIL
) {
819 gen6_3DSTATE_STENCIL_BUFFER(r
->builder
,
820 &blitter
->fb
.dst
.u
.zs
);
823 gen7_3DSTATE_CLEAR_PARAMS(r
->builder
,
824 blitter
->depth_clear_value
);
828 gen7_rectlist_wm_multisample(struct ilo_render
*r
,
829 const struct ilo_blitter
*blitter
,
830 struct gen6_rectlist_session
*session
)
832 const uint32_t *packed_sample_pos
=
833 (blitter
->fb
.num_samples
> 4) ? r
->packed_sample_position_8x
:
834 (blitter
->fb
.num_samples
> 1) ? &r
->packed_sample_position_4x
:
835 &r
->packed_sample_position_1x
;
837 gen7_wa_pre_3dstate_multisample(r
);
839 gen6_3DSTATE_MULTISAMPLE(r
->builder
, blitter
->fb
.num_samples
,
840 packed_sample_pos
, true);
842 gen7_3DSTATE_SAMPLE_MASK(r
->builder
,
843 (1 << blitter
->fb
.num_samples
) - 1, blitter
->fb
.num_samples
);
847 gen7_rectlist_commands(struct ilo_render
*r
,
848 const struct ilo_blitter
*blitter
,
849 struct gen6_rectlist_session
*session
)
851 gen7_rectlist_wm_multisample(r
, blitter
, session
);
853 gen6_state_base_address(r
->builder
, true);
855 gen6_3DSTATE_VERTEX_BUFFERS(r
->builder
,
856 &blitter
->ve
, &blitter
->vb
);
858 gen6_3DSTATE_VERTEX_ELEMENTS(r
->builder
,
859 &blitter
->ve
, false, false);
861 gen7_rectlist_pcb_alloc(r
, blitter
, session
);
863 /* needed for any VS-related commands */
866 gen7_rectlist_urb(r
, blitter
, session
);
868 if (blitter
->uses
& ILO_BLITTER_USE_DSA
) {
869 gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(r
->builder
,
870 session
->DEPTH_STENCIL_STATE
);
873 if (blitter
->uses
& ILO_BLITTER_USE_CC
) {
874 gen7_3DSTATE_CC_STATE_POINTERS(r
->builder
,
875 session
->COLOR_CALC_STATE
);
878 gen7_rectlist_vs_to_sf(r
, blitter
, session
);
879 gen7_rectlist_wm(r
, blitter
, session
);
881 if (blitter
->uses
& ILO_BLITTER_USE_VIEWPORT
) {
882 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(r
->builder
,
883 session
->CC_VIEWPORT
);
886 gen7_rectlist_wm_depth(r
, blitter
, session
);
888 gen6_3DSTATE_DRAWING_RECTANGLE(r
->builder
, 0, 0,
889 blitter
->fb
.width
, blitter
->fb
.height
);
891 gen7_3DPRIMITIVE(r
->builder
, &blitter
->draw
, NULL
);
895 gen7_rectlist_states(struct ilo_render
*r
,
896 const struct ilo_blitter
*blitter
,
897 struct gen6_rectlist_session
*session
)
899 if (blitter
->uses
& ILO_BLITTER_USE_DSA
) {
900 session
->DEPTH_STENCIL_STATE
=
901 gen6_DEPTH_STENCIL_STATE(r
->builder
, &blitter
->dsa
);
904 if (blitter
->uses
& ILO_BLITTER_USE_CC
) {
905 session
->COLOR_CALC_STATE
=
906 gen6_COLOR_CALC_STATE(r
->builder
, &blitter
->cc
.stencil_ref
,
907 blitter
->cc
.alpha_ref
, &blitter
->cc
.blend_color
);
910 if (blitter
->uses
& ILO_BLITTER_USE_VIEWPORT
) {
911 session
->CC_VIEWPORT
=
912 gen6_CC_VIEWPORT(r
->builder
, &blitter
->viewport
, 1);
917 ilo_render_emit_rectlist_gen7(struct ilo_render
*render
,
918 const struct ilo_blitter
*blitter
)
920 struct gen6_rectlist_session session
;
922 memset(&session
, 0, sizeof(session
));
923 gen7_rectlist_states(render
, blitter
, &session
);
924 gen7_rectlist_commands(render
, blitter
, &session
);
928 gen7_render_max_command_size(const struct ilo_render
*render
)
933 size
+= GEN7_3DSTATE_URB_ANY__SIZE
* 4;
934 size
+= GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_ANY__SIZE
* 5;
935 size
+= GEN6_3DSTATE_CONSTANT_ANY__SIZE
* 5;
936 size
+= GEN7_3DSTATE_POINTERS_ANY__SIZE
* (5 + 5 + 4);
937 size
+= GEN7_3DSTATE_SO_BUFFER__SIZE
* 4;
938 size
+= GEN6_PIPE_CONTROL__SIZE
* 5;
941 GEN6_STATE_BASE_ADDRESS__SIZE
+
942 GEN6_STATE_SIP__SIZE
+
943 GEN6_3DSTATE_VF_STATISTICS__SIZE
+
944 GEN6_PIPELINE_SELECT__SIZE
+
945 GEN6_3DSTATE_CLEAR_PARAMS__SIZE
+
946 GEN6_3DSTATE_DEPTH_BUFFER__SIZE
+
947 GEN6_3DSTATE_STENCIL_BUFFER__SIZE
+
948 GEN6_3DSTATE_HIER_DEPTH_BUFFER__SIZE
+
949 GEN6_3DSTATE_VERTEX_BUFFERS__SIZE
+
950 GEN6_3DSTATE_VERTEX_ELEMENTS__SIZE
+
951 GEN6_3DSTATE_INDEX_BUFFER__SIZE
+
952 GEN75_3DSTATE_VF__SIZE
+
953 GEN6_3DSTATE_VS__SIZE
+
954 GEN6_3DSTATE_GS__SIZE
+
955 GEN6_3DSTATE_CLIP__SIZE
+
956 GEN6_3DSTATE_SF__SIZE
+
957 GEN6_3DSTATE_WM__SIZE
+
958 GEN6_3DSTATE_SAMPLE_MASK__SIZE
+
959 GEN7_3DSTATE_HS__SIZE
+
960 GEN7_3DSTATE_TE__SIZE
+
961 GEN7_3DSTATE_DS__SIZE
+
962 GEN7_3DSTATE_STREAMOUT__SIZE
+
963 GEN7_3DSTATE_SBE__SIZE
+
964 GEN7_3DSTATE_PS__SIZE
+
965 GEN6_3DSTATE_DRAWING_RECTANGLE__SIZE
+
966 GEN6_3DSTATE_POLY_STIPPLE_OFFSET__SIZE
+
967 GEN6_3DSTATE_POLY_STIPPLE_PATTERN__SIZE
+
968 GEN6_3DSTATE_LINE_STIPPLE__SIZE
+
969 GEN6_3DSTATE_AA_LINE_PARAMETERS__SIZE
+
970 GEN6_3DSTATE_MULTISAMPLE__SIZE
+
971 GEN7_3DSTATE_SO_DECL_LIST__SIZE
+
972 GEN6_3DPRIMITIVE__SIZE
;
979 ilo_render_estimate_size_gen7(struct ilo_render
*render
,
980 enum ilo_render_action action
,
986 case ILO_RENDER_DRAW
:
988 const struct ilo_state_vector
*ilo
= arg
;
990 size
= gen7_render_max_command_size(render
) +
991 gen6_render_estimate_state_size(render
, ilo
);
994 case ILO_RENDER_RECTLIST
:
995 size
= 64 + 256; /* states + commands */
998 assert(!"unknown render action");
1007 ilo_render_init_gen7(struct ilo_render
*render
)
1009 render
->estimate_size
= ilo_render_estimate_size_gen7
;
1010 render
->emit_draw
= ilo_render_emit_draw_gen7
;
1011 render
->emit_rectlist
= ilo_render_emit_rectlist_gen7
;