ilo: implement pipe_context::bind_sampler_states()
[mesa.git] / src / gallium / drivers / ilo / ilo_3d_pipeline_gen7.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2013 LunarG, Inc.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "util/u_dual_blend.h"
29 #include "intel_reg.h"
30
31 #include "ilo_common.h"
32 #include "ilo_context.h"
33 #include "ilo_cp.h"
34 #include "ilo_gpe_gen7.h"
35 #include "ilo_shader.h"
36 #include "ilo_state.h"
37 #include "ilo_3d_pipeline.h"
38 #include "ilo_3d_pipeline_gen6.h"
39 #include "ilo_3d_pipeline_gen7.h"
40
41 static void
42 gen7_wa_pipe_control_cs_stall(struct ilo_3d_pipeline *p,
43 bool change_multisample_state,
44 bool change_depth_state)
45 {
46 struct intel_bo *bo = NULL;
47 uint32_t dw1 = PIPE_CONTROL_CS_STALL;
48
49 assert(p->dev->gen == ILO_GEN(7) || p->dev->gen == ILO_GEN(7.5));
50
51 /* emit once */
52 if (p->state.has_gen6_wa_pipe_control)
53 return;
54 p->state.has_gen6_wa_pipe_control = true;
55
56 /*
57 * From the Ivy Bridge PRM, volume 2 part 1, page 258:
58 *
59 * "Due to an HW issue driver needs to send a pipe control with stall
60 * when ever there is state change in depth bias related state"
61 *
62 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
63 *
64 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
65 * in the ring after this instruction
66 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
67 *
68 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
69 *
70 * "Driver must ierarchi that all the caches in the depth pipe are
71 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
72 * requires driver to send a PIPE_CONTROL with a CS stall along with a
73 * Depth Flush prior to this command.
74 *
75 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
76 *
77 * "Driver must send a least one PIPE_CONTROL command with CS Stall and
78 * a post sync operation prior to the group of depth
79 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
80 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
81 */
82
83 if (change_multisample_state)
84 dw1 |= PIPE_CONTROL_DEPTH_CACHE_FLUSH;
85
86 if (change_depth_state) {
87 dw1 |= PIPE_CONTROL_WRITE_IMMEDIATE;
88 bo = p->workaround_bo;
89 }
90
91 gen6_emit_PIPE_CONTROL(p->dev, dw1, bo, 0, false, p->cp);
92 }
93
94 static void
95 gen7_wa_pipe_control_vs_depth_stall(struct ilo_3d_pipeline *p)
96 {
97 assert(p->dev->gen == ILO_GEN(7) || p->dev->gen == ILO_GEN(7.5));
98
99 /*
100 * From the Ivy Bridge PRM, volume 2 part 1, page 106:
101 *
102 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
103 * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
104 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
105 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
106 * needs to be sent before any combination of VS associated 3DSTATE."
107 */
108 gen6_emit_PIPE_CONTROL(p->dev,
109 PIPE_CONTROL_DEPTH_STALL |
110 PIPE_CONTROL_WRITE_IMMEDIATE,
111 p->workaround_bo, 0, false, p->cp);
112 }
113
114 static void
115 gen7_wa_pipe_control_wm_depth_stall(struct ilo_3d_pipeline *p,
116 bool change_depth_buffer)
117 {
118 assert(p->dev->gen == ILO_GEN(7) || p->dev->gen == ILO_GEN(7.5));
119
120 /*
121 * From the Ivy Bridge PRM, volume 2 part 1, page 276:
122 *
123 * "The driver must make sure a PIPE_CONTROL with the Depth Stall
124 * Enable bit set after all the following states are programmed:
125 *
126 * * 3DSTATE_PS
127 * * 3DSTATE_VIEWPORT_STATE_POINTERS_CC
128 * * 3DSTATE_CONSTANT_PS
129 * * 3DSTATE_BINDING_TABLE_POINTERS_PS
130 * * 3DSTATE_SAMPLER_STATE_POINTERS_PS
131 * * 3DSTATE_CC_STATE_POINTERS
132 * * 3DSTATE_BLEND_STATE_POINTERS
133 * * 3DSTATE_DEPTH_STENCIL_STATE_POINTERS"
134 *
135 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
136 *
137 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
138 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
139 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
140 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
141 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
142 * Depth Flush Bit set, followed by another pipelined depth stall
143 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
144 * guarantee that the pipeline from WM onwards is already flushed
145 * (e.g., via a preceding MI_FLUSH)."
146 */
147 gen6_emit_PIPE_CONTROL(p->dev,
148 PIPE_CONTROL_DEPTH_STALL,
149 NULL, 0, false, p->cp);
150
151 if (!change_depth_buffer)
152 return;
153
154 gen6_emit_PIPE_CONTROL(p->dev,
155 PIPE_CONTROL_DEPTH_CACHE_FLUSH,
156 NULL, 0, false, p->cp);
157
158 gen6_emit_PIPE_CONTROL(p->dev,
159 PIPE_CONTROL_DEPTH_STALL,
160 NULL, 0, false, p->cp);
161 }
162
163 static void
164 gen7_wa_pipe_control_wm_max_threads_stall(struct ilo_3d_pipeline *p)
165 {
166 assert(p->dev->gen == ILO_GEN(7));
167
168 /*
169 * From the Ivy Bridge PRM, volume 2 part 1, page 286:
170 *
171 * "If this field (Maximum Number of Threads in 3DSTATE_WM) is changed
172 * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at
173 * Pixel Scoreboard set is required to be issued."
174 */
175 gen6_emit_PIPE_CONTROL(p->dev,
176 PIPE_CONTROL_STALL_AT_SCOREBOARD,
177 NULL, 0, false, p->cp);
178
179 }
180
181 #define DIRTY(state) (session->pipe_dirty & ILO_DIRTY_ ## state)
182
183 static void
184 gen7_pipeline_common_urb(struct ilo_3d_pipeline *p,
185 const struct ilo_context *ilo,
186 struct gen6_pipeline_session *session)
187 {
188 /* 3DSTATE_URB_{VS,GS,HS,DS} */
189 if (DIRTY(VE) || DIRTY(VS)) {
190 /* the first 16KB are reserved for VS and PS PCBs */
191 const int offset =
192 (p->dev->gen == ILO_GEN(7.5) && p->dev->gt == 3) ? 32768 : 16384;
193 int vs_entry_size, vs_total_size;
194
195 vs_entry_size = (ilo->vs) ?
196 ilo_shader_get_kernel_param(ilo->vs, ILO_KERNEL_OUTPUT_COUNT) : 0;
197
198 /*
199 * From the Ivy Bridge PRM, volume 2 part 1, page 35:
200 *
201 * "Programming Restriction: As the VS URB entry serves as both the
202 * per-vertex input and output of the VS shader, the VS URB
203 * Allocation Size must be sized to the maximum of the vertex input
204 * and output structures."
205 */
206 if (vs_entry_size < ilo->ve->count)
207 vs_entry_size = ilo->ve->count;
208
209 vs_entry_size *= sizeof(float) * 4;
210 vs_total_size = ilo->dev->urb_size - offset;
211
212 gen7_wa_pipe_control_vs_depth_stall(p);
213
214 gen7_emit_3DSTATE_URB_VS(p->dev,
215 offset, vs_total_size, vs_entry_size, p->cp);
216
217 gen7_emit_3DSTATE_URB_GS(p->dev, offset, 0, 0, p->cp);
218 gen7_emit_3DSTATE_URB_HS(p->dev, offset, 0, 0, p->cp);
219 gen7_emit_3DSTATE_URB_DS(p->dev, offset, 0, 0, p->cp);
220 }
221 }
222
223 static void
224 gen7_pipeline_common_pcb_alloc(struct ilo_3d_pipeline *p,
225 const struct ilo_context *ilo,
226 struct gen6_pipeline_session *session)
227 {
228 /* 3DSTATE_PUSH_CONSTANT_ALLOC_{VS,PS} */
229 if (session->hw_ctx_changed) {
230 /*
231 * Push constant buffers are only allowed to take up at most the first
232 * 16KB of the URB. Split the space evenly for VS and FS.
233 */
234 const int max_size =
235 (p->dev->gen == ILO_GEN(7.5) && p->dev->gt == 3) ? 32768 : 16384;
236 const int size = max_size / 2;
237 int offset = 0;
238
239 gen7_emit_3DSTATE_PUSH_CONSTANT_ALLOC_VS(p->dev, offset, size, p->cp);
240 offset += size;
241
242 gen7_emit_3DSTATE_PUSH_CONSTANT_ALLOC_PS(p->dev, offset, size, p->cp);
243
244 if (p->dev->gen == ILO_GEN(7))
245 gen7_wa_pipe_control_cs_stall(p, true, true);
246 }
247 }
248
249 static void
250 gen7_pipeline_common_pointers_1(struct ilo_3d_pipeline *p,
251 const struct ilo_context *ilo,
252 struct gen6_pipeline_session *session)
253 {
254 /* 3DSTATE_VIEWPORT_STATE_POINTERS_{CC,SF_CLIP} */
255 if (session->viewport_state_changed) {
256 gen7_emit_3DSTATE_VIEWPORT_STATE_POINTERS_CC(p->dev,
257 p->state.CC_VIEWPORT, p->cp);
258
259 gen7_emit_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(p->dev,
260 p->state.SF_CLIP_VIEWPORT, p->cp);
261 }
262 }
263
264 static void
265 gen7_pipeline_common_pointers_2(struct ilo_3d_pipeline *p,
266 const struct ilo_context *ilo,
267 struct gen6_pipeline_session *session)
268 {
269 /* 3DSTATE_BLEND_STATE_POINTERS */
270 if (session->cc_state_blend_changed) {
271 gen7_emit_3DSTATE_BLEND_STATE_POINTERS(p->dev,
272 p->state.BLEND_STATE, p->cp);
273 }
274
275 /* 3DSTATE_CC_STATE_POINTERS */
276 if (session->cc_state_cc_changed) {
277 gen7_emit_3DSTATE_CC_STATE_POINTERS(p->dev,
278 p->state.COLOR_CALC_STATE, p->cp);
279 }
280
281 /* 3DSTATE_DEPTH_STENCIL_STATE_POINTERS */
282 if (session->cc_state_dsa_changed) {
283 gen7_emit_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(p->dev,
284 p->state.DEPTH_STENCIL_STATE, p->cp);
285 }
286 }
287
288 static void
289 gen7_pipeline_vs(struct ilo_3d_pipeline *p,
290 const struct ilo_context *ilo,
291 struct gen6_pipeline_session *session)
292 {
293 const bool emit_3dstate_binding_table = session->binding_table_vs_changed;
294 const bool emit_3dstate_sampler_state = session->sampler_state_vs_changed;
295 /* see gen6_pipeline_vs() */
296 const bool emit_3dstate_constant_vs = session->pcb_state_vs_changed;
297 const bool emit_3dstate_vs = (DIRTY(VS) || DIRTY(SAMPLER_VS) ||
298 session->kernel_bo_changed);
299
300 /* emit depth stall before any of the VS commands */
301 if (emit_3dstate_binding_table || emit_3dstate_sampler_state ||
302 emit_3dstate_constant_vs || emit_3dstate_vs)
303 gen7_wa_pipe_control_vs_depth_stall(p);
304
305 /* 3DSTATE_BINDING_TABLE_POINTERS_VS */
306 if (emit_3dstate_binding_table) {
307 gen7_emit_3DSTATE_BINDING_TABLE_POINTERS_VS(p->dev,
308 p->state.vs.BINDING_TABLE_STATE, p->cp);
309 }
310
311 /* 3DSTATE_SAMPLER_STATE_POINTERS_VS */
312 if (emit_3dstate_sampler_state) {
313 gen7_emit_3DSTATE_SAMPLER_STATE_POINTERS_VS(p->dev,
314 p->state.vs.SAMPLER_STATE, p->cp);
315 }
316
317 /* 3DSTATE_CONSTANT_VS */
318 if (emit_3dstate_constant_vs) {
319 gen7_emit_3DSTATE_CONSTANT_VS(p->dev,
320 &p->state.vs.PUSH_CONSTANT_BUFFER,
321 &p->state.vs.PUSH_CONSTANT_BUFFER_size,
322 1, p->cp);
323 }
324
325 /* 3DSTATE_VS */
326 if (emit_3dstate_vs) {
327 const int num_samplers = ilo->sampler[PIPE_SHADER_VERTEX].count;
328
329 gen6_emit_3DSTATE_VS(p->dev, ilo->vs, num_samplers, p->cp);
330 }
331 }
332
333 static void
334 gen7_pipeline_hs(struct ilo_3d_pipeline *p,
335 const struct ilo_context *ilo,
336 struct gen6_pipeline_session *session)
337 {
338 /* 3DSTATE_CONSTANT_HS and 3DSTATE_HS */
339 if (session->hw_ctx_changed) {
340 gen7_emit_3DSTATE_CONSTANT_HS(p->dev, 0, 0, 0, p->cp);
341 gen7_emit_3DSTATE_HS(p->dev, NULL, 0, p->cp);
342 }
343
344 /* 3DSTATE_BINDING_TABLE_POINTERS_HS */
345 if (session->hw_ctx_changed)
346 gen7_emit_3DSTATE_BINDING_TABLE_POINTERS_HS(p->dev, 0, p->cp);
347 }
348
349 static void
350 gen7_pipeline_te(struct ilo_3d_pipeline *p,
351 const struct ilo_context *ilo,
352 struct gen6_pipeline_session *session)
353 {
354 /* 3DSTATE_TE */
355 if (session->hw_ctx_changed)
356 gen7_emit_3DSTATE_TE(p->dev, p->cp);
357 }
358
359 static void
360 gen7_pipeline_ds(struct ilo_3d_pipeline *p,
361 const struct ilo_context *ilo,
362 struct gen6_pipeline_session *session)
363 {
364 /* 3DSTATE_CONSTANT_DS and 3DSTATE_DS */
365 if (session->hw_ctx_changed) {
366 gen7_emit_3DSTATE_CONSTANT_DS(p->dev, 0, 0, 0, p->cp);
367 gen7_emit_3DSTATE_DS(p->dev, NULL, 0, p->cp);
368 }
369
370 /* 3DSTATE_BINDING_TABLE_POINTERS_DS */
371 if (session->hw_ctx_changed)
372 gen7_emit_3DSTATE_BINDING_TABLE_POINTERS_DS(p->dev, 0, p->cp);
373
374 }
375
376 static void
377 gen7_pipeline_gs(struct ilo_3d_pipeline *p,
378 const struct ilo_context *ilo,
379 struct gen6_pipeline_session *session)
380 {
381 /* 3DSTATE_CONSTANT_GS and 3DSTATE_GS */
382 if (session->hw_ctx_changed) {
383 gen7_emit_3DSTATE_CONSTANT_GS(p->dev, 0, 0, 0, p->cp);
384 gen7_emit_3DSTATE_GS(p->dev, NULL, 0, p->cp);
385 }
386
387 /* 3DSTATE_BINDING_TABLE_POINTERS_GS */
388 if (session->binding_table_gs_changed) {
389 gen7_emit_3DSTATE_BINDING_TABLE_POINTERS_GS(p->dev,
390 p->state.gs.BINDING_TABLE_STATE, p->cp);
391 }
392 }
393
394 static void
395 gen7_pipeline_sol(struct ilo_3d_pipeline *p,
396 const struct ilo_context *ilo,
397 struct gen6_pipeline_session *session)
398 {
399 const struct pipe_stream_output_info *so_info;
400 const struct ilo_shader_state *shader;
401 bool dirty_sh = false;
402
403 if (ilo->gs) {
404 shader = ilo->gs;
405 dirty_sh = DIRTY(GS);
406 }
407 else {
408 shader = ilo->vs;
409 dirty_sh = DIRTY(VS);
410 }
411
412 so_info = ilo_shader_get_kernel_so_info(shader);
413
414 gen6_pipeline_update_max_svbi(p, ilo, session);
415
416 /* 3DSTATE_SO_BUFFER */
417 if ((DIRTY(SO) || dirty_sh || session->batch_bo_changed) &&
418 ilo->so.enabled) {
419 int i;
420
421 for (i = 0; i < ilo->so.count; i++) {
422 const int stride = so_info->stride[i] * 4; /* in bytes */
423 int base = 0;
424
425 /* reset HW write offsets and offset buffer base */
426 if (!p->cp->render_ctx) {
427 ilo_cp_set_one_off_flags(p->cp, INTEL_EXEC_GEN7_SOL_RESET);
428 base += p->state.so_num_vertices * stride;
429 }
430
431 gen7_emit_3DSTATE_SO_BUFFER(p->dev, i, base, stride,
432 ilo->so.states[i], p->cp);
433 }
434
435 for (; i < 4; i++)
436 gen7_emit_3DSTATE_SO_BUFFER(p->dev, i, 0, 0, NULL, p->cp);
437 }
438
439 /* 3DSTATE_SO_DECL_LIST */
440 if (dirty_sh && ilo->so.enabled)
441 gen7_emit_3DSTATE_SO_DECL_LIST(p->dev, so_info, p->cp);
442
443 /* 3DSTATE_STREAMOUT */
444 if (DIRTY(SO) || DIRTY(RASTERIZER) || dirty_sh) {
445 const unsigned buffer_mask = (1 << ilo->so.count) - 1;
446 const int output_count = ilo_shader_get_kernel_param(shader,
447 ILO_KERNEL_OUTPUT_COUNT);
448
449 gen7_emit_3DSTATE_STREAMOUT(p->dev, buffer_mask, output_count,
450 ilo->rasterizer->state.rasterizer_discard, p->cp);
451 }
452 }
453
454 static void
455 gen7_pipeline_sf(struct ilo_3d_pipeline *p,
456 const struct ilo_context *ilo,
457 struct gen6_pipeline_session *session)
458 {
459 /* 3DSTATE_SBE */
460 if (DIRTY(RASTERIZER) || DIRTY(FS))
461 gen7_emit_3DSTATE_SBE(p->dev, ilo->rasterizer, ilo->fs, ilo->cp);
462
463 /* 3DSTATE_SF */
464 if (DIRTY(RASTERIZER) || DIRTY(FB)) {
465 gen7_wa_pipe_control_cs_stall(p, true, true);
466 gen7_emit_3DSTATE_SF(p->dev, ilo->rasterizer, ilo->fb.state.zsbuf, p->cp);
467 }
468 }
469
470 static void
471 gen7_pipeline_wm(struct ilo_3d_pipeline *p,
472 const struct ilo_context *ilo,
473 struct gen6_pipeline_session *session)
474 {
475 /* 3DSTATE_WM */
476 if (DIRTY(FS) || DIRTY(BLEND) || DIRTY(DSA) || DIRTY(RASTERIZER)) {
477 const bool cc_may_kill = (ilo->dsa->dw_alpha ||
478 ilo->blend->alpha_to_coverage);
479
480 if (p->dev->gen == ILO_GEN(7) && session->hw_ctx_changed)
481 gen7_wa_pipe_control_wm_max_threads_stall(p);
482
483 gen7_emit_3DSTATE_WM(p->dev, ilo->fs,
484 ilo->rasterizer, cc_may_kill, p->cp);
485 }
486
487 /* 3DSTATE_BINDING_TABLE_POINTERS_PS */
488 if (session->binding_table_fs_changed) {
489 gen7_emit_3DSTATE_BINDING_TABLE_POINTERS_PS(p->dev,
490 p->state.wm.BINDING_TABLE_STATE, p->cp);
491 }
492
493 /* 3DSTATE_SAMPLER_STATE_POINTERS_PS */
494 if (session->sampler_state_fs_changed) {
495 gen7_emit_3DSTATE_SAMPLER_STATE_POINTERS_PS(p->dev,
496 p->state.wm.SAMPLER_STATE, p->cp);
497 }
498
499 /* 3DSTATE_CONSTANT_PS */
500 if (session->pcb_state_fs_changed) {
501 gen7_emit_3DSTATE_CONSTANT_PS(p->dev,
502 &p->state.wm.PUSH_CONSTANT_BUFFER,
503 &p->state.wm.PUSH_CONSTANT_BUFFER_size,
504 1, p->cp);
505 }
506
507 /* 3DSTATE_PS */
508 if (DIRTY(FS) || DIRTY(SAMPLER_FS) || DIRTY(BLEND) ||
509 session->kernel_bo_changed) {
510 const int num_samplers = ilo->sampler[PIPE_SHADER_FRAGMENT].count;
511 const bool dual_blend = ilo->blend->dual_blend;
512
513 gen7_emit_3DSTATE_PS(p->dev, ilo->fs, num_samplers, dual_blend, p->cp);
514 }
515
516 /* 3DSTATE_SCISSOR_STATE_POINTERS */
517 if (session->scissor_state_changed) {
518 gen6_emit_3DSTATE_SCISSOR_STATE_POINTERS(p->dev,
519 p->state.SCISSOR_RECT, p->cp);
520 }
521
522 /* XXX what is the best way to know if this workaround is needed? */
523 {
524 const bool emit_3dstate_ps =
525 (DIRTY(FS) || DIRTY(SAMPLER_FS) || DIRTY(BLEND));
526 const bool emit_3dstate_depth_buffer =
527 (DIRTY(FB) || DIRTY(DSA) || session->state_bo_changed);
528
529 if (emit_3dstate_ps ||
530 emit_3dstate_depth_buffer ||
531 session->pcb_state_fs_changed ||
532 session->viewport_state_changed ||
533 session->binding_table_fs_changed ||
534 session->sampler_state_fs_changed ||
535 session->cc_state_cc_changed ||
536 session->cc_state_blend_changed ||
537 session->cc_state_dsa_changed)
538 gen7_wa_pipe_control_wm_depth_stall(p, emit_3dstate_depth_buffer);
539 }
540
541 /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
542 if (DIRTY(FB) || session->batch_bo_changed) {
543 const struct ilo_zs_surface *zs;
544
545 if (ilo->fb.state.zsbuf) {
546 const struct ilo_surface_cso *surface =
547 (const struct ilo_surface_cso *) ilo->fb.state.zsbuf;
548
549 assert(!surface->is_rt);
550 zs = &surface->u.zs;
551 }
552 else {
553 zs = &ilo->fb.null_zs;
554 }
555
556 gen6_emit_3DSTATE_DEPTH_BUFFER(p->dev, zs, p->cp);
557 gen6_emit_3DSTATE_HIER_DEPTH_BUFFER(p->dev, zs, p->cp);
558 gen6_emit_3DSTATE_STENCIL_BUFFER(p->dev, zs, p->cp);
559
560 /* TODO */
561 gen7_emit_3DSTATE_CLEAR_PARAMS(p->dev, 0, p->cp);
562 }
563 }
564
565 static void
566 gen7_pipeline_wm_multisample(struct ilo_3d_pipeline *p,
567 const struct ilo_context *ilo,
568 struct gen6_pipeline_session *session)
569 {
570 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
571 if (DIRTY(SAMPLE_MASK) || DIRTY(FB)) {
572 const uint32_t *packed_sample_pos;
573
574 gen7_wa_pipe_control_cs_stall(p, true, true);
575
576 packed_sample_pos =
577 (ilo->fb.num_samples > 4) ? p->packed_sample_position_8x :
578 (ilo->fb.num_samples > 1) ? &p->packed_sample_position_4x :
579 &p->packed_sample_position_1x;
580
581 gen6_emit_3DSTATE_MULTISAMPLE(p->dev,
582 ilo->fb.num_samples, packed_sample_pos,
583 ilo->rasterizer->state.half_pixel_center, p->cp);
584
585 gen7_emit_3DSTATE_SAMPLE_MASK(p->dev,
586 (ilo->fb.num_samples > 1) ? ilo->sample_mask : 0x1,
587 ilo->fb.num_samples, p->cp);
588 }
589 }
590
591 static void
592 gen7_pipeline_vf_draw(struct ilo_3d_pipeline *p,
593 const struct ilo_context *ilo,
594 struct gen6_pipeline_session *session)
595 {
596 /* 3DPRIMITIVE */
597 gen7_emit_3DPRIMITIVE(p->dev, ilo->draw, &ilo->ib, false, p->cp);
598 p->state.has_gen6_wa_pipe_control = false;
599 }
600
601 static void
602 gen7_pipeline_commands(struct ilo_3d_pipeline *p,
603 const struct ilo_context *ilo,
604 struct gen6_pipeline_session *session)
605 {
606 /*
607 * We try to keep the order of the commands match, as closely as possible,
608 * that of the classic i965 driver. It allows us to compare the command
609 * streams easily.
610 */
611 gen6_pipeline_common_select(p, ilo, session);
612 gen6_pipeline_common_sip(p, ilo, session);
613 gen6_pipeline_vf_statistics(p, ilo, session);
614 gen7_pipeline_common_pcb_alloc(p, ilo, session);
615 gen6_pipeline_common_base_address(p, ilo, session);
616 gen7_pipeline_common_pointers_1(p, ilo, session);
617 gen7_pipeline_common_urb(p, ilo, session);
618 gen7_pipeline_common_pointers_2(p, ilo, session);
619 gen7_pipeline_wm_multisample(p, ilo, session);
620 gen7_pipeline_gs(p, ilo, session);
621 gen7_pipeline_hs(p, ilo, session);
622 gen7_pipeline_te(p, ilo, session);
623 gen7_pipeline_ds(p, ilo, session);
624 gen7_pipeline_vs(p, ilo, session);
625 gen7_pipeline_sol(p, ilo, session);
626 gen6_pipeline_clip(p, ilo, session);
627 gen7_pipeline_sf(p, ilo, session);
628 gen7_pipeline_wm(p, ilo, session);
629 gen6_pipeline_wm_raster(p, ilo, session);
630 gen6_pipeline_sf_rect(p, ilo, session);
631 gen6_pipeline_vf(p, ilo, session);
632 gen7_pipeline_vf_draw(p, ilo, session);
633 }
634
635 static void
636 ilo_3d_pipeline_emit_draw_gen7(struct ilo_3d_pipeline *p,
637 const struct ilo_context *ilo)
638 {
639 struct gen6_pipeline_session session;
640
641 gen6_pipeline_prepare(p, ilo, &session);
642
643 session.emit_draw_states = gen6_pipeline_states;
644 session.emit_draw_commands = gen7_pipeline_commands;
645
646 gen6_pipeline_draw(p, ilo, &session);
647 gen6_pipeline_end(p, ilo, &session);
648 }
649
650 static int
651 gen7_pipeline_estimate_commands(const struct ilo_3d_pipeline *p,
652 const struct ilo_context *ilo)
653 {
654 static int size;
655 enum ilo_gpe_gen7_command cmd;
656
657 if (size)
658 return size;
659
660 for (cmd = 0; cmd < ILO_GPE_GEN7_COMMAND_COUNT; cmd++) {
661 int count;
662
663 switch (cmd) {
664 case ILO_GPE_GEN7_PIPE_CONTROL:
665 /* for the workaround */
666 count = 2;
667 /* another one after 3DSTATE_URB */
668 count += 1;
669 /* and another one after 3DSTATE_CONSTANT_VS */
670 count += 1;
671 break;
672 case ILO_GPE_GEN7_3DSTATE_VERTEX_BUFFERS:
673 count = 33;
674 break;
675 case ILO_GPE_GEN7_3DSTATE_VERTEX_ELEMENTS:
676 count = 34;
677 break;
678 case ILO_GPE_GEN7_MEDIA_VFE_STATE:
679 case ILO_GPE_GEN7_MEDIA_CURBE_LOAD:
680 case ILO_GPE_GEN7_MEDIA_INTERFACE_DESCRIPTOR_LOAD:
681 case ILO_GPE_GEN7_MEDIA_STATE_FLUSH:
682 case ILO_GPE_GEN7_GPGPU_WALKER:
683 /* media commands */
684 count = 0;
685 break;
686 default:
687 count = 1;
688 break;
689 }
690
691 if (count) {
692 size += ilo_gpe_gen7_estimate_command_size(p->dev,
693 cmd, count);
694 }
695 }
696
697 return size;
698 }
699
700 static int
701 gen7_pipeline_estimate_states(const struct ilo_3d_pipeline *p,
702 const struct ilo_context *ilo)
703 {
704 static int static_size;
705 int shader_type, count, size;
706
707 if (!static_size) {
708 struct {
709 enum ilo_gpe_gen7_state state;
710 int count;
711 } static_states[] = {
712 /* viewports */
713 { ILO_GPE_GEN7_SF_CLIP_VIEWPORT, 1 },
714 { ILO_GPE_GEN7_CC_VIEWPORT, 1 },
715 /* cc */
716 { ILO_GPE_GEN7_COLOR_CALC_STATE, 1 },
717 { ILO_GPE_GEN7_BLEND_STATE, ILO_MAX_DRAW_BUFFERS },
718 { ILO_GPE_GEN7_DEPTH_STENCIL_STATE, 1 },
719 /* scissors */
720 { ILO_GPE_GEN7_SCISSOR_RECT, 1 },
721 /* binding table (vs, gs, fs) */
722 { ILO_GPE_GEN7_BINDING_TABLE_STATE, ILO_MAX_VS_SURFACES },
723 { ILO_GPE_GEN7_BINDING_TABLE_STATE, ILO_MAX_GS_SURFACES },
724 { ILO_GPE_GEN7_BINDING_TABLE_STATE, ILO_MAX_WM_SURFACES },
725 };
726 int i;
727
728 for (i = 0; i < Elements(static_states); i++) {
729 static_size += ilo_gpe_gen7_estimate_state_size(p->dev,
730 static_states[i].state,
731 static_states[i].count);
732 }
733 }
734
735 size = static_size;
736
737 /*
738 * render targets (fs)
739 * sampler views (vs, fs)
740 * constant buffers (vs, fs)
741 */
742 count = ilo->fb.state.nr_cbufs;
743 for (shader_type = 0; shader_type < PIPE_SHADER_TYPES; shader_type++) {
744 count += ilo->view[shader_type].count;
745 count += util_bitcount(ilo->cbuf[shader_type].enabled_mask);
746 }
747
748 if (count) {
749 size += ilo_gpe_gen7_estimate_state_size(p->dev,
750 ILO_GPE_GEN7_SURFACE_STATE, count);
751 }
752
753 /* samplers (vs, fs) */
754 for (shader_type = 0; shader_type < PIPE_SHADER_TYPES; shader_type++) {
755 count = ilo->sampler[shader_type].count;
756 if (count) {
757 size += ilo_gpe_gen7_estimate_state_size(p->dev,
758 ILO_GPE_GEN7_SAMPLER_BORDER_COLOR_STATE, count);
759 size += ilo_gpe_gen7_estimate_state_size(p->dev,
760 ILO_GPE_GEN7_SAMPLER_STATE, count);
761 }
762 }
763
764 /* pcb (vs) */
765 if (ilo->vs) {
766 const int cbuf0_size =
767 ilo_shader_get_kernel_param(ilo->vs, ILO_KERNEL_PCB_CBUF0_SIZE);
768 const int ucp_size =
769 ilo_shader_get_kernel_param(ilo->vs, ILO_KERNEL_VS_PCB_UCP_SIZE);
770
771 size += ilo_gpe_gen7_estimate_state_size(p->dev,
772 ILO_GPE_GEN7_PUSH_CONSTANT_BUFFER, cbuf0_size + ucp_size);
773 }
774
775 /* pcb (fs) */
776 if (ilo->fs) {
777 const int cbuf0_size =
778 ilo_shader_get_kernel_param(ilo->fs, ILO_KERNEL_PCB_CBUF0_SIZE);
779
780 size += ilo_gpe_gen7_estimate_state_size(p->dev,
781 ILO_GPE_GEN7_PUSH_CONSTANT_BUFFER, cbuf0_size);
782 }
783
784 return size;
785 }
786
787 static int
788 ilo_3d_pipeline_estimate_size_gen7(struct ilo_3d_pipeline *p,
789 enum ilo_3d_pipeline_action action,
790 const void *arg)
791 {
792 int size;
793
794 switch (action) {
795 case ILO_3D_PIPELINE_DRAW:
796 {
797 const struct ilo_context *ilo = arg;
798
799 size = gen7_pipeline_estimate_commands(p, ilo) +
800 gen7_pipeline_estimate_states(p, ilo);
801 }
802 break;
803 case ILO_3D_PIPELINE_FLUSH:
804 case ILO_3D_PIPELINE_WRITE_TIMESTAMP:
805 case ILO_3D_PIPELINE_WRITE_DEPTH_COUNT:
806 size = ilo_gpe_gen7_estimate_command_size(p->dev,
807 ILO_GPE_GEN7_PIPE_CONTROL, 1);
808 break;
809 default:
810 assert(!"unknown 3D pipeline action");
811 size = 0;
812 break;
813 }
814
815 return size;
816 }
817
818 void
819 ilo_3d_pipeline_init_gen7(struct ilo_3d_pipeline *p)
820 {
821 p->estimate_size = ilo_3d_pipeline_estimate_size_gen7;
822 p->emit_draw = ilo_3d_pipeline_emit_draw_gen7;
823 p->emit_flush = ilo_3d_pipeline_emit_flush_gen6;
824 p->emit_write_timestamp = ilo_3d_pipeline_emit_write_timestamp_gen6;
825 p->emit_write_depth_count = ilo_3d_pipeline_emit_write_depth_count_gen6;
826 }