ilo: embed ilo_state_urb in ilo_state_vector
[mesa.git] / src / gallium / drivers / ilo / ilo_render_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 "genhw/genhw.h"
29 #include "core/ilo_builder_3d.h"
30 #include "core/ilo_builder_render.h"
31
32 #include "ilo_blitter.h"
33 #include "ilo_shader.h"
34 #include "ilo_state.h"
35 #include "ilo_render_gen.h"
36
37 static void
38 gen7_wa_post_3dstate_push_constant_alloc_ps(struct ilo_render *r)
39 {
40 /*
41 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
42 *
43 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
44 * in the ring after this instruction
45 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
46 */
47 const uint32_t dw1 = GEN6_PIPE_CONTROL_CS_STALL;
48
49 ILO_DEV_ASSERT(r->dev, 7, 7);
50
51 r->state.deferred_pipe_control_dw1 |= dw1;
52 }
53
54 static void
55 gen7_wa_pre_vs(struct ilo_render *r)
56 {
57 /*
58 * From the Ivy Bridge PRM, volume 2 part 1, page 106:
59 *
60 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
61 * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
62 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
63 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
64 * needs to be sent before any combination of VS associated 3DSTATE."
65 */
66 const uint32_t dw1 = GEN6_PIPE_CONTROL_DEPTH_STALL |
67 GEN6_PIPE_CONTROL_WRITE_IMM;
68
69 ILO_DEV_ASSERT(r->dev, 7, 7);
70
71 if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
72 ilo_render_pipe_control(r, dw1);
73 }
74
75 static void
76 gen7_wa_pre_3dstate_sf_depth_bias(struct ilo_render *r)
77 {
78 /*
79 * From the Ivy Bridge PRM, volume 2 part 1, page 258:
80 *
81 * "Due to an HW issue driver needs to send a pipe control with stall
82 * when ever there is state change in depth bias related state (in
83 * 3DSTATE_SF)"
84 */
85 const uint32_t dw1 = GEN6_PIPE_CONTROL_CS_STALL;
86
87 ILO_DEV_ASSERT(r->dev, 7, 7);
88
89 if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
90 ilo_render_pipe_control(r, dw1);
91 }
92
93 static void
94 gen7_wa_pre_3dstate_multisample(struct ilo_render *r)
95 {
96 /*
97 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
98 *
99 * "Driver must ierarchi that all the caches in the depth pipe are
100 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
101 * requires driver to send a PIPE_CONTROL with a CS stall along with a
102 * Depth Flush prior to this command.
103 */
104 const uint32_t dw1 = GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
105 GEN6_PIPE_CONTROL_CS_STALL;
106
107 ILO_DEV_ASSERT(r->dev, 7, 7.5);
108
109 if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
110 ilo_render_pipe_control(r, dw1);
111 }
112
113 static void
114 gen7_wa_pre_depth(struct ilo_render *r)
115 {
116 ILO_DEV_ASSERT(r->dev, 7, 7.5);
117
118 if (ilo_dev_gen(r->dev) == ILO_GEN(7)) {
119 /*
120 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
121 *
122 * "Driver must send a least one PIPE_CONTROL command with CS Stall
123 * and a post sync operation prior to the group of depth
124 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
125 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
126 */
127 const uint32_t dw1 = GEN6_PIPE_CONTROL_CS_STALL |
128 GEN6_PIPE_CONTROL_WRITE_IMM;
129
130 if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
131 ilo_render_pipe_control(r, dw1);
132 }
133
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 ilo_render_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_STALL);
148 ilo_render_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH);
149 ilo_render_pipe_control(r, GEN6_PIPE_CONTROL_DEPTH_STALL);
150 }
151
152 static void
153 gen7_wa_pre_3dstate_ps_max_threads(struct ilo_render *r)
154 {
155 /*
156 * From the Ivy Bridge PRM, volume 2 part 1, page 286:
157 *
158 * "If this field (Maximum Number of Threads in 3DSTATE_PS) is changed
159 * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at
160 * Pixel Scoreboard set is required to be issued."
161 */
162 const uint32_t dw1 = GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
163
164 ILO_DEV_ASSERT(r->dev, 7, 7.5);
165
166 if ((r->state.current_pipe_control_dw1 & dw1) != dw1)
167 ilo_render_pipe_control(r, dw1);
168 }
169
170 static void
171 gen7_wa_post_ps_and_later(struct ilo_render *r)
172 {
173 /*
174 * From the Ivy Bridge PRM, volume 2 part 1, page 276:
175 *
176 * "The driver must make sure a PIPE_CONTROL with the Depth Stall
177 * Enable bit set after all the following states are programmed:
178 *
179 * - 3DSTATE_PS
180 * - 3DSTATE_VIEWPORT_STATE_POINTERS_CC
181 * - 3DSTATE_CONSTANT_PS
182 * - 3DSTATE_BINDING_TABLE_POINTERS_PS
183 * - 3DSTATE_SAMPLER_STATE_POINTERS_PS
184 * - 3DSTATE_CC_STATE_POINTERS
185 * - 3DSTATE_BLEND_STATE_POINTERS
186 * - 3DSTATE_DEPTH_STENCIL_STATE_POINTERS"
187 */
188 const uint32_t dw1 = GEN6_PIPE_CONTROL_DEPTH_STALL;
189
190 ILO_DEV_ASSERT(r->dev, 7, 7);
191
192 r->state.deferred_pipe_control_dw1 |= dw1;
193 }
194
195 #define DIRTY(state) (session->pipe_dirty & ILO_DIRTY_ ## state)
196
197 void
198 gen7_draw_common_urb(struct ilo_render *r,
199 const struct ilo_state_vector *vec,
200 struct ilo_render_draw_session *session)
201 {
202 /* 3DSTATE_URB_{VS,GS,HS,DS} */
203 if (session->urb_delta.dirty & (ILO_STATE_URB_3DSTATE_URB_VS |
204 ILO_STATE_URB_3DSTATE_URB_HS |
205 ILO_STATE_URB_3DSTATE_URB_DS |
206 ILO_STATE_URB_3DSTATE_URB_GS)) {
207 if (ilo_dev_gen(r->dev) == ILO_GEN(7))
208 gen7_wa_pre_vs(r);
209
210 gen7_3DSTATE_URB_VS(r->builder, &vec->urb);
211 gen7_3DSTATE_URB_GS(r->builder, &vec->urb);
212 gen7_3DSTATE_URB_HS(r->builder, &vec->urb);
213 gen7_3DSTATE_URB_DS(r->builder, &vec->urb);
214 }
215 }
216
217 void
218 gen7_draw_common_pcb_alloc(struct ilo_render *r,
219 const struct ilo_state_vector *vec,
220 struct ilo_render_draw_session *session)
221 {
222 /* 3DSTATE_PUSH_CONSTANT_ALLOC_{VS,PS} */
223 if (session->urb_delta.dirty &
224 (ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_VS |
225 ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_HS |
226 ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_DS |
227 ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_GS |
228 ILO_STATE_URB_3DSTATE_PUSH_CONSTANT_ALLOC_PS)) {
229 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(r->builder, &vec->urb);
230 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_GS(r->builder, &vec->urb);
231 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(r->builder, &vec->urb);
232
233 if (ilo_dev_gen(r->dev) == ILO_GEN(7))
234 gen7_wa_post_3dstate_push_constant_alloc_ps(r);
235 }
236 }
237
238 void
239 gen7_draw_common_pointers_1(struct ilo_render *r,
240 const struct ilo_state_vector *vec,
241 struct ilo_render_draw_session *session)
242 {
243 /* 3DSTATE_VIEWPORT_STATE_POINTERS_{CC,SF_CLIP} */
244 if (session->viewport_changed) {
245 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(r->builder,
246 r->state.CC_VIEWPORT);
247
248 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(r->builder,
249 r->state.SF_CLIP_VIEWPORT);
250 }
251 }
252
253 void
254 gen7_draw_common_pointers_2(struct ilo_render *r,
255 const struct ilo_state_vector *vec,
256 struct ilo_render_draw_session *session)
257 {
258 /* 3DSTATE_BLEND_STATE_POINTERS */
259 if (session->blend_changed) {
260 gen7_3DSTATE_BLEND_STATE_POINTERS(r->builder,
261 r->state.BLEND_STATE);
262 }
263
264 /* 3DSTATE_CC_STATE_POINTERS */
265 if (session->cc_changed) {
266 gen7_3DSTATE_CC_STATE_POINTERS(r->builder,
267 r->state.COLOR_CALC_STATE);
268 }
269
270 /* 3DSTATE_DEPTH_STENCIL_STATE_POINTERS */
271 if (ilo_dev_gen(r->dev) < ILO_GEN(8) && session->dsa_changed) {
272 gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(r->builder,
273 r->state.DEPTH_STENCIL_STATE);
274 }
275 }
276
277 void
278 gen7_draw_vs(struct ilo_render *r,
279 const struct ilo_state_vector *vec,
280 struct ilo_render_draw_session *session)
281 {
282 const bool emit_3dstate_binding_table = session->binding_table_vs_changed;
283 const bool emit_3dstate_sampler_state = session->sampler_vs_changed;
284 /* see gen6_draw_vs() */
285 const bool emit_3dstate_constant_vs = session->pcb_vs_changed;
286 const bool emit_3dstate_vs = (DIRTY(VS) || r->instruction_bo_changed);
287
288 /* emit depth stall before any of the VS commands */
289 if (ilo_dev_gen(r->dev) == ILO_GEN(7)) {
290 if (emit_3dstate_binding_table || emit_3dstate_sampler_state ||
291 emit_3dstate_constant_vs || emit_3dstate_vs)
292 gen7_wa_pre_vs(r);
293 }
294
295 /* 3DSTATE_BINDING_TABLE_POINTERS_VS */
296 if (emit_3dstate_binding_table) {
297 gen7_3DSTATE_BINDING_TABLE_POINTERS_VS(r->builder,
298 r->state.vs.BINDING_TABLE_STATE);
299 }
300
301 /* 3DSTATE_SAMPLER_STATE_POINTERS_VS */
302 if (emit_3dstate_sampler_state) {
303 gen7_3DSTATE_SAMPLER_STATE_POINTERS_VS(r->builder,
304 r->state.vs.SAMPLER_STATE);
305 }
306
307 /* 3DSTATE_CONSTANT_VS */
308 if (emit_3dstate_constant_vs) {
309 gen7_3DSTATE_CONSTANT_VS(r->builder,
310 &r->state.vs.PUSH_CONSTANT_BUFFER,
311 &r->state.vs.PUSH_CONSTANT_BUFFER_size,
312 1);
313 }
314
315 /* 3DSTATE_VS */
316 if (ilo_dev_gen(r->dev) >= ILO_GEN(8)) {
317 if (emit_3dstate_vs || DIRTY(RASTERIZER)) {
318 gen8_3DSTATE_VS(r->builder, vec->vs,
319 vec->rasterizer->state.clip_plane_enable);
320 }
321 } else {
322 if (emit_3dstate_vs)
323 gen6_3DSTATE_VS(r->builder, vec->vs);
324 }
325 }
326
327 void
328 gen7_draw_hs(struct ilo_render *r,
329 const struct ilo_state_vector *vec,
330 struct ilo_render_draw_session *session)
331 {
332 /* 3DSTATE_CONSTANT_HS and 3DSTATE_HS */
333 if (r->hw_ctx_changed) {
334 gen7_3DSTATE_CONSTANT_HS(r->builder, 0, 0, 0);
335 gen7_disable_3DSTATE_HS(r->builder);
336 }
337
338 /* 3DSTATE_BINDING_TABLE_POINTERS_HS */
339 if (r->hw_ctx_changed)
340 gen7_3DSTATE_BINDING_TABLE_POINTERS_HS(r->builder, 0);
341 }
342
343 void
344 gen7_draw_te(struct ilo_render *r,
345 const struct ilo_state_vector *vec,
346 struct ilo_render_draw_session *session)
347 {
348 /* 3DSTATE_TE */
349 if (r->hw_ctx_changed)
350 gen7_3DSTATE_TE(r->builder);
351 }
352
353 void
354 gen7_draw_ds(struct ilo_render *r,
355 const struct ilo_state_vector *vec,
356 struct ilo_render_draw_session *session)
357 {
358 /* 3DSTATE_CONSTANT_DS and 3DSTATE_DS */
359 if (r->hw_ctx_changed) {
360 gen7_3DSTATE_CONSTANT_DS(r->builder, 0, 0, 0);
361 gen7_disable_3DSTATE_DS(r->builder);
362 }
363
364 /* 3DSTATE_BINDING_TABLE_POINTERS_DS */
365 if (r->hw_ctx_changed)
366 gen7_3DSTATE_BINDING_TABLE_POINTERS_DS(r->builder, 0);
367
368 }
369
370 void
371 gen7_draw_gs(struct ilo_render *r,
372 const struct ilo_state_vector *vec,
373 struct ilo_render_draw_session *session)
374 {
375 /* 3DSTATE_CONSTANT_GS and 3DSTATE_GS */
376 if (r->hw_ctx_changed) {
377 gen7_3DSTATE_CONSTANT_GS(r->builder, 0, 0, 0);
378 gen7_disable_3DSTATE_GS(r->builder);
379 }
380
381 /* 3DSTATE_BINDING_TABLE_POINTERS_GS */
382 if (session->binding_table_gs_changed) {
383 gen7_3DSTATE_BINDING_TABLE_POINTERS_GS(r->builder,
384 r->state.gs.BINDING_TABLE_STATE);
385 }
386 }
387
388 void
389 gen7_draw_sol(struct ilo_render *r,
390 const struct ilo_state_vector *vec,
391 struct ilo_render_draw_session *session)
392 {
393 const struct ilo_state_sol *sol;
394 const struct ilo_shader_state *shader;
395 bool dirty_sh = false;
396
397 if (vec->gs) {
398 shader = vec->gs;
399 dirty_sh = DIRTY(GS);
400 }
401 else {
402 shader = vec->vs;
403 dirty_sh = DIRTY(VS);
404 }
405
406 sol = ilo_shader_get_kernel_sol(shader);
407
408 /* 3DSTATE_SO_BUFFER */
409 if ((DIRTY(SO) || dirty_sh || r->batch_bo_changed) &&
410 vec->so.enabled) {
411 const struct pipe_stream_output_info *so_info;
412 int i;
413
414 so_info = ilo_shader_get_kernel_so_info(shader);
415
416 for (i = 0; i < vec->so.count; i++) {
417 const int stride = so_info->stride[i] * 4; /* in bytes */
418
419 gen7_3DSTATE_SO_BUFFER(r->builder, i, stride, vec->so.states[i]);
420 }
421
422 for (; i < 4; i++)
423 gen7_disable_3DSTATE_SO_BUFFER(r->builder, i);
424 }
425
426 /* 3DSTATE_SO_DECL_LIST */
427 if (dirty_sh && vec->so.enabled)
428 gen7_3DSTATE_SO_DECL_LIST(r->builder, sol);
429
430 /*
431 * From the Ivy Bridge PRM, volume 2 part 1, page 196-197:
432 *
433 * "Anytime the SOL unit MMIO registers or non-pipeline state are
434 * written, the SOL unit needs to receive a pipeline state update with
435 * SOL unit dirty state for information programmed in MMIO/NP to get
436 * loaded into the SOL unit.
437 *
438 * The SOL unit incorrectly double buffers MMIO/NP registers and only
439 * moves them into the design for usage when control topology is
440 * received with the SOL unit dirty state.
441 *
442 * If the state does not change, need to resend the same state.
443 *
444 * Because of corruption, software must flush the whole fixed function
445 * pipeline when 3DSTATE_STREAMOUT changes state."
446 *
447 * The first and fourth paragraphs are gone on Gen7.5+.
448 */
449
450 /* 3DSTATE_STREAMOUT */
451 gen7_3DSTATE_STREAMOUT(r->builder, sol);
452 }
453
454 static void
455 gen7_draw_sf(struct ilo_render *r,
456 const struct ilo_state_vector *vec,
457 struct ilo_render_draw_session *session)
458 {
459 /* 3DSTATE_SBE */
460 if (DIRTY(RASTERIZER) || DIRTY(FS)) {
461 gen7_3DSTATE_SBE(r->builder, vec->fs, (vec->rasterizer) ?
462 vec->rasterizer->state.sprite_coord_mode : 0);
463 }
464
465 /* 3DSTATE_SF */
466 if (session->rs_delta.dirty & ILO_STATE_RASTER_3DSTATE_SF) {
467 if (ilo_dev_gen(r->dev) == ILO_GEN(7))
468 gen7_wa_pre_3dstate_sf_depth_bias(r);
469
470 gen7_3DSTATE_SF(r->builder, &vec->rasterizer->rs);
471 }
472 }
473
474 static void
475 gen7_draw_wm(struct ilo_render *r,
476 const struct ilo_state_vector *vec,
477 struct ilo_render_draw_session *session)
478 {
479 /* 3DSTATE_WM */
480 if (DIRTY(FS) || DIRTY(BLEND) ||
481 (session->rs_delta.dirty & ILO_STATE_RASTER_3DSTATE_WM)) {
482 gen7_3DSTATE_WM(r->builder, &vec->rasterizer->rs, vec->fs,
483 vec->blend->alpha_may_kill);
484 }
485
486 /* 3DSTATE_BINDING_TABLE_POINTERS_PS */
487 if (session->binding_table_fs_changed) {
488 gen7_3DSTATE_BINDING_TABLE_POINTERS_PS(r->builder,
489 r->state.wm.BINDING_TABLE_STATE);
490 }
491
492 /* 3DSTATE_SAMPLER_STATE_POINTERS_PS */
493 if (session->sampler_fs_changed) {
494 gen7_3DSTATE_SAMPLER_STATE_POINTERS_PS(r->builder,
495 r->state.wm.SAMPLER_STATE);
496 }
497
498 /* 3DSTATE_CONSTANT_PS */
499 if (session->pcb_fs_changed) {
500 gen7_3DSTATE_CONSTANT_PS(r->builder,
501 &r->state.wm.PUSH_CONSTANT_BUFFER,
502 &r->state.wm.PUSH_CONSTANT_BUFFER_size,
503 1);
504 }
505
506 /* 3DSTATE_PS */
507 if (DIRTY(FS) || DIRTY(BLEND) || r->instruction_bo_changed) {
508 const bool dual_blend = vec->blend->dual_blend;
509
510 if (r->hw_ctx_changed)
511 gen7_wa_pre_3dstate_ps_max_threads(r);
512
513 gen7_3DSTATE_PS(r->builder, vec->fs, dual_blend);
514 }
515
516 /* 3DSTATE_SCISSOR_STATE_POINTERS */
517 if (session->scissor_changed) {
518 gen6_3DSTATE_SCISSOR_STATE_POINTERS(r->builder,
519 r->state.SCISSOR_RECT);
520 }
521
522 {
523 const bool emit_3dstate_ps = (DIRTY(FS) || DIRTY(BLEND));
524 const bool emit_3dstate_depth_buffer =
525 (DIRTY(FB) || DIRTY(DSA) || r->state_bo_changed);
526
527 if (ilo_dev_gen(r->dev) == ILO_GEN(7)) {
528 /* XXX what is the best way to know if this workaround is needed? */
529 if (emit_3dstate_ps ||
530 session->pcb_fs_changed ||
531 session->viewport_changed ||
532 session->binding_table_fs_changed ||
533 session->sampler_fs_changed ||
534 session->cc_changed ||
535 session->blend_changed ||
536 session->dsa_changed)
537 gen7_wa_post_ps_and_later(r);
538 }
539
540 if (emit_3dstate_depth_buffer)
541 gen7_wa_pre_depth(r);
542 }
543
544 /* 3DSTATE_DEPTH_BUFFER and 3DSTATE_CLEAR_PARAMS */
545 if (DIRTY(FB) || r->batch_bo_changed) {
546 const struct ilo_state_zs *zs;
547 uint32_t clear_params;
548
549 if (vec->fb.state.zsbuf) {
550 const struct ilo_surface_cso *surface =
551 (const struct ilo_surface_cso *) vec->fb.state.zsbuf;
552 const struct ilo_texture_slice *slice =
553 ilo_texture_get_slice(ilo_texture(surface->base.texture),
554 surface->base.u.tex.level, surface->base.u.tex.first_layer);
555
556 assert(!surface->is_rt);
557 zs = &surface->u.zs;
558 clear_params = slice->clear_value;
559 }
560 else {
561 zs = &vec->fb.null_zs;
562 clear_params = 0;
563 }
564
565 gen6_3DSTATE_DEPTH_BUFFER(r->builder, zs);
566 gen6_3DSTATE_HIER_DEPTH_BUFFER(r->builder, zs);
567 gen6_3DSTATE_STENCIL_BUFFER(r->builder, zs);
568 gen7_3DSTATE_CLEAR_PARAMS(r->builder, clear_params);
569 }
570 }
571
572 static void
573 gen7_draw_wm_multisample(struct ilo_render *r,
574 const struct ilo_state_vector *vec,
575 struct ilo_render_draw_session *session)
576 {
577 /* 3DSTATE_MULTISAMPLE */
578 if (DIRTY(FB) || (session->rs_delta.dirty &
579 ILO_STATE_RASTER_3DSTATE_MULTISAMPLE)) {
580 const uint32_t *pattern;
581 int pattern_len;
582
583 gen7_wa_pre_3dstate_multisample(r);
584
585 if (vec->fb.num_samples > 4) {
586 pattern = r->sample_pattern_8x;
587 pattern_len = ARRAY_SIZE(r->sample_pattern_8x);
588 } else {
589 pattern = (vec->fb.num_samples > 1) ?
590 &r->sample_pattern_4x : &r->sample_pattern_1x;
591 pattern_len = 1;
592 }
593
594 gen6_3DSTATE_MULTISAMPLE(r->builder, &vec->rasterizer->rs,
595 pattern, pattern_len);
596 }
597
598 /* 3DSTATE_SAMPLE_MASK */
599 if (session->rs_delta.dirty & ILO_STATE_RASTER_3DSTATE_SAMPLE_MASK)
600 gen6_3DSTATE_SAMPLE_MASK(r->builder, &vec->rasterizer->rs);
601 }
602
603 void
604 ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
605 const struct ilo_state_vector *vec,
606 struct ilo_render_draw_session *session)
607 {
608 ILO_DEV_ASSERT(render->dev, 7, 7.5);
609
610 /*
611 * We try to keep the order of the commands match, as closely as possible,
612 * that of the classic i965 driver. It allows us to compare the command
613 * streams easily.
614 */
615 gen6_draw_common_select(render, vec, session);
616 gen6_draw_common_sip(render, vec, session);
617 gen6_draw_vf_statistics(render, vec, session);
618 gen7_draw_common_pcb_alloc(render, vec, session);
619 gen6_draw_common_base_address(render, vec, session);
620 gen7_draw_common_pointers_1(render, vec, session);
621 gen7_draw_common_urb(render, vec, session);
622 gen7_draw_common_pointers_2(render, vec, session);
623 gen7_draw_wm_multisample(render, vec, session);
624 gen7_draw_gs(render, vec, session);
625 gen7_draw_hs(render, vec, session);
626 gen7_draw_te(render, vec, session);
627 gen7_draw_ds(render, vec, session);
628 gen7_draw_vs(render, vec, session);
629 gen7_draw_sol(render, vec, session);
630 gen6_draw_clip(render, vec, session);
631 gen7_draw_sf(render, vec, session);
632 gen7_draw_wm(render, vec, session);
633 gen6_draw_wm_raster(render, vec, session);
634 gen6_draw_sf_rect(render, vec, session);
635 gen6_draw_vf(render, vec, session);
636
637 ilo_render_3dprimitive(render, vec->draw, &vec->ib);
638 }
639
640 static void
641 gen7_rectlist_pcb_alloc(struct ilo_render *r,
642 const struct ilo_blitter *blitter)
643 {
644 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_VS(r->builder, &blitter->urb);
645 gen7_3DSTATE_PUSH_CONSTANT_ALLOC_PS(r->builder, &blitter->urb);
646
647 if (ilo_dev_gen(r->dev) == ILO_GEN(7))
648 gen7_wa_post_3dstate_push_constant_alloc_ps(r);
649 }
650
651 static void
652 gen7_rectlist_urb(struct ilo_render *r,
653 const struct ilo_blitter *blitter)
654 {
655 gen7_3DSTATE_URB_VS(r->builder, &blitter->urb);
656 gen7_3DSTATE_URB_GS(r->builder, &blitter->urb);
657 gen7_3DSTATE_URB_HS(r->builder, &blitter->urb);
658 gen7_3DSTATE_URB_DS(r->builder, &blitter->urb);
659 }
660
661 static void
662 gen7_rectlist_vs_to_sf(struct ilo_render *r,
663 const struct ilo_blitter *blitter)
664 {
665 gen7_3DSTATE_CONSTANT_VS(r->builder, NULL, NULL, 0);
666 gen6_disable_3DSTATE_VS(r->builder);
667
668 gen7_3DSTATE_CONSTANT_HS(r->builder, NULL, NULL, 0);
669 gen7_disable_3DSTATE_HS(r->builder);
670
671 gen7_3DSTATE_TE(r->builder);
672
673 gen7_3DSTATE_CONSTANT_DS(r->builder, NULL, NULL, 0);
674 gen7_disable_3DSTATE_DS(r->builder);
675
676 gen7_3DSTATE_CONSTANT_GS(r->builder, NULL, NULL, 0);
677 gen7_disable_3DSTATE_GS(r->builder);
678
679 gen7_3DSTATE_STREAMOUT(r->builder, &blitter->sol);
680
681 gen6_3DSTATE_CLIP(r->builder, &blitter->fb.rs);
682
683 if (ilo_dev_gen(r->dev) == ILO_GEN(7))
684 gen7_wa_pre_3dstate_sf_depth_bias(r);
685
686 gen7_3DSTATE_SF(r->builder, &blitter->fb.rs);
687 gen7_3DSTATE_SBE(r->builder, NULL, 0);
688 }
689
690 static void
691 gen7_rectlist_wm(struct ilo_render *r,
692 const struct ilo_blitter *blitter)
693 {
694 gen7_3DSTATE_WM(r->builder, &blitter->fb.rs, NULL, false);
695
696 gen7_3DSTATE_CONSTANT_PS(r->builder, NULL, NULL, 0);
697
698 gen7_wa_pre_3dstate_ps_max_threads(r);
699 gen7_disable_3DSTATE_PS(r->builder);
700 }
701
702 static void
703 gen7_rectlist_wm_depth(struct ilo_render *r,
704 const struct ilo_blitter *blitter)
705 {
706 gen7_wa_pre_depth(r);
707
708 if (blitter->uses & (ILO_BLITTER_USE_FB_DEPTH |
709 ILO_BLITTER_USE_FB_STENCIL))
710 gen6_3DSTATE_DEPTH_BUFFER(r->builder, &blitter->fb.dst.u.zs);
711
712 if (blitter->uses & ILO_BLITTER_USE_FB_DEPTH) {
713 gen6_3DSTATE_HIER_DEPTH_BUFFER(r->builder,
714 &blitter->fb.dst.u.zs);
715 }
716
717 if (blitter->uses & ILO_BLITTER_USE_FB_STENCIL) {
718 gen6_3DSTATE_STENCIL_BUFFER(r->builder,
719 &blitter->fb.dst.u.zs);
720 }
721
722 gen7_3DSTATE_CLEAR_PARAMS(r->builder,
723 blitter->depth_clear_value);
724 }
725
726 static void
727 gen7_rectlist_wm_multisample(struct ilo_render *r,
728 const struct ilo_blitter *blitter)
729 {
730 const uint32_t *pattern;
731 int pattern_len;
732
733 if (blitter->fb.num_samples > 4) {
734 pattern = r->sample_pattern_8x;
735 pattern_len = ARRAY_SIZE(r->sample_pattern_8x);
736 } else {
737 pattern = (blitter->fb.num_samples > 1) ?
738 &r->sample_pattern_4x : &r->sample_pattern_1x;
739 pattern_len = 1;
740 }
741
742 gen7_wa_pre_3dstate_multisample(r);
743
744 gen6_3DSTATE_MULTISAMPLE(r->builder, &blitter->fb.rs,
745 pattern, pattern_len);
746
747 gen6_3DSTATE_SAMPLE_MASK(r->builder, &blitter->fb.rs);
748 }
749
750 void
751 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
752 const struct ilo_blitter *blitter,
753 const struct ilo_render_rectlist_session *session)
754 {
755 ILO_DEV_ASSERT(r->dev, 7, 7.5);
756
757 gen7_rectlist_wm_multisample(r, blitter);
758
759 gen6_state_base_address(r->builder, true);
760
761 gen6_user_3DSTATE_VERTEX_BUFFERS(r->builder,
762 session->vb_start, session->vb_end,
763 sizeof(blitter->vertices[0]));
764
765 gen6_3DSTATE_VERTEX_ELEMENTS(r->builder, &blitter->ve);
766
767 gen7_rectlist_pcb_alloc(r, blitter);
768
769 /* needed for any VS-related commands */
770 if (ilo_dev_gen(r->dev) == ILO_GEN(7))
771 gen7_wa_pre_vs(r);
772
773 gen7_rectlist_urb(r, blitter);
774
775 if (blitter->uses & ILO_BLITTER_USE_DSA) {
776 gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(r->builder,
777 r->state.DEPTH_STENCIL_STATE);
778 }
779
780 if (blitter->uses & ILO_BLITTER_USE_CC) {
781 gen7_3DSTATE_CC_STATE_POINTERS(r->builder,
782 r->state.COLOR_CALC_STATE);
783 }
784
785 gen7_rectlist_vs_to_sf(r, blitter);
786 gen7_rectlist_wm(r, blitter);
787
788 if (blitter->uses & ILO_BLITTER_USE_VIEWPORT) {
789 gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(r->builder,
790 r->state.CC_VIEWPORT);
791 }
792
793 gen7_rectlist_wm_depth(r, blitter);
794
795 gen6_3DSTATE_DRAWING_RECTANGLE(r->builder, 0, 0,
796 blitter->fb.width, blitter->fb.height);
797
798 if (ilo_dev_gen(r->dev) == ILO_GEN(7))
799 gen7_wa_post_ps_and_later(r);
800
801 ilo_render_3dprimitive(r, &blitter->draw, NULL);
802 }
803
804 int
805 ilo_render_get_draw_commands_len_gen7(const struct ilo_render *render,
806 const struct ilo_state_vector *vec)
807 {
808 static int len;
809
810 ILO_DEV_ASSERT(render->dev, 7, 7.5);
811
812 if (!len) {
813 len += GEN7_3DSTATE_URB_ANY__SIZE * 4;
814 len += GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_ANY__SIZE * 5;
815 len += GEN6_3DSTATE_CONSTANT_ANY__SIZE * 5;
816 len += GEN7_3DSTATE_POINTERS_ANY__SIZE * (5 + 5 + 4);
817 len += GEN7_3DSTATE_SO_BUFFER__SIZE * 4;
818 len += GEN6_PIPE_CONTROL__SIZE * 5;
819
820 len +=
821 GEN6_STATE_BASE_ADDRESS__SIZE +
822 GEN6_STATE_SIP__SIZE +
823 GEN6_3DSTATE_VF_STATISTICS__SIZE +
824 GEN6_PIPELINE_SELECT__SIZE +
825 GEN6_3DSTATE_CLEAR_PARAMS__SIZE +
826 GEN6_3DSTATE_DEPTH_BUFFER__SIZE +
827 GEN6_3DSTATE_STENCIL_BUFFER__SIZE +
828 GEN6_3DSTATE_HIER_DEPTH_BUFFER__SIZE +
829 GEN6_3DSTATE_VERTEX_BUFFERS__SIZE +
830 GEN6_3DSTATE_VERTEX_ELEMENTS__SIZE +
831 GEN6_3DSTATE_INDEX_BUFFER__SIZE +
832 GEN75_3DSTATE_VF__SIZE +
833 GEN6_3DSTATE_VS__SIZE +
834 GEN6_3DSTATE_GS__SIZE +
835 GEN6_3DSTATE_CLIP__SIZE +
836 GEN6_3DSTATE_SF__SIZE +
837 GEN6_3DSTATE_WM__SIZE +
838 GEN6_3DSTATE_SAMPLE_MASK__SIZE +
839 GEN7_3DSTATE_HS__SIZE +
840 GEN7_3DSTATE_TE__SIZE +
841 GEN7_3DSTATE_DS__SIZE +
842 GEN7_3DSTATE_STREAMOUT__SIZE +
843 GEN7_3DSTATE_SBE__SIZE +
844 GEN7_3DSTATE_PS__SIZE +
845 GEN6_3DSTATE_DRAWING_RECTANGLE__SIZE +
846 GEN6_3DSTATE_POLY_STIPPLE_OFFSET__SIZE +
847 GEN6_3DSTATE_POLY_STIPPLE_PATTERN__SIZE +
848 GEN6_3DSTATE_LINE_STIPPLE__SIZE +
849 GEN6_3DSTATE_AA_LINE_PARAMETERS__SIZE +
850 GEN6_3DSTATE_MULTISAMPLE__SIZE +
851 GEN7_3DSTATE_SO_DECL_LIST__SIZE +
852 GEN6_3DPRIMITIVE__SIZE;
853 }
854
855 return len;
856 }