anv: add helper to get vue map for fragment shader
[mesa.git] / src / intel / vulkan / genX_pipeline.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "anv_private.h"
25
26 #include "genxml/gen_macros.h"
27 #include "genxml/genX_pack.h"
28
29 #include "common/gen_l3_config.h"
30 #include "common/gen_sample_positions.h"
31 #include "vk_format_info.h"
32
33 static uint32_t
34 vertex_element_comp_control(enum isl_format format, unsigned comp)
35 {
36 uint8_t bits;
37 switch (comp) {
38 case 0: bits = isl_format_layouts[format].channels.r.bits; break;
39 case 1: bits = isl_format_layouts[format].channels.g.bits; break;
40 case 2: bits = isl_format_layouts[format].channels.b.bits; break;
41 case 3: bits = isl_format_layouts[format].channels.a.bits; break;
42 default: unreachable("Invalid component");
43 }
44
45 /*
46 * Take in account hardware restrictions when dealing with 64-bit floats.
47 *
48 * From Broadwell spec, command reference structures, page 586:
49 * "When SourceElementFormat is set to one of the *64*_PASSTHRU formats,
50 * 64-bit components are stored * in the URB without any conversion. In
51 * this case, vertex elements must be written as 128 or 256 bits, with
52 * VFCOMP_STORE_0 being used to pad the output as required. E.g., if
53 * R64_PASSTHRU is used to copy a 64-bit Red component into the URB,
54 * Component 1 must be specified as VFCOMP_STORE_0 (with Components 2,3
55 * set to VFCOMP_NOSTORE) in order to output a 128-bit vertex element, or
56 * Components 1-3 must be specified as VFCOMP_STORE_0 in order to output
57 * a 256-bit vertex element. Likewise, use of R64G64B64_PASSTHRU requires
58 * Component 3 to be specified as VFCOMP_STORE_0 in order to output a
59 * 256-bit vertex element."
60 */
61 if (bits) {
62 return VFCOMP_STORE_SRC;
63 } else if (comp >= 2 &&
64 !isl_format_layouts[format].channels.b.bits &&
65 isl_format_layouts[format].channels.r.type == ISL_RAW) {
66 /* When emitting 64-bit attributes, we need to write either 128 or 256
67 * bit chunks, using VFCOMP_NOSTORE when not writing the chunk, and
68 * VFCOMP_STORE_0 to pad the written chunk */
69 return VFCOMP_NOSTORE;
70 } else if (comp < 3 ||
71 isl_format_layouts[format].channels.r.type == ISL_RAW) {
72 /* Note we need to pad with value 0, not 1, due hardware restrictions
73 * (see comment above) */
74 return VFCOMP_STORE_0;
75 } else if (isl_format_layouts[format].channels.r.type == ISL_UINT ||
76 isl_format_layouts[format].channels.r.type == ISL_SINT) {
77 assert(comp == 3);
78 return VFCOMP_STORE_1_INT;
79 } else {
80 assert(comp == 3);
81 return VFCOMP_STORE_1_FP;
82 }
83 }
84
85 static void
86 emit_vertex_input(struct anv_pipeline *pipeline,
87 const VkPipelineVertexInputStateCreateInfo *info)
88 {
89 const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);
90
91 /* Pull inputs_read out of the VS prog data */
92 const uint64_t inputs_read = vs_prog_data->inputs_read;
93 const uint64_t double_inputs_read = vs_prog_data->double_inputs_read;
94 assert((inputs_read & ((1 << VERT_ATTRIB_GENERIC0) - 1)) == 0);
95 const uint32_t elements = inputs_read >> VERT_ATTRIB_GENERIC0;
96 const uint32_t elements_double = double_inputs_read >> VERT_ATTRIB_GENERIC0;
97
98 #if GEN_GEN >= 8
99 /* On BDW+, we only need to allocate space for base ids. Setting up
100 * the actual vertex and instance id is a separate packet.
101 */
102 const bool needs_svgs_elem = vs_prog_data->uses_basevertex ||
103 vs_prog_data->uses_baseinstance;
104 #else
105 /* On Haswell and prior, vertex and instance id are created by using the
106 * ComponentControl fields, so we need an element for any of them.
107 */
108 const bool needs_svgs_elem = vs_prog_data->uses_vertexid ||
109 vs_prog_data->uses_instanceid ||
110 vs_prog_data->uses_basevertex ||
111 vs_prog_data->uses_baseinstance;
112 #endif
113
114 uint32_t elem_count = __builtin_popcount(elements) -
115 __builtin_popcount(elements_double) / 2;
116
117 uint32_t total_elems = elem_count + needs_svgs_elem;
118 if (total_elems == 0)
119 return;
120
121 uint32_t *p;
122
123 const uint32_t num_dwords = 1 + total_elems * 2;
124 p = anv_batch_emitn(&pipeline->batch, num_dwords,
125 GENX(3DSTATE_VERTEX_ELEMENTS));
126 memset(p + 1, 0, (num_dwords - 1) * 4);
127
128 for (uint32_t i = 0; i < info->vertexAttributeDescriptionCount; i++) {
129 const VkVertexInputAttributeDescription *desc =
130 &info->pVertexAttributeDescriptions[i];
131 enum isl_format format = anv_get_isl_format(&pipeline->device->info,
132 desc->format,
133 VK_IMAGE_ASPECT_COLOR_BIT,
134 VK_IMAGE_TILING_LINEAR);
135
136 assert(desc->binding < 32);
137
138 if ((elements & (1 << desc->location)) == 0)
139 continue; /* Binding unused */
140
141 uint32_t slot =
142 __builtin_popcount(elements & ((1 << desc->location) - 1)) -
143 DIV_ROUND_UP(__builtin_popcount(elements_double &
144 ((1 << desc->location) -1)), 2);
145
146 struct GENX(VERTEX_ELEMENT_STATE) element = {
147 .VertexBufferIndex = desc->binding,
148 .Valid = true,
149 .SourceElementFormat = format,
150 .EdgeFlagEnable = false,
151 .SourceElementOffset = desc->offset,
152 .Component0Control = vertex_element_comp_control(format, 0),
153 .Component1Control = vertex_element_comp_control(format, 1),
154 .Component2Control = vertex_element_comp_control(format, 2),
155 .Component3Control = vertex_element_comp_control(format, 3),
156 };
157 GENX(VERTEX_ELEMENT_STATE_pack)(NULL, &p[1 + slot * 2], &element);
158
159 #if GEN_GEN >= 8
160 /* On Broadwell and later, we have a separate VF_INSTANCING packet
161 * that controls instancing. On Haswell and prior, that's part of
162 * VERTEX_BUFFER_STATE which we emit later.
163 */
164 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_VF_INSTANCING), vfi) {
165 vfi.InstancingEnable = pipeline->instancing_enable[desc->binding];
166 vfi.VertexElementIndex = slot;
167 /* Vulkan so far doesn't have an instance divisor, so
168 * this is always 1 (ignored if not instancing). */
169 vfi.InstanceDataStepRate = 1;
170 }
171 #endif
172 }
173
174 const uint32_t id_slot = elem_count;
175 if (needs_svgs_elem) {
176 /* From the Broadwell PRM for the 3D_Vertex_Component_Control enum:
177 * "Within a VERTEX_ELEMENT_STATE structure, if a Component
178 * Control field is set to something other than VFCOMP_STORE_SRC,
179 * no higher-numbered Component Control fields may be set to
180 * VFCOMP_STORE_SRC"
181 *
182 * This means, that if we have BaseInstance, we need BaseVertex as
183 * well. Just do all or nothing.
184 */
185 uint32_t base_ctrl = (vs_prog_data->uses_basevertex ||
186 vs_prog_data->uses_baseinstance) ?
187 VFCOMP_STORE_SRC : VFCOMP_STORE_0;
188
189 struct GENX(VERTEX_ELEMENT_STATE) element = {
190 .VertexBufferIndex = 32, /* Reserved for this */
191 .Valid = true,
192 .SourceElementFormat = ISL_FORMAT_R32G32_UINT,
193 .Component0Control = base_ctrl,
194 .Component1Control = base_ctrl,
195 #if GEN_GEN >= 8
196 .Component2Control = VFCOMP_STORE_0,
197 .Component3Control = VFCOMP_STORE_0,
198 #else
199 .Component2Control = VFCOMP_STORE_VID,
200 .Component3Control = VFCOMP_STORE_IID,
201 #endif
202 };
203 GENX(VERTEX_ELEMENT_STATE_pack)(NULL, &p[1 + id_slot * 2], &element);
204 }
205
206 #if GEN_GEN >= 8
207 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_VF_SGVS), sgvs) {
208 sgvs.VertexIDEnable = vs_prog_data->uses_vertexid;
209 sgvs.VertexIDComponentNumber = 2;
210 sgvs.VertexIDElementOffset = id_slot;
211 sgvs.InstanceIDEnable = vs_prog_data->uses_instanceid;
212 sgvs.InstanceIDComponentNumber = 3;
213 sgvs.InstanceIDElementOffset = id_slot;
214 }
215 #endif
216 }
217
218 void
219 genX(emit_urb_setup)(struct anv_device *device, struct anv_batch *batch,
220 const struct gen_l3_config *l3_config,
221 VkShaderStageFlags active_stages,
222 const unsigned entry_size[4])
223 {
224 const struct gen_device_info *devinfo = &device->info;
225 #if GEN_IS_HASWELL
226 const unsigned push_constant_kb = devinfo->gt == 3 ? 32 : 16;
227 #else
228 const unsigned push_constant_kb = GEN_GEN >= 8 ? 32 : 16;
229 #endif
230
231 const unsigned urb_size_kb = gen_get_l3_config_urb_size(devinfo, l3_config);
232
233 unsigned entries[4];
234 unsigned start[4];
235 gen_get_urb_config(devinfo,
236 1024 * push_constant_kb, 1024 * urb_size_kb,
237 active_stages &
238 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
239 active_stages & VK_SHADER_STAGE_GEOMETRY_BIT,
240 entry_size, entries, start);
241
242 #if GEN_GEN == 7 && !GEN_IS_HASWELL
243 /* From the IVB PRM Vol. 2, Part 1, Section 3.2.1:
244 *
245 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
246 * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
247 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
248 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
249 * needs to be sent before any combination of VS associated 3DSTATE."
250 */
251 anv_batch_emit(batch, GEN7_PIPE_CONTROL, pc) {
252 pc.DepthStallEnable = true;
253 pc.PostSyncOperation = WriteImmediateData;
254 pc.Address = (struct anv_address) { &device->workaround_bo, 0 };
255 }
256 #endif
257
258 for (int i = 0; i <= MESA_SHADER_GEOMETRY; i++) {
259 anv_batch_emit(batch, GENX(3DSTATE_URB_VS), urb) {
260 urb._3DCommandSubOpcode += i;
261 urb.VSURBStartingAddress = start[i];
262 urb.VSURBEntryAllocationSize = entry_size[i] - 1;
263 urb.VSNumberofURBEntries = entries[i];
264 }
265 }
266 }
267
268 static inline void
269 emit_urb_setup(struct anv_pipeline *pipeline)
270 {
271 unsigned entry_size[4];
272 for (int i = MESA_SHADER_VERTEX; i <= MESA_SHADER_GEOMETRY; i++) {
273 const struct brw_vue_prog_data *prog_data =
274 !anv_pipeline_has_stage(pipeline, i) ? NULL :
275 (const struct brw_vue_prog_data *) pipeline->shaders[i]->prog_data;
276
277 entry_size[i] = prog_data ? prog_data->urb_entry_size : 1;
278 }
279
280 genX(emit_urb_setup)(pipeline->device, &pipeline->batch,
281 pipeline->urb.l3_config,
282 pipeline->active_stages, entry_size);
283 }
284
285 static void
286 emit_3dstate_sbe(struct anv_pipeline *pipeline)
287 {
288 const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
289 const struct brw_vue_map *fs_input_map;
290
291 if (!anv_pipeline_has_stage(pipeline, MESA_SHADER_FRAGMENT)) {
292 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_SBE), sbe);
293 #if GEN_GEN >= 8
294 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_SBE_SWIZ), sbe);
295 #endif
296 return;
297 }
298
299 fs_input_map = anv_pipeline_get_fs_input_map(pipeline);
300
301 struct GENX(3DSTATE_SBE) sbe = {
302 GENX(3DSTATE_SBE_header),
303 .AttributeSwizzleEnable = true,
304 .PointSpriteTextureCoordinateOrigin = UPPERLEFT,
305 .NumberofSFOutputAttributes = wm_prog_data->num_varying_inputs,
306 .ConstantInterpolationEnable = wm_prog_data->flat_inputs,
307 };
308
309 #if GEN_GEN >= 9
310 for (unsigned i = 0; i < 32; i++)
311 sbe.AttributeActiveComponentFormat[i] = ACF_XYZW;
312 #endif
313
314 #if GEN_GEN >= 8
315 /* On Broadwell, they broke 3DSTATE_SBE into two packets */
316 struct GENX(3DSTATE_SBE_SWIZ) swiz = {
317 GENX(3DSTATE_SBE_SWIZ_header),
318 };
319 #else
320 # define swiz sbe
321 #endif
322
323 /* Skip the VUE header and position slots by default */
324 unsigned urb_entry_read_offset = 1;
325 int max_source_attr = 0;
326 for (int attr = 0; attr < VARYING_SLOT_MAX; attr++) {
327 int input_index = wm_prog_data->urb_setup[attr];
328
329 if (input_index < 0)
330 continue;
331
332 /* gl_Layer is stored in the VUE header */
333 if (attr == VARYING_SLOT_LAYER) {
334 urb_entry_read_offset = 0;
335 continue;
336 }
337
338 if (attr == VARYING_SLOT_PNTC) {
339 sbe.PointSpriteTextureCoordinateEnable = 1 << input_index;
340 continue;
341 }
342
343 const int slot = fs_input_map->varying_to_slot[attr];
344
345 if (input_index >= 16)
346 continue;
347
348 if (slot == -1) {
349 /* This attribute does not exist in the VUE--that means that the
350 * vertex shader did not write to it. It could be that it's a
351 * regular varying read by the fragment shader but not written by
352 * the vertex shader or it's gl_PrimitiveID. In the first case the
353 * value is undefined, in the second it needs to be
354 * gl_PrimitiveID.
355 */
356 swiz.Attribute[input_index].ConstantSource = PRIM_ID;
357 swiz.Attribute[input_index].ComponentOverrideX = true;
358 swiz.Attribute[input_index].ComponentOverrideY = true;
359 swiz.Attribute[input_index].ComponentOverrideZ = true;
360 swiz.Attribute[input_index].ComponentOverrideW = true;
361 } else {
362 /* We have to subtract two slots to accout for the URB entry output
363 * read offset in the VS and GS stages.
364 */
365 assert(slot >= 2);
366 const int source_attr = slot - 2 * urb_entry_read_offset;
367 max_source_attr = MAX2(max_source_attr, source_attr);
368 swiz.Attribute[input_index].SourceAttribute = source_attr;
369 }
370 }
371
372 sbe.VertexURBEntryReadOffset = urb_entry_read_offset;
373 sbe.VertexURBEntryReadLength = DIV_ROUND_UP(max_source_attr + 1, 2);
374 #if GEN_GEN >= 8
375 sbe.ForceVertexURBEntryReadOffset = true;
376 sbe.ForceVertexURBEntryReadLength = true;
377 #endif
378
379 uint32_t *dw = anv_batch_emit_dwords(&pipeline->batch,
380 GENX(3DSTATE_SBE_length));
381 GENX(3DSTATE_SBE_pack)(&pipeline->batch, dw, &sbe);
382
383 #if GEN_GEN >= 8
384 dw = anv_batch_emit_dwords(&pipeline->batch, GENX(3DSTATE_SBE_SWIZ_length));
385 GENX(3DSTATE_SBE_SWIZ_pack)(&pipeline->batch, dw, &swiz);
386 #endif
387 }
388
389 static const uint32_t vk_to_gen_cullmode[] = {
390 [VK_CULL_MODE_NONE] = CULLMODE_NONE,
391 [VK_CULL_MODE_FRONT_BIT] = CULLMODE_FRONT,
392 [VK_CULL_MODE_BACK_BIT] = CULLMODE_BACK,
393 [VK_CULL_MODE_FRONT_AND_BACK] = CULLMODE_BOTH
394 };
395
396 static const uint32_t vk_to_gen_fillmode[] = {
397 [VK_POLYGON_MODE_FILL] = FILL_MODE_SOLID,
398 [VK_POLYGON_MODE_LINE] = FILL_MODE_WIREFRAME,
399 [VK_POLYGON_MODE_POINT] = FILL_MODE_POINT,
400 };
401
402 static const uint32_t vk_to_gen_front_face[] = {
403 [VK_FRONT_FACE_COUNTER_CLOCKWISE] = 1,
404 [VK_FRONT_FACE_CLOCKWISE] = 0
405 };
406
407 static void
408 emit_rs_state(struct anv_pipeline *pipeline,
409 const VkPipelineRasterizationStateCreateInfo *rs_info,
410 const VkPipelineMultisampleStateCreateInfo *ms_info,
411 const struct anv_render_pass *pass,
412 const struct anv_subpass *subpass)
413 {
414 struct GENX(3DSTATE_SF) sf = {
415 GENX(3DSTATE_SF_header),
416 };
417
418 sf.ViewportTransformEnable = true;
419 sf.StatisticsEnable = true;
420 sf.TriangleStripListProvokingVertexSelect = 0;
421 sf.LineStripListProvokingVertexSelect = 0;
422 sf.TriangleFanProvokingVertexSelect = 1;
423 sf.PointWidthSource = Vertex;
424 sf.PointWidth = 1.0;
425
426 #if GEN_GEN >= 8
427 struct GENX(3DSTATE_RASTER) raster = {
428 GENX(3DSTATE_RASTER_header),
429 };
430 #else
431 # define raster sf
432 #endif
433
434 /* For details on 3DSTATE_RASTER multisample state, see the BSpec table
435 * "Multisample Modes State".
436 */
437 #if GEN_GEN >= 8
438 raster.DXMultisampleRasterizationEnable = true;
439 raster.ForcedSampleCount = FSC_NUMRASTSAMPLES_0;
440 raster.ForceMultisampling = false;
441 #else
442 raster.MultisampleRasterizationMode =
443 (ms_info && ms_info->rasterizationSamples > 1) ?
444 MSRASTMODE_ON_PATTERN : MSRASTMODE_OFF_PIXEL;
445 #endif
446
447 raster.FrontWinding = vk_to_gen_front_face[rs_info->frontFace];
448 raster.CullMode = vk_to_gen_cullmode[rs_info->cullMode];
449 raster.FrontFaceFillMode = vk_to_gen_fillmode[rs_info->polygonMode];
450 raster.BackFaceFillMode = vk_to_gen_fillmode[rs_info->polygonMode];
451 raster.ScissorRectangleEnable = true;
452
453 #if GEN_GEN >= 9
454 /* GEN9+ splits ViewportZClipTestEnable into near and far enable bits */
455 raster.ViewportZFarClipTestEnable = !pipeline->depth_clamp_enable;
456 raster.ViewportZNearClipTestEnable = !pipeline->depth_clamp_enable;
457 #elif GEN_GEN >= 8
458 raster.ViewportZClipTestEnable = !pipeline->depth_clamp_enable;
459 #endif
460
461 raster.GlobalDepthOffsetEnableSolid = rs_info->depthBiasEnable;
462 raster.GlobalDepthOffsetEnableWireframe = rs_info->depthBiasEnable;
463 raster.GlobalDepthOffsetEnablePoint = rs_info->depthBiasEnable;
464
465 #if GEN_GEN == 7
466 /* Gen7 requires that we provide the depth format in 3DSTATE_SF so that it
467 * can get the depth offsets correct.
468 */
469 if (subpass->depth_stencil_attachment < pass->attachment_count) {
470 VkFormat vk_format =
471 pass->attachments[subpass->depth_stencil_attachment].format;
472 assert(vk_format_is_depth_or_stencil(vk_format));
473 if (vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_DEPTH_BIT) {
474 enum isl_format isl_format =
475 anv_get_isl_format(&pipeline->device->info, vk_format,
476 VK_IMAGE_ASPECT_DEPTH_BIT,
477 VK_IMAGE_TILING_OPTIMAL);
478 sf.DepthBufferSurfaceFormat =
479 isl_format_get_depth_format(isl_format, false);
480 }
481 }
482 #endif
483
484 #if GEN_GEN >= 8
485 GENX(3DSTATE_SF_pack)(NULL, pipeline->gen8.sf, &sf);
486 GENX(3DSTATE_RASTER_pack)(NULL, pipeline->gen8.raster, &raster);
487 #else
488 # undef raster
489 GENX(3DSTATE_SF_pack)(NULL, &pipeline->gen7.sf, &sf);
490 #endif
491 }
492
493 static void
494 emit_ms_state(struct anv_pipeline *pipeline,
495 const VkPipelineMultisampleStateCreateInfo *info)
496 {
497 uint32_t samples = 1;
498 uint32_t log2_samples = 0;
499
500 /* From the Vulkan 1.0 spec:
501 * If pSampleMask is NULL, it is treated as if the mask has all bits
502 * enabled, i.e. no coverage is removed from fragments.
503 *
504 * 3DSTATE_SAMPLE_MASK.SampleMask is 16 bits.
505 */
506 #if GEN_GEN >= 8
507 uint32_t sample_mask = 0xffff;
508 #else
509 uint32_t sample_mask = 0xff;
510 #endif
511
512 if (info) {
513 samples = info->rasterizationSamples;
514 log2_samples = __builtin_ffs(samples) - 1;
515 }
516
517 if (info && info->pSampleMask)
518 sample_mask &= info->pSampleMask[0];
519
520 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_MULTISAMPLE), ms) {
521 ms.NumberofMultisamples = log2_samples;
522
523 #if GEN_GEN >= 8
524 /* The PRM says that this bit is valid only for DX9:
525 *
526 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
527 * should not have any effect by setting or not setting this bit.
528 */
529 ms.PixelPositionOffsetEnable = false;
530 ms.PixelLocation = CENTER;
531 #else
532 ms.PixelLocation = PIXLOC_CENTER;
533
534 switch (samples) {
535 case 1:
536 GEN_SAMPLE_POS_1X(ms.Sample);
537 break;
538 case 2:
539 GEN_SAMPLE_POS_2X(ms.Sample);
540 break;
541 case 4:
542 GEN_SAMPLE_POS_4X(ms.Sample);
543 break;
544 case 8:
545 GEN_SAMPLE_POS_8X(ms.Sample);
546 break;
547 default:
548 break;
549 }
550 #endif
551 }
552
553 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_SAMPLE_MASK), sm) {
554 sm.SampleMask = sample_mask;
555 }
556 }
557
558 static const uint32_t vk_to_gen_logic_op[] = {
559 [VK_LOGIC_OP_COPY] = LOGICOP_COPY,
560 [VK_LOGIC_OP_CLEAR] = LOGICOP_CLEAR,
561 [VK_LOGIC_OP_AND] = LOGICOP_AND,
562 [VK_LOGIC_OP_AND_REVERSE] = LOGICOP_AND_REVERSE,
563 [VK_LOGIC_OP_AND_INVERTED] = LOGICOP_AND_INVERTED,
564 [VK_LOGIC_OP_NO_OP] = LOGICOP_NOOP,
565 [VK_LOGIC_OP_XOR] = LOGICOP_XOR,
566 [VK_LOGIC_OP_OR] = LOGICOP_OR,
567 [VK_LOGIC_OP_NOR] = LOGICOP_NOR,
568 [VK_LOGIC_OP_EQUIVALENT] = LOGICOP_EQUIV,
569 [VK_LOGIC_OP_INVERT] = LOGICOP_INVERT,
570 [VK_LOGIC_OP_OR_REVERSE] = LOGICOP_OR_REVERSE,
571 [VK_LOGIC_OP_COPY_INVERTED] = LOGICOP_COPY_INVERTED,
572 [VK_LOGIC_OP_OR_INVERTED] = LOGICOP_OR_INVERTED,
573 [VK_LOGIC_OP_NAND] = LOGICOP_NAND,
574 [VK_LOGIC_OP_SET] = LOGICOP_SET,
575 };
576
577 static const uint32_t vk_to_gen_blend[] = {
578 [VK_BLEND_FACTOR_ZERO] = BLENDFACTOR_ZERO,
579 [VK_BLEND_FACTOR_ONE] = BLENDFACTOR_ONE,
580 [VK_BLEND_FACTOR_SRC_COLOR] = BLENDFACTOR_SRC_COLOR,
581 [VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR] = BLENDFACTOR_INV_SRC_COLOR,
582 [VK_BLEND_FACTOR_DST_COLOR] = BLENDFACTOR_DST_COLOR,
583 [VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR] = BLENDFACTOR_INV_DST_COLOR,
584 [VK_BLEND_FACTOR_SRC_ALPHA] = BLENDFACTOR_SRC_ALPHA,
585 [VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA] = BLENDFACTOR_INV_SRC_ALPHA,
586 [VK_BLEND_FACTOR_DST_ALPHA] = BLENDFACTOR_DST_ALPHA,
587 [VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA] = BLENDFACTOR_INV_DST_ALPHA,
588 [VK_BLEND_FACTOR_CONSTANT_COLOR] = BLENDFACTOR_CONST_COLOR,
589 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR]= BLENDFACTOR_INV_CONST_COLOR,
590 [VK_BLEND_FACTOR_CONSTANT_ALPHA] = BLENDFACTOR_CONST_ALPHA,
591 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA]= BLENDFACTOR_INV_CONST_ALPHA,
592 [VK_BLEND_FACTOR_SRC_ALPHA_SATURATE] = BLENDFACTOR_SRC_ALPHA_SATURATE,
593 [VK_BLEND_FACTOR_SRC1_COLOR] = BLENDFACTOR_SRC1_COLOR,
594 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR] = BLENDFACTOR_INV_SRC1_COLOR,
595 [VK_BLEND_FACTOR_SRC1_ALPHA] = BLENDFACTOR_SRC1_ALPHA,
596 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA] = BLENDFACTOR_INV_SRC1_ALPHA,
597 };
598
599 static const uint32_t vk_to_gen_blend_op[] = {
600 [VK_BLEND_OP_ADD] = BLENDFUNCTION_ADD,
601 [VK_BLEND_OP_SUBTRACT] = BLENDFUNCTION_SUBTRACT,
602 [VK_BLEND_OP_REVERSE_SUBTRACT] = BLENDFUNCTION_REVERSE_SUBTRACT,
603 [VK_BLEND_OP_MIN] = BLENDFUNCTION_MIN,
604 [VK_BLEND_OP_MAX] = BLENDFUNCTION_MAX,
605 };
606
607 static const uint32_t vk_to_gen_compare_op[] = {
608 [VK_COMPARE_OP_NEVER] = PREFILTEROPNEVER,
609 [VK_COMPARE_OP_LESS] = PREFILTEROPLESS,
610 [VK_COMPARE_OP_EQUAL] = PREFILTEROPEQUAL,
611 [VK_COMPARE_OP_LESS_OR_EQUAL] = PREFILTEROPLEQUAL,
612 [VK_COMPARE_OP_GREATER] = PREFILTEROPGREATER,
613 [VK_COMPARE_OP_NOT_EQUAL] = PREFILTEROPNOTEQUAL,
614 [VK_COMPARE_OP_GREATER_OR_EQUAL] = PREFILTEROPGEQUAL,
615 [VK_COMPARE_OP_ALWAYS] = PREFILTEROPALWAYS,
616 };
617
618 static const uint32_t vk_to_gen_stencil_op[] = {
619 [VK_STENCIL_OP_KEEP] = STENCILOP_KEEP,
620 [VK_STENCIL_OP_ZERO] = STENCILOP_ZERO,
621 [VK_STENCIL_OP_REPLACE] = STENCILOP_REPLACE,
622 [VK_STENCIL_OP_INCREMENT_AND_CLAMP] = STENCILOP_INCRSAT,
623 [VK_STENCIL_OP_DECREMENT_AND_CLAMP] = STENCILOP_DECRSAT,
624 [VK_STENCIL_OP_INVERT] = STENCILOP_INVERT,
625 [VK_STENCIL_OP_INCREMENT_AND_WRAP] = STENCILOP_INCR,
626 [VK_STENCIL_OP_DECREMENT_AND_WRAP] = STENCILOP_DECR,
627 };
628
629 static void
630 emit_ds_state(struct anv_pipeline *pipeline,
631 const VkPipelineDepthStencilStateCreateInfo *info,
632 const struct anv_render_pass *pass,
633 const struct anv_subpass *subpass)
634 {
635 #if GEN_GEN == 7
636 # define depth_stencil_dw pipeline->gen7.depth_stencil_state
637 #elif GEN_GEN == 8
638 # define depth_stencil_dw pipeline->gen8.wm_depth_stencil
639 #else
640 # define depth_stencil_dw pipeline->gen9.wm_depth_stencil
641 #endif
642
643 if (info == NULL) {
644 /* We're going to OR this together with the dynamic state. We need
645 * to make sure it's initialized to something useful.
646 */
647 memset(depth_stencil_dw, 0, sizeof(depth_stencil_dw));
648 return;
649 }
650
651 /* VkBool32 depthBoundsTestEnable; // optional (depth_bounds_test) */
652
653 #if GEN_GEN <= 7
654 struct GENX(DEPTH_STENCIL_STATE) depth_stencil = {
655 #else
656 struct GENX(3DSTATE_WM_DEPTH_STENCIL) depth_stencil = {
657 #endif
658 .DepthTestEnable = info->depthTestEnable,
659 .DepthBufferWriteEnable = info->depthWriteEnable,
660 .DepthTestFunction = vk_to_gen_compare_op[info->depthCompareOp],
661 .DoubleSidedStencilEnable = true,
662
663 .StencilTestEnable = info->stencilTestEnable,
664 .StencilBufferWriteEnable = info->stencilTestEnable,
665 .StencilFailOp = vk_to_gen_stencil_op[info->front.failOp],
666 .StencilPassDepthPassOp = vk_to_gen_stencil_op[info->front.passOp],
667 .StencilPassDepthFailOp = vk_to_gen_stencil_op[info->front.depthFailOp],
668 .StencilTestFunction = vk_to_gen_compare_op[info->front.compareOp],
669 .BackfaceStencilFailOp = vk_to_gen_stencil_op[info->back.failOp],
670 .BackfaceStencilPassDepthPassOp = vk_to_gen_stencil_op[info->back.passOp],
671 .BackfaceStencilPassDepthFailOp =vk_to_gen_stencil_op[info->back.depthFailOp],
672 .BackfaceStencilTestFunction = vk_to_gen_compare_op[info->back.compareOp],
673 };
674
675 VkImageAspectFlags aspects = 0;
676 if (subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) {
677 VkFormat depth_stencil_format =
678 pass->attachments[subpass->depth_stencil_attachment].format;
679 aspects = vk_format_aspects(depth_stencil_format);
680 }
681
682 /* The Vulkan spec requires that if either depth or stencil is not present,
683 * the pipeline is to act as if the test silently passes.
684 */
685 if (!(aspects & VK_IMAGE_ASPECT_DEPTH_BIT)) {
686 depth_stencil.DepthBufferWriteEnable = false;
687 depth_stencil.DepthTestFunction = PREFILTEROPALWAYS;
688 }
689
690 if (!(aspects & VK_IMAGE_ASPECT_STENCIL_BIT)) {
691 depth_stencil.StencilBufferWriteEnable = false;
692 depth_stencil.StencilTestFunction = PREFILTEROPALWAYS;
693 depth_stencil.BackfaceStencilTestFunction = PREFILTEROPALWAYS;
694 }
695
696 /* From the Broadwell PRM:
697 *
698 * "If Depth_Test_Enable = 1 AND Depth_Test_func = EQUAL, the
699 * Depth_Write_Enable must be set to 0."
700 */
701 if (info->depthTestEnable && info->depthCompareOp == VK_COMPARE_OP_EQUAL)
702 depth_stencil.DepthBufferWriteEnable = false;
703
704 #if GEN_GEN <= 7
705 GENX(DEPTH_STENCIL_STATE_pack)(NULL, depth_stencil_dw, &depth_stencil);
706 #else
707 GENX(3DSTATE_WM_DEPTH_STENCIL_pack)(NULL, depth_stencil_dw, &depth_stencil);
708 #endif
709 }
710
711 static void
712 emit_cb_state(struct anv_pipeline *pipeline,
713 const VkPipelineColorBlendStateCreateInfo *info,
714 const VkPipelineMultisampleStateCreateInfo *ms_info)
715 {
716 struct anv_device *device = pipeline->device;
717
718 const uint32_t num_dwords = GENX(BLEND_STATE_length);
719 pipeline->blend_state =
720 anv_state_pool_alloc(&device->dynamic_state_pool, num_dwords * 4, 64);
721
722 struct GENX(BLEND_STATE) blend_state = {
723 #if GEN_GEN >= 8
724 .AlphaToCoverageEnable = ms_info && ms_info->alphaToCoverageEnable,
725 .AlphaToOneEnable = ms_info && ms_info->alphaToOneEnable,
726 #else
727 /* Make sure it gets zeroed */
728 .Entry = { { 0, }, },
729 #endif
730 };
731
732 /* Default everything to disabled */
733 for (uint32_t i = 0; i < 8; i++) {
734 blend_state.Entry[i].WriteDisableAlpha = true;
735 blend_state.Entry[i].WriteDisableRed = true;
736 blend_state.Entry[i].WriteDisableGreen = true;
737 blend_state.Entry[i].WriteDisableBlue = true;
738 }
739
740 uint32_t surface_count = 0;
741 struct anv_pipeline_bind_map *map;
742 if (anv_pipeline_has_stage(pipeline, MESA_SHADER_FRAGMENT)) {
743 map = &pipeline->shaders[MESA_SHADER_FRAGMENT]->bind_map;
744 surface_count = map->surface_count;
745 }
746
747 bool has_writeable_rt = false;
748 for (unsigned i = 0; i < surface_count; i++) {
749 struct anv_pipeline_binding *binding = &map->surface_to_descriptor[i];
750
751 /* All color attachments are at the beginning of the binding table */
752 if (binding->set != ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS)
753 break;
754
755 /* We can have at most 8 attachments */
756 assert(i < 8);
757
758 if (binding->index >= info->attachmentCount)
759 continue;
760
761 assert(binding->binding == 0);
762 const VkPipelineColorBlendAttachmentState *a =
763 &info->pAttachments[binding->index];
764
765 blend_state.Entry[i] = (struct GENX(BLEND_STATE_ENTRY)) {
766 #if GEN_GEN < 8
767 .AlphaToCoverageEnable = ms_info && ms_info->alphaToCoverageEnable,
768 .AlphaToOneEnable = ms_info && ms_info->alphaToOneEnable,
769 #endif
770 .LogicOpEnable = info->logicOpEnable,
771 .LogicOpFunction = vk_to_gen_logic_op[info->logicOp],
772 .ColorBufferBlendEnable = a->blendEnable,
773 .ColorClampRange = COLORCLAMP_RTFORMAT,
774 .PreBlendColorClampEnable = true,
775 .PostBlendColorClampEnable = true,
776 .SourceBlendFactor = vk_to_gen_blend[a->srcColorBlendFactor],
777 .DestinationBlendFactor = vk_to_gen_blend[a->dstColorBlendFactor],
778 .ColorBlendFunction = vk_to_gen_blend_op[a->colorBlendOp],
779 .SourceAlphaBlendFactor = vk_to_gen_blend[a->srcAlphaBlendFactor],
780 .DestinationAlphaBlendFactor = vk_to_gen_blend[a->dstAlphaBlendFactor],
781 .AlphaBlendFunction = vk_to_gen_blend_op[a->alphaBlendOp],
782 .WriteDisableAlpha = !(a->colorWriteMask & VK_COLOR_COMPONENT_A_BIT),
783 .WriteDisableRed = !(a->colorWriteMask & VK_COLOR_COMPONENT_R_BIT),
784 .WriteDisableGreen = !(a->colorWriteMask & VK_COLOR_COMPONENT_G_BIT),
785 .WriteDisableBlue = !(a->colorWriteMask & VK_COLOR_COMPONENT_B_BIT),
786 };
787
788 if (a->srcColorBlendFactor != a->srcAlphaBlendFactor ||
789 a->dstColorBlendFactor != a->dstAlphaBlendFactor ||
790 a->colorBlendOp != a->alphaBlendOp) {
791 #if GEN_GEN >= 8
792 blend_state.IndependentAlphaBlendEnable = true;
793 #else
794 blend_state.Entry[i].IndependentAlphaBlendEnable = true;
795 #endif
796 }
797
798 if (a->colorWriteMask != 0)
799 has_writeable_rt = true;
800
801 /* Our hardware applies the blend factor prior to the blend function
802 * regardless of what function is used. Technically, this means the
803 * hardware can do MORE than GL or Vulkan specify. However, it also
804 * means that, for MIN and MAX, we have to stomp the blend factor to
805 * ONE to make it a no-op.
806 */
807 if (a->colorBlendOp == VK_BLEND_OP_MIN ||
808 a->colorBlendOp == VK_BLEND_OP_MAX) {
809 blend_state.Entry[i].SourceBlendFactor = BLENDFACTOR_ONE;
810 blend_state.Entry[i].DestinationBlendFactor = BLENDFACTOR_ONE;
811 }
812 if (a->alphaBlendOp == VK_BLEND_OP_MIN ||
813 a->alphaBlendOp == VK_BLEND_OP_MAX) {
814 blend_state.Entry[i].SourceAlphaBlendFactor = BLENDFACTOR_ONE;
815 blend_state.Entry[i].DestinationAlphaBlendFactor = BLENDFACTOR_ONE;
816 }
817 }
818
819 #if GEN_GEN >= 8
820 struct GENX(BLEND_STATE_ENTRY) *bs0 = &blend_state.Entry[0];
821 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_PS_BLEND), blend) {
822 blend.AlphaToCoverageEnable = blend_state.AlphaToCoverageEnable;
823 blend.HasWriteableRT = has_writeable_rt;
824 blend.ColorBufferBlendEnable = bs0->ColorBufferBlendEnable;
825 blend.SourceAlphaBlendFactor = bs0->SourceAlphaBlendFactor;
826 blend.DestinationAlphaBlendFactor = bs0->DestinationAlphaBlendFactor;
827 blend.SourceBlendFactor = bs0->SourceBlendFactor;
828 blend.DestinationBlendFactor = bs0->DestinationBlendFactor;
829 blend.AlphaTestEnable = false;
830 blend.IndependentAlphaBlendEnable =
831 blend_state.IndependentAlphaBlendEnable;
832 }
833 #else
834 (void)has_writeable_rt;
835 #endif
836
837 GENX(BLEND_STATE_pack)(NULL, pipeline->blend_state.map, &blend_state);
838 if (!device->info.has_llc)
839 anv_state_clflush(pipeline->blend_state);
840
841 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_BLEND_STATE_POINTERS), bsp) {
842 bsp.BlendStatePointer = pipeline->blend_state.offset;
843 #if GEN_GEN >= 8
844 bsp.BlendStatePointerValid = true;
845 #endif
846 }
847 }
848
849 /**
850 * Get the brw_vue_prog_data for the last stage which outputs VUEs.
851 */
852 static inline struct brw_vue_prog_data *
853 get_last_vue_prog_data(struct anv_pipeline *pipeline)
854 {
855 for (int s = MESA_SHADER_GEOMETRY; s >= 0; s--) {
856 if (pipeline->shaders[s])
857 return (struct brw_vue_prog_data *) pipeline->shaders[s]->prog_data;
858 }
859 return NULL;
860 }
861
862 static void
863 emit_3dstate_clip(struct anv_pipeline *pipeline,
864 const VkPipelineViewportStateCreateInfo *vp_info,
865 const VkPipelineRasterizationStateCreateInfo *rs_info)
866 {
867 const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
868 (void) wm_prog_data;
869 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_CLIP), clip) {
870 clip.ClipEnable = true;
871 clip.EarlyCullEnable = true;
872 clip.APIMode = APIMODE_D3D,
873 clip.ViewportXYClipTestEnable = true;
874
875 clip.ClipMode = CLIPMODE_NORMAL;
876
877 clip.TriangleStripListProvokingVertexSelect = 0;
878 clip.LineStripListProvokingVertexSelect = 0;
879 clip.TriangleFanProvokingVertexSelect = 1;
880
881 clip.MinimumPointWidth = 0.125;
882 clip.MaximumPointWidth = 255.875;
883 clip.MaximumVPIndex = (vp_info ? vp_info->viewportCount : 1) - 1;
884
885 #if GEN_GEN == 7
886 clip.FrontWinding = vk_to_gen_front_face[rs_info->frontFace];
887 clip.CullMode = vk_to_gen_cullmode[rs_info->cullMode];
888 clip.ViewportZClipTestEnable = !pipeline->depth_clamp_enable;
889 const struct brw_vue_prog_data *last = get_last_vue_prog_data(pipeline);
890 if (last) {
891 clip.UserClipDistanceClipTestEnableBitmask = last->clip_distance_mask;
892 clip.UserClipDistanceCullTestEnableBitmask = last->cull_distance_mask;
893 }
894 #else
895 clip.NonPerspectiveBarycentricEnable = wm_prog_data ?
896 (wm_prog_data->barycentric_interp_modes & 0x38) != 0 : 0;
897 #endif
898 }
899 }
900
901 static void
902 emit_3dstate_streamout(struct anv_pipeline *pipeline,
903 const VkPipelineRasterizationStateCreateInfo *rs_info)
904 {
905 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_STREAMOUT), so) {
906 so.RenderingDisable = rs_info->rasterizerDiscardEnable;
907 }
908 }
909
910 static inline uint32_t
911 get_sampler_count(const struct anv_shader_bin *bin)
912 {
913 return DIV_ROUND_UP(bin->bind_map.sampler_count, 4);
914 }
915
916 static inline uint32_t
917 get_binding_table_entry_count(const struct anv_shader_bin *bin)
918 {
919 return DIV_ROUND_UP(bin->bind_map.surface_count, 32);
920 }
921
922 static inline struct anv_address
923 get_scratch_address(struct anv_pipeline *pipeline,
924 gl_shader_stage stage,
925 const struct anv_shader_bin *bin)
926 {
927 return (struct anv_address) {
928 .bo = anv_scratch_pool_alloc(pipeline->device,
929 &pipeline->device->scratch_pool,
930 stage, bin->prog_data->total_scratch),
931 .offset = 0,
932 };
933 }
934
935 static inline uint32_t
936 get_scratch_space(const struct anv_shader_bin *bin)
937 {
938 return ffs(bin->prog_data->total_scratch / 2048);
939 }
940
941 static inline uint32_t
942 get_urb_output_offset()
943 {
944 /* Skip the VUE header and position slots */
945 return 1;
946 }
947
948 static inline uint32_t
949 get_urb_output_length(const struct anv_shader_bin *bin)
950 {
951 const struct brw_vue_prog_data *prog_data =
952 (const struct brw_vue_prog_data *)bin->prog_data;
953
954 return (prog_data->vue_map.num_slots + 1) / 2 - get_urb_output_offset();
955 }
956
957 static void
958 emit_3dstate_vs(struct anv_pipeline *pipeline)
959 {
960 const struct gen_device_info *devinfo = &pipeline->device->info;
961 const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);
962 const struct anv_shader_bin *vs_bin =
963 pipeline->shaders[MESA_SHADER_VERTEX];
964
965 assert(anv_pipeline_has_stage(pipeline, MESA_SHADER_VERTEX));
966
967 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_VS), vs) {
968 vs.FunctionEnable = true;
969 vs.StatisticsEnable = true;
970 vs.KernelStartPointer = vs_bin->kernel.offset;
971 #if GEN_GEN >= 8
972 vs.SIMD8DispatchEnable =
973 vs_prog_data->base.dispatch_mode == DISPATCH_MODE_SIMD8;
974 #endif
975
976 assert(!vs_prog_data->base.base.use_alt_mode);
977 vs.SingleVertexDispatch = false;
978 vs.VectorMaskEnable = false;
979 vs.SamplerCount = get_sampler_count(vs_bin);
980 vs.BindingTableEntryCount = get_binding_table_entry_count(vs_bin);
981 vs.FloatingPointMode = IEEE754;
982 vs.IllegalOpcodeExceptionEnable = false;
983 vs.SoftwareExceptionEnable = false;
984 vs.MaximumNumberofThreads = devinfo->max_vs_threads - 1;
985 vs.VertexCacheDisable = false;
986
987 vs.VertexURBEntryReadLength = vs_prog_data->base.urb_read_length;
988 vs.VertexURBEntryReadOffset = 0;
989 vs.DispatchGRFStartRegisterForURBData =
990 vs_prog_data->base.base.dispatch_grf_start_reg;
991
992 #if GEN_GEN >= 8
993 vs.VertexURBEntryOutputReadOffset = get_urb_output_offset();
994 vs.VertexURBEntryOutputLength = get_urb_output_length(vs_bin);
995
996 vs.UserClipDistanceClipTestEnableBitmask =
997 vs_prog_data->base.clip_distance_mask;
998 vs.UserClipDistanceCullTestEnableBitmask =
999 vs_prog_data->base.cull_distance_mask;
1000 #endif
1001
1002 vs.PerThreadScratchSpace = get_scratch_space(vs_bin);
1003 vs.ScratchSpaceBasePointer =
1004 get_scratch_address(pipeline, MESA_SHADER_VERTEX, vs_bin);
1005 }
1006 }
1007
1008 static void
1009 emit_3dstate_gs(struct anv_pipeline *pipeline)
1010 {
1011 const struct gen_device_info *devinfo = &pipeline->device->info;
1012 const struct anv_shader_bin *gs_bin =
1013 pipeline->shaders[MESA_SHADER_GEOMETRY];
1014
1015 if (!anv_pipeline_has_stage(pipeline, MESA_SHADER_GEOMETRY)) {
1016 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_GS), gs);
1017 return;
1018 }
1019
1020 const struct brw_gs_prog_data *gs_prog_data = get_gs_prog_data(pipeline);
1021
1022 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_GS), gs) {
1023 gs.FunctionEnable = true;
1024 gs.StatisticsEnable = true;
1025 gs.KernelStartPointer = gs_bin->kernel.offset;
1026 gs.DispatchMode = gs_prog_data->base.dispatch_mode;
1027
1028 gs.SingleProgramFlow = false;
1029 gs.VectorMaskEnable = false;
1030 gs.SamplerCount = get_sampler_count(gs_bin);
1031 gs.BindingTableEntryCount = get_binding_table_entry_count(gs_bin);
1032 gs.IncludeVertexHandles = gs_prog_data->base.include_vue_handles;
1033 gs.IncludePrimitiveID = gs_prog_data->include_primitive_id;
1034
1035 if (GEN_GEN == 8) {
1036 /* Broadwell is weird. It needs us to divide by 2. */
1037 gs.MaximumNumberofThreads = devinfo->max_gs_threads / 2 - 1;
1038 } else {
1039 gs.MaximumNumberofThreads = devinfo->max_gs_threads - 1;
1040 }
1041
1042 gs.OutputVertexSize = gs_prog_data->output_vertex_size_hwords * 2 - 1;
1043 gs.OutputTopology = gs_prog_data->output_topology;
1044 gs.VertexURBEntryReadLength = gs_prog_data->base.urb_read_length;
1045 gs.ControlDataFormat = gs_prog_data->control_data_format;
1046 gs.ControlDataHeaderSize = gs_prog_data->control_data_header_size_hwords;
1047 gs.InstanceControl = MAX2(gs_prog_data->invocations, 1) - 1;
1048 #if GEN_GEN >= 8 || GEN_IS_HASWELL
1049 gs.ReorderMode = TRAILING;
1050 #else
1051 gs.ReorderEnable = true;
1052 #endif
1053
1054 #if GEN_GEN >= 8
1055 gs.ExpectedVertexCount = gs_prog_data->vertices_in;
1056 gs.StaticOutput = gs_prog_data->static_vertex_count >= 0;
1057 gs.StaticOutputVertexCount = gs_prog_data->static_vertex_count >= 0 ?
1058 gs_prog_data->static_vertex_count : 0;
1059 #endif
1060
1061 gs.VertexURBEntryReadOffset = 0;
1062 gs.VertexURBEntryReadLength = gs_prog_data->base.urb_read_length;
1063 gs.DispatchGRFStartRegisterForURBData =
1064 gs_prog_data->base.base.dispatch_grf_start_reg;
1065
1066 #if GEN_GEN >= 8
1067 gs.VertexURBEntryOutputReadOffset = get_urb_output_offset();
1068 gs.VertexURBEntryOutputLength = get_urb_output_length(gs_bin);
1069
1070 gs.UserClipDistanceClipTestEnableBitmask =
1071 gs_prog_data->base.clip_distance_mask;
1072 gs.UserClipDistanceCullTestEnableBitmask =
1073 gs_prog_data->base.cull_distance_mask;
1074 #endif
1075
1076 gs.PerThreadScratchSpace = get_scratch_space(gs_bin);
1077 gs.ScratchSpaceBasePointer =
1078 get_scratch_address(pipeline, MESA_SHADER_GEOMETRY, gs_bin);
1079 }
1080 }
1081
1082 static void
1083 emit_3dstate_wm(struct anv_pipeline *pipeline, struct anv_subpass *subpass,
1084 const VkPipelineMultisampleStateCreateInfo *multisample)
1085 {
1086 const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
1087
1088 MAYBE_UNUSED uint32_t samples =
1089 multisample ? multisample->rasterizationSamples : 1;
1090
1091 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_WM), wm) {
1092 wm.StatisticsEnable = true;
1093 wm.LineEndCapAntialiasingRegionWidth = _05pixels;
1094 wm.LineAntialiasingRegionWidth = _10pixels;
1095 wm.PointRasterizationRule = RASTRULE_UPPER_RIGHT;
1096
1097 if (anv_pipeline_has_stage(pipeline, MESA_SHADER_FRAGMENT)) {
1098 if (wm_prog_data->early_fragment_tests) {
1099 wm.EarlyDepthStencilControl = EDSC_PREPS;
1100 } else if (wm_prog_data->has_side_effects) {
1101 wm.EarlyDepthStencilControl = EDSC_PSEXEC;
1102 } else {
1103 wm.EarlyDepthStencilControl = EDSC_NORMAL;
1104 }
1105
1106 wm.BarycentricInterpolationMode =
1107 wm_prog_data->barycentric_interp_modes;
1108
1109 #if GEN_GEN < 8
1110 /* FIXME: This needs a lot more work, cf gen7 upload_wm_state(). */
1111 wm.ThreadDispatchEnable = true;
1112
1113 wm.PixelShaderComputedDepthMode = wm_prog_data->computed_depth_mode;
1114 wm.PixelShaderUsesSourceDepth = wm_prog_data->uses_src_depth;
1115 wm.PixelShaderUsesSourceW = wm_prog_data->uses_src_w;
1116 wm.PixelShaderUsesInputCoverageMask = wm_prog_data->uses_sample_mask;
1117
1118 /* If the subpass has a depth or stencil self-dependency, then we
1119 * need to force the hardware to do the depth/stencil write *after*
1120 * fragment shader execution. Otherwise, the writes may hit memory
1121 * before we get around to fetching from the input attachment and we
1122 * may get the depth or stencil value from the current draw rather
1123 * than the previous one.
1124 */
1125 wm.PixelShaderKillsPixel = subpass->has_ds_self_dep ||
1126 wm_prog_data->uses_kill;
1127
1128 if (samples > 1) {
1129 wm.MultisampleRasterizationMode = MSRASTMODE_ON_PATTERN;
1130 if (wm_prog_data->persample_dispatch) {
1131 wm.MultisampleDispatchMode = MSDISPMODE_PERSAMPLE;
1132 } else {
1133 wm.MultisampleDispatchMode = MSDISPMODE_PERPIXEL;
1134 }
1135 } else {
1136 wm.MultisampleRasterizationMode = MSRASTMODE_OFF_PIXEL;
1137 wm.MultisampleDispatchMode = MSDISPMODE_PERSAMPLE;
1138 }
1139 #endif
1140 }
1141 }
1142 }
1143
1144 static inline bool
1145 is_dual_src_blend_factor(VkBlendFactor factor)
1146 {
1147 return factor == VK_BLEND_FACTOR_SRC1_COLOR ||
1148 factor == VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR ||
1149 factor == VK_BLEND_FACTOR_SRC1_ALPHA ||
1150 factor == VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA;
1151 }
1152
1153 static void
1154 emit_3dstate_ps(struct anv_pipeline *pipeline,
1155 const VkPipelineColorBlendStateCreateInfo *blend)
1156 {
1157 MAYBE_UNUSED const struct gen_device_info *devinfo = &pipeline->device->info;
1158 const struct anv_shader_bin *fs_bin =
1159 pipeline->shaders[MESA_SHADER_FRAGMENT];
1160
1161 if (!anv_pipeline_has_stage(pipeline, MESA_SHADER_FRAGMENT)) {
1162 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_PS), ps) {
1163 #if GEN_GEN == 7
1164 /* Even if no fragments are ever dispatched, gen7 hardware hangs if
1165 * we don't at least set the maximum number of threads.
1166 */
1167 ps.MaximumNumberofThreads = devinfo->max_wm_threads - 1;
1168 #endif
1169 }
1170 return;
1171 }
1172
1173 const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
1174
1175 #if GEN_GEN < 8
1176 /* The hardware wedges if you have this bit set but don't turn on any dual
1177 * source blend factors.
1178 */
1179 bool dual_src_blend = false;
1180 if (wm_prog_data->dual_src_blend) {
1181 for (uint32_t i = 0; i < blend->attachmentCount; i++) {
1182 const VkPipelineColorBlendAttachmentState *bstate =
1183 &blend->pAttachments[i];
1184
1185 if (bstate->blendEnable &&
1186 (is_dual_src_blend_factor(bstate->srcColorBlendFactor) ||
1187 is_dual_src_blend_factor(bstate->dstColorBlendFactor) ||
1188 is_dual_src_blend_factor(bstate->srcAlphaBlendFactor) ||
1189 is_dual_src_blend_factor(bstate->dstAlphaBlendFactor))) {
1190 dual_src_blend = true;
1191 break;
1192 }
1193 }
1194 }
1195 #endif
1196
1197 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_PS), ps) {
1198 ps.KernelStartPointer0 = fs_bin->kernel.offset;
1199 ps.KernelStartPointer1 = 0;
1200 ps.KernelStartPointer2 = fs_bin->kernel.offset +
1201 wm_prog_data->prog_offset_2;
1202 ps._8PixelDispatchEnable = wm_prog_data->dispatch_8;
1203 ps._16PixelDispatchEnable = wm_prog_data->dispatch_16;
1204 ps._32PixelDispatchEnable = false;
1205
1206 ps.SingleProgramFlow = false;
1207 ps.VectorMaskEnable = true;
1208 ps.SamplerCount = get_sampler_count(fs_bin);
1209 ps.BindingTableEntryCount = get_binding_table_entry_count(fs_bin);
1210 ps.PushConstantEnable = wm_prog_data->base.nr_params > 0;
1211 ps.PositionXYOffsetSelect = wm_prog_data->uses_pos_offset ?
1212 POSOFFSET_SAMPLE: POSOFFSET_NONE;
1213 #if GEN_GEN < 8
1214 ps.AttributeEnable = wm_prog_data->num_varying_inputs > 0;
1215 ps.oMaskPresenttoRenderTarget = wm_prog_data->uses_omask;
1216 ps.DualSourceBlendEnable = dual_src_blend;
1217 #endif
1218
1219 #if GEN_IS_HASWELL
1220 /* Haswell requires the sample mask to be set in this packet as well
1221 * as in 3DSTATE_SAMPLE_MASK; the values should match.
1222 */
1223 ps.SampleMask = 0xff;
1224 #endif
1225
1226 #if GEN_GEN >= 9
1227 ps.MaximumNumberofThreadsPerPSD = 64 - 1;
1228 #elif GEN_GEN >= 8
1229 ps.MaximumNumberofThreadsPerPSD = 64 - 2;
1230 #else
1231 ps.MaximumNumberofThreads = devinfo->max_wm_threads - 1;
1232 #endif
1233
1234 ps.DispatchGRFStartRegisterForConstantSetupData0 =
1235 wm_prog_data->base.dispatch_grf_start_reg;
1236 ps.DispatchGRFStartRegisterForConstantSetupData1 = 0;
1237 ps.DispatchGRFStartRegisterForConstantSetupData2 =
1238 wm_prog_data->dispatch_grf_start_reg_2;
1239
1240 ps.PerThreadScratchSpace = get_scratch_space(fs_bin);
1241 ps.ScratchSpaceBasePointer =
1242 get_scratch_address(pipeline, MESA_SHADER_FRAGMENT, fs_bin);
1243 }
1244 }
1245
1246 #if GEN_GEN >= 8
1247 static void
1248 emit_3dstate_ps_extra(struct anv_pipeline *pipeline,
1249 struct anv_subpass *subpass)
1250 {
1251 const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
1252
1253 if (!anv_pipeline_has_stage(pipeline, MESA_SHADER_FRAGMENT)) {
1254 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_PS_EXTRA), ps);
1255 return;
1256 }
1257
1258 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_PS_EXTRA), ps) {
1259 ps.PixelShaderValid = true;
1260 ps.AttributeEnable = wm_prog_data->num_varying_inputs > 0;
1261 ps.oMaskPresenttoRenderTarget = wm_prog_data->uses_omask;
1262 ps.PixelShaderIsPerSample = wm_prog_data->persample_dispatch;
1263 ps.PixelShaderComputedDepthMode = wm_prog_data->computed_depth_mode;
1264 ps.PixelShaderUsesSourceDepth = wm_prog_data->uses_src_depth;
1265 ps.PixelShaderUsesSourceW = wm_prog_data->uses_src_w;
1266
1267 /* If the subpass has a depth or stencil self-dependency, then we need
1268 * to force the hardware to do the depth/stencil write *after* fragment
1269 * shader execution. Otherwise, the writes may hit memory before we get
1270 * around to fetching from the input attachment and we may get the depth
1271 * or stencil value from the current draw rather than the previous one.
1272 */
1273 ps.PixelShaderKillsPixel = subpass->has_ds_self_dep ||
1274 wm_prog_data->uses_kill;
1275
1276 #if GEN_GEN >= 9
1277 ps.PixelShaderPullsBary = wm_prog_data->pulls_bary;
1278 ps.InputCoverageMaskState = wm_prog_data->uses_sample_mask ?
1279 ICMS_INNER_CONSERVATIVE : ICMS_NONE;
1280 #else
1281 ps.PixelShaderUsesInputCoverageMask = wm_prog_data->uses_sample_mask;
1282 #endif
1283 }
1284 }
1285
1286 static void
1287 emit_3dstate_vf_topology(struct anv_pipeline *pipeline)
1288 {
1289 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_VF_TOPOLOGY), vft) {
1290 vft.PrimitiveTopologyType = pipeline->topology;
1291 }
1292 }
1293 #endif
1294
1295 static VkResult
1296 genX(graphics_pipeline_create)(
1297 VkDevice _device,
1298 struct anv_pipeline_cache * cache,
1299 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1300 const VkAllocationCallbacks* pAllocator,
1301 VkPipeline* pPipeline)
1302 {
1303 ANV_FROM_HANDLE(anv_device, device, _device);
1304 ANV_FROM_HANDLE(anv_render_pass, pass, pCreateInfo->renderPass);
1305 struct anv_subpass *subpass = &pass->subpasses[pCreateInfo->subpass];
1306 struct anv_pipeline *pipeline;
1307 VkResult result;
1308
1309 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
1310
1311 pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
1312 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
1313 if (pipeline == NULL)
1314 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1315
1316 result = anv_pipeline_init(pipeline, device, cache,
1317 pCreateInfo, pAllocator);
1318 if (result != VK_SUCCESS) {
1319 vk_free2(&device->alloc, pAllocator, pipeline);
1320 return result;
1321 }
1322
1323 assert(pCreateInfo->pVertexInputState);
1324 emit_vertex_input(pipeline, pCreateInfo->pVertexInputState);
1325 assert(pCreateInfo->pRasterizationState);
1326 emit_rs_state(pipeline, pCreateInfo->pRasterizationState,
1327 pCreateInfo->pMultisampleState, pass, subpass);
1328 emit_ms_state(pipeline, pCreateInfo->pMultisampleState);
1329 emit_ds_state(pipeline, pCreateInfo->pDepthStencilState, pass, subpass);
1330 emit_cb_state(pipeline, pCreateInfo->pColorBlendState,
1331 pCreateInfo->pMultisampleState);
1332
1333 emit_urb_setup(pipeline);
1334
1335 emit_3dstate_clip(pipeline, pCreateInfo->pViewportState,
1336 pCreateInfo->pRasterizationState);
1337 emit_3dstate_streamout(pipeline, pCreateInfo->pRasterizationState);
1338
1339 #if 0
1340 /* From gen7_vs_state.c */
1341
1342 /**
1343 * From Graphics BSpec: 3D-Media-GPGPU Engine > 3D Pipeline Stages >
1344 * Geometry > Geometry Shader > State:
1345 *
1346 * "Note: Because of corruption in IVB:GT2, software needs to flush the
1347 * whole fixed function pipeline when the GS enable changes value in
1348 * the 3DSTATE_GS."
1349 *
1350 * The hardware architects have clarified that in this context "flush the
1351 * whole fixed function pipeline" means to emit a PIPE_CONTROL with the "CS
1352 * Stall" bit set.
1353 */
1354 if (!brw->is_haswell && !brw->is_baytrail)
1355 gen7_emit_vs_workaround_flush(brw);
1356 #endif
1357
1358 emit_3dstate_vs(pipeline);
1359 emit_3dstate_gs(pipeline);
1360 emit_3dstate_sbe(pipeline);
1361 emit_3dstate_wm(pipeline, subpass, pCreateInfo->pMultisampleState);
1362 emit_3dstate_ps(pipeline, pCreateInfo->pColorBlendState);
1363 #if GEN_GEN >= 8
1364 emit_3dstate_ps_extra(pipeline, subpass);
1365 emit_3dstate_vf_topology(pipeline);
1366 #endif
1367
1368 *pPipeline = anv_pipeline_to_handle(pipeline);
1369
1370 return VK_SUCCESS;
1371 }
1372
1373 static VkResult
1374 compute_pipeline_create(
1375 VkDevice _device,
1376 struct anv_pipeline_cache * cache,
1377 const VkComputePipelineCreateInfo* pCreateInfo,
1378 const VkAllocationCallbacks* pAllocator,
1379 VkPipeline* pPipeline)
1380 {
1381 ANV_FROM_HANDLE(anv_device, device, _device);
1382 const struct anv_physical_device *physical_device =
1383 &device->instance->physicalDevice;
1384 const struct gen_device_info *devinfo = &physical_device->info;
1385 struct anv_pipeline *pipeline;
1386 VkResult result;
1387
1388 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO);
1389
1390 pipeline = vk_alloc2(&device->alloc, pAllocator, sizeof(*pipeline), 8,
1391 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
1392 if (pipeline == NULL)
1393 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1394
1395 pipeline->device = device;
1396 pipeline->layout = anv_pipeline_layout_from_handle(pCreateInfo->layout);
1397
1398 pipeline->blend_state.map = NULL;
1399
1400 result = anv_reloc_list_init(&pipeline->batch_relocs,
1401 pAllocator ? pAllocator : &device->alloc);
1402 if (result != VK_SUCCESS) {
1403 vk_free2(&device->alloc, pAllocator, pipeline);
1404 return result;
1405 }
1406 pipeline->batch.next = pipeline->batch.start = pipeline->batch_data;
1407 pipeline->batch.end = pipeline->batch.start + sizeof(pipeline->batch_data);
1408 pipeline->batch.relocs = &pipeline->batch_relocs;
1409
1410 /* When we free the pipeline, we detect stages based on the NULL status
1411 * of various prog_data pointers. Make them NULL by default.
1412 */
1413 memset(pipeline->shaders, 0, sizeof(pipeline->shaders));
1414
1415 pipeline->active_stages = 0;
1416
1417 pipeline->needs_data_cache = false;
1418
1419 assert(pCreateInfo->stage.stage == VK_SHADER_STAGE_COMPUTE_BIT);
1420 ANV_FROM_HANDLE(anv_shader_module, module, pCreateInfo->stage.module);
1421 result = anv_pipeline_compile_cs(pipeline, cache, pCreateInfo, module,
1422 pCreateInfo->stage.pName,
1423 pCreateInfo->stage.pSpecializationInfo);
1424 if (result != VK_SUCCESS) {
1425 vk_free2(&device->alloc, pAllocator, pipeline);
1426 return result;
1427 }
1428
1429 const struct brw_cs_prog_data *cs_prog_data = get_cs_prog_data(pipeline);
1430
1431 anv_pipeline_setup_l3_config(pipeline, cs_prog_data->base.total_shared > 0);
1432
1433 uint32_t group_size = cs_prog_data->local_size[0] *
1434 cs_prog_data->local_size[1] * cs_prog_data->local_size[2];
1435 uint32_t remainder = group_size & (cs_prog_data->simd_size - 1);
1436
1437 if (remainder > 0)
1438 pipeline->cs_right_mask = ~0u >> (32 - remainder);
1439 else
1440 pipeline->cs_right_mask = ~0u >> (32 - cs_prog_data->simd_size);
1441
1442 const uint32_t vfe_curbe_allocation =
1443 ALIGN(cs_prog_data->push.per_thread.regs * cs_prog_data->threads +
1444 cs_prog_data->push.cross_thread.regs, 2);
1445
1446 const uint32_t subslices = MAX2(physical_device->subslice_total, 1);
1447
1448 const struct anv_shader_bin *cs_bin =
1449 pipeline->shaders[MESA_SHADER_COMPUTE];
1450
1451 anv_batch_emit(&pipeline->batch, GENX(MEDIA_VFE_STATE), vfe) {
1452 #if GEN_GEN > 7
1453 vfe.StackSize = 0;
1454 #else
1455 vfe.GPGPUMode = true;
1456 #endif
1457 vfe.MaximumNumberofThreads =
1458 devinfo->max_cs_threads * subslices - 1;
1459 vfe.NumberofURBEntries = GEN_GEN <= 7 ? 0 : 2;
1460 vfe.ResetGatewayTimer = true;
1461 #if GEN_GEN <= 8
1462 vfe.BypassGatewayControl = true;
1463 #endif
1464 vfe.URBEntryAllocationSize = GEN_GEN <= 7 ? 0 : 2;
1465 vfe.CURBEAllocationSize = vfe_curbe_allocation;
1466
1467 vfe.PerThreadScratchSpace = get_scratch_space(cs_bin);
1468 vfe.ScratchSpaceBasePointer =
1469 get_scratch_address(pipeline, MESA_SHADER_COMPUTE, cs_bin);
1470 }
1471
1472 struct GENX(INTERFACE_DESCRIPTOR_DATA) desc = {
1473 .KernelStartPointer = cs_bin->kernel.offset,
1474
1475 .SamplerCount = get_sampler_count(cs_bin),
1476 .BindingTableEntryCount = get_binding_table_entry_count(cs_bin),
1477 .BarrierEnable = cs_prog_data->uses_barrier,
1478 .SharedLocalMemorySize =
1479 encode_slm_size(GEN_GEN, cs_prog_data->base.total_shared),
1480
1481 #if !GEN_IS_HASWELL
1482 .ConstantURBEntryReadOffset = 0,
1483 #endif
1484 .ConstantURBEntryReadLength = cs_prog_data->push.per_thread.regs,
1485 #if GEN_GEN >= 8 || GEN_IS_HASWELL
1486 .CrossThreadConstantDataReadLength =
1487 cs_prog_data->push.cross_thread.regs,
1488 #endif
1489
1490 .NumberofThreadsinGPGPUThreadGroup = cs_prog_data->threads,
1491 };
1492 GENX(INTERFACE_DESCRIPTOR_DATA_pack)(NULL,
1493 pipeline->interface_descriptor_data,
1494 &desc);
1495
1496 *pPipeline = anv_pipeline_to_handle(pipeline);
1497
1498 return VK_SUCCESS;
1499 }
1500
1501 VkResult genX(CreateGraphicsPipelines)(
1502 VkDevice _device,
1503 VkPipelineCache pipelineCache,
1504 uint32_t count,
1505 const VkGraphicsPipelineCreateInfo* pCreateInfos,
1506 const VkAllocationCallbacks* pAllocator,
1507 VkPipeline* pPipelines)
1508 {
1509 ANV_FROM_HANDLE(anv_pipeline_cache, pipeline_cache, pipelineCache);
1510
1511 VkResult result = VK_SUCCESS;
1512
1513 unsigned i;
1514 for (i = 0; i < count; i++) {
1515 result = genX(graphics_pipeline_create)(_device,
1516 pipeline_cache,
1517 &pCreateInfos[i],
1518 pAllocator, &pPipelines[i]);
1519
1520 /* Bail out on the first error as it is not obvious what error should be
1521 * report upon 2 different failures. */
1522 if (result != VK_SUCCESS)
1523 break;
1524 }
1525
1526 for (; i < count; i++)
1527 pPipelines[i] = VK_NULL_HANDLE;
1528
1529 return result;
1530 }
1531
1532 VkResult genX(CreateComputePipelines)(
1533 VkDevice _device,
1534 VkPipelineCache pipelineCache,
1535 uint32_t count,
1536 const VkComputePipelineCreateInfo* pCreateInfos,
1537 const VkAllocationCallbacks* pAllocator,
1538 VkPipeline* pPipelines)
1539 {
1540 ANV_FROM_HANDLE(anv_pipeline_cache, pipeline_cache, pipelineCache);
1541
1542 VkResult result = VK_SUCCESS;
1543
1544 unsigned i;
1545 for (i = 0; i < count; i++) {
1546 result = compute_pipeline_create(_device, pipeline_cache,
1547 &pCreateInfos[i],
1548 pAllocator, &pPipelines[i]);
1549
1550 /* Bail out on the first error as it is not obvious what error should be
1551 * report upon 2 different failures. */
1552 if (result != VK_SUCCESS)
1553 break;
1554 }
1555
1556 for (; i < count; i++)
1557 pPipelines[i] = VK_NULL_HANDLE;
1558
1559 return result;
1560 }