intel/compiler: Add and use helpers for working with KSP indices
[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 "dev/gen_device_info.h"
29 #include "common/gen_sample_positions.h"
30 #include "genxml/gen_macros.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 uint32_t size,
57 uint32_t alignment,
58 uint32_t *offset);
59 static void *
60 blorp_alloc_vertex_buffer(struct blorp_batch *batch, uint32_t size,
61 struct blorp_address *addr);
62 static void
63 blorp_vf_invalidate_for_vb_48b_transitions(struct blorp_batch *batch,
64 const struct blorp_address *addrs,
65 unsigned num_vbs);
66
67 #if GEN_GEN >= 8
68 static struct blorp_address
69 blorp_get_workaround_page(struct blorp_batch *batch);
70 #endif
71
72 static void
73 blorp_alloc_binding_table(struct blorp_batch *batch, unsigned num_entries,
74 unsigned state_size, unsigned state_alignment,
75 uint32_t *bt_offset, uint32_t *surface_offsets,
76 void **surface_maps);
77
78 static void
79 blorp_flush_range(struct blorp_batch *batch, void *start, size_t size);
80
81 static void
82 blorp_surface_reloc(struct blorp_batch *batch, uint32_t ss_offset,
83 struct blorp_address address, uint32_t delta);
84
85 #if GEN_GEN >= 7 && GEN_GEN < 10
86 static struct blorp_address
87 blorp_get_surface_base_address(struct blorp_batch *batch);
88 #endif
89
90 static void
91 blorp_emit_urb_config(struct blorp_batch *batch,
92 unsigned vs_entry_size, unsigned sf_entry_size);
93
94 static void
95 blorp_emit_pipeline(struct blorp_batch *batch,
96 const struct blorp_params *params);
97
98 /***** BEGIN blorp_exec implementation ******/
99
100 static uint64_t
101 _blorp_combine_address(struct blorp_batch *batch, void *location,
102 struct blorp_address address, uint32_t delta)
103 {
104 if (address.buffer == NULL) {
105 return address.offset + delta;
106 } else {
107 return blorp_emit_reloc(batch, location, address, delta);
108 }
109 }
110
111 #define __gen_address_type struct blorp_address
112 #define __gen_user_data struct blorp_batch
113 #define __gen_combine_address _blorp_combine_address
114
115 #include "genxml/genX_pack.h"
116
117 #define _blorp_cmd_length(cmd) cmd ## _length
118 #define _blorp_cmd_length_bias(cmd) cmd ## _length_bias
119 #define _blorp_cmd_header(cmd) cmd ## _header
120 #define _blorp_cmd_pack(cmd) cmd ## _pack
121
122 #define blorp_emit(batch, cmd, name) \
123 for (struct cmd name = { _blorp_cmd_header(cmd) }, \
124 *_dst = blorp_emit_dwords(batch, _blorp_cmd_length(cmd)); \
125 __builtin_expect(_dst != NULL, 1); \
126 _blorp_cmd_pack(cmd)(batch, (void *)_dst, &name), \
127 _dst = NULL)
128
129 #define blorp_emitn(batch, cmd, n) ({ \
130 uint32_t *_dw = blorp_emit_dwords(batch, n); \
131 if (_dw) { \
132 struct cmd template = { \
133 _blorp_cmd_header(cmd), \
134 .DWordLength = n - _blorp_cmd_length_bias(cmd), \
135 }; \
136 _blorp_cmd_pack(cmd)(batch, _dw, &template); \
137 } \
138 _dw ? _dw + 1 : NULL; /* Array starts at dw[1] */ \
139 })
140
141 #define STRUCT_ZERO(S) ({ struct S t; memset(&t, 0, sizeof(t)); t; })
142
143 #define blorp_emit_dynamic(batch, state, name, align, offset) \
144 for (struct state name = STRUCT_ZERO(state), \
145 *_dst = blorp_alloc_dynamic_state(batch, \
146 _blorp_cmd_length(state) * 4, \
147 align, offset); \
148 __builtin_expect(_dst != NULL, 1); \
149 _blorp_cmd_pack(state)(batch, (void *)_dst, &name), \
150 blorp_flush_range(batch, _dst, _blorp_cmd_length(state) * 4), \
151 _dst = NULL)
152
153 /* 3DSTATE_URB
154 * 3DSTATE_URB_VS
155 * 3DSTATE_URB_HS
156 * 3DSTATE_URB_DS
157 * 3DSTATE_URB_GS
158 *
159 * Assign the entire URB to the VS. Even though the VS disabled, URB space
160 * is still needed because the clipper loads the VUE's from the URB. From
161 * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
162 * Dword 1.15:0 "VS Number of URB Entries":
163 * This field is always used (even if VS Function Enable is DISABLED).
164 *
165 * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
166 * safely ignore it because this batch contains only one draw call.
167 * Because of URB corruption caused by allocating a previous GS unit
168 * URB entry to the VS unit, software is required to send a “GS NULL
169 * Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
170 * plus a dummy DRAW call before any case where VS will be taking over
171 * GS URB space.
172 *
173 * If the 3DSTATE_URB_VS is emitted, than the others must be also.
174 * From the Ivybridge PRM, Volume 2 Part 1, section 1.7.1 3DSTATE_URB_VS:
175 *
176 * 3DSTATE_URB_HS, 3DSTATE_URB_DS, and 3DSTATE_URB_GS must also be
177 * programmed in order for the programming of this state to be
178 * valid.
179 */
180 static void
181 emit_urb_config(struct blorp_batch *batch,
182 const struct blorp_params *params)
183 {
184 /* Once vertex fetcher has written full VUE entries with complete
185 * header the space requirement is as follows per vertex (in bytes):
186 *
187 * Header Position Program constants
188 * +--------+------------+-------------------+
189 * | 16 | 16 | n x 16 |
190 * +--------+------------+-------------------+
191 *
192 * where 'n' stands for number of varying inputs expressed as vec4s.
193 */
194 const unsigned num_varyings =
195 params->wm_prog_data ? params->wm_prog_data->num_varying_inputs : 0;
196 const unsigned total_needed = 16 + 16 + num_varyings * 16;
197
198 /* The URB size is expressed in units of 64 bytes (512 bits) */
199 const unsigned vs_entry_size = DIV_ROUND_UP(total_needed, 64);
200
201 const unsigned sf_entry_size =
202 params->sf_prog_data ? params->sf_prog_data->urb_entry_size : 0;
203
204 blorp_emit_urb_config(batch, vs_entry_size, sf_entry_size);
205 }
206
207 #if GEN_GEN >= 7
208 static void
209 blorp_emit_memcpy(struct blorp_batch *batch,
210 struct blorp_address dst,
211 struct blorp_address src,
212 uint32_t size);
213 #endif
214
215 static void
216 blorp_emit_vertex_data(struct blorp_batch *batch,
217 const struct blorp_params *params,
218 struct blorp_address *addr,
219 uint32_t *size)
220 {
221 const float vertices[] = {
222 /* v0 */ (float)params->x1, (float)params->y1, params->z,
223 /* v1 */ (float)params->x0, (float)params->y1, params->z,
224 /* v2 */ (float)params->x0, (float)params->y0, params->z,
225 };
226
227 void *data = blorp_alloc_vertex_buffer(batch, sizeof(vertices), addr);
228 memcpy(data, vertices, sizeof(vertices));
229 *size = sizeof(vertices);
230 blorp_flush_range(batch, data, *size);
231 }
232
233 static void
234 blorp_emit_input_varying_data(struct blorp_batch *batch,
235 const struct blorp_params *params,
236 struct blorp_address *addr,
237 uint32_t *size)
238 {
239 const unsigned vec4_size_in_bytes = 4 * sizeof(float);
240 const unsigned max_num_varyings =
241 DIV_ROUND_UP(sizeof(params->wm_inputs), vec4_size_in_bytes);
242 const unsigned num_varyings =
243 params->wm_prog_data ? params->wm_prog_data->num_varying_inputs : 0;
244
245 *size = 16 + num_varyings * vec4_size_in_bytes;
246
247 const uint32_t *const inputs_src = (const uint32_t *)&params->wm_inputs;
248 void *data = blorp_alloc_vertex_buffer(batch, *size, addr);
249 uint32_t *inputs = data;
250
251 /* Copy in the VS inputs */
252 assert(sizeof(params->vs_inputs) == 16);
253 memcpy(inputs, &params->vs_inputs, sizeof(params->vs_inputs));
254 inputs += 4;
255
256 if (params->wm_prog_data) {
257 /* Walk over the attribute slots, determine if the attribute is used by
258 * the program and when necessary copy the values from the input storage
259 * to the vertex data buffer.
260 */
261 for (unsigned i = 0; i < max_num_varyings; i++) {
262 const gl_varying_slot attr = VARYING_SLOT_VAR0 + i;
263
264 const int input_index = params->wm_prog_data->urb_setup[attr];
265 if (input_index < 0)
266 continue;
267
268 memcpy(inputs, inputs_src + i * 4, vec4_size_in_bytes);
269
270 inputs += 4;
271 }
272 }
273
274 blorp_flush_range(batch, data, *size);
275
276 if (params->dst_clear_color_as_input) {
277 #if GEN_GEN >= 7
278 /* In this case, the clear color isn't known statically and instead
279 * comes in through an indirect which we have to copy into the vertex
280 * buffer before we execute the 3DPRIMITIVE. We already copied the
281 * value of params->wm_inputs.clear_color into the vertex buffer in the
282 * loop above. Now we emit code to stomp it from the GPU with the
283 * actual clear color value.
284 */
285 assert(num_varyings == 1);
286
287 /* The clear color is the first thing after the header */
288 struct blorp_address clear_color_input_addr = *addr;
289 clear_color_input_addr.offset += 16;
290
291 const unsigned clear_color_size =
292 GEN_GEN < 10 ? batch->blorp->isl_dev->ss.clear_value_size : 4 * 4;
293 blorp_emit_memcpy(batch, clear_color_input_addr,
294 params->dst.clear_color_addr,
295 clear_color_size);
296 #else
297 unreachable("MCS partial resolve is not a thing on SNB and earlier");
298 #endif
299 }
300 }
301
302 static void
303 blorp_fill_vertex_buffer_state(struct blorp_batch *batch,
304 struct GENX(VERTEX_BUFFER_STATE) *vb,
305 unsigned idx,
306 struct blorp_address addr, uint32_t size,
307 uint32_t stride)
308 {
309 vb[idx].VertexBufferIndex = idx;
310 vb[idx].BufferStartingAddress = addr;
311 vb[idx].BufferPitch = stride;
312
313 #if GEN_GEN >= 6
314 vb[idx].VertexBufferMOCS = addr.mocs;
315 #endif
316
317 #if GEN_GEN >= 7
318 vb[idx].AddressModifyEnable = true;
319 #endif
320
321 #if GEN_GEN >= 8
322 vb[idx].BufferSize = size;
323 #elif GEN_GEN >= 5
324 vb[idx].BufferAccessType = stride > 0 ? VERTEXDATA : INSTANCEDATA;
325 vb[idx].EndAddress = vb[idx].BufferStartingAddress;
326 vb[idx].EndAddress.offset += size - 1;
327 #elif GEN_GEN == 4
328 vb[idx].BufferAccessType = stride > 0 ? VERTEXDATA : INSTANCEDATA;
329 vb[idx].MaxIndex = stride > 0 ? size / stride : 0;
330 #endif
331 }
332
333 static void
334 blorp_emit_vertex_buffers(struct blorp_batch *batch,
335 const struct blorp_params *params)
336 {
337 struct GENX(VERTEX_BUFFER_STATE) vb[3];
338 uint32_t num_vbs = 2;
339 memset(vb, 0, sizeof(vb));
340
341 struct blorp_address addrs[2] = {};
342 uint32_t size;
343 blorp_emit_vertex_data(batch, params, &addrs[0], &size);
344 blorp_fill_vertex_buffer_state(batch, vb, 0, addrs[0], size,
345 3 * sizeof(float));
346
347 blorp_emit_input_varying_data(batch, params, &addrs[1], &size);
348 blorp_fill_vertex_buffer_state(batch, vb, 1, addrs[1], size, 0);
349
350 const unsigned num_dwords = 1 + num_vbs * GENX(VERTEX_BUFFER_STATE_length);
351 uint32_t *dw = blorp_emitn(batch, GENX(3DSTATE_VERTEX_BUFFERS), num_dwords);
352 if (!dw)
353 return;
354
355 blorp_vf_invalidate_for_vb_48b_transitions(batch, addrs, num_vbs);
356
357 for (unsigned i = 0; i < num_vbs; i++) {
358 GENX(VERTEX_BUFFER_STATE_pack)(batch, dw, &vb[i]);
359 dw += GENX(VERTEX_BUFFER_STATE_length);
360 }
361 }
362
363 static void
364 blorp_emit_vertex_elements(struct blorp_batch *batch,
365 const struct blorp_params *params)
366 {
367 const unsigned num_varyings =
368 params->wm_prog_data ? params->wm_prog_data->num_varying_inputs : 0;
369 bool need_ndc = batch->blorp->compiler->devinfo->gen <= 5;
370 const unsigned num_elements = 2 + need_ndc + num_varyings;
371
372 struct GENX(VERTEX_ELEMENT_STATE) ve[num_elements];
373 memset(ve, 0, num_elements * sizeof(*ve));
374
375 /* Setup VBO for the rectangle primitive..
376 *
377 * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
378 * vertices. The vertices reside in screen space with DirectX
379 * coordinates (that is, (0, 0) is the upper left corner).
380 *
381 * v2 ------ implied
382 * | |
383 * | |
384 * v1 ----- v0
385 *
386 * Since the VS is disabled, the clipper loads each VUE directly from
387 * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
388 * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
389 * dw0: Reserved, MBZ.
390 * dw1: Render Target Array Index. Below vertex fetcher gets programmed
391 * to assign this with primitive instance identifier which will be
392 * used for layered clears. All other renders have only one instance
393 * and therefore the value will be effectively zero.
394 * dw2: Viewport Index. The HiZ op disables viewport mapping and
395 * scissoring, so set the dword to 0.
396 * dw3: Point Width: The HiZ op does not emit the POINTLIST primitive,
397 * so set the dword to 0.
398 * dw4: Vertex Position X.
399 * dw5: Vertex Position Y.
400 * dw6: Vertex Position Z.
401 * dw7: Vertex Position W.
402 *
403 * dw8: Flat vertex input 0
404 * dw9: Flat vertex input 1
405 * ...
406 * dwn: Flat vertex input n - 8
407 *
408 * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
409 * "Vertex URB Entry (VUE) Formats".
410 *
411 * Only vertex position X and Y are going to be variable, Z is fixed to
412 * zero and W to one. Header words dw0,2,3 are zero. There is no need to
413 * include the fixed values in the vertex buffer. Vertex fetcher can be
414 * instructed to fill vertex elements with constant values of one and zero
415 * instead of reading them from the buffer.
416 * Flat inputs are program constants that are not interpolated. Moreover
417 * their values will be the same between vertices.
418 *
419 * See the vertex element setup below.
420 */
421 unsigned slot = 0;
422
423 ve[slot] = (struct GENX(VERTEX_ELEMENT_STATE)) {
424 .VertexBufferIndex = 1,
425 .Valid = true,
426 .SourceElementFormat = ISL_FORMAT_R32G32B32A32_FLOAT,
427 .SourceElementOffset = 0,
428 .Component0Control = VFCOMP_STORE_SRC,
429
430 /* From Gen8 onwards hardware is no more instructed to overwrite
431 * components using an element specifier. Instead one has separate
432 * 3DSTATE_VF_SGVS (System Generated Value Setup) state packet for it.
433 */
434 #if GEN_GEN >= 8
435 .Component1Control = VFCOMP_STORE_0,
436 #elif GEN_GEN >= 5
437 .Component1Control = VFCOMP_STORE_IID,
438 #else
439 .Component1Control = VFCOMP_STORE_0,
440 #endif
441 .Component2Control = VFCOMP_STORE_0,
442 .Component3Control = VFCOMP_STORE_0,
443 #if GEN_GEN <= 5
444 .DestinationElementOffset = slot * 4,
445 #endif
446 };
447 slot++;
448
449 #if GEN_GEN <= 5
450 /* On Iron Lake and earlier, a native device coordinates version of the
451 * position goes right after the normal VUE header and before position.
452 * Since w == 1 for all of our coordinates, this is just a copy of the
453 * position.
454 */
455 ve[slot] = (struct GENX(VERTEX_ELEMENT_STATE)) {
456 .VertexBufferIndex = 0,
457 .Valid = true,
458 .SourceElementFormat = ISL_FORMAT_R32G32B32_FLOAT,
459 .SourceElementOffset = 0,
460 .Component0Control = VFCOMP_STORE_SRC,
461 .Component1Control = VFCOMP_STORE_SRC,
462 .Component2Control = VFCOMP_STORE_SRC,
463 .Component3Control = VFCOMP_STORE_1_FP,
464 .DestinationElementOffset = slot * 4,
465 };
466 slot++;
467 #endif
468
469 ve[slot] = (struct GENX(VERTEX_ELEMENT_STATE)) {
470 .VertexBufferIndex = 0,
471 .Valid = true,
472 .SourceElementFormat = ISL_FORMAT_R32G32B32_FLOAT,
473 .SourceElementOffset = 0,
474 .Component0Control = VFCOMP_STORE_SRC,
475 .Component1Control = VFCOMP_STORE_SRC,
476 .Component2Control = VFCOMP_STORE_SRC,
477 .Component3Control = VFCOMP_STORE_1_FP,
478 #if GEN_GEN <= 5
479 .DestinationElementOffset = slot * 4,
480 #endif
481 };
482 slot++;
483
484 for (unsigned i = 0; i < num_varyings; ++i) {
485 ve[slot] = (struct GENX(VERTEX_ELEMENT_STATE)) {
486 .VertexBufferIndex = 1,
487 .Valid = true,
488 .SourceElementFormat = ISL_FORMAT_R32G32B32A32_FLOAT,
489 .SourceElementOffset = 16 + i * 4 * sizeof(float),
490 .Component0Control = VFCOMP_STORE_SRC,
491 .Component1Control = VFCOMP_STORE_SRC,
492 .Component2Control = VFCOMP_STORE_SRC,
493 .Component3Control = VFCOMP_STORE_SRC,
494 #if GEN_GEN <= 5
495 .DestinationElementOffset = slot * 4,
496 #endif
497 };
498 slot++;
499 }
500
501 const unsigned num_dwords =
502 1 + GENX(VERTEX_ELEMENT_STATE_length) * num_elements;
503 uint32_t *dw = blorp_emitn(batch, GENX(3DSTATE_VERTEX_ELEMENTS), num_dwords);
504 if (!dw)
505 return;
506
507 for (unsigned i = 0; i < num_elements; i++) {
508 GENX(VERTEX_ELEMENT_STATE_pack)(batch, dw, &ve[i]);
509 dw += GENX(VERTEX_ELEMENT_STATE_length);
510 }
511
512 #if GEN_GEN >= 8
513 /* Overwrite Render Target Array Index (2nd dword) in the VUE header with
514 * primitive instance identifier. This is used for layered clears.
515 */
516 blorp_emit(batch, GENX(3DSTATE_VF_SGVS), sgvs) {
517 sgvs.InstanceIDEnable = true;
518 sgvs.InstanceIDComponentNumber = COMP_1;
519 sgvs.InstanceIDElementOffset = 0;
520 }
521
522 for (unsigned i = 0; i < num_elements; i++) {
523 blorp_emit(batch, GENX(3DSTATE_VF_INSTANCING), vf) {
524 vf.VertexElementIndex = i;
525 vf.InstancingEnable = false;
526 }
527 }
528
529 blorp_emit(batch, GENX(3DSTATE_VF_TOPOLOGY), topo) {
530 topo.PrimitiveTopologyType = _3DPRIM_RECTLIST;
531 }
532 #endif
533 }
534
535 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
536 static uint32_t
537 blorp_emit_cc_viewport(struct blorp_batch *batch)
538 {
539 uint32_t cc_vp_offset;
540 blorp_emit_dynamic(batch, GENX(CC_VIEWPORT), vp, 32, &cc_vp_offset) {
541 vp.MinimumDepth = 0.0;
542 vp.MaximumDepth = 1.0;
543 }
544
545 #if GEN_GEN >= 7
546 blorp_emit(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC), vsp) {
547 vsp.CCViewportPointer = cc_vp_offset;
548 }
549 #elif GEN_GEN == 6
550 blorp_emit(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS), vsp) {
551 vsp.CCViewportStateChange = true;
552 vsp.PointertoCC_VIEWPORT = cc_vp_offset;
553 }
554 #endif
555
556 return cc_vp_offset;
557 }
558
559 static uint32_t
560 blorp_emit_sampler_state(struct blorp_batch *batch)
561 {
562 uint32_t offset;
563 blorp_emit_dynamic(batch, GENX(SAMPLER_STATE), sampler, 32, &offset) {
564 sampler.MipModeFilter = MIPFILTER_NONE;
565 sampler.MagModeFilter = MAPFILTER_LINEAR;
566 sampler.MinModeFilter = MAPFILTER_LINEAR;
567 sampler.MinLOD = 0;
568 sampler.MaxLOD = 0;
569 sampler.TCXAddressControlMode = TCM_CLAMP;
570 sampler.TCYAddressControlMode = TCM_CLAMP;
571 sampler.TCZAddressControlMode = TCM_CLAMP;
572 sampler.MaximumAnisotropy = RATIO21;
573 sampler.RAddressMinFilterRoundingEnable = true;
574 sampler.RAddressMagFilterRoundingEnable = true;
575 sampler.VAddressMinFilterRoundingEnable = true;
576 sampler.VAddressMagFilterRoundingEnable = true;
577 sampler.UAddressMinFilterRoundingEnable = true;
578 sampler.UAddressMagFilterRoundingEnable = true;
579 #if GEN_GEN > 6
580 sampler.NonnormalizedCoordinateEnable = true;
581 #endif
582 }
583
584 #if GEN_GEN >= 7
585 blorp_emit(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS_PS), ssp) {
586 ssp.PointertoPSSamplerState = offset;
587 }
588 #elif GEN_GEN == 6
589 blorp_emit(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS), ssp) {
590 ssp.VSSamplerStateChange = true;
591 ssp.GSSamplerStateChange = true;
592 ssp.PSSamplerStateChange = true;
593 ssp.PointertoPSSamplerState = offset;
594 }
595 #endif
596
597 return offset;
598 }
599
600 /* What follows is the code for setting up a "pipeline" on Sandy Bridge and
601 * later hardware. This file will be included by i965 for gen4-5 as well, so
602 * this code is guarded by GEN_GEN >= 6.
603 */
604 #if GEN_GEN >= 6
605
606 static void
607 blorp_emit_vs_config(struct blorp_batch *batch,
608 const struct blorp_params *params)
609 {
610 struct brw_vs_prog_data *vs_prog_data = params->vs_prog_data;
611 assert(!vs_prog_data || GEN_GEN < 11 ||
612 vs_prog_data->base.dispatch_mode == DISPATCH_MODE_SIMD8);
613
614 blorp_emit(batch, GENX(3DSTATE_VS), vs) {
615 if (vs_prog_data) {
616 vs.Enable = true;
617
618 vs.KernelStartPointer = params->vs_prog_kernel;
619
620 vs.DispatchGRFStartRegisterForURBData =
621 vs_prog_data->base.base.dispatch_grf_start_reg;
622 vs.VertexURBEntryReadLength =
623 vs_prog_data->base.urb_read_length;
624 vs.VertexURBEntryReadOffset = 0;
625
626 vs.MaximumNumberofThreads =
627 batch->blorp->isl_dev->info->max_vs_threads - 1;
628
629 #if GEN_GEN >= 8
630 vs.SIMD8DispatchEnable =
631 vs_prog_data->base.dispatch_mode == DISPATCH_MODE_SIMD8;
632 #endif
633 }
634 }
635 }
636
637 static void
638 blorp_emit_sf_config(struct blorp_batch *batch,
639 const struct blorp_params *params)
640 {
641 const struct brw_wm_prog_data *prog_data = params->wm_prog_data;
642
643 /* 3DSTATE_SF
644 *
645 * Disable ViewportTransformEnable (dw2.1)
646 *
647 * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
648 * Primitives Overview":
649 * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
650 * use of screen- space coordinates).
651 *
652 * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
653 * and BackFaceFillMode (dw2.5:6) to SOLID(0).
654 *
655 * From the Sandy Bridge PRM, Volume 2, Part 1, Section
656 * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
657 * SOLID: Any triangle or rectangle object found to be front-facing
658 * is rendered as a solid object. This setting is required when
659 * (rendering rectangle (RECTLIST) objects.
660 */
661
662 #if GEN_GEN >= 8
663
664 blorp_emit(batch, GENX(3DSTATE_SF), sf);
665
666 blorp_emit(batch, GENX(3DSTATE_RASTER), raster) {
667 raster.CullMode = CULLMODE_NONE;
668 }
669
670 blorp_emit(batch, GENX(3DSTATE_SBE), sbe) {
671 sbe.VertexURBEntryReadOffset = 1;
672 if (prog_data) {
673 sbe.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
674 sbe.VertexURBEntryReadLength = brw_blorp_get_urb_length(prog_data);
675 sbe.ConstantInterpolationEnable = prog_data->flat_inputs;
676 } else {
677 sbe.NumberofSFOutputAttributes = 0;
678 sbe.VertexURBEntryReadLength = 1;
679 }
680 sbe.ForceVertexURBEntryReadLength = true;
681 sbe.ForceVertexURBEntryReadOffset = true;
682
683 #if GEN_GEN >= 9
684 for (unsigned i = 0; i < 32; i++)
685 sbe.AttributeActiveComponentFormat[i] = ACF_XYZW;
686 #endif
687 }
688
689 #elif GEN_GEN >= 7
690
691 blorp_emit(batch, GENX(3DSTATE_SF), sf) {
692 sf.FrontFaceFillMode = FILL_MODE_SOLID;
693 sf.BackFaceFillMode = FILL_MODE_SOLID;
694
695 sf.MultisampleRasterizationMode = params->num_samples > 1 ?
696 MSRASTMODE_ON_PATTERN : MSRASTMODE_OFF_PIXEL;
697
698 #if GEN_GEN == 7
699 sf.DepthBufferSurfaceFormat = params->depth_format;
700 #endif
701 }
702
703 blorp_emit(batch, GENX(3DSTATE_SBE), sbe) {
704 sbe.VertexURBEntryReadOffset = 1;
705 if (prog_data) {
706 sbe.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
707 sbe.VertexURBEntryReadLength = brw_blorp_get_urb_length(prog_data);
708 sbe.ConstantInterpolationEnable = prog_data->flat_inputs;
709 } else {
710 sbe.NumberofSFOutputAttributes = 0;
711 sbe.VertexURBEntryReadLength = 1;
712 }
713 }
714
715 #else /* GEN_GEN <= 6 */
716
717 blorp_emit(batch, GENX(3DSTATE_SF), sf) {
718 sf.FrontFaceFillMode = FILL_MODE_SOLID;
719 sf.BackFaceFillMode = FILL_MODE_SOLID;
720
721 sf.MultisampleRasterizationMode = params->num_samples > 1 ?
722 MSRASTMODE_ON_PATTERN : MSRASTMODE_OFF_PIXEL;
723
724 sf.VertexURBEntryReadOffset = 1;
725 if (prog_data) {
726 sf.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
727 sf.VertexURBEntryReadLength = brw_blorp_get_urb_length(prog_data);
728 sf.ConstantInterpolationEnable = prog_data->flat_inputs;
729 } else {
730 sf.NumberofSFOutputAttributes = 0;
731 sf.VertexURBEntryReadLength = 1;
732 }
733 }
734
735 #endif /* GEN_GEN */
736 }
737
738 static void
739 blorp_emit_ps_config(struct blorp_batch *batch,
740 const struct blorp_params *params)
741 {
742 const struct brw_wm_prog_data *prog_data = params->wm_prog_data;
743
744 /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
745 * nonzero to prevent the GPU from hanging. While the documentation doesn't
746 * mention this explicitly, it notes that the valid range for the field is
747 * [1,39] = [2,40] threads, which excludes zero.
748 *
749 * To be safe (and to minimize extraneous code) we go ahead and fully
750 * configure the WM state whether or not there is a WM program.
751 */
752
753 #if GEN_GEN >= 8
754
755 blorp_emit(batch, GENX(3DSTATE_WM), wm);
756
757 blorp_emit(batch, GENX(3DSTATE_PS), ps) {
758 if (params->src.enabled) {
759 ps.SamplerCount = 1; /* Up to 4 samplers */
760 ps.BindingTableEntryCount = 2;
761 } else {
762 ps.BindingTableEntryCount = 1;
763 }
764
765 if (prog_data) {
766 ps._8PixelDispatchEnable = prog_data->dispatch_8;
767 ps._16PixelDispatchEnable = prog_data->dispatch_16;
768
769 ps.DispatchGRFStartRegisterForConstantSetupData0 =
770 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 0);
771 ps.DispatchGRFStartRegisterForConstantSetupData1 =
772 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 1);
773 ps.DispatchGRFStartRegisterForConstantSetupData2 =
774 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 2);
775
776 ps.KernelStartPointer0 = params->wm_prog_kernel +
777 brw_wm_prog_data_prog_offset(prog_data, ps, 0);
778 ps.KernelStartPointer1 = params->wm_prog_kernel +
779 brw_wm_prog_data_prog_offset(prog_data, ps, 1);
780 ps.KernelStartPointer2 = params->wm_prog_kernel +
781 brw_wm_prog_data_prog_offset(prog_data, ps, 2);
782 }
783
784 /* 3DSTATE_PS expects the number of threads per PSD, which is always 64
785 * for pre Gen11 and 128 for gen11+; On gen11+ If a programmed value is
786 * k, it implies 2(k+1) threads. It implicitly scales for different GT
787 * levels (which have some # of PSDs).
788 *
789 * In Gen8 the format is U8-2 whereas in Gen9+ it is U9-1.
790 */
791 if (GEN_GEN >= 9)
792 ps.MaximumNumberofThreadsPerPSD = 64 - 1;
793 else
794 ps.MaximumNumberofThreadsPerPSD = 64 - 2;
795
796 switch (params->fast_clear_op) {
797 case ISL_AUX_OP_NONE:
798 break;
799 #if GEN_GEN >= 9
800 case ISL_AUX_OP_PARTIAL_RESOLVE:
801 ps.RenderTargetResolveType = RESOLVE_PARTIAL;
802 break;
803 case ISL_AUX_OP_FULL_RESOLVE:
804 ps.RenderTargetResolveType = RESOLVE_FULL;
805 break;
806 #else
807 case ISL_AUX_OP_FULL_RESOLVE:
808 ps.RenderTargetResolveEnable = true;
809 break;
810 #endif
811 case ISL_AUX_OP_FAST_CLEAR:
812 ps.RenderTargetFastClearEnable = true;
813 break;
814 default:
815 unreachable("Invalid fast clear op");
816 }
817 }
818
819 blorp_emit(batch, GENX(3DSTATE_PS_EXTRA), psx) {
820 if (prog_data) {
821 psx.PixelShaderValid = true;
822 psx.AttributeEnable = prog_data->num_varying_inputs > 0;
823 psx.PixelShaderIsPerSample = prog_data->persample_dispatch;
824 }
825
826 if (params->src.enabled)
827 psx.PixelShaderKillsPixel = true;
828 }
829
830 #elif GEN_GEN >= 7
831
832 blorp_emit(batch, GENX(3DSTATE_WM), wm) {
833 switch (params->hiz_op) {
834 case ISL_AUX_OP_FAST_CLEAR:
835 wm.DepthBufferClear = true;
836 break;
837 case ISL_AUX_OP_FULL_RESOLVE:
838 wm.DepthBufferResolveEnable = true;
839 break;
840 case ISL_AUX_OP_AMBIGUATE:
841 wm.HierarchicalDepthBufferResolveEnable = true;
842 break;
843 case ISL_AUX_OP_NONE:
844 break;
845 default:
846 unreachable("not reached");
847 }
848
849 if (prog_data)
850 wm.ThreadDispatchEnable = true;
851
852 if (params->src.enabled)
853 wm.PixelShaderKillsPixel = true;
854
855 if (params->num_samples > 1) {
856 wm.MultisampleRasterizationMode = MSRASTMODE_ON_PATTERN;
857 wm.MultisampleDispatchMode =
858 (prog_data && prog_data->persample_dispatch) ?
859 MSDISPMODE_PERSAMPLE : MSDISPMODE_PERPIXEL;
860 } else {
861 wm.MultisampleRasterizationMode = MSRASTMODE_OFF_PIXEL;
862 wm.MultisampleDispatchMode = MSDISPMODE_PERSAMPLE;
863 }
864 }
865
866 blorp_emit(batch, GENX(3DSTATE_PS), ps) {
867 ps.MaximumNumberofThreads =
868 batch->blorp->isl_dev->info->max_wm_threads - 1;
869
870 #if GEN_IS_HASWELL
871 ps.SampleMask = 1;
872 #endif
873
874 if (prog_data) {
875 ps._8PixelDispatchEnable = prog_data->dispatch_8;
876 ps._16PixelDispatchEnable = prog_data->dispatch_16;
877
878 ps.DispatchGRFStartRegisterForConstantSetupData0 =
879 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 0);
880 ps.DispatchGRFStartRegisterForConstantSetupData1 =
881 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 1);
882 ps.DispatchGRFStartRegisterForConstantSetupData2 =
883 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 2);
884
885 ps.KernelStartPointer0 = params->wm_prog_kernel +
886 brw_wm_prog_data_prog_offset(prog_data, ps, 0);
887 ps.KernelStartPointer1 = params->wm_prog_kernel +
888 brw_wm_prog_data_prog_offset(prog_data, ps, 1);
889 ps.KernelStartPointer2 = params->wm_prog_kernel +
890 brw_wm_prog_data_prog_offset(prog_data, ps, 2);
891
892 ps.AttributeEnable = prog_data->num_varying_inputs > 0;
893 } else {
894 /* Gen7 hardware gets angry if we don't enable at least one dispatch
895 * mode, so just enable 16-pixel dispatch if we don't have a program.
896 */
897 ps._16PixelDispatchEnable = true;
898 }
899
900 if (params->src.enabled)
901 ps.SamplerCount = 1; /* Up to 4 samplers */
902
903 switch (params->fast_clear_op) {
904 case ISL_AUX_OP_NONE:
905 break;
906 case ISL_AUX_OP_FULL_RESOLVE:
907 ps.RenderTargetResolveEnable = true;
908 break;
909 case ISL_AUX_OP_FAST_CLEAR:
910 ps.RenderTargetFastClearEnable = true;
911 break;
912 default:
913 unreachable("Invalid fast clear op");
914 }
915 }
916
917 #else /* GEN_GEN <= 6 */
918
919 blorp_emit(batch, GENX(3DSTATE_WM), wm) {
920 wm.MaximumNumberofThreads =
921 batch->blorp->isl_dev->info->max_wm_threads - 1;
922
923 switch (params->hiz_op) {
924 case ISL_AUX_OP_FAST_CLEAR:
925 wm.DepthBufferClear = true;
926 break;
927 case ISL_AUX_OP_FULL_RESOLVE:
928 wm.DepthBufferResolveEnable = true;
929 break;
930 case ISL_AUX_OP_AMBIGUATE:
931 wm.HierarchicalDepthBufferResolveEnable = true;
932 break;
933 case ISL_AUX_OP_NONE:
934 break;
935 default:
936 unreachable("not reached");
937 }
938
939 if (prog_data) {
940 wm.ThreadDispatchEnable = true;
941
942 wm._8PixelDispatchEnable = prog_data->dispatch_8;
943 wm._16PixelDispatchEnable = prog_data->dispatch_16;
944
945 wm.DispatchGRFStartRegisterForConstantSetupData0 =
946 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, wm, 0);
947 wm.DispatchGRFStartRegisterForConstantSetupData1 =
948 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, wm, 1);
949 wm.DispatchGRFStartRegisterForConstantSetupData2 =
950 brw_wm_prog_data_dispatch_grf_start_reg(prog_data, wm, 2);
951
952 wm.KernelStartPointer0 = params->wm_prog_kernel +
953 brw_wm_prog_data_prog_offset(prog_data, wm, 0);
954 wm.KernelStartPointer1 = params->wm_prog_kernel +
955 brw_wm_prog_data_prog_offset(prog_data, wm, 1);
956 wm.KernelStartPointer2 = params->wm_prog_kernel +
957 brw_wm_prog_data_prog_offset(prog_data, wm, 2);
958
959 wm.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
960 }
961
962 if (params->src.enabled) {
963 wm.SamplerCount = 1; /* Up to 4 samplers */
964 wm.PixelShaderKillsPixel = true; /* TODO: temporarily smash on */
965 }
966
967 if (params->num_samples > 1) {
968 wm.MultisampleRasterizationMode = MSRASTMODE_ON_PATTERN;
969 wm.MultisampleDispatchMode =
970 (prog_data && prog_data->persample_dispatch) ?
971 MSDISPMODE_PERSAMPLE : MSDISPMODE_PERPIXEL;
972 } else {
973 wm.MultisampleRasterizationMode = MSRASTMODE_OFF_PIXEL;
974 wm.MultisampleDispatchMode = MSDISPMODE_PERSAMPLE;
975 }
976 }
977
978 #endif /* GEN_GEN */
979 }
980
981 static uint32_t
982 blorp_emit_blend_state(struct blorp_batch *batch,
983 const struct blorp_params *params)
984 {
985 struct GENX(BLEND_STATE) blend;
986 memset(&blend, 0, sizeof(blend));
987
988 uint32_t offset;
989 int size = GENX(BLEND_STATE_length) * 4;
990 size += GENX(BLEND_STATE_ENTRY_length) * 4 * params->num_draw_buffers;
991 uint32_t *state = blorp_alloc_dynamic_state(batch, size, 64, &offset);
992 uint32_t *pos = state;
993
994 GENX(BLEND_STATE_pack)(NULL, pos, &blend);
995 pos += GENX(BLEND_STATE_length);
996
997 for (unsigned i = 0; i < params->num_draw_buffers; ++i) {
998 struct GENX(BLEND_STATE_ENTRY) entry = {
999 .PreBlendColorClampEnable = true,
1000 .PostBlendColorClampEnable = true,
1001 .ColorClampRange = COLORCLAMP_RTFORMAT,
1002
1003 .WriteDisableRed = params->color_write_disable[0],
1004 .WriteDisableGreen = params->color_write_disable[1],
1005 .WriteDisableBlue = params->color_write_disable[2],
1006 .WriteDisableAlpha = params->color_write_disable[3],
1007 };
1008 GENX(BLEND_STATE_ENTRY_pack)(NULL, pos, &entry);
1009 pos += GENX(BLEND_STATE_ENTRY_length);
1010 }
1011
1012 blorp_flush_range(batch, state, size);
1013
1014 #if GEN_GEN >= 7
1015 blorp_emit(batch, GENX(3DSTATE_BLEND_STATE_POINTERS), sp) {
1016 sp.BlendStatePointer = offset;
1017 #if GEN_GEN >= 8
1018 sp.BlendStatePointerValid = true;
1019 #endif
1020 }
1021 #endif
1022
1023 #if GEN_GEN >= 8
1024 blorp_emit(batch, GENX(3DSTATE_PS_BLEND), ps_blend) {
1025 ps_blend.HasWriteableRT = true;
1026 }
1027 #endif
1028
1029 return offset;
1030 }
1031
1032 static uint32_t
1033 blorp_emit_color_calc_state(struct blorp_batch *batch,
1034 MAYBE_UNUSED const struct blorp_params *params)
1035 {
1036 uint32_t offset;
1037 blorp_emit_dynamic(batch, GENX(COLOR_CALC_STATE), cc, 64, &offset) {
1038 #if GEN_GEN <= 8
1039 cc.StencilReferenceValue = params->stencil_ref;
1040 #endif
1041 }
1042
1043 #if GEN_GEN >= 7
1044 blorp_emit(batch, GENX(3DSTATE_CC_STATE_POINTERS), sp) {
1045 sp.ColorCalcStatePointer = offset;
1046 #if GEN_GEN >= 8
1047 sp.ColorCalcStatePointerValid = true;
1048 #endif
1049 }
1050 #endif
1051
1052 return offset;
1053 }
1054
1055 static uint32_t
1056 blorp_emit_depth_stencil_state(struct blorp_batch *batch,
1057 const struct blorp_params *params)
1058 {
1059 #if GEN_GEN >= 8
1060 struct GENX(3DSTATE_WM_DEPTH_STENCIL) ds = {
1061 GENX(3DSTATE_WM_DEPTH_STENCIL_header),
1062 };
1063 #else
1064 struct GENX(DEPTH_STENCIL_STATE) ds = { 0 };
1065 #endif
1066
1067 if (params->depth.enabled) {
1068 ds.DepthBufferWriteEnable = true;
1069
1070 switch (params->hiz_op) {
1071 case ISL_AUX_OP_NONE:
1072 ds.DepthTestEnable = true;
1073 ds.DepthTestFunction = COMPAREFUNCTION_ALWAYS;
1074 break;
1075
1076 /* See the following sections of the Sandy Bridge PRM, Volume 2, Part1:
1077 * - 7.5.3.1 Depth Buffer Clear
1078 * - 7.5.3.2 Depth Buffer Resolve
1079 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
1080 */
1081 case ISL_AUX_OP_FULL_RESOLVE:
1082 ds.DepthTestEnable = true;
1083 ds.DepthTestFunction = COMPAREFUNCTION_NEVER;
1084 break;
1085
1086 case ISL_AUX_OP_FAST_CLEAR:
1087 case ISL_AUX_OP_AMBIGUATE:
1088 ds.DepthTestEnable = false;
1089 break;
1090 case ISL_AUX_OP_PARTIAL_RESOLVE:
1091 unreachable("Invalid HIZ op");
1092 }
1093 }
1094
1095 if (params->stencil.enabled) {
1096 ds.StencilBufferWriteEnable = true;
1097 ds.StencilTestEnable = true;
1098 ds.DoubleSidedStencilEnable = false;
1099
1100 ds.StencilTestFunction = COMPAREFUNCTION_ALWAYS;
1101 ds.StencilPassDepthPassOp = STENCILOP_REPLACE;
1102
1103 ds.StencilWriteMask = params->stencil_mask;
1104 #if GEN_GEN >= 9
1105 ds.StencilReferenceValue = params->stencil_ref;
1106 #endif
1107 }
1108
1109 #if GEN_GEN >= 8
1110 uint32_t offset = 0;
1111 uint32_t *dw = blorp_emit_dwords(batch,
1112 GENX(3DSTATE_WM_DEPTH_STENCIL_length));
1113 if (!dw)
1114 return 0;
1115
1116 GENX(3DSTATE_WM_DEPTH_STENCIL_pack)(NULL, dw, &ds);
1117 #else
1118 uint32_t offset;
1119 void *state = blorp_alloc_dynamic_state(batch,
1120 GENX(DEPTH_STENCIL_STATE_length) * 4,
1121 64, &offset);
1122 GENX(DEPTH_STENCIL_STATE_pack)(NULL, state, &ds);
1123 blorp_flush_range(batch, state, GENX(DEPTH_STENCIL_STATE_length) * 4);
1124 #endif
1125
1126 #if GEN_GEN == 7
1127 blorp_emit(batch, GENX(3DSTATE_DEPTH_STENCIL_STATE_POINTERS), sp) {
1128 sp.PointertoDEPTH_STENCIL_STATE = offset;
1129 }
1130 #endif
1131
1132 return offset;
1133 }
1134
1135 static void
1136 blorp_emit_3dstate_multisample(struct blorp_batch *batch,
1137 const struct blorp_params *params)
1138 {
1139 blorp_emit(batch, GENX(3DSTATE_MULTISAMPLE), ms) {
1140 ms.NumberofMultisamples = __builtin_ffs(params->num_samples) - 1;
1141
1142 #if GEN_GEN >= 8
1143 /* The PRM says that this bit is valid only for DX9:
1144 *
1145 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
1146 * should not have any effect by setting or not setting this bit.
1147 */
1148 ms.PixelPositionOffsetEnable = false;
1149 #elif GEN_GEN >= 7
1150
1151 switch (params->num_samples) {
1152 case 1:
1153 GEN_SAMPLE_POS_1X(ms.Sample);
1154 break;
1155 case 2:
1156 GEN_SAMPLE_POS_2X(ms.Sample);
1157 break;
1158 case 4:
1159 GEN_SAMPLE_POS_4X(ms.Sample);
1160 break;
1161 case 8:
1162 GEN_SAMPLE_POS_8X(ms.Sample);
1163 break;
1164 default:
1165 break;
1166 }
1167 #else
1168 GEN_SAMPLE_POS_4X(ms.Sample);
1169 #endif
1170 ms.PixelLocation = CENTER;
1171 }
1172 }
1173
1174 static void
1175 blorp_emit_pipeline(struct blorp_batch *batch,
1176 const struct blorp_params *params)
1177 {
1178 uint32_t blend_state_offset = 0;
1179 uint32_t color_calc_state_offset;
1180 uint32_t depth_stencil_state_offset;
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 }
1187 color_calc_state_offset = blorp_emit_color_calc_state(batch, params);
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.ColorCalcStatePointerValid = true;
1205 cc.DEPTH_STENCIL_STATEChange = true;
1206 cc.PointertoBLEND_STATE = blend_state_offset;
1207 cc.ColorCalcStatePointer = 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->src.enabled)
1225 blorp_emit_sampler_state(batch);
1226
1227 blorp_emit_3dstate_multisample(batch, params);
1228
1229 blorp_emit(batch, GENX(3DSTATE_SAMPLE_MASK), mask) {
1230 mask.SampleMask = (1 << params->num_samples) - 1;
1231 }
1232
1233 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
1234 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
1235 *
1236 * [DevSNB] A pipeline flush must be programmed prior to a
1237 * 3DSTATE_VS command that causes the VS Function Enable to
1238 * toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
1239 * command with CS stall bit set and a post sync operation.
1240 *
1241 * We've already done one at the start of the BLORP operation.
1242 */
1243 blorp_emit_vs_config(batch, params);
1244 #if GEN_GEN >= 7
1245 blorp_emit(batch, GENX(3DSTATE_HS), hs);
1246 blorp_emit(batch, GENX(3DSTATE_TE), te);
1247 blorp_emit(batch, GENX(3DSTATE_DS), DS);
1248 blorp_emit(batch, GENX(3DSTATE_STREAMOUT), so);
1249 #endif
1250 blorp_emit(batch, GENX(3DSTATE_GS), gs);
1251
1252 blorp_emit(batch, GENX(3DSTATE_CLIP), clip) {
1253 clip.PerspectiveDivideDisable = true;
1254 }
1255
1256 blorp_emit_sf_config(batch, params);
1257 blorp_emit_ps_config(batch, params);
1258
1259 blorp_emit_cc_viewport(batch);
1260 }
1261
1262 /******** This is the end of the pipeline setup code ********/
1263
1264 #endif /* GEN_GEN >= 6 */
1265
1266 #if GEN_GEN >= 7
1267 static void
1268 blorp_emit_memcpy(struct blorp_batch *batch,
1269 struct blorp_address dst,
1270 struct blorp_address src,
1271 uint32_t size)
1272 {
1273 assert(size % 4 == 0);
1274
1275 for (unsigned dw = 0; dw < size; dw += 4) {
1276 #if GEN_GEN >= 8
1277 blorp_emit(batch, GENX(MI_COPY_MEM_MEM), cp) {
1278 cp.DestinationMemoryAddress = dst;
1279 cp.SourceMemoryAddress = src;
1280 }
1281 #else
1282 /* IVB does not have a general purpose register for command streamer
1283 * commands. Therefore, we use an alternate temporary register.
1284 */
1285 #define BLORP_TEMP_REG 0x2440 /* GEN7_3DPRIM_BASE_VERTEX */
1286 blorp_emit(batch, GENX(MI_LOAD_REGISTER_MEM), load) {
1287 load.RegisterAddress = BLORP_TEMP_REG;
1288 load.MemoryAddress = src;
1289 }
1290 blorp_emit(batch, GENX(MI_STORE_REGISTER_MEM), store) {
1291 store.RegisterAddress = BLORP_TEMP_REG;
1292 store.MemoryAddress = dst;
1293 }
1294 #undef BLORP_TEMP_REG
1295 #endif
1296 dst.offset += 4;
1297 src.offset += 4;
1298 }
1299 }
1300 #endif
1301
1302 static void
1303 blorp_emit_surface_state(struct blorp_batch *batch,
1304 const struct brw_blorp_surface_info *surface,
1305 enum isl_aux_op op,
1306 void *state, uint32_t state_offset,
1307 const bool color_write_disables[4],
1308 bool is_render_target)
1309 {
1310 const struct isl_device *isl_dev = batch->blorp->isl_dev;
1311 struct isl_surf surf = surface->surf;
1312
1313 if (surf.dim == ISL_SURF_DIM_1D &&
1314 surf.dim_layout == ISL_DIM_LAYOUT_GEN4_2D) {
1315 assert(surf.logical_level0_px.height == 1);
1316 surf.dim = ISL_SURF_DIM_2D;
1317 }
1318
1319 /* Blorp doesn't support HiZ in any of the blit or slow-clear paths */
1320 enum isl_aux_usage aux_usage = surface->aux_usage;
1321 if (aux_usage == ISL_AUX_USAGE_HIZ)
1322 aux_usage = ISL_AUX_USAGE_NONE;
1323
1324 isl_channel_mask_t write_disable_mask = 0;
1325 if (is_render_target && GEN_GEN <= 5) {
1326 if (color_write_disables[0])
1327 write_disable_mask |= ISL_CHANNEL_RED_BIT;
1328 if (color_write_disables[1])
1329 write_disable_mask |= ISL_CHANNEL_GREEN_BIT;
1330 if (color_write_disables[2])
1331 write_disable_mask |= ISL_CHANNEL_BLUE_BIT;
1332 if (color_write_disables[3])
1333 write_disable_mask |= ISL_CHANNEL_ALPHA_BIT;
1334 }
1335
1336 const bool use_clear_address =
1337 GEN_GEN >= 10 && (surface->clear_color_addr.buffer != NULL);
1338
1339 isl_surf_fill_state(batch->blorp->isl_dev, state,
1340 .surf = &surf, .view = &surface->view,
1341 .aux_surf = &surface->aux_surf, .aux_usage = aux_usage,
1342 .mocs = surface->addr.mocs,
1343 .clear_color = surface->clear_color,
1344 .use_clear_address = use_clear_address,
1345 .write_disables = write_disable_mask);
1346
1347 blorp_surface_reloc(batch, state_offset + isl_dev->ss.addr_offset,
1348 surface->addr, 0);
1349
1350 if (aux_usage != ISL_AUX_USAGE_NONE) {
1351 /* On gen7 and prior, the bottom 12 bits of the MCS base address are
1352 * used to store other information. This should be ok, however, because
1353 * surface buffer addresses are always 4K page alinged.
1354 */
1355 assert((surface->aux_addr.offset & 0xfff) == 0);
1356 uint32_t *aux_addr = state + isl_dev->ss.aux_addr_offset;
1357 blorp_surface_reloc(batch, state_offset + isl_dev->ss.aux_addr_offset,
1358 surface->aux_addr, *aux_addr);
1359 }
1360
1361 if (surface->clear_color_addr.buffer) {
1362 #if GEN_GEN >= 10
1363 assert((surface->clear_color_addr.offset & 0x3f) == 0);
1364 uint32_t *clear_addr = state + isl_dev->ss.clear_color_state_offset;
1365 blorp_surface_reloc(batch, state_offset +
1366 isl_dev->ss.clear_color_state_offset,
1367 surface->clear_color_addr, *clear_addr);
1368 #elif GEN_GEN >= 7
1369 if (op == ISL_AUX_OP_FULL_RESOLVE || op == ISL_AUX_OP_PARTIAL_RESOLVE) {
1370 struct blorp_address dst_addr = blorp_get_surface_base_address(batch);
1371 dst_addr.offset += state_offset + isl_dev->ss.clear_value_offset;
1372 blorp_emit_memcpy(batch, dst_addr, surface->clear_color_addr,
1373 isl_dev->ss.clear_value_size);
1374 }
1375 #else
1376 unreachable("Fast clears are only supported on gen7+");
1377 #endif
1378 }
1379
1380 blorp_flush_range(batch, state, GENX(RENDER_SURFACE_STATE_length) * 4);
1381 }
1382
1383 static void
1384 blorp_emit_null_surface_state(struct blorp_batch *batch,
1385 const struct brw_blorp_surface_info *surface,
1386 uint32_t *state)
1387 {
1388 struct GENX(RENDER_SURFACE_STATE) ss = {
1389 .SurfaceType = SURFTYPE_NULL,
1390 .SurfaceFormat = ISL_FORMAT_R8G8B8A8_UNORM,
1391 .Width = surface->surf.logical_level0_px.width - 1,
1392 .Height = surface->surf.logical_level0_px.height - 1,
1393 .MIPCountLOD = surface->view.base_level,
1394 .MinimumArrayElement = surface->view.base_array_layer,
1395 .Depth = surface->view.array_len - 1,
1396 .RenderTargetViewExtent = surface->view.array_len - 1,
1397 #if GEN_GEN >= 6
1398 .NumberofMultisamples = ffs(surface->surf.samples) - 1,
1399 #endif
1400
1401 #if GEN_GEN >= 7
1402 .SurfaceArray = surface->surf.dim != ISL_SURF_DIM_3D,
1403 #endif
1404
1405 #if GEN_GEN >= 8
1406 .TileMode = YMAJOR,
1407 #else
1408 .TiledSurface = true,
1409 #endif
1410 };
1411
1412 GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &ss);
1413
1414 blorp_flush_range(batch, state, GENX(RENDER_SURFACE_STATE_length) * 4);
1415 }
1416
1417 static void
1418 blorp_emit_surface_states(struct blorp_batch *batch,
1419 const struct blorp_params *params)
1420 {
1421 const struct isl_device *isl_dev = batch->blorp->isl_dev;
1422 uint32_t bind_offset = 0, surface_offsets[2];
1423 void *surface_maps[2];
1424
1425 MAYBE_UNUSED bool has_indirect_clear_color = false;
1426 if (params->use_pre_baked_binding_table) {
1427 bind_offset = params->pre_baked_binding_table_offset;
1428 } else {
1429 unsigned num_surfaces = 1 + params->src.enabled;
1430 blorp_alloc_binding_table(batch, num_surfaces,
1431 isl_dev->ss.size, isl_dev->ss.align,
1432 &bind_offset, surface_offsets, surface_maps);
1433
1434 if (params->dst.enabled) {
1435 blorp_emit_surface_state(batch, &params->dst,
1436 params->fast_clear_op,
1437 surface_maps[BLORP_RENDERBUFFER_BT_INDEX],
1438 surface_offsets[BLORP_RENDERBUFFER_BT_INDEX],
1439 params->color_write_disable, true);
1440 if (params->dst.clear_color_addr.buffer != NULL)
1441 has_indirect_clear_color = true;
1442 } else {
1443 assert(params->depth.enabled || params->stencil.enabled);
1444 const struct brw_blorp_surface_info *surface =
1445 params->depth.enabled ? &params->depth : &params->stencil;
1446 blorp_emit_null_surface_state(batch, surface,
1447 surface_maps[BLORP_RENDERBUFFER_BT_INDEX]);
1448 }
1449
1450 if (params->src.enabled) {
1451 blorp_emit_surface_state(batch, &params->src,
1452 params->fast_clear_op,
1453 surface_maps[BLORP_TEXTURE_BT_INDEX],
1454 surface_offsets[BLORP_TEXTURE_BT_INDEX],
1455 NULL, false);
1456 if (params->src.clear_color_addr.buffer != NULL)
1457 has_indirect_clear_color = true;
1458 }
1459 }
1460
1461 #if GEN_GEN >= 7
1462 if (has_indirect_clear_color) {
1463 /* Updating a surface state object may require that the state cache be
1464 * invalidated. From the SKL PRM, Shared Functions -> State -> State
1465 * Caching:
1466 *
1467 * Whenever the RENDER_SURFACE_STATE object in memory pointed to by
1468 * the Binding Table Pointer (BTP) and Binding Table Index (BTI) is
1469 * modified [...], the L1 state cache must be invalidated to ensure
1470 * the new surface or sampler state is fetched from system memory.
1471 */
1472 blorp_emit(batch, GENX(PIPE_CONTROL), pipe) {
1473 pipe.StateCacheInvalidationEnable = true;
1474 }
1475 }
1476 #endif
1477
1478 #if GEN_GEN >= 7
1479 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS), bt);
1480 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_HS), bt);
1481 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_DS), bt);
1482 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_GS), bt);
1483
1484 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_PS), bt) {
1485 bt.PointertoPSBindingTable = bind_offset;
1486 }
1487 #elif GEN_GEN >= 6
1488 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS), bt) {
1489 bt.PSBindingTableChange = true;
1490 bt.PointertoPSBindingTable = bind_offset;
1491 }
1492 #else
1493 blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS), bt) {
1494 bt.PointertoPSBindingTable = bind_offset;
1495 }
1496 #endif
1497 }
1498
1499 static void
1500 blorp_emit_depth_stencil_config(struct blorp_batch *batch,
1501 const struct blorp_params *params)
1502 {
1503 const struct isl_device *isl_dev = batch->blorp->isl_dev;
1504
1505 uint32_t *dw = blorp_emit_dwords(batch, isl_dev->ds.size / 4);
1506 if (dw == NULL)
1507 return;
1508
1509 struct isl_depth_stencil_hiz_emit_info info = { };
1510
1511 if (params->depth.enabled) {
1512 info.view = &params->depth.view;
1513 info.mocs = params->depth.addr.mocs;
1514 } else if (params->stencil.enabled) {
1515 info.view = &params->stencil.view;
1516 info.mocs = params->stencil.addr.mocs;
1517 }
1518
1519 if (params->depth.enabled) {
1520 info.depth_surf = &params->depth.surf;
1521
1522 info.depth_address =
1523 blorp_emit_reloc(batch, dw + isl_dev->ds.depth_offset / 4,
1524 params->depth.addr, 0);
1525
1526 info.hiz_usage = params->depth.aux_usage;
1527 if (info.hiz_usage == ISL_AUX_USAGE_HIZ) {
1528 info.hiz_surf = &params->depth.aux_surf;
1529
1530 struct blorp_address hiz_address = params->depth.aux_addr;
1531 #if GEN_GEN == 6
1532 /* Sandy bridge hardware does not technically support mipmapped HiZ.
1533 * However, we have a special layout that allows us to make it work
1534 * anyway by manually offsetting to the specified miplevel.
1535 */
1536 assert(info.hiz_surf->dim_layout == ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ);
1537 uint32_t offset_B;
1538 isl_surf_get_image_offset_B_tile_sa(info.hiz_surf,
1539 info.view->base_level, 0, 0,
1540 &offset_B, NULL, NULL);
1541 hiz_address.offset += offset_B;
1542 #endif
1543
1544 info.hiz_address =
1545 blorp_emit_reloc(batch, dw + isl_dev->ds.hiz_offset / 4,
1546 hiz_address, 0);
1547
1548 info.depth_clear_value = params->depth.clear_color.f32[0];
1549 }
1550 }
1551
1552 if (params->stencil.enabled) {
1553 info.stencil_surf = &params->stencil.surf;
1554
1555 struct blorp_address stencil_address = params->stencil.addr;
1556 #if GEN_GEN == 6
1557 /* Sandy bridge hardware does not technically support mipmapped stencil.
1558 * However, we have a special layout that allows us to make it work
1559 * anyway by manually offsetting to the specified miplevel.
1560 */
1561 assert(info.stencil_surf->dim_layout == ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ);
1562 uint32_t offset_B;
1563 isl_surf_get_image_offset_B_tile_sa(info.stencil_surf,
1564 info.view->base_level, 0, 0,
1565 &offset_B, NULL, NULL);
1566 stencil_address.offset += offset_B;
1567 #endif
1568
1569 info.stencil_address =
1570 blorp_emit_reloc(batch, dw + isl_dev->ds.stencil_offset / 4,
1571 stencil_address, 0);
1572 }
1573
1574 isl_emit_depth_stencil_hiz_s(isl_dev, dw, &info);
1575 }
1576
1577 #if GEN_GEN >= 8
1578 /* Emits the Optimized HiZ sequence specified in the BDW+ PRMs. The
1579 * depth/stencil buffer extents are ignored to handle APIs which perform
1580 * clearing operations without such information.
1581 * */
1582 static void
1583 blorp_emit_gen8_hiz_op(struct blorp_batch *batch,
1584 const struct blorp_params *params)
1585 {
1586 /* We should be performing an operation on a depth or stencil buffer.
1587 */
1588 assert(params->depth.enabled || params->stencil.enabled);
1589
1590 /* The stencil buffer should only be enabled if a fast clear operation is
1591 * requested.
1592 */
1593 if (params->stencil.enabled)
1594 assert(params->hiz_op == ISL_AUX_OP_FAST_CLEAR);
1595
1596 /* From the BDW PRM Volume 2, 3DSTATE_WM_HZ_OP:
1597 *
1598 * 3DSTATE_MULTISAMPLE packet must be used prior to this packet to change
1599 * the Number of Multisamples. This packet must not be used to change
1600 * Number of Multisamples in a rendering sequence.
1601 *
1602 * Since HIZ may be the first thing in a batch buffer, play safe and always
1603 * emit 3DSTATE_MULTISAMPLE.
1604 */
1605 blorp_emit_3dstate_multisample(batch, params);
1606
1607 /* If we can't alter the depth stencil config and multiple layers are
1608 * involved, the HiZ op will fail. This is because the op requires that a
1609 * new config is emitted for each additional layer.
1610 */
1611 if (batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL) {
1612 assert(params->num_layers <= 1);
1613 } else {
1614 blorp_emit_depth_stencil_config(batch, params);
1615 }
1616
1617 blorp_emit(batch, GENX(3DSTATE_WM_HZ_OP), hzp) {
1618 switch (params->hiz_op) {
1619 case ISL_AUX_OP_FAST_CLEAR:
1620 hzp.StencilBufferClearEnable = params->stencil.enabled;
1621 hzp.DepthBufferClearEnable = params->depth.enabled;
1622 hzp.StencilClearValue = params->stencil_ref;
1623 hzp.FullSurfaceDepthandStencilClear = params->full_surface_hiz_op;
1624 break;
1625 case ISL_AUX_OP_FULL_RESOLVE:
1626 assert(params->full_surface_hiz_op);
1627 hzp.DepthBufferResolveEnable = true;
1628 break;
1629 case ISL_AUX_OP_AMBIGUATE:
1630 assert(params->full_surface_hiz_op);
1631 hzp.HierarchicalDepthBufferResolveEnable = true;
1632 break;
1633 case ISL_AUX_OP_PARTIAL_RESOLVE:
1634 case ISL_AUX_OP_NONE:
1635 unreachable("Invalid HIZ op");
1636 }
1637
1638 hzp.NumberofMultisamples = ffs(params->num_samples) - 1;
1639 hzp.SampleMask = 0xFFFF;
1640
1641 /* Due to a hardware issue, this bit MBZ */
1642 assert(hzp.ScissorRectangleEnable == false);
1643
1644 /* Contrary to the HW docs both fields are inclusive */
1645 hzp.ClearRectangleXMin = params->x0;
1646 hzp.ClearRectangleYMin = params->y0;
1647
1648 /* Contrary to the HW docs both fields are exclusive */
1649 hzp.ClearRectangleXMax = params->x1;
1650 hzp.ClearRectangleYMax = params->y1;
1651 }
1652
1653 /* PIPE_CONTROL w/ all bits clear except for “Post-Sync Operation” must set
1654 * to “Write Immediate Data” enabled.
1655 */
1656 blorp_emit(batch, GENX(PIPE_CONTROL), pc) {
1657 pc.PostSyncOperation = WriteImmediateData;
1658 pc.Address = blorp_get_workaround_page(batch);
1659 }
1660
1661 blorp_emit(batch, GENX(3DSTATE_WM_HZ_OP), hzp);
1662 }
1663 #endif
1664
1665 static void
1666 blorp_update_clear_color(struct blorp_batch *batch,
1667 const struct brw_blorp_surface_info *info,
1668 enum isl_aux_op op)
1669 {
1670 if (info->clear_color_addr.buffer && op == ISL_AUX_OP_FAST_CLEAR) {
1671 #if GEN_GEN >= 9
1672 for (int i = 0; i < 4; i++) {
1673 blorp_emit(batch, GENX(MI_STORE_DATA_IMM), sdi) {
1674 sdi.Address = info->clear_color_addr;
1675 sdi.Address.offset += i * 4;
1676 sdi.ImmediateData = info->clear_color.u32[i];
1677 }
1678 }
1679 #elif GEN_GEN >= 7
1680 blorp_emit(batch, GENX(MI_STORE_DATA_IMM), sdi) {
1681 sdi.Address = info->clear_color_addr;
1682 sdi.ImmediateData = ISL_CHANNEL_SELECT_RED << 25 |
1683 ISL_CHANNEL_SELECT_GREEN << 22 |
1684 ISL_CHANNEL_SELECT_BLUE << 19 |
1685 ISL_CHANNEL_SELECT_ALPHA << 16;
1686 if (isl_format_has_int_channel(info->view.format)) {
1687 for (unsigned i = 0; i < 4; i++) {
1688 assert(info->clear_color.u32[i] == 0 ||
1689 info->clear_color.u32[i] == 1);
1690 }
1691 sdi.ImmediateData |= (info->clear_color.u32[0] != 0) << 31;
1692 sdi.ImmediateData |= (info->clear_color.u32[1] != 0) << 30;
1693 sdi.ImmediateData |= (info->clear_color.u32[2] != 0) << 29;
1694 sdi.ImmediateData |= (info->clear_color.u32[3] != 0) << 28;
1695 } else {
1696 for (unsigned i = 0; i < 4; i++) {
1697 assert(info->clear_color.f32[i] == 0.0f ||
1698 info->clear_color.f32[i] == 1.0f);
1699 }
1700 sdi.ImmediateData |= (info->clear_color.f32[0] != 0.0f) << 31;
1701 sdi.ImmediateData |= (info->clear_color.f32[1] != 0.0f) << 30;
1702 sdi.ImmediateData |= (info->clear_color.f32[2] != 0.0f) << 29;
1703 sdi.ImmediateData |= (info->clear_color.f32[3] != 0.0f) << 28;
1704 }
1705 }
1706 #endif
1707 }
1708 }
1709
1710 /**
1711 * \brief Execute a blit or render pass operation.
1712 *
1713 * To execute the operation, this function manually constructs and emits a
1714 * batch to draw a rectangle primitive. The batchbuffer is flushed before
1715 * constructing and after emitting the batch.
1716 *
1717 * This function alters no GL state.
1718 */
1719 static void
1720 blorp_exec(struct blorp_batch *batch, const struct blorp_params *params)
1721 {
1722 if (!(batch->flags & BLORP_BATCH_NO_UPDATE_CLEAR_COLOR)) {
1723 blorp_update_clear_color(batch, &params->dst, params->fast_clear_op);
1724 blorp_update_clear_color(batch, &params->depth, params->hiz_op);
1725 }
1726
1727 #if GEN_GEN >= 8
1728 if (params->hiz_op != ISL_AUX_OP_NONE) {
1729 blorp_emit_gen8_hiz_op(batch, params);
1730 return;
1731 }
1732 #endif
1733
1734 blorp_emit_vertex_buffers(batch, params);
1735 blorp_emit_vertex_elements(batch, params);
1736
1737 blorp_emit_pipeline(batch, params);
1738
1739 blorp_emit_surface_states(batch, params);
1740
1741 if (!(batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL))
1742 blorp_emit_depth_stencil_config(batch, params);
1743
1744 blorp_emit(batch, GENX(3DPRIMITIVE), prim) {
1745 prim.VertexAccessType = SEQUENTIAL;
1746 prim.PrimitiveTopologyType = _3DPRIM_RECTLIST;
1747 #if GEN_GEN >= 7
1748 prim.PredicateEnable = batch->flags & BLORP_BATCH_PREDICATE_ENABLE;
1749 #endif
1750 prim.VertexCountPerInstance = 3;
1751 prim.InstanceCount = params->num_layers;
1752 }
1753 }
1754
1755 #endif /* BLORP_GENX_EXEC_H */