• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BRW_H
25 #define BLORP_GENX_EXEC_BRW_H
26 
27 #include "blorp_priv.h"
28 #include "dev/intel_device_info.h"
29 #include "common/intel_sample_positions.h"
30 #include "common/intel_l3_config.h"
31 #include "genxml/gen_macros.h"
32 #include "intel/compiler/brw_compiler.h"
33 
34 /**
35  * This file provides the blorp pipeline setup and execution functionality.
36  * It defines the following function:
37  *
38  * static void
39  * blorp_exec(struct blorp_context *blorp, void *batch_data,
40  *            const struct blorp_params *params);
41  *
42  * It is the job of whoever includes this header to wrap this in something
43  * to get an externally visible symbol.
44  *
45  * In order for the blorp_exec function to work, the driver must provide
46  * implementations of the following static helper functions.
47  */
48 
49 static void *
50 blorp_emit_dwords(struct blorp_batch *batch, unsigned n);
51 
52 static uint64_t
53 blorp_emit_reloc(struct blorp_batch *batch,
54                  void *location, struct blorp_address address, uint32_t delta);
55 
56 static void
57 blorp_measure_start(struct blorp_batch *batch,
58                     const struct blorp_params *params);
59 
60 static void
61 blorp_measure_end(struct blorp_batch *batch,
62                   const struct blorp_params *params);
63 
64 static void *
65 blorp_alloc_dynamic_state(struct blorp_batch *batch,
66                           uint32_t size,
67                           uint32_t alignment,
68                           uint32_t *offset);
69 
70 UNUSED static void *
71 blorp_alloc_general_state(struct blorp_batch *batch,
72                           uint32_t size,
73                           uint32_t alignment,
74                           uint32_t *offset);
75 
76 static void *
77 blorp_alloc_vertex_buffer(struct blorp_batch *batch, uint32_t size,
78                           struct blorp_address *addr);
79 static void
80 blorp_vf_invalidate_for_vb_48b_transitions(struct blorp_batch *batch,
81                                            const struct blorp_address *addrs,
82                                            uint32_t *sizes,
83                                            unsigned num_vbs);
84 
85 UNUSED static struct blorp_address
86 blorp_get_workaround_address(struct blorp_batch *batch);
87 
88 static bool
89 blorp_alloc_binding_table(struct blorp_batch *batch, unsigned num_entries,
90                           unsigned state_size, unsigned state_alignment,
91                           uint32_t *bt_offset, uint32_t *surface_offsets,
92                           void **surface_maps);
93 
94 static uint32_t
95 blorp_binding_table_offset_to_pointer(struct blorp_batch *batch,
96                                       uint32_t offset);
97 
98 static void
99 blorp_flush_range(struct blorp_batch *batch, void *start, size_t size);
100 
101 static void
102 blorp_surface_reloc(struct blorp_batch *batch, uint32_t ss_offset,
103                     struct blorp_address address, uint32_t delta);
104 
105 static uint64_t
106 blorp_get_surface_address(struct blorp_batch *batch,
107                           struct blorp_address address);
108 
109 #if GFX_VER < 10
110 static struct blorp_address
111 blorp_get_surface_base_address(struct blorp_batch *batch);
112 #endif
113 
114 static const struct intel_l3_config *
115 blorp_get_l3_config(struct blorp_batch *batch);
116 
117 static void
118 blorp_pre_emit_urb_config(struct blorp_batch *batch,
119                           struct intel_urb_config *urb_config);
120 
121 static void
122 blorp_emit_urb_config(struct blorp_batch *batch,
123                       struct intel_urb_config *urb_config);
124 
125 static void
126 blorp_emit_pipeline(struct blorp_batch *batch,
127                     const struct blorp_params *params);
128 
129 static void
130 blorp_emit_pre_draw(struct blorp_batch *batch,
131                     const struct blorp_params *params);
132 static void
133 blorp_emit_post_draw(struct blorp_batch *batch,
134                      const struct blorp_params *params);
135 
136 static inline unsigned
brw_blorp_get_urb_length(const struct brw_wm_prog_data * prog_data)137 brw_blorp_get_urb_length(const struct brw_wm_prog_data *prog_data)
138 {
139    if (prog_data == NULL)
140       return 1;
141 
142    /* From the BSpec: 3D Pipeline - Strips and Fans - 3DSTATE_SBE
143     *
144     * read_length = ceiling((max_source_attr+1)/2)
145     */
146    return MAX2((prog_data->num_varying_inputs + 1) / 2, 1);
147 }
148 
149 /***** BEGIN blorp_exec implementation ******/
150 
151 static uint64_t
_blorp_combine_address(struct blorp_batch * batch,void * location,struct blorp_address address,uint32_t delta)152 _blorp_combine_address(struct blorp_batch *batch, void *location,
153                        struct blorp_address address, uint32_t delta)
154 {
155    if (address.buffer == NULL) {
156       return address.offset + delta;
157    } else {
158       return blorp_emit_reloc(batch, location, address, delta);
159    }
160 }
161 
162 #define __gen_address_type struct blorp_address
163 #define __gen_user_data struct blorp_batch
164 #define __gen_combine_address _blorp_combine_address
165 
166 #include "genxml/genX_pack.h"
167 #include "common/intel_genX_state_brw.h"
168 
169 #define _blorp_cmd_length(cmd) cmd ## _length
170 #define _blorp_cmd_length_bias(cmd) cmd ## _length_bias
171 #define _blorp_cmd_header(cmd) cmd ## _header
172 #define _blorp_cmd_pack(cmd) cmd ## _pack
173 
174 #define blorp_emit(batch, cmd, name)                              \
175    for (struct cmd name = { _blorp_cmd_header(cmd) },             \
176         *_dst = blorp_emit_dwords(batch, _blorp_cmd_length(cmd)); \
177         __builtin_expect(_dst != NULL, 1);                        \
178         _blorp_cmd_pack(cmd)(batch, (void *)_dst, &name),         \
179         _dst = NULL)
180 
181 #define blorp_emitn(batch, cmd, n, ...) ({                  \
182       uint32_t *_dw = blorp_emit_dwords(batch, n);          \
183       if (_dw) {                                            \
184          struct cmd template = {                            \
185             _blorp_cmd_header(cmd),                         \
186             .DWordLength = n - _blorp_cmd_length_bias(cmd), \
187             __VA_ARGS__                                     \
188          };                                                 \
189          _blorp_cmd_pack(cmd)(batch, _dw, &template);       \
190       }                                                     \
191       _dw ? _dw + 1 : NULL; /* Array starts at dw[1] */     \
192    })
193 
194 #define STRUCT_ZERO(S) ({ struct S t; memset(&t, 0, sizeof(t)); t; })
195 
196 #define blorp_emit_dynamic(batch, state, name, align, offset)      \
197    for (struct state name = STRUCT_ZERO(state),                         \
198         *_dst = blorp_alloc_dynamic_state(batch,                   \
199                                           _blorp_cmd_length(state) * 4, \
200                                           align, offset);               \
201         __builtin_expect(_dst != NULL, 1);                              \
202         _blorp_cmd_pack(state)(batch, (void *)_dst, &name),             \
203         blorp_flush_range(batch, _dst, _blorp_cmd_length(state) * 4),   \
204         _dst = NULL)
205 
206 /* 3DSTATE_URB
207  * 3DSTATE_URB_VS
208  * 3DSTATE_URB_HS
209  * 3DSTATE_URB_DS
210  * 3DSTATE_URB_GS
211  *
212  * Assign the entire URB to the VS. Even though the VS disabled, URB space
213  * is still needed because the clipper loads the VUE's from the URB. From
214  * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
215  * Dword 1.15:0 "VS Number of URB Entries":
216  *     This field is always used (even if VS Function Enable is DISABLED).
217  *
218  * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
219  * safely ignore it because this batch contains only one draw call.
220  *     Because of URB corruption caused by allocating a previous GS unit
221  *     URB entry to the VS unit, software is required to send a “GS NULL
222  *     Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
223  *     plus a dummy DRAW call before any case where VS will be taking over
224  *     GS URB space.
225  *
226  * If the 3DSTATE_URB_VS is emitted, than the others must be also.
227  * From the Ivybridge PRM, Volume 2 Part 1, section 1.7.1 3DSTATE_URB_VS:
228  *
229  *     3DSTATE_URB_HS, 3DSTATE_URB_DS, and 3DSTATE_URB_GS must also be
230  *     programmed in order for the programming of this state to be
231  *     valid.
232  */
233 static void
emit_urb_config(struct blorp_batch * batch,const struct blorp_params * params,UNUSED enum intel_urb_deref_block_size * deref_block_size)234 emit_urb_config(struct blorp_batch *batch,
235                 const struct blorp_params *params,
236                 UNUSED enum intel_urb_deref_block_size *deref_block_size)
237 {
238    /* Once vertex fetcher has written full VUE entries with complete
239     * header the space requirement is as follows per vertex (in bytes):
240     *
241     *     Header    Position    Program constants
242     *   +--------+------------+-------------------+
243     *   |   16   |     16     |      n x 16       |
244     *   +--------+------------+-------------------+
245     *
246     * where 'n' stands for number of varying inputs expressed as vec4s.
247     */
248    struct brw_wm_prog_data *wm_prog_data = params->wm_prog_data;
249    const unsigned num_varyings =
250       wm_prog_data ? wm_prog_data->num_varying_inputs : 0;
251    const unsigned total_needed = 16 + 16 + num_varyings * 16;
252 
253    /* The URB size is expressed in units of 64 bytes (512 bits) */
254    const unsigned vs_entry_size = DIV_ROUND_UP(total_needed, 64);
255 
256    struct intel_urb_config urb_cfg = {
257       .size = { vs_entry_size, 1, 1, 1 },
258    };
259 
260    bool constrained;
261    intel_get_urb_config(batch->blorp->compiler->brw->devinfo,
262                         blorp_get_l3_config(batch),
263                         false, false, &urb_cfg,
264                         deref_block_size, &constrained);
265 
266    /* Tell drivers about the config. */
267    blorp_pre_emit_urb_config(batch, &urb_cfg);
268 
269    for (int i = 0; i <= MESA_SHADER_GEOMETRY; i++) {
270       blorp_emit(batch, GENX(3DSTATE_URB_VS), urb) {
271          urb._3DCommandSubOpcode      += i;
272          urb.VSURBStartingAddress      = urb_cfg.start[i];
273          urb.VSURBEntryAllocationSize  = urb_cfg.size[i] - 1;
274          urb.VSNumberofURBEntries      = urb_cfg.entries[i];
275       }
276    }
277 
278    if (batch->blorp->config.use_mesh_shading) {
279 #if GFX_VERx10 >= 125
280       blorp_emit(batch, GENX(3DSTATE_URB_ALLOC_MESH), zero);
281       blorp_emit(batch, GENX(3DSTATE_URB_ALLOC_TASK), zero);
282 #endif
283    }
284 }
285 
286 static void
287 blorp_emit_memcpy(struct blorp_batch *batch,
288                   struct blorp_address dst,
289                   struct blorp_address src,
290                   uint32_t size);
291 
292 static void
blorp_emit_vertex_data(struct blorp_batch * batch,const struct blorp_params * params,struct blorp_address * addr,uint32_t * size)293 blorp_emit_vertex_data(struct blorp_batch *batch,
294                        const struct blorp_params *params,
295                        struct blorp_address *addr,
296                        uint32_t *size)
297 {
298    const float vertices[] = {
299       /* v0 */ (float)params->x1, (float)params->y1, params->z,
300       /* v1 */ (float)params->x0, (float)params->y1, params->z,
301       /* v2 */ (float)params->x0, (float)params->y0, params->z,
302    };
303 
304    void *data = blorp_alloc_vertex_buffer(batch, sizeof(vertices), addr);
305    memcpy(data, vertices, sizeof(vertices));
306    *size = sizeof(vertices);
307    blorp_flush_range(batch, data, *size);
308 }
309 
310 static void
blorp_emit_input_varying_data(struct blorp_batch * batch,const struct blorp_params * params,struct blorp_address * addr,uint32_t * size)311 blorp_emit_input_varying_data(struct blorp_batch *batch,
312                               const struct blorp_params *params,
313                               struct blorp_address *addr,
314                               uint32_t *size)
315 {
316    const unsigned vec4_size_in_bytes = 4 * sizeof(float);
317    const unsigned max_num_varyings =
318       DIV_ROUND_UP(sizeof(params->wm_inputs), vec4_size_in_bytes);
319    struct brw_wm_prog_data *wm_prog_data = params->wm_prog_data;
320    const unsigned num_varyings =
321       wm_prog_data ? wm_prog_data->num_varying_inputs : 0;
322 
323    *size = 16 + num_varyings * vec4_size_in_bytes;
324 
325    const uint32_t *const inputs_src = (const uint32_t *)&params->wm_inputs;
326    void *data = blorp_alloc_vertex_buffer(batch, *size, addr);
327    uint32_t *inputs = data;
328 
329    /* Copy in the VS inputs */
330    assert(sizeof(params->vs_inputs) == 16);
331    memcpy(inputs, &params->vs_inputs, sizeof(params->vs_inputs));
332    inputs += 4;
333 
334    if (params->wm_prog_data) {
335       /* Walk over the attribute slots, determine if the attribute is used by
336        * the program and when necessary copy the values from the input storage
337        * to the vertex data buffer.
338        */
339       for (unsigned i = 0; i < max_num_varyings; i++) {
340          const gl_varying_slot attr = VARYING_SLOT_VAR0 + i;
341 
342          const int input_index = wm_prog_data->urb_setup[attr];
343          if (input_index < 0)
344             continue;
345 
346          memcpy(inputs, inputs_src + i * 4, vec4_size_in_bytes);
347 
348          inputs += 4;
349       }
350    }
351 
352    blorp_flush_range(batch, data, *size);
353 
354    if (params->dst_clear_color_as_input) {
355       /* In this case, the clear color isn't known statically and instead
356        * comes in through an indirect which we have to copy into the vertex
357        * buffer before we execute the 3DPRIMITIVE.  We already copied the
358        * value of params->wm_inputs.clear_color into the vertex buffer in the
359        * loop above.  Now we emit code to stomp it from the GPU with the
360        * actual clear color value.
361        */
362       assert(num_varyings == 1);
363 
364       /* The clear color is the first thing after the header */
365       struct blorp_address clear_color_input_addr = *addr;
366       clear_color_input_addr.offset += 16;
367 
368       const unsigned clear_color_size =
369          GFX_VER < 10 ? batch->blorp->isl_dev->ss.clear_value_size : 4 * 4;
370       blorp_emit_memcpy(batch, clear_color_input_addr,
371                         params->dst.clear_color_addr,
372                         clear_color_size);
373    }
374 }
375 
376 static void
blorp_fill_vertex_buffer_state(struct GENX (VERTEX_BUFFER_STATE)* vb,unsigned idx,struct blorp_address addr,uint32_t size,uint32_t stride)377 blorp_fill_vertex_buffer_state(struct GENX(VERTEX_BUFFER_STATE) *vb,
378                                unsigned idx,
379                                struct blorp_address addr, uint32_t size,
380                                uint32_t stride)
381 {
382    vb[idx].VertexBufferIndex = idx;
383    vb[idx].BufferStartingAddress = addr;
384    vb[idx].BufferPitch = stride;
385    vb[idx].MOCS = addr.mocs;
386    vb[idx].AddressModifyEnable = true;
387    vb[idx].BufferSize = size;
388 
389 #if GFX_VER >= 12
390    vb[idx].L3BypassDisable = true;
391 #endif
392 }
393 
394 static void
blorp_emit_vertex_buffers(struct blorp_batch * batch,const struct blorp_params * params)395 blorp_emit_vertex_buffers(struct blorp_batch *batch,
396                           const struct blorp_params *params)
397 {
398    struct GENX(VERTEX_BUFFER_STATE) vb[2] = {};
399    const uint32_t num_vbs = ARRAY_SIZE(vb);
400 
401    struct blorp_address addrs[2] = {};
402    uint32_t sizes[2];
403    blorp_emit_vertex_data(batch, params, &addrs[0], &sizes[0]);
404    blorp_fill_vertex_buffer_state(vb, 0, addrs[0], sizes[0],
405                                   3 * sizeof(float));
406 
407    blorp_emit_input_varying_data(batch, params, &addrs[1], &sizes[1]);
408    blorp_fill_vertex_buffer_state(vb, 1, addrs[1], sizes[1], 0);
409 
410    blorp_vf_invalidate_for_vb_48b_transitions(batch, addrs, sizes, num_vbs);
411 
412    const unsigned num_dwords = 1 + num_vbs * GENX(VERTEX_BUFFER_STATE_length);
413    uint32_t *dw = blorp_emitn(batch, GENX(3DSTATE_VERTEX_BUFFERS), num_dwords);
414    if (!dw)
415       return;
416 
417    for (unsigned i = 0; i < num_vbs; i++) {
418       GENX(VERTEX_BUFFER_STATE_pack)(batch, dw, &vb[i]);
419       dw += GENX(VERTEX_BUFFER_STATE_length);
420    }
421 }
422 
423 static void
blorp_emit_vertex_elements(struct blorp_batch * batch,const struct blorp_params * params)424 blorp_emit_vertex_elements(struct blorp_batch *batch,
425                            const struct blorp_params *params)
426 {
427    struct brw_wm_prog_data *wm_prog_data = params->wm_prog_data;
428    const unsigned num_varyings =
429       wm_prog_data ? wm_prog_data->num_varying_inputs : 0;
430    const unsigned num_elements = 2 + num_varyings;
431 
432    struct GENX(VERTEX_ELEMENT_STATE) ve[num_elements];
433    memset(ve, 0, num_elements * sizeof(*ve));
434 
435    /* Setup VBO for the rectangle primitive..
436     *
437     * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
438     * vertices. The vertices reside in screen space with DirectX
439     * coordinates (that is, (0, 0) is the upper left corner).
440     *
441     *   v2 ------ implied
442     *    |        |
443     *    |        |
444     *   v1 ----- v0
445     *
446     * Since the VS is disabled, the clipper loads each VUE directly from
447     * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
448     * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
449     *   dw0: Reserved, MBZ.
450     *   dw1: Render Target Array Index. Below vertex fetcher gets programmed
451     *        to assign this with primitive instance identifier which will be
452     *        used for layered clears. All other renders have only one instance
453     *        and therefore the value will be effectively zero.
454     *   dw2: Viewport Index. The HiZ op disables viewport mapping and
455     *        scissoring, so set the dword to 0.
456     *   dw3: Point Width: The HiZ op does not emit the POINTLIST primitive,
457     *        so set the dword to 0.
458     *   dw4: Vertex Position X.
459     *   dw5: Vertex Position Y.
460     *   dw6: Vertex Position Z.
461     *   dw7: Vertex Position W.
462     *
463     *   dw8: Flat vertex input 0
464     *   dw9: Flat vertex input 1
465     *   ...
466     *   dwn: Flat vertex input n - 8
467     *
468     * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
469     * "Vertex URB Entry (VUE) Formats".
470     *
471     * Only vertex position X and Y are going to be variable, Z is fixed to
472     * zero and W to one. Header words dw0,2,3 are zero. There is no need to
473     * include the fixed values in the vertex buffer. Vertex fetcher can be
474     * instructed to fill vertex elements with constant values of one and zero
475     * instead of reading them from the buffer.
476     * Flat inputs are program constants that are not interpolated. Moreover
477     * their values will be the same between vertices.
478     *
479     * See the vertex element setup below.
480     */
481    unsigned slot = 0;
482 
483    ve[slot] = (struct GENX(VERTEX_ELEMENT_STATE)) {
484       .VertexBufferIndex = 1,
485       .Valid = true,
486       .SourceElementFormat = ISL_FORMAT_R32G32B32A32_FLOAT,
487       .SourceElementOffset = 0,
488       .Component0Control = VFCOMP_STORE_SRC,
489 
490       /* From Gfx8 onwards hardware is no more instructed to overwrite
491        * components using an element specifier. Instead one has separate
492        * 3DSTATE_VF_SGVS (System Generated Value Setup) state packet for it.
493        */
494       .Component1Control = VFCOMP_STORE_0,
495       .Component2Control = VFCOMP_STORE_0,
496       .Component3Control = VFCOMP_STORE_0,
497    };
498    slot++;
499 
500    ve[slot] = (struct GENX(VERTEX_ELEMENT_STATE)) {
501       .VertexBufferIndex = 0,
502       .Valid = true,
503       .SourceElementFormat = ISL_FORMAT_R32G32B32_FLOAT,
504       .SourceElementOffset = 0,
505       .Component0Control = VFCOMP_STORE_SRC,
506       .Component1Control = VFCOMP_STORE_SRC,
507       .Component2Control = VFCOMP_STORE_SRC,
508       .Component3Control = VFCOMP_STORE_1_FP,
509    };
510    slot++;
511 
512    for (unsigned i = 0; i < num_varyings; ++i) {
513       ve[slot] = (struct GENX(VERTEX_ELEMENT_STATE)) {
514          .VertexBufferIndex = 1,
515          .Valid = true,
516          .SourceElementFormat = ISL_FORMAT_R32G32B32A32_FLOAT,
517          .SourceElementOffset = 16 + i * 4 * sizeof(float),
518          .Component0Control = VFCOMP_STORE_SRC,
519          .Component1Control = VFCOMP_STORE_SRC,
520          .Component2Control = VFCOMP_STORE_SRC,
521          .Component3Control = VFCOMP_STORE_SRC,
522       };
523       slot++;
524    }
525 
526    const unsigned num_dwords =
527       1 + GENX(VERTEX_ELEMENT_STATE_length) * num_elements;
528    uint32_t *dw = blorp_emitn(batch, GENX(3DSTATE_VERTEX_ELEMENTS), num_dwords);
529    if (!dw)
530       return;
531 
532    for (unsigned i = 0; i < num_elements; i++) {
533       GENX(VERTEX_ELEMENT_STATE_pack)(batch, dw, &ve[i]);
534       dw += GENX(VERTEX_ELEMENT_STATE_length);
535    }
536 
537    blorp_emit(batch, GENX(3DSTATE_VF_STATISTICS), vf) {
538       vf.StatisticsEnable = false;
539    }
540 
541    /* Overwrite Render Target Array Index (2nd dword) in the VUE header with
542     * primitive instance identifier. This is used for layered clears.
543     */
544    blorp_emit(batch, GENX(3DSTATE_VF_SGVS), sgvs) {
545       sgvs.InstanceIDEnable = true;
546       sgvs.InstanceIDComponentNumber = COMP_1;
547       sgvs.InstanceIDElementOffset = 0;
548    }
549 
550 #if GFX_VER >= 11
551    blorp_emit(batch, GENX(3DSTATE_VF_SGVS_2), sgvs);
552 #endif
553 
554    for (unsigned i = 0; i < num_elements; i++) {
555       blorp_emit(batch, GENX(3DSTATE_VF_INSTANCING), vf) {
556          vf.VertexElementIndex = i;
557          vf.InstancingEnable = false;
558       }
559    }
560 
561    blorp_emit(batch, GENX(3DSTATE_VF_TOPOLOGY), topo) {
562       topo.PrimitiveTopologyType = _3DPRIM_RECTLIST;
563    }
564 }
565 
566 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
567 static uint32_t
blorp_emit_cc_viewport(struct blorp_batch * batch)568 blorp_emit_cc_viewport(struct blorp_batch *batch)
569 {
570    uint32_t cc_vp_offset;
571    blorp_emit_dynamic(batch, GENX(CC_VIEWPORT), vp, 32, &cc_vp_offset) {
572       vp.MinimumDepth = batch->blorp->config.use_unrestricted_depth_range ?
573                            -FLT_MAX : 0.0;
574       vp.MaximumDepth = batch->blorp->config.use_unrestricted_depth_range ?
575                            FLT_MAX : 1.0;
576    }
577 
578    blorp_emit(batch, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC), vsp) {
579       vsp.CCViewportPointer = cc_vp_offset;
580    }
581 
582    return cc_vp_offset;
583 }
584 
585 static uint32_t
blorp_emit_sampler_state(struct blorp_batch * batch)586 blorp_emit_sampler_state(struct blorp_batch *batch)
587 {
588    uint32_t offset;
589    blorp_emit_dynamic(batch, GENX(SAMPLER_STATE), sampler, 32, &offset) {
590       sampler.MipModeFilter = MIPFILTER_NONE;
591       sampler.MagModeFilter = MAPFILTER_LINEAR;
592       sampler.MinModeFilter = MAPFILTER_LINEAR;
593       sampler.MinLOD = 0;
594       sampler.MaxLOD = 0;
595       sampler.TCXAddressControlMode = TCM_CLAMP;
596       sampler.TCYAddressControlMode = TCM_CLAMP;
597       sampler.TCZAddressControlMode = TCM_CLAMP;
598       sampler.MaximumAnisotropy = RATIO21;
599       sampler.RAddressMinFilterRoundingEnable = true;
600       sampler.RAddressMagFilterRoundingEnable = true;
601       sampler.VAddressMinFilterRoundingEnable = true;
602       sampler.VAddressMagFilterRoundingEnable = true;
603       sampler.UAddressMinFilterRoundingEnable = true;
604       sampler.UAddressMagFilterRoundingEnable = true;
605       sampler.NonnormalizedCoordinateEnable = true;
606    }
607 
608    return offset;
609 }
610 
611 UNUSED static uint32_t
blorp_emit_sampler_state_ps(struct blorp_batch * batch)612 blorp_emit_sampler_state_ps(struct blorp_batch *batch)
613 {
614    uint32_t offset = blorp_emit_sampler_state(batch);
615 
616    blorp_emit(batch, GENX(3DSTATE_SAMPLER_STATE_POINTERS_PS), ssp) {
617       ssp.PointertoPSSamplerState = offset;
618    }
619 
620    return offset;
621 }
622 
623 /* What follows is the code for setting up a "pipeline". */
624 
625 static void
blorp_emit_vs_config(struct blorp_batch * batch,const struct blorp_params * params)626 blorp_emit_vs_config(struct blorp_batch *batch,
627                      const struct blorp_params *params)
628 {
629    struct brw_vs_prog_data *vs_prog_data = params->vs_prog_data;
630    assert(!vs_prog_data || GFX_VER < 11 ||
631           vs_prog_data->base.dispatch_mode == INTEL_DISPATCH_MODE_SIMD8);
632 
633    blorp_emit(batch, GENX(3DSTATE_VS), vs) {
634       if (vs_prog_data) {
635          vs.Enable = true;
636 
637          vs.KernelStartPointer = params->vs_prog_kernel;
638 
639          vs.DispatchGRFStartRegisterForURBData =
640             vs_prog_data->base.base.dispatch_grf_start_reg;
641          vs.VertexURBEntryReadLength =
642             vs_prog_data->base.urb_read_length;
643          vs.VertexURBEntryReadOffset = 0;
644 
645          vs.MaximumNumberofThreads =
646             batch->blorp->isl_dev->info->max_vs_threads - 1;
647 
648          assert(vs_prog_data->base.dispatch_mode == INTEL_DISPATCH_MODE_SIMD8);
649 #if GFX_VER < 20
650          vs.SIMD8DispatchEnable = true;
651 #endif
652       }
653    }
654 }
655 
656 static void
blorp_emit_sf_config(struct blorp_batch * batch,const struct blorp_params * params,UNUSED enum intel_urb_deref_block_size urb_deref_block_size)657 blorp_emit_sf_config(struct blorp_batch *batch,
658                      const struct blorp_params *params,
659                      UNUSED enum intel_urb_deref_block_size urb_deref_block_size)
660 {
661    const struct brw_wm_prog_data *prog_data = params->wm_prog_data;
662 
663    /* 3DSTATE_SF
664     *
665     * Disable ViewportTransformEnable (dw2.1)
666     *
667     * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
668     * Primitives Overview":
669     *     RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
670     *     use of screen- space coordinates).
671     *
672     * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
673     * and BackFaceFillMode (dw2.5:6) to SOLID(0).
674     *
675     * From the Sandy Bridge PRM, Volume 2, Part 1, Section
676     * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
677     *     SOLID: Any triangle or rectangle object found to be front-facing
678     *     is rendered as a solid object. This setting is required when
679     *     (rendering rectangle (RECTLIST) objects.
680     */
681 
682    blorp_emit(batch, GENX(3DSTATE_SF), sf) {
683 #if GFX_VER >= 12
684       sf.DerefBlockSize = urb_deref_block_size;
685 #endif
686    }
687 
688    blorp_emit(batch, GENX(3DSTATE_RASTER), raster) {
689       raster.CullMode = CULLMODE_NONE;
690    }
691 
692    blorp_emit(batch, GENX(3DSTATE_SBE), sbe) {
693       sbe.VertexURBEntryReadOffset = 1;
694       if (prog_data) {
695          sbe.NumberofSFOutputAttributes = prog_data->num_varying_inputs;
696          sbe.VertexURBEntryReadLength = brw_blorp_get_urb_length(prog_data);
697          sbe.ConstantInterpolationEnable = prog_data->flat_inputs;
698       } else {
699          sbe.NumberofSFOutputAttributes = 0;
700          sbe.VertexURBEntryReadLength = 1;
701       }
702       sbe.ForceVertexURBEntryReadLength = true;
703       sbe.ForceVertexURBEntryReadOffset = true;
704 
705       for (unsigned i = 0; i < 32; i++)
706          sbe.AttributeActiveComponentFormat[i] = ACF_XYZW;
707    }
708 }
709 
710 static void
blorp_emit_ps_config(struct blorp_batch * batch,const struct blorp_params * params)711 blorp_emit_ps_config(struct blorp_batch *batch,
712                      const struct blorp_params *params)
713 {
714    const struct brw_wm_prog_data *prog_data = params->wm_prog_data;
715 
716    /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
717     * nonzero to prevent the GPU from hanging.  While the documentation doesn't
718     * mention this explicitly, it notes that the valid range for the field is
719     * [1,39] = [2,40] threads, which excludes zero.
720     *
721     * To be safe (and to minimize extraneous code) we go ahead and fully
722     * configure the WM state whether or not there is a WM program.
723     */
724 
725    const struct intel_device_info *devinfo = batch->blorp->compiler->brw->devinfo;
726 
727    blorp_emit(batch, GENX(3DSTATE_WM), wm);
728 
729    blorp_emit(batch, GENX(3DSTATE_PS), ps) {
730       if (params->src.enabled) {
731          ps.SamplerCount = 1; /* Up to 4 samplers */
732          ps.BindingTableEntryCount = 2;
733       } else {
734          ps.BindingTableEntryCount = 1;
735       }
736 
737       /* SAMPLER_STATE prefetching is broken on Gfx11 - Wa_1606682166 */
738       if (GFX_VER == 11)
739          ps.SamplerCount = 0;
740 
741       /* 3DSTATE_PS expects the number of threads per PSD, which is always 64
742        * for pre Gfx11 and 128 for gfx11+; On gfx11+ If a programmed value is
743        * k, it implies 2(k+1) threads. It implicitly scales for different GT
744        * levels (which have some # of PSDs).
745        */
746       ps.MaximumNumberofThreadsPerPSD = devinfo->max_threads_per_psd - 1;
747 
748       switch (params->fast_clear_op) {
749       case ISL_AUX_OP_NONE:
750          break;
751 #if GFX_VER >= 10
752       case ISL_AUX_OP_AMBIGUATE:
753          ps.RenderTargetFastClearEnable = true;
754          ps.RenderTargetResolveType = FAST_CLEAR_0;
755          break;
756 #endif
757       case ISL_AUX_OP_PARTIAL_RESOLVE:
758          ps.RenderTargetResolveType = RESOLVE_PARTIAL;
759          break;
760       case ISL_AUX_OP_FULL_RESOLVE:
761          ps.RenderTargetResolveType = RESOLVE_FULL;
762          break;
763       case ISL_AUX_OP_FAST_CLEAR:
764          ps.RenderTargetFastClearEnable = true;
765          break;
766       default:
767          unreachable("Invalid fast clear op");
768       }
769 
770       /* The RENDER_SURFACE_STATE page for TGL says:
771        *
772        *   For an 8 bpp surface with NUM_MULTISAMPLES = 1, Surface Width not
773        *   multiple of 64 pixels and more than 1 mip level in the view, Fast
774        *   Clear is not supported when AUX_CCS_E is set in this field.
775        *
776        * The granularity of a fast-clear or ambiguate operation is likely one
777        * CCS element. For an 8 bpp primary surface, this maps to 32px x 4rows.
778        * Due to the surface layout parameters, if LOD0's width isn't a
779        * multiple of 64px, LOD1 and LOD2+ will share CCS elements. Assert that
780        * these operations aren't occurring on these LODs.
781        *
782        * We don't explicitly check for TGL+ because the restriction is
783        * technically applicable to all hardware. Platforms prior to TGL don't
784        * support CCS on 8 bpp surfaces. So, these unaligned fast clear
785        * operations shouldn't be occurring prior to TGL as well.
786        */
787       if (isl_format_get_layout(params->dst.surf.format)->bpb == 8 &&
788           params->dst.surf.logical_level0_px.width % 64 != 0 &&
789           params->dst.surf.levels >= 3 &&
790           params->dst.view.base_level >= 1) {
791          assert(params->num_samples == 1);
792          assert(!ps.RenderTargetFastClearEnable);
793       }
794 
795       if (prog_data) {
796          intel_set_ps_dispatch_state(&ps, devinfo, prog_data,
797                                      params->num_samples,
798                                      0 /* msaa_flags */);
799 
800          ps.DispatchGRFStartRegisterForConstantSetupData0 =
801             brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 0);
802          ps.DispatchGRFStartRegisterForConstantSetupData1 =
803             brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 1);
804 #if GFX_VER < 20
805          ps.DispatchGRFStartRegisterForConstantSetupData2 =
806             brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 2);
807 #endif
808 
809          ps.KernelStartPointer0 = params->wm_prog_kernel +
810                                   brw_wm_prog_data_prog_offset(prog_data, ps, 0);
811          ps.KernelStartPointer1 = params->wm_prog_kernel +
812                                   brw_wm_prog_data_prog_offset(prog_data, ps, 1);
813 #if GFX_VER < 20
814          ps.KernelStartPointer2 = params->wm_prog_kernel +
815                                   brw_wm_prog_data_prog_offset(prog_data, ps, 2);
816 #endif
817       }
818    }
819 
820    blorp_emit(batch, GENX(3DSTATE_PS_EXTRA), psx) {
821       if (prog_data) {
822          psx.PixelShaderValid = true;
823 #if GFX_VER < 20
824          psx.AttributeEnable = prog_data->num_varying_inputs > 0;
825 #endif
826          psx.PixelShaderIsPerSample = prog_data->persample_dispatch;
827          psx.PixelShaderComputedDepthMode = prog_data->computed_depth_mode;
828          psx.PixelShaderComputesStencil = prog_data->computed_stencil;
829       }
830 
831       if (params->src.enabled)
832          psx.PixelShaderKillsPixel = true;
833    }
834 }
835 
836 static void
blorp_emit_blend_state(struct blorp_batch * batch,const struct blorp_params * params)837 blorp_emit_blend_state(struct blorp_batch *batch,
838                        const struct blorp_params *params)
839 {
840    struct GENX(BLEND_STATE) blend = { };
841 
842    uint32_t offset;
843    int size = GENX(BLEND_STATE_length) * 4;
844    size += GENX(BLEND_STATE_ENTRY_length) * 4 * params->num_draw_buffers;
845    uint32_t *state = blorp_alloc_dynamic_state(batch, size, 64, &offset);
846    uint32_t *pos = state;
847 
848    GENX(BLEND_STATE_pack)(NULL, pos, &blend);
849    pos += GENX(BLEND_STATE_length);
850 
851    for (unsigned i = 0; i < params->num_draw_buffers; ++i) {
852       struct GENX(BLEND_STATE_ENTRY) entry = {
853          .PreBlendColorClampEnable = true,
854          .PostBlendColorClampEnable = true,
855          .ColorClampRange = COLORCLAMP_RTFORMAT,
856 
857          .WriteDisableRed = params->color_write_disable & 1,
858          .WriteDisableGreen = params->color_write_disable & 2,
859          .WriteDisableBlue = params->color_write_disable & 4,
860          .WriteDisableAlpha = params->color_write_disable & 8,
861       };
862       GENX(BLEND_STATE_ENTRY_pack)(NULL, pos, &entry);
863       pos += GENX(BLEND_STATE_ENTRY_length);
864    }
865 
866    blorp_flush_range(batch, state, size);
867 
868    blorp_emit(batch, GENX(3DSTATE_BLEND_STATE_POINTERS), sp) {
869       sp.BlendStatePointer = offset;
870       sp.BlendStatePointerValid = true;
871    }
872 
873    blorp_emit(batch, GENX(3DSTATE_PS_BLEND), ps_blend) {
874       ps_blend.HasWriteableRT = true;
875    }
876 }
877 
878 static void
blorp_emit_color_calc_state(struct blorp_batch * batch,UNUSED const struct blorp_params * params)879 blorp_emit_color_calc_state(struct blorp_batch *batch,
880                             UNUSED const struct blorp_params *params)
881 {
882    uint32_t offset;
883    blorp_emit_dynamic(batch, GENX(COLOR_CALC_STATE), cc, 64, &offset) {}
884 
885    blorp_emit(batch, GENX(3DSTATE_CC_STATE_POINTERS), sp) {
886       sp.ColorCalcStatePointer = offset;
887       sp.ColorCalcStatePointerValid = true;
888    }
889 }
890 
891 static void
blorp_emit_depth_stencil_state(struct blorp_batch * batch,const struct blorp_params * params)892 blorp_emit_depth_stencil_state(struct blorp_batch *batch,
893                                const struct blorp_params *params)
894 {
895    blorp_emit(batch, GENX(3DSTATE_WM_DEPTH_STENCIL), ds) {
896       if (params->depth.enabled) {
897          ds.DepthBufferWriteEnable = true;
898 
899          switch (params->hiz_op) {
900          /* See the following sections of the Sandy Bridge PRM, Volume 2, Part1:
901           *   - 7.5.3.1 Depth Buffer Clear
902           *   - 7.5.3.2 Depth Buffer Resolve
903           *   - 7.5.3.3 Hierarchical Depth Buffer Resolve
904           */
905          case ISL_AUX_OP_FULL_RESOLVE:
906             ds.DepthTestEnable = true;
907             ds.DepthTestFunction = COMPAREFUNCTION_NEVER;
908             break;
909 
910          case ISL_AUX_OP_NONE:
911          case ISL_AUX_OP_FAST_CLEAR:
912          case ISL_AUX_OP_AMBIGUATE:
913             ds.DepthTestEnable = false;
914             break;
915          case ISL_AUX_OP_PARTIAL_RESOLVE:
916             unreachable("Invalid HIZ op");
917          }
918       }
919 
920       if (params->stencil.enabled) {
921          ds.StencilBufferWriteEnable = true;
922          ds.StencilTestEnable = true;
923          ds.DoubleSidedStencilEnable = false;
924 
925          ds.StencilTestFunction = COMPAREFUNCTION_ALWAYS;
926          ds.StencilPassDepthPassOp = STENCILOP_REPLACE;
927 
928          ds.StencilWriteMask = params->stencil_mask;
929          ds.StencilReferenceValue = params->stencil_ref;
930       }
931    }
932 
933 #if GFX_VER >= 12
934    blorp_emit(batch, GENX(3DSTATE_DEPTH_BOUNDS), db) {
935       db.DepthBoundsTestEnable = false;
936       db.DepthBoundsTestMinValue = 0.0;
937       db.DepthBoundsTestMaxValue = 1.0;
938    }
939 #endif
940 }
941 
942 static void
blorp_emit_3dstate_multisample(struct blorp_batch * batch,const struct blorp_params * params)943 blorp_emit_3dstate_multisample(struct blorp_batch *batch,
944                                const struct blorp_params *params)
945 {
946    blorp_emit(batch, GENX(3DSTATE_MULTISAMPLE), ms) {
947       ms.NumberofMultisamples       = __builtin_ffs(params->num_samples) - 1;
948       ms.PixelLocation              = CENTER;
949    }
950 }
951 
952 static void
blorp_emit_pipeline(struct blorp_batch * batch,const struct blorp_params * params)953 blorp_emit_pipeline(struct blorp_batch *batch,
954                     const struct blorp_params *params)
955 {
956    enum intel_urb_deref_block_size urb_deref_block_size;
957    emit_urb_config(batch, params, &urb_deref_block_size);
958 
959    if (params->wm_prog_data) {
960       blorp_emit_blend_state(batch, params);
961    }
962    blorp_emit_color_calc_state(batch, params);
963    blorp_emit_depth_stencil_state(batch, params);
964 
965    UNUSED uint32_t mocs = isl_mocs(batch->blorp->isl_dev, 0, false);
966 
967 #if GFX_VER >= 12
968    blorp_emit(batch, GENX(3DSTATE_CONSTANT_ALL), pc) {
969       /* Update empty push constants for all stages (bitmask = 11111b) */
970       pc.ShaderUpdateEnable = 0x1f;
971       pc.MOCS = mocs;
972    }
973 #else
974    blorp_emit(batch, GENX(3DSTATE_CONSTANT_VS), xs) { xs.MOCS = mocs; }
975    blorp_emit(batch, GENX(3DSTATE_CONSTANT_HS), xs) { xs.MOCS = mocs; }
976    blorp_emit(batch, GENX(3DSTATE_CONSTANT_DS), xs) { xs.MOCS = mocs; }
977    blorp_emit(batch, GENX(3DSTATE_CONSTANT_GS), xs) { xs.MOCS = mocs; }
978    blorp_emit(batch, GENX(3DSTATE_CONSTANT_PS), xs) { xs.MOCS = mocs; }
979 #endif
980 
981    if (params->src.enabled)
982       blorp_emit_sampler_state_ps(batch);
983 
984    blorp_emit_3dstate_multisample(batch, params);
985 
986    blorp_emit(batch, GENX(3DSTATE_SAMPLE_MASK), mask) {
987       mask.SampleMask = (1 << params->num_samples) - 1;
988    }
989 
990    /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
991     * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
992     *
993     *   [DevSNB] A pipeline flush must be programmed prior to a
994     *   3DSTATE_VS command that causes the VS Function Enable to
995     *   toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
996     *   command with CS stall bit set and a post sync operation.
997     *
998     * We've already done one at the start of the BLORP operation.
999     */
1000    blorp_emit_vs_config(batch, params);
1001    blorp_emit(batch, GENX(3DSTATE_HS), hs);
1002    blorp_emit(batch, GENX(3DSTATE_TE), te);
1003    blorp_emit(batch, GENX(3DSTATE_DS), DS);
1004    blorp_emit(batch, GENX(3DSTATE_STREAMOUT), so);
1005    blorp_emit(batch, GENX(3DSTATE_GS), gs);
1006 
1007    blorp_emit(batch, GENX(3DSTATE_CLIP), clip) {
1008       clip.PerspectiveDivideDisable = true;
1009    }
1010 
1011    blorp_emit_sf_config(batch, params, urb_deref_block_size);
1012    blorp_emit_ps_config(batch, params);
1013 
1014    blorp_emit_cc_viewport(batch);
1015 
1016 #if GFX_VER >= 12
1017    /* Disable Primitive Replication. */
1018    blorp_emit(batch, GENX(3DSTATE_PRIMITIVE_REPLICATION), pr);
1019 #endif
1020 
1021    if (batch->blorp->config.use_mesh_shading) {
1022 #if GFX_VERx10 >= 125
1023       blorp_emit(batch, GENX(3DSTATE_MESH_CONTROL), zero);
1024       blorp_emit(batch, GENX(3DSTATE_TASK_CONTROL), zero);
1025 #endif
1026    }
1027 }
1028 
1029 /******** This is the end of the pipeline setup code ********/
1030 
1031 static void
blorp_emit_memcpy(struct blorp_batch * batch,struct blorp_address dst,struct blorp_address src,uint32_t size)1032 blorp_emit_memcpy(struct blorp_batch *batch,
1033                   struct blorp_address dst,
1034                   struct blorp_address src,
1035                   uint32_t size)
1036 {
1037    assert(size % 4 == 0);
1038 
1039    for (unsigned dw = 0; dw < size; dw += 4) {
1040       blorp_emit(batch, GENX(MI_COPY_MEM_MEM), cp) {
1041          cp.DestinationMemoryAddress = dst;
1042          cp.SourceMemoryAddress = src;
1043       }
1044       dst.offset += 4;
1045       src.offset += 4;
1046    }
1047 }
1048 
1049 static void
blorp_emit_surface_state(struct blorp_batch * batch,const struct blorp_surface_info * surface,UNUSED enum isl_aux_op aux_op,void * state,uint32_t state_offset,uint8_t color_write_disable,bool is_render_target)1050 blorp_emit_surface_state(struct blorp_batch *batch,
1051                          const struct blorp_surface_info *surface,
1052                          UNUSED enum isl_aux_op aux_op,
1053                          void *state, uint32_t state_offset,
1054                          uint8_t color_write_disable,
1055                          bool is_render_target)
1056 {
1057    const struct isl_device *isl_dev = batch->blorp->isl_dev;
1058    struct isl_surf surf = surface->surf;
1059 
1060    if (surf.dim == ISL_SURF_DIM_1D &&
1061        surf.dim_layout == ISL_DIM_LAYOUT_GFX4_2D) {
1062       assert(surf.logical_level0_px.height == 1);
1063       surf.dim = ISL_SURF_DIM_2D;
1064    }
1065 
1066    if (isl_aux_usage_has_hiz(surface->aux_usage)) {
1067       /* BLORP doesn't render with depth so we can't use HiZ */
1068       assert(!is_render_target);
1069       /* We can't reinterpret HiZ */
1070       assert(surface->surf.format == surface->view.format);
1071    }
1072 
1073    enum isl_aux_usage aux_usage = surface->aux_usage;
1074 
1075    /* On gfx12, implicit CCS has no aux buffer */
1076    bool use_aux_address = (aux_usage != ISL_AUX_USAGE_NONE) &&
1077                           (surface->aux_addr.buffer != NULL);
1078 
1079    const bool use_clear_address =
1080       GFX_VER >= 10 && (surface->clear_color_addr.buffer != NULL);
1081 
1082    isl_surf_fill_state(batch->blorp->isl_dev, state,
1083                        .surf = &surf, .view = &surface->view,
1084                        .aux_surf = &surface->aux_surf, .aux_usage = aux_usage,
1085                        .address =
1086                           blorp_get_surface_address(batch, surface->addr),
1087                        .aux_address = !use_aux_address ? 0 :
1088                           blorp_get_surface_address(batch, surface->aux_addr),
1089                        .clear_address = !use_clear_address ? 0 :
1090                           blorp_get_surface_address(batch,
1091                                                     surface->clear_color_addr),
1092                        .mocs = surface->addr.mocs,
1093                        .clear_color = surface->clear_color,
1094                        .use_clear_address = use_clear_address);
1095 
1096    blorp_surface_reloc(batch, state_offset + isl_dev->ss.addr_offset,
1097                        surface->addr, 0);
1098 
1099    if (use_aux_address) {
1100       /* On gfx7 and prior, the bottom 12 bits of the MCS base address are
1101        * used to store other information.  This should be ok, however, because
1102        * surface buffer addresses are always 4K page alinged.
1103        */
1104       assert((surface->aux_addr.offset & 0xfff) == 0);
1105       uint32_t *aux_addr = state + isl_dev->ss.aux_addr_offset;
1106       blorp_surface_reloc(batch, state_offset + isl_dev->ss.aux_addr_offset,
1107                           surface->aux_addr, *aux_addr);
1108    }
1109 
1110    if (aux_usage != ISL_AUX_USAGE_NONE && surface->clear_color_addr.buffer) {
1111 #if GFX_VER >= 10
1112       assert((surface->clear_color_addr.offset & 0x3f) == 0);
1113       uint32_t *clear_addr = state + isl_dev->ss.clear_color_state_offset;
1114       blorp_surface_reloc(batch, state_offset +
1115                           isl_dev->ss.clear_color_state_offset,
1116                           surface->clear_color_addr, *clear_addr);
1117 #else
1118       /* Fast clears just whack the AUX surface and don't actually use the
1119        * clear color for anything.  We can avoid the MI memcpy on that case.
1120        */
1121       if (aux_op != ISL_AUX_OP_FAST_CLEAR) {
1122          struct blorp_address dst_addr = blorp_get_surface_base_address(batch);
1123          dst_addr.offset += state_offset + isl_dev->ss.clear_value_offset;
1124          blorp_emit_memcpy(batch, dst_addr, surface->clear_color_addr,
1125                            isl_dev->ss.clear_value_size);
1126       }
1127 #endif
1128    }
1129 
1130    blorp_flush_range(batch, state, GENX(RENDER_SURFACE_STATE_length) * 4);
1131 }
1132 
1133 static void
blorp_emit_null_surface_state(struct blorp_batch * batch,const struct blorp_surface_info * surface,uint32_t * state)1134 blorp_emit_null_surface_state(struct blorp_batch *batch,
1135                               const struct blorp_surface_info *surface,
1136                               uint32_t *state)
1137 {
1138    struct GENX(RENDER_SURFACE_STATE) ss = {
1139       .SurfaceType = SURFTYPE_NULL,
1140       .SurfaceFormat = ISL_FORMAT_R8G8B8A8_UNORM,
1141       .Width = surface->surf.logical_level0_px.width - 1,
1142       .Height = surface->surf.logical_level0_px.height - 1,
1143       .MIPCountLOD = surface->view.base_level,
1144       .MinimumArrayElement = surface->view.base_array_layer,
1145       .Depth = surface->view.array_len - 1,
1146       .RenderTargetViewExtent = surface->view.array_len - 1,
1147       .NumberofMultisamples = ffs(surface->surf.samples) - 1,
1148       .MOCS = isl_mocs(batch->blorp->isl_dev, 0, false),
1149 
1150       .SurfaceArray = surface->surf.dim != ISL_SURF_DIM_3D,
1151 
1152 #if GFX_VERx10 >= 125
1153       .TileMode = TILE4,
1154 #else
1155       .TileMode = YMAJOR,
1156 #endif
1157    };
1158 
1159    GENX(RENDER_SURFACE_STATE_pack)(NULL, state, &ss);
1160 
1161    blorp_flush_range(batch, state, GENX(RENDER_SURFACE_STATE_length) * 4);
1162 }
1163 
1164 static uint32_t
blorp_setup_binding_table(struct blorp_batch * batch,const struct blorp_params * params)1165 blorp_setup_binding_table(struct blorp_batch *batch,
1166                            const struct blorp_params *params)
1167 {
1168    const struct isl_device *isl_dev = batch->blorp->isl_dev;
1169    uint32_t surface_offsets[2], bind_offset = 0;
1170    void *surface_maps[2];
1171 
1172    if (params->use_pre_baked_binding_table) {
1173       bind_offset = params->pre_baked_binding_table_offset;
1174    } else {
1175       unsigned num_surfaces = 1 + params->src.enabled;
1176       if (!blorp_alloc_binding_table(batch, num_surfaces,
1177                                      isl_dev->ss.size, isl_dev->ss.align,
1178                                      &bind_offset, surface_offsets, surface_maps))
1179          return 0;
1180 
1181       if (params->dst.enabled) {
1182          blorp_emit_surface_state(batch, &params->dst,
1183                                   params->fast_clear_op,
1184                                   surface_maps[BLORP_RENDERBUFFER_BT_INDEX],
1185                                   surface_offsets[BLORP_RENDERBUFFER_BT_INDEX],
1186                                   params->color_write_disable, true);
1187       } else {
1188          assert(params->depth.enabled || params->stencil.enabled);
1189          const struct blorp_surface_info *surface =
1190             params->depth.enabled ? &params->depth : &params->stencil;
1191          blorp_emit_null_surface_state(batch, surface,
1192                                        surface_maps[BLORP_RENDERBUFFER_BT_INDEX]);
1193       }
1194 
1195       if (params->src.enabled) {
1196          blorp_emit_surface_state(batch, &params->src,
1197                                   params->fast_clear_op,
1198                                   surface_maps[BLORP_TEXTURE_BT_INDEX],
1199                                   surface_offsets[BLORP_TEXTURE_BT_INDEX],
1200                                   0, false);
1201       }
1202    }
1203 
1204    return bind_offset;
1205 }
1206 
1207 static void
blorp_emit_btp(struct blorp_batch * batch,uint32_t bind_offset)1208 blorp_emit_btp(struct blorp_batch *batch, uint32_t bind_offset)
1209 {
1210    blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_VS), bt);
1211    blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_HS), bt);
1212    blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_DS), bt);
1213    blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_GS), bt);
1214 
1215    blorp_emit(batch, GENX(3DSTATE_BINDING_TABLE_POINTERS_PS), bt) {
1216       bt.PointertoPSBindingTable =
1217          blorp_binding_table_offset_to_pointer(batch, bind_offset);
1218    }
1219 }
1220 
1221 static void
blorp_emit_depth_stencil_config(struct blorp_batch * batch,const struct blorp_params * params)1222 blorp_emit_depth_stencil_config(struct blorp_batch *batch,
1223                                 const struct blorp_params *params)
1224 {
1225    const struct isl_device *isl_dev = batch->blorp->isl_dev;
1226 
1227    uint32_t *dw = blorp_emit_dwords(batch, isl_dev->ds.size / 4);
1228    if (dw == NULL)
1229       return;
1230 
1231    struct isl_depth_stencil_hiz_emit_info info = { };
1232 
1233    if (params->depth.enabled) {
1234       info.view = &params->depth.view;
1235       info.mocs = params->depth.addr.mocs;
1236    } else if (params->stencil.enabled) {
1237       info.view = &params->stencil.view;
1238       info.mocs = params->stencil.addr.mocs;
1239    } else {
1240       info.mocs = isl_mocs(isl_dev, 0, false);
1241    }
1242 
1243    if (params->depth.enabled) {
1244       info.depth_surf = &params->depth.surf;
1245 
1246       info.depth_address =
1247          blorp_emit_reloc(batch, dw + isl_dev->ds.depth_offset / 4,
1248                           params->depth.addr, 0);
1249 
1250       info.hiz_usage = params->depth.aux_usage;
1251       if (isl_aux_usage_has_hiz(info.hiz_usage)) {
1252          info.hiz_surf = &params->depth.aux_surf;
1253 
1254          struct blorp_address hiz_address = params->depth.aux_addr;
1255 
1256          info.hiz_address =
1257             blorp_emit_reloc(batch, dw + isl_dev->ds.hiz_offset / 4,
1258                              hiz_address, 0);
1259 
1260          info.depth_clear_value = params->depth.clear_color.f32[0];
1261       }
1262    }
1263 
1264    if (params->stencil.enabled) {
1265       info.stencil_surf = &params->stencil.surf;
1266 
1267       info.stencil_aux_usage = params->stencil.aux_usage;
1268       struct blorp_address stencil_address = params->stencil.addr;
1269 
1270       info.stencil_address =
1271          blorp_emit_reloc(batch, dw + isl_dev->ds.stencil_offset / 4,
1272                           stencil_address, 0);
1273    }
1274 
1275    isl_emit_depth_stencil_hiz_s(isl_dev, dw, &info);
1276 
1277 #if GFX_VER >= 11
1278    /* Wa_1408224581
1279     *
1280     * Workaround: Gfx12LP Astep only An additional pipe control with
1281     * post-sync = store dword operation would be required.( w/a is to
1282     * have an additional pipe control after the stencil state whenever
1283     * the surface state bits of this state is changing).
1284     *
1285     * This also seems sufficient to handle Wa_14014097488.
1286     */
1287    blorp_emit(batch, GENX(PIPE_CONTROL), pc) {
1288       pc.PostSyncOperation = WriteImmediateData;
1289       pc.Address = blorp_get_workaround_address(batch);
1290    }
1291 #endif
1292 }
1293 
1294 /* Emits the Optimized HiZ sequence specified in the BDW+ PRMs. The
1295  * depth/stencil buffer extents are ignored to handle APIs which perform
1296  * clearing operations without such information.
1297  * */
1298 static void
blorp_emit_gfx8_hiz_op(struct blorp_batch * batch,const struct blorp_params * params)1299 blorp_emit_gfx8_hiz_op(struct blorp_batch *batch,
1300                        const struct blorp_params *params)
1301 {
1302    /* We should be performing an operation on a depth or stencil buffer.
1303     */
1304    assert(params->depth.enabled || params->stencil.enabled);
1305 
1306    blorp_measure_start(batch, params);
1307 
1308    /* The stencil buffer should only be enabled if a fast clear operation is
1309     * requested.
1310     */
1311    if (params->stencil.enabled)
1312       assert(params->hiz_op == ISL_AUX_OP_FAST_CLEAR);
1313 
1314    /* From the BDW PRM Volume 2, 3DSTATE_WM_HZ_OP:
1315     *
1316     * 3DSTATE_MULTISAMPLE packet must be used prior to this packet to change
1317     * the Number of Multisamples. This packet must not be used to change
1318     * Number of Multisamples in a rendering sequence.
1319     *
1320     * Since HIZ may be the first thing in a batch buffer, play safe and always
1321     * emit 3DSTATE_MULTISAMPLE.
1322     */
1323    blorp_emit_3dstate_multisample(batch, params);
1324 
1325    /* From the BDW PRM Volume 7, Depth Buffer Clear:
1326     *
1327     *    The clear value must be between the min and max depth values
1328     *    (inclusive) defined in the CC_VIEWPORT. If the depth buffer format is
1329     *    D32_FLOAT, then +/-DENORM values are also allowed.
1330     *
1331     * Set the bounds to match our hardware limits, [0.0, 1.0].
1332     */
1333    if (params->depth.enabled && params->hiz_op == ISL_AUX_OP_FAST_CLEAR) {
1334       assert(params->depth.clear_color.f32[0] >= 0.0f);
1335       assert(params->depth.clear_color.f32[0] <= 1.0f);
1336       blorp_emit_cc_viewport(batch);
1337    }
1338 
1339    /* According to the SKL PRM formula for WM_INT::ThreadDispatchEnable, the
1340     * 3DSTATE_WM::ForceThreadDispatchEnable field can force WM thread dispatch
1341     * even when WM_HZ_OP is active.  However, WM thread dispatch is normally
1342     * disabled for HiZ ops and it appears that force-enabling it can lead to
1343     * GPU hangs on at least Skylake.  Since we don't know the current state of
1344     * the 3DSTATE_WM packet, just emit a dummy one prior to 3DSTATE_WM_HZ_OP.
1345     */
1346    blorp_emit(batch, GENX(3DSTATE_WM), wm);
1347 
1348    /* If we can't alter the depth stencil config and multiple layers are
1349     * involved, the HiZ op will fail. This is because the op requires that a
1350     * new config is emitted for each additional layer.
1351     */
1352    if (batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL) {
1353       assert(params->num_layers <= 1);
1354    } else {
1355       blorp_emit_depth_stencil_config(batch, params);
1356    }
1357 
1358    /* TODO - If we ever start using 3DSTATE_WM_HZ_OP::StencilBufferResolveEnable
1359     * we need to implement required steps, flushes documented in Wa_1605967699.
1360     */
1361    blorp_emit(batch, GENX(3DSTATE_WM_HZ_OP), hzp) {
1362       switch (params->hiz_op) {
1363       case ISL_AUX_OP_FAST_CLEAR:
1364          hzp.StencilBufferClearEnable = params->stencil.enabled;
1365          hzp.DepthBufferClearEnable = params->depth.enabled;
1366          hzp.StencilClearValue = params->stencil_ref;
1367          hzp.FullSurfaceDepthandStencilClear = params->full_surface_hiz_op;
1368 #if GFX_VER >= 20
1369          hzp.DepthClearValue = params->depth.clear_color.f32[0];
1370 #endif
1371          break;
1372       case ISL_AUX_OP_FULL_RESOLVE:
1373          assert(params->full_surface_hiz_op);
1374          hzp.DepthBufferResolveEnable = true;
1375          break;
1376       case ISL_AUX_OP_AMBIGUATE:
1377          assert(params->full_surface_hiz_op);
1378          hzp.HierarchicalDepthBufferResolveEnable = true;
1379          break;
1380       case ISL_AUX_OP_PARTIAL_RESOLVE:
1381       case ISL_AUX_OP_NONE:
1382          unreachable("Invalid HIZ op");
1383       }
1384 
1385       hzp.NumberofMultisamples = ffs(params->num_samples) - 1;
1386       hzp.SampleMask = 0xFFFF;
1387 
1388       /* Due to a hardware issue, this bit MBZ */
1389       assert(hzp.ScissorRectangleEnable == false);
1390 
1391       /* Contrary to the HW docs both fields are inclusive */
1392       hzp.ClearRectangleXMin = params->x0;
1393       hzp.ClearRectangleYMin = params->y0;
1394 
1395       /* Contrary to the HW docs both fields are exclusive */
1396       hzp.ClearRectangleXMax = params->x1;
1397       hzp.ClearRectangleYMax = params->y1;
1398    }
1399 
1400    /* PIPE_CONTROL w/ all bits clear except for “Post-Sync Operation” must set
1401     * to “Write Immediate Data” enabled.
1402     */
1403    blorp_emit(batch, GENX(PIPE_CONTROL), pc) {
1404       pc.PostSyncOperation = WriteImmediateData;
1405       pc.Address = blorp_get_workaround_address(batch);
1406    }
1407 
1408    blorp_emit(batch, GENX(3DSTATE_WM_HZ_OP), hzp);
1409 
1410    blorp_measure_end(batch, params);
1411 }
1412 
1413 static void
blorp_update_clear_color(UNUSED struct blorp_batch * batch,const struct blorp_surface_info * info)1414 blorp_update_clear_color(UNUSED struct blorp_batch *batch,
1415                          const struct blorp_surface_info *info)
1416 {
1417    assert(info->clear_color_addr.buffer != NULL);
1418 #if GFX_VER == 11
1419    /* 2 QWORDS */
1420    const unsigned inlinedata_dw = 2 * 2;
1421    const unsigned num_dwords = GENX(MI_ATOMIC_length) + inlinedata_dw;
1422 
1423    struct blorp_address clear_addr = info->clear_color_addr;
1424    uint32_t *dw = blorp_emitn(batch, GENX(MI_ATOMIC), num_dwords,
1425                               .DataSize = MI_ATOMIC_QWORD,
1426                               .ATOMICOPCODE = MI_ATOMIC_OP_MOVE8B,
1427                               .InlineData = true,
1428                               .MemoryAddress = clear_addr);
1429    /* dw starts at dword 1, but we need to fill dwords 3 and 5 */
1430    dw[2] = info->clear_color.u32[0];
1431    dw[3] = 0;
1432    dw[4] = info->clear_color.u32[1];
1433    dw[5] = 0;
1434 
1435    clear_addr.offset += 8;
1436    dw = blorp_emitn(batch, GENX(MI_ATOMIC), num_dwords,
1437                     .DataSize = MI_ATOMIC_QWORD,
1438                     .ATOMICOPCODE = MI_ATOMIC_OP_MOVE8B,
1439                     .CSSTALL = true,
1440                     .ReturnDataControl = true,
1441                     .InlineData = true,
1442                     .MemoryAddress = clear_addr);
1443    /* dw starts at dword 1, but we need to fill dwords 3 and 5 */
1444    dw[2] = info->clear_color.u32[2];
1445    dw[3] = 0;
1446    dw[4] = info->clear_color.u32[3];
1447    dw[5] = 0;
1448 
1449 #else
1450 
1451    /* According to Wa_2201730850, in the Clear Color Programming Note under
1452     * the Red channel, "Software shall write the converted Depth Clear to this
1453     * dword." The only depth formats listed under the red channel are IEEE_FP
1454     * and UNORM24_X8. These two requirements are incompatible with the UNORM16
1455     * depth format, so just ignore that case and simply perform the conversion
1456     * for all depth formats.
1457     */
1458    union isl_color_value fixed_color = info->clear_color;
1459    if (GFX_VER == 12 && isl_surf_usage_is_depth(info->surf.usage)) {
1460       isl_color_value_pack(&info->clear_color, info->surf.format,
1461                            fixed_color.u32);
1462    }
1463 
1464    for (int i = 0; i < 4; i++) {
1465       blorp_emit(batch, GENX(MI_STORE_DATA_IMM), sdi) {
1466          sdi.Address = info->clear_color_addr;
1467          sdi.Address.offset += i * 4;
1468          sdi.ImmediateData = fixed_color.u32[i];
1469 #if GFX_VER >= 12
1470          if (i == 3)
1471             sdi.ForceWriteCompletionCheck = true;
1472 #endif
1473       }
1474    }
1475 
1476    /* The RENDER_SURFACE_STATE::ClearColor field states that software should
1477     * write the converted depth value 16B after the clear address:
1478     *
1479     *    3D Sampler will always fetch clear depth from the location 16-bytes
1480     *    above this address, where the clear depth, converted to native
1481     *    surface format by software, will be stored.
1482     *
1483     */
1484 #if GFX_VER >= 12
1485    if (isl_surf_usage_is_depth(info->surf.usage)) {
1486       blorp_emit(batch, GENX(MI_STORE_DATA_IMM), sdi) {
1487          sdi.Address = info->clear_color_addr;
1488          sdi.Address.offset += 4 * 4;
1489          sdi.ImmediateData = fixed_color.u32[0];
1490          sdi.ForceWriteCompletionCheck = true;
1491       }
1492    }
1493 #endif
1494 
1495 #endif
1496 }
1497 
1498 static bool
blorp_uses_bti_rt_writes(const struct blorp_batch * batch,const struct blorp_params * params)1499 blorp_uses_bti_rt_writes(const struct blorp_batch *batch, const struct blorp_params *params)
1500 {
1501    if (batch->flags & (BLORP_BATCH_USE_BLITTER | BLORP_BATCH_USE_COMPUTE))
1502       return false;
1503 
1504    /* HIZ clears use WM_HZ ops rather than a clear shader using RT writes. */
1505    return params->hiz_op == ISL_AUX_OP_NONE;
1506 }
1507 
1508 static void
blorp_exec_3d(struct blorp_batch * batch,const struct blorp_params * params)1509 blorp_exec_3d(struct blorp_batch *batch, const struct blorp_params *params)
1510 {
1511    if (!(batch->flags & BLORP_BATCH_NO_UPDATE_CLEAR_COLOR)) {
1512       if (params->fast_clear_op == ISL_AUX_OP_FAST_CLEAR &&
1513           params->dst.clear_color_addr.buffer != NULL) {
1514          blorp_update_clear_color(batch, &params->dst);
1515       }
1516 
1517       if (params->hiz_op == ISL_AUX_OP_FAST_CLEAR &&
1518           params->depth.clear_color_addr.buffer != NULL) {
1519          blorp_update_clear_color(batch, &params->depth);
1520       }
1521    }
1522 
1523    if (params->hiz_op != ISL_AUX_OP_NONE) {
1524       blorp_emit_gfx8_hiz_op(batch, params);
1525       return;
1526    }
1527 
1528    blorp_emit_vertex_buffers(batch, params);
1529    blorp_emit_vertex_elements(batch, params);
1530 
1531    blorp_emit_pipeline(batch, params);
1532 
1533    blorp_emit_btp(batch, blorp_setup_binding_table(batch, params));
1534 
1535    if (!(batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL))
1536       blorp_emit_depth_stencil_config(batch, params);
1537 
1538    const UNUSED bool use_tbimr = false;
1539    blorp_emit_pre_draw(batch, params);
1540    blorp_emit(batch, GENX(3DPRIMITIVE), prim) {
1541       prim.VertexAccessType = SEQUENTIAL;
1542       prim.PrimitiveTopologyType = _3DPRIM_RECTLIST;
1543       prim.PredicateEnable = batch->flags & BLORP_BATCH_PREDICATE_ENABLE;
1544 #if GFX_VERx10 >= 125
1545       prim.TBIMREnable = use_tbimr;
1546 #endif
1547       prim.VertexCountPerInstance = 3;
1548       prim.InstanceCount = params->num_layers;
1549    }
1550    blorp_emit_post_draw(batch, params);
1551 }
1552 
1553 static void
blorp_get_compute_push_const(struct blorp_batch * batch,const struct blorp_params * params,uint32_t threads,uint32_t * state_offset,unsigned * state_size)1554 blorp_get_compute_push_const(struct blorp_batch *batch,
1555                              const struct blorp_params *params,
1556                              uint32_t threads,
1557                              uint32_t *state_offset,
1558                              unsigned *state_size)
1559 {
1560    const struct brw_cs_prog_data *cs_prog_data = params->cs_prog_data;
1561    const unsigned push_const_size =
1562       ALIGN(brw_cs_push_const_total_size(cs_prog_data, threads), 64);
1563    assert(cs_prog_data->push.cross_thread.size +
1564           cs_prog_data->push.per_thread.size == sizeof(params->wm_inputs));
1565 
1566    if (push_const_size == 0) {
1567       *state_offset = 0;
1568       *state_size = 0;
1569       return;
1570    }
1571 
1572    uint32_t push_const_offset;
1573    uint32_t *push_const =
1574       GFX_VERx10 >= 125 ?
1575       blorp_alloc_general_state(batch, push_const_size, 64,
1576                                 &push_const_offset) :
1577       blorp_alloc_dynamic_state(batch, push_const_size, 64,
1578                                 &push_const_offset);
1579    memset(push_const, 0x0, push_const_size);
1580 
1581    void *dst = push_const;
1582    const void *src = (char *)&params->wm_inputs;
1583 
1584    if (cs_prog_data->push.cross_thread.size > 0) {
1585       memcpy(dst, src, cs_prog_data->push.cross_thread.size);
1586       dst += cs_prog_data->push.cross_thread.size;
1587       src += cs_prog_data->push.cross_thread.size;
1588    }
1589 
1590    assert(GFX_VERx10 < 125 || cs_prog_data->push.per_thread.size == 0);
1591 #if GFX_VERx10 < 125
1592    if (cs_prog_data->push.per_thread.size > 0) {
1593       for (unsigned t = 0; t < threads; t++) {
1594          memcpy(dst, src, (cs_prog_data->push.per_thread.dwords - 1) * 4);
1595 
1596          uint32_t *subgroup_id = dst + cs_prog_data->push.per_thread.size - 4;
1597          *subgroup_id = t;
1598 
1599          dst += cs_prog_data->push.per_thread.size;
1600       }
1601    }
1602 #endif
1603 
1604    *state_offset = push_const_offset;
1605    *state_size = push_const_size;
1606 }
1607 
1608 static void
blorp_exec_compute(struct blorp_batch * batch,const struct blorp_params * params)1609 blorp_exec_compute(struct blorp_batch *batch, const struct blorp_params *params)
1610 {
1611    assert(!(batch->flags & BLORP_BATCH_NO_UPDATE_CLEAR_COLOR));
1612    assert(!(batch->flags & BLORP_BATCH_PREDICATE_ENABLE));
1613    assert(params->hiz_op == ISL_AUX_OP_NONE);
1614 
1615    blorp_measure_start(batch, params);
1616 
1617    const struct intel_device_info *devinfo = batch->blorp->compiler->brw->devinfo;
1618    const struct brw_cs_prog_data *cs_prog_data = params->cs_prog_data;
1619    const struct brw_stage_prog_data *prog_data = &cs_prog_data->base;
1620    const struct intel_cs_dispatch_info dispatch =
1621       brw_cs_get_dispatch_info(devinfo, cs_prog_data, NULL);
1622 
1623    uint32_t group_x0 = params->x0 / cs_prog_data->local_size[0];
1624    uint32_t group_y0 = params->y0 / cs_prog_data->local_size[1];
1625    uint32_t group_z0 = params->dst.z_offset;
1626    uint32_t group_x1 = DIV_ROUND_UP(params->x1, cs_prog_data->local_size[0]);
1627    uint32_t group_y1 = DIV_ROUND_UP(params->y1, cs_prog_data->local_size[1]);
1628    assert(params->num_layers >= 1);
1629    uint32_t group_z1 = params->dst.z_offset + params->num_layers;
1630    assert(cs_prog_data->local_size[2] == 1);
1631 
1632 #if GFX_VERx10 >= 125
1633    assert(cs_prog_data->push.per_thread.regs == 0);
1634    blorp_emit(batch, GENX(COMPUTE_WALKER), cw) {
1635       cw.SIMDSize                       = dispatch.simd_size / 16;
1636       cw.LocalXMaximum                  = cs_prog_data->local_size[0] - 1;
1637       cw.LocalYMaximum                  = cs_prog_data->local_size[1] - 1;
1638       cw.LocalZMaximum                  = cs_prog_data->local_size[2] - 1;
1639       cw.ThreadGroupIDStartingX         = group_x0;
1640       cw.ThreadGroupIDStartingY         = group_y0;
1641       cw.ThreadGroupIDStartingZ         = group_z0;
1642       cw.ThreadGroupIDXDimension        = group_x1;
1643       cw.ThreadGroupIDYDimension        = group_y1;
1644       cw.ThreadGroupIDZDimension        = group_z1;
1645       cw.ExecutionMask                  = 0xffffffff;
1646       cw.PostSync.MOCS                  = isl_mocs(batch->blorp->isl_dev, 0, false);
1647 
1648       uint32_t surfaces_offset = blorp_setup_binding_table(batch, params);
1649 
1650       uint32_t samplers_offset =
1651          params->src.enabled ? blorp_emit_sampler_state(batch) : 0;
1652 
1653       uint32_t push_const_offset;
1654       unsigned push_const_size;
1655       blorp_get_compute_push_const(batch, params, dispatch.threads,
1656                                    &push_const_offset, &push_const_size);
1657       cw.IndirectDataStartAddress       = push_const_offset;
1658       cw.IndirectDataLength             = push_const_size;
1659 
1660 #if GFX_VERx10 >= 125
1661       cw.GenerateLocalID                = cs_prog_data->generate_local_id != 0;
1662       cw.EmitLocal                      = cs_prog_data->generate_local_id;
1663       cw.WalkOrder                      = cs_prog_data->walk_order;
1664       cw.TileLayout = cs_prog_data->walk_order == INTEL_WALK_ORDER_YXZ ?
1665                       TileY32bpe : Linear;
1666 #endif
1667 
1668       cw.InterfaceDescriptor = (struct GENX(INTERFACE_DESCRIPTOR_DATA)) {
1669          .KernelStartPointer = params->cs_prog_kernel,
1670          .SamplerStatePointer = samplers_offset,
1671          .SamplerCount = params->src.enabled ? 1 : 0,
1672          .BindingTableEntryCount = params->src.enabled ? 2 : 1,
1673          .BindingTablePointer = surfaces_offset,
1674          .NumberofThreadsinGPGPUThreadGroup = dispatch.threads,
1675          .SharedLocalMemorySize =
1676             encode_slm_size(GFX_VER, prog_data->total_shared),
1677          .PreferredSLMAllocationSize = preferred_slm_allocation_size(devinfo),
1678          .NumberOfBarriers = cs_prog_data->uses_barrier,
1679       };
1680    }
1681 
1682 #else
1683 
1684    /* The MEDIA_VFE_STATE documentation for Gfx8+ says:
1685     *
1686     * "A stalling PIPE_CONTROL is required before MEDIA_VFE_STATE unless
1687     *  the only bits that are changed are scoreboard related: Scoreboard
1688     *  Enable, Scoreboard Type, Scoreboard Mask, Scoreboard * Delta. For
1689     *  these scoreboard related states, a MEDIA_STATE_FLUSH is sufficient."
1690     *
1691     * Earlier generations say "MI_FLUSH" instead of "stalling PIPE_CONTROL",
1692     * but MI_FLUSH isn't really a thing, so we assume they meant PIPE_CONTROL.
1693     */
1694    blorp_emit(batch, GENX(PIPE_CONTROL), pc) {
1695       pc.CommandStreamerStallEnable = true;
1696       pc.StallAtPixelScoreboard = true;
1697    }
1698 
1699    blorp_emit(batch, GENX(MEDIA_VFE_STATE), vfe) {
1700       assert(prog_data->total_scratch == 0);
1701       vfe.MaximumNumberofThreads =
1702          devinfo->max_cs_threads * devinfo->subslice_total - 1;
1703       vfe.NumberofURBEntries = 2;
1704 #if GFX_VER < 11
1705       vfe.ResetGatewayTimer =
1706          Resettingrelativetimerandlatchingtheglobaltimestamp;
1707 #endif
1708       vfe.URBEntryAllocationSize = 2;
1709 
1710       const uint32_t vfe_curbe_allocation =
1711          ALIGN(cs_prog_data->push.per_thread.regs * dispatch.threads +
1712                cs_prog_data->push.cross_thread.regs, 2);
1713       vfe.CURBEAllocationSize = vfe_curbe_allocation;
1714    }
1715 
1716    uint32_t push_const_offset;
1717    unsigned push_const_size;
1718    blorp_get_compute_push_const(batch, params, dispatch.threads,
1719                                 &push_const_offset, &push_const_size);
1720 
1721    blorp_emit(batch, GENX(MEDIA_CURBE_LOAD), curbe) {
1722       curbe.CURBETotalDataLength = push_const_size;
1723       curbe.CURBEDataStartAddress = push_const_offset;
1724    }
1725 
1726    uint32_t surfaces_offset = blorp_setup_binding_table(batch, params);
1727 
1728    uint32_t samplers_offset =
1729       params->src.enabled ? blorp_emit_sampler_state(batch) : 0;
1730 
1731    struct GENX(INTERFACE_DESCRIPTOR_DATA) idd = {
1732       .KernelStartPointer = params->cs_prog_kernel,
1733       .SamplerStatePointer = samplers_offset,
1734       .SamplerCount = params->src.enabled ? 1 : 0,
1735       .BindingTableEntryCount = params->src.enabled ? 2 : 1,
1736       .BindingTablePointer = surfaces_offset,
1737       .ConstantURBEntryReadLength = cs_prog_data->push.per_thread.regs,
1738       .NumberofThreadsinGPGPUThreadGroup = dispatch.threads,
1739       .SharedLocalMemorySize = encode_slm_size(GFX_VER,
1740                                                prog_data->total_shared),
1741       .BarrierEnable = cs_prog_data->uses_barrier,
1742       .CrossThreadConstantDataReadLength =
1743          cs_prog_data->push.cross_thread.regs,
1744    };
1745 
1746    uint32_t idd_offset;
1747    uint32_t size = GENX(INTERFACE_DESCRIPTOR_DATA_length) * sizeof(uint32_t);
1748    void *state = blorp_alloc_dynamic_state(batch, size, 64, &idd_offset);
1749    GENX(INTERFACE_DESCRIPTOR_DATA_pack)(NULL, state, &idd);
1750 
1751    blorp_emit(batch, GENX(MEDIA_INTERFACE_DESCRIPTOR_LOAD), mid) {
1752       mid.InterfaceDescriptorTotalLength        = size;
1753       mid.InterfaceDescriptorDataStartAddress   = idd_offset;
1754    }
1755 
1756    blorp_emit(batch, GENX(GPGPU_WALKER), ggw) {
1757       ggw.SIMDSize                     = dispatch.simd_size / 16;
1758       ggw.ThreadDepthCounterMaximum    = 0;
1759       ggw.ThreadHeightCounterMaximum   = 0;
1760       ggw.ThreadWidthCounterMaximum    = dispatch.threads - 1;
1761       ggw.ThreadGroupIDStartingX       = group_x0;
1762       ggw.ThreadGroupIDStartingY       = group_y0;
1763       ggw.ThreadGroupIDStartingResumeZ = group_z0;
1764       ggw.ThreadGroupIDXDimension      = group_x1;
1765       ggw.ThreadGroupIDYDimension      = group_y1;
1766       ggw.ThreadGroupIDZDimension      = group_z1;
1767       ggw.RightExecutionMask           = dispatch.right_mask;
1768       ggw.BottomExecutionMask          = 0xffffffff;
1769    }
1770 
1771 #endif
1772 
1773    blorp_measure_end(batch, params);
1774 }
1775 
1776 /* -----------------------------------------------------------------------
1777  * -- BLORP on blitter
1778  * -----------------------------------------------------------------------
1779  */
1780 
1781 #include "isl/isl_genX_helpers.h"
1782 
1783 #if GFX_VER >= 12
1784 static uint32_t
xy_bcb_tiling(const struct isl_surf * surf)1785 xy_bcb_tiling(const struct isl_surf *surf)
1786 {
1787    switch (surf->tiling) {
1788    case ISL_TILING_LINEAR:
1789       return XY_TILE_LINEAR;
1790 #if GFX_VERx10 >= 125
1791    case ISL_TILING_X:
1792       return XY_TILE_X;
1793    case ISL_TILING_4:
1794       return XY_TILE_4;
1795    case ISL_TILING_64:
1796    case ISL_TILING_64_XE2:
1797       return XY_TILE_64;
1798 #else
1799    case ISL_TILING_Y0:
1800       return XY_TILE_Y;
1801 #endif
1802    default:
1803       unreachable("Invalid tiling for XY_BLOCK_COPY_BLT");
1804    }
1805 }
1806 
1807 static uint32_t
xy_color_depth(const struct isl_format_layout * fmtl)1808 xy_color_depth(const struct isl_format_layout *fmtl)
1809 {
1810    switch (fmtl->bpb) {
1811    case 128: return XY_BPP_128_BIT;
1812    case  96: return XY_BPP_96_BIT;
1813    case  64: return XY_BPP_64_BIT;
1814    case  32: return XY_BPP_32_BIT;
1815    case  16: return XY_BPP_16_BIT;
1816    case   8: return XY_BPP_8_BIT;
1817    default:
1818       unreachable("Invalid bpp");
1819    }
1820 }
1821 #endif
1822 
1823 #if GFX_VERx10 >= 125
1824 static uint32_t
xy_bcb_surf_dim(const struct isl_surf * surf)1825 xy_bcb_surf_dim(const struct isl_surf *surf)
1826 {
1827    switch (surf->dim) {
1828    case ISL_SURF_DIM_1D:
1829       return XY_SURFTYPE_1D;
1830    case ISL_SURF_DIM_2D:
1831       return XY_SURFTYPE_2D;
1832    case ISL_SURF_DIM_3D:
1833       return XY_SURFTYPE_3D;
1834    default:
1835       unreachable("Invalid dimensionality for XY_BLOCK_COPY_BLT");
1836    }
1837 }
1838 
1839 static uint32_t
xy_bcb_surf_depth(const struct isl_surf * surf)1840 xy_bcb_surf_depth(const struct isl_surf *surf)
1841 {
1842    return surf->dim == ISL_SURF_DIM_3D ? surf->logical_level0_px.depth
1843                                        : surf->logical_level0_px.array_len;
1844 }
1845 
1846 static uint32_t
xy_aux_mode(const struct blorp_surface_info * info)1847 xy_aux_mode(const struct blorp_surface_info *info)
1848 {
1849    switch (info->aux_usage) {
1850    case ISL_AUX_USAGE_CCS_E:
1851    case ISL_AUX_USAGE_FCV_CCS_E:
1852    case ISL_AUX_USAGE_STC_CCS:
1853       return XY_CCS_E;
1854    case ISL_AUX_USAGE_NONE:
1855       return XY_NONE;
1856    default:
1857       unreachable("Unsupported aux mode");
1858    }
1859 }
1860 #endif
1861 
1862 UNUSED static void
blorp_xy_block_copy_blt(struct blorp_batch * batch,const struct blorp_params * params)1863 blorp_xy_block_copy_blt(struct blorp_batch *batch,
1864                         const struct blorp_params *params)
1865 {
1866 #if GFX_VER < 12
1867    unreachable("Blitter is only supported on Gfx12+");
1868 #else
1869    UNUSED const struct isl_device *isl_dev = batch->blorp->isl_dev;
1870 
1871    assert(batch->flags & BLORP_BATCH_USE_BLITTER);
1872    assert(!(batch->flags & BLORP_BATCH_NO_UPDATE_CLEAR_COLOR));
1873    assert(!(batch->flags & BLORP_BATCH_PREDICATE_ENABLE));
1874    assert(params->hiz_op == ISL_AUX_OP_NONE);
1875 
1876    assert(params->num_layers == 1);
1877    assert(params->dst.view.levels == 1);
1878    assert(params->src.view.levels == 1);
1879 
1880 #if GFX_VERx10 < 125
1881    assert(params->dst.view.base_array_layer == 0);
1882    assert(params->dst.z_offset == 0);
1883 #endif
1884 
1885    unsigned dst_x0 = params->x0;
1886    unsigned dst_x1 = params->x1;
1887    unsigned src_x0 =
1888       dst_x0 - params->wm_inputs.coord_transform[0].offset;
1889    ASSERTED unsigned src_x1 =
1890       dst_x1 - params->wm_inputs.coord_transform[0].offset;
1891    unsigned dst_y0 = params->y0;
1892    unsigned dst_y1 = params->y1;
1893    unsigned src_y0 =
1894       dst_y0 - params->wm_inputs.coord_transform[1].offset;
1895    ASSERTED unsigned src_y1 =
1896       dst_y1 - params->wm_inputs.coord_transform[1].offset;
1897 
1898    assert(src_x1 - src_x0 == dst_x1 - dst_x0);
1899    assert(src_y1 - src_y0 == dst_y1 - dst_y0);
1900 
1901    const struct isl_surf *src_surf = &params->src.surf;
1902    const struct isl_surf *dst_surf = &params->dst.surf;
1903 
1904    const struct isl_format_layout *fmtl =
1905       isl_format_get_layout(params->dst.view.format);
1906 
1907    if (fmtl->bpb == 96) {
1908       assert(src_surf->tiling == ISL_TILING_LINEAR &&
1909              dst_surf->tiling == ISL_TILING_LINEAR);
1910    }
1911 
1912    assert(src_surf->samples == 1);
1913    assert(dst_surf->samples == 1);
1914 
1915    unsigned dst_pitch_unit = dst_surf->tiling == ISL_TILING_LINEAR ? 1 : 4;
1916    unsigned src_pitch_unit = src_surf->tiling == ISL_TILING_LINEAR ? 1 : 4;
1917 
1918 #if GFX_VERx10 >= 125
1919    struct isl_extent3d src_align = isl_get_image_alignment(src_surf);
1920    struct isl_extent3d dst_align = isl_get_image_alignment(dst_surf);
1921 #endif
1922 
1923    blorp_emit(batch, GENX(XY_BLOCK_COPY_BLT), blt) {
1924       blt.ColorDepth = xy_color_depth(fmtl);
1925 
1926       blt.DestinationPitch = (dst_surf->row_pitch_B / dst_pitch_unit) - 1;
1927       blt.DestinationMOCS = params->dst.addr.mocs;
1928       blt.DestinationTiling = xy_bcb_tiling(dst_surf);
1929       blt.DestinationX1 = dst_x0;
1930       blt.DestinationY1 = dst_y0;
1931       blt.DestinationX2 = dst_x1;
1932       blt.DestinationY2 = dst_y1;
1933       blt.DestinationBaseAddress = params->dst.addr;
1934       blt.DestinationXOffset = params->dst.tile_x_sa;
1935       blt.DestinationYOffset = params->dst.tile_y_sa;
1936 
1937 #if GFX_VERx10 >= 125
1938       blt.DestinationSurfaceType = xy_bcb_surf_dim(dst_surf);
1939       blt.DestinationSurfaceWidth = dst_surf->logical_level0_px.w - 1;
1940       blt.DestinationSurfaceHeight = dst_surf->logical_level0_px.h - 1;
1941       blt.DestinationSurfaceDepth = xy_bcb_surf_depth(dst_surf) - 1;
1942       blt.DestinationArrayIndex =
1943          params->dst.view.base_array_layer + params->dst.z_offset;
1944       blt.DestinationSurfaceQPitch = isl_get_qpitch(dst_surf) >> 2;
1945       blt.DestinationLOD = params->dst.view.base_level;
1946       blt.DestinationMipTailStartLOD = dst_surf->miptail_start_level;
1947       blt.DestinationHorizontalAlign = isl_encode_halign(dst_align.width);
1948       blt.DestinationVerticalAlign = isl_encode_valign(dst_align.height);
1949       /* XY_BLOCK_COPY_BLT only supports AUX_CCS. */
1950       blt.DestinationDepthStencilResource =
1951          params->dst.aux_usage == ISL_AUX_USAGE_STC_CCS;
1952       blt.DestinationTargetMemory =
1953          params->dst.addr.local_hint ? XY_MEM_LOCAL : XY_MEM_SYSTEM;
1954 
1955       if (params->dst.aux_usage != ISL_AUX_USAGE_NONE) {
1956          blt.DestinationAuxiliarySurfaceMode = xy_aux_mode(&params->dst);
1957          blt.DestinationCompressionEnable = true;
1958          blt.DestinationCompressionFormat =
1959             isl_get_render_compression_format(dst_surf->format);
1960          blt.DestinationClearValueEnable = !!params->dst.clear_color_addr.buffer;
1961          blt.DestinationClearAddress = params->dst.clear_color_addr;
1962       }
1963 #endif
1964 
1965       blt.SourceX1 = src_x0;
1966       blt.SourceY1 = src_y0;
1967       blt.SourcePitch = (src_surf->row_pitch_B / src_pitch_unit) - 1;
1968       blt.SourceMOCS = params->src.addr.mocs;
1969       blt.SourceTiling = xy_bcb_tiling(src_surf);
1970       blt.SourceBaseAddress = params->src.addr;
1971       blt.SourceXOffset = params->src.tile_x_sa;
1972       blt.SourceYOffset = params->src.tile_y_sa;
1973 
1974 #if GFX_VERx10 >= 125
1975       blt.SourceSurfaceType = xy_bcb_surf_dim(src_surf);
1976       blt.SourceSurfaceWidth = src_surf->logical_level0_px.w - 1;
1977       blt.SourceSurfaceHeight = src_surf->logical_level0_px.h - 1;
1978       blt.SourceSurfaceDepth = xy_bcb_surf_depth(src_surf) - 1;
1979       blt.SourceArrayIndex =
1980          params->src.view.base_array_layer + params->src.z_offset;
1981       blt.SourceSurfaceQPitch = isl_get_qpitch(src_surf) >> 2;
1982       blt.SourceLOD = params->src.view.base_level;
1983       blt.SourceMipTailStartLOD = src_surf->miptail_start_level;
1984       blt.SourceHorizontalAlign = isl_encode_halign(src_align.width);
1985       blt.SourceVerticalAlign = isl_encode_valign(src_align.height);
1986       /* XY_BLOCK_COPY_BLT only supports AUX_CCS. */
1987       blt.SourceDepthStencilResource =
1988          params->src.aux_usage == ISL_AUX_USAGE_STC_CCS;
1989       blt.SourceTargetMemory =
1990          params->src.addr.local_hint ? XY_MEM_LOCAL : XY_MEM_SYSTEM;
1991 
1992       if (params->src.aux_usage != ISL_AUX_USAGE_NONE) {
1993          blt.SourceAuxiliarySurfaceMode = xy_aux_mode(&params->src);
1994          blt.SourceCompressionEnable = true;
1995          blt.SourceCompressionFormat =
1996             isl_get_render_compression_format(src_surf->format);
1997          blt.SourceClearValueEnable = !!params->src.clear_color_addr.buffer;
1998          blt.SourceClearAddress = params->src.clear_color_addr;
1999       }
2000 
2001       /* XeHP needs special MOCS values for the blitter */
2002       blt.DestinationMOCS = isl_dev->mocs.blitter_dst;
2003       blt.SourceMOCS = isl_dev->mocs.blitter_src;
2004 #endif
2005    }
2006 #endif
2007 }
2008 
2009 UNUSED static void
blorp_xy_fast_color_blit(struct blorp_batch * batch,const struct blorp_params * params)2010 blorp_xy_fast_color_blit(struct blorp_batch *batch,
2011                          const struct blorp_params *params)
2012 {
2013 #if GFX_VER < 12
2014    unreachable("Blitter is only supported on Gfx12+");
2015 #else
2016    UNUSED const struct isl_device *isl_dev = batch->blorp->isl_dev;
2017    const struct isl_surf *dst_surf = &params->dst.surf;
2018    const struct isl_format_layout *fmtl =
2019       isl_format_get_layout(params->dst.view.format);
2020 
2021    assert(batch->flags & BLORP_BATCH_USE_BLITTER);
2022    assert(!(batch->flags & BLORP_BATCH_NO_UPDATE_CLEAR_COLOR));
2023    assert(!(batch->flags & BLORP_BATCH_PREDICATE_ENABLE));
2024    assert(params->hiz_op == ISL_AUX_OP_NONE);
2025 
2026    assert(params->num_layers == 1);
2027    assert(params->dst.view.levels == 1);
2028    assert(dst_surf->samples == 1);
2029    assert(fmtl->bpb != 96 || dst_surf->tiling == ISL_TILING_LINEAR);
2030 
2031 #if GFX_VERx10 < 125
2032    assert(params->dst.view.base_array_layer == 0);
2033    assert(params->dst.z_offset == 0);
2034 #endif
2035 
2036    unsigned dst_pitch_unit = dst_surf->tiling == ISL_TILING_LINEAR ? 1 : 4;
2037 
2038 #if GFX_VERx10 >= 125
2039    struct isl_extent3d dst_align = isl_get_image_alignment(dst_surf);
2040 #endif
2041 
2042    blorp_emit(batch, GENX(XY_FAST_COLOR_BLT), blt) {
2043       blt.ColorDepth = xy_color_depth(fmtl);
2044 
2045       blt.DestinationPitch = (dst_surf->row_pitch_B / dst_pitch_unit) - 1;
2046       blt.DestinationTiling = xy_bcb_tiling(dst_surf);
2047       blt.DestinationX1 = params->x0;
2048       blt.DestinationY1 = params->y0;
2049       blt.DestinationX2 = params->x1;
2050       blt.DestinationY2 = params->y1;
2051       blt.DestinationBaseAddress = params->dst.addr;
2052       blt.DestinationXOffset = params->dst.tile_x_sa;
2053       blt.DestinationYOffset = params->dst.tile_y_sa;
2054 
2055       isl_color_value_pack((union isl_color_value *)
2056                            params->wm_inputs.clear_color,
2057                            params->dst.view.format, blt.FillColor);
2058 
2059 #if GFX_VERx10 >= 125
2060       blt.DestinationSurfaceType = xy_bcb_surf_dim(dst_surf);
2061       blt.DestinationSurfaceWidth = dst_surf->logical_level0_px.w - 1;
2062       blt.DestinationSurfaceHeight = dst_surf->logical_level0_px.h - 1;
2063       blt.DestinationSurfaceDepth = xy_bcb_surf_depth(dst_surf) - 1;
2064       blt.DestinationArrayIndex =
2065          params->dst.view.base_array_layer + params->dst.z_offset;
2066       blt.DestinationSurfaceQPitch = isl_get_qpitch(dst_surf) >> 2;
2067       blt.DestinationLOD = params->dst.view.base_level;
2068       blt.DestinationMipTailStartLOD = dst_surf->miptail_start_level;
2069       blt.DestinationHorizontalAlign = isl_encode_halign(dst_align.width);
2070       blt.DestinationVerticalAlign = isl_encode_valign(dst_align.height);
2071       /* XY_FAST_COLOR_BLT only supports AUX_CCS. */
2072       blt.DestinationDepthStencilResource =
2073          params->dst.aux_usage == ISL_AUX_USAGE_STC_CCS;
2074       blt.DestinationTargetMemory =
2075          params->dst.addr.local_hint ? XY_MEM_LOCAL : XY_MEM_SYSTEM;
2076 
2077       if (params->dst.aux_usage != ISL_AUX_USAGE_NONE) {
2078          blt.DestinationAuxiliarySurfaceMode = xy_aux_mode(&params->dst);
2079          blt.DestinationCompressionEnable = true;
2080          blt.DestinationCompressionFormat =
2081             isl_get_render_compression_format(dst_surf->format);
2082          blt.DestinationClearValueEnable = !!params->dst.clear_color_addr.buffer;
2083          blt.DestinationClearAddress = params->dst.clear_color_addr;
2084       }
2085 
2086       /* XeHP needs special MOCS values for the blitter */
2087       blt.DestinationMOCS = isl_dev->mocs.blitter_dst;
2088 #endif
2089    }
2090 #endif
2091 }
2092 
2093 static void
blorp_exec_blitter(struct blorp_batch * batch,const struct blorp_params * params)2094 blorp_exec_blitter(struct blorp_batch *batch,
2095                    const struct blorp_params *params)
2096 {
2097    blorp_measure_start(batch, params);
2098 
2099    if (params->src.enabled)
2100       blorp_xy_block_copy_blt(batch, params);
2101    else
2102       blorp_xy_fast_color_blit(batch, params);
2103 
2104    blorp_measure_end(batch, params);
2105 }
2106 
2107 /**
2108  * \brief Execute a blit or render pass operation.
2109  *
2110  * To execute the operation, this function manually constructs and emits a
2111  * batch to draw a rectangle primitive. The batchbuffer is flushed before
2112  * constructing and after emitting the batch.
2113  *
2114  * This function alters no GL state.
2115  */
2116 static void
blorp_exec(struct blorp_batch * batch,const struct blorp_params * params)2117 blorp_exec(struct blorp_batch *batch, const struct blorp_params *params)
2118 {
2119    if (batch->flags & BLORP_BATCH_USE_BLITTER) {
2120       blorp_exec_blitter(batch, params);
2121    } else if (batch->flags & BLORP_BATCH_USE_COMPUTE) {
2122       blorp_exec_compute(batch, params);
2123    } else {
2124       blorp_exec_3d(batch, params);
2125    }
2126 }
2127 
2128 #endif /* BLORP_GENX_EXEC_BRW_H */
2129