i965: add component packing support for gs
[mesa.git] / src / mesa / drivers / dri / i965 / gen8_blorp.c
1 /*
2 * Copyright © 2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25
26 #include "intel_batchbuffer.h"
27 #include "intel_fbo.h"
28 #include "intel_mipmap_tree.h"
29
30 #include "brw_context.h"
31 #include "brw_defines.h"
32 #include "brw_state.h"
33
34 #include "brw_blorp.h"
35
36
37 /* SURFACE_STATE for renderbuffer or texture surface (see
38 * brw_update_renderbuffer_surface and brw_update_texture_surface)
39 */
40 static uint32_t
41 gen8_blorp_emit_surface_state(struct brw_context *brw,
42 const struct brw_blorp_surface_info *surface,
43 uint32_t read_domains, uint32_t write_domain,
44 bool is_render_target)
45 {
46 uint32_t wm_surf_offset;
47 const struct intel_mipmap_tree *mt = surface->mt;
48 const uint32_t mocs_wb = is_render_target ?
49 (brw->gen >= 9 ? SKL_MOCS_PTE : BDW_MOCS_PTE) :
50 (brw->gen >= 9 ? SKL_MOCS_WB : BDW_MOCS_WB);
51 const uint32_t tiling = surface->map_stencil_as_y_tiled
52 ? I915_TILING_Y : mt->tiling;
53 uint32_t tile_x, tile_y;
54
55 uint32_t *surf = gen8_allocate_surface_state(brw, &wm_surf_offset, -1);
56
57 surf[0] = BRW_SURFACE_2D << BRW_SURFACE_TYPE_SHIFT |
58 surface->brw_surfaceformat << BRW_SURFACE_FORMAT_SHIFT |
59 gen8_vertical_alignment(brw, mt, BRW_SURFACE_2D) |
60 gen8_horizontal_alignment(brw, mt, BRW_SURFACE_2D) |
61 gen8_surface_tiling_mode(tiling);
62
63 surf[1] = SET_FIELD(mocs_wb, GEN8_SURFACE_MOCS) | mt->qpitch >> 2;
64
65 surf[2] = SET_FIELD(surface->width - 1, GEN7_SURFACE_WIDTH) |
66 SET_FIELD(surface->height - 1, GEN7_SURFACE_HEIGHT);
67
68 uint32_t pitch_bytes = mt->pitch;
69 if (surface->map_stencil_as_y_tiled)
70 pitch_bytes *= 2;
71 surf[3] = pitch_bytes - 1;
72
73 surf[4] = gen7_surface_msaa_bits(surface->num_samples,
74 surface->msaa_layout);
75
76 if (surface->mt->mcs_mt) {
77 surf[6] = SET_FIELD(surface->mt->qpitch / 4, GEN8_SURFACE_AUX_QPITCH) |
78 SET_FIELD((surface->mt->mcs_mt->pitch / 128) - 1,
79 GEN8_SURFACE_AUX_PITCH) |
80 gen8_get_aux_mode(brw, mt);
81 } else {
82 surf[6] = 0;
83 }
84
85 gen8_emit_fast_clear_color(brw, mt, surf);
86 surf[7] |= SET_FIELD(HSW_SCS_RED, GEN7_SURFACE_SCS_R) |
87 SET_FIELD(HSW_SCS_GREEN, GEN7_SURFACE_SCS_G) |
88 SET_FIELD(HSW_SCS_BLUE, GEN7_SURFACE_SCS_B) |
89 SET_FIELD(HSW_SCS_ALPHA, GEN7_SURFACE_SCS_A);
90
91 /* reloc */
92 *((uint64_t *)&surf[8]) =
93 brw_blorp_compute_tile_offsets(surface, &tile_x, &tile_y) +
94 mt->bo->offset64;
95
96 /* Note that the low bits of these fields are missing, so there's the
97 * possibility of getting in trouble.
98 */
99 assert(tile_x % 4 == 0);
100 assert(tile_y % 4 == 0);
101 surf[5] = SET_FIELD(tile_x / 4, BRW_SURFACE_X_OFFSET) |
102 SET_FIELD(tile_y / 4, GEN8_SURFACE_Y_OFFSET);
103
104 if (brw->gen >= 9) {
105 /* Disable Mip Tail by setting a large value. */
106 surf[5] |= SET_FIELD(15, GEN9_SURFACE_MIP_TAIL_START_LOD);
107 }
108
109 if (surface->mt->mcs_mt) {
110 *((uint64_t *) &surf[10]) = surface->mt->mcs_mt->bo->offset64;
111 drm_intel_bo_emit_reloc(brw->batch.bo,
112 wm_surf_offset + 10 * 4,
113 surface->mt->mcs_mt->bo, 0,
114 read_domains, write_domain);
115 }
116
117 /* Emit relocation to surface contents */
118 drm_intel_bo_emit_reloc(brw->batch.bo,
119 wm_surf_offset + 8 * 4,
120 mt->bo,
121 surf[8] - mt->bo->offset64,
122 read_domains, write_domain);
123
124 return wm_surf_offset;
125 }
126
127 static uint32_t
128 gen8_blorp_emit_blend_state(struct brw_context *brw,
129 const struct brw_blorp_params *params)
130 {
131 uint32_t blend_state_offset;
132
133 assume(params->num_draw_buffers);
134
135 const unsigned size = 4 + 8 * params->num_draw_buffers;
136 uint32_t *blend = (uint32_t *)brw_state_batch(brw, AUB_TRACE_BLEND_STATE,
137 size, 64,
138 &blend_state_offset);
139 memset(blend, 0, size);
140
141 for (unsigned i = 0; i < params->num_draw_buffers; ++i) {
142 if (params->color_write_disable[0])
143 blend[1 + 2 * i] |= GEN8_BLEND_WRITE_DISABLE_RED;
144 if (params->color_write_disable[1])
145 blend[1 + 2 * i] |= GEN8_BLEND_WRITE_DISABLE_GREEN;
146 if (params->color_write_disable[2])
147 blend[1 + 2 * i] |= GEN8_BLEND_WRITE_DISABLE_BLUE;
148 if (params->color_write_disable[3])
149 blend[1 + 2 * i] |= GEN8_BLEND_WRITE_DISABLE_ALPHA;
150
151 blend[1 + 2 * i + 1] = GEN8_BLEND_PRE_BLEND_COLOR_CLAMP_ENABLE |
152 GEN8_BLEND_POST_BLEND_COLOR_CLAMP_ENABLE |
153 GEN8_BLEND_COLOR_CLAMP_RANGE_RTFORMAT;
154 }
155
156 return blend_state_offset;
157 }
158
159 /* 3DSTATE_VS
160 *
161 * Disable vertex shader.
162 */
163 static void
164 gen8_blorp_emit_vs_disable(struct brw_context *brw)
165 {
166 BEGIN_BATCH(9);
167 OUT_BATCH(_3DSTATE_VS << 16 | (9 - 2));
168 OUT_BATCH(0);
169 OUT_BATCH(0);
170 OUT_BATCH(0);
171 OUT_BATCH(0);
172 OUT_BATCH(0);
173 OUT_BATCH(0);
174 OUT_BATCH(0);
175 OUT_BATCH(0);
176 ADVANCE_BATCH();
177 }
178
179 /* 3DSTATE_HS
180 *
181 * Disable the hull shader.
182 */
183 static void
184 gen8_blorp_emit_hs_disable(struct brw_context *brw)
185 {
186 BEGIN_BATCH(9);
187 OUT_BATCH(_3DSTATE_HS << 16 | (9 - 2));
188 OUT_BATCH(0);
189 OUT_BATCH(0);
190 OUT_BATCH(0);
191 OUT_BATCH(0);
192 OUT_BATCH(0);
193 OUT_BATCH(0);
194 OUT_BATCH(0);
195 OUT_BATCH(0);
196 ADVANCE_BATCH();
197 }
198
199 /* 3DSTATE_DS
200 *
201 * Disable the domain shader.
202 */
203 static void
204 gen8_blorp_emit_ds_disable(struct brw_context *brw)
205 {
206 const int ds_pkt_len = brw->gen >= 9 ? 11 : 9;
207 BEGIN_BATCH(ds_pkt_len);
208 OUT_BATCH(_3DSTATE_DS << 16 | (ds_pkt_len - 2));
209 for (int i = 0; i < ds_pkt_len - 1; i++)
210 OUT_BATCH(0);
211 ADVANCE_BATCH();
212 }
213
214 /* 3DSTATE_GS
215 *
216 * Disable the geometry shader.
217 */
218 static void
219 gen8_blorp_emit_gs_disable(struct brw_context *brw)
220 {
221 BEGIN_BATCH(10);
222 OUT_BATCH(_3DSTATE_GS << 16 | (10 - 2));
223 OUT_BATCH(0);
224 OUT_BATCH(0);
225 OUT_BATCH(0);
226 OUT_BATCH(0);
227 OUT_BATCH(0);
228 OUT_BATCH(0);
229 OUT_BATCH(0);
230 OUT_BATCH(0);
231 OUT_BATCH(0);
232 ADVANCE_BATCH();
233 }
234
235 /* 3DSTATE_STREAMOUT
236 *
237 * Disable streamout.
238 */
239 static void
240 gen8_blorp_emit_streamout_disable(struct brw_context *brw)
241 {
242 BEGIN_BATCH(5);
243 OUT_BATCH(_3DSTATE_STREAMOUT << 16 | (5 - 2));
244 OUT_BATCH(0);
245 OUT_BATCH(0);
246 OUT_BATCH(0);
247 OUT_BATCH(0);
248 ADVANCE_BATCH();
249 }
250
251 static void
252 gen8_blorp_emit_raster_state(struct brw_context *brw)
253 {
254 BEGIN_BATCH(5);
255 OUT_BATCH(_3DSTATE_RASTER << 16 | (5 - 2));
256 OUT_BATCH(GEN8_RASTER_CULL_NONE);
257 OUT_BATCH_F(0);
258 OUT_BATCH_F(0);
259 OUT_BATCH_F(0);
260 ADVANCE_BATCH();
261 }
262
263 static void
264 gen8_blorp_emit_sbe_state(struct brw_context *brw,
265 const struct brw_blorp_params *params)
266 {
267 const unsigned num_varyings = params->wm_prog_data->num_varying_inputs;
268 const unsigned urb_read_length =
269 brw_blorp_get_urb_length(params->wm_prog_data);
270
271 /* 3DSTATE_SBE */
272 {
273 const unsigned sbe_cmd_length = brw->gen == 8 ? 4 : 6;
274 BEGIN_BATCH(sbe_cmd_length);
275 OUT_BATCH(_3DSTATE_SBE << 16 | (sbe_cmd_length - 2));
276
277 /* There is no need for swizzling (GEN7_SBE_SWIZZLE_ENABLE). All the
278 * vertex data coming from vertex fetcher is taken as unmodified
279 * (i.e., passed through). Vertex shader state is disabled and vertex
280 * fetcher builds complete vertex entries including VUE header.
281 * This is for unknown reason really needed to be disabled when more
282 * than one vec4 worth of vertex attributes are needed.
283 */
284 OUT_BATCH(num_varyings << GEN7_SBE_NUM_OUTPUTS_SHIFT |
285 urb_read_length << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT |
286 BRW_SF_URB_ENTRY_READ_OFFSET <<
287 GEN8_SBE_URB_ENTRY_READ_OFFSET_SHIFT |
288 GEN8_SBE_FORCE_URB_ENTRY_READ_LENGTH |
289 GEN8_SBE_FORCE_URB_ENTRY_READ_OFFSET);
290 OUT_BATCH(0);
291 OUT_BATCH(params->wm_prog_data->flat_inputs);
292 if (sbe_cmd_length >= 6) {
293 /* Fragment coordinates are always enabled. */
294 uint32_t dw4 = (GEN9_SBE_ACTIVE_COMPONENT_XYZW << (0 << 1));
295
296 for (unsigned i = 0; i < num_varyings; ++i) {
297 dw4 |= (GEN9_SBE_ACTIVE_COMPONENT_XYZW << ((i + 1) << 1));
298 }
299
300 OUT_BATCH(dw4);
301 OUT_BATCH(0);
302 }
303 ADVANCE_BATCH();
304 }
305
306 {
307 BEGIN_BATCH(11);
308 OUT_BATCH(_3DSTATE_SBE_SWIZ << 16 | (11 - 2));
309
310 /* Output DWords 1 through 8: */
311 for (int i = 0; i < 8; i++) {
312 OUT_BATCH(0);
313 }
314
315 OUT_BATCH(0); /* wrapshortest enables 0-7 */
316 OUT_BATCH(0); /* wrapshortest enables 8-15 */
317 ADVANCE_BATCH();
318 }
319 }
320
321 static void
322 gen8_blorp_emit_sf_config(struct brw_context *brw)
323 {
324 /* See gen6_blorp_emit_sf_config() */
325 BEGIN_BATCH(4);
326 OUT_BATCH(_3DSTATE_SF << 16 | (4 - 2));
327 OUT_BATCH(0);
328 OUT_BATCH(0);
329 OUT_BATCH(GEN6_SF_LINE_AA_MODE_TRUE);
330 ADVANCE_BATCH();
331 }
332
333 /**
334 * Disable thread dispatch (dw5.19) and enable the HiZ op.
335 */
336 static void
337 gen8_blorp_emit_wm_state(struct brw_context *brw)
338 {
339 BEGIN_BATCH(2);
340 OUT_BATCH(_3DSTATE_WM << 16 | (2 - 2));
341 OUT_BATCH(GEN7_WM_LINE_AA_WIDTH_1_0 |
342 GEN7_WM_LINE_END_CAP_AA_WIDTH_0_5 |
343 GEN7_WM_POINT_RASTRULE_UPPER_RIGHT);
344 ADVANCE_BATCH();
345 }
346
347 /**
348 * 3DSTATE_PS
349 *
350 * Pixel shader dispatch is disabled above in 3DSTATE_WM, dw1.29. Despite
351 * that, thread dispatch info must still be specified.
352 * - Maximum Number of Threads (dw4.24:31) must be nonzero, as the
353 * valid range for this field is [0x3, 0x2f].
354 * - A dispatch mode must be given; that is, at least one of the
355 * "N Pixel Dispatch Enable" (N=8,16,32) fields must be set. This was
356 * discovered through simulator error messages.
357 */
358 static void
359 gen8_blorp_emit_ps_config(struct brw_context *brw,
360 const struct brw_blorp_params *params)
361 {
362 const struct brw_blorp_prog_data *prog_data = params->wm_prog_data;
363 uint32_t dw3, dw5, dw6, dw7, ksp0, ksp2;
364
365 dw3 = dw5 = dw6 = dw7 = ksp0 = ksp2 = 0;
366 dw3 |= GEN7_PS_VECTOR_MASK_ENABLE;
367
368 if (params->src.mt) {
369 dw3 |= 1 << GEN7_PS_SAMPLER_COUNT_SHIFT; /* Up to 4 samplers */
370 dw3 |= 2 << GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT; /* Two surfaces */
371 } else {
372 dw3 |= 1 << GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT; /* One surface */
373 }
374
375 dw7 |= prog_data->first_curbe_grf_0 << GEN7_PS_DISPATCH_START_GRF_SHIFT_0;
376 dw7 |= prog_data->first_curbe_grf_2 << GEN7_PS_DISPATCH_START_GRF_SHIFT_2;
377
378 if (params->wm_prog_data->dispatch_8)
379 dw6 |= GEN7_PS_8_DISPATCH_ENABLE;
380 if (params->wm_prog_data->dispatch_16)
381 dw6 |= GEN7_PS_16_DISPATCH_ENABLE;
382
383 ksp0 = params->wm_prog_kernel;
384 ksp2 = params->wm_prog_kernel + params->wm_prog_data->ksp_offset_2;
385
386 /* 3DSTATE_PS expects the number of threads per PSD, which is always 64;
387 * it implicitly scales for different GT levels (which have some # of PSDs).
388 *
389 * In Gen8 the format is U8-2 whereas in Gen9 it is U8-1.
390 */
391 if (brw->gen >= 9)
392 dw6 |= (64 - 1) << HSW_PS_MAX_THREADS_SHIFT;
393 else
394 dw6 |= (64 - 2) << HSW_PS_MAX_THREADS_SHIFT;
395
396 dw6 |= GEN7_PS_POSOFFSET_NONE;
397 dw6 |= params->fast_clear_op;
398
399 BEGIN_BATCH(12);
400 OUT_BATCH(_3DSTATE_PS << 16 | (12 - 2));
401 OUT_BATCH(ksp0);
402 OUT_BATCH(0);
403 OUT_BATCH(dw3);
404 OUT_BATCH(0);
405 OUT_BATCH(0);
406 OUT_BATCH(dw6);
407 OUT_BATCH(dw7);
408 OUT_BATCH(0); /* kernel 1 pointer */
409 OUT_BATCH(0);
410 OUT_BATCH(ksp2);
411 OUT_BATCH(0);
412 ADVANCE_BATCH();
413 }
414
415 static void
416 gen8_blorp_emit_ps_blend(struct brw_context *brw)
417 {
418 BEGIN_BATCH(2);
419 OUT_BATCH(_3DSTATE_PS_BLEND << 16 | (2 - 2));
420 OUT_BATCH(GEN8_PS_BLEND_HAS_WRITEABLE_RT);
421 ADVANCE_BATCH();
422 }
423
424 static void
425 gen8_blorp_emit_ps_extra(struct brw_context *brw,
426 const struct brw_blorp_params *params)
427 {
428 const struct brw_blorp_prog_data *prog_data = params->wm_prog_data;
429 uint32_t dw1 = 0;
430
431 dw1 |= GEN8_PSX_PIXEL_SHADER_VALID;
432
433 if (params->src.mt)
434 dw1 |= GEN8_PSX_KILL_ENABLE;
435
436 if (params->wm_prog_data->num_varying_inputs)
437 dw1 |= GEN8_PSX_ATTRIBUTE_ENABLE;
438
439 if (params->dst.num_samples > 1 && prog_data &&
440 prog_data->persample_msaa_dispatch)
441 dw1 |= GEN8_PSX_SHADER_IS_PER_SAMPLE;
442
443 BEGIN_BATCH(2);
444 OUT_BATCH(_3DSTATE_PS_EXTRA << 16 | (2 - 2));
445 OUT_BATCH(dw1);
446 ADVANCE_BATCH();
447 }
448
449 static void
450 gen8_blorp_emit_depth_disable(struct brw_context *brw)
451 {
452 /* Skip repeated NULL depth/stencil emits (think 2D rendering). */
453 if (brw->no_depth_or_stencil)
454 return;
455
456 brw_emit_depth_stall_flushes(brw);
457
458 BEGIN_BATCH(8);
459 OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER << 16 | (8 - 2));
460 OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT << 18) | (BRW_SURFACE_NULL << 29));
461 OUT_BATCH(0);
462 OUT_BATCH(0);
463 OUT_BATCH(0);
464 OUT_BATCH(0);
465 OUT_BATCH(0);
466 OUT_BATCH(0);
467 ADVANCE_BATCH();
468
469 BEGIN_BATCH(5);
470 OUT_BATCH(GEN7_3DSTATE_HIER_DEPTH_BUFFER << 16 | (5 - 2));
471 OUT_BATCH(0);
472 OUT_BATCH(0);
473 OUT_BATCH(0);
474 OUT_BATCH(0);
475 ADVANCE_BATCH();
476
477 BEGIN_BATCH(5);
478 OUT_BATCH(GEN7_3DSTATE_STENCIL_BUFFER << 16 | (5 - 2));
479 OUT_BATCH(0);
480 OUT_BATCH(0);
481 OUT_BATCH(0);
482 OUT_BATCH(0);
483 ADVANCE_BATCH();
484 }
485
486 static void
487 gen8_blorp_emit_vf_topology(struct brw_context *brw)
488 {
489 BEGIN_BATCH(2);
490 OUT_BATCH(_3DSTATE_VF_TOPOLOGY << 16 | (2 - 2));
491 OUT_BATCH(_3DPRIM_RECTLIST);
492 ADVANCE_BATCH();
493 }
494
495 static void
496 gen8_blorp_emit_vf_sys_gen_vals_state(struct brw_context *brw)
497 {
498 BEGIN_BATCH(2);
499 OUT_BATCH(_3DSTATE_VF_SGVS << 16 | (2 - 2));
500 OUT_BATCH(0);
501 ADVANCE_BATCH();
502 }
503
504 static void
505 gen8_blorp_emit_vf_instancing_state(struct brw_context *brw,
506 const struct brw_blorp_params *params)
507 {
508 const unsigned num_varyings =
509 params->wm_prog_data ? params->wm_prog_data->num_varying_inputs : 0;
510 const unsigned num_elems = 2 + num_varyings;
511
512 for (unsigned i = 0; i < num_elems; ++i) {
513 BEGIN_BATCH(3);
514 OUT_BATCH(_3DSTATE_VF_INSTANCING << 16 | (3 - 2));
515 OUT_BATCH(i);
516 OUT_BATCH(0);
517 ADVANCE_BATCH();
518 }
519 }
520
521 static void
522 gen8_blorp_emit_vf_state(struct brw_context *brw)
523 {
524 BEGIN_BATCH(2);
525 OUT_BATCH(_3DSTATE_VF << 16 | (2 - 2));
526 OUT_BATCH(0);
527 ADVANCE_BATCH();
528 }
529
530 static void
531 gen8_blorp_emit_depth_stencil_state(struct brw_context *brw,
532 const struct brw_blorp_params *params)
533 {
534 const unsigned pkt_len = brw->gen >= 9 ? 4 : 3;
535
536 BEGIN_BATCH(pkt_len);
537 OUT_BATCH(_3DSTATE_WM_DEPTH_STENCIL << 16 | (pkt_len - 2));
538 OUT_BATCH(0);
539 OUT_BATCH(0);
540 if (pkt_len > 3) {
541 OUT_BATCH(0);
542 }
543 ADVANCE_BATCH();
544 }
545
546 static void
547 gen8_blorp_emit_disable_constant_ps(struct brw_context *brw)
548 {
549 const int dwords = brw->gen >= 8 ? 11 : 7;
550 BEGIN_BATCH(dwords);
551 OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 | (dwords - 2));
552
553 if (brw->gen >= 9) {
554 OUT_BATCH(0);
555 OUT_BATCH(0);
556 } else {
557 OUT_BATCH(0);
558 OUT_BATCH(0);
559 }
560
561 if (brw->gen >= 9) {
562 OUT_BATCH(0);
563 OUT_BATCH(0);
564 OUT_BATCH(0);
565 OUT_BATCH(0);
566 OUT_BATCH(0);
567 OUT_BATCH(0);
568 OUT_BATCH(0);
569 OUT_BATCH(0);
570 } else {
571 OUT_BATCH(0);
572 OUT_BATCH(0);
573 OUT_BATCH(0);
574 OUT_BATCH(0);
575 OUT_BATCH(0);
576 OUT_BATCH(0);
577 OUT_BATCH(0);
578 OUT_BATCH(0);
579 }
580
581 ADVANCE_BATCH();
582 }
583
584 static uint32_t
585 gen8_blorp_emit_surface_states(struct brw_context *brw,
586 const struct brw_blorp_params *params)
587 {
588 uint32_t wm_surf_offset_renderbuffer;
589 uint32_t wm_surf_offset_texture = 0;
590
591 intel_miptree_used_for_rendering(params->dst.mt);
592
593 wm_surf_offset_renderbuffer =
594 gen8_blorp_emit_surface_state(brw, &params->dst,
595 I915_GEM_DOMAIN_RENDER,
596 I915_GEM_DOMAIN_RENDER,
597 true /* is_render_target */);
598 if (params->src.mt) {
599 const struct brw_blorp_surface_info *surface = &params->src;
600 struct intel_mipmap_tree *mt = surface->mt;
601
602 /* If src is a 2D multisample array texture on Gen7+ using
603 * INTEL_MSAA_LAYOUT_UMS or INTEL_MSAA_LAYOUT_CMS, src layer is the
604 * physical layer holding sample 0. So, for example, if mt->num_samples
605 * == 4, then logical layer n corresponds to layer == 4*n.
606 *
607 * Multisampled depth and stencil surfaces have the samples interleaved
608 * (INTEL_MSAA_LAYOUT_IMS) and therefore the layer doesn't need
609 * adjustment.
610 */
611 const unsigned layer_divider =
612 (mt->msaa_layout == INTEL_MSAA_LAYOUT_UMS ||
613 mt->msaa_layout == INTEL_MSAA_LAYOUT_CMS) ?
614 MAX2(mt->num_samples, 1) : 1;
615
616 /* Cube textures are sampled as 2D array. */
617 const bool is_cube = mt->target == GL_TEXTURE_CUBE_MAP_ARRAY ||
618 mt->target == GL_TEXTURE_CUBE_MAP;
619 const unsigned depth = (is_cube ? 6 : 1) * mt->logical_depth0;
620 const GLenum target = is_cube ? GL_TEXTURE_2D_ARRAY : mt->target;
621 const unsigned layer = mt->target != GL_TEXTURE_3D ?
622 surface->layer / layer_divider : 0;
623
624 brw->vtbl.emit_texture_surface_state(brw, mt, target,
625 layer, depth,
626 surface->level, mt->last_level + 1,
627 surface->brw_surfaceformat,
628 surface->swizzle,
629 &wm_surf_offset_texture,
630 -1, false, false);
631 }
632
633 return gen6_blorp_emit_binding_table(brw,
634 wm_surf_offset_renderbuffer,
635 wm_surf_offset_texture);
636 }
637
638 /**
639 * \copydoc gen6_blorp_exec()
640 */
641 void
642 gen8_blorp_exec(struct brw_context *brw, const struct brw_blorp_params *params)
643 {
644 uint32_t wm_bind_bo_offset = 0;
645
646 brw_upload_state_base_address(brw);
647
648 gen7_blorp_emit_cc_viewport(brw);
649 gen7_l3_state.emit(brw);
650
651 gen7_blorp_emit_urb_config(brw, params);
652
653 const uint32_t cc_blend_state_offset =
654 gen8_blorp_emit_blend_state(brw, params);
655 gen7_blorp_emit_blend_state_pointer(brw, cc_blend_state_offset);
656
657 const uint32_t cc_state_offset = gen6_blorp_emit_cc_state(brw);
658 gen7_blorp_emit_cc_state_pointer(brw, cc_state_offset);
659
660 gen8_blorp_emit_disable_constant_ps(brw);
661 wm_bind_bo_offset = gen8_blorp_emit_surface_states(brw, params);
662
663 gen7_blorp_emit_binding_table_pointers_ps(brw, wm_bind_bo_offset);
664
665 if (params->src.mt) {
666 const uint32_t sampler_offset =
667 gen6_blorp_emit_sampler_state(brw, BRW_MAPFILTER_LINEAR, 0, true);
668 gen7_blorp_emit_sampler_state_pointers_ps(brw, sampler_offset);
669 }
670
671 gen8_emit_3dstate_multisample(brw, params->dst.num_samples);
672 gen6_emit_3dstate_sample_mask(brw,
673 params->dst.num_samples > 1 ?
674 (1 << params->dst.num_samples) - 1 : 1);
675
676 gen8_disable_stages.emit(brw);
677 gen8_blorp_emit_vs_disable(brw);
678 gen8_blorp_emit_hs_disable(brw);
679 gen7_blorp_emit_te_disable(brw);
680 gen8_blorp_emit_ds_disable(brw);
681 gen8_blorp_emit_gs_disable(brw);
682
683 gen8_blorp_emit_streamout_disable(brw);
684 gen6_blorp_emit_clip_disable(brw);
685 gen8_blorp_emit_raster_state(brw);
686 gen8_blorp_emit_sbe_state(brw, params);
687 gen8_blorp_emit_sf_config(brw);
688
689 gen8_blorp_emit_ps_blend(brw);
690 gen8_blorp_emit_ps_extra(brw, params);
691
692 gen8_blorp_emit_ps_config(brw, params);
693
694 gen8_blorp_emit_depth_stencil_state(brw, params);
695 gen8_blorp_emit_wm_state(brw);
696
697 gen8_blorp_emit_depth_disable(brw);
698 gen7_blorp_emit_clear_params(brw, params);
699 gen6_blorp_emit_drawing_rectangle(brw, params);
700 gen8_blorp_emit_vf_topology(brw);
701 gen8_blorp_emit_vf_sys_gen_vals_state(brw);
702 gen6_blorp_emit_vertices(brw, params);
703 gen8_blorp_emit_vf_instancing_state(brw, params);
704 gen8_blorp_emit_vf_state(brw);
705 gen7_blorp_emit_primitive(brw, params);
706
707 if (brw->gen < 9)
708 gen8_write_pma_stall_bits(brw, 0);
709 }