anv: Implement SSBOs bindings with GPU addresses in the descriptor BO
[mesa.git] / src / intel / vulkan / anv_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 <assert.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29
30 #include "util/mesa-sha1.h"
31 #include "util/os_time.h"
32 #include "common/gen_l3_config.h"
33 #include "anv_private.h"
34 #include "compiler/brw_nir.h"
35 #include "anv_nir.h"
36 #include "nir/nir_xfb_info.h"
37 #include "spirv/nir_spirv.h"
38 #include "vk_util.h"
39
40 /* Needed for SWIZZLE macros */
41 #include "program/prog_instruction.h"
42
43 // Shader functions
44
45 VkResult anv_CreateShaderModule(
46 VkDevice _device,
47 const VkShaderModuleCreateInfo* pCreateInfo,
48 const VkAllocationCallbacks* pAllocator,
49 VkShaderModule* pShaderModule)
50 {
51 ANV_FROM_HANDLE(anv_device, device, _device);
52 struct anv_shader_module *module;
53
54 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
55 assert(pCreateInfo->flags == 0);
56
57 module = vk_alloc2(&device->alloc, pAllocator,
58 sizeof(*module) + pCreateInfo->codeSize, 8,
59 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
60 if (module == NULL)
61 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
62
63 module->size = pCreateInfo->codeSize;
64 memcpy(module->data, pCreateInfo->pCode, module->size);
65
66 _mesa_sha1_compute(module->data, module->size, module->sha1);
67
68 *pShaderModule = anv_shader_module_to_handle(module);
69
70 return VK_SUCCESS;
71 }
72
73 void anv_DestroyShaderModule(
74 VkDevice _device,
75 VkShaderModule _module,
76 const VkAllocationCallbacks* pAllocator)
77 {
78 ANV_FROM_HANDLE(anv_device, device, _device);
79 ANV_FROM_HANDLE(anv_shader_module, module, _module);
80
81 if (!module)
82 return;
83
84 vk_free2(&device->alloc, pAllocator, module);
85 }
86
87 #define SPIR_V_MAGIC_NUMBER 0x07230203
88
89 static const uint64_t stage_to_debug[] = {
90 [MESA_SHADER_VERTEX] = DEBUG_VS,
91 [MESA_SHADER_TESS_CTRL] = DEBUG_TCS,
92 [MESA_SHADER_TESS_EVAL] = DEBUG_TES,
93 [MESA_SHADER_GEOMETRY] = DEBUG_GS,
94 [MESA_SHADER_FRAGMENT] = DEBUG_WM,
95 [MESA_SHADER_COMPUTE] = DEBUG_CS,
96 };
97
98 /* Eventually, this will become part of anv_CreateShader. Unfortunately,
99 * we can't do that yet because we don't have the ability to copy nir.
100 */
101 static nir_shader *
102 anv_shader_compile_to_nir(struct anv_device *device,
103 void *mem_ctx,
104 const struct anv_shader_module *module,
105 const char *entrypoint_name,
106 gl_shader_stage stage,
107 const VkSpecializationInfo *spec_info)
108 {
109 const struct anv_physical_device *pdevice =
110 &device->instance->physicalDevice;
111 const struct brw_compiler *compiler = pdevice->compiler;
112 const nir_shader_compiler_options *nir_options =
113 compiler->glsl_compiler_options[stage].NirOptions;
114
115 uint32_t *spirv = (uint32_t *) module->data;
116 assert(spirv[0] == SPIR_V_MAGIC_NUMBER);
117 assert(module->size % 4 == 0);
118
119 uint32_t num_spec_entries = 0;
120 struct nir_spirv_specialization *spec_entries = NULL;
121 if (spec_info && spec_info->mapEntryCount > 0) {
122 num_spec_entries = spec_info->mapEntryCount;
123 spec_entries = malloc(num_spec_entries * sizeof(*spec_entries));
124 for (uint32_t i = 0; i < num_spec_entries; i++) {
125 VkSpecializationMapEntry entry = spec_info->pMapEntries[i];
126 const void *data = spec_info->pData + entry.offset;
127 assert(data + entry.size <= spec_info->pData + spec_info->dataSize);
128
129 spec_entries[i].id = spec_info->pMapEntries[i].constantID;
130 if (spec_info->dataSize == 8)
131 spec_entries[i].data64 = *(const uint64_t *)data;
132 else
133 spec_entries[i].data32 = *(const uint32_t *)data;
134 }
135 }
136
137 struct spirv_to_nir_options spirv_options = {
138 .lower_workgroup_access_to_offsets = true,
139 .caps = {
140 .derivative_group = true,
141 .device_group = true,
142 .draw_parameters = true,
143 .float16 = pdevice->info.gen >= 8,
144 .float64 = pdevice->info.gen >= 8,
145 .geometry_streams = true,
146 .image_write_without_format = true,
147 .int8 = pdevice->info.gen >= 8,
148 .int16 = pdevice->info.gen >= 8,
149 .int64 = pdevice->info.gen >= 8,
150 .min_lod = true,
151 .multiview = true,
152 .physical_storage_buffer_address = pdevice->has_a64_buffer_access,
153 .post_depth_coverage = pdevice->info.gen >= 9,
154 .shader_viewport_index_layer = true,
155 .stencil_export = pdevice->info.gen >= 9,
156 .storage_8bit = pdevice->info.gen >= 8,
157 .storage_16bit = pdevice->info.gen >= 8,
158 .subgroup_arithmetic = true,
159 .subgroup_basic = true,
160 .subgroup_ballot = true,
161 .subgroup_quad = true,
162 .subgroup_shuffle = true,
163 .subgroup_vote = true,
164 .tessellation = true,
165 .transform_feedback = pdevice->info.gen >= 8,
166 .variable_pointers = true,
167 },
168 .ubo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT, 2),
169 .phys_ssbo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT64, 1),
170 .push_const_ptr_type = glsl_uint_type(),
171 .shared_ptr_type = glsl_uint_type(),
172 };
173
174 if (pdevice->has_a64_buffer_access) {
175 if (device->robust_buffer_access)
176 spirv_options.ssbo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT, 4);
177 else
178 spirv_options.ssbo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT64, 1);
179 } else {
180 spirv_options.ssbo_ptr_type = glsl_vector_type(GLSL_TYPE_UINT, 2);
181 }
182
183 nir_function *entry_point =
184 spirv_to_nir(spirv, module->size / 4,
185 spec_entries, num_spec_entries,
186 stage, entrypoint_name, &spirv_options, nir_options);
187 nir_shader *nir = entry_point->shader;
188 assert(nir->info.stage == stage);
189 nir_validate_shader(nir, "after spirv_to_nir");
190 ralloc_steal(mem_ctx, nir);
191
192 free(spec_entries);
193
194 if (unlikely(INTEL_DEBUG & stage_to_debug[stage])) {
195 fprintf(stderr, "NIR (from SPIR-V) for %s shader:\n",
196 gl_shader_stage_name(stage));
197 nir_print_shader(nir, stderr);
198 }
199
200 /* We have to lower away local constant initializers right before we
201 * inline functions. That way they get properly initialized at the top
202 * of the function and not at the top of its caller.
203 */
204 NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp);
205 NIR_PASS_V(nir, nir_lower_returns);
206 NIR_PASS_V(nir, nir_inline_functions);
207 NIR_PASS_V(nir, nir_opt_deref);
208
209 /* Pick off the single entrypoint that we want */
210 foreach_list_typed_safe(nir_function, func, node, &nir->functions) {
211 if (func != entry_point)
212 exec_node_remove(&func->node);
213 }
214 assert(exec_list_length(&nir->functions) == 1);
215
216 /* Now that we've deleted all but the main function, we can go ahead and
217 * lower the rest of the constant initializers. We do this here so that
218 * nir_remove_dead_variables and split_per_member_structs below see the
219 * corresponding stores.
220 */
221 NIR_PASS_V(nir, nir_lower_constant_initializers, ~0);
222
223 /* Split member structs. We do this before lower_io_to_temporaries so that
224 * it doesn't lower system values to temporaries by accident.
225 */
226 NIR_PASS_V(nir, nir_split_var_copies);
227 NIR_PASS_V(nir, nir_split_per_member_structs);
228
229 NIR_PASS_V(nir, nir_remove_dead_variables,
230 nir_var_shader_in | nir_var_shader_out | nir_var_system_value);
231
232 NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_mem_global,
233 nir_address_format_64bit_global);
234
235 NIR_PASS_V(nir, nir_propagate_invariant);
236 NIR_PASS_V(nir, nir_lower_io_to_temporaries,
237 entry_point->impl, true, false);
238
239 NIR_PASS_V(nir, nir_lower_frexp);
240
241 /* Vulkan uses the separate-shader linking model */
242 nir->info.separate_shader = true;
243
244 nir = brw_preprocess_nir(compiler, nir, NULL);
245
246 return nir;
247 }
248
249 void anv_DestroyPipeline(
250 VkDevice _device,
251 VkPipeline _pipeline,
252 const VkAllocationCallbacks* pAllocator)
253 {
254 ANV_FROM_HANDLE(anv_device, device, _device);
255 ANV_FROM_HANDLE(anv_pipeline, pipeline, _pipeline);
256
257 if (!pipeline)
258 return;
259
260 anv_reloc_list_finish(&pipeline->batch_relocs,
261 pAllocator ? pAllocator : &device->alloc);
262 if (pipeline->blend_state.map)
263 anv_state_pool_free(&device->dynamic_state_pool, pipeline->blend_state);
264
265 for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
266 if (pipeline->shaders[s])
267 anv_shader_bin_unref(device, pipeline->shaders[s]);
268 }
269
270 vk_free2(&device->alloc, pAllocator, pipeline);
271 }
272
273 static const uint32_t vk_to_gen_primitive_type[] = {
274 [VK_PRIMITIVE_TOPOLOGY_POINT_LIST] = _3DPRIM_POINTLIST,
275 [VK_PRIMITIVE_TOPOLOGY_LINE_LIST] = _3DPRIM_LINELIST,
276 [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP] = _3DPRIM_LINESTRIP,
277 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST] = _3DPRIM_TRILIST,
278 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP] = _3DPRIM_TRISTRIP,
279 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN] = _3DPRIM_TRIFAN,
280 [VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY] = _3DPRIM_LINELIST_ADJ,
281 [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY] = _3DPRIM_LINESTRIP_ADJ,
282 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY] = _3DPRIM_TRILIST_ADJ,
283 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY] = _3DPRIM_TRISTRIP_ADJ,
284 };
285
286 static void
287 populate_sampler_prog_key(const struct gen_device_info *devinfo,
288 struct brw_sampler_prog_key_data *key)
289 {
290 /* Almost all multisampled textures are compressed. The only time when we
291 * don't compress a multisampled texture is for 16x MSAA with a surface
292 * width greater than 8k which is a bit of an edge case. Since the sampler
293 * just ignores the MCS parameter to ld2ms when MCS is disabled, it's safe
294 * to tell the compiler to always assume compression.
295 */
296 key->compressed_multisample_layout_mask = ~0;
297
298 /* SkyLake added support for 16x MSAA. With this came a new message for
299 * reading from a 16x MSAA surface with compression. The new message was
300 * needed because now the MCS data is 64 bits instead of 32 or lower as is
301 * the case for 8x, 4x, and 2x. The key->msaa_16 bit-field controls which
302 * message we use. Fortunately, the 16x message works for 8x, 4x, and 2x
303 * so we can just use it unconditionally. This may not be quite as
304 * efficient but it saves us from recompiling.
305 */
306 if (devinfo->gen >= 9)
307 key->msaa_16 = ~0;
308
309 /* XXX: Handle texture swizzle on HSW- */
310 for (int i = 0; i < MAX_SAMPLERS; i++) {
311 /* Assume color sampler, no swizzling. (Works for BDW+) */
312 key->swizzles[i] = SWIZZLE_XYZW;
313 }
314 }
315
316 static void
317 populate_vs_prog_key(const struct gen_device_info *devinfo,
318 struct brw_vs_prog_key *key)
319 {
320 memset(key, 0, sizeof(*key));
321
322 populate_sampler_prog_key(devinfo, &key->tex);
323
324 /* XXX: Handle vertex input work-arounds */
325
326 /* XXX: Handle sampler_prog_key */
327 }
328
329 static void
330 populate_tcs_prog_key(const struct gen_device_info *devinfo,
331 unsigned input_vertices,
332 struct brw_tcs_prog_key *key)
333 {
334 memset(key, 0, sizeof(*key));
335
336 populate_sampler_prog_key(devinfo, &key->tex);
337
338 key->input_vertices = input_vertices;
339 }
340
341 static void
342 populate_tes_prog_key(const struct gen_device_info *devinfo,
343 struct brw_tes_prog_key *key)
344 {
345 memset(key, 0, sizeof(*key));
346
347 populate_sampler_prog_key(devinfo, &key->tex);
348 }
349
350 static void
351 populate_gs_prog_key(const struct gen_device_info *devinfo,
352 struct brw_gs_prog_key *key)
353 {
354 memset(key, 0, sizeof(*key));
355
356 populate_sampler_prog_key(devinfo, &key->tex);
357 }
358
359 static void
360 populate_wm_prog_key(const struct gen_device_info *devinfo,
361 const struct anv_subpass *subpass,
362 const VkPipelineMultisampleStateCreateInfo *ms_info,
363 struct brw_wm_prog_key *key)
364 {
365 memset(key, 0, sizeof(*key));
366
367 populate_sampler_prog_key(devinfo, &key->tex);
368
369 /* We set this to 0 here and set to the actual value before we call
370 * brw_compile_fs.
371 */
372 key->input_slots_valid = 0;
373
374 /* Vulkan doesn't specify a default */
375 key->high_quality_derivatives = false;
376
377 /* XXX Vulkan doesn't appear to specify */
378 key->clamp_fragment_color = false;
379
380 assert(subpass->color_count <= MAX_RTS);
381 for (uint32_t i = 0; i < subpass->color_count; i++) {
382 if (subpass->color_attachments[i].attachment != VK_ATTACHMENT_UNUSED)
383 key->color_outputs_valid |= (1 << i);
384 }
385
386 key->nr_color_regions = util_bitcount(key->color_outputs_valid);
387
388 /* To reduce possible shader recompilations we would need to know if
389 * there is a SampleMask output variable to compute if we should emit
390 * code to workaround the issue that hardware disables alpha to coverage
391 * when there is SampleMask output.
392 */
393 key->alpha_to_coverage = ms_info && ms_info->alphaToCoverageEnable;
394
395 /* Vulkan doesn't support fixed-function alpha test */
396 key->alpha_test_replicate_alpha = false;
397
398 if (ms_info) {
399 /* We should probably pull this out of the shader, but it's fairly
400 * harmless to compute it and then let dead-code take care of it.
401 */
402 if (ms_info->rasterizationSamples > 1) {
403 key->persample_interp =
404 (ms_info->minSampleShading * ms_info->rasterizationSamples) > 1;
405 key->multisample_fbo = true;
406 }
407
408 key->frag_coord_adds_sample_pos = ms_info->sampleShadingEnable;
409 }
410 }
411
412 static void
413 populate_cs_prog_key(const struct gen_device_info *devinfo,
414 struct brw_cs_prog_key *key)
415 {
416 memset(key, 0, sizeof(*key));
417
418 populate_sampler_prog_key(devinfo, &key->tex);
419 }
420
421 struct anv_pipeline_stage {
422 gl_shader_stage stage;
423
424 const struct anv_shader_module *module;
425 const char *entrypoint;
426 const VkSpecializationInfo *spec_info;
427
428 unsigned char shader_sha1[20];
429
430 union brw_any_prog_key key;
431
432 struct {
433 gl_shader_stage stage;
434 unsigned char sha1[20];
435 } cache_key;
436
437 nir_shader *nir;
438
439 struct anv_pipeline_binding surface_to_descriptor[256];
440 struct anv_pipeline_binding sampler_to_descriptor[256];
441 struct anv_pipeline_bind_map bind_map;
442
443 union brw_any_prog_data prog_data;
444
445 VkPipelineCreationFeedbackEXT feedback;
446 };
447
448 static void
449 anv_pipeline_hash_shader(const struct anv_shader_module *module,
450 const char *entrypoint,
451 gl_shader_stage stage,
452 const VkSpecializationInfo *spec_info,
453 unsigned char *sha1_out)
454 {
455 struct mesa_sha1 ctx;
456 _mesa_sha1_init(&ctx);
457
458 _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
459 _mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint));
460 _mesa_sha1_update(&ctx, &stage, sizeof(stage));
461 if (spec_info) {
462 _mesa_sha1_update(&ctx, spec_info->pMapEntries,
463 spec_info->mapEntryCount *
464 sizeof(*spec_info->pMapEntries));
465 _mesa_sha1_update(&ctx, spec_info->pData,
466 spec_info->dataSize);
467 }
468
469 _mesa_sha1_final(&ctx, sha1_out);
470 }
471
472 static void
473 anv_pipeline_hash_graphics(struct anv_pipeline *pipeline,
474 struct anv_pipeline_layout *layout,
475 struct anv_pipeline_stage *stages,
476 unsigned char *sha1_out)
477 {
478 struct mesa_sha1 ctx;
479 _mesa_sha1_init(&ctx);
480
481 _mesa_sha1_update(&ctx, &pipeline->subpass->view_mask,
482 sizeof(pipeline->subpass->view_mask));
483
484 if (layout)
485 _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
486
487 const bool rba = pipeline->device->robust_buffer_access;
488 _mesa_sha1_update(&ctx, &rba, sizeof(rba));
489
490 for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
491 if (stages[s].entrypoint) {
492 _mesa_sha1_update(&ctx, stages[s].shader_sha1,
493 sizeof(stages[s].shader_sha1));
494 _mesa_sha1_update(&ctx, &stages[s].key, brw_prog_key_size(s));
495 }
496 }
497
498 _mesa_sha1_final(&ctx, sha1_out);
499 }
500
501 static void
502 anv_pipeline_hash_compute(struct anv_pipeline *pipeline,
503 struct anv_pipeline_layout *layout,
504 struct anv_pipeline_stage *stage,
505 unsigned char *sha1_out)
506 {
507 struct mesa_sha1 ctx;
508 _mesa_sha1_init(&ctx);
509
510 if (layout)
511 _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
512
513 const bool rba = pipeline->device->robust_buffer_access;
514 _mesa_sha1_update(&ctx, &rba, sizeof(rba));
515
516 _mesa_sha1_update(&ctx, stage->shader_sha1,
517 sizeof(stage->shader_sha1));
518 _mesa_sha1_update(&ctx, &stage->key.cs, sizeof(stage->key.cs));
519
520 _mesa_sha1_final(&ctx, sha1_out);
521 }
522
523 static nir_shader *
524 anv_pipeline_stage_get_nir(struct anv_pipeline *pipeline,
525 struct anv_pipeline_cache *cache,
526 void *mem_ctx,
527 struct anv_pipeline_stage *stage)
528 {
529 const struct brw_compiler *compiler =
530 pipeline->device->instance->physicalDevice.compiler;
531 const nir_shader_compiler_options *nir_options =
532 compiler->glsl_compiler_options[stage->stage].NirOptions;
533 nir_shader *nir;
534
535 nir = anv_device_search_for_nir(pipeline->device, cache,
536 nir_options,
537 stage->shader_sha1,
538 mem_ctx);
539 if (nir) {
540 assert(nir->info.stage == stage->stage);
541 return nir;
542 }
543
544 nir = anv_shader_compile_to_nir(pipeline->device,
545 mem_ctx,
546 stage->module,
547 stage->entrypoint,
548 stage->stage,
549 stage->spec_info);
550 if (nir) {
551 anv_device_upload_nir(pipeline->device, cache, nir, stage->shader_sha1);
552 return nir;
553 }
554
555 return NULL;
556 }
557
558 static void
559 anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
560 void *mem_ctx,
561 struct anv_pipeline_stage *stage,
562 struct anv_pipeline_layout *layout)
563 {
564 const struct anv_physical_device *pdevice =
565 &pipeline->device->instance->physicalDevice;
566 const struct brw_compiler *compiler = pdevice->compiler;
567
568 struct brw_stage_prog_data *prog_data = &stage->prog_data.base;
569 nir_shader *nir = stage->nir;
570
571 if (nir->info.stage == MESA_SHADER_FRAGMENT) {
572 NIR_PASS_V(nir, nir_lower_wpos_center, pipeline->sample_shading_enable);
573 NIR_PASS_V(nir, anv_nir_lower_input_attachments);
574 }
575
576 NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);
577
578 NIR_PASS_V(nir, anv_nir_lower_push_constants);
579
580 if (nir->info.stage != MESA_SHADER_COMPUTE)
581 NIR_PASS_V(nir, anv_nir_lower_multiview, pipeline->subpass->view_mask);
582
583 if (nir->info.stage == MESA_SHADER_COMPUTE)
584 prog_data->total_shared = nir->num_shared;
585
586 nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
587
588 if (nir->num_uniforms > 0) {
589 assert(prog_data->nr_params == 0);
590
591 /* If the shader uses any push constants at all, we'll just give
592 * them the maximum possible number
593 */
594 assert(nir->num_uniforms <= MAX_PUSH_CONSTANTS_SIZE);
595 nir->num_uniforms = MAX_PUSH_CONSTANTS_SIZE;
596 prog_data->nr_params += MAX_PUSH_CONSTANTS_SIZE / sizeof(float);
597 prog_data->param = ralloc_array(mem_ctx, uint32_t, prog_data->nr_params);
598
599 /* We now set the param values to be offsets into a
600 * anv_push_constant_data structure. Since the compiler doesn't
601 * actually dereference any of the gl_constant_value pointers in the
602 * params array, it doesn't really matter what we put here.
603 */
604 struct anv_push_constants *null_data = NULL;
605 /* Fill out the push constants section of the param array */
606 for (unsigned i = 0; i < MAX_PUSH_CONSTANTS_SIZE / sizeof(float); i++) {
607 prog_data->param[i] = ANV_PARAM_PUSH(
608 (uintptr_t)&null_data->client_data[i * sizeof(float)]);
609 }
610 }
611
612 if (nir->info.num_ssbos > 0 || nir->info.num_images > 0)
613 pipeline->needs_data_cache = true;
614
615 NIR_PASS_V(nir, brw_nir_lower_image_load_store, compiler->devinfo);
616
617 /* Apply the actual pipeline layout to UBOs, SSBOs, and textures */
618 if (layout) {
619 anv_nir_apply_pipeline_layout(pdevice,
620 pipeline->device->robust_buffer_access,
621 layout, nir, prog_data,
622 &stage->bind_map);
623
624 NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_mem_ubo,
625 nir_address_format_32bit_index_offset);
626
627 nir_address_format ssbo_address_format;
628 if (pdevice->has_a64_buffer_access) {
629 if (pipeline->device->robust_buffer_access)
630 ssbo_address_format = nir_address_format_64bit_bounded_global;
631 else
632 ssbo_address_format = nir_address_format_64bit_global;
633 } else {
634 ssbo_address_format = nir_address_format_32bit_index_offset;
635 }
636 NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_mem_ssbo,
637 ssbo_address_format);
638
639 NIR_PASS_V(nir, nir_opt_constant_folding);
640 }
641
642 if (nir->info.stage != MESA_SHADER_COMPUTE)
643 brw_nir_analyze_ubo_ranges(compiler, nir, NULL, prog_data->ubo_ranges);
644
645 assert(nir->num_uniforms == prog_data->nr_params * 4);
646
647 stage->nir = nir;
648 }
649
650 static void
651 anv_pipeline_link_vs(const struct brw_compiler *compiler,
652 struct anv_pipeline_stage *vs_stage,
653 struct anv_pipeline_stage *next_stage)
654 {
655 if (next_stage)
656 brw_nir_link_shaders(compiler, &vs_stage->nir, &next_stage->nir);
657 }
658
659 static const unsigned *
660 anv_pipeline_compile_vs(const struct brw_compiler *compiler,
661 void *mem_ctx,
662 struct anv_device *device,
663 struct anv_pipeline_stage *vs_stage)
664 {
665 brw_compute_vue_map(compiler->devinfo,
666 &vs_stage->prog_data.vs.base.vue_map,
667 vs_stage->nir->info.outputs_written,
668 vs_stage->nir->info.separate_shader);
669
670 return brw_compile_vs(compiler, device, mem_ctx, &vs_stage->key.vs,
671 &vs_stage->prog_data.vs, vs_stage->nir, -1, NULL);
672 }
673
674 static void
675 merge_tess_info(struct shader_info *tes_info,
676 const struct shader_info *tcs_info)
677 {
678 /* The Vulkan 1.0.38 spec, section 21.1 Tessellator says:
679 *
680 * "PointMode. Controls generation of points rather than triangles
681 * or lines. This functionality defaults to disabled, and is
682 * enabled if either shader stage includes the execution mode.
683 *
684 * and about Triangles, Quads, IsoLines, VertexOrderCw, VertexOrderCcw,
685 * PointMode, SpacingEqual, SpacingFractionalEven, SpacingFractionalOdd,
686 * and OutputVertices, it says:
687 *
688 * "One mode must be set in at least one of the tessellation
689 * shader stages."
690 *
691 * So, the fields can be set in either the TCS or TES, but they must
692 * agree if set in both. Our backend looks at TES, so bitwise-or in
693 * the values from the TCS.
694 */
695 assert(tcs_info->tess.tcs_vertices_out == 0 ||
696 tes_info->tess.tcs_vertices_out == 0 ||
697 tcs_info->tess.tcs_vertices_out == tes_info->tess.tcs_vertices_out);
698 tes_info->tess.tcs_vertices_out |= tcs_info->tess.tcs_vertices_out;
699
700 assert(tcs_info->tess.spacing == TESS_SPACING_UNSPECIFIED ||
701 tes_info->tess.spacing == TESS_SPACING_UNSPECIFIED ||
702 tcs_info->tess.spacing == tes_info->tess.spacing);
703 tes_info->tess.spacing |= tcs_info->tess.spacing;
704
705 assert(tcs_info->tess.primitive_mode == 0 ||
706 tes_info->tess.primitive_mode == 0 ||
707 tcs_info->tess.primitive_mode == tes_info->tess.primitive_mode);
708 tes_info->tess.primitive_mode |= tcs_info->tess.primitive_mode;
709 tes_info->tess.ccw |= tcs_info->tess.ccw;
710 tes_info->tess.point_mode |= tcs_info->tess.point_mode;
711 }
712
713 static void
714 anv_pipeline_link_tcs(const struct brw_compiler *compiler,
715 struct anv_pipeline_stage *tcs_stage,
716 struct anv_pipeline_stage *tes_stage)
717 {
718 assert(tes_stage && tes_stage->stage == MESA_SHADER_TESS_EVAL);
719
720 brw_nir_link_shaders(compiler, &tcs_stage->nir, &tes_stage->nir);
721
722 nir_lower_patch_vertices(tes_stage->nir,
723 tcs_stage->nir->info.tess.tcs_vertices_out,
724 NULL);
725
726 /* Copy TCS info into the TES info */
727 merge_tess_info(&tes_stage->nir->info, &tcs_stage->nir->info);
728
729 /* Whacking the key after cache lookup is a bit sketchy, but all of
730 * this comes from the SPIR-V, which is part of the hash used for the
731 * pipeline cache. So it should be safe.
732 */
733 tcs_stage->key.tcs.tes_primitive_mode =
734 tes_stage->nir->info.tess.primitive_mode;
735 tcs_stage->key.tcs.quads_workaround =
736 compiler->devinfo->gen < 9 &&
737 tes_stage->nir->info.tess.primitive_mode == 7 /* GL_QUADS */ &&
738 tes_stage->nir->info.tess.spacing == TESS_SPACING_EQUAL;
739 }
740
741 static const unsigned *
742 anv_pipeline_compile_tcs(const struct brw_compiler *compiler,
743 void *mem_ctx,
744 struct anv_device *device,
745 struct anv_pipeline_stage *tcs_stage,
746 struct anv_pipeline_stage *prev_stage)
747 {
748 tcs_stage->key.tcs.outputs_written =
749 tcs_stage->nir->info.outputs_written;
750 tcs_stage->key.tcs.patch_outputs_written =
751 tcs_stage->nir->info.patch_outputs_written;
752
753 return brw_compile_tcs(compiler, device, mem_ctx, &tcs_stage->key.tcs,
754 &tcs_stage->prog_data.tcs, tcs_stage->nir,
755 -1, NULL);
756 }
757
758 static void
759 anv_pipeline_link_tes(const struct brw_compiler *compiler,
760 struct anv_pipeline_stage *tes_stage,
761 struct anv_pipeline_stage *next_stage)
762 {
763 if (next_stage)
764 brw_nir_link_shaders(compiler, &tes_stage->nir, &next_stage->nir);
765 }
766
767 static const unsigned *
768 anv_pipeline_compile_tes(const struct brw_compiler *compiler,
769 void *mem_ctx,
770 struct anv_device *device,
771 struct anv_pipeline_stage *tes_stage,
772 struct anv_pipeline_stage *tcs_stage)
773 {
774 tes_stage->key.tes.inputs_read =
775 tcs_stage->nir->info.outputs_written;
776 tes_stage->key.tes.patch_inputs_read =
777 tcs_stage->nir->info.patch_outputs_written;
778
779 return brw_compile_tes(compiler, device, mem_ctx, &tes_stage->key.tes,
780 &tcs_stage->prog_data.tcs.base.vue_map,
781 &tes_stage->prog_data.tes, tes_stage->nir,
782 NULL, -1, NULL);
783 }
784
785 static void
786 anv_pipeline_link_gs(const struct brw_compiler *compiler,
787 struct anv_pipeline_stage *gs_stage,
788 struct anv_pipeline_stage *next_stage)
789 {
790 if (next_stage)
791 brw_nir_link_shaders(compiler, &gs_stage->nir, &next_stage->nir);
792 }
793
794 static const unsigned *
795 anv_pipeline_compile_gs(const struct brw_compiler *compiler,
796 void *mem_ctx,
797 struct anv_device *device,
798 struct anv_pipeline_stage *gs_stage,
799 struct anv_pipeline_stage *prev_stage)
800 {
801 brw_compute_vue_map(compiler->devinfo,
802 &gs_stage->prog_data.gs.base.vue_map,
803 gs_stage->nir->info.outputs_written,
804 gs_stage->nir->info.separate_shader);
805
806 return brw_compile_gs(compiler, device, mem_ctx, &gs_stage->key.gs,
807 &gs_stage->prog_data.gs, gs_stage->nir,
808 NULL, -1, NULL);
809 }
810
811 static void
812 anv_pipeline_link_fs(const struct brw_compiler *compiler,
813 struct anv_pipeline_stage *stage)
814 {
815 unsigned num_rts = 0;
816 const int max_rt = FRAG_RESULT_DATA7 - FRAG_RESULT_DATA0 + 1;
817 struct anv_pipeline_binding rt_bindings[max_rt];
818 nir_function_impl *impl = nir_shader_get_entrypoint(stage->nir);
819 int rt_to_bindings[max_rt];
820 memset(rt_to_bindings, -1, sizeof(rt_to_bindings));
821 bool rt_used[max_rt];
822 memset(rt_used, 0, sizeof(rt_used));
823
824 /* Flag used render targets */
825 nir_foreach_variable_safe(var, &stage->nir->outputs) {
826 if (var->data.location < FRAG_RESULT_DATA0)
827 continue;
828
829 const unsigned rt = var->data.location - FRAG_RESULT_DATA0;
830 /* Unused or out-of-bounds */
831 if (rt >= MAX_RTS || !(stage->key.wm.color_outputs_valid & (1 << rt)))
832 continue;
833
834 const unsigned array_len =
835 glsl_type_is_array(var->type) ? glsl_get_length(var->type) : 1;
836 assert(rt + array_len <= max_rt);
837
838 for (unsigned i = 0; i < array_len; i++)
839 rt_used[rt + i] = true;
840 }
841
842 /* Set new, compacted, location */
843 for (unsigned i = 0; i < max_rt; i++) {
844 if (!rt_used[i])
845 continue;
846
847 rt_to_bindings[i] = num_rts;
848 rt_bindings[rt_to_bindings[i]] = (struct anv_pipeline_binding) {
849 .set = ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS,
850 .binding = 0,
851 .index = i,
852 };
853 num_rts++;
854 }
855
856 bool deleted_output = false;
857 nir_foreach_variable_safe(var, &stage->nir->outputs) {
858 if (var->data.location < FRAG_RESULT_DATA0)
859 continue;
860
861 const unsigned rt = var->data.location - FRAG_RESULT_DATA0;
862 if (rt >= MAX_RTS ||
863 !(stage->key.wm.color_outputs_valid & (1 << rt))) {
864 /* Unused or out-of-bounds, throw it away */
865 deleted_output = true;
866 var->data.mode = nir_var_function_temp;
867 exec_node_remove(&var->node);
868 exec_list_push_tail(&impl->locals, &var->node);
869 continue;
870 }
871
872 /* Give it the new location */
873 assert(rt_to_bindings[rt] != -1);
874 var->data.location = rt_to_bindings[rt] + FRAG_RESULT_DATA0;
875 }
876
877 if (deleted_output)
878 nir_fixup_deref_modes(stage->nir);
879
880 if (num_rts == 0) {
881 /* If we have no render targets, we need a null render target */
882 rt_bindings[0] = (struct anv_pipeline_binding) {
883 .set = ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS,
884 .binding = 0,
885 .index = UINT32_MAX,
886 };
887 num_rts = 1;
888 }
889
890 /* Now that we've determined the actual number of render targets, adjust
891 * the key accordingly.
892 */
893 stage->key.wm.nr_color_regions = num_rts;
894 stage->key.wm.color_outputs_valid = (1 << num_rts) - 1;
895
896 assert(num_rts <= max_rt);
897 assert(stage->bind_map.surface_count == 0);
898 typed_memcpy(stage->bind_map.surface_to_descriptor,
899 rt_bindings, num_rts);
900 stage->bind_map.surface_count += num_rts;
901 }
902
903 static const unsigned *
904 anv_pipeline_compile_fs(const struct brw_compiler *compiler,
905 void *mem_ctx,
906 struct anv_device *device,
907 struct anv_pipeline_stage *fs_stage,
908 struct anv_pipeline_stage *prev_stage)
909 {
910 /* TODO: we could set this to 0 based on the information in nir_shader, but
911 * we need this before we call spirv_to_nir.
912 */
913 assert(prev_stage);
914 fs_stage->key.wm.input_slots_valid =
915 prev_stage->prog_data.vue.vue_map.slots_valid;
916
917 const unsigned *code =
918 brw_compile_fs(compiler, device, mem_ctx, &fs_stage->key.wm,
919 &fs_stage->prog_data.wm, fs_stage->nir,
920 NULL, -1, -1, -1, true, false, NULL, NULL);
921
922 if (fs_stage->key.wm.nr_color_regions == 0 &&
923 !fs_stage->prog_data.wm.has_side_effects &&
924 !fs_stage->prog_data.wm.uses_kill &&
925 fs_stage->prog_data.wm.computed_depth_mode == BRW_PSCDEPTH_OFF &&
926 !fs_stage->prog_data.wm.computed_stencil) {
927 /* This fragment shader has no outputs and no side effects. Go ahead
928 * and return the code pointer so we don't accidentally think the
929 * compile failed but zero out prog_data which will set program_size to
930 * zero and disable the stage.
931 */
932 memset(&fs_stage->prog_data, 0, sizeof(fs_stage->prog_data));
933 }
934
935 return code;
936 }
937
938 static VkResult
939 anv_pipeline_compile_graphics(struct anv_pipeline *pipeline,
940 struct anv_pipeline_cache *cache,
941 const VkGraphicsPipelineCreateInfo *info)
942 {
943 VkPipelineCreationFeedbackEXT pipeline_feedback = {
944 .flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT,
945 };
946 int64_t pipeline_start = os_time_get_nano();
947
948 const struct brw_compiler *compiler =
949 pipeline->device->instance->physicalDevice.compiler;
950 struct anv_pipeline_stage stages[MESA_SHADER_STAGES] = {};
951
952 pipeline->active_stages = 0;
953
954 VkResult result;
955 for (uint32_t i = 0; i < info->stageCount; i++) {
956 const VkPipelineShaderStageCreateInfo *sinfo = &info->pStages[i];
957 gl_shader_stage stage = vk_to_mesa_shader_stage(sinfo->stage);
958
959 pipeline->active_stages |= sinfo->stage;
960
961 int64_t stage_start = os_time_get_nano();
962
963 stages[stage].stage = stage;
964 stages[stage].module = anv_shader_module_from_handle(sinfo->module);
965 stages[stage].entrypoint = sinfo->pName;
966 stages[stage].spec_info = sinfo->pSpecializationInfo;
967 anv_pipeline_hash_shader(stages[stage].module,
968 stages[stage].entrypoint,
969 stage,
970 stages[stage].spec_info,
971 stages[stage].shader_sha1);
972
973 const struct gen_device_info *devinfo = &pipeline->device->info;
974 switch (stage) {
975 case MESA_SHADER_VERTEX:
976 populate_vs_prog_key(devinfo, &stages[stage].key.vs);
977 break;
978 case MESA_SHADER_TESS_CTRL:
979 populate_tcs_prog_key(devinfo,
980 info->pTessellationState->patchControlPoints,
981 &stages[stage].key.tcs);
982 break;
983 case MESA_SHADER_TESS_EVAL:
984 populate_tes_prog_key(devinfo, &stages[stage].key.tes);
985 break;
986 case MESA_SHADER_GEOMETRY:
987 populate_gs_prog_key(devinfo, &stages[stage].key.gs);
988 break;
989 case MESA_SHADER_FRAGMENT:
990 populate_wm_prog_key(devinfo, pipeline->subpass,
991 info->pMultisampleState,
992 &stages[stage].key.wm);
993 break;
994 default:
995 unreachable("Invalid graphics shader stage");
996 }
997
998 stages[stage].feedback.duration += os_time_get_nano() - stage_start;
999 stages[stage].feedback.flags |= VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT;
1000 }
1001
1002 if (pipeline->active_stages & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)
1003 pipeline->active_stages |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
1004
1005 assert(pipeline->active_stages & VK_SHADER_STAGE_VERTEX_BIT);
1006
1007 ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
1008
1009 unsigned char sha1[20];
1010 anv_pipeline_hash_graphics(pipeline, layout, stages, sha1);
1011
1012 unsigned found = 0;
1013 unsigned cache_hits = 0;
1014 for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
1015 if (!stages[s].entrypoint)
1016 continue;
1017
1018 int64_t stage_start = os_time_get_nano();
1019
1020 stages[s].cache_key.stage = s;
1021 memcpy(stages[s].cache_key.sha1, sha1, sizeof(sha1));
1022
1023 bool cache_hit;
1024 struct anv_shader_bin *bin =
1025 anv_device_search_for_kernel(pipeline->device, cache,
1026 &stages[s].cache_key,
1027 sizeof(stages[s].cache_key), &cache_hit);
1028 if (bin) {
1029 found++;
1030 pipeline->shaders[s] = bin;
1031 }
1032
1033 if (cache_hit) {
1034 cache_hits++;
1035 stages[s].feedback.flags |=
1036 VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
1037 }
1038 stages[s].feedback.duration += os_time_get_nano() - stage_start;
1039 }
1040
1041 if (found == __builtin_popcount(pipeline->active_stages)) {
1042 if (cache_hits == found) {
1043 pipeline_feedback.flags |=
1044 VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
1045 }
1046 /* We found all our shaders in the cache. We're done. */
1047 goto done;
1048 } else if (found > 0) {
1049 /* We found some but not all of our shaders. This shouldn't happen
1050 * most of the time but it can if we have a partially populated
1051 * pipeline cache.
1052 */
1053 assert(found < __builtin_popcount(pipeline->active_stages));
1054
1055 vk_debug_report(&pipeline->device->instance->debug_report_callbacks,
1056 VK_DEBUG_REPORT_WARNING_BIT_EXT |
1057 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
1058 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT,
1059 (uint64_t)(uintptr_t)cache,
1060 0, 0, "anv",
1061 "Found a partial pipeline in the cache. This is "
1062 "most likely caused by an incomplete pipeline cache "
1063 "import or export");
1064
1065 /* We're going to have to recompile anyway, so just throw away our
1066 * references to the shaders in the cache. We'll get them out of the
1067 * cache again as part of the compilation process.
1068 */
1069 for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
1070 stages[s].feedback.flags = 0;
1071 if (pipeline->shaders[s]) {
1072 anv_shader_bin_unref(pipeline->device, pipeline->shaders[s]);
1073 pipeline->shaders[s] = NULL;
1074 }
1075 }
1076 }
1077
1078 void *pipeline_ctx = ralloc_context(NULL);
1079
1080 for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
1081 if (!stages[s].entrypoint)
1082 continue;
1083
1084 int64_t stage_start = os_time_get_nano();
1085
1086 assert(stages[s].stage == s);
1087 assert(pipeline->shaders[s] == NULL);
1088
1089 stages[s].bind_map = (struct anv_pipeline_bind_map) {
1090 .surface_to_descriptor = stages[s].surface_to_descriptor,
1091 .sampler_to_descriptor = stages[s].sampler_to_descriptor
1092 };
1093
1094 stages[s].nir = anv_pipeline_stage_get_nir(pipeline, cache,
1095 pipeline_ctx,
1096 &stages[s]);
1097 if (stages[s].nir == NULL) {
1098 result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1099 goto fail;
1100 }
1101
1102 stages[s].feedback.duration += os_time_get_nano() - stage_start;
1103 }
1104
1105 /* Walk backwards to link */
1106 struct anv_pipeline_stage *next_stage = NULL;
1107 for (int s = MESA_SHADER_STAGES - 1; s >= 0; s--) {
1108 if (!stages[s].entrypoint)
1109 continue;
1110
1111 switch (s) {
1112 case MESA_SHADER_VERTEX:
1113 anv_pipeline_link_vs(compiler, &stages[s], next_stage);
1114 break;
1115 case MESA_SHADER_TESS_CTRL:
1116 anv_pipeline_link_tcs(compiler, &stages[s], next_stage);
1117 break;
1118 case MESA_SHADER_TESS_EVAL:
1119 anv_pipeline_link_tes(compiler, &stages[s], next_stage);
1120 break;
1121 case MESA_SHADER_GEOMETRY:
1122 anv_pipeline_link_gs(compiler, &stages[s], next_stage);
1123 break;
1124 case MESA_SHADER_FRAGMENT:
1125 anv_pipeline_link_fs(compiler, &stages[s]);
1126 break;
1127 default:
1128 unreachable("Invalid graphics shader stage");
1129 }
1130
1131 next_stage = &stages[s];
1132 }
1133
1134 struct anv_pipeline_stage *prev_stage = NULL;
1135 for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
1136 if (!stages[s].entrypoint)
1137 continue;
1138
1139 int64_t stage_start = os_time_get_nano();
1140
1141 void *stage_ctx = ralloc_context(NULL);
1142
1143 nir_xfb_info *xfb_info = NULL;
1144 if (s == MESA_SHADER_VERTEX ||
1145 s == MESA_SHADER_TESS_EVAL ||
1146 s == MESA_SHADER_GEOMETRY)
1147 xfb_info = nir_gather_xfb_info(stages[s].nir, stage_ctx);
1148
1149 anv_pipeline_lower_nir(pipeline, stage_ctx, &stages[s], layout);
1150
1151 const unsigned *code;
1152 switch (s) {
1153 case MESA_SHADER_VERTEX:
1154 code = anv_pipeline_compile_vs(compiler, stage_ctx, pipeline->device,
1155 &stages[s]);
1156 break;
1157 case MESA_SHADER_TESS_CTRL:
1158 code = anv_pipeline_compile_tcs(compiler, stage_ctx, pipeline->device,
1159 &stages[s], prev_stage);
1160 break;
1161 case MESA_SHADER_TESS_EVAL:
1162 code = anv_pipeline_compile_tes(compiler, stage_ctx, pipeline->device,
1163 &stages[s], prev_stage);
1164 break;
1165 case MESA_SHADER_GEOMETRY:
1166 code = anv_pipeline_compile_gs(compiler, stage_ctx, pipeline->device,
1167 &stages[s], prev_stage);
1168 break;
1169 case MESA_SHADER_FRAGMENT:
1170 code = anv_pipeline_compile_fs(compiler, stage_ctx, pipeline->device,
1171 &stages[s], prev_stage);
1172 break;
1173 default:
1174 unreachable("Invalid graphics shader stage");
1175 }
1176 if (code == NULL) {
1177 ralloc_free(stage_ctx);
1178 result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1179 goto fail;
1180 }
1181
1182 struct anv_shader_bin *bin =
1183 anv_device_upload_kernel(pipeline->device, cache,
1184 &stages[s].cache_key,
1185 sizeof(stages[s].cache_key),
1186 code, stages[s].prog_data.base.program_size,
1187 stages[s].nir->constant_data,
1188 stages[s].nir->constant_data_size,
1189 &stages[s].prog_data.base,
1190 brw_prog_data_size(s),
1191 xfb_info, &stages[s].bind_map);
1192 if (!bin) {
1193 ralloc_free(stage_ctx);
1194 result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1195 goto fail;
1196 }
1197
1198 pipeline->shaders[s] = bin;
1199 ralloc_free(stage_ctx);
1200
1201 stages[s].feedback.duration += os_time_get_nano() - stage_start;
1202
1203 prev_stage = &stages[s];
1204 }
1205
1206 ralloc_free(pipeline_ctx);
1207
1208 done:
1209
1210 if (pipeline->shaders[MESA_SHADER_FRAGMENT] &&
1211 pipeline->shaders[MESA_SHADER_FRAGMENT]->prog_data->program_size == 0) {
1212 /* This can happen if we decided to implicitly disable the fragment
1213 * shader. See anv_pipeline_compile_fs().
1214 */
1215 anv_shader_bin_unref(pipeline->device,
1216 pipeline->shaders[MESA_SHADER_FRAGMENT]);
1217 pipeline->shaders[MESA_SHADER_FRAGMENT] = NULL;
1218 pipeline->active_stages &= ~VK_SHADER_STAGE_FRAGMENT_BIT;
1219 }
1220
1221 pipeline_feedback.duration = os_time_get_nano() - pipeline_start;
1222
1223 const VkPipelineCreationFeedbackCreateInfoEXT *create_feedback =
1224 vk_find_struct_const(info->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO_EXT);
1225 if (create_feedback) {
1226 *create_feedback->pPipelineCreationFeedback = pipeline_feedback;
1227
1228 assert(info->stageCount == create_feedback->pipelineStageCreationFeedbackCount);
1229 for (uint32_t i = 0; i < info->stageCount; i++) {
1230 gl_shader_stage s = vk_to_mesa_shader_stage(info->pStages[i].stage);
1231 create_feedback->pPipelineStageCreationFeedbacks[i] = stages[s].feedback;
1232 }
1233 }
1234
1235 return VK_SUCCESS;
1236
1237 fail:
1238 ralloc_free(pipeline_ctx);
1239
1240 for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
1241 if (pipeline->shaders[s])
1242 anv_shader_bin_unref(pipeline->device, pipeline->shaders[s]);
1243 }
1244
1245 return result;
1246 }
1247
1248 VkResult
1249 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
1250 struct anv_pipeline_cache *cache,
1251 const VkComputePipelineCreateInfo *info,
1252 const struct anv_shader_module *module,
1253 const char *entrypoint,
1254 const VkSpecializationInfo *spec_info)
1255 {
1256 VkPipelineCreationFeedbackEXT pipeline_feedback = {
1257 .flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT,
1258 };
1259 int64_t pipeline_start = os_time_get_nano();
1260
1261 const struct brw_compiler *compiler =
1262 pipeline->device->instance->physicalDevice.compiler;
1263
1264 struct anv_pipeline_stage stage = {
1265 .stage = MESA_SHADER_COMPUTE,
1266 .module = module,
1267 .entrypoint = entrypoint,
1268 .spec_info = spec_info,
1269 .cache_key = {
1270 .stage = MESA_SHADER_COMPUTE,
1271 },
1272 .feedback = {
1273 .flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT,
1274 },
1275 };
1276 anv_pipeline_hash_shader(stage.module,
1277 stage.entrypoint,
1278 MESA_SHADER_COMPUTE,
1279 stage.spec_info,
1280 stage.shader_sha1);
1281
1282 struct anv_shader_bin *bin = NULL;
1283
1284 populate_cs_prog_key(&pipeline->device->info, &stage.key.cs);
1285
1286 ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
1287
1288 anv_pipeline_hash_compute(pipeline, layout, &stage, stage.cache_key.sha1);
1289 bool cache_hit;
1290 bin = anv_device_search_for_kernel(pipeline->device, cache, &stage.cache_key,
1291 sizeof(stage.cache_key), &cache_hit);
1292
1293 if (bin == NULL) {
1294 int64_t stage_start = os_time_get_nano();
1295
1296 stage.bind_map = (struct anv_pipeline_bind_map) {
1297 .surface_to_descriptor = stage.surface_to_descriptor,
1298 .sampler_to_descriptor = stage.sampler_to_descriptor
1299 };
1300
1301 /* Set up a binding for the gl_NumWorkGroups */
1302 stage.bind_map.surface_count = 1;
1303 stage.bind_map.surface_to_descriptor[0] = (struct anv_pipeline_binding) {
1304 .set = ANV_DESCRIPTOR_SET_NUM_WORK_GROUPS,
1305 };
1306
1307 void *mem_ctx = ralloc_context(NULL);
1308
1309 stage.nir = anv_pipeline_stage_get_nir(pipeline, cache, mem_ctx, &stage);
1310 if (stage.nir == NULL) {
1311 ralloc_free(mem_ctx);
1312 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1313 }
1314
1315 anv_pipeline_lower_nir(pipeline, mem_ctx, &stage, layout);
1316
1317 NIR_PASS_V(stage.nir, anv_nir_add_base_work_group_id,
1318 &stage.prog_data.cs);
1319
1320 const unsigned *shader_code =
1321 brw_compile_cs(compiler, pipeline->device, mem_ctx, &stage.key.cs,
1322 &stage.prog_data.cs, stage.nir, -1, NULL);
1323 if (shader_code == NULL) {
1324 ralloc_free(mem_ctx);
1325 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1326 }
1327
1328 const unsigned code_size = stage.prog_data.base.program_size;
1329 bin = anv_device_upload_kernel(pipeline->device, cache,
1330 &stage.cache_key, sizeof(stage.cache_key),
1331 shader_code, code_size,
1332 stage.nir->constant_data,
1333 stage.nir->constant_data_size,
1334 &stage.prog_data.base,
1335 sizeof(stage.prog_data.cs),
1336 NULL, &stage.bind_map);
1337 if (!bin) {
1338 ralloc_free(mem_ctx);
1339 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
1340 }
1341
1342 ralloc_free(mem_ctx);
1343
1344 stage.feedback.duration = os_time_get_nano() - stage_start;
1345 }
1346
1347 if (cache_hit) {
1348 stage.feedback.flags |=
1349 VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
1350 pipeline_feedback.flags |=
1351 VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
1352 }
1353 pipeline_feedback.duration = os_time_get_nano() - pipeline_start;
1354
1355 const VkPipelineCreationFeedbackCreateInfoEXT *create_feedback =
1356 vk_find_struct_const(info->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO_EXT);
1357 if (create_feedback) {
1358 *create_feedback->pPipelineCreationFeedback = pipeline_feedback;
1359
1360 assert(create_feedback->pipelineStageCreationFeedbackCount == 1);
1361 create_feedback->pPipelineStageCreationFeedbacks[0] = stage.feedback;
1362 }
1363
1364 pipeline->active_stages = VK_SHADER_STAGE_COMPUTE_BIT;
1365 pipeline->shaders[MESA_SHADER_COMPUTE] = bin;
1366
1367 return VK_SUCCESS;
1368 }
1369
1370 /**
1371 * Copy pipeline state not marked as dynamic.
1372 * Dynamic state is pipeline state which hasn't been provided at pipeline
1373 * creation time, but is dynamically provided afterwards using various
1374 * vkCmdSet* functions.
1375 *
1376 * The set of state considered "non_dynamic" is determined by the pieces of
1377 * state that have their corresponding VkDynamicState enums omitted from
1378 * VkPipelineDynamicStateCreateInfo::pDynamicStates.
1379 *
1380 * @param[out] pipeline Destination non_dynamic state.
1381 * @param[in] pCreateInfo Source of non_dynamic state to be copied.
1382 */
1383 static void
1384 copy_non_dynamic_state(struct anv_pipeline *pipeline,
1385 const VkGraphicsPipelineCreateInfo *pCreateInfo)
1386 {
1387 anv_cmd_dirty_mask_t states = ANV_CMD_DIRTY_DYNAMIC_ALL;
1388 struct anv_subpass *subpass = pipeline->subpass;
1389
1390 pipeline->dynamic_state = default_dynamic_state;
1391
1392 if (pCreateInfo->pDynamicState) {
1393 /* Remove all of the states that are marked as dynamic */
1394 uint32_t count = pCreateInfo->pDynamicState->dynamicStateCount;
1395 for (uint32_t s = 0; s < count; s++)
1396 states &= ~(1 << pCreateInfo->pDynamicState->pDynamicStates[s]);
1397 }
1398
1399 struct anv_dynamic_state *dynamic = &pipeline->dynamic_state;
1400
1401 /* Section 9.2 of the Vulkan 1.0.15 spec says:
1402 *
1403 * pViewportState is [...] NULL if the pipeline
1404 * has rasterization disabled.
1405 */
1406 if (!pCreateInfo->pRasterizationState->rasterizerDiscardEnable) {
1407 assert(pCreateInfo->pViewportState);
1408
1409 dynamic->viewport.count = pCreateInfo->pViewportState->viewportCount;
1410 if (states & (1 << VK_DYNAMIC_STATE_VIEWPORT)) {
1411 typed_memcpy(dynamic->viewport.viewports,
1412 pCreateInfo->pViewportState->pViewports,
1413 pCreateInfo->pViewportState->viewportCount);
1414 }
1415
1416 dynamic->scissor.count = pCreateInfo->pViewportState->scissorCount;
1417 if (states & (1 << VK_DYNAMIC_STATE_SCISSOR)) {
1418 typed_memcpy(dynamic->scissor.scissors,
1419 pCreateInfo->pViewportState->pScissors,
1420 pCreateInfo->pViewportState->scissorCount);
1421 }
1422 }
1423
1424 if (states & (1 << VK_DYNAMIC_STATE_LINE_WIDTH)) {
1425 assert(pCreateInfo->pRasterizationState);
1426 dynamic->line_width = pCreateInfo->pRasterizationState->lineWidth;
1427 }
1428
1429 if (states & (1 << VK_DYNAMIC_STATE_DEPTH_BIAS)) {
1430 assert(pCreateInfo->pRasterizationState);
1431 dynamic->depth_bias.bias =
1432 pCreateInfo->pRasterizationState->depthBiasConstantFactor;
1433 dynamic->depth_bias.clamp =
1434 pCreateInfo->pRasterizationState->depthBiasClamp;
1435 dynamic->depth_bias.slope =
1436 pCreateInfo->pRasterizationState->depthBiasSlopeFactor;
1437 }
1438
1439 /* Section 9.2 of the Vulkan 1.0.15 spec says:
1440 *
1441 * pColorBlendState is [...] NULL if the pipeline has rasterization
1442 * disabled or if the subpass of the render pass the pipeline is
1443 * created against does not use any color attachments.
1444 */
1445 bool uses_color_att = false;
1446 for (unsigned i = 0; i < subpass->color_count; ++i) {
1447 if (subpass->color_attachments[i].attachment != VK_ATTACHMENT_UNUSED) {
1448 uses_color_att = true;
1449 break;
1450 }
1451 }
1452
1453 if (uses_color_att &&
1454 !pCreateInfo->pRasterizationState->rasterizerDiscardEnable) {
1455 assert(pCreateInfo->pColorBlendState);
1456
1457 if (states & (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS))
1458 typed_memcpy(dynamic->blend_constants,
1459 pCreateInfo->pColorBlendState->blendConstants, 4);
1460 }
1461
1462 /* If there is no depthstencil attachment, then don't read
1463 * pDepthStencilState. The Vulkan spec states that pDepthStencilState may
1464 * be NULL in this case. Even if pDepthStencilState is non-NULL, there is
1465 * no need to override the depthstencil defaults in
1466 * anv_pipeline::dynamic_state when there is no depthstencil attachment.
1467 *
1468 * Section 9.2 of the Vulkan 1.0.15 spec says:
1469 *
1470 * pDepthStencilState is [...] NULL if the pipeline has rasterization
1471 * disabled or if the subpass of the render pass the pipeline is created
1472 * against does not use a depth/stencil attachment.
1473 */
1474 if (!pCreateInfo->pRasterizationState->rasterizerDiscardEnable &&
1475 subpass->depth_stencil_attachment) {
1476 assert(pCreateInfo->pDepthStencilState);
1477
1478 if (states & (1 << VK_DYNAMIC_STATE_DEPTH_BOUNDS)) {
1479 dynamic->depth_bounds.min =
1480 pCreateInfo->pDepthStencilState->minDepthBounds;
1481 dynamic->depth_bounds.max =
1482 pCreateInfo->pDepthStencilState->maxDepthBounds;
1483 }
1484
1485 if (states & (1 << VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK)) {
1486 dynamic->stencil_compare_mask.front =
1487 pCreateInfo->pDepthStencilState->front.compareMask;
1488 dynamic->stencil_compare_mask.back =
1489 pCreateInfo->pDepthStencilState->back.compareMask;
1490 }
1491
1492 if (states & (1 << VK_DYNAMIC_STATE_STENCIL_WRITE_MASK)) {
1493 dynamic->stencil_write_mask.front =
1494 pCreateInfo->pDepthStencilState->front.writeMask;
1495 dynamic->stencil_write_mask.back =
1496 pCreateInfo->pDepthStencilState->back.writeMask;
1497 }
1498
1499 if (states & (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE)) {
1500 dynamic->stencil_reference.front =
1501 pCreateInfo->pDepthStencilState->front.reference;
1502 dynamic->stencil_reference.back =
1503 pCreateInfo->pDepthStencilState->back.reference;
1504 }
1505 }
1506
1507 pipeline->dynamic_state_mask = states;
1508 }
1509
1510 static void
1511 anv_pipeline_validate_create_info(const VkGraphicsPipelineCreateInfo *info)
1512 {
1513 #ifdef DEBUG
1514 struct anv_render_pass *renderpass = NULL;
1515 struct anv_subpass *subpass = NULL;
1516
1517 /* Assert that all required members of VkGraphicsPipelineCreateInfo are
1518 * present. See the Vulkan 1.0.28 spec, Section 9.2 Graphics Pipelines.
1519 */
1520 assert(info->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
1521
1522 renderpass = anv_render_pass_from_handle(info->renderPass);
1523 assert(renderpass);
1524
1525 assert(info->subpass < renderpass->subpass_count);
1526 subpass = &renderpass->subpasses[info->subpass];
1527
1528 assert(info->stageCount >= 1);
1529 assert(info->pVertexInputState);
1530 assert(info->pInputAssemblyState);
1531 assert(info->pRasterizationState);
1532 if (!info->pRasterizationState->rasterizerDiscardEnable) {
1533 assert(info->pViewportState);
1534 assert(info->pMultisampleState);
1535
1536 if (subpass && subpass->depth_stencil_attachment)
1537 assert(info->pDepthStencilState);
1538
1539 if (subpass && subpass->color_count > 0) {
1540 bool all_color_unused = true;
1541 for (int i = 0; i < subpass->color_count; i++) {
1542 if (subpass->color_attachments[i].attachment != VK_ATTACHMENT_UNUSED)
1543 all_color_unused = false;
1544 }
1545 /* pColorBlendState is ignored if the pipeline has rasterization
1546 * disabled or if the subpass of the render pass the pipeline is
1547 * created against does not use any color attachments.
1548 */
1549 assert(info->pColorBlendState || all_color_unused);
1550 }
1551 }
1552
1553 for (uint32_t i = 0; i < info->stageCount; ++i) {
1554 switch (info->pStages[i].stage) {
1555 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
1556 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
1557 assert(info->pTessellationState);
1558 break;
1559 default:
1560 break;
1561 }
1562 }
1563 #endif
1564 }
1565
1566 /**
1567 * Calculate the desired L3 partitioning based on the current state of the
1568 * pipeline. For now this simply returns the conservative defaults calculated
1569 * by get_default_l3_weights(), but we could probably do better by gathering
1570 * more statistics from the pipeline state (e.g. guess of expected URB usage
1571 * and bound surfaces), or by using feed-back from performance counters.
1572 */
1573 void
1574 anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm)
1575 {
1576 const struct gen_device_info *devinfo = &pipeline->device->info;
1577
1578 const struct gen_l3_weights w =
1579 gen_get_default_l3_weights(devinfo, pipeline->needs_data_cache, needs_slm);
1580
1581 pipeline->urb.l3_config = gen_get_l3_config(devinfo, w);
1582 pipeline->urb.total_size =
1583 gen_get_l3_config_urb_size(devinfo, pipeline->urb.l3_config);
1584 }
1585
1586 VkResult
1587 anv_pipeline_init(struct anv_pipeline *pipeline,
1588 struct anv_device *device,
1589 struct anv_pipeline_cache *cache,
1590 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1591 const VkAllocationCallbacks *alloc)
1592 {
1593 VkResult result;
1594
1595 anv_pipeline_validate_create_info(pCreateInfo);
1596
1597 if (alloc == NULL)
1598 alloc = &device->alloc;
1599
1600 pipeline->device = device;
1601
1602 ANV_FROM_HANDLE(anv_render_pass, render_pass, pCreateInfo->renderPass);
1603 assert(pCreateInfo->subpass < render_pass->subpass_count);
1604 pipeline->subpass = &render_pass->subpasses[pCreateInfo->subpass];
1605
1606 result = anv_reloc_list_init(&pipeline->batch_relocs, alloc);
1607 if (result != VK_SUCCESS)
1608 return result;
1609
1610 pipeline->batch.alloc = alloc;
1611 pipeline->batch.next = pipeline->batch.start = pipeline->batch_data;
1612 pipeline->batch.end = pipeline->batch.start + sizeof(pipeline->batch_data);
1613 pipeline->batch.relocs = &pipeline->batch_relocs;
1614 pipeline->batch.status = VK_SUCCESS;
1615
1616 copy_non_dynamic_state(pipeline, pCreateInfo);
1617 pipeline->depth_clamp_enable = pCreateInfo->pRasterizationState &&
1618 pCreateInfo->pRasterizationState->depthClampEnable;
1619
1620 /* Previously we enabled depth clipping when !depthClampEnable.
1621 * DepthClipStateCreateInfo now makes depth clipping explicit so if the
1622 * clipping info is available, use its enable value to determine clipping,
1623 * otherwise fallback to the previous !depthClampEnable logic.
1624 */
1625 const VkPipelineRasterizationDepthClipStateCreateInfoEXT *clip_info =
1626 vk_find_struct_const(pCreateInfo->pRasterizationState->pNext,
1627 PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT);
1628 pipeline->depth_clip_enable = clip_info ? clip_info->depthClipEnable : !pipeline->depth_clamp_enable;
1629
1630 pipeline->sample_shading_enable = pCreateInfo->pMultisampleState &&
1631 pCreateInfo->pMultisampleState->sampleShadingEnable;
1632
1633 pipeline->needs_data_cache = false;
1634
1635 /* When we free the pipeline, we detect stages based on the NULL status
1636 * of various prog_data pointers. Make them NULL by default.
1637 */
1638 memset(pipeline->shaders, 0, sizeof(pipeline->shaders));
1639
1640 result = anv_pipeline_compile_graphics(pipeline, cache, pCreateInfo);
1641 if (result != VK_SUCCESS) {
1642 anv_reloc_list_finish(&pipeline->batch_relocs, alloc);
1643 return result;
1644 }
1645
1646 assert(pipeline->shaders[MESA_SHADER_VERTEX]);
1647
1648 anv_pipeline_setup_l3_config(pipeline, false);
1649
1650 const VkPipelineVertexInputStateCreateInfo *vi_info =
1651 pCreateInfo->pVertexInputState;
1652
1653 const uint64_t inputs_read = get_vs_prog_data(pipeline)->inputs_read;
1654
1655 pipeline->vb_used = 0;
1656 for (uint32_t i = 0; i < vi_info->vertexAttributeDescriptionCount; i++) {
1657 const VkVertexInputAttributeDescription *desc =
1658 &vi_info->pVertexAttributeDescriptions[i];
1659
1660 if (inputs_read & (1ull << (VERT_ATTRIB_GENERIC0 + desc->location)))
1661 pipeline->vb_used |= 1 << desc->binding;
1662 }
1663
1664 for (uint32_t i = 0; i < vi_info->vertexBindingDescriptionCount; i++) {
1665 const VkVertexInputBindingDescription *desc =
1666 &vi_info->pVertexBindingDescriptions[i];
1667
1668 pipeline->vb[desc->binding].stride = desc->stride;
1669
1670 /* Step rate is programmed per vertex element (attribute), not
1671 * binding. Set up a map of which bindings step per instance, for
1672 * reference by vertex element setup. */
1673 switch (desc->inputRate) {
1674 default:
1675 case VK_VERTEX_INPUT_RATE_VERTEX:
1676 pipeline->vb[desc->binding].instanced = false;
1677 break;
1678 case VK_VERTEX_INPUT_RATE_INSTANCE:
1679 pipeline->vb[desc->binding].instanced = true;
1680 break;
1681 }
1682
1683 pipeline->vb[desc->binding].instance_divisor = 1;
1684 }
1685
1686 const VkPipelineVertexInputDivisorStateCreateInfoEXT *vi_div_state =
1687 vk_find_struct_const(vi_info->pNext,
1688 PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT);
1689 if (vi_div_state) {
1690 for (uint32_t i = 0; i < vi_div_state->vertexBindingDivisorCount; i++) {
1691 const VkVertexInputBindingDivisorDescriptionEXT *desc =
1692 &vi_div_state->pVertexBindingDivisors[i];
1693
1694 pipeline->vb[desc->binding].instance_divisor = desc->divisor;
1695 }
1696 }
1697
1698 /* Our implementation of VK_KHR_multiview uses instancing to draw the
1699 * different views. If the client asks for instancing, we need to multiply
1700 * the instance divisor by the number of views ensure that we repeat the
1701 * client's per-instance data once for each view.
1702 */
1703 if (pipeline->subpass->view_mask) {
1704 const uint32_t view_count = anv_subpass_view_count(pipeline->subpass);
1705 for (uint32_t vb = 0; vb < MAX_VBS; vb++) {
1706 if (pipeline->vb[vb].instanced)
1707 pipeline->vb[vb].instance_divisor *= view_count;
1708 }
1709 }
1710
1711 const VkPipelineInputAssemblyStateCreateInfo *ia_info =
1712 pCreateInfo->pInputAssemblyState;
1713 const VkPipelineTessellationStateCreateInfo *tess_info =
1714 pCreateInfo->pTessellationState;
1715 pipeline->primitive_restart = ia_info->primitiveRestartEnable;
1716
1717 if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
1718 pipeline->topology = _3DPRIM_PATCHLIST(tess_info->patchControlPoints);
1719 else
1720 pipeline->topology = vk_to_gen_primitive_type[ia_info->topology];
1721
1722 return VK_SUCCESS;
1723 }