intel/blorp: Set QPitch for depth and HiZ on gen8+
[mesa.git] / src / intel / blorp / blorp_genX_exec.h
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 #ifndef BLORP_GENX_EXEC_H
25 #define BLORP_GENX_EXEC_H
26
27 #include "blorp_priv.h"
28 #include "common/gen_device_info.h"
29 #include "common/gen_sample_positions.h"
30 #include "intel_aub.h"
31
32 /**
33 * This file provides the blorp pipeline setup and execution functionality.
34 * It defines the following function:
35 *
36 * static void
37 * blorp_exec(struct blorp_context *blorp, void *batch_data,
38 * const struct blorp_params *params);
39 *
40 * It is the job of whoever includes this header to wrap this in something
41 * to get an externally visible symbol.
42 *
43 * In order for the blorp_exec function to work, the driver must provide
44 * implementations of the following static helper functions.
45 */
46
47 static void *
48 blorp_emit_dwords(struct blorp_batch *batch, unsigned n);
49
50 static uint64_t
51 blorp_emit_reloc(struct blorp_batch *batch,
52 void *location, struct blorp_address address, uint32_t delta);
53
54 static void *
55 blorp_alloc_dynamic_state(struct blorp_batch *batch,
56 enum aub_state_struct_type type,
57 uint32_t size,
58 uint32_t alignment,
59 uint32_t *offset);
60 static void *
61 blorp_alloc_vertex_buffer(struct blorp_batch *batch, uint32_t size,
62 struct blorp_address *addr);
63
64 static void
65 blorp_alloc_binding_table(struct blorp_batch *batch, unsigned num_entries,
66 unsigned state_size, unsigned state_alignment,
67 uint32_t *bt_offset, uint32_t *surface_offsets,
68 void **surface_maps);
69 static void
70 blorp_surface_reloc(struct blorp_batch *batch, uint32_t ss_offset,
71 struct blorp_address address, uint32_t delta);
72
73 static void
74 blorp_emit_urb_config(struct blorp_batch *batch, unsigned vs_entry_size);
75
76 /***** BEGIN blorp_exec implementation ******/
77
78 #include "genxml/gen_macros.h"
79
80 static uint64_t
81 _blorp_combine_address(struct blorp_batch *batch, void *location,
82 struct blorp_address address, uint32_t delta)
83 {
84 if (address.buffer == NULL) {
85 return address.offset + delta;
86 } else {
87 return blorp_emit_reloc(batch, location, address, delta);
88 }
89 }
90
91 #define __gen_address_type struct blorp_address
92 #define __gen_user_data struct blorp_batch
93 #define __gen_combine_address _blorp_combine_address
94
95 #include "genxml/genX_pack.h"
96
97 #define _blorp_cmd_length(cmd) cmd ## _length
98 #define _blorp_cmd_length_bias(cmd) cmd ## _length_bias
99 #define _blorp_cmd_header(cmd) cmd ## _header
100 #define _blorp_cmd_pack(cmd) cmd ## _pack
101
102 #define blorp_emit(batch, cmd, name) \
103 for (struct cmd name = { _blorp_cmd_header(cmd) }, \
104 *_dst = blorp_emit_dwords(batch, _blorp_cmd_length(cmd)); \
105 __builtin_expect(_dst != NULL, 1); \
106 _blorp_cmd_pack(cmd)(batch, (void *)_dst, &name), \
107 _dst = NULL)
108
109 #define blorp_emitn(batch, cmd, n) ({ \
110 uint32_t *_dw = blorp_emit_dwords(batch, n); \
111 struct cmd template = { \
112 _blorp_cmd_header(cmd), \
113 .DWordLength = n - _blorp_cmd_length_bias(cmd), \
114 }; \
115 _blorp_cmd_pack(cmd)(batch, _dw, &template); \
116 _dw + 1; /* Array starts at dw[1] */ \
117 })
118
119 /* 3DSTATE_URB
120 * 3DSTATE_URB_VS
121 * 3DSTATE_URB_HS
122 * 3DSTATE_URB_DS
123 * 3DSTATE_URB_GS
124 *
125 * Assign the entire URB to the VS. Even though the VS disabled, URB space
126 * is still needed because the clipper loads the VUE's from the URB. From
127 * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
128 * Dword 1.15:0 "VS Number of URB Entries":
129 * This field is always used (even if VS Function Enable is DISABLED).
130 *
131 * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
132 * safely ignore it because this batch contains only one draw call.
133 * Because of URB corruption caused by allocating a previous GS unit
134 * URB entry to the VS unit, software is required to send a “GS NULL
135 * Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
136 * plus a dummy DRAW call before any case where VS will be taking over
137 * GS URB space.
138 *
139 * If the 3DSTATE_URB_VS is emitted, than the others must be also.
140 * From the Ivybridge PRM, Volume 2 Part 1, section 1.7.1 3DSTATE_URB_VS:
141 *
142 * 3DSTATE_URB_HS, 3DSTATE_URB_DS, and 3DSTATE_URB_GS must also be
143 * programmed in order for the programming of this state to be
144 * valid.
145 */
146 static void
147 emit_urb_config(struct blorp_batch *batch,
148 const struct blorp_params *params)
149 {
150 /* Once vertex fetcher has written full VUE entries with complete
151 * header the space requirement is as follows per vertex (in bytes):
152 *
153 * Header Position Program constants
154 * +--------+------------+-------------------+
155 * | 16 | 16 | n x 16 |
156 * +--------+------------+-------------------+
157 *
158 * where 'n' stands for number of varying inputs expressed as vec4s.
159 */
160 const unsigned num_varyings =
161 params->wm_prog_data ? params->wm_prog_data->num_varying_inputs : 0;
162 const unsigned total_needed = 16 + 16 + num_varyings * 16;
163
164 /* The URB size is expressed in units of 64 bytes (512 bits) */
165 const unsigned vs_entry_size = DIV_ROUND_UP(total_needed, 64);
166
167 blorp_emit_urb_config(batch, vs_entry_size);
168 }
169
170 static void
171 blorp_emit_vertex_data(struct blorp_batch *batch,
172 const struct blorp_params *params,
173 struct blorp_address *addr,
174 uint32_t *size)
175 {
176 const float vertices[] = {
177 /* v0 */ (float)params->x1, (float)params->y1, params->z,
178 /* v1 */ (float)params->x0, (float)params->y1, params->z,
179 /* v2 */ (float)params->x0, (float)params->y0, params->z,
180 };
181
182 void *data = blorp_alloc_vertex_buffer(batch, sizeof(vertices), addr);
183 memcpy(data, vertices, sizeof(vertices));
184 *size = sizeof(vertices);
185 }
186
187 static void
188 blorp_emit_input_varying_data(struct blorp_batch *batch,
189 const struct blorp_params *params,
190 struct blorp_address *addr,
191 uint32_t *size)
192 {
193 const unsigned vec4_size_in_bytes = 4 * sizeof(float);
194 const unsigned max_num_varyings =
195 DIV_ROUND_UP(sizeof(params->wm_inputs), vec4_size_in_bytes);
196 const unsigned num_varyings = params->wm_prog_data->num_varying_inputs;
197
198 *size = num_varyings * vec4_size_in_bytes;
199
200 const float *const inputs_src = (const float *)&params->wm_inputs;
201 float *inputs = blorp_alloc_vertex_buffer(batch, *size, addr);
202
203 /* Walk over the attribute slots, determine if the attribute is used by
204 * the program and when necessary copy the values from the input storage to
205 * the vertex data buffer.
206 */
207 for (unsigned i = 0; i < max_num_varyings; i++) {
208 const gl_varying_slot attr = VARYING_SLOT_VAR0 + i;
209
210 if (!(params->wm_prog_data->inputs_read & (1ull << attr)))
211 continue;
212
213 memcpy(inputs, inputs_src + i * 4, vec4_size_in_bytes);
214
215 inputs += 4;
216 }
217 }
218
219 static void
220 blorp_emit_vertex_buffers(struct blorp_batch *batch,
221 const struct blorp_params *params)
222 {
223 struct GENX(VERTEX_BUFFER_STATE) vb[2];
224 memset(vb, 0, sizeof(vb));
225
226 unsigned num_buffers = 1;
227
228 uint32_t size;
229 blorp_emit_vertex_data(batch, params, &vb[0].BufferStartingAddress, &size);
230 vb[0].VertexBufferIndex = 0;
231 vb[0].BufferPitch = 3 * sizeof(float);
232 vb[0].VertexBufferMOCS = batch->blorp->mocs.vb;
233 #if GEN_GEN >= 7
234 vb[0].AddressModifyEnable = true;
235 #endif
236 #if GEN_GEN >= 8
237 vb[0].BufferSize = size;
238 #else
239 vb[0].BufferAccessType = VERTEXDATA;
240 vb[0].EndAddress = vb[0].BufferStartingAddress;
241 vb[0].EndAddress.offset += size - 1;
242 #endif
243
244 if (params->wm_prog_data && params->wm_prog_data->num_varying_inputs) {
245 blorp_emit_input_varying_data(batch, params,
246 &vb[1].BufferStartingAddress, &size);
247 vb[1].VertexBufferIndex = 1;
248 vb[1].BufferPitch = 0;
249 vb[1].VertexBufferMOCS = batch->blorp->mocs.vb;
250 #if GEN_GEN >= 7
251 vb[1].AddressModifyEnable = true;
252 #endif
253 #if GEN_GEN >= 8
254 vb[1].BufferSize = size;
255 #else
256 vb[1].BufferAccessType = INSTANCEDATA;
257 vb[1].EndAddress = vb[1].BufferStartingAddress;
258 vb[1].EndAddress.offset += size - 1;
259 #endif
260 num_buffers++;
261 }
262
263 const unsigned num_dwords =
264 1 + GENX(VERTEX_BUFFER_STATE_length) * num_buffers;
265 uint32_t *dw = blorp_emitn(batch, GENX(3DSTATE_VERTEX_BUFFERS), num_dwords);
266
267 for (unsigned i = 0; i < num_buffers; i++) {
268 GENX(VERTEX_BUFFER_STATE_pack)(batch, dw, &vb[i]);
269 dw += GENX(VERTEX_BUFFER_STATE_length);
270 }
271 }
272
273 static void
274 blorp_emit_vertex_elements(struct blorp_batch *batch,
275 const struct blorp_params *params)
276 {
277 const unsigned num_varyings =
278 params->wm_prog_data ? params->wm_prog_data->num_varying_inputs : 0;
279 const unsigned num_elements = 2 + num_varyings;
280
281 struct GENX(VERTEX_ELEMENT_STATE) ve[num_elements];
282 memset(ve, 0, num_elements * sizeof(*ve));
283
284 /* Setup VBO for the rectangle primitive..
285 *
286 * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
287 * vertices. The vertices reside in screen space with DirectX
288 * coordinates (that is, (0, 0) is the upper left corner).
289 *
290 * v2 ------ implied
291 * | |
292 * | |
293 * v1 ----- v0
294 *
295 * Since the VS is disabled, the clipper loads each VUE directly from
296 * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
297 * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
298 * dw0: Reserved, MBZ.
299 * dw1: Render Target Array Index. Below vertex fetcher gets programmed
300 * to assign this with primitive instance identifier which will be
301 * used for layered clears. All other renders have only one instance
302 * and therefore the value will be effectively zero.
303 * dw2: Viewport Index. The HiZ op disables viewport mapping and
304 * scissoring, so set the dword to 0.
305 * dw3: Point Width: The HiZ op does not emit the POINTLIST primitive,
306 * so set the dword to 0.
307 * dw4: Vertex Position X.
308 * dw5: Vertex Position Y.
309 * dw6: Vertex Position Z.
310 * dw7: Vertex Position W.
311 *
312 * dw8: Flat vertex input 0
313 * dw9: Flat vertex input 1
314 * ...
315 * dwn: Flat vertex input n - 8
316 *
317 * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
318 * "Vertex URB Entry (VUE) Formats".
319 *
320 * Only vertex position X and Y are going to be variable, Z is fixed to
321 * zero and W to one. Header words dw0,2,3 are zero. There is no need to
322 * include the fixed values in the vertex buffer. Vertex fetcher can be
323 * instructed to fill vertex elements with constant values of one and zero
324 * instead of reading them from the buffer.
325 * Flat inputs are program constants that are not interpolated. Moreover
326 * their values will be the same between vertices.
327 *
328 * See the vertex element setup below.
329 */
330 ve[0].VertexBufferIndex = 0;
331 ve[0].Valid = true;
332 ve[0].SourceElementFormat = ISL_FORMAT_R32G32B32A32_FLOAT;
333 ve[0].SourceElementOffset = 0;
334 ve[0].Component0Control = VFCOMP_STORE_0;
335
336 /* From Gen8 onwards hardware is no more instructed to overwrite components
337 * using an element specifier. Instead one has separate 3DSTATE_VF_SGVS
338 * (System Generated Value Setup) state packet for it.
339 */
340 #if GEN_GEN >= 8
341 ve[0].Component1Control = VFCOMP_STORE_0;
342 #else
343 ve[0].Component1Control = VFCOMP_STORE_IID;
344 #endif
345 ve[0].Component2Control = VFCOMP_STORE_0;
346 ve[0].Component3Control = VFCOMP_STORE_0;
347
348 ve[1].VertexBufferIndex = 0;
349 ve[1].Valid = true;
350 ve[1].SourceElementFormat = ISL_FORMAT_R32G32B32_FLOAT;
351 ve[1].SourceElementOffset = 0;
352 ve[1].Component0Control = VFCOMP_STORE_SRC;
353 ve[1].Component1Control = VFCOMP_STORE_SRC;
354 ve[1].Component2Control = VFCOMP_STORE_SRC;
355 ve[1].Component3Control = VFCOMP_STORE_1_FP;
356
357 for (unsigned i = 0; i < num_varyings; ++i) {
358 ve[i + 2].VertexBufferIndex = 1;
359 ve[i + 2].Valid = true;
360 ve[i + 2].SourceElementFormat = ISL_FORMAT_R32G32B32A32_FLOAT;
361 ve[i + 2].SourceElementOffset = i * 4 * sizeof(float);
362 ve[i + 2].Component0Control = VFCOMP_STORE_SRC;
363 ve[i + 2].Component1Control = VFCOMP_STORE_SRC;
364 ve[i + 2].Component2Control = VFCOMP_STORE_SRC;
365 ve[i + 2].Component3Control = VFCOMP_STORE_SRC;
366 }
367
368 const unsigned num_dwords =
369 1 + GENX(VERTEX_ELEMENT_STATE_length) * num_elements;
370 uint32_t *dw = blorp_emitn(batch, GENX(3DSTATE_VERTEX_ELEMENTS), num_dwords);
371
372 for (unsigned i = 0; i < num_elements; i++) {
373 GENX(VERTEX_ELEMENT_STATE_pack)(batch, dw, &ve[i]);
374 dw += GENX(VERTEX_ELEMENT_STATE_length);
375 }
376
377 #if GEN_GEN >= 8
378 /* Overwrite Render Target Array Index (2nd dword) in the VUE header with
379 * primitive instance identifier. This is used for layered clears.
380 */
381 blorp_emit(batch, GENX(3DSTATE_VF_SGVS), sgvs) {
382 sgvs.InstanceIDEnable = true;
383 sgvs.InstanceIDComponentNumber = COMP_1;
384 sgvs.InstanceIDElementOffset = 0;
385 }
386
387 for (unsigned i = 0; i < num_elements; i++) {
388 blorp_emit(batch, GENX(3DSTATE_VF_INSTANCING), vf) {
389 vf.VertexElementIndex = i;
390 vf.InstancingEnable = false;
391 }
392 }
393
394 blorp_emit(batch, GENX(3DSTATE_VF_TOPOLOGY), topo) {
395 topo.PrimitiveTopologyType = _3DPRIM_RECTLIST;
396 }
397 #endif
398 }
399
400 static void
401 blorp_emit_sf_config(struct blorp_batch *batch,
402 const struct blorp_params *params)
403 {
404 const struct brw_blorp_prog_data *prog_data = params->wm_prog_data;
405
406 /* 3DSTATE_SF
407 *
408 * Disable ViewportTransformEnable (dw2.1)
409 *
410 * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
411 * Primitives Overview":
412 * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
413 * use of screen- space coordinates).
414 *
415 * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
416 * and BackFaceFillMode (dw2.5:6) to SOLID(0).
417 *
418 * From the Sandy Bridge PRM, Volume 2, Part 1, Section
419 * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
420 * SOLID: Any triangle or rectangle object found to be front-facing
421 * is rendered as a solid object. This setting is required when
422 * (rendering rectangle (RECTLIST) objects.
423 */
424
425 #if GEN_GEN >= 8
426
427 blorp_emit(batch, GENX(3DSTATE_SF), sf);
428
429 blorp_emit(batch, GENX(3DSTATE_RASTER), raster) {
430 raster.CullMode = CULLMODE_NONE;
431 }
432
433 blorp_emit(batch, GENX(3DSTATE_SBE), sbe) {
434 sbe.VertexURBEntryReadOffset = 1;
435 sbe.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
436 sbe.VertexURBEntryReadLength = brw_blorp_get_urb_length(prog_data);
437 sbe.ForceVertexURBEntryReadLength = true;
438 sbe.ForceVertexURBEntryReadOffset = true;
439 sbe.ConstantInterpolationEnable = prog_data->flat_inputs;
440
441 #if GEN_GEN >= 9
442 for (unsigned i = 0; i < 32; i++)
443 sbe.AttributeActiveComponentFormat[i] = ACF_XYZW;
444 #endif
445 }
446
447 #elif GEN_GEN >= 7
448
449 blorp_emit(batch, GENX(3DSTATE_SF), sf) {
450 sf.FrontFaceFillMode = FILL_MODE_SOLID;
451 sf.BackFaceFillMode = FILL_MODE_SOLID;
452
453 sf.MultisampleRasterizationMode = params->dst.surf.samples > 1 ?
454 MSRASTMODE_ON_PATTERN : MSRASTMODE_OFF_PIXEL;
455
456 #if GEN_GEN == 7
457 sf.DepthBufferSurfaceFormat = params->depth_format;
458 #endif
459 }
460
461 blorp_emit(batch, GENX(3DSTATE_SBE), sbe) {
462 sbe.VertexURBEntryReadOffset = 1;
463 if (prog_data) {
464 sbe.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
465 sbe.VertexURBEntryReadLength = brw_blorp_get_urb_length(prog_data);
466 sbe.ConstantInterpolationEnable = prog_data->flat_inputs;
467 } else {
468 sbe.NumberofSFOutputAttributes = 0;
469 sbe.VertexURBEntryReadLength = 1;
470 }
471 }
472
473 #else /* GEN_GEN <= 6 */
474
475 blorp_emit(batch, GENX(3DSTATE_SF), sf) {
476 sf.FrontFaceFillMode = FILL_MODE_SOLID;
477 sf.BackFaceFillMode = FILL_MODE_SOLID;
478
479 sf.MultisampleRasterizationMode = params->dst.surf.samples > 1 ?
480 MSRASTMODE_ON_PATTERN : MSRASTMODE_OFF_PIXEL;
481
482 sf.VertexURBEntryReadOffset = 1;
483 if (prog_data) {
484 sf.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
485 sf.VertexURBEntryReadLength = brw_blorp_get_urb_length(prog_data);
486 sf.ConstantInterpolationEnable = prog_data->flat_inputs;
487 } else {
488 sf.NumberofSFOutputAttributes = 0;
489 sf.VertexURBEntryReadLength = 1;
490 }
491 }
492
493 #endif /* GEN_GEN */
494 }
495
496 static void
497 blorp_emit_ps_config(struct blorp_batch *batch,
498 const struct blorp_params *params)
499 {
500 const struct brw_blorp_prog_data *prog_data = params->wm_prog_data;
501
502 /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
503 * nonzero to prevent the GPU from hanging. While the documentation doesn't
504 * mention this explicitly, it notes that the valid range for the field is
505 * [1,39] = [2,40] threads, which excludes zero.
506 *
507 * To be safe (and to minimize extraneous code) we go ahead and fully
508 * configure the WM state whether or not there is a WM program.
509 */
510
511 #if GEN_GEN >= 8
512
513 blorp_emit(batch, GENX(3DSTATE_WM), wm);
514
515 blorp_emit(batch, GENX(3DSTATE_PS), ps) {
516 if (params->src.addr.buffer) {
517 ps.SamplerCount = 1; /* Up to 4 samplers */
518 ps.BindingTableEntryCount = 2;
519 } else {
520 ps.BindingTableEntryCount = 1;
521 }
522
523 ps.DispatchGRFStartRegisterForConstantSetupData0 =
524 prog_data->first_curbe_grf_0;
525 ps.DispatchGRFStartRegisterForConstantSetupData2 =
526 prog_data->first_curbe_grf_2;
527
528 ps._8PixelDispatchEnable = prog_data->dispatch_8;
529 ps._16PixelDispatchEnable = prog_data->dispatch_16;
530
531 ps.KernelStartPointer0 = params->wm_prog_kernel;
532 ps.KernelStartPointer2 =
533 params->wm_prog_kernel + prog_data->ksp_offset_2;
534
535 /* 3DSTATE_PS expects the number of threads per PSD, which is always 64;
536 * it implicitly scales for different GT levels (which have some # of
537 * PSDs).
538 *
539 * In Gen8 the format is U8-2 whereas in Gen9 it is U8-1.
540 */
541 if (GEN_GEN >= 9)
542 ps.MaximumNumberofThreadsPerPSD = 64 - 1;
543 else
544 ps.MaximumNumberofThreadsPerPSD = 64 - 2;
545
546 switch (params->fast_clear_op) {
547 case BLORP_FAST_CLEAR_OP_NONE:
548 break;
549 #if GEN_GEN >= 9
550 case BLORP_FAST_CLEAR_OP_RESOLVE_PARTIAL:
551 ps.RenderTargetResolveType = RESOLVE_PARTIAL;
552 break;
553 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL:
554 ps.RenderTargetResolveType = RESOLVE_FULL;
555 break;
556 #else
557 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL:
558 ps.RenderTargetResolveEnable = true;
559 break;
560 #endif
561 case BLORP_FAST_CLEAR_OP_CLEAR:
562 ps.RenderTargetFastClearEnable = true;
563 break;
564 default:
565 unreachable("Invalid fast clear op");
566 }
567 }
568
569 blorp_emit(batch, GENX(3DSTATE_PS_EXTRA), psx) {
570 psx.PixelShaderValid = true;
571
572 if (params->src.addr.buffer)
573 psx.PixelShaderKillsPixel = true;
574
575 psx.AttributeEnable = prog_data->num_varying_inputs > 0;
576
577 if (prog_data && prog_data->persample_msaa_dispatch)
578 psx.PixelShaderIsPerSample = true;
579 }
580
581 #elif GEN_GEN >= 7
582
583 blorp_emit(batch, GENX(3DSTATE_WM), wm) {
584 switch (params->hiz_op) {
585 case BLORP_HIZ_OP_DEPTH_CLEAR:
586 wm.DepthBufferClear = true;
587 break;
588 case BLORP_HIZ_OP_DEPTH_RESOLVE:
589 wm.DepthBufferResolveEnable = true;
590 break;
591 case BLORP_HIZ_OP_HIZ_RESOLVE:
592 wm.HierarchicalDepthBufferResolveEnable = true;
593 break;
594 case BLORP_HIZ_OP_NONE:
595 break;
596 default:
597 unreachable("not reached");
598 }
599
600 if (prog_data)
601 wm.ThreadDispatchEnable = true;
602
603 if (params->src.addr.buffer)
604 wm.PixelShaderKillPixel = true;
605
606 if (params->dst.surf.samples > 1) {
607 wm.MultisampleRasterizationMode = MSRASTMODE_ON_PATTERN;
608 wm.MultisampleDispatchMode =
609 (prog_data && prog_data->persample_msaa_dispatch) ?
610 MSDISPMODE_PERSAMPLE : MSDISPMODE_PERPIXEL;
611 } else {
612 wm.MultisampleRasterizationMode = MSRASTMODE_OFF_PIXEL;
613 wm.MultisampleDispatchMode = MSDISPMODE_PERSAMPLE;
614 }
615 }
616
617 blorp_emit(batch, GENX(3DSTATE_PS), ps) {
618 ps.MaximumNumberofThreads =
619 batch->blorp->isl_dev->info->max_wm_threads - 1;
620
621 #if GEN_IS_HASWELL
622 ps.SampleMask = 1;
623 #endif
624
625 if (prog_data) {
626 ps.DispatchGRFStartRegisterforConstantSetupData0 =
627 prog_data->first_curbe_grf_0;
628 ps.DispatchGRFStartRegisterforConstantSetupData2 =
629 prog_data->first_curbe_grf_2;
630
631 ps.KernelStartPointer0 = params->wm_prog_kernel;
632 ps.KernelStartPointer2 =
633 params->wm_prog_kernel + prog_data->ksp_offset_2;
634
635 ps._8PixelDispatchEnable = prog_data->dispatch_8;
636 ps._16PixelDispatchEnable = prog_data->dispatch_16;
637
638 ps.AttributeEnable = prog_data->num_varying_inputs > 0;
639 } else {
640 /* Gen7 hardware gets angry if we don't enable at least one dispatch
641 * mode, so just enable 16-pixel dispatch if we don't have a program.
642 */
643 ps._16PixelDispatchEnable = true;
644 }
645
646 if (params->src.addr.buffer)
647 ps.SamplerCount = 1; /* Up to 4 samplers */
648
649 switch (params->fast_clear_op) {
650 case BLORP_FAST_CLEAR_OP_NONE:
651 break;
652 case BLORP_FAST_CLEAR_OP_RESOLVE_FULL:
653 ps.RenderTargetResolveEnable = true;
654 break;
655 case BLORP_FAST_CLEAR_OP_CLEAR:
656 ps.RenderTargetFastClearEnable = true;
657 break;
658 default:
659 unreachable("Invalid fast clear op");
660 }
661 }
662
663 #else /* GEN_GEN <= 6 */
664
665 blorp_emit(batch, GENX(3DSTATE_WM), wm) {
666 wm.MaximumNumberofThreads =
667 batch->blorp->isl_dev->info->max_wm_threads - 1;
668
669 switch (params->hiz_op) {
670 case BLORP_HIZ_OP_DEPTH_CLEAR:
671 wm.DepthBufferClear = true;
672 break;
673 case BLORP_HIZ_OP_DEPTH_RESOLVE:
674 wm.DepthBufferResolveEnable = true;
675 break;
676 case BLORP_HIZ_OP_HIZ_RESOLVE:
677 wm.HierarchicalDepthBufferResolveEnable = true;
678 break;
679 case BLORP_HIZ_OP_NONE:
680 break;
681 default:
682 unreachable("not reached");
683 }
684
685 if (prog_data) {
686 wm.ThreadDispatchEnable = true;
687
688 wm.DispatchGRFStartRegisterforConstantSetupData0 =
689 prog_data->first_curbe_grf_0;
690 wm.DispatchGRFStartRegisterforConstantSetupData2 =
691 prog_data->first_curbe_grf_2;
692
693 wm.KernelStartPointer0 = params->wm_prog_kernel;
694 wm.KernelStartPointer2 =
695 params->wm_prog_kernel + prog_data->ksp_offset_2;
696
697 wm._8PixelDispatchEnable = prog_data->dispatch_8;
698 wm._16PixelDispatchEnable = prog_data->dispatch_16;
699
700 wm.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
701 }
702
703 if (params->src.addr.buffer) {
704 wm.SamplerCount = 1; /* Up to 4 samplers */
705 wm.PixelShaderKillPixel = true; /* TODO: temporarily smash on */
706 }
707
708 if (params->dst.surf.samples > 1) {
709 wm.MultisampleRasterizationMode = MSRASTMODE_ON_PATTERN;
710 wm.MultisampleDispatchMode =
711 (prog_data && prog_data->persample_msaa_dispatch) ?
712 MSDISPMODE_PERSAMPLE : MSDISPMODE_PERPIXEL;
713 } else {
714 wm.MultisampleRasterizationMode = MSRASTMODE_OFF_PIXEL;
715 wm.MultisampleDispatchMode = MSDISPMODE_PERSAMPLE;
716 }
717 }
718
719 #endif /* GEN_GEN */
720 }
721
722 static const uint32_t isl_to_gen_ds_surftype [] = {
723 #if GEN_GEN >= 9
724 /* From the SKL PRM, "3DSTATE_DEPTH_STENCIL::SurfaceType":
725 *
726 * "If depth/stencil is enabled with 1D render target, depth/stencil
727 * surface type needs to be set to 2D surface type and height set to 1.
728 * Depth will use (legacy) TileY and stencil will use TileW. For this
729 * case only, the Surface Type of the depth buffer can be 2D while the
730 * Surface Type of the render target(s) are 1D, representing an
731 * exception to a programming note above.
732 */
733 [ISL_SURF_DIM_1D] = SURFTYPE_2D,
734 #else
735 [ISL_SURF_DIM_1D] = SURFTYPE_1D,
736 #endif
737 [ISL_SURF_DIM_2D] = SURFTYPE_2D,
738 [ISL_SURF_DIM_3D] = SURFTYPE_3D,
739 };
740
741 static void
742 blorp_emit_depth_stencil_config(struct blorp_batch *batch,
743 const struct blorp_params *params)
744 {
745 #if GEN_GEN >= 7
746 const uint32_t mocs = 1; /* GEN7_MOCS_L3 */
747 #else
748 const uint32_t mocs = 0;
749 #endif
750
751 blorp_emit(batch, GENX(3DSTATE_DEPTH_BUFFER), db) {
752 #if GEN_GEN >= 7
753 db.DepthWriteEnable = params->depth.addr.buffer != NULL;
754 db.StencilWriteEnable = params->stencil.addr.buffer != NULL;
755 #endif
756
757 #if GEN_GEN <= 6
758 db.SeparateStencilBufferEnable = true;
759 #endif
760
761 if (params->depth.addr.buffer) {
762 db.SurfaceFormat = params->depth_format;
763 db.SurfaceType = isl_to_gen_ds_surftype[params->depth.surf.dim];
764
765 #if GEN_GEN <= 6
766 db.TiledSurface = true;
767 db.TileWalk = TILEWALK_YMAJOR;
768 db.MIPMapLayoutMode = MIPLAYOUT_BELOW;
769 #endif
770
771 db.HierarchicalDepthBufferEnable =
772 params->depth.aux_usage == ISL_AUX_USAGE_HIZ;
773
774 db.Width = params->depth.surf.logical_level0_px.width - 1;
775 db.Height = params->depth.surf.logical_level0_px.height - 1;
776 db.RenderTargetViewExtent = db.Depth =
777 params->depth.view.array_len - 1;
778
779 db.LOD = params->depth.view.base_level;
780 db.MinimumArrayElement = params->depth.view.base_array_layer;
781
782 db.SurfacePitch = params->depth.surf.row_pitch - 1;
783 #if GEN_GEN >= 8
784 db.SurfaceQPitch =
785 isl_surf_get_array_pitch_el_rows(&params->depth.surf) >> 2,
786 #endif
787
788 db.SurfaceBaseAddress = params->depth.addr;
789 db.DepthBufferMOCS = mocs;
790 } else {
791 db.SurfaceFormat = D32_FLOAT;
792 db.SurfaceType = isl_to_gen_ds_surftype[params->stencil.surf.dim];
793
794 /* If we don't have a depth buffer, pull dimensions from stencil */
795 assert(params->stencil.addr.buffer != NULL);
796
797 db.Width = params->stencil.surf.logical_level0_px.width - 1;
798 db.Height = params->stencil.surf.logical_level0_px.height - 1;
799 db.RenderTargetViewExtent = db.Depth =
800 params->stencil.view.array_len - 1;
801
802 db.LOD = params->stencil.view.base_level;
803 db.MinimumArrayElement = params->stencil.view.base_array_layer;
804 }
805 }
806
807 blorp_emit(batch, GENX(3DSTATE_HIER_DEPTH_BUFFER), hiz) {
808 if (params->depth.aux_usage == ISL_AUX_USAGE_HIZ) {
809 hiz.SurfacePitch = params->depth.aux_surf.row_pitch - 1;
810 hiz.SurfaceBaseAddress = params->depth.aux_addr;
811 hiz.HierarchicalDepthBufferMOCS = mocs;
812 #if GEN_GEN >= 8
813 hiz.SurfaceQPitch =
814 isl_surf_get_array_pitch_sa_rows(&params->depth.aux_surf) >> 2;
815 #endif
816 }
817 }
818
819 blorp_emit(batch, GENX(3DSTATE_STENCIL_BUFFER), sb) {
820 if (params->stencil.addr.buffer) {
821 #if GEN_GEN >= 8 || GEN_IS_HASWELL
822 sb.StencilBufferEnable = true;
823 #endif
824
825 sb.SurfacePitch = params->stencil.surf.row_pitch - 1,
826 #if GEN_GEN >= 8
827 sb.SurfaceQPitch =
828 isl_surf_get_array_pitch_el_rows(&params->stencil.surf) >> 2,
829 #endif
830
831 sb.SurfaceBaseAddress = params->stencil.addr;
832 sb.StencilBufferMOCS = batch->blorp->mocs.tex;
833 }
834 }
835
836 /* 3DSTATE_CLEAR_PARAMS
837 *
838 * From the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE_CLEAR_PARAMS:
839 * [DevSNB] 3DSTATE_CLEAR_PARAMS packet must follow the DEPTH_BUFFER_STATE
840 * packet when HiZ is enabled and the DEPTH_BUFFER_STATE changes.
841 */
842 blorp_emit(batch, GENX(3DSTATE_CLEAR_PARAMS), clear) {
843 clear.DepthClearValueValid = true;
844 clear.DepthClearValue = params->depth.clear_color.u32[0];
845 }
846 }
847
848 static uint32_t
849 blorp_emit_blend_state(struct blorp_batch *batch,
850 const struct blorp_params *params)
851 {
852 struct GENX(BLEND_STATE) blend;
853 memset(&blend, 0, sizeof(blend));
854
855 for (unsigned i = 0; i < params->num_draw_buffers; ++i) {
856 blend.Entry[i].PreBlendColorClampEnable = true;
857 blend.Entry[i].PostBlendColorClampEnable = true;
858 blend.Entry[i].ColorClampRange = COLORCLAMP_RTFORMAT;
859
860 blend.Entry[i].WriteDisableRed = params->color_write_disable[0];
861 blend.Entry[i].WriteDisableGreen = params->color_write_disable[1];
862 blend.Entry[i].WriteDisableBlue = params->color_write_disable[2];
863 blend.Entry[i].WriteDisableAlpha = params->color_write_disable[3];
864 }
865
866 uint32_t offset;
867 void *state = blorp_alloc_dynamic_state(batch, AUB_TRACE_BLEND_STATE,
868 GENX(BLEND_STATE_length) * 4,
869 64, &offset);
870 GENX(BLEND_STATE_pack)(NULL, state, &blend);
871
872 #if GEN_GEN >= 7
873 blorp_emit(batch, GENX(3DSTATE_BLEND_STATE_POINTERS), sp) {
874 sp.BlendStatePointer = offset;
875 #if GEN_GEN >= 8
876 sp.BlendStatePointerValid = true;
877 #endif
878 }
879 #endif
880
881 #if GEN_GEN >= 8
882 blorp_emit(batch, GENX(3DSTATE_PS_BLEND), ps_blend) {
883 ps_blend.HasWriteableRT = true;
884 }
885 #endif
886
887 return offset;
888 }
889
890 static uint32_t
891 blorp_emit_color_calc_state(struct blorp_batch *batch,
892 const struct blorp_params *params)
893 {
894 uint32_t offset;
895 void *state = blorp_alloc_dynamic_state(batch, AUB_TRACE_CC_STATE,
896 GENX(COLOR_CALC_STATE_length) * 4,
897 64, &offset);
898 memset(state, 0, GENX(COLOR_CALC_STATE_length) * 4);
899
900 #if GEN_GEN >= 7
901 blorp_emit(batch, GENX(3DSTATE_CC_STATE_POINTERS), sp) {
902 sp.ColorCalcStatePointer = offset;
903 #if GEN_GEN >= 8
904 sp.ColorCalcStatePointerValid = true;
905 #endif
906 }
907 #endif
908
909 return offset;
910 }
911
912 static uint32_t
913 blorp_emit_depth_stencil_state(struct blorp_batch *batch,
914 const struct blorp_params *params)
915 {
916 #if GEN_GEN >= 8
917
918 /* On gen8+, DEPTH_STENCIL state is simply an instruction */
919 blorp_emit(batch, GENX(3DSTATE_WM_DEPTH_STENCIL), ds);
920 return 0;
921
922 #else /* GEN_GEN <= 7 */
923
924 /* See the following sections of the Sandy Bridge PRM, Volume 1, Part2:
925 * - 7.5.3.1 Depth Buffer Clear
926 * - 7.5.3.2 Depth Buffer Resolve
927 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
928 */
929 struct GENX(DEPTH_STENCIL_STATE) ds = {
930 .DepthBufferWriteEnable = true,
931 };
932
933 if (params->hiz_op == BLORP_HIZ_OP_DEPTH_RESOLVE) {
934 ds.DepthTestEnable = true;
935 ds.DepthTestFunction = COMPAREFUNCTION_NEVER;
936 }
937
938 uint32_t offset;
939 void *state = blorp_alloc_dynamic_state(batch, AUB_TRACE_DEPTH_STENCIL_STATE,
940 GENX(DEPTH_STENCIL_STATE_length) * 4,
941 64, &offset);
942 GENX(DEPTH_STENCIL_STATE_pack)(NULL, state, &ds);
943
944 #if GEN_GEN >= 7
945 blorp_emit(batch, GENX(3DSTATE_DEPTH_STENCIL_STATE_POINTERS), sp) {
946 sp.PointertoDEPTH_STENCIL_STATE = offset;
947 }
948 #endif
949
950 return offset;
951
952 #endif /* GEN_GEN */
953 }
954
955 struct surface_state_info {
956 unsigned num_dwords;
957 unsigned ss_align; /* Required alignment of RENDER_SURFACE_STATE in bytes */
958 unsigned reloc_dw;
959 unsigned aux_reloc_dw;
960 };
961
962 static const struct surface_state_info surface_state_infos[] = {
963 [6] = {6, 32, 1, 0},
964 [7] = {8, 32, 1, 6},
965 [8] = {13, 64, 8, 10},
966 [9] = {16, 64, 8, 10},
967 };
968
969 static void
970 blorp_emit_surface_state(struct blorp_batch *batch,
971 const struct brw_blorp_surface_info *surface,
972 uint32_t *state, uint32_t state_offset,
973 bool is_render_target)
974 {
975 const struct surface_state_info ss_info = surface_state_infos[GEN_GEN];
976
977 struct isl_surf surf = surface->surf;
978
979 if (surf.dim == ISL_SURF_DIM_1D &&
980 surf.dim_layout == ISL_DIM_LAYOUT_GEN4_2D) {
981 assert(surf.logical_level0_px.height == 1);
982 surf.dim = ISL_SURF_DIM_2D;
983 }
984
985 /* Blorp doesn't support HiZ in any of the blit or slow-clear paths */
986 enum isl_aux_usage aux_usage = surface->aux_usage;
987 if (aux_usage == ISL_AUX_USAGE_HIZ)
988 aux_usage = ISL_AUX_USAGE_NONE;
989
990 const uint32_t mocs =
991 is_render_target ? batch->blorp->mocs.rb : batch->blorp->mocs.tex;
992
993 isl_surf_fill_state(batch->blorp->isl_dev, state,
994 .surf = &surf, .view = &surface->view,
995 .aux_surf = &surface->aux_surf, .aux_usage = aux_usage,
996 .mocs = mocs, .clear_color = surface->clear_color);
997
998 blorp_surface_reloc(batch, state_offset + ss_info.reloc_dw * 4,
999 surface->addr, 0);
1000
1001 if (aux_usage != ISL_AUX_USAGE_NONE) {
1002 /* On gen7 and prior, the bottom 12 bits of the MCS base address are
1003 * used to store other information. This should be ok, however, because
1004 * surface buffer addresses are always 4K page alinged.
1005 */
1006 assert((surface->aux_addr.offset & 0xfff) == 0);
1007 blorp_surface_reloc(batch, state_offset + ss_info.aux_reloc_dw * 4,
1008 surface->aux_addr, state[ss_info.aux_reloc_dw]);
1009 }
1010 }
1011
1012 static void
1013 blorp_emit_surface_states(struct blorp_batch *batch,
1014 const struct blorp_params *params)
1015 {
1016 uint32_t bind_offset, surface_offsets[2];
1017 void *surface_maps[2];
1018
1019 const unsigned ss_size = GENX(RENDER_SURFACE_STATE_length) * 4;
1020 const unsigned ss_align = GENX(RENDER_SURFACE_STATE_length) > 8 ? 64 : 32;
1021
1022 unsigned num_surfaces = 1 + (params->src.addr.buffer != NULL);
1023 blorp_alloc_binding_table(batch, num_surfaces, ss_size, ss_align,
1024 &bind_offset, surface_offsets, surface_maps);
1025
1026 blorp_emit_surface_state(batch, &params->dst,
1027 surface_maps[BLORP_RENDERBUFFER_BT_INDEX],
1028 surface_offsets[BLORP_RENDERBUFFER_BT_INDEX], true);
1029 if (params->src.addr.buffer) {
1030 blorp_emit_surface_state(batch, &params->src,
1031 surface_maps[BLORP_TEXTURE_BT_INDEX],
1032 surface_offsets[BLORP_TEXTURE_BT_INDEX], false);
1033 }
1034
1035 #if GEN_GEN >= 7
1036 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_PS), bt) {
1037 bt.PointertoPSBindingTable = bind_offset;
1038 }
1039 #else
1040 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS), bt) {
1041 bt.PSBindingTableChange = true;
1042 bt.PointertoPSBindingTable = bind_offset;
1043 }
1044 #endif
1045 }
1046
1047 static void
1048 blorp_emit_sampler_state(struct blorp_batch *batch,
1049 const struct blorp_params *params)
1050 {
1051 struct GENX(SAMPLER_STATE) sampler = {
1052 .MipModeFilter = MIPFILTER_NONE,
1053 .MagModeFilter = MAPFILTER_LINEAR,
1054 .MinModeFilter = MAPFILTER_LINEAR,
1055 .MinLOD = 0,
1056 .MaxLOD = 0,
1057 .TCXAddressControlMode = TCM_CLAMP,
1058 .TCYAddressControlMode = TCM_CLAMP,
1059 .TCZAddressControlMode = TCM_CLAMP,
1060 .MaximumAnisotropy = RATIO21,
1061 .RAddressMinFilterRoundingEnable = true,
1062 .RAddressMagFilterRoundingEnable = true,
1063 .VAddressMinFilterRoundingEnable = true,
1064 .VAddressMagFilterRoundingEnable = true,
1065 .UAddressMinFilterRoundingEnable = true,
1066 .UAddressMagFilterRoundingEnable = true,
1067 .NonnormalizedCoordinateEnable = true,
1068 };
1069
1070 uint32_t offset;
1071 void *state = blorp_alloc_dynamic_state(batch, AUB_TRACE_SAMPLER_STATE,
1072 GENX(SAMPLER_STATE_length) * 4,
1073 32, &offset);
1074 GENX(SAMPLER_STATE_pack)(NULL, state, &sampler);
1075
1076 #if GEN_GEN >= 7
1077 blorp_emit(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS_PS), ssp) {
1078 ssp.PointertoPSSamplerState = offset;
1079 }
1080 #else
1081 blorp_emit(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS), ssp) {
1082 ssp.VSSamplerStateChange = true;
1083 ssp.GSSamplerStateChange = true;
1084 ssp.PSSamplerStateChange = true;
1085 ssp.PointertoPSSamplerState = offset;
1086 }
1087 #endif
1088 }
1089
1090 static void
1091 blorp_emit_3dstate_multisample(struct blorp_batch *batch,
1092 const struct blorp_params *params)
1093 {
1094 const unsigned samples = params->dst.surf.samples;
1095
1096 blorp_emit(batch, GENX(3DSTATE_MULTISAMPLE), ms) {
1097 ms.NumberofMultisamples = __builtin_ffs(samples) - 1;
1098
1099 #if GEN_GEN >= 8
1100 /* The PRM says that this bit is valid only for DX9:
1101 *
1102 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
1103 * should not have any effect by setting or not setting this bit.
1104 */
1105 ms.PixelPositionOffsetEnable = false;
1106 ms.PixelLocation = CENTER;
1107 #elif GEN_GEN >= 7
1108 ms.PixelLocation = PIXLOC_CENTER;
1109
1110 switch (samples) {
1111 case 1:
1112 GEN_SAMPLE_POS_1X(ms.Sample);
1113 break;
1114 case 2:
1115 GEN_SAMPLE_POS_2X(ms.Sample);
1116 break;
1117 case 4:
1118 GEN_SAMPLE_POS_4X(ms.Sample);
1119 break;
1120 case 8:
1121 GEN_SAMPLE_POS_8X(ms.Sample);
1122 break;
1123 default:
1124 break;
1125 }
1126 #else
1127 ms.PixelLocation = PIXLOC_CENTER;
1128 GEN_SAMPLE_POS_4X(ms.Sample);
1129 #endif
1130 }
1131 }
1132
1133 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
1134 static void
1135 blorp_emit_viewport_state(struct blorp_batch *batch,
1136 const struct blorp_params *params)
1137 {
1138 uint32_t cc_vp_offset;
1139
1140 void *state = blorp_alloc_dynamic_state(batch, AUB_TRACE_CC_VP_STATE,
1141 GENX(CC_VIEWPORT_length) * 4, 32,
1142 &cc_vp_offset);
1143
1144 GENX(CC_VIEWPORT_pack)(batch, state,
1145 &(struct GENX(CC_VIEWPORT)) {
1146 .MinimumDepth = 0.0,
1147 .MaximumDepth = 1.0,
1148 });
1149
1150 #if GEN_GEN >= 7
1151 blorp_emit(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC), vsp) {
1152 vsp.CCViewportPointer = cc_vp_offset;
1153 }
1154 #else
1155 blorp_emit(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS), vsp) {
1156 vsp.CCViewportStateChange = true;
1157 vsp.PointertoCC_VIEWPORT = cc_vp_offset;
1158 }
1159 #endif
1160 }
1161
1162
1163 /**
1164 * \brief Execute a blit or render pass operation.
1165 *
1166 * To execute the operation, this function manually constructs and emits a
1167 * batch to draw a rectangle primitive. The batchbuffer is flushed before
1168 * constructing and after emitting the batch.
1169 *
1170 * This function alters no GL state.
1171 */
1172 static void
1173 blorp_exec(struct blorp_batch *batch, const struct blorp_params *params)
1174 {
1175 uint32_t blend_state_offset = 0;
1176 uint32_t color_calc_state_offset = 0;
1177 uint32_t depth_stencil_state_offset;
1178
1179 blorp_emit_vertex_buffers(batch, params);
1180 blorp_emit_vertex_elements(batch, params);
1181
1182 emit_urb_config(batch, params);
1183
1184 if (params->wm_prog_data) {
1185 blend_state_offset = blorp_emit_blend_state(batch, params);
1186 color_calc_state_offset = blorp_emit_color_calc_state(batch, params);
1187 }
1188 depth_stencil_state_offset = blorp_emit_depth_stencil_state(batch, params);
1189
1190 #if GEN_GEN <= 6
1191 /* 3DSTATE_CC_STATE_POINTERS
1192 *
1193 * The pointer offsets are relative to
1194 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
1195 *
1196 * The HiZ op doesn't use BLEND_STATE or COLOR_CALC_STATE.
1197 *
1198 * The dynamic state emit helpers emit their own STATE_POINTERS packets on
1199 * gen7+. However, on gen6 and earlier, they're all lumpped together in
1200 * one CC_STATE_POINTERS packet so we have to emit that here.
1201 */
1202 blorp_emit(batch, GENX(3DSTATE_CC_STATE_POINTERS), cc) {
1203 cc.BLEND_STATEChange = true;
1204 cc.COLOR_CALC_STATEChange = true;
1205 cc.DEPTH_STENCIL_STATEChange = true;
1206 cc.PointertoBLEND_STATE = blend_state_offset;
1207 cc.PointertoCOLOR_CALC_STATE = color_calc_state_offset;
1208 cc.PointertoDEPTH_STENCIL_STATE = depth_stencil_state_offset;
1209 }
1210 #else
1211 (void)blend_state_offset;
1212 (void)color_calc_state_offset;
1213 (void)depth_stencil_state_offset;
1214 #endif
1215
1216 blorp_emit(batch, GENX(3DSTATE_CONSTANT_VS), vs);
1217 #if GEN_GEN >= 7
1218 blorp_emit(batch, GENX(3DSTATE_CONSTANT_HS), hs);
1219 blorp_emit(batch, GENX(3DSTATE_CONSTANT_DS), DS);
1220 #endif
1221 blorp_emit(batch, GENX(3DSTATE_CONSTANT_GS), gs);
1222 blorp_emit(batch, GENX(3DSTATE_CONSTANT_PS), ps);
1223
1224 if (params->wm_prog_data)
1225 blorp_emit_surface_states(batch, params);
1226
1227 if (params->src.addr.buffer)
1228 blorp_emit_sampler_state(batch, params);
1229
1230 blorp_emit_3dstate_multisample(batch, params);
1231
1232 blorp_emit(batch, GENX(3DSTATE_SAMPLE_MASK), mask) {
1233 mask.SampleMask = (1 << params->dst.surf.samples) - 1;
1234 }
1235
1236 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
1237 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
1238 *
1239 * [DevSNB] A pipeline flush must be programmed prior to a
1240 * 3DSTATE_VS command that causes the VS Function Enable to
1241 * toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
1242 * command with CS stall bit set and a post sync operation.
1243 *
1244 * We've already done one at the start of the BLORP operation.
1245 */
1246 blorp_emit(batch, GENX(3DSTATE_VS), vs);
1247 #if GEN_GEN >= 7
1248 blorp_emit(batch, GENX(3DSTATE_HS), hs);
1249 blorp_emit(batch, GENX(3DSTATE_TE), te);
1250 blorp_emit(batch, GENX(3DSTATE_DS), DS);
1251 blorp_emit(batch, GENX(3DSTATE_STREAMOUT), so);
1252 #endif
1253 blorp_emit(batch, GENX(3DSTATE_GS), gs);
1254
1255 blorp_emit(batch, GENX(3DSTATE_CLIP), clip) {
1256 clip.PerspectiveDivideDisable = true;
1257 }
1258
1259 blorp_emit_sf_config(batch, params);
1260 blorp_emit_ps_config(batch, params);
1261
1262 blorp_emit_viewport_state(batch, params);
1263
1264 if (params->depth.addr.buffer || params->stencil.addr.buffer) {
1265 blorp_emit_depth_stencil_config(batch, params);
1266 } else {
1267 blorp_emit(batch, GENX(3DSTATE_DEPTH_BUFFER), db) {
1268 db.SurfaceType = SURFTYPE_NULL;
1269 db.SurfaceFormat = D32_FLOAT;
1270 }
1271 blorp_emit(batch, GENX(3DSTATE_HIER_DEPTH_BUFFER), hiz);
1272 blorp_emit(batch, GENX(3DSTATE_STENCIL_BUFFER), sb);
1273 blorp_emit(batch, GENX(3DSTATE_CLEAR_PARAMS), clear);
1274 }
1275
1276 blorp_emit(batch, GENX(3DPRIMITIVE), prim) {
1277 prim.VertexAccessType = SEQUENTIAL;
1278 prim.PrimitiveTopologyType = _3DPRIM_RECTLIST;
1279 prim.VertexCountPerInstance = 3;
1280 prim.InstanceCount = params->num_layers;
1281 }
1282 }
1283
1284 #endif /* BLORP_GENX_EXEC_H */