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"
30 #include "util/u_prim.h"
32 #include "ilo_blitter.h"
33 #include "ilo_builder_3d.h"
34 #include "ilo_builder_mi.h"
35 #include "ilo_builder_render.h"
36 #include "ilo_query.h"
37 #include "ilo_shader.h"
38 #include "ilo_state.h"
39 #include "ilo_render.h"
40 #include "ilo_render_gen.h"
43 * A wrapper for gen6_PIPE_CONTROL().
46 gen6_pipe_control(struct ilo_3d_pipeline
*p
, uint32_t dw1
)
48 struct intel_bo
*bo
= (dw1
& GEN6_PIPE_CONTROL_WRITE__MASK
) ?
49 p
->workaround_bo
: NULL
;
51 ILO_DEV_ASSERT(p
->dev
, 6, 6);
53 gen6_PIPE_CONTROL(p
->builder
, dw1
, bo
, 0, false);
55 p
->state
.current_pipe_control_dw1
|= dw1
;
57 assert(!p
->state
.deferred_pipe_control_dw1
);
61 * This should be called before PIPE_CONTROL.
64 gen6_wa_pre_pipe_control(struct ilo_3d_pipeline
*p
, uint32_t dw1
)
67 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
69 * "Pipe-control with CS-stall bit set must be sent BEFORE the
70 * pipe-control with a post-sync op and no write-cache flushes."
72 * This WA may also be triggered indirectly by the other two WAs on the
75 * "Before any depth stall flush (including those produced by
76 * non-pipelined state commands), software needs to first send a
77 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
79 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
80 * PIPE_CONTROL with any non-zero post-sync-op is required."
82 const bool direct_wa_cond
= (dw1
& GEN6_PIPE_CONTROL_WRITE__MASK
) &&
83 !(dw1
& GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH
);
84 const bool indirect_wa_cond
= (dw1
& GEN6_PIPE_CONTROL_DEPTH_STALL
) |
85 (dw1
& GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH
);
87 ILO_DEV_ASSERT(p
->dev
, 6, 6);
89 if (!direct_wa_cond
&& !indirect_wa_cond
)
92 if (!(p
->state
.current_pipe_control_dw1
& GEN6_PIPE_CONTROL_CS_STALL
)) {
94 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
96 * "1 of the following must also be set (when CS stall is set):
98 * - Depth Cache Flush Enable ([0] of DW1)
99 * - Stall at Pixel Scoreboard ([1] of DW1)
100 * - Depth Stall ([13] of DW1)
101 * - Post-Sync Operation ([13] of DW1)
102 * - Render Target Cache Flush Enable ([12] of DW1)
103 * - Notify Enable ([8] of DW1)"
105 * Because of the WAs above, we have to pick Stall at Pixel Scoreboard.
107 const uint32_t direct_wa
= GEN6_PIPE_CONTROL_CS_STALL
|
108 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL
;
110 gen6_pipe_control(p
, direct_wa
);
113 if (indirect_wa_cond
&&
114 !(p
->state
.current_pipe_control_dw1
& GEN6_PIPE_CONTROL_WRITE__MASK
)) {
115 const uint32_t indirect_wa
= GEN6_PIPE_CONTROL_WRITE_IMM
;
117 gen6_pipe_control(p
, indirect_wa
);
122 * This should be called before any non-pipelined state command.
125 gen6_wa_pre_non_pipelined(struct ilo_3d_pipeline
*p
)
127 ILO_DEV_ASSERT(p
->dev
, 6, 6);
129 /* non-pipelined state commands produce depth stall */
130 gen6_wa_pre_pipe_control(p
, GEN6_PIPE_CONTROL_DEPTH_STALL
);
134 gen6_wa_post_3dstate_constant_vs(struct ilo_3d_pipeline
*p
)
137 * According to upload_vs_state() of the classic driver, we need to emit a
138 * PIPE_CONTROL after 3DSTATE_CONSTANT_VS, otherwise the command is kept
139 * being buffered by VS FF, to the point that the FF dies.
141 const uint32_t dw1
= GEN6_PIPE_CONTROL_DEPTH_STALL
|
142 GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE
|
143 GEN6_PIPE_CONTROL_STATE_CACHE_INVALIDATE
;
145 gen6_wa_pre_pipe_control(p
, dw1
);
147 if ((p
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
148 gen6_pipe_control(p
, dw1
);
152 gen6_wa_pre_3dstate_wm_max_threads(struct ilo_3d_pipeline
*p
)
155 * From the Sandy Bridge PRM, volume 2 part 1, page 274:
157 * "A PIPE_CONTROL command, with only the Stall At Pixel Scoreboard
158 * field set (DW1 Bit 1), must be issued prior to any change to the
159 * value in this field (Maximum Number of Threads in 3DSTATE_WM)"
161 const uint32_t dw1
= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL
;
163 ILO_DEV_ASSERT(p
->dev
, 6, 6);
165 gen6_wa_pre_pipe_control(p
, dw1
);
167 if ((p
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
168 gen6_pipe_control(p
, dw1
);
172 gen6_wa_pre_3dstate_multisample(struct ilo_3d_pipeline
*p
)
175 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
177 * "Driver must guarentee that all the caches in the depth pipe are
178 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
179 * requires driver to send a PIPE_CONTROL with a CS stall along with a
180 * Depth Flush prior to this command."
182 const uint32_t dw1
= GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
183 GEN6_PIPE_CONTROL_CS_STALL
;
185 ILO_DEV_ASSERT(p
->dev
, 6, 6);
187 gen6_wa_pre_pipe_control(p
, dw1
);
189 if ((p
->state
.current_pipe_control_dw1
& dw1
) != dw1
)
190 gen6_pipe_control(p
, dw1
);
194 gen6_wa_pre_depth(struct ilo_3d_pipeline
*p
)
196 ILO_DEV_ASSERT(p
->dev
, 6, 6);
199 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
201 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
202 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
203 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
204 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
205 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
206 * Depth Flush Bit set, followed by another pipelined depth stall
207 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
208 * guarantee that the pipeline from WM onwards is already flushed
209 * (e.g., via a preceding MI_FLUSH)."
211 * According to the classic driver, it also applies for GEN6.
213 gen6_wa_pre_pipe_control(p
, GEN6_PIPE_CONTROL_DEPTH_STALL
|
214 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
);
216 gen6_pipe_control(p
, GEN6_PIPE_CONTROL_DEPTH_STALL
);
217 gen6_pipe_control(p
, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
);
218 gen6_pipe_control(p
, GEN6_PIPE_CONTROL_DEPTH_STALL
);
221 #define DIRTY(state) (session->pipe_dirty & ILO_DIRTY_ ## state)
224 gen6_pipeline_common_select(struct ilo_3d_pipeline
*p
,
225 const struct ilo_state_vector
*vec
,
226 struct gen6_pipeline_session
*session
)
228 /* PIPELINE_SELECT */
229 if (session
->hw_ctx_changed
) {
230 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
231 gen6_wa_pre_non_pipelined(p
);
233 gen6_PIPELINE_SELECT(p
->builder
, 0x0);
238 gen6_pipeline_common_sip(struct ilo_3d_pipeline
*p
,
239 const struct ilo_state_vector
*vec
,
240 struct gen6_pipeline_session
*session
)
243 if (session
->hw_ctx_changed
) {
244 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
245 gen6_wa_pre_non_pipelined(p
);
247 gen6_STATE_SIP(p
->builder
, 0);
252 gen6_pipeline_common_base_address(struct ilo_3d_pipeline
*p
,
253 const struct ilo_state_vector
*vec
,
254 struct gen6_pipeline_session
*session
)
256 /* STATE_BASE_ADDRESS */
257 if (session
->state_bo_changed
|| session
->kernel_bo_changed
||
258 session
->batch_bo_changed
) {
259 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
260 gen6_wa_pre_non_pipelined(p
);
262 gen6_state_base_address(p
->builder
, session
->hw_ctx_changed
);
265 * From the Sandy Bridge PRM, volume 1 part 1, page 28:
267 * "The following commands must be reissued following any change to
268 * the base addresses:
270 * * 3DSTATE_BINDING_TABLE_POINTERS
271 * * 3DSTATE_SAMPLER_STATE_POINTERS
272 * * 3DSTATE_VIEWPORT_STATE_POINTERS
273 * * 3DSTATE_CC_POINTERS
274 * * MEDIA_STATE_POINTERS"
276 * 3DSTATE_SCISSOR_STATE_POINTERS is not on the list, but it is
277 * reasonable to also reissue the command. Same to PCB.
279 session
->viewport_state_changed
= true;
281 session
->cc_state_blend_changed
= true;
282 session
->cc_state_dsa_changed
= true;
283 session
->cc_state_cc_changed
= true;
285 session
->scissor_state_changed
= true;
287 session
->binding_table_vs_changed
= true;
288 session
->binding_table_gs_changed
= true;
289 session
->binding_table_fs_changed
= true;
291 session
->sampler_state_vs_changed
= true;
292 session
->sampler_state_gs_changed
= true;
293 session
->sampler_state_fs_changed
= true;
295 session
->pcb_state_vs_changed
= true;
296 session
->pcb_state_gs_changed
= true;
297 session
->pcb_state_fs_changed
= true;
302 gen6_pipeline_common_urb(struct ilo_3d_pipeline
*p
,
303 const struct ilo_state_vector
*vec
,
304 struct gen6_pipeline_session
*session
)
307 if (DIRTY(VE
) || DIRTY(VS
) || DIRTY(GS
)) {
308 const bool gs_active
= (vec
->gs
|| (vec
->vs
&&
309 ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_VS_GEN6_SO
)));
310 int vs_entry_size
, gs_entry_size
;
311 int vs_total_size
, gs_total_size
;
313 vs_entry_size
= (vec
->vs
) ?
314 ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_OUTPUT_COUNT
) : 0;
317 * As indicated by 2e712e41db0c0676e9f30fc73172c0e8de8d84d4, VF and VS
318 * share VUE handles. The VUE allocation size must be large enough to
319 * store either VF outputs (number of VERTEX_ELEMENTs) and VS outputs.
321 * I am not sure if the PRM explicitly states that VF and VS share VUE
322 * handles. But here is a citation that implies so:
324 * From the Sandy Bridge PRM, volume 2 part 1, page 44:
326 * "Once a FF stage that spawn threads has sufficient input to
327 * initiate a thread, it must guarantee that it is safe to request
328 * the thread initiation. For all these FF stages, this check is
331 * - The availability of output URB entries:
332 * - VS: As the input URB entries are overwritten with the
333 * VS-generated output data, output URB availability isn't a
336 if (vs_entry_size
< vec
->ve
->count
)
337 vs_entry_size
= vec
->ve
->count
;
339 gs_entry_size
= (vec
->gs
) ?
340 ilo_shader_get_kernel_param(vec
->gs
, ILO_KERNEL_OUTPUT_COUNT
) :
341 (gs_active
) ? vs_entry_size
: 0;
344 vs_entry_size
*= sizeof(float) * 4;
345 gs_entry_size
*= sizeof(float) * 4;
346 vs_total_size
= p
->dev
->urb_size
;
350 gs_total_size
= vs_total_size
;
356 gen6_3DSTATE_URB(p
->builder
, vs_total_size
, gs_total_size
,
357 vs_entry_size
, gs_entry_size
);
360 * From the Sandy Bridge PRM, volume 2 part 1, page 27:
362 * "Because of a urb corruption caused by allocating a previous
363 * gsunit's urb entry to vsunit software is required to send a
364 * "GS NULL Fence" (Send URB fence with VS URB size == 1 and GS URB
365 * size == 0) plus a dummy DRAW call before any case where VS will
366 * be taking over GS URB space."
368 if (p
->state
.gs
.active
&& !gs_active
)
369 ilo_3d_pipeline_emit_flush_gen6(p
);
371 p
->state
.gs
.active
= gs_active
;
376 gen6_pipeline_common_pointers_1(struct ilo_3d_pipeline
*p
,
377 const struct ilo_state_vector
*vec
,
378 struct gen6_pipeline_session
*session
)
380 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
381 if (session
->viewport_state_changed
) {
382 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(p
->builder
,
383 p
->state
.CLIP_VIEWPORT
,
384 p
->state
.SF_VIEWPORT
,
385 p
->state
.CC_VIEWPORT
);
390 gen6_pipeline_common_pointers_2(struct ilo_3d_pipeline
*p
,
391 const struct ilo_state_vector
*vec
,
392 struct gen6_pipeline_session
*session
)
394 /* 3DSTATE_CC_STATE_POINTERS */
395 if (session
->cc_state_blend_changed
||
396 session
->cc_state_dsa_changed
||
397 session
->cc_state_cc_changed
) {
398 gen6_3DSTATE_CC_STATE_POINTERS(p
->builder
,
399 p
->state
.BLEND_STATE
,
400 p
->state
.DEPTH_STENCIL_STATE
,
401 p
->state
.COLOR_CALC_STATE
);
404 /* 3DSTATE_SAMPLER_STATE_POINTERS */
405 if (session
->sampler_state_vs_changed
||
406 session
->sampler_state_gs_changed
||
407 session
->sampler_state_fs_changed
) {
408 gen6_3DSTATE_SAMPLER_STATE_POINTERS(p
->builder
,
409 p
->state
.vs
.SAMPLER_STATE
,
411 p
->state
.wm
.SAMPLER_STATE
);
416 gen6_pipeline_common_pointers_3(struct ilo_3d_pipeline
*p
,
417 const struct ilo_state_vector
*vec
,
418 struct gen6_pipeline_session
*session
)
420 /* 3DSTATE_SCISSOR_STATE_POINTERS */
421 if (session
->scissor_state_changed
) {
422 gen6_3DSTATE_SCISSOR_STATE_POINTERS(p
->builder
,
423 p
->state
.SCISSOR_RECT
);
426 /* 3DSTATE_BINDING_TABLE_POINTERS */
427 if (session
->binding_table_vs_changed
||
428 session
->binding_table_gs_changed
||
429 session
->binding_table_fs_changed
) {
430 gen6_3DSTATE_BINDING_TABLE_POINTERS(p
->builder
,
431 p
->state
.vs
.BINDING_TABLE_STATE
,
432 p
->state
.gs
.BINDING_TABLE_STATE
,
433 p
->state
.wm
.BINDING_TABLE_STATE
);
438 gen6_pipeline_vf(struct ilo_3d_pipeline
*p
,
439 const struct ilo_state_vector
*vec
,
440 struct gen6_pipeline_session
*session
)
442 if (ilo_dev_gen(p
->dev
) >= ILO_GEN(7.5)) {
443 /* 3DSTATE_INDEX_BUFFER */
444 if (DIRTY(IB
) || session
->batch_bo_changed
) {
445 gen6_3DSTATE_INDEX_BUFFER(p
->builder
,
450 if (session
->primitive_restart_changed
) {
451 gen7_3DSTATE_VF(p
->builder
, vec
->draw
->primitive_restart
,
452 vec
->draw
->restart_index
);
456 /* 3DSTATE_INDEX_BUFFER */
457 if (DIRTY(IB
) || session
->primitive_restart_changed
||
458 session
->batch_bo_changed
) {
459 gen6_3DSTATE_INDEX_BUFFER(p
->builder
,
460 &vec
->ib
, vec
->draw
->primitive_restart
);
464 /* 3DSTATE_VERTEX_BUFFERS */
465 if (DIRTY(VB
) || DIRTY(VE
) || session
->batch_bo_changed
)
466 gen6_3DSTATE_VERTEX_BUFFERS(p
->builder
, vec
->ve
, &vec
->vb
);
468 /* 3DSTATE_VERTEX_ELEMENTS */
469 if (DIRTY(VE
) || DIRTY(VS
)) {
470 const struct ilo_ve_state
*ve
= vec
->ve
;
471 bool last_velement_edgeflag
= false;
472 bool prepend_generate_ids
= false;
475 if (ilo_shader_get_kernel_param(vec
->vs
,
476 ILO_KERNEL_VS_INPUT_EDGEFLAG
)) {
477 /* we rely on the state tracker here */
478 assert(ilo_shader_get_kernel_param(vec
->vs
,
479 ILO_KERNEL_INPUT_COUNT
) == ve
->count
);
481 last_velement_edgeflag
= true;
484 if (ilo_shader_get_kernel_param(vec
->vs
,
485 ILO_KERNEL_VS_INPUT_INSTANCEID
) ||
486 ilo_shader_get_kernel_param(vec
->vs
,
487 ILO_KERNEL_VS_INPUT_VERTEXID
))
488 prepend_generate_ids
= true;
491 gen6_3DSTATE_VERTEX_ELEMENTS(p
->builder
, ve
,
492 last_velement_edgeflag
, prepend_generate_ids
);
497 gen6_pipeline_vf_statistics(struct ilo_3d_pipeline
*p
,
498 const struct ilo_state_vector
*vec
,
499 struct gen6_pipeline_session
*session
)
501 /* 3DSTATE_VF_STATISTICS */
502 if (session
->hw_ctx_changed
)
503 gen6_3DSTATE_VF_STATISTICS(p
->builder
, false);
507 gen6_pipeline_vf_draw(struct ilo_3d_pipeline
*p
,
508 const struct ilo_state_vector
*vec
,
509 struct gen6_pipeline_session
*session
)
512 gen6_3DPRIMITIVE(p
->builder
, vec
->draw
, &vec
->ib
);
514 p
->state
.current_pipe_control_dw1
= 0;
515 assert(!p
->state
.deferred_pipe_control_dw1
);
519 gen6_pipeline_vs(struct ilo_3d_pipeline
*p
,
520 const struct ilo_state_vector
*vec
,
521 struct gen6_pipeline_session
*session
)
523 const bool emit_3dstate_vs
= (DIRTY(VS
) || DIRTY(SAMPLER_VS
) ||
524 session
->kernel_bo_changed
);
525 const bool emit_3dstate_constant_vs
= session
->pcb_state_vs_changed
;
528 * the classic i965 does this in upload_vs_state(), citing a spec that I
531 if (emit_3dstate_vs
&& ilo_dev_gen(p
->dev
) == ILO_GEN(6))
532 gen6_wa_pre_non_pipelined(p
);
534 /* 3DSTATE_CONSTANT_VS */
535 if (emit_3dstate_constant_vs
) {
536 gen6_3DSTATE_CONSTANT_VS(p
->builder
,
537 &p
->state
.vs
.PUSH_CONSTANT_BUFFER
,
538 &p
->state
.vs
.PUSH_CONSTANT_BUFFER_size
,
543 if (emit_3dstate_vs
) {
544 const int num_samplers
= vec
->sampler
[PIPE_SHADER_VERTEX
].count
;
546 gen6_3DSTATE_VS(p
->builder
, vec
->vs
, num_samplers
);
549 if (emit_3dstate_constant_vs
&& ilo_dev_gen(p
->dev
) == ILO_GEN(6))
550 gen6_wa_post_3dstate_constant_vs(p
);
554 gen6_pipeline_gs(struct ilo_3d_pipeline
*p
,
555 const struct ilo_state_vector
*vec
,
556 struct gen6_pipeline_session
*session
)
558 /* 3DSTATE_CONSTANT_GS */
559 if (session
->pcb_state_gs_changed
)
560 gen6_3DSTATE_CONSTANT_GS(p
->builder
, NULL
, NULL
, 0);
563 if (DIRTY(GS
) || DIRTY(VS
) ||
564 session
->prim_changed
|| session
->kernel_bo_changed
) {
565 const int verts_per_prim
= u_vertices_per_prim(session
->reduced_prim
);
567 gen6_3DSTATE_GS(p
->builder
, vec
->gs
, vec
->vs
, verts_per_prim
);
572 gen6_pipeline_update_max_svbi(struct ilo_3d_pipeline
*p
,
573 const struct ilo_state_vector
*vec
,
574 struct gen6_pipeline_session
*session
)
576 if (DIRTY(VS
) || DIRTY(GS
) || DIRTY(SO
)) {
577 const struct pipe_stream_output_info
*so_info
=
578 (vec
->gs
) ? ilo_shader_get_kernel_so_info(vec
->gs
) :
579 (vec
->vs
) ? ilo_shader_get_kernel_so_info(vec
->vs
) : NULL
;
580 unsigned max_svbi
= 0xffffffff;
583 for (i
= 0; i
< so_info
->num_outputs
; i
++) {
584 const int output_buffer
= so_info
->output
[i
].output_buffer
;
585 const struct pipe_stream_output_target
*so
=
586 vec
->so
.states
[output_buffer
];
587 const int struct_size
= so_info
->stride
[output_buffer
] * 4;
588 const int elem_size
= so_info
->output
[i
].num_components
* 4;
596 buf_size
= so
->buffer_size
- so_info
->output
[i
].dst_offset
* 4;
598 count
= buf_size
/ struct_size
;
599 if (buf_size
% struct_size
>= elem_size
)
602 if (count
< max_svbi
)
606 if (p
->state
.so_max_vertices
!= max_svbi
) {
607 p
->state
.so_max_vertices
= max_svbi
;
616 gen6_pipeline_gs_svbi(struct ilo_3d_pipeline
*p
,
617 const struct ilo_state_vector
*vec
,
618 struct gen6_pipeline_session
*session
)
620 const bool emit
= gen6_pipeline_update_max_svbi(p
, vec
, session
);
622 /* 3DSTATE_GS_SVB_INDEX */
624 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
625 gen6_wa_pre_non_pipelined(p
);
627 gen6_3DSTATE_GS_SVB_INDEX(p
->builder
,
628 0, 0, p
->state
.so_max_vertices
,
631 if (session
->hw_ctx_changed
) {
635 * From the Sandy Bridge PRM, volume 2 part 1, page 148:
637 * "If a buffer is not enabled then the SVBI must be set to 0x0
638 * in order to not cause overflow in that SVBI."
640 * "If a buffer is not enabled then the MaxSVBI must be set to
641 * 0xFFFFFFFF in order to not cause overflow in that SVBI."
643 for (i
= 1; i
< 4; i
++) {
644 gen6_3DSTATE_GS_SVB_INDEX(p
->builder
,
645 i
, 0, 0xffffffff, false);
652 gen6_pipeline_clip(struct ilo_3d_pipeline
*p
,
653 const struct ilo_state_vector
*vec
,
654 struct gen6_pipeline_session
*session
)
657 if (DIRTY(RASTERIZER
) || DIRTY(FS
) || DIRTY(VIEWPORT
) || DIRTY(FB
)) {
658 bool enable_guardband
= true;
662 * We do not do 2D clipping yet. Guard band test should only be enabled
663 * when the viewport is larger than the framebuffer.
665 for (i
= 0; i
< vec
->viewport
.count
; i
++) {
666 const struct ilo_viewport_cso
*vp
= &vec
->viewport
.cso
[i
];
668 if (vp
->min_x
> 0.0f
|| vp
->max_x
< vec
->fb
.state
.width
||
669 vp
->min_y
> 0.0f
|| vp
->max_y
< vec
->fb
.state
.height
) {
670 enable_guardband
= false;
675 gen6_3DSTATE_CLIP(p
->builder
, vec
->rasterizer
,
676 vec
->fs
, enable_guardband
, 1);
681 gen6_pipeline_sf(struct ilo_3d_pipeline
*p
,
682 const struct ilo_state_vector
*vec
,
683 struct gen6_pipeline_session
*session
)
686 if (DIRTY(RASTERIZER
) || DIRTY(FS
))
687 gen6_3DSTATE_SF(p
->builder
, vec
->rasterizer
, vec
->fs
);
691 gen6_pipeline_sf_rect(struct ilo_3d_pipeline
*p
,
692 const struct ilo_state_vector
*vec
,
693 struct gen6_pipeline_session
*session
)
695 /* 3DSTATE_DRAWING_RECTANGLE */
697 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
698 gen6_wa_pre_non_pipelined(p
);
700 gen6_3DSTATE_DRAWING_RECTANGLE(p
->builder
, 0, 0,
701 vec
->fb
.state
.width
, vec
->fb
.state
.height
);
706 gen6_pipeline_wm(struct ilo_3d_pipeline
*p
,
707 const struct ilo_state_vector
*vec
,
708 struct gen6_pipeline_session
*session
)
710 /* 3DSTATE_CONSTANT_PS */
711 if (session
->pcb_state_fs_changed
) {
712 gen6_3DSTATE_CONSTANT_PS(p
->builder
,
713 &p
->state
.wm
.PUSH_CONSTANT_BUFFER
,
714 &p
->state
.wm
.PUSH_CONSTANT_BUFFER_size
,
719 if (DIRTY(FS
) || DIRTY(SAMPLER_FS
) || DIRTY(BLEND
) || DIRTY(DSA
) ||
720 DIRTY(RASTERIZER
) || session
->kernel_bo_changed
) {
721 const int num_samplers
= vec
->sampler
[PIPE_SHADER_FRAGMENT
].count
;
722 const bool dual_blend
= vec
->blend
->dual_blend
;
723 const bool cc_may_kill
= (vec
->dsa
->dw_alpha
||
724 vec
->blend
->alpha_to_coverage
);
726 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6) && session
->hw_ctx_changed
)
727 gen6_wa_pre_3dstate_wm_max_threads(p
);
729 gen6_3DSTATE_WM(p
->builder
, vec
->fs
, num_samplers
,
730 vec
->rasterizer
, dual_blend
, cc_may_kill
, 0);
735 gen6_pipeline_wm_multisample(struct ilo_3d_pipeline
*p
,
736 const struct ilo_state_vector
*vec
,
737 struct gen6_pipeline_session
*session
)
739 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
740 if (DIRTY(SAMPLE_MASK
) || DIRTY(FB
)) {
741 const uint32_t *packed_sample_pos
;
743 packed_sample_pos
= (vec
->fb
.num_samples
> 1) ?
744 &p
->packed_sample_position_4x
: &p
->packed_sample_position_1x
;
746 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6)) {
747 gen6_wa_pre_non_pipelined(p
);
748 gen6_wa_pre_3dstate_multisample(p
);
751 gen6_3DSTATE_MULTISAMPLE(p
->builder
,
752 vec
->fb
.num_samples
, packed_sample_pos
,
753 vec
->rasterizer
->state
.half_pixel_center
);
755 gen6_3DSTATE_SAMPLE_MASK(p
->builder
,
756 (vec
->fb
.num_samples
> 1) ? vec
->sample_mask
: 0x1);
761 gen6_pipeline_wm_depth(struct ilo_3d_pipeline
*p
,
762 const struct ilo_state_vector
*vec
,
763 struct gen6_pipeline_session
*session
)
765 /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
766 if (DIRTY(FB
) || session
->batch_bo_changed
) {
767 const struct ilo_zs_surface
*zs
;
768 uint32_t clear_params
;
770 if (vec
->fb
.state
.zsbuf
) {
771 const struct ilo_surface_cso
*surface
=
772 (const struct ilo_surface_cso
*) vec
->fb
.state
.zsbuf
;
773 const struct ilo_texture_slice
*slice
=
774 ilo_texture_get_slice(ilo_texture(surface
->base
.texture
),
775 surface
->base
.u
.tex
.level
, surface
->base
.u
.tex
.first_layer
);
777 assert(!surface
->is_rt
);
780 clear_params
= slice
->clear_value
;
783 zs
= &vec
->fb
.null_zs
;
787 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6)) {
788 gen6_wa_pre_non_pipelined(p
);
789 gen6_wa_pre_depth(p
);
792 gen6_3DSTATE_DEPTH_BUFFER(p
->builder
, zs
);
793 gen6_3DSTATE_HIER_DEPTH_BUFFER(p
->builder
, zs
);
794 gen6_3DSTATE_STENCIL_BUFFER(p
->builder
, zs
);
795 gen6_3DSTATE_CLEAR_PARAMS(p
->builder
, clear_params
);
800 gen6_pipeline_wm_raster(struct ilo_3d_pipeline
*p
,
801 const struct ilo_state_vector
*vec
,
802 struct gen6_pipeline_session
*session
)
804 /* 3DSTATE_POLY_STIPPLE_PATTERN and 3DSTATE_POLY_STIPPLE_OFFSET */
805 if ((DIRTY(RASTERIZER
) || DIRTY(POLY_STIPPLE
)) &&
806 vec
->rasterizer
->state
.poly_stipple_enable
) {
807 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
808 gen6_wa_pre_non_pipelined(p
);
810 gen6_3DSTATE_POLY_STIPPLE_PATTERN(p
->builder
,
813 gen6_3DSTATE_POLY_STIPPLE_OFFSET(p
->builder
, 0, 0);
816 /* 3DSTATE_LINE_STIPPLE */
817 if (DIRTY(RASTERIZER
) && vec
->rasterizer
->state
.line_stipple_enable
) {
818 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
819 gen6_wa_pre_non_pipelined(p
);
821 gen6_3DSTATE_LINE_STIPPLE(p
->builder
,
822 vec
->rasterizer
->state
.line_stipple_pattern
,
823 vec
->rasterizer
->state
.line_stipple_factor
+ 1);
826 /* 3DSTATE_AA_LINE_PARAMETERS */
827 if (DIRTY(RASTERIZER
) && vec
->rasterizer
->state
.line_smooth
) {
828 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
829 gen6_wa_pre_non_pipelined(p
);
831 gen6_3DSTATE_AA_LINE_PARAMETERS(p
->builder
);
836 gen6_pipeline_state_viewports(struct ilo_3d_pipeline
*p
,
837 const struct ilo_state_vector
*vec
,
838 struct gen6_pipeline_session
*session
)
840 /* SF_CLIP_VIEWPORT and CC_VIEWPORT */
841 if (ilo_dev_gen(p
->dev
) >= ILO_GEN(7) && DIRTY(VIEWPORT
)) {
842 p
->state
.SF_CLIP_VIEWPORT
= gen7_SF_CLIP_VIEWPORT(p
->builder
,
843 vec
->viewport
.cso
, vec
->viewport
.count
);
845 p
->state
.CC_VIEWPORT
= gen6_CC_VIEWPORT(p
->builder
,
846 vec
->viewport
.cso
, vec
->viewport
.count
);
848 session
->viewport_state_changed
= true;
850 /* SF_VIEWPORT, CLIP_VIEWPORT, and CC_VIEWPORT */
851 else if (DIRTY(VIEWPORT
)) {
852 p
->state
.CLIP_VIEWPORT
= gen6_CLIP_VIEWPORT(p
->builder
,
853 vec
->viewport
.cso
, vec
->viewport
.count
);
855 p
->state
.SF_VIEWPORT
= gen6_SF_VIEWPORT(p
->builder
,
856 vec
->viewport
.cso
, vec
->viewport
.count
);
858 p
->state
.CC_VIEWPORT
= gen6_CC_VIEWPORT(p
->builder
,
859 vec
->viewport
.cso
, vec
->viewport
.count
);
861 session
->viewport_state_changed
= true;
866 gen6_pipeline_state_cc(struct ilo_3d_pipeline
*p
,
867 const struct ilo_state_vector
*vec
,
868 struct gen6_pipeline_session
*session
)
871 if (DIRTY(BLEND
) || DIRTY(FB
) || DIRTY(DSA
)) {
872 p
->state
.BLEND_STATE
= gen6_BLEND_STATE(p
->builder
,
873 vec
->blend
, &vec
->fb
, vec
->dsa
);
875 session
->cc_state_blend_changed
= true;
878 /* COLOR_CALC_STATE */
879 if (DIRTY(DSA
) || DIRTY(STENCIL_REF
) || DIRTY(BLEND_COLOR
)) {
880 p
->state
.COLOR_CALC_STATE
=
881 gen6_COLOR_CALC_STATE(p
->builder
, &vec
->stencil_ref
,
882 vec
->dsa
->alpha_ref
, &vec
->blend_color
);
884 session
->cc_state_cc_changed
= true;
887 /* DEPTH_STENCIL_STATE */
889 p
->state
.DEPTH_STENCIL_STATE
=
890 gen6_DEPTH_STENCIL_STATE(p
->builder
, vec
->dsa
);
892 session
->cc_state_dsa_changed
= true;
897 gen6_pipeline_state_scissors(struct ilo_3d_pipeline
*p
,
898 const struct ilo_state_vector
*vec
,
899 struct gen6_pipeline_session
*session
)
902 if (DIRTY(SCISSOR
) || DIRTY(VIEWPORT
)) {
903 /* there should be as many scissors as there are viewports */
904 p
->state
.SCISSOR_RECT
= gen6_SCISSOR_RECT(p
->builder
,
905 &vec
->scissor
, vec
->viewport
.count
);
907 session
->scissor_state_changed
= true;
912 gen6_pipeline_state_surfaces_rt(struct ilo_3d_pipeline
*p
,
913 const struct ilo_state_vector
*vec
,
914 struct gen6_pipeline_session
*session
)
916 /* SURFACE_STATEs for render targets */
918 const struct ilo_fb_state
*fb
= &vec
->fb
;
919 const int offset
= ILO_WM_DRAW_SURFACE(0);
920 uint32_t *surface_state
= &p
->state
.wm
.SURFACE_STATE
[offset
];
923 for (i
= 0; i
< fb
->state
.nr_cbufs
; i
++) {
924 const struct ilo_surface_cso
*surface
=
925 (const struct ilo_surface_cso
*) fb
->state
.cbufs
[i
];
929 gen6_SURFACE_STATE(p
->builder
, &fb
->null_rt
, true);
932 assert(surface
&& surface
->is_rt
);
934 gen6_SURFACE_STATE(p
->builder
, &surface
->u
.rt
, true);
939 * Upload at least one render target, as
940 * brw_update_renderbuffer_surfaces() does. I don't know why.
944 gen6_SURFACE_STATE(p
->builder
, &fb
->null_rt
, true);
949 memset(&surface_state
[i
], 0, (ILO_MAX_DRAW_BUFFERS
- i
) * 4);
951 if (i
&& session
->num_surfaces
[PIPE_SHADER_FRAGMENT
] < offset
+ i
)
952 session
->num_surfaces
[PIPE_SHADER_FRAGMENT
] = offset
+ i
;
954 session
->binding_table_fs_changed
= true;
959 gen6_pipeline_state_surfaces_so(struct ilo_3d_pipeline
*p
,
960 const struct ilo_state_vector
*vec
,
961 struct gen6_pipeline_session
*session
)
963 const struct ilo_so_state
*so
= &vec
->so
;
965 if (ilo_dev_gen(p
->dev
) != ILO_GEN(6))
968 /* SURFACE_STATEs for stream output targets */
969 if (DIRTY(VS
) || DIRTY(GS
) || DIRTY(SO
)) {
970 const struct pipe_stream_output_info
*so_info
=
971 (vec
->gs
) ? ilo_shader_get_kernel_so_info(vec
->gs
) :
972 (vec
->vs
) ? ilo_shader_get_kernel_so_info(vec
->vs
) : NULL
;
973 const int offset
= ILO_GS_SO_SURFACE(0);
974 uint32_t *surface_state
= &p
->state
.gs
.SURFACE_STATE
[offset
];
977 for (i
= 0; so_info
&& i
< so_info
->num_outputs
; i
++) {
978 const int target
= so_info
->output
[i
].output_buffer
;
979 const struct pipe_stream_output_target
*so_target
=
980 (target
< so
->count
) ? so
->states
[target
] : NULL
;
983 surface_state
[i
] = gen6_so_SURFACE_STATE(p
->builder
,
984 so_target
, so_info
, i
);
987 surface_state
[i
] = 0;
991 memset(&surface_state
[i
], 0, (ILO_MAX_SO_BINDINGS
- i
) * 4);
993 if (i
&& session
->num_surfaces
[PIPE_SHADER_GEOMETRY
] < offset
+ i
)
994 session
->num_surfaces
[PIPE_SHADER_GEOMETRY
] = offset
+ i
;
996 session
->binding_table_gs_changed
= true;
1001 gen6_pipeline_state_surfaces_view(struct ilo_3d_pipeline
*p
,
1002 const struct ilo_state_vector
*vec
,
1004 struct gen6_pipeline_session
*session
)
1006 const struct ilo_view_state
*view
= &vec
->view
[shader_type
];
1007 uint32_t *surface_state
;
1011 /* SURFACE_STATEs for sampler views */
1012 switch (shader_type
) {
1013 case PIPE_SHADER_VERTEX
:
1014 if (DIRTY(VIEW_VS
)) {
1015 offset
= ILO_VS_TEXTURE_SURFACE(0);
1016 surface_state
= &p
->state
.vs
.SURFACE_STATE
[offset
];
1018 session
->binding_table_vs_changed
= true;
1024 case PIPE_SHADER_FRAGMENT
:
1025 if (DIRTY(VIEW_FS
)) {
1026 offset
= ILO_WM_TEXTURE_SURFACE(0);
1027 surface_state
= &p
->state
.wm
.SURFACE_STATE
[offset
];
1029 session
->binding_table_fs_changed
= true;
1043 for (i
= 0; i
< view
->count
; i
++) {
1044 if (view
->states
[i
]) {
1045 const struct ilo_view_cso
*cso
=
1046 (const struct ilo_view_cso
*) view
->states
[i
];
1049 gen6_SURFACE_STATE(p
->builder
, &cso
->surface
, false);
1052 surface_state
[i
] = 0;
1056 memset(&surface_state
[i
], 0, (ILO_MAX_SAMPLER_VIEWS
- i
) * 4);
1058 if (i
&& session
->num_surfaces
[shader_type
] < offset
+ i
)
1059 session
->num_surfaces
[shader_type
] = offset
+ i
;
1063 gen6_pipeline_state_surfaces_const(struct ilo_3d_pipeline
*p
,
1064 const struct ilo_state_vector
*vec
,
1066 struct gen6_pipeline_session
*session
)
1068 const struct ilo_cbuf_state
*cbuf
= &vec
->cbuf
[shader_type
];
1069 uint32_t *surface_state
;
1070 bool *binding_table_changed
;
1071 int offset
, count
, i
;
1076 /* SURFACE_STATEs for constant buffers */
1077 switch (shader_type
) {
1078 case PIPE_SHADER_VERTEX
:
1079 offset
= ILO_VS_CONST_SURFACE(0);
1080 surface_state
= &p
->state
.vs
.SURFACE_STATE
[offset
];
1081 binding_table_changed
= &session
->binding_table_vs_changed
;
1083 case PIPE_SHADER_FRAGMENT
:
1084 offset
= ILO_WM_CONST_SURFACE(0);
1085 surface_state
= &p
->state
.wm
.SURFACE_STATE
[offset
];
1086 binding_table_changed
= &session
->binding_table_fs_changed
;
1093 /* constants are pushed via PCB */
1094 if (cbuf
->enabled_mask
== 0x1 && !cbuf
->cso
[0].resource
) {
1095 memset(surface_state
, 0, ILO_MAX_CONST_BUFFERS
* 4);
1099 count
= util_last_bit(cbuf
->enabled_mask
);
1100 for (i
= 0; i
< count
; i
++) {
1101 if (cbuf
->cso
[i
].resource
) {
1102 surface_state
[i
] = gen6_SURFACE_STATE(p
->builder
,
1103 &cbuf
->cso
[i
].surface
, false);
1106 surface_state
[i
] = 0;
1110 memset(&surface_state
[count
], 0, (ILO_MAX_CONST_BUFFERS
- count
) * 4);
1112 if (count
&& session
->num_surfaces
[shader_type
] < offset
+ count
)
1113 session
->num_surfaces
[shader_type
] = offset
+ count
;
1115 *binding_table_changed
= true;
1119 gen6_pipeline_state_binding_tables(struct ilo_3d_pipeline
*p
,
1120 const struct ilo_state_vector
*vec
,
1122 struct gen6_pipeline_session
*session
)
1124 uint32_t *binding_table_state
, *surface_state
;
1125 int *binding_table_state_size
, size
;
1128 /* BINDING_TABLE_STATE */
1129 switch (shader_type
) {
1130 case PIPE_SHADER_VERTEX
:
1131 surface_state
= p
->state
.vs
.SURFACE_STATE
;
1132 binding_table_state
= &p
->state
.vs
.BINDING_TABLE_STATE
;
1133 binding_table_state_size
= &p
->state
.vs
.BINDING_TABLE_STATE_size
;
1135 skip
= !session
->binding_table_vs_changed
;
1137 case PIPE_SHADER_GEOMETRY
:
1138 surface_state
= p
->state
.gs
.SURFACE_STATE
;
1139 binding_table_state
= &p
->state
.gs
.BINDING_TABLE_STATE
;
1140 binding_table_state_size
= &p
->state
.gs
.BINDING_TABLE_STATE_size
;
1142 skip
= !session
->binding_table_gs_changed
;
1144 case PIPE_SHADER_FRAGMENT
:
1145 surface_state
= p
->state
.wm
.SURFACE_STATE
;
1146 binding_table_state
= &p
->state
.wm
.BINDING_TABLE_STATE
;
1147 binding_table_state_size
= &p
->state
.wm
.BINDING_TABLE_STATE_size
;
1149 skip
= !session
->binding_table_fs_changed
;
1160 * If we have seemingly less SURFACE_STATEs than before, it could be that
1161 * we did not touch those reside at the tail in this upload. Loop over
1162 * them to figure out the real number of SURFACE_STATEs.
1164 for (size
= *binding_table_state_size
;
1165 size
> session
->num_surfaces
[shader_type
]; size
--) {
1166 if (surface_state
[size
- 1])
1169 if (size
< session
->num_surfaces
[shader_type
])
1170 size
= session
->num_surfaces
[shader_type
];
1172 *binding_table_state
= gen6_BINDING_TABLE_STATE(p
->builder
,
1173 surface_state
, size
);
1174 *binding_table_state_size
= size
;
1178 gen6_pipeline_state_samplers(struct ilo_3d_pipeline
*p
,
1179 const struct ilo_state_vector
*vec
,
1181 struct gen6_pipeline_session
*session
)
1183 const struct ilo_sampler_cso
* const *samplers
=
1184 vec
->sampler
[shader_type
].cso
;
1185 const struct pipe_sampler_view
* const *views
=
1186 (const struct pipe_sampler_view
**) vec
->view
[shader_type
].states
;
1187 const int num_samplers
= vec
->sampler
[shader_type
].count
;
1188 const int num_views
= vec
->view
[shader_type
].count
;
1189 uint32_t *sampler_state
, *border_color_state
;
1190 bool emit_border_color
= false;
1193 /* SAMPLER_BORDER_COLOR_STATE and SAMPLER_STATE */
1194 switch (shader_type
) {
1195 case PIPE_SHADER_VERTEX
:
1196 if (DIRTY(SAMPLER_VS
) || DIRTY(VIEW_VS
)) {
1197 sampler_state
= &p
->state
.vs
.SAMPLER_STATE
;
1198 border_color_state
= p
->state
.vs
.SAMPLER_BORDER_COLOR_STATE
;
1200 if (DIRTY(SAMPLER_VS
))
1201 emit_border_color
= true;
1203 session
->sampler_state_vs_changed
= true;
1209 case PIPE_SHADER_FRAGMENT
:
1210 if (DIRTY(SAMPLER_FS
) || DIRTY(VIEW_FS
)) {
1211 sampler_state
= &p
->state
.wm
.SAMPLER_STATE
;
1212 border_color_state
= p
->state
.wm
.SAMPLER_BORDER_COLOR_STATE
;
1214 if (DIRTY(SAMPLER_FS
))
1215 emit_border_color
= true;
1217 session
->sampler_state_fs_changed
= true;
1231 if (emit_border_color
) {
1234 for (i
= 0; i
< num_samplers
; i
++) {
1235 border_color_state
[i
] = (samplers
[i
]) ?
1236 gen6_SAMPLER_BORDER_COLOR_STATE(p
->builder
, samplers
[i
]) : 0;
1240 /* should we take the minimum of num_samplers and num_views? */
1241 *sampler_state
= gen6_SAMPLER_STATE(p
->builder
,
1244 MIN2(num_samplers
, num_views
));
1248 gen6_pipeline_state_pcb(struct ilo_3d_pipeline
*p
,
1249 const struct ilo_state_vector
*vec
,
1250 struct gen6_pipeline_session
*session
)
1252 /* push constant buffer for VS */
1253 if (DIRTY(VS
) || DIRTY(CBUF
) || DIRTY(CLIP
)) {
1254 const int cbuf0_size
= (vec
->vs
) ?
1255 ilo_shader_get_kernel_param(vec
->vs
,
1256 ILO_KERNEL_PCB_CBUF0_SIZE
) : 0;
1257 const int clip_state_size
= (vec
->vs
) ?
1258 ilo_shader_get_kernel_param(vec
->vs
,
1259 ILO_KERNEL_VS_PCB_UCP_SIZE
) : 0;
1260 const int total_size
= cbuf0_size
+ clip_state_size
;
1265 p
->state
.vs
.PUSH_CONSTANT_BUFFER
=
1266 gen6_push_constant_buffer(p
->builder
, total_size
, &pcb
);
1267 p
->state
.vs
.PUSH_CONSTANT_BUFFER_size
= total_size
;
1270 const struct ilo_cbuf_state
*cbuf
=
1271 &vec
->cbuf
[PIPE_SHADER_VERTEX
];
1273 if (cbuf0_size
<= cbuf
->cso
[0].user_buffer_size
) {
1274 memcpy(pcb
, cbuf
->cso
[0].user_buffer
, cbuf0_size
);
1277 memcpy(pcb
, cbuf
->cso
[0].user_buffer
,
1278 cbuf
->cso
[0].user_buffer_size
);
1279 memset(pcb
+ cbuf
->cso
[0].user_buffer_size
, 0,
1280 cbuf0_size
- cbuf
->cso
[0].user_buffer_size
);
1286 if (clip_state_size
)
1287 memcpy(pcb
, &vec
->clip
, clip_state_size
);
1289 session
->pcb_state_vs_changed
= true;
1291 else if (p
->state
.vs
.PUSH_CONSTANT_BUFFER_size
) {
1292 p
->state
.vs
.PUSH_CONSTANT_BUFFER
= 0;
1293 p
->state
.vs
.PUSH_CONSTANT_BUFFER_size
= 0;
1295 session
->pcb_state_vs_changed
= true;
1299 /* push constant buffer for FS */
1300 if (DIRTY(FS
) || DIRTY(CBUF
)) {
1301 const int cbuf0_size
= (vec
->fs
) ?
1302 ilo_shader_get_kernel_param(vec
->fs
, ILO_KERNEL_PCB_CBUF0_SIZE
) : 0;
1305 const struct ilo_cbuf_state
*cbuf
= &vec
->cbuf
[PIPE_SHADER_FRAGMENT
];
1308 p
->state
.wm
.PUSH_CONSTANT_BUFFER
=
1309 gen6_push_constant_buffer(p
->builder
, cbuf0_size
, &pcb
);
1310 p
->state
.wm
.PUSH_CONSTANT_BUFFER_size
= cbuf0_size
;
1312 if (cbuf0_size
<= cbuf
->cso
[0].user_buffer_size
) {
1313 memcpy(pcb
, cbuf
->cso
[0].user_buffer
, cbuf0_size
);
1316 memcpy(pcb
, cbuf
->cso
[0].user_buffer
,
1317 cbuf
->cso
[0].user_buffer_size
);
1318 memset(pcb
+ cbuf
->cso
[0].user_buffer_size
, 0,
1319 cbuf0_size
- cbuf
->cso
[0].user_buffer_size
);
1322 session
->pcb_state_fs_changed
= true;
1324 else if (p
->state
.wm
.PUSH_CONSTANT_BUFFER_size
) {
1325 p
->state
.wm
.PUSH_CONSTANT_BUFFER
= 0;
1326 p
->state
.wm
.PUSH_CONSTANT_BUFFER_size
= 0;
1328 session
->pcb_state_fs_changed
= true;
1336 gen6_pipeline_commands(struct ilo_3d_pipeline
*p
,
1337 const struct ilo_state_vector
*vec
,
1338 struct gen6_pipeline_session
*session
)
1341 * We try to keep the order of the commands match, as closely as possible,
1342 * that of the classic i965 driver. It allows us to compare the command
1345 gen6_pipeline_common_select(p
, vec
, session
);
1346 gen6_pipeline_gs_svbi(p
, vec
, session
);
1347 gen6_pipeline_common_sip(p
, vec
, session
);
1348 gen6_pipeline_vf_statistics(p
, vec
, session
);
1349 gen6_pipeline_common_base_address(p
, vec
, session
);
1350 gen6_pipeline_common_pointers_1(p
, vec
, session
);
1351 gen6_pipeline_common_urb(p
, vec
, session
);
1352 gen6_pipeline_common_pointers_2(p
, vec
, session
);
1353 gen6_pipeline_wm_multisample(p
, vec
, session
);
1354 gen6_pipeline_vs(p
, vec
, session
);
1355 gen6_pipeline_gs(p
, vec
, session
);
1356 gen6_pipeline_clip(p
, vec
, session
);
1357 gen6_pipeline_sf(p
, vec
, session
);
1358 gen6_pipeline_wm(p
, vec
, session
);
1359 gen6_pipeline_common_pointers_3(p
, vec
, session
);
1360 gen6_pipeline_wm_depth(p
, vec
, session
);
1361 gen6_pipeline_wm_raster(p
, vec
, session
);
1362 gen6_pipeline_sf_rect(p
, vec
, session
);
1363 gen6_pipeline_vf(p
, vec
, session
);
1364 gen6_pipeline_vf_draw(p
, vec
, session
);
1368 gen6_pipeline_states(struct ilo_3d_pipeline
*p
,
1369 const struct ilo_state_vector
*vec
,
1370 struct gen6_pipeline_session
*session
)
1374 gen6_pipeline_state_viewports(p
, vec
, session
);
1375 gen6_pipeline_state_cc(p
, vec
, session
);
1376 gen6_pipeline_state_scissors(p
, vec
, session
);
1377 gen6_pipeline_state_pcb(p
, vec
, session
);
1380 * upload all SURAFCE_STATEs together so that we know there are minimal
1383 gen6_pipeline_state_surfaces_rt(p
, vec
, session
);
1384 gen6_pipeline_state_surfaces_so(p
, vec
, session
);
1385 for (shader_type
= 0; shader_type
< PIPE_SHADER_TYPES
; shader_type
++) {
1386 gen6_pipeline_state_surfaces_view(p
, vec
, shader_type
, session
);
1387 gen6_pipeline_state_surfaces_const(p
, vec
, shader_type
, session
);
1390 for (shader_type
= 0; shader_type
< PIPE_SHADER_TYPES
; shader_type
++) {
1391 gen6_pipeline_state_samplers(p
, vec
, shader_type
, session
);
1392 /* this must be called after all SURFACE_STATEs are uploaded */
1393 gen6_pipeline_state_binding_tables(p
, vec
, shader_type
, session
);
1398 gen6_pipeline_prepare(const struct ilo_3d_pipeline
*p
,
1399 const struct ilo_state_vector
*vec
,
1400 struct gen6_pipeline_session
*session
)
1402 memset(session
, 0, sizeof(*session
));
1403 session
->pipe_dirty
= vec
->dirty
;
1404 session
->reduced_prim
= u_reduced_prim(vec
->draw
->mode
);
1406 session
->hw_ctx_changed
=
1407 (p
->invalidate_flags
& ILO_3D_PIPELINE_INVALIDATE_HW
);
1409 if (session
->hw_ctx_changed
) {
1410 /* these should be enough to make everything uploaded */
1411 session
->batch_bo_changed
= true;
1412 session
->state_bo_changed
= true;
1413 session
->kernel_bo_changed
= true;
1414 session
->prim_changed
= true;
1415 session
->primitive_restart_changed
= true;
1418 * Any state that involves resources needs to be re-emitted when the
1419 * batch bo changed. This is because we do not pin the resources and
1420 * their offsets (or existence) may change between batch buffers.
1422 session
->batch_bo_changed
=
1423 (p
->invalidate_flags
& ILO_3D_PIPELINE_INVALIDATE_BATCH_BO
);
1425 session
->state_bo_changed
=
1426 (p
->invalidate_flags
& ILO_3D_PIPELINE_INVALIDATE_STATE_BO
);
1427 session
->kernel_bo_changed
=
1428 (p
->invalidate_flags
& ILO_3D_PIPELINE_INVALIDATE_KERNEL_BO
);
1429 session
->prim_changed
= (p
->state
.reduced_prim
!= session
->reduced_prim
);
1430 session
->primitive_restart_changed
=
1431 (p
->state
.primitive_restart
!= vec
->draw
->primitive_restart
);
1436 gen6_pipeline_draw(struct ilo_3d_pipeline
*p
,
1437 const struct ilo_state_vector
*vec
,
1438 struct gen6_pipeline_session
*session
)
1440 /* force all states to be uploaded if the state bo changed */
1441 if (session
->state_bo_changed
)
1442 session
->pipe_dirty
= ILO_DIRTY_ALL
;
1444 session
->pipe_dirty
= vec
->dirty
;
1446 session
->emit_draw_states(p
, vec
, session
);
1448 /* force all commands to be uploaded if the HW context changed */
1449 if (session
->hw_ctx_changed
)
1450 session
->pipe_dirty
= ILO_DIRTY_ALL
;
1452 session
->pipe_dirty
= vec
->dirty
;
1454 session
->emit_draw_commands(p
, vec
, session
);
1458 gen6_pipeline_end(struct ilo_3d_pipeline
*p
,
1459 const struct ilo_state_vector
*vec
,
1460 struct gen6_pipeline_session
*session
)
1462 p
->state
.reduced_prim
= session
->reduced_prim
;
1463 p
->state
.primitive_restart
= vec
->draw
->primitive_restart
;
1467 ilo_3d_pipeline_emit_draw_gen6(struct ilo_3d_pipeline
*p
,
1468 const struct ilo_state_vector
*vec
)
1470 struct gen6_pipeline_session session
;
1472 gen6_pipeline_prepare(p
, vec
, &session
);
1474 session
.emit_draw_states
= gen6_pipeline_states
;
1475 session
.emit_draw_commands
= gen6_pipeline_commands
;
1477 gen6_pipeline_draw(p
, vec
, &session
);
1478 gen6_pipeline_end(p
, vec
, &session
);
1482 ilo_3d_pipeline_emit_flush_gen6(struct ilo_3d_pipeline
*p
)
1484 const uint32_t dw1
= GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE
|
1485 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH
|
1486 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH
|
1487 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE
|
1488 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
|
1489 GEN6_PIPE_CONTROL_CS_STALL
;
1491 ILO_DEV_ASSERT(p
->dev
, 6, 7.5);
1493 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
1494 gen6_wa_pre_pipe_control(p
, dw1
);
1496 gen6_PIPE_CONTROL(p
->builder
, dw1
, NULL
, 0, false);
1498 p
->state
.current_pipe_control_dw1
|= dw1
;
1499 p
->state
.deferred_pipe_control_dw1
&= ~dw1
;
1503 ilo_3d_pipeline_emit_query_gen6(struct ilo_3d_pipeline
*p
,
1504 struct ilo_query
*q
, uint32_t offset
)
1506 const uint32_t pipeline_statistics_regs
[] = {
1507 GEN6_REG_IA_VERTICES_COUNT
,
1508 GEN6_REG_IA_PRIMITIVES_COUNT
,
1509 GEN6_REG_VS_INVOCATION_COUNT
,
1510 GEN6_REG_GS_INVOCATION_COUNT
,
1511 GEN6_REG_GS_PRIMITIVES_COUNT
,
1512 GEN6_REG_CL_INVOCATION_COUNT
,
1513 GEN6_REG_CL_PRIMITIVES_COUNT
,
1514 GEN6_REG_PS_INVOCATION_COUNT
,
1515 (ilo_dev_gen(p
->dev
) >= ILO_GEN(7)) ? GEN7_REG_HS_INVOCATION_COUNT
: 0,
1516 (ilo_dev_gen(p
->dev
) >= ILO_GEN(7)) ? GEN7_REG_DS_INVOCATION_COUNT
: 0,
1519 const uint32_t primitives_generated_reg
=
1520 (ilo_dev_gen(p
->dev
) >= ILO_GEN(7) && q
->index
> 0) ?
1521 GEN7_REG_SO_PRIM_STORAGE_NEEDED(q
->index
) :
1522 GEN6_REG_CL_INVOCATION_COUNT
;
1523 const uint32_t primitives_emitted_reg
=
1524 (ilo_dev_gen(p
->dev
) >= ILO_GEN(7)) ?
1525 GEN7_REG_SO_NUM_PRIMS_WRITTEN(q
->index
) :
1526 GEN6_REG_SO_NUM_PRIMS_WRITTEN
;
1527 const uint32_t *regs
;
1528 int reg_count
= 0, i
;
1529 uint32_t pipe_control_dw1
= 0;
1531 ILO_DEV_ASSERT(p
->dev
, 6, 7.5);
1534 case PIPE_QUERY_OCCLUSION_COUNTER
:
1535 pipe_control_dw1
= GEN6_PIPE_CONTROL_DEPTH_STALL
|
1536 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT
;
1538 case PIPE_QUERY_TIMESTAMP
:
1539 case PIPE_QUERY_TIME_ELAPSED
:
1540 pipe_control_dw1
= GEN6_PIPE_CONTROL_WRITE_TIMESTAMP
;
1542 case PIPE_QUERY_PRIMITIVES_GENERATED
:
1543 regs
= &primitives_generated_reg
;
1546 case PIPE_QUERY_PRIMITIVES_EMITTED
:
1547 regs
= &primitives_emitted_reg
;
1550 case PIPE_QUERY_PIPELINE_STATISTICS
:
1551 regs
= pipeline_statistics_regs
;
1552 reg_count
= Elements(pipeline_statistics_regs
);
1558 if (pipe_control_dw1
) {
1559 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
1560 gen6_wa_pre_pipe_control(p
, pipe_control_dw1
);
1562 gen6_PIPE_CONTROL(p
->builder
, pipe_control_dw1
, q
->bo
, offset
, true);
1564 p
->state
.current_pipe_control_dw1
|= pipe_control_dw1
;
1565 p
->state
.deferred_pipe_control_dw1
&= ~pipe_control_dw1
;
1573 for (i
= 0; i
< reg_count
; i
++) {
1575 /* store lower 32 bits */
1576 gen6_MI_STORE_REGISTER_MEM(p
->builder
, q
->bo
, offset
, regs
[i
]);
1577 /* store higher 32 bits */
1578 gen6_MI_STORE_REGISTER_MEM(p
->builder
, q
->bo
,
1579 offset
+ 4, regs
[i
] + 4);
1581 gen6_MI_STORE_DATA_IMM(p
->builder
, q
->bo
, offset
, 0, true);
1589 gen6_rectlist_vs_to_sf(struct ilo_3d_pipeline
*p
,
1590 const struct ilo_blitter
*blitter
,
1591 struct gen6_rectlist_session
*session
)
1593 gen6_3DSTATE_CONSTANT_VS(p
->builder
, NULL
, NULL
, 0);
1594 gen6_3DSTATE_VS(p
->builder
, NULL
, 0);
1596 gen6_wa_post_3dstate_constant_vs(p
);
1598 gen6_3DSTATE_CONSTANT_GS(p
->builder
, NULL
, NULL
, 0);
1599 gen6_3DSTATE_GS(p
->builder
, NULL
, NULL
, 0);
1601 gen6_3DSTATE_CLIP(p
->builder
, NULL
, NULL
, false, 0);
1602 gen6_3DSTATE_SF(p
->builder
, NULL
, NULL
);
1606 gen6_rectlist_wm(struct ilo_3d_pipeline
*p
,
1607 const struct ilo_blitter
*blitter
,
1608 struct gen6_rectlist_session
*session
)
1612 switch (blitter
->op
) {
1613 case ILO_BLITTER_RECTLIST_CLEAR_ZS
:
1614 hiz_op
= GEN6_WM_DW4_DEPTH_CLEAR
;
1616 case ILO_BLITTER_RECTLIST_RESOLVE_Z
:
1617 hiz_op
= GEN6_WM_DW4_DEPTH_RESOLVE
;
1619 case ILO_BLITTER_RECTLIST_RESOLVE_HIZ
:
1620 hiz_op
= GEN6_WM_DW4_HIZ_RESOLVE
;
1627 gen6_3DSTATE_CONSTANT_PS(p
->builder
, NULL
, NULL
, 0);
1629 gen6_wa_pre_3dstate_wm_max_threads(p
);
1630 gen6_3DSTATE_WM(p
->builder
, NULL
, 0, NULL
, false, false, hiz_op
);
1634 gen6_rectlist_wm_depth(struct ilo_3d_pipeline
*p
,
1635 const struct ilo_blitter
*blitter
,
1636 struct gen6_rectlist_session
*session
)
1638 gen6_wa_pre_depth(p
);
1640 if (blitter
->uses
& (ILO_BLITTER_USE_FB_DEPTH
|
1641 ILO_BLITTER_USE_FB_STENCIL
)) {
1642 gen6_3DSTATE_DEPTH_BUFFER(p
->builder
,
1643 &blitter
->fb
.dst
.u
.zs
);
1646 if (blitter
->uses
& ILO_BLITTER_USE_FB_DEPTH
) {
1647 gen6_3DSTATE_HIER_DEPTH_BUFFER(p
->builder
,
1648 &blitter
->fb
.dst
.u
.zs
);
1651 if (blitter
->uses
& ILO_BLITTER_USE_FB_STENCIL
) {
1652 gen6_3DSTATE_STENCIL_BUFFER(p
->builder
,
1653 &blitter
->fb
.dst
.u
.zs
);
1656 gen6_3DSTATE_CLEAR_PARAMS(p
->builder
,
1657 blitter
->depth_clear_value
);
1661 gen6_rectlist_wm_multisample(struct ilo_3d_pipeline
*p
,
1662 const struct ilo_blitter
*blitter
,
1663 struct gen6_rectlist_session
*session
)
1665 const uint32_t *packed_sample_pos
= (blitter
->fb
.num_samples
> 1) ?
1666 &p
->packed_sample_position_4x
: &p
->packed_sample_position_1x
;
1668 gen6_wa_pre_3dstate_multisample(p
);
1670 gen6_3DSTATE_MULTISAMPLE(p
->builder
, blitter
->fb
.num_samples
,
1671 packed_sample_pos
, true);
1673 gen6_3DSTATE_SAMPLE_MASK(p
->builder
,
1674 (1 << blitter
->fb
.num_samples
) - 1);
1678 gen6_rectlist_commands(struct ilo_3d_pipeline
*p
,
1679 const struct ilo_blitter
*blitter
,
1680 struct gen6_rectlist_session
*session
)
1682 gen6_wa_pre_non_pipelined(p
);
1684 gen6_rectlist_wm_multisample(p
, blitter
, session
);
1686 gen6_state_base_address(p
->builder
, true);
1688 gen6_3DSTATE_VERTEX_BUFFERS(p
->builder
,
1689 &blitter
->ve
, &blitter
->vb
);
1691 gen6_3DSTATE_VERTEX_ELEMENTS(p
->builder
,
1692 &blitter
->ve
, false, false);
1694 gen6_3DSTATE_URB(p
->builder
,
1695 p
->dev
->urb_size
, 0, blitter
->ve
.count
* 4 * sizeof(float), 0);
1696 /* 3DSTATE_URB workaround */
1697 if (p
->state
.gs
.active
) {
1698 ilo_3d_pipeline_emit_flush_gen6(p
);
1699 p
->state
.gs
.active
= false;
1703 (ILO_BLITTER_USE_DSA
| ILO_BLITTER_USE_CC
)) {
1704 gen6_3DSTATE_CC_STATE_POINTERS(p
->builder
, 0,
1705 session
->DEPTH_STENCIL_STATE
, session
->COLOR_CALC_STATE
);
1708 gen6_rectlist_vs_to_sf(p
, blitter
, session
);
1709 gen6_rectlist_wm(p
, blitter
, session
);
1711 if (blitter
->uses
& ILO_BLITTER_USE_VIEWPORT
) {
1712 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(p
->builder
,
1713 0, 0, session
->CC_VIEWPORT
);
1716 gen6_rectlist_wm_depth(p
, blitter
, session
);
1718 gen6_3DSTATE_DRAWING_RECTANGLE(p
->builder
, 0, 0,
1719 blitter
->fb
.width
, blitter
->fb
.height
);
1721 gen6_3DPRIMITIVE(p
->builder
, &blitter
->draw
, NULL
);
1725 gen6_rectlist_states(struct ilo_3d_pipeline
*p
,
1726 const struct ilo_blitter
*blitter
,
1727 struct gen6_rectlist_session
*session
)
1729 if (blitter
->uses
& ILO_BLITTER_USE_DSA
) {
1730 session
->DEPTH_STENCIL_STATE
=
1731 gen6_DEPTH_STENCIL_STATE(p
->builder
, &blitter
->dsa
);
1734 if (blitter
->uses
& ILO_BLITTER_USE_CC
) {
1735 session
->COLOR_CALC_STATE
=
1736 gen6_COLOR_CALC_STATE(p
->builder
, &blitter
->cc
.stencil_ref
,
1737 blitter
->cc
.alpha_ref
, &blitter
->cc
.blend_color
);
1740 if (blitter
->uses
& ILO_BLITTER_USE_VIEWPORT
) {
1741 session
->CC_VIEWPORT
=
1742 gen6_CC_VIEWPORT(p
->builder
, &blitter
->viewport
, 1);
1747 ilo_3d_pipeline_emit_rectlist_gen6(struct ilo_3d_pipeline
*p
,
1748 const struct ilo_blitter
*blitter
)
1750 struct gen6_rectlist_session session
;
1752 memset(&session
, 0, sizeof(session
));
1753 gen6_rectlist_states(p
, blitter
, &session
);
1754 gen6_rectlist_commands(p
, blitter
, &session
);
1758 gen6_pipeline_max_command_size(const struct ilo_3d_pipeline
*p
)
1763 size
+= GEN6_3DSTATE_CONSTANT_ANY__SIZE
* 3;
1764 size
+= GEN6_3DSTATE_GS_SVB_INDEX__SIZE
* 4;
1765 size
+= GEN6_PIPE_CONTROL__SIZE
* 5;
1768 GEN6_STATE_BASE_ADDRESS__SIZE
+
1769 GEN6_STATE_SIP__SIZE
+
1770 GEN6_3DSTATE_VF_STATISTICS__SIZE
+
1771 GEN6_PIPELINE_SELECT__SIZE
+
1772 GEN6_3DSTATE_BINDING_TABLE_POINTERS__SIZE
+
1773 GEN6_3DSTATE_SAMPLER_STATE_POINTERS__SIZE
+
1774 GEN6_3DSTATE_URB__SIZE
+
1775 GEN6_3DSTATE_VERTEX_BUFFERS__SIZE
+
1776 GEN6_3DSTATE_VERTEX_ELEMENTS__SIZE
+
1777 GEN6_3DSTATE_INDEX_BUFFER__SIZE
+
1778 GEN6_3DSTATE_VIEWPORT_STATE_POINTERS__SIZE
+
1779 GEN6_3DSTATE_CC_STATE_POINTERS__SIZE
+
1780 GEN6_3DSTATE_SCISSOR_STATE_POINTERS__SIZE
+
1781 GEN6_3DSTATE_VS__SIZE
+
1782 GEN6_3DSTATE_GS__SIZE
+
1783 GEN6_3DSTATE_CLIP__SIZE
+
1784 GEN6_3DSTATE_SF__SIZE
+
1785 GEN6_3DSTATE_WM__SIZE
+
1786 GEN6_3DSTATE_SAMPLE_MASK__SIZE
+
1787 GEN6_3DSTATE_DRAWING_RECTANGLE__SIZE
+
1788 GEN6_3DSTATE_DEPTH_BUFFER__SIZE
+
1789 GEN6_3DSTATE_POLY_STIPPLE_OFFSET__SIZE
+
1790 GEN6_3DSTATE_POLY_STIPPLE_PATTERN__SIZE
+
1791 GEN6_3DSTATE_LINE_STIPPLE__SIZE
+
1792 GEN6_3DSTATE_AA_LINE_PARAMETERS__SIZE
+
1793 GEN6_3DSTATE_MULTISAMPLE__SIZE
+
1794 GEN6_3DSTATE_STENCIL_BUFFER__SIZE
+
1795 GEN6_3DSTATE_HIER_DEPTH_BUFFER__SIZE
+
1796 GEN6_3DSTATE_CLEAR_PARAMS__SIZE
+
1797 GEN6_3DPRIMITIVE__SIZE
;
1804 gen6_pipeline_estimate_state_size(const struct ilo_3d_pipeline
*p
,
1805 const struct ilo_state_vector
*vec
)
1807 static int static_size
;
1811 /* 64 bytes, or 16 dwords */
1812 const int alignment
= 64 / 4;
1815 size
= alignment
- 1;
1818 size
+= align(GEN6_BLEND_STATE__SIZE
* ILO_MAX_DRAW_BUFFERS
, alignment
);
1819 size
+= align(GEN6_DEPTH_STENCIL_STATE__SIZE
, alignment
);
1820 size
+= align(GEN6_COLOR_CALC_STATE__SIZE
, alignment
);
1822 /* viewport arrays */
1823 if (ilo_dev_gen(p
->dev
) >= ILO_GEN(7)) {
1825 align(GEN7_SF_CLIP_VIEWPORT__SIZE
* ILO_MAX_VIEWPORTS
, 16) +
1826 align(GEN6_CC_VIEWPORT__SIZE
* ILO_MAX_VIEWPORTS
, 8) +
1827 align(GEN6_SCISSOR_RECT__SIZE
* ILO_MAX_VIEWPORTS
, 8);
1831 align(GEN6_SF_VIEWPORT__SIZE
* ILO_MAX_VIEWPORTS
, 8) +
1832 align(GEN6_CLIP_VIEWPORT__SIZE
* ILO_MAX_VIEWPORTS
, 8) +
1833 align(GEN6_CC_VIEWPORT__SIZE
* ILO_MAX_VIEWPORTS
, 8) +
1834 align(GEN6_SCISSOR_RECT__SIZE
* ILO_MAX_VIEWPORTS
, 8);
1842 for (sh_type
= 0; sh_type
< PIPE_SHADER_TYPES
; sh_type
++) {
1843 const int alignment
= 32 / 4;
1844 int num_samplers
, num_surfaces
, pcb_size
;
1847 num_samplers
= vec
->sampler
[sh_type
].count
;
1849 /* sampler views and constant buffers */
1850 num_surfaces
= vec
->view
[sh_type
].count
+
1851 util_bitcount(vec
->cbuf
[sh_type
].enabled_mask
);
1856 case PIPE_SHADER_VERTEX
:
1858 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6)) {
1859 const struct pipe_stream_output_info
*so_info
=
1860 ilo_shader_get_kernel_so_info(vec
->vs
);
1862 /* stream outputs */
1863 num_surfaces
+= so_info
->num_outputs
;
1866 pcb_size
= ilo_shader_get_kernel_param(vec
->vs
,
1867 ILO_KERNEL_PCB_CBUF0_SIZE
);
1868 pcb_size
+= ilo_shader_get_kernel_param(vec
->vs
,
1869 ILO_KERNEL_VS_PCB_UCP_SIZE
);
1872 case PIPE_SHADER_GEOMETRY
:
1873 if (vec
->gs
&& ilo_dev_gen(p
->dev
) == ILO_GEN(6)) {
1874 const struct pipe_stream_output_info
*so_info
=
1875 ilo_shader_get_kernel_so_info(vec
->gs
);
1877 /* stream outputs */
1878 num_surfaces
+= so_info
->num_outputs
;
1881 case PIPE_SHADER_FRAGMENT
:
1882 /* render targets */
1883 num_surfaces
+= vec
->fb
.state
.nr_cbufs
;
1886 pcb_size
= ilo_shader_get_kernel_param(vec
->fs
,
1887 ILO_KERNEL_PCB_CBUF0_SIZE
);
1894 /* SAMPLER_STATE array and SAMPLER_BORDER_COLORs */
1896 size
+= align(GEN6_SAMPLER_STATE__SIZE
* num_samplers
, alignment
) +
1897 align(GEN6_SAMPLER_BORDER_COLOR__SIZE
, alignment
) * num_samplers
;
1900 /* BINDING_TABLE_STATE and SURFACE_STATEs */
1902 size
+= align(num_surfaces
, alignment
) +
1903 align(GEN6_SURFACE_STATE__SIZE
, alignment
) * num_surfaces
;
1908 size
+= align(pcb_size
, alignment
);
1915 gen6_pipeline_estimate_query_size(const struct ilo_3d_pipeline
*p
,
1916 const struct ilo_query
*q
)
1920 ILO_DEV_ASSERT(p
->dev
, 6, 7.5);
1923 case PIPE_QUERY_OCCLUSION_COUNTER
:
1924 size
= GEN6_PIPE_CONTROL__SIZE
;
1925 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
1928 case PIPE_QUERY_TIMESTAMP
:
1929 case PIPE_QUERY_TIME_ELAPSED
:
1930 size
= GEN6_PIPE_CONTROL__SIZE
;
1931 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
1934 case PIPE_QUERY_PRIMITIVES_GENERATED
:
1935 case PIPE_QUERY_PRIMITIVES_EMITTED
:
1936 size
= GEN6_PIPE_CONTROL__SIZE
;
1937 if (ilo_dev_gen(p
->dev
) == ILO_GEN(6))
1940 size
+= GEN6_MI_STORE_REGISTER_MEM__SIZE
* 2;
1942 case PIPE_QUERY_PIPELINE_STATISTICS
:
1943 if (ilo_dev_gen(p
->dev
) >= ILO_GEN(7)) {
1944 const int num_regs
= 10;
1945 const int num_pads
= 1;
1947 size
= GEN6_PIPE_CONTROL__SIZE
+
1948 GEN6_MI_STORE_REGISTER_MEM__SIZE
* 2 * num_regs
+
1949 GEN6_MI_STORE_DATA_IMM__SIZE
* num_pads
;
1951 const int num_regs
= 8;
1952 const int num_pads
= 3;
1954 size
= GEN6_PIPE_CONTROL__SIZE
* 3 +
1955 GEN6_MI_STORE_REGISTER_MEM__SIZE
* 2 * num_regs
+
1956 GEN6_MI_STORE_DATA_IMM__SIZE
* num_pads
;
1968 ilo_3d_pipeline_estimate_size_gen6(struct ilo_3d_pipeline
*p
,
1969 enum ilo_3d_pipeline_action action
,
1975 case ILO_3D_PIPELINE_DRAW
:
1977 const struct ilo_state_vector
*ilo
= arg
;
1979 size
= gen6_pipeline_max_command_size(p
) +
1980 gen6_pipeline_estimate_state_size(p
, ilo
);
1983 case ILO_3D_PIPELINE_FLUSH
:
1984 size
= GEN6_PIPE_CONTROL__SIZE
* 3;
1986 case ILO_3D_PIPELINE_QUERY
:
1987 size
= gen6_pipeline_estimate_query_size(p
,
1988 (const struct ilo_query
*) arg
);
1990 case ILO_3D_PIPELINE_RECTLIST
:
1991 size
= 64 + 256; /* states + commands */
1994 assert(!"unknown 3D pipeline action");
2003 ilo_3d_pipeline_init_gen6(struct ilo_3d_pipeline
*p
)
2005 p
->estimate_size
= ilo_3d_pipeline_estimate_size_gen6
;
2006 p
->emit_draw
= ilo_3d_pipeline_emit_draw_gen6
;
2007 p
->emit_flush
= ilo_3d_pipeline_emit_flush_gen6
;
2008 p
->emit_query
= ilo_3d_pipeline_emit_query_gen6
;
2009 p
->emit_rectlist
= ilo_3d_pipeline_emit_rectlist_gen6
;