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 "core/ilo_builder_3d.h"
30 #include "core/ilo_builder_render.h"
32 #include "ilo_blitter.h"
33 #include "ilo_shader.h"
34 #include "ilo_state.h"
35 #include "ilo_render_gen.h"
38 gen7_wa_post_3dstate_push_constant_alloc_ps(struct ilo_render
*r
)
41 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
43 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
44 * in the ring after this instruction
45 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
47 const uint32_t dw1
= GEN6_PIPE_CONTROL_CS_STALL
;
49 ILO_DEV_ASSERT(r
->dev
, 7, 7);
51 r
->state
.deferred_pipe_control_dw1
|= dw1
;
55 gen7_wa_pre_vs(struct ilo_render
*r
)
58 * From the Ivy Bridge PRM, volume 2 part 1, page 106:
60 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
61 * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
62 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
63 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
64 * needs to be sent before any combination of VS associated 3DSTATE."
66 const uint32_t dw1
= GEN6_PIPE_CONTROL_DEPTH_STALL
|
67 GEN6_PIPE_CONTROL_WRITE_IMM
;
69 ILO_DEV_ASSERT(r
->dev
, 7, 7);
71 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
72 ilo_render_pipe_control(r
, dw1
);
76 gen7_wa_pre_3dstate_sf_depth_bias(struct ilo_render
*r
)
79 * From the Ivy Bridge PRM, volume 2 part 1, page 258:
81 * "Due to an HW issue driver needs to send a pipe control with stall
82 * when ever there is state change in depth bias related state (in
85 const uint32_t dw1
= GEN6_PIPE_CONTROL_CS_STALL
;
87 ILO_DEV_ASSERT(r
->dev
, 7, 7);
89 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
90 ilo_render_pipe_control(r
, dw1
);
94 gen7_wa_pre_3dstate_multisample(struct ilo_render
*r
)
97 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
99 * "Driver must ierarchi that all the caches in the depth pipe are
100 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
101 * requires driver to send a PIPE_CONTROL with a CS stall along with a
102 * Depth Flush prior to this command.
104 const uint32_t dw1
= GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
105 GEN6_PIPE_CONTROL_CS_STALL
;
107 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
109 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
110 ilo_render_pipe_control(r
, dw1
);
114 gen7_wa_pre_depth(struct ilo_render
*r
)
116 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
118 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7)) {
120 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
122 * "Driver must send a least one PIPE_CONTROL command with CS Stall
123 * and a post sync operation prior to the group of depth
124 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
125 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
127 const uint32_t dw1
= GEN6_PIPE_CONTROL_CS_STALL
|
128 GEN6_PIPE_CONTROL_WRITE_IMM
;
130 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
131 ilo_render_pipe_control(r
, dw1
);
135 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
137 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
138 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
139 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
140 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
141 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
142 * Depth Flush Bit set, followed by another pipelined depth stall
143 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
144 * guarantee that the pipeline from WM onwards is already flushed
145 * (e.g., via a preceding MI_FLUSH)."
147 ilo_render_pipe_control(r
, GEN6_PIPE_CONTROL_DEPTH_STALL
);
148 ilo_render_pipe_control(r
, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
);
149 ilo_render_pipe_control(r
, GEN6_PIPE_CONTROL_DEPTH_STALL
);
153 gen7_wa_pre_3dstate_ps_max_threads(struct ilo_render
*r
)
156 * From the Ivy Bridge PRM, volume 2 part 1, page 286:
158 * "If this field (Maximum Number of Threads in 3DSTATE_PS) is changed
159 * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at
160 * Pixel Scoreboard set is required to be issued."
162 const uint32_t dw1
= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL
;
164 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
166 if ((r
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
167 ilo_render_pipe_control(r
, dw1
);
171 gen7_wa_post_ps_and_later(struct ilo_render
*r
)
174 * From the Ivy Bridge PRM, volume 2 part 1, page 276:
176 * "The driver must make sure a PIPE_CONTROL with the Depth Stall
177 * Enable bit set after all the following states are programmed:
180 * - 3DSTATE_VIEWPORT_STATE_POINTERS_CC
181 * - 3DSTATE_CONSTANT_PS
182 * - 3DSTATE_BINDING_TABLE_POINTERS_PS
183 * - 3DSTATE_SAMPLER_STATE_POINTERS_PS
184 * - 3DSTATE_CC_STATE_POINTERS
185 * - 3DSTATE_BLEND_STATE_POINTERS
186 * - 3DSTATE_DEPTH_STENCIL_STATE_POINTERS"
188 const uint32_t dw1
= GEN6_PIPE_CONTROL_DEPTH_STALL
;
190 ILO_DEV_ASSERT(r
->dev
, 7, 7);
192 r
->state
.deferred_pipe_control_dw1
|= dw1
;
195 #define DIRTY(state) (session->pipe_dirty & ILO_DIRTY_ ## state)
198 gen7_draw_common_urb(struct ilo_render
*r
,
199 const struct ilo_state_vector
*vec
,
200 struct ilo_render_draw_session
*session
)
202 /* 3DSTATE_URB_{VS,GS,HS,DS} */
203 if (session
->urb_delta
.dirty
& (ILO_STATE_URB_3DSTATE_URB_VS
|
204 ILO_STATE_URB_3DSTATE_URB_HS
|
205 ILO_STATE_URB_3DSTATE_URB_DS
|
206 ILO_STATE_URB_3DSTATE_URB_GS
)) {
207 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7))
210 gen7_3DSTATE_URB_VS(r
->builder
, &vec
->urb
);
211 gen7_3DSTATE_URB_GS(r
->builder
, &vec
->urb
);
212 gen7_3DSTATE_URB_HS(r
->builder
, &vec
->urb
);
213 gen7_3DSTATE_URB_DS(r
->builder
, &vec
->urb
);
218 gen7_draw_common_pcb_alloc(struct ilo_render
*r
,
219 const struct ilo_state_vector
*vec
,
220 struct ilo_render_draw_session
*session
)
222 /* 3DSTATE_PUSH_CONSTANT_ALLOC_{VS,PS} */
223 if (session
->urb_delta
.dirty
&
224 (ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_VS
|
225 ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_HS
|
226 ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_DS
|
227 ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_GS
|
228 ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_PS
)) {
229 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(r
->builder
, &vec
->urb
);
230 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_GS(r
->builder
, &vec
->urb
);
231 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(r
->builder
, &vec
->urb
);
233 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7))
234 gen7_wa_post_3dstate_push_constant_alloc_ps(r
);
239 gen7_draw_common_pointers_1(struct ilo_render
*r
,
240 const struct ilo_state_vector
*vec
,
241 struct ilo_render_draw_session
*session
)
243 /* 3DSTATE_VIEWPORT_STATE_POINTERS_{CC,SF_CLIP} */
244 if (session
->viewport_changed
) {
245 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(r
->builder
,
246 r
->state
.CC_VIEWPORT
);
248 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(r
->builder
,
249 r
->state
.SF_CLIP_VIEWPORT
);
254 gen7_draw_common_pointers_2(struct ilo_render
*r
,
255 const struct ilo_state_vector
*vec
,
256 struct ilo_render_draw_session
*session
)
258 /* 3DSTATE_BLEND_STATE_POINTERS */
259 if (session
->blend_changed
) {
260 gen7_3DSTATE_BLEND_STATE_POINTERS(r
->builder
,
261 r
->state
.BLEND_STATE
);
264 /* 3DSTATE_CC_STATE_POINTERS */
265 if (session
->cc_changed
) {
266 gen7_3DSTATE_CC_STATE_POINTERS(r
->builder
,
267 r
->state
.COLOR_CALC_STATE
);
270 /* 3DSTATE_DEPTH_STENCIL_STATE_POINTERS */
271 if (ilo_dev_gen(r
->dev
) < ILO_GEN(8) && session
->dsa_changed
) {
272 gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(r
->builder
,
273 r
->state
.DEPTH_STENCIL_STATE
);
278 gen7_draw_vs(struct ilo_render
*r
,
279 const struct ilo_state_vector
*vec
,
280 struct ilo_render_draw_session
*session
)
282 const bool emit_3dstate_binding_table
= session
->binding_table_vs_changed
;
283 const bool emit_3dstate_sampler_state
= session
->sampler_vs_changed
;
284 /* see gen6_draw_vs() */
285 const bool emit_3dstate_constant_vs
= session
->pcb_vs_changed
;
286 const bool emit_3dstate_vs
= (DIRTY(VS
) || r
->instruction_bo_changed
);
288 /* emit depth stall before any of the VS commands */
289 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7)) {
290 if (emit_3dstate_binding_table
|| emit_3dstate_sampler_state
||
291 emit_3dstate_constant_vs
|| emit_3dstate_vs
)
295 /* 3DSTATE_BINDING_TABLE_POINTERS_VS */
296 if (emit_3dstate_binding_table
) {
297 gen7_3DSTATE_BINDING_TABLE_POINTERS_VS(r
->builder
,
298 r
->state
.vs
.BINDING_TABLE_STATE
);
301 /* 3DSTATE_SAMPLER_STATE_POINTERS_VS */
302 if (emit_3dstate_sampler_state
) {
303 gen7_3DSTATE_SAMPLER_STATE_POINTERS_VS(r
->builder
,
304 r
->state
.vs
.SAMPLER_STATE
);
307 /* 3DSTATE_CONSTANT_VS */
308 if (emit_3dstate_constant_vs
) {
309 gen7_3DSTATE_CONSTANT_VS(r
->builder
,
310 &r
->state
.vs
.PUSH_CONSTANT_BUFFER
,
311 &r
->state
.vs
.PUSH_CONSTANT_BUFFER_size
,
316 if (emit_3dstate_vs
) {
317 const union ilo_shader_cso
*cso
= ilo_shader_get_kernel_cso(vec
->vs
);
318 const uint32_t kernel_offset
= ilo_shader_get_kernel_offset(vec
->vs
);
320 if (ilo_dev_gen(r
->dev
) >= ILO_GEN(8))
321 gen8_3DSTATE_VS(r
->builder
, &cso
->vs
, kernel_offset
);
323 gen6_3DSTATE_VS(r
->builder
, &cso
->vs
, kernel_offset
);
328 gen7_draw_hs(struct ilo_render
*r
,
329 const struct ilo_state_vector
*vec
,
330 struct ilo_render_draw_session
*session
)
332 /* 3DSTATE_CONSTANT_HS and 3DSTATE_HS */
333 if (r
->hw_ctx_changed
) {
334 const struct ilo_state_hs
*hs
= &vec
->disabled_hs
;
335 const uint32_t kernel_offset
= 0;
337 gen7_3DSTATE_CONSTANT_HS(r
->builder
, 0, 0, 0);
339 if (ilo_dev_gen(r
->dev
) >= ILO_GEN(8))
340 gen8_3DSTATE_HS(r
->builder
, hs
, kernel_offset
);
342 gen7_3DSTATE_HS(r
->builder
, hs
, kernel_offset
);
345 /* 3DSTATE_BINDING_TABLE_POINTERS_HS */
346 if (r
->hw_ctx_changed
)
347 gen7_3DSTATE_BINDING_TABLE_POINTERS_HS(r
->builder
, 0);
351 gen7_draw_te(struct ilo_render
*r
,
352 const struct ilo_state_vector
*vec
,
353 struct ilo_render_draw_session
*session
)
356 if (r
->hw_ctx_changed
) {
357 const struct ilo_state_ds
*ds
= &vec
->disabled_ds
;
358 gen7_3DSTATE_TE(r
->builder
, ds
);
363 gen7_draw_ds(struct ilo_render
*r
,
364 const struct ilo_state_vector
*vec
,
365 struct ilo_render_draw_session
*session
)
367 /* 3DSTATE_CONSTANT_DS and 3DSTATE_DS */
368 if (r
->hw_ctx_changed
) {
369 const struct ilo_state_ds
*ds
= &vec
->disabled_ds
;
370 const uint32_t kernel_offset
= 0;
372 gen7_3DSTATE_CONSTANT_DS(r
->builder
, 0, 0, 0);
374 if (ilo_dev_gen(r
->dev
) >= ILO_GEN(8))
375 gen8_3DSTATE_DS(r
->builder
, ds
, kernel_offset
);
377 gen7_3DSTATE_DS(r
->builder
, ds
, kernel_offset
);
380 /* 3DSTATE_BINDING_TABLE_POINTERS_DS */
381 if (r
->hw_ctx_changed
)
382 gen7_3DSTATE_BINDING_TABLE_POINTERS_DS(r
->builder
, 0);
387 gen7_draw_gs(struct ilo_render
*r
,
388 const struct ilo_state_vector
*vec
,
389 struct ilo_render_draw_session
*session
)
391 /* 3DSTATE_CONSTANT_GS and 3DSTATE_GS */
392 if (r
->hw_ctx_changed
) {
393 const struct ilo_state_gs
*gs
= &vec
->disabled_gs
;
394 const uint32_t kernel_offset
= 0;
396 gen7_3DSTATE_CONSTANT_GS(r
->builder
, 0, 0, 0);
398 if (ilo_dev_gen(r
->dev
) >= ILO_GEN(8))
399 gen8_3DSTATE_GS(r
->builder
, gs
, kernel_offset
);
401 gen7_3DSTATE_GS(r
->builder
, gs
, kernel_offset
);
404 /* 3DSTATE_BINDING_TABLE_POINTERS_GS */
405 if (session
->binding_table_gs_changed
) {
406 gen7_3DSTATE_BINDING_TABLE_POINTERS_GS(r
->builder
,
407 r
->state
.gs
.BINDING_TABLE_STATE
);
412 gen7_draw_sol(struct ilo_render
*r
,
413 const struct ilo_state_vector
*vec
,
414 struct ilo_render_draw_session
*session
)
416 const struct ilo_state_sol
*sol
;
417 const struct ilo_shader_state
*shader
;
418 bool dirty_sh
= false;
422 dirty_sh
= DIRTY(GS
);
426 dirty_sh
= DIRTY(VS
);
429 sol
= ilo_shader_get_kernel_sol(shader
);
431 /* 3DSTATE_SO_BUFFER */
432 if ((DIRTY(SO
) || dirty_sh
|| r
->batch_bo_changed
) &&
434 const struct pipe_stream_output_info
*so_info
;
437 so_info
= ilo_shader_get_kernel_so_info(shader
);
439 for (i
= 0; i
< vec
->so
.count
; i
++) {
440 const int stride
= so_info
->stride
[i
] * 4; /* in bytes */
442 gen7_3DSTATE_SO_BUFFER(r
->builder
, i
, stride
, vec
->so
.states
[i
]);
446 gen7_disable_3DSTATE_SO_BUFFER(r
->builder
, i
);
449 /* 3DSTATE_SO_DECL_LIST */
450 if (dirty_sh
&& vec
->so
.enabled
)
451 gen7_3DSTATE_SO_DECL_LIST(r
->builder
, sol
);
454 * From the Ivy Bridge PRM, volume 2 part 1, page 196-197:
456 * "Anytime the SOL unit MMIO registers or non-pipeline state are
457 * written, the SOL unit needs to receive a pipeline state update with
458 * SOL unit dirty state for information programmed in MMIO/NP to get
459 * loaded into the SOL unit.
461 * The SOL unit incorrectly double buffers MMIO/NP registers and only
462 * moves them into the design for usage when control topology is
463 * received with the SOL unit dirty state.
465 * If the state does not change, need to resend the same state.
467 * Because of corruption, software must flush the whole fixed function
468 * pipeline when 3DSTATE_STREAMOUT changes state."
470 * The first and fourth paragraphs are gone on Gen7.5+.
473 /* 3DSTATE_STREAMOUT */
474 gen7_3DSTATE_STREAMOUT(r
->builder
, sol
);
478 gen7_draw_sf(struct ilo_render
*r
,
479 const struct ilo_state_vector
*vec
,
480 struct ilo_render_draw_session
*session
)
484 const struct ilo_state_sbe
*sbe
= ilo_shader_get_kernel_sbe(vec
->fs
);
485 gen7_3DSTATE_SBE(r
->builder
, sbe
);
489 if (session
->rs_delta
.dirty
& ILO_STATE_RASTER_3DSTATE_SF
) {
490 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7))
491 gen7_wa_pre_3dstate_sf_depth_bias(r
);
493 gen7_3DSTATE_SF(r
->builder
, &vec
->rasterizer
->rs
);
498 gen7_draw_wm(struct ilo_render
*r
,
499 const struct ilo_state_vector
*vec
,
500 struct ilo_render_draw_session
*session
)
502 const union ilo_shader_cso
*cso
= ilo_shader_get_kernel_cso(vec
->fs
);
503 const uint32_t kernel_offset
= ilo_shader_get_kernel_offset(vec
->fs
);
506 if (DIRTY(FS
) || (session
->rs_delta
.dirty
& ILO_STATE_RASTER_3DSTATE_WM
))
507 gen7_3DSTATE_WM(r
->builder
, &vec
->rasterizer
->rs
, &cso
->ps
);
509 /* 3DSTATE_BINDING_TABLE_POINTERS_PS */
510 if (session
->binding_table_fs_changed
) {
511 gen7_3DSTATE_BINDING_TABLE_POINTERS_PS(r
->builder
,
512 r
->state
.wm
.BINDING_TABLE_STATE
);
515 /* 3DSTATE_SAMPLER_STATE_POINTERS_PS */
516 if (session
->sampler_fs_changed
) {
517 gen7_3DSTATE_SAMPLER_STATE_POINTERS_PS(r
->builder
,
518 r
->state
.wm
.SAMPLER_STATE
);
521 /* 3DSTATE_CONSTANT_PS */
522 if (session
->pcb_fs_changed
) {
523 gen7_3DSTATE_CONSTANT_PS(r
->builder
,
524 &r
->state
.wm
.PUSH_CONSTANT_BUFFER
,
525 &r
->state
.wm
.PUSH_CONSTANT_BUFFER_size
,
530 if (DIRTY(FS
) || r
->instruction_bo_changed
) {
531 if (r
->hw_ctx_changed
)
532 gen7_wa_pre_3dstate_ps_max_threads(r
);
534 gen7_3DSTATE_PS(r
->builder
, &cso
->ps
, kernel_offset
);
537 /* 3DSTATE_SCISSOR_STATE_POINTERS */
538 if (session
->scissor_changed
) {
539 gen6_3DSTATE_SCISSOR_STATE_POINTERS(r
->builder
,
540 r
->state
.SCISSOR_RECT
);
544 const bool emit_3dstate_ps
= (DIRTY(FS
) || DIRTY(BLEND
));
545 const bool emit_3dstate_depth_buffer
=
546 (DIRTY(FB
) || DIRTY(DSA
) || r
->state_bo_changed
);
548 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7)) {
549 /* XXX what is the best way to know if this workaround is needed? */
550 if (emit_3dstate_ps
||
551 session
->pcb_fs_changed
||
552 session
->viewport_changed
||
553 session
->binding_table_fs_changed
||
554 session
->sampler_fs_changed
||
555 session
->cc_changed
||
556 session
->blend_changed
||
557 session
->dsa_changed
)
558 gen7_wa_post_ps_and_later(r
);
561 if (emit_3dstate_depth_buffer
)
562 gen7_wa_pre_depth(r
);
565 /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
566 if (DIRTY(FB
) || r
->batch_bo_changed
) {
567 const struct ilo_state_zs
*zs
;
568 uint32_t clear_params
;
570 if (vec
->fb
.state
.zsbuf
) {
571 const struct ilo_surface_cso
*surface
=
572 (const struct ilo_surface_cso
*) vec
->fb
.state
.zsbuf
;
573 const struct ilo_texture_slice
*slice
=
574 ilo_texture_get_slice(ilo_texture(surface
->base
.texture
),
575 surface
->base
.u
.tex
.level
, surface
->base
.u
.tex
.first_layer
);
577 assert(!surface
->is_rt
);
579 clear_params
= slice
->clear_value
;
582 zs
= &vec
->fb
.null_zs
;
586 gen6_3DSTATE_DEPTH_BUFFER(r
->builder
, zs
);
587 gen6_3DSTATE_HIER_DEPTH_BUFFER(r
->builder
, zs
);
588 gen6_3DSTATE_STENCIL_BUFFER(r
->builder
, zs
);
589 gen7_3DSTATE_CLEAR_PARAMS(r
->builder
, clear_params
);
594 gen7_draw_wm_multisample(struct ilo_render
*r
,
595 const struct ilo_state_vector
*vec
,
596 struct ilo_render_draw_session
*session
)
598 /* 3DSTATE_MULTISAMPLE */
599 if (DIRTY(FB
) || (session
->rs_delta
.dirty
&
600 ILO_STATE_RASTER_3DSTATE_MULTISAMPLE
)) {
601 const uint32_t *pattern
;
604 gen7_wa_pre_3dstate_multisample(r
);
606 if (vec
->fb
.num_samples
> 4) {
607 pattern
= r
->sample_pattern_8x
;
608 pattern_len
= ARRAY_SIZE(r
->sample_pattern_8x
);
610 pattern
= (vec
->fb
.num_samples
> 1) ?
611 &r
->sample_pattern_4x
: &r
->sample_pattern_1x
;
615 gen6_3DSTATE_MULTISAMPLE(r
->builder
, &vec
->rasterizer
->rs
,
616 pattern
, pattern_len
);
619 /* 3DSTATE_SAMPLE_MASK */
620 if (session
->rs_delta
.dirty
& ILO_STATE_RASTER_3DSTATE_SAMPLE_MASK
)
621 gen6_3DSTATE_SAMPLE_MASK(r
->builder
, &vec
->rasterizer
->rs
);
625 ilo_render_emit_draw_commands_gen7(struct ilo_render
*render
,
626 const struct ilo_state_vector
*vec
,
627 struct ilo_render_draw_session
*session
)
629 ILO_DEV_ASSERT(render
->dev
, 7, 7.5);
632 * We try to keep the order of the commands match, as closely as possible,
633 * that of the classic i965 driver. It allows us to compare the command
636 gen6_draw_common_select(render
, vec
, session
);
637 gen6_draw_common_sip(render
, vec
, session
);
638 gen6_draw_vf_statistics(render
, vec
, session
);
639 gen7_draw_common_pcb_alloc(render
, vec
, session
);
640 gen6_draw_common_base_address(render
, vec
, session
);
641 gen7_draw_common_pointers_1(render
, vec
, session
);
642 gen7_draw_common_urb(render
, vec
, session
);
643 gen7_draw_common_pointers_2(render
, vec
, session
);
644 gen7_draw_wm_multisample(render
, vec
, session
);
645 gen7_draw_gs(render
, vec
, session
);
646 gen7_draw_hs(render
, vec
, session
);
647 gen7_draw_te(render
, vec
, session
);
648 gen7_draw_ds(render
, vec
, session
);
649 gen7_draw_vs(render
, vec
, session
);
650 gen7_draw_sol(render
, vec
, session
);
651 gen6_draw_clip(render
, vec
, session
);
652 gen7_draw_sf(render
, vec
, session
);
653 gen7_draw_wm(render
, vec
, session
);
654 gen6_draw_wm_raster(render
, vec
, session
);
655 gen6_draw_sf_rect(render
, vec
, session
);
656 gen6_draw_vf(render
, vec
, session
);
658 ilo_render_3dprimitive(render
, vec
->draw
, &vec
->ib
);
662 gen7_rectlist_pcb_alloc(struct ilo_render
*r
,
663 const struct ilo_blitter
*blitter
)
665 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(r
->builder
, &blitter
->urb
);
666 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(r
->builder
, &blitter
->urb
);
668 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7))
669 gen7_wa_post_3dstate_push_constant_alloc_ps(r
);
673 gen7_rectlist_urb(struct ilo_render
*r
,
674 const struct ilo_blitter
*blitter
)
676 gen7_3DSTATE_URB_VS(r
->builder
, &blitter
->urb
);
677 gen7_3DSTATE_URB_GS(r
->builder
, &blitter
->urb
);
678 gen7_3DSTATE_URB_HS(r
->builder
, &blitter
->urb
);
679 gen7_3DSTATE_URB_DS(r
->builder
, &blitter
->urb
);
683 gen7_rectlist_vs_to_sf(struct ilo_render
*r
,
684 const struct ilo_blitter
*blitter
)
686 gen7_3DSTATE_CONSTANT_VS(r
->builder
, NULL
, NULL
, 0);
687 gen6_3DSTATE_VS(r
->builder
, &blitter
->vs
, 0);
689 gen7_3DSTATE_CONSTANT_HS(r
->builder
, NULL
, NULL
, 0);
690 gen7_3DSTATE_HS(r
->builder
, &blitter
->hs
, 0);
692 gen7_3DSTATE_TE(r
->builder
, &blitter
->ds
);
694 gen7_3DSTATE_CONSTANT_DS(r
->builder
, NULL
, NULL
, 0);
695 gen7_3DSTATE_DS(r
->builder
, &blitter
->ds
, 0);
697 gen7_3DSTATE_CONSTANT_GS(r
->builder
, NULL
, NULL
, 0);
698 gen7_3DSTATE_GS(r
->builder
, &blitter
->gs
, 0);
700 gen7_3DSTATE_STREAMOUT(r
->builder
, &blitter
->sol
);
702 gen6_3DSTATE_CLIP(r
->builder
, &blitter
->fb
.rs
);
704 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7))
705 gen7_wa_pre_3dstate_sf_depth_bias(r
);
707 gen7_3DSTATE_SF(r
->builder
, &blitter
->fb
.rs
);
708 gen7_3DSTATE_SBE(r
->builder
, &blitter
->sbe
);
712 gen7_rectlist_wm(struct ilo_render
*r
,
713 const struct ilo_blitter
*blitter
)
715 gen7_3DSTATE_WM(r
->builder
, &blitter
->fb
.rs
, &blitter
->ps
);
717 gen7_3DSTATE_CONSTANT_PS(r
->builder
, NULL
, NULL
, 0);
719 gen7_wa_pre_3dstate_ps_max_threads(r
);
720 gen7_3DSTATE_PS(r
->builder
, &blitter
->ps
, 0);
724 gen7_rectlist_wm_depth(struct ilo_render
*r
,
725 const struct ilo_blitter
*blitter
)
727 gen7_wa_pre_depth(r
);
729 if (blitter
->uses
& (ILO_BLITTER_USE_FB_DEPTH
|
730 ILO_BLITTER_USE_FB_STENCIL
))
731 gen6_3DSTATE_DEPTH_BUFFER(r
->builder
, &blitter
->fb
.dst
.u
.zs
);
733 if (blitter
->uses
& ILO_BLITTER_USE_FB_DEPTH
) {
734 gen6_3DSTATE_HIER_DEPTH_BUFFER(r
->builder
,
735 &blitter
->fb
.dst
.u
.zs
);
738 if (blitter
->uses
& ILO_BLITTER_USE_FB_STENCIL
) {
739 gen6_3DSTATE_STENCIL_BUFFER(r
->builder
,
740 &blitter
->fb
.dst
.u
.zs
);
743 gen7_3DSTATE_CLEAR_PARAMS(r
->builder
,
744 blitter
->depth_clear_value
);
748 gen7_rectlist_wm_multisample(struct ilo_render
*r
,
749 const struct ilo_blitter
*blitter
)
751 const uint32_t *pattern
;
754 if (blitter
->fb
.num_samples
> 4) {
755 pattern
= r
->sample_pattern_8x
;
756 pattern_len
= ARRAY_SIZE(r
->sample_pattern_8x
);
758 pattern
= (blitter
->fb
.num_samples
> 1) ?
759 &r
->sample_pattern_4x
: &r
->sample_pattern_1x
;
763 gen7_wa_pre_3dstate_multisample(r
);
765 gen6_3DSTATE_MULTISAMPLE(r
->builder
, &blitter
->fb
.rs
,
766 pattern
, pattern_len
);
768 gen6_3DSTATE_SAMPLE_MASK(r
->builder
, &blitter
->fb
.rs
);
772 ilo_render_emit_rectlist_commands_gen7(struct ilo_render
*r
,
773 const struct ilo_blitter
*blitter
,
774 const struct ilo_render_rectlist_session
*session
)
776 ILO_DEV_ASSERT(r
->dev
, 7, 7.5);
778 gen7_rectlist_wm_multisample(r
, blitter
);
780 gen6_state_base_address(r
->builder
, true);
782 gen6_user_3DSTATE_VERTEX_BUFFERS(r
->builder
,
783 session
->vb_start
, session
->vb_end
,
784 sizeof(blitter
->vertices
[0]));
786 gen6_3DSTATE_VERTEX_ELEMENTS(r
->builder
, &blitter
->vf
);
788 gen7_rectlist_pcb_alloc(r
, blitter
);
790 /* needed for any VS-related commands */
791 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7))
794 gen7_rectlist_urb(r
, blitter
);
796 if (blitter
->uses
& ILO_BLITTER_USE_DSA
) {
797 gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(r
->builder
,
798 r
->state
.DEPTH_STENCIL_STATE
);
801 if (blitter
->uses
& ILO_BLITTER_USE_CC
) {
802 gen7_3DSTATE_CC_STATE_POINTERS(r
->builder
,
803 r
->state
.COLOR_CALC_STATE
);
806 gen7_rectlist_vs_to_sf(r
, blitter
);
807 gen7_rectlist_wm(r
, blitter
);
809 if (blitter
->uses
& ILO_BLITTER_USE_VIEWPORT
) {
810 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(r
->builder
,
811 r
->state
.CC_VIEWPORT
);
814 gen7_rectlist_wm_depth(r
, blitter
);
816 gen6_3DSTATE_DRAWING_RECTANGLE(r
->builder
, 0, 0,
817 blitter
->fb
.width
, blitter
->fb
.height
);
819 if (ilo_dev_gen(r
->dev
) == ILO_GEN(7))
820 gen7_wa_post_ps_and_later(r
);
822 ilo_render_3dprimitive(r
, &blitter
->draw
, NULL
);
826 ilo_render_get_draw_commands_len_gen7(const struct ilo_render
*render
,
827 const struct ilo_state_vector
*vec
)
831 ILO_DEV_ASSERT(render
->dev
, 7, 7.5);
834 len
+= GEN7_3DSTATE_URB_ANY__SIZE
* 4;
835 len
+= GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_ANY__SIZE
* 5;
836 len
+= GEN6_3DSTATE_CONSTANT_ANY__SIZE
* 5;
837 len
+= GEN7_3DSTATE_POINTERS_ANY__SIZE
* (5 + 5 + 4);
838 len
+= GEN7_3DSTATE_SO_BUFFER__SIZE
* 4;
839 len
+= GEN6_PIPE_CONTROL__SIZE
* 5;
842 GEN6_STATE_BASE_ADDRESS__SIZE
+
843 GEN6_STATE_SIP__SIZE
+
844 GEN6_3DSTATE_VF_STATISTICS__SIZE
+
845 GEN6_PIPELINE_SELECT__SIZE
+
846 GEN6_3DSTATE_CLEAR_PARAMS__SIZE
+
847 GEN6_3DSTATE_DEPTH_BUFFER__SIZE
+
848 GEN6_3DSTATE_STENCIL_BUFFER__SIZE
+
849 GEN6_3DSTATE_HIER_DEPTH_BUFFER__SIZE
+
850 GEN6_3DSTATE_VERTEX_BUFFERS__SIZE
+
851 GEN6_3DSTATE_VERTEX_ELEMENTS__SIZE
+
852 GEN6_3DSTATE_INDEX_BUFFER__SIZE
+
853 GEN75_3DSTATE_VF__SIZE
+
854 GEN6_3DSTATE_VS__SIZE
+
855 GEN6_3DSTATE_GS__SIZE
+
856 GEN6_3DSTATE_CLIP__SIZE
+
857 GEN6_3DSTATE_SF__SIZE
+
858 GEN6_3DSTATE_WM__SIZE
+
859 GEN6_3DSTATE_SAMPLE_MASK__SIZE
+
860 GEN7_3DSTATE_HS__SIZE
+
861 GEN7_3DSTATE_TE__SIZE
+
862 GEN7_3DSTATE_DS__SIZE
+
863 GEN7_3DSTATE_STREAMOUT__SIZE
+
864 GEN7_3DSTATE_SBE__SIZE
+
865 GEN7_3DSTATE_PS__SIZE
+
866 GEN6_3DSTATE_DRAWING_RECTANGLE__SIZE
+
867 GEN6_3DSTATE_POLY_STIPPLE_OFFSET__SIZE
+
868 GEN6_3DSTATE_POLY_STIPPLE_PATTERN__SIZE
+
869 GEN6_3DSTATE_LINE_STIPPLE__SIZE
+
870 GEN6_3DSTATE_AA_LINE_PARAMETERS__SIZE
+
871 GEN6_3DSTATE_MULTISAMPLE__SIZE
+
872 GEN7_3DSTATE_SO_DECL_LIST__SIZE
+
873 GEN6_3DPRIMITIVE__SIZE
;