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 "util/u_dual_blend.h"
29 #include "util/u_prim.h"
30 #include "intel_reg.h"
32 #include "ilo_context.h"
34 #include "ilo_gpe_gen6.h"
35 #include "ilo_shader.h"
36 #include "ilo_state.h"
37 #include "ilo_3d_pipeline.h"
38 #include "ilo_3d_pipeline_gen6.h"
41 * This should be called before any depth stall flush (including those
42 * produced by non-pipelined state commands) or cache flush on GEN6.
44 * \see intel_emit_post_sync_nonzero_flush()
47 gen6_wa_pipe_control_post_sync(struct ilo_3d_pipeline
*p
,
48 bool caller_post_sync
)
50 assert(p
->dev
->gen
== ILO_GEN(6));
53 if (p
->state
.has_gen6_wa_pipe_control
)
56 p
->state
.has_gen6_wa_pipe_control
= true;
59 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
61 * "Pipe-control with CS-stall bit set must be sent BEFORE the
62 * pipe-control with a post-sync op and no write-cache flushes."
64 * The workaround below necessitates this workaround.
66 p
->gen6_PIPE_CONTROL(p
->dev
,
67 PIPE_CONTROL_CS_STALL
|
68 PIPE_CONTROL_STALL_AT_SCOREBOARD
,
69 NULL
, 0, false, p
->cp
);
71 /* the caller will emit the post-sync op */
76 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
78 * "Before any depth stall flush (including those produced by
79 * non-pipelined state commands), software needs to first send a
80 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
82 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
83 * PIPE_CONTROL with any non-zero post-sync-op is required."
85 p
->gen6_PIPE_CONTROL(p
->dev
,
86 PIPE_CONTROL_WRITE_IMMEDIATE
,
87 p
->workaround_bo
, 0, false, p
->cp
);
91 gen6_wa_pipe_control_wm_multisample_flush(struct ilo_3d_pipeline
*p
)
93 assert(p
->dev
->gen
== ILO_GEN(6));
95 gen6_wa_pipe_control_post_sync(p
, false);
98 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
100 * "Driver must guarentee that all the caches in the depth pipe are
101 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
102 * requires driver to send a PIPE_CONTROL with a CS stall along with a
103 * Depth Flush prior to this command."
105 p
->gen6_PIPE_CONTROL(p
->dev
,
106 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
107 PIPE_CONTROL_CS_STALL
,
112 gen6_wa_pipe_control_wm_depth_flush(struct ilo_3d_pipeline
*p
)
114 assert(p
->dev
->gen
== ILO_GEN(6));
116 gen6_wa_pipe_control_post_sync(p
, false);
119 * According to intel_emit_depth_stall_flushes() of classic i965, we need
120 * to emit a sequence of PIPE_CONTROLs prior to emitting depth related
123 p
->gen6_PIPE_CONTROL(p
->dev
,
124 PIPE_CONTROL_DEPTH_STALL
,
125 NULL
, 0, false, p
->cp
);
127 p
->gen6_PIPE_CONTROL(p
->dev
,
128 PIPE_CONTROL_DEPTH_CACHE_FLUSH
,
129 NULL
, 0, false, p
->cp
);
131 p
->gen6_PIPE_CONTROL(p
->dev
,
132 PIPE_CONTROL_DEPTH_STALL
,
133 NULL
, 0, false, p
->cp
);
137 gen6_wa_pipe_control_wm_max_threads_stall(struct ilo_3d_pipeline
*p
)
139 assert(p
->dev
->gen
== ILO_GEN(6));
141 /* the post-sync workaround should cover this already */
142 if (p
->state
.has_gen6_wa_pipe_control
)
146 * From the Sandy Bridge PRM, volume 2 part 1, page 274:
148 * "A PIPE_CONTROL command, with only the Stall At Pixel Scoreboard
149 * field set (DW1 Bit 1), must be issued prior to any change to the
150 * value in this field (Maximum Number of Threads in 3DSTATE_WM)"
152 p
->gen6_PIPE_CONTROL(p
->dev
,
153 PIPE_CONTROL_STALL_AT_SCOREBOARD
,
154 NULL
, 0, false, p
->cp
);
159 gen6_wa_pipe_control_vs_const_flush(struct ilo_3d_pipeline
*p
)
161 assert(p
->dev
->gen
== ILO_GEN(6));
163 gen6_wa_pipe_control_post_sync(p
, false);
166 * According to upload_vs_state() of classic i965, we need to emit
167 * PIPE_CONTROL after 3DSTATE_CONSTANT_VS so that the command is kept being
168 * buffered by VS FF, to the point that the FF dies.
170 p
->gen6_PIPE_CONTROL(p
->dev
,
171 PIPE_CONTROL_DEPTH_STALL
|
172 PIPE_CONTROL_INSTRUCTION_FLUSH
|
173 PIPE_CONTROL_STATE_CACHE_INVALIDATE
,
174 NULL
, 0, false, p
->cp
);
177 #define DIRTY(state) (session->pipe_dirty & ILO_DIRTY_ ## state)
180 gen6_pipeline_common_select(struct ilo_3d_pipeline
*p
,
181 const struct ilo_context
*ilo
,
182 struct gen6_pipeline_session
*session
)
184 /* PIPELINE_SELECT */
185 if (session
->hw_ctx_changed
) {
186 if (p
->dev
->gen
== ILO_GEN(6))
187 gen6_wa_pipe_control_post_sync(p
, false);
189 p
->gen6_PIPELINE_SELECT(p
->dev
, 0x0, p
->cp
);
194 gen6_pipeline_common_sip(struct ilo_3d_pipeline
*p
,
195 const struct ilo_context
*ilo
,
196 struct gen6_pipeline_session
*session
)
199 if (session
->hw_ctx_changed
) {
200 if (p
->dev
->gen
== ILO_GEN(6))
201 gen6_wa_pipe_control_post_sync(p
, false);
203 p
->gen6_STATE_SIP(p
->dev
, 0, p
->cp
);
208 gen6_pipeline_common_base_address(struct ilo_3d_pipeline
*p
,
209 const struct ilo_context
*ilo
,
210 struct gen6_pipeline_session
*session
)
212 /* STATE_BASE_ADDRESS */
213 if (session
->state_bo_changed
|| session
->instruction_bo_changed
) {
214 if (p
->dev
->gen
== ILO_GEN(6))
215 gen6_wa_pipe_control_post_sync(p
, false);
217 p
->gen6_STATE_BASE_ADDRESS(p
->dev
,
218 NULL
, p
->cp
->bo
, p
->cp
->bo
, NULL
, ilo
->shader_cache
->bo
,
222 * From the Sandy Bridge PRM, volume 1 part 1, page 28:
224 * "The following commands must be reissued following any change to
225 * the base addresses:
227 * * 3DSTATE_BINDING_TABLE_POINTERS
228 * * 3DSTATE_SAMPLER_STATE_POINTERS
229 * * 3DSTATE_VIEWPORT_STATE_POINTERS
230 * * 3DSTATE_CC_POINTERS
231 * * MEDIA_STATE_POINTERS"
233 * 3DSTATE_SCISSOR_STATE_POINTERS is not on the list, but it is
234 * reasonable to also reissue the command. Same to PCB.
236 session
->viewport_state_changed
= true;
238 session
->cc_state_blend_changed
= true;
239 session
->cc_state_dsa_changed
= true;
240 session
->cc_state_cc_changed
= true;
242 session
->scissor_state_changed
= true;
244 session
->binding_table_vs_changed
= true;
245 session
->binding_table_gs_changed
= true;
246 session
->binding_table_fs_changed
= true;
248 session
->sampler_state_vs_changed
= true;
249 session
->sampler_state_gs_changed
= true;
250 session
->sampler_state_fs_changed
= true;
252 session
->pcb_state_vs_changed
= true;
253 session
->pcb_state_gs_changed
= true;
254 session
->pcb_state_fs_changed
= true;
259 gen6_pipeline_common_urb(struct ilo_3d_pipeline
*p
,
260 const struct ilo_context
*ilo
,
261 struct gen6_pipeline_session
*session
)
264 if (DIRTY(VERTEX_ELEMENTS
) || DIRTY(VS
) || DIRTY(GS
)) {
265 const struct ilo_shader
*vs
= (ilo
->vs
) ? ilo
->vs
->shader
: NULL
;
266 const struct ilo_shader
*gs
= (ilo
->gs
) ? ilo
->gs
->shader
: NULL
;
267 const bool gs_active
= (gs
|| (vs
&& vs
->stream_output
));
268 int vs_entry_size
, gs_entry_size
;
269 int vs_total_size
, gs_total_size
;
271 vs_entry_size
= (vs
) ? vs
->out
.count
: 0;
274 * As indicated by 2e712e41db0c0676e9f30fc73172c0e8de8d84d4, VF and VS
275 * share VUE handles. The VUE allocation size must be large enough to
276 * store either VF outputs (number of VERTEX_ELEMENTs) and VS outputs.
278 * I am not sure if the PRM explicitly states that VF and VS share VUE
279 * handles. But here is a citation that implies so:
281 * From the Sandy Bridge PRM, volume 2 part 1, page 44:
283 * "Once a FF stage that spawn threads has sufficient input to
284 * initiate a thread, it must guarantee that it is safe to request
285 * the thread initiation. For all these FF stages, this check is
288 * - The availability of output URB entries:
289 * - VS: As the input URB entries are overwritten with the
290 * VS-generated output data, output URB availability isn't a
293 if (vs_entry_size
< ilo
->ve
->count
)
294 vs_entry_size
= ilo
->ve
->count
;
296 gs_entry_size
= (gs
) ? gs
->out
.count
:
297 (vs
&& vs
->stream_output
) ? vs_entry_size
: 0;
300 vs_entry_size
*= sizeof(float) * 4;
301 gs_entry_size
*= sizeof(float) * 4;
302 vs_total_size
= ilo
->dev
->urb_size
;
306 gs_total_size
= vs_total_size
;
312 p
->gen6_3DSTATE_URB(p
->dev
, vs_total_size
, gs_total_size
,
313 vs_entry_size
, gs_entry_size
, p
->cp
);
316 * From the Sandy Bridge PRM, volume 2 part 1, page 27:
318 * "Because of a urb corruption caused by allocating a previous
319 * gsunit's urb entry to vsunit software is required to send a
320 * "GS NULL Fence" (Send URB fence with VS URB size == 1 and GS URB
321 * size == 0) plus a dummy DRAW call before any case where VS will
322 * be taking over GS URB space."
324 if (p
->state
.gs
.active
&& !gs_active
)
325 ilo_3d_pipeline_emit_flush_gen6(p
);
327 p
->state
.gs
.active
= gs_active
;
332 gen6_pipeline_common_pointers_1(struct ilo_3d_pipeline
*p
,
333 const struct ilo_context
*ilo
,
334 struct gen6_pipeline_session
*session
)
336 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
337 if (session
->viewport_state_changed
) {
338 p
->gen6_3DSTATE_VIEWPORT_STATE_POINTERS(p
->dev
,
339 p
->state
.CLIP_VIEWPORT
,
340 p
->state
.SF_VIEWPORT
,
341 p
->state
.CC_VIEWPORT
, p
->cp
);
346 gen6_pipeline_common_pointers_2(struct ilo_3d_pipeline
*p
,
347 const struct ilo_context
*ilo
,
348 struct gen6_pipeline_session
*session
)
350 /* 3DSTATE_CC_STATE_POINTERS */
351 if (session
->cc_state_blend_changed
||
352 session
->cc_state_dsa_changed
||
353 session
->cc_state_cc_changed
) {
354 p
->gen6_3DSTATE_CC_STATE_POINTERS(p
->dev
,
355 p
->state
.BLEND_STATE
,
356 p
->state
.DEPTH_STENCIL_STATE
,
357 p
->state
.COLOR_CALC_STATE
, p
->cp
);
360 /* 3DSTATE_SAMPLER_STATE_POINTERS */
361 if (session
->sampler_state_vs_changed
||
362 session
->sampler_state_gs_changed
||
363 session
->sampler_state_fs_changed
) {
364 p
->gen6_3DSTATE_SAMPLER_STATE_POINTERS(p
->dev
,
365 p
->state
.vs
.SAMPLER_STATE
,
367 p
->state
.wm
.SAMPLER_STATE
, p
->cp
);
372 gen6_pipeline_common_pointers_3(struct ilo_3d_pipeline
*p
,
373 const struct ilo_context
*ilo
,
374 struct gen6_pipeline_session
*session
)
376 /* 3DSTATE_SCISSOR_STATE_POINTERS */
377 if (session
->scissor_state_changed
) {
378 p
->gen6_3DSTATE_SCISSOR_STATE_POINTERS(p
->dev
,
379 p
->state
.SCISSOR_RECT
, p
->cp
);
382 /* 3DSTATE_BINDING_TABLE_POINTERS */
383 if (session
->binding_table_vs_changed
||
384 session
->binding_table_gs_changed
||
385 session
->binding_table_fs_changed
) {
386 p
->gen6_3DSTATE_BINDING_TABLE_POINTERS(p
->dev
,
387 p
->state
.vs
.BINDING_TABLE_STATE
,
388 p
->state
.gs
.BINDING_TABLE_STATE
,
389 p
->state
.wm
.BINDING_TABLE_STATE
, p
->cp
);
394 gen6_pipeline_vf(struct ilo_3d_pipeline
*p
,
395 const struct ilo_context
*ilo
,
396 struct gen6_pipeline_session
*session
)
398 /* 3DSTATE_INDEX_BUFFER */
399 if (DIRTY(INDEX_BUFFER
)) {
400 p
->gen6_3DSTATE_INDEX_BUFFER(p
->dev
,
401 &ilo
->ib
.state
, session
->info
->primitive_restart
, p
->cp
);
404 /* 3DSTATE_VERTEX_BUFFERS */
405 if (DIRTY(VERTEX_BUFFERS
)) {
406 p
->gen6_3DSTATE_VERTEX_BUFFERS(p
->dev
,
407 ilo
->vb
.states
, NULL
, ilo
->vb
.enabled_mask
, p
->cp
);
410 /* 3DSTATE_VERTEX_ELEMENTS */
411 if (DIRTY(VERTEX_ELEMENTS
) || DIRTY(VS
)) {
412 const struct ilo_ve_state
*ve
= ilo
->ve
;
413 bool last_velement_edgeflag
= false;
414 bool prepend_generate_ids
= false;
417 const struct ilo_shader_info
*info
= &ilo
->vs
->info
;
419 if (info
->edgeflag_in
>= 0) {
420 /* we rely on the state tracker here */
421 assert(info
->edgeflag_in
== ve
->count
- 1);
422 last_velement_edgeflag
= true;
425 prepend_generate_ids
= (info
->has_instanceid
|| info
->has_vertexid
);
428 p
->gen6_3DSTATE_VERTEX_ELEMENTS(p
->dev
,
429 ve
->states
, ve
->count
,
430 last_velement_edgeflag
, prepend_generate_ids
, p
->cp
);
435 gen6_pipeline_vf_statistics(struct ilo_3d_pipeline
*p
,
436 const struct ilo_context
*ilo
,
437 struct gen6_pipeline_session
*session
)
439 /* 3DSTATE_VF_STATISTICS */
440 if (session
->hw_ctx_changed
)
441 p
->gen6_3DSTATE_VF_STATISTICS(p
->dev
, false, p
->cp
);
445 gen6_pipeline_vf_draw(struct ilo_3d_pipeline
*p
,
446 const struct ilo_context
*ilo
,
447 struct gen6_pipeline_session
*session
)
450 p
->gen6_3DPRIMITIVE(p
->dev
, session
->info
, false, p
->cp
);
451 p
->state
.has_gen6_wa_pipe_control
= false;
455 gen6_pipeline_vs(struct ilo_3d_pipeline
*p
,
456 const struct ilo_context
*ilo
,
457 struct gen6_pipeline_session
*session
)
459 const bool emit_3dstate_vs
= (DIRTY(VS
) || DIRTY(VERTEX_SAMPLERS
));
460 const bool emit_3dstate_constant_vs
= session
->pcb_state_vs_changed
;
463 * the classic i965 does this in upload_vs_state(), citing a spec that I
466 if (emit_3dstate_vs
&& p
->dev
->gen
== ILO_GEN(6))
467 gen6_wa_pipe_control_post_sync(p
, false);
469 /* 3DSTATE_CONSTANT_VS */
470 if (emit_3dstate_constant_vs
) {
471 p
->gen6_3DSTATE_CONSTANT_VS(p
->dev
,
472 &p
->state
.vs
.PUSH_CONSTANT_BUFFER
,
473 &p
->state
.vs
.PUSH_CONSTANT_BUFFER_size
,
478 if (emit_3dstate_vs
) {
479 const struct ilo_shader
*vs
= (ilo
->vs
)? ilo
->vs
->shader
: NULL
;
480 const int num_samplers
= ilo
->sampler
[PIPE_SHADER_VERTEX
].count
;
482 p
->gen6_3DSTATE_VS(p
->dev
, vs
, num_samplers
, p
->cp
);
485 if (emit_3dstate_constant_vs
&& p
->dev
->gen
== ILO_GEN(6))
486 gen6_wa_pipe_control_vs_const_flush(p
);
490 gen6_pipeline_gs(struct ilo_3d_pipeline
*p
,
491 const struct ilo_context
*ilo
,
492 struct gen6_pipeline_session
*session
)
494 /* 3DSTATE_CONSTANT_GS */
495 if (session
->pcb_state_gs_changed
)
496 p
->gen6_3DSTATE_CONSTANT_GS(p
->dev
, NULL
, NULL
, 0, p
->cp
);
499 if (DIRTY(GS
) || DIRTY(VS
) || session
->prim_changed
) {
500 const struct ilo_shader
*gs
= (ilo
->gs
)? ilo
->gs
->shader
: NULL
;
501 const struct ilo_shader
*vs
= (ilo
->vs
)? ilo
->vs
->shader
: NULL
;
502 const int num_vertices
= u_vertices_per_prim(session
->reduced_prim
);
505 assert(!gs
->pcb
.clip_state_size
);
507 p
->gen6_3DSTATE_GS(p
->dev
, gs
, vs
,
508 (vs
) ? vs
->cache_offset
+ vs
->gs_offsets
[num_vertices
- 1] : 0,
514 gen6_pipeline_update_max_svbi(struct ilo_3d_pipeline
*p
,
515 const struct ilo_context
*ilo
,
516 struct gen6_pipeline_session
*session
)
518 if (DIRTY(VS
) || DIRTY(GS
) || DIRTY(STREAM_OUTPUT_TARGETS
)) {
519 const struct pipe_stream_output_info
*so_info
=
520 (ilo
->gs
) ? &ilo
->gs
->info
.stream_output
:
521 (ilo
->vs
) ? &ilo
->vs
->info
.stream_output
: NULL
;
522 unsigned max_svbi
= 0xffffffff;
525 for (i
= 0; i
< so_info
->num_outputs
; i
++) {
526 const int output_buffer
= so_info
->output
[i
].output_buffer
;
527 const struct pipe_stream_output_target
*so
=
528 ilo
->so
.states
[output_buffer
];
529 const int struct_size
= so_info
->stride
[output_buffer
] * 4;
530 const int elem_size
= so_info
->output
[i
].num_components
* 4;
538 buf_size
= so
->buffer_size
- so_info
->output
[i
].dst_offset
* 4;
540 count
= buf_size
/ struct_size
;
541 if (buf_size
% struct_size
>= elem_size
)
544 if (count
< max_svbi
)
548 if (p
->state
.so_max_vertices
!= max_svbi
) {
549 p
->state
.so_max_vertices
= max_svbi
;
558 gen6_pipeline_gs_svbi(struct ilo_3d_pipeline
*p
,
559 const struct ilo_context
*ilo
,
560 struct gen6_pipeline_session
*session
)
562 const bool emit
= gen6_pipeline_update_max_svbi(p
, ilo
, session
);
564 /* 3DSTATE_GS_SVB_INDEX */
566 if (p
->dev
->gen
== ILO_GEN(6))
567 gen6_wa_pipe_control_post_sync(p
, false);
569 p
->gen6_3DSTATE_GS_SVB_INDEX(p
->dev
,
570 0, p
->state
.so_num_vertices
, p
->state
.so_max_vertices
,
573 if (session
->hw_ctx_changed
) {
577 * From the Sandy Bridge PRM, volume 2 part 1, page 148:
579 * "If a buffer is not enabled then the SVBI must be set to 0x0
580 * in order to not cause overflow in that SVBI."
582 * "If a buffer is not enabled then the MaxSVBI must be set to
583 * 0xFFFFFFFF in order to not cause overflow in that SVBI."
585 for (i
= 1; i
< 4; i
++) {
586 p
->gen6_3DSTATE_GS_SVB_INDEX(p
->dev
,
587 i
, 0, 0xffffffff, false, p
->cp
);
594 gen6_pipeline_clip(struct ilo_3d_pipeline
*p
,
595 const struct ilo_context
*ilo
,
596 struct gen6_pipeline_session
*session
)
599 if (DIRTY(RASTERIZER
) || DIRTY(FS
) ||
600 DIRTY(VIEWPORT
) || DIRTY(FRAMEBUFFER
)) {
601 const struct pipe_viewport_state
*vp
= &ilo
->viewport
.states
[0];
602 bool enable_guardband
;
603 float x1
, x2
, y1
, y2
;
606 * We do not do 2D clipping yet. Guard band test should only be enabled
607 * when the viewport is larger than the framebuffer.
609 x1
= fabs(vp
->scale
[0]) * -1.0f
+ vp
->translate
[0];
610 x2
= fabs(vp
->scale
[0]) * 1.0f
+ vp
->translate
[0];
611 y1
= fabs(vp
->scale
[1]) * -1.0f
+ vp
->translate
[1];
612 y2
= fabs(vp
->scale
[1]) * 1.0f
+ vp
->translate
[1];
614 (x1
<= 0.0f
&& x2
>= (float) ilo
->fb
.state
.width
&&
615 y1
<= 0.0f
&& y2
>= (float) ilo
->fb
.state
.height
);
617 p
->gen6_3DSTATE_CLIP(p
->dev
,
618 &ilo
->rasterizer
->state
,
619 (ilo
->fs
&& ilo
->fs
->shader
->in
.has_linear_interp
),
620 enable_guardband
, 1, p
->cp
);
625 gen6_pipeline_sf(struct ilo_3d_pipeline
*p
,
626 const struct ilo_context
*ilo
,
627 struct gen6_pipeline_session
*session
)
630 if (DIRTY(RASTERIZER
) || DIRTY(VS
) || DIRTY(GS
) || DIRTY(FS
)) {
631 const struct ilo_shader
*fs
= (ilo
->fs
)? ilo
->fs
->shader
: NULL
;
632 const struct ilo_shader
*last_sh
=
633 (ilo
->gs
)? ilo
->gs
->shader
:
634 (ilo
->vs
)? ilo
->vs
->shader
: NULL
;
636 p
->gen6_3DSTATE_SF(p
->dev
,
637 &ilo
->rasterizer
->state
, fs
, last_sh
, p
->cp
);
642 gen6_pipeline_sf_rect(struct ilo_3d_pipeline
*p
,
643 const struct ilo_context
*ilo
,
644 struct gen6_pipeline_session
*session
)
646 /* 3DSTATE_DRAWING_RECTANGLE */
647 if (DIRTY(FRAMEBUFFER
)) {
648 if (p
->dev
->gen
== ILO_GEN(6))
649 gen6_wa_pipe_control_post_sync(p
, false);
651 p
->gen6_3DSTATE_DRAWING_RECTANGLE(p
->dev
, 0, 0,
652 ilo
->fb
.state
.width
, ilo
->fb
.state
.height
, p
->cp
);
657 gen6_pipeline_wm(struct ilo_3d_pipeline
*p
,
658 const struct ilo_context
*ilo
,
659 struct gen6_pipeline_session
*session
)
661 /* 3DSTATE_CONSTANT_PS */
662 if (session
->pcb_state_fs_changed
)
663 p
->gen6_3DSTATE_CONSTANT_PS(p
->dev
, NULL
, NULL
, 0, p
->cp
);
666 if (DIRTY(FS
) || DIRTY(FRAGMENT_SAMPLERS
) ||
667 DIRTY(BLEND
) || DIRTY(DEPTH_STENCIL_ALPHA
) ||
669 const struct ilo_shader
*fs
= (ilo
->fs
)? ilo
->fs
->shader
: NULL
;
670 const int num_samplers
= ilo
->sampler
[PIPE_SHADER_FRAGMENT
].count
;
671 const bool dual_blend
=
672 (!ilo
->blend
->state
.logicop_enable
&&
673 ilo
->blend
->state
.rt
[0].blend_enable
&&
674 util_blend_state_is_dual(&ilo
->blend
->state
, 0));
675 const bool cc_may_kill
= (ilo
->dsa
->state
.alpha
.enabled
||
676 ilo
->blend
->state
.alpha_to_coverage
);
679 assert(!fs
->pcb
.clip_state_size
);
681 if (p
->dev
->gen
== ILO_GEN(6) && session
->hw_ctx_changed
)
682 gen6_wa_pipe_control_wm_max_threads_stall(p
);
684 p
->gen6_3DSTATE_WM(p
->dev
, fs
, num_samplers
,
685 &ilo
->rasterizer
->state
, dual_blend
, cc_may_kill
, p
->cp
);
690 gen6_pipeline_wm_multisample(struct ilo_3d_pipeline
*p
,
691 const struct ilo_context
*ilo
,
692 struct gen6_pipeline_session
*session
)
694 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
695 if (DIRTY(SAMPLE_MASK
) || DIRTY(FRAMEBUFFER
)) {
696 const uint32_t *packed_sample_pos
;
698 packed_sample_pos
= (ilo
->fb
.num_samples
> 1) ?
699 &p
->packed_sample_position_4x
: &p
->packed_sample_position_1x
;
701 if (p
->dev
->gen
== ILO_GEN(6)) {
702 gen6_wa_pipe_control_post_sync(p
, false);
703 gen6_wa_pipe_control_wm_multisample_flush(p
);
706 p
->gen6_3DSTATE_MULTISAMPLE(p
->dev
,
707 ilo
->fb
.num_samples
, packed_sample_pos
,
708 ilo
->rasterizer
->state
.half_pixel_center
, p
->cp
);
710 p
->gen6_3DSTATE_SAMPLE_MASK(p
->dev
,
711 (ilo
->fb
.num_samples
> 1) ? ilo
->sample_mask
: 0x1, p
->cp
);
716 gen6_pipeline_wm_depth(struct ilo_3d_pipeline
*p
,
717 const struct ilo_context
*ilo
,
718 struct gen6_pipeline_session
*session
)
720 /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
721 if (DIRTY(FRAMEBUFFER
)) {
722 if (p
->dev
->gen
== ILO_GEN(6)) {
723 gen6_wa_pipe_control_post_sync(p
, false);
724 gen6_wa_pipe_control_wm_depth_flush(p
);
727 p
->gen6_3DSTATE_DEPTH_BUFFER(p
->dev
,
728 ilo
->fb
.state
.zsbuf
, false, p
->cp
);
731 p
->gen6_3DSTATE_CLEAR_PARAMS(p
->dev
, 0, p
->cp
);
736 gen6_pipeline_wm_raster(struct ilo_3d_pipeline
*p
,
737 const struct ilo_context
*ilo
,
738 struct gen6_pipeline_session
*session
)
740 /* 3DSTATE_POLY_STIPPLE_PATTERN and 3DSTATE_POLY_STIPPLE_OFFSET */
741 if ((DIRTY(RASTERIZER
) || DIRTY(POLY_STIPPLE
)) &&
742 ilo
->rasterizer
->state
.poly_stipple_enable
) {
743 if (p
->dev
->gen
== ILO_GEN(6))
744 gen6_wa_pipe_control_post_sync(p
, false);
746 p
->gen6_3DSTATE_POLY_STIPPLE_PATTERN(p
->dev
,
747 &ilo
->poly_stipple
, p
->cp
);
749 p
->gen6_3DSTATE_POLY_STIPPLE_OFFSET(p
->dev
, 0, 0, p
->cp
);
752 /* 3DSTATE_LINE_STIPPLE */
753 if (DIRTY(RASTERIZER
) && ilo
->rasterizer
->state
.line_stipple_enable
) {
754 if (p
->dev
->gen
== ILO_GEN(6))
755 gen6_wa_pipe_control_post_sync(p
, false);
757 p
->gen6_3DSTATE_LINE_STIPPLE(p
->dev
,
758 ilo
->rasterizer
->state
.line_stipple_pattern
,
759 ilo
->rasterizer
->state
.line_stipple_factor
+ 1, p
->cp
);
762 /* 3DSTATE_AA_LINE_PARAMETERS */
763 if (DIRTY(RASTERIZER
) && ilo
->rasterizer
->state
.line_smooth
) {
764 if (p
->dev
->gen
== ILO_GEN(6))
765 gen6_wa_pipe_control_post_sync(p
, false);
767 p
->gen6_3DSTATE_AA_LINE_PARAMETERS(p
->dev
, p
->cp
);
772 gen6_pipeline_state_viewports(struct ilo_3d_pipeline
*p
,
773 const struct ilo_context
*ilo
,
774 struct gen6_pipeline_session
*session
)
776 /* SF_CLIP_VIEWPORT and CC_VIEWPORT */
777 if (p
->dev
->gen
>= ILO_GEN(7) && DIRTY(VIEWPORT
)) {
778 p
->state
.SF_CLIP_VIEWPORT
= p
->gen7_SF_CLIP_VIEWPORT(p
->dev
,
779 ilo
->viewport
.states
, ilo
->viewport
.count
, p
->cp
);
781 p
->state
.CC_VIEWPORT
= p
->gen6_CC_VIEWPORT(p
->dev
,
782 ilo
->viewport
.states
, ilo
->viewport
.count
, p
->cp
);
784 session
->viewport_state_changed
= true;
786 /* SF_VIEWPORT, CLIP_VIEWPORT, and CC_VIEWPORT */
787 else if (DIRTY(VIEWPORT
)) {
788 p
->state
.CLIP_VIEWPORT
= p
->gen6_CLIP_VIEWPORT(p
->dev
,
789 ilo
->viewport
.states
, ilo
->viewport
.count
, p
->cp
);
791 p
->state
.SF_VIEWPORT
= p
->gen6_SF_VIEWPORT(p
->dev
,
792 ilo
->viewport
.states
, ilo
->viewport
.count
, p
->cp
);
794 p
->state
.CC_VIEWPORT
= p
->gen6_CC_VIEWPORT(p
->dev
,
795 ilo
->viewport
.states
, ilo
->viewport
.count
, p
->cp
);
797 session
->viewport_state_changed
= true;
802 gen6_pipeline_state_cc(struct ilo_3d_pipeline
*p
,
803 const struct ilo_context
*ilo
,
804 struct gen6_pipeline_session
*session
)
807 if (DIRTY(BLEND
) || DIRTY(FRAMEBUFFER
) || DIRTY(DEPTH_STENCIL_ALPHA
)) {
808 p
->state
.BLEND_STATE
= p
->gen6_BLEND_STATE(p
->dev
,
809 &ilo
->blend
->state
, &ilo
->fb
, &ilo
->dsa
->state
.alpha
, p
->cp
);
811 session
->cc_state_blend_changed
= true;
814 /* COLOR_CALC_STATE */
815 if (DIRTY(DEPTH_STENCIL_ALPHA
) || DIRTY(STENCIL_REF
) || DIRTY(BLEND_COLOR
)) {
816 p
->state
.COLOR_CALC_STATE
=
817 p
->gen6_COLOR_CALC_STATE(p
->dev
, &ilo
->stencil_ref
,
818 ilo
->dsa
->state
.alpha
.ref_value
, &ilo
->blend_color
, p
->cp
);
820 session
->cc_state_cc_changed
= true;
823 /* DEPTH_STENCIL_STATE */
824 if (DIRTY(DEPTH_STENCIL_ALPHA
)) {
825 p
->state
.DEPTH_STENCIL_STATE
=
826 p
->gen6_DEPTH_STENCIL_STATE(p
->dev
, &ilo
->dsa
->state
, p
->cp
);
828 session
->cc_state_dsa_changed
= true;
833 gen6_pipeline_state_scissors(struct ilo_3d_pipeline
*p
,
834 const struct ilo_context
*ilo
,
835 struct gen6_pipeline_session
*session
)
838 if (DIRTY(SCISSOR
) || DIRTY(VIEWPORT
)) {
839 /* there should be as many scissors as there are viewports */
840 p
->state
.SCISSOR_RECT
= p
->gen6_SCISSOR_RECT(p
->dev
,
841 ilo
->scissor
.states
, ilo
->viewport
.count
, p
->cp
);
843 session
->scissor_state_changed
= true;
848 gen6_pipeline_state_surfaces_rt(struct ilo_3d_pipeline
*p
,
849 const struct ilo_context
*ilo
,
850 struct gen6_pipeline_session
*session
)
852 /* SURFACE_STATEs for render targets */
853 if (DIRTY(FRAMEBUFFER
)) {
854 const int offset
= ILO_WM_DRAW_SURFACE(0);
855 uint32_t *surface_state
= &p
->state
.wm
.SURFACE_STATE
[offset
];
858 for (i
= 0; i
< ilo
->fb
.state
.nr_cbufs
; i
++) {
859 const struct pipe_surface
*surface
= ilo
->fb
.state
.cbufs
[i
];
863 p
->gen6_surf_SURFACE_STATE(p
->dev
, surface
, p
->cp
);
867 * Upload at least one render target, as
868 * brw_update_renderbuffer_surfaces() does. I don't know why.
871 struct pipe_surface null_surface
;
873 memset(&null_surface
, 0, sizeof(null_surface
));
874 null_surface
.width
= ilo
->fb
.state
.width
;
875 null_surface
.height
= ilo
->fb
.state
.height
;
878 p
->gen6_surf_SURFACE_STATE(p
->dev
, &null_surface
, p
->cp
);
883 memset(&surface_state
[i
], 0, (ILO_MAX_DRAW_BUFFERS
- i
) * 4);
885 if (i
&& session
->num_surfaces
[PIPE_SHADER_FRAGMENT
] < offset
+ i
)
886 session
->num_surfaces
[PIPE_SHADER_FRAGMENT
] = offset
+ i
;
888 session
->binding_table_fs_changed
= true;
893 gen6_pipeline_state_surfaces_so(struct ilo_3d_pipeline
*p
,
894 const struct ilo_context
*ilo
,
895 struct gen6_pipeline_session
*session
)
897 const struct ilo_shader_state
*vs
= ilo
->vs
;
898 const struct ilo_shader_state
*gs
= ilo
->gs
;
899 const struct pipe_stream_output_target
**so_targets
=
900 (const struct pipe_stream_output_target
**) ilo
->so
.states
;
901 const int num_so_targets
= ilo
->so
.count
;
903 if (p
->dev
->gen
!= ILO_GEN(6))
906 /* SURFACE_STATEs for stream output targets */
907 if (DIRTY(VS
) || DIRTY(GS
) || DIRTY(STREAM_OUTPUT_TARGETS
)) {
908 const struct pipe_stream_output_info
*so_info
=
909 (gs
) ? &gs
->info
.stream_output
:
910 (vs
) ? &vs
->info
.stream_output
: NULL
;
911 const int offset
= ILO_GS_SO_SURFACE(0);
912 uint32_t *surface_state
= &p
->state
.gs
.SURFACE_STATE
[offset
];
915 for (i
= 0; so_info
&& i
< so_info
->num_outputs
; i
++) {
916 const int target
= so_info
->output
[i
].output_buffer
;
917 const struct pipe_stream_output_target
*so_target
=
918 (target
< num_so_targets
) ? so_targets
[target
] : NULL
;
921 surface_state
[i
] = p
->gen6_so_SURFACE_STATE(p
->dev
,
922 so_target
, so_info
, i
, p
->cp
);
925 surface_state
[i
] = 0;
929 memset(&surface_state
[i
], 0, (ILO_MAX_SO_BINDINGS
- i
) * 4);
931 if (i
&& session
->num_surfaces
[PIPE_SHADER_GEOMETRY
] < offset
+ i
)
932 session
->num_surfaces
[PIPE_SHADER_GEOMETRY
] = offset
+ i
;
934 session
->binding_table_gs_changed
= true;
939 gen6_pipeline_state_surfaces_view(struct ilo_3d_pipeline
*p
,
940 const struct ilo_context
*ilo
,
942 struct gen6_pipeline_session
*session
)
944 const struct pipe_sampler_view
**views
=
945 (const struct pipe_sampler_view
**) ilo
->view
[shader_type
].states
;
946 const int num_views
= ilo
->view
[shader_type
].count
;
947 uint32_t *surface_state
;
951 /* SURFACE_STATEs for sampler views */
952 switch (shader_type
) {
953 case PIPE_SHADER_VERTEX
:
954 if (DIRTY(VERTEX_SAMPLER_VIEWS
)) {
955 offset
= ILO_VS_TEXTURE_SURFACE(0);
956 surface_state
= &p
->state
.vs
.SURFACE_STATE
[offset
];
958 session
->binding_table_vs_changed
= true;
964 case PIPE_SHADER_FRAGMENT
:
965 if (DIRTY(FRAGMENT_SAMPLER_VIEWS
)) {
966 offset
= ILO_WM_TEXTURE_SURFACE(0);
967 surface_state
= &p
->state
.wm
.SURFACE_STATE
[offset
];
969 session
->binding_table_fs_changed
= true;
983 for (i
= 0; i
< num_views
; i
++) {
986 p
->gen6_view_SURFACE_STATE(p
->dev
, views
[i
], p
->cp
);
989 surface_state
[i
] = 0;
993 memset(&surface_state
[i
], 0, (ILO_MAX_SAMPLER_VIEWS
- i
) * 4);
995 if (i
&& session
->num_surfaces
[shader_type
] < offset
+ i
)
996 session
->num_surfaces
[shader_type
] = offset
+ i
;
1000 gen6_pipeline_state_surfaces_const(struct ilo_3d_pipeline
*p
,
1001 const struct ilo_context
*ilo
,
1003 struct gen6_pipeline_session
*session
)
1005 const struct pipe_constant_buffer
*buffers
=
1006 ilo
->cbuf
[shader_type
].states
;
1007 const int num_buffers
= ilo
->cbuf
[shader_type
].count
;
1008 uint32_t *surface_state
;
1012 /* SURFACE_STATEs for constant buffers */
1013 switch (shader_type
) {
1014 case PIPE_SHADER_VERTEX
:
1015 if (DIRTY(CONSTANT_BUFFER
)) {
1016 offset
= ILO_VS_CONST_SURFACE(0);
1017 surface_state
= &p
->state
.vs
.SURFACE_STATE
[offset
];
1019 session
->binding_table_vs_changed
= true;
1025 case PIPE_SHADER_FRAGMENT
:
1026 if (DIRTY(CONSTANT_BUFFER
)) {
1027 offset
= ILO_WM_CONST_SURFACE(0);
1028 surface_state
= &p
->state
.wm
.SURFACE_STATE
[offset
];
1030 session
->binding_table_fs_changed
= true;
1044 for (i
= 0; i
< num_buffers
; i
++) {
1045 if (buffers
[i
].buffer
) {
1047 p
->gen6_cbuf_SURFACE_STATE(p
->dev
, &buffers
[i
], p
->cp
);
1050 surface_state
[i
] = 0;
1054 memset(&surface_state
[i
], 0, (ILO_MAX_CONST_BUFFERS
- i
) * 4);
1056 if (i
&& session
->num_surfaces
[shader_type
] < offset
+ i
)
1057 session
->num_surfaces
[shader_type
] = offset
+ i
;
1061 gen6_pipeline_state_binding_tables(struct ilo_3d_pipeline
*p
,
1062 const struct ilo_context
*ilo
,
1064 struct gen6_pipeline_session
*session
)
1066 uint32_t *binding_table_state
, *surface_state
;
1067 int *binding_table_state_size
, size
;
1070 /* BINDING_TABLE_STATE */
1071 switch (shader_type
) {
1072 case PIPE_SHADER_VERTEX
:
1073 surface_state
= p
->state
.vs
.SURFACE_STATE
;
1074 binding_table_state
= &p
->state
.vs
.BINDING_TABLE_STATE
;
1075 binding_table_state_size
= &p
->state
.vs
.BINDING_TABLE_STATE_size
;
1077 skip
= !session
->binding_table_vs_changed
;
1079 case PIPE_SHADER_GEOMETRY
:
1080 surface_state
= p
->state
.gs
.SURFACE_STATE
;
1081 binding_table_state
= &p
->state
.gs
.BINDING_TABLE_STATE
;
1082 binding_table_state_size
= &p
->state
.gs
.BINDING_TABLE_STATE_size
;
1084 skip
= !session
->binding_table_gs_changed
;
1086 case PIPE_SHADER_FRAGMENT
:
1087 surface_state
= p
->state
.wm
.SURFACE_STATE
;
1088 binding_table_state
= &p
->state
.wm
.BINDING_TABLE_STATE
;
1089 binding_table_state_size
= &p
->state
.wm
.BINDING_TABLE_STATE_size
;
1091 skip
= !session
->binding_table_fs_changed
;
1102 * If we have seemingly less SURFACE_STATEs than before, it could be that
1103 * we did not touch those reside at the tail in this upload. Loop over
1104 * them to figure out the real number of SURFACE_STATEs.
1106 for (size
= *binding_table_state_size
;
1107 size
> session
->num_surfaces
[shader_type
]; size
--) {
1108 if (surface_state
[size
- 1])
1111 if (size
< session
->num_surfaces
[shader_type
])
1112 size
= session
->num_surfaces
[shader_type
];
1114 *binding_table_state
= p
->gen6_BINDING_TABLE_STATE(p
->dev
,
1115 surface_state
, size
, p
->cp
);
1116 *binding_table_state_size
= size
;
1120 gen6_pipeline_state_samplers(struct ilo_3d_pipeline
*p
,
1121 const struct ilo_context
*ilo
,
1123 struct gen6_pipeline_session
*session
)
1125 const struct pipe_sampler_state
**samplers
=
1126 (const struct pipe_sampler_state
**) ilo
->sampler
[shader_type
].states
;
1127 const struct pipe_sampler_view
**views
=
1128 (const struct pipe_sampler_view
**) ilo
->view
[shader_type
].states
;
1129 const int num_samplers
= ilo
->sampler
[shader_type
].count
;
1130 const int num_views
= ilo
->view
[shader_type
].count
;
1131 uint32_t *sampler_state
, *border_color_state
;
1132 bool emit_border_color
= false;
1135 /* SAMPLER_BORDER_COLOR_STATE and SAMPLER_STATE */
1136 switch (shader_type
) {
1137 case PIPE_SHADER_VERTEX
:
1138 if (DIRTY(VERTEX_SAMPLERS
) || DIRTY(VERTEX_SAMPLER_VIEWS
)) {
1139 sampler_state
= &p
->state
.vs
.SAMPLER_STATE
;
1140 border_color_state
= p
->state
.vs
.SAMPLER_BORDER_COLOR_STATE
;
1142 if (DIRTY(VERTEX_SAMPLERS
))
1143 emit_border_color
= true;
1145 session
->sampler_state_vs_changed
= true;
1151 case PIPE_SHADER_FRAGMENT
:
1152 if (DIRTY(FRAGMENT_SAMPLERS
) || DIRTY(FRAGMENT_SAMPLER_VIEWS
)) {
1153 sampler_state
= &p
->state
.wm
.SAMPLER_STATE
;
1154 border_color_state
= p
->state
.wm
.SAMPLER_BORDER_COLOR_STATE
;
1156 if (DIRTY(FRAGMENT_SAMPLERS
))
1157 emit_border_color
= true;
1159 session
->sampler_state_fs_changed
= true;
1173 if (emit_border_color
) {
1176 for (i
= 0; i
< num_samplers
; i
++) {
1177 border_color_state
[i
] = (samplers
[i
]) ?
1178 p
->gen6_SAMPLER_BORDER_COLOR_STATE(p
->dev
,
1179 &samplers
[i
]->border_color
, p
->cp
) : 0;
1183 /* should we take the minimum of num_samplers and num_views? */
1184 *sampler_state
= p
->gen6_SAMPLER_STATE(p
->dev
,
1187 MIN2(num_samplers
, num_views
), p
->cp
);
1191 gen6_pipeline_state_pcb(struct ilo_3d_pipeline
*p
,
1192 const struct ilo_context
*ilo
,
1193 struct gen6_pipeline_session
*session
)
1195 /* push constant buffer for VS */
1196 if (DIRTY(VS
) || DIRTY(CLIP
)) {
1197 const struct ilo_shader
*vs
= (ilo
->vs
)? ilo
->vs
->shader
: NULL
;
1199 if (vs
&& vs
->pcb
.clip_state_size
) {
1202 p
->state
.vs
.PUSH_CONSTANT_BUFFER_size
= vs
->pcb
.clip_state_size
;
1203 p
->state
.vs
.PUSH_CONSTANT_BUFFER
=
1204 p
->gen6_push_constant_buffer(p
->dev
,
1205 p
->state
.vs
.PUSH_CONSTANT_BUFFER_size
, &pcb
, p
->cp
);
1207 memcpy(pcb
, &ilo
->clip
, vs
->pcb
.clip_state_size
);
1210 p
->state
.vs
.PUSH_CONSTANT_BUFFER_size
= 0;
1211 p
->state
.vs
.PUSH_CONSTANT_BUFFER
= 0;
1214 session
->pcb_state_vs_changed
= true;
1221 gen6_pipeline_commands(struct ilo_3d_pipeline
*p
,
1222 const struct ilo_context
*ilo
,
1223 struct gen6_pipeline_session
*session
)
1226 * We try to keep the order of the commands match, as closely as possible,
1227 * that of the classic i965 driver. It allows us to compare the command
1230 gen6_pipeline_common_select(p
, ilo
, session
);
1231 gen6_pipeline_gs_svbi(p
, ilo
, session
);
1232 gen6_pipeline_common_sip(p
, ilo
, session
);
1233 gen6_pipeline_vf_statistics(p
, ilo
, session
);
1234 gen6_pipeline_common_base_address(p
, ilo
, session
);
1235 gen6_pipeline_common_pointers_1(p
, ilo
, session
);
1236 gen6_pipeline_common_urb(p
, ilo
, session
);
1237 gen6_pipeline_common_pointers_2(p
, ilo
, session
);
1238 gen6_pipeline_wm_multisample(p
, ilo
, session
);
1239 gen6_pipeline_vs(p
, ilo
, session
);
1240 gen6_pipeline_gs(p
, ilo
, session
);
1241 gen6_pipeline_clip(p
, ilo
, session
);
1242 gen6_pipeline_sf(p
, ilo
, session
);
1243 gen6_pipeline_wm(p
, ilo
, session
);
1244 gen6_pipeline_common_pointers_3(p
, ilo
, session
);
1245 gen6_pipeline_wm_depth(p
, ilo
, session
);
1246 gen6_pipeline_wm_raster(p
, ilo
, session
);
1247 gen6_pipeline_sf_rect(p
, ilo
, session
);
1248 gen6_pipeline_vf(p
, ilo
, session
);
1249 gen6_pipeline_vf_draw(p
, ilo
, session
);
1253 gen6_pipeline_states(struct ilo_3d_pipeline
*p
,
1254 const struct ilo_context
*ilo
,
1255 struct gen6_pipeline_session
*session
)
1259 gen6_pipeline_state_viewports(p
, ilo
, session
);
1260 gen6_pipeline_state_cc(p
, ilo
, session
);
1261 gen6_pipeline_state_scissors(p
, ilo
, session
);
1262 gen6_pipeline_state_pcb(p
, ilo
, session
);
1265 * upload all SURAFCE_STATEs together so that we know there are minimal
1268 gen6_pipeline_state_surfaces_rt(p
, ilo
, session
);
1269 gen6_pipeline_state_surfaces_so(p
, ilo
, session
);
1270 for (shader_type
= 0; shader_type
< PIPE_SHADER_TYPES
; shader_type
++) {
1271 gen6_pipeline_state_surfaces_view(p
, ilo
, shader_type
, session
);
1272 gen6_pipeline_state_surfaces_const(p
, ilo
, shader_type
, session
);
1275 for (shader_type
= 0; shader_type
< PIPE_SHADER_TYPES
; shader_type
++) {
1276 gen6_pipeline_state_samplers(p
, ilo
, shader_type
, session
);
1277 /* this must be called after all SURFACE_STATEs are uploaded */
1278 gen6_pipeline_state_binding_tables(p
, ilo
, shader_type
, session
);
1283 gen6_pipeline_prepare(const struct ilo_3d_pipeline
*p
,
1284 const struct ilo_context
*ilo
,
1285 const struct pipe_draw_info
*info
,
1286 struct gen6_pipeline_session
*session
)
1288 memset(session
, 0, sizeof(*session
));
1289 session
->info
= info
;
1290 session
->pipe_dirty
= ilo
->dirty
;
1291 session
->reduced_prim
= u_reduced_prim(info
->mode
);
1293 /* available space before the session */
1294 session
->init_cp_space
= ilo_cp_space(p
->cp
);
1296 session
->hw_ctx_changed
=
1297 (p
->invalidate_flags
& ILO_3D_PIPELINE_INVALIDATE_HW
);
1299 if (session
->hw_ctx_changed
) {
1300 /* these should be enough to make everything uploaded */
1301 session
->state_bo_changed
= true;
1302 session
->instruction_bo_changed
= true;
1303 session
->prim_changed
= true;
1306 session
->state_bo_changed
=
1307 (p
->invalidate_flags
& ILO_3D_PIPELINE_INVALIDATE_STATE_BO
);
1308 session
->instruction_bo_changed
=
1309 (p
->invalidate_flags
& ILO_3D_PIPELINE_INVALIDATE_KERNEL_BO
);
1310 session
->prim_changed
= (p
->state
.reduced_prim
!= session
->reduced_prim
);
1315 gen6_pipeline_draw(struct ilo_3d_pipeline
*p
,
1316 const struct ilo_context
*ilo
,
1317 struct gen6_pipeline_session
*session
)
1319 /* force all states to be uploaded if the state bo changed */
1320 if (session
->state_bo_changed
)
1321 session
->pipe_dirty
= ILO_DIRTY_ALL
;
1323 session
->pipe_dirty
= ilo
->dirty
;
1325 session
->emit_draw_states(p
, ilo
, session
);
1327 /* force all commands to be uploaded if the HW context changed */
1328 if (session
->hw_ctx_changed
)
1329 session
->pipe_dirty
= ILO_DIRTY_ALL
;
1331 session
->pipe_dirty
= ilo
->dirty
;
1333 session
->emit_draw_commands(p
, ilo
, session
);
1337 gen6_pipeline_end(struct ilo_3d_pipeline
*p
,
1338 const struct ilo_context
*ilo
,
1339 struct gen6_pipeline_session
*session
)
1343 /* sanity check size estimation */
1344 used
= session
->init_cp_space
- ilo_cp_space(p
->cp
);
1345 estimate
= ilo_3d_pipeline_estimate_size(p
, ILO_3D_PIPELINE_DRAW
, ilo
);
1346 assert(used
<= estimate
);
1348 p
->state
.reduced_prim
= session
->reduced_prim
;
1352 ilo_3d_pipeline_emit_draw_gen6(struct ilo_3d_pipeline
*p
,
1353 const struct ilo_context
*ilo
,
1354 const struct pipe_draw_info
*info
)
1356 struct gen6_pipeline_session session
;
1358 gen6_pipeline_prepare(p
, ilo
, info
, &session
);
1360 session
.emit_draw_states
= gen6_pipeline_states
;
1361 session
.emit_draw_commands
= gen6_pipeline_commands
;
1363 gen6_pipeline_draw(p
, ilo
, &session
);
1364 gen6_pipeline_end(p
, ilo
, &session
);
1368 ilo_3d_pipeline_emit_flush_gen6(struct ilo_3d_pipeline
*p
)
1370 if (p
->dev
->gen
== ILO_GEN(6))
1371 gen6_wa_pipe_control_post_sync(p
, false);
1373 p
->gen6_PIPE_CONTROL(p
->dev
,
1374 PIPE_CONTROL_INSTRUCTION_FLUSH
|
1375 PIPE_CONTROL_WRITE_FLUSH
|
1376 PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
1377 PIPE_CONTROL_VF_CACHE_INVALIDATE
|
1378 PIPE_CONTROL_TC_FLUSH
|
1379 PIPE_CONTROL_NO_WRITE
|
1380 PIPE_CONTROL_CS_STALL
,
1381 0, 0, false, p
->cp
);
1385 ilo_3d_pipeline_emit_write_timestamp_gen6(struct ilo_3d_pipeline
*p
,
1386 struct intel_bo
*bo
, int index
)
1388 if (p
->dev
->gen
== ILO_GEN(6))
1389 gen6_wa_pipe_control_post_sync(p
, true);
1391 p
->gen6_PIPE_CONTROL(p
->dev
,
1392 PIPE_CONTROL_WRITE_TIMESTAMP
,
1393 bo
, index
* sizeof(uint64_t) | PIPE_CONTROL_GLOBAL_GTT_WRITE
,
1398 ilo_3d_pipeline_emit_write_depth_count_gen6(struct ilo_3d_pipeline
*p
,
1399 struct intel_bo
*bo
, int index
)
1401 if (p
->dev
->gen
== ILO_GEN(6))
1402 gen6_wa_pipe_control_post_sync(p
, false);
1404 p
->gen6_PIPE_CONTROL(p
->dev
,
1405 PIPE_CONTROL_DEPTH_STALL
|
1406 PIPE_CONTROL_WRITE_DEPTH_COUNT
,
1407 bo
, index
* sizeof(uint64_t) | PIPE_CONTROL_GLOBAL_GTT_WRITE
,
1412 gen6_pipeline_estimate_commands(const struct ilo_3d_pipeline
*p
,
1413 const struct ilo_gpe_gen6
*gen6
,
1414 const struct ilo_context
*ilo
)
1417 enum ilo_gpe_gen6_command cmd
;
1422 for (cmd
= 0; cmd
< ILO_GPE_GEN6_COMMAND_COUNT
; cmd
++) {
1426 case ILO_GPE_GEN6_PIPE_CONTROL
:
1427 /* for the workaround */
1429 /* another one after 3DSTATE_URB */
1431 /* and another one after 3DSTATE_CONSTANT_VS */
1434 case ILO_GPE_GEN6_3DSTATE_GS_SVB_INDEX
:
1435 /* there are 4 SVBIs */
1438 case ILO_GPE_GEN6_3DSTATE_VERTEX_BUFFERS
:
1441 case ILO_GPE_GEN6_3DSTATE_VERTEX_ELEMENTS
:
1444 case ILO_GPE_GEN6_MEDIA_VFE_STATE
:
1445 case ILO_GPE_GEN6_MEDIA_CURBE_LOAD
:
1446 case ILO_GPE_GEN6_MEDIA_INTERFACE_DESCRIPTOR_LOAD
:
1447 case ILO_GPE_GEN6_MEDIA_GATEWAY_STATE
:
1448 case ILO_GPE_GEN6_MEDIA_STATE_FLUSH
:
1449 case ILO_GPE_GEN6_MEDIA_OBJECT_WALKER
:
1450 /* media commands */
1459 size
+= gen6
->estimate_command_size(p
->dev
, cmd
, count
);
1466 gen6_pipeline_estimate_states(const struct ilo_3d_pipeline
*p
,
1467 const struct ilo_gpe_gen6
*gen6
,
1468 const struct ilo_context
*ilo
)
1470 static int static_size
;
1471 int shader_type
, count
, size
;
1475 enum ilo_gpe_gen6_state state
;
1477 } static_states
[] = {
1479 { ILO_GPE_GEN6_SF_VIEWPORT
, 1 },
1480 { ILO_GPE_GEN6_CLIP_VIEWPORT
, 1 },
1481 { ILO_GPE_GEN6_CC_VIEWPORT
, 1 },
1483 { ILO_GPE_GEN6_COLOR_CALC_STATE
, 1 },
1484 { ILO_GPE_GEN6_BLEND_STATE
, ILO_MAX_DRAW_BUFFERS
},
1485 { ILO_GPE_GEN6_DEPTH_STENCIL_STATE
, 1 },
1487 { ILO_GPE_GEN6_SCISSOR_RECT
, 1 },
1488 /* binding table (vs, gs, fs) */
1489 { ILO_GPE_GEN6_BINDING_TABLE_STATE
, ILO_MAX_VS_SURFACES
},
1490 { ILO_GPE_GEN6_BINDING_TABLE_STATE
, ILO_MAX_GS_SURFACES
},
1491 { ILO_GPE_GEN6_BINDING_TABLE_STATE
, ILO_MAX_WM_SURFACES
},
1495 for (i
= 0; i
< Elements(static_states
); i
++) {
1496 static_size
+= gen6
->estimate_state_size(p
->dev
,
1497 static_states
[i
].state
,
1498 static_states
[i
].count
);
1505 * render targets (fs)
1506 * stream outputs (gs)
1507 * sampler views (vs, fs)
1508 * constant buffers (vs, fs)
1510 count
= ilo
->fb
.state
.nr_cbufs
;
1513 count
+= ilo
->gs
->info
.stream_output
.num_outputs
;
1515 count
+= ilo
->vs
->info
.stream_output
.num_outputs
;
1517 for (shader_type
= 0; shader_type
< PIPE_SHADER_TYPES
; shader_type
++) {
1518 count
+= ilo
->view
[shader_type
].count
;
1519 count
+= ilo
->cbuf
[shader_type
].count
;
1523 size
+= gen6
->estimate_state_size(p
->dev
,
1524 ILO_GPE_GEN6_SURFACE_STATE
, count
);
1527 /* samplers (vs, fs) */
1528 for (shader_type
= 0; shader_type
< PIPE_SHADER_TYPES
; shader_type
++) {
1529 count
= ilo
->sampler
[shader_type
].count
;
1531 size
+= gen6
->estimate_state_size(p
->dev
,
1532 ILO_GPE_GEN6_SAMPLER_BORDER_COLOR_STATE
, count
);
1533 size
+= gen6
->estimate_state_size(p
->dev
,
1534 ILO_GPE_GEN6_SAMPLER_STATE
, count
);
1539 if (ilo
->vs
&& ilo
->vs
->shader
->pcb
.clip_state_size
) {
1540 const int pcb_size
= ilo
->vs
->shader
->pcb
.clip_state_size
;
1542 size
+= gen6
->estimate_state_size(p
->dev
,
1543 ILO_GPE_GEN6_PUSH_CONSTANT_BUFFER
, pcb_size
);
1550 ilo_3d_pipeline_estimate_size_gen6(struct ilo_3d_pipeline
*p
,
1551 enum ilo_3d_pipeline_action action
,
1554 const struct ilo_gpe_gen6
*gen6
= ilo_gpe_gen6_get();
1558 case ILO_3D_PIPELINE_DRAW
:
1560 const struct ilo_context
*ilo
= arg
;
1562 size
= gen6_pipeline_estimate_commands(p
, gen6
, ilo
) +
1563 gen6_pipeline_estimate_states(p
, gen6
, ilo
);
1566 case ILO_3D_PIPELINE_FLUSH
:
1567 size
= gen6
->estimate_command_size(p
->dev
,
1568 ILO_GPE_GEN6_PIPE_CONTROL
, 1) * 3;
1570 case ILO_3D_PIPELINE_WRITE_TIMESTAMP
:
1571 size
= gen6
->estimate_command_size(p
->dev
,
1572 ILO_GPE_GEN6_PIPE_CONTROL
, 1) * 2;
1574 case ILO_3D_PIPELINE_WRITE_DEPTH_COUNT
:
1575 size
= gen6
->estimate_command_size(p
->dev
,
1576 ILO_GPE_GEN6_PIPE_CONTROL
, 1) * 3;
1579 assert(!"unknown 3D pipeline action");
1588 ilo_3d_pipeline_init_gen6(struct ilo_3d_pipeline
*p
)
1590 const struct ilo_gpe_gen6
*gen6
= ilo_gpe_gen6_get();
1592 p
->estimate_size
= ilo_3d_pipeline_estimate_size_gen6
;
1593 p
->emit_draw
= ilo_3d_pipeline_emit_draw_gen6
;
1594 p
->emit_flush
= ilo_3d_pipeline_emit_flush_gen6
;
1595 p
->emit_write_timestamp
= ilo_3d_pipeline_emit_write_timestamp_gen6
;
1596 p
->emit_write_depth_count
= ilo_3d_pipeline_emit_write_depth_count_gen6
;
1598 #define GEN6_USE(p, name, from) \
1599 p->gen6_ ## name = from->emit_ ## name
1600 GEN6_USE(p
, STATE_BASE_ADDRESS
, gen6
);
1601 GEN6_USE(p
, STATE_SIP
, gen6
);
1602 GEN6_USE(p
, PIPELINE_SELECT
, gen6
);
1603 GEN6_USE(p
, 3DSTATE_BINDING_TABLE_POINTERS
, gen6
);
1604 GEN6_USE(p
, 3DSTATE_SAMPLER_STATE_POINTERS
, gen6
);
1605 GEN6_USE(p
, 3DSTATE_URB
, gen6
);
1606 GEN6_USE(p
, 3DSTATE_VERTEX_BUFFERS
, gen6
);
1607 GEN6_USE(p
, 3DSTATE_VERTEX_ELEMENTS
, gen6
);
1608 GEN6_USE(p
, 3DSTATE_INDEX_BUFFER
, gen6
);
1609 GEN6_USE(p
, 3DSTATE_VF_STATISTICS
, gen6
);
1610 GEN6_USE(p
, 3DSTATE_VIEWPORT_STATE_POINTERS
, gen6
);
1611 GEN6_USE(p
, 3DSTATE_CC_STATE_POINTERS
, gen6
);
1612 GEN6_USE(p
, 3DSTATE_SCISSOR_STATE_POINTERS
, gen6
);
1613 GEN6_USE(p
, 3DSTATE_VS
, gen6
);
1614 GEN6_USE(p
, 3DSTATE_GS
, gen6
);
1615 GEN6_USE(p
, 3DSTATE_CLIP
, gen6
);
1616 GEN6_USE(p
, 3DSTATE_SF
, gen6
);
1617 GEN6_USE(p
, 3DSTATE_WM
, gen6
);
1618 GEN6_USE(p
, 3DSTATE_CONSTANT_VS
, gen6
);
1619 GEN6_USE(p
, 3DSTATE_CONSTANT_GS
, gen6
);
1620 GEN6_USE(p
, 3DSTATE_CONSTANT_PS
, gen6
);
1621 GEN6_USE(p
, 3DSTATE_SAMPLE_MASK
, gen6
);
1622 GEN6_USE(p
, 3DSTATE_DRAWING_RECTANGLE
, gen6
);
1623 GEN6_USE(p
, 3DSTATE_DEPTH_BUFFER
, gen6
);
1624 GEN6_USE(p
, 3DSTATE_POLY_STIPPLE_OFFSET
, gen6
);
1625 GEN6_USE(p
, 3DSTATE_POLY_STIPPLE_PATTERN
, gen6
);
1626 GEN6_USE(p
, 3DSTATE_LINE_STIPPLE
, gen6
);
1627 GEN6_USE(p
, 3DSTATE_AA_LINE_PARAMETERS
, gen6
);
1628 GEN6_USE(p
, 3DSTATE_GS_SVB_INDEX
, gen6
);
1629 GEN6_USE(p
, 3DSTATE_MULTISAMPLE
, gen6
);
1630 GEN6_USE(p
, 3DSTATE_STENCIL_BUFFER
, gen6
);
1631 GEN6_USE(p
, 3DSTATE_HIER_DEPTH_BUFFER
, gen6
);
1632 GEN6_USE(p
, 3DSTATE_CLEAR_PARAMS
, gen6
);
1633 GEN6_USE(p
, PIPE_CONTROL
, gen6
);
1634 GEN6_USE(p
, 3DPRIMITIVE
, gen6
);
1635 GEN6_USE(p
, INTERFACE_DESCRIPTOR_DATA
, gen6
);
1636 GEN6_USE(p
, SF_VIEWPORT
, gen6
);
1637 GEN6_USE(p
, CLIP_VIEWPORT
, gen6
);
1638 GEN6_USE(p
, CC_VIEWPORT
, gen6
);
1639 GEN6_USE(p
, COLOR_CALC_STATE
, gen6
);
1640 GEN6_USE(p
, BLEND_STATE
, gen6
);
1641 GEN6_USE(p
, DEPTH_STENCIL_STATE
, gen6
);
1642 GEN6_USE(p
, SCISSOR_RECT
, gen6
);
1643 GEN6_USE(p
, BINDING_TABLE_STATE
, gen6
);
1644 GEN6_USE(p
, surf_SURFACE_STATE
, gen6
);
1645 GEN6_USE(p
, view_SURFACE_STATE
, gen6
);
1646 GEN6_USE(p
, cbuf_SURFACE_STATE
, gen6
);
1647 GEN6_USE(p
, so_SURFACE_STATE
, gen6
);
1648 GEN6_USE(p
, SAMPLER_STATE
, gen6
);
1649 GEN6_USE(p
, SAMPLER_BORDER_COLOR_STATE
, gen6
);
1650 GEN6_USE(p
, push_constant_buffer
, gen6
);