2 * Copyright © 2015 Intel Corporation
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:
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
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
30 #include "util/mesa-sha1.h"
31 #include "common/gen_l3_config.h"
32 #include "anv_private.h"
35 #include "spirv/nir_spirv.h"
37 /* Needed for SWIZZLE macros */
38 #include "program/prog_instruction.h"
42 VkResult
anv_CreateShaderModule(
44 const VkShaderModuleCreateInfo
* pCreateInfo
,
45 const VkAllocationCallbacks
* pAllocator
,
46 VkShaderModule
* pShaderModule
)
48 ANV_FROM_HANDLE(anv_device
, device
, _device
);
49 struct anv_shader_module
*module
;
51 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO
);
52 assert(pCreateInfo
->flags
== 0);
54 module
= anv_alloc2(&device
->alloc
, pAllocator
,
55 sizeof(*module
) + pCreateInfo
->codeSize
, 8,
56 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
58 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
61 module
->size
= pCreateInfo
->codeSize
;
62 memcpy(module
->data
, pCreateInfo
->pCode
, module
->size
);
64 _mesa_sha1_compute(module
->data
, module
->size
, module
->sha1
);
66 *pShaderModule
= anv_shader_module_to_handle(module
);
71 void anv_DestroyShaderModule(
73 VkShaderModule _module
,
74 const VkAllocationCallbacks
* pAllocator
)
76 ANV_FROM_HANDLE(anv_device
, device
, _device
);
77 ANV_FROM_HANDLE(anv_shader_module
, module
, _module
);
79 anv_free2(&device
->alloc
, pAllocator
, module
);
82 #define SPIR_V_MAGIC_NUMBER 0x07230203
84 /* Eventually, this will become part of anv_CreateShader. Unfortunately,
85 * we can't do that yet because we don't have the ability to copy nir.
88 anv_shader_compile_to_nir(struct anv_device
*device
,
89 struct anv_shader_module
*module
,
90 const char *entrypoint_name
,
91 gl_shader_stage stage
,
92 const VkSpecializationInfo
*spec_info
)
94 if (strcmp(entrypoint_name
, "main") != 0) {
95 anv_finishme("Multiple shaders per module not really supported");
98 const struct brw_compiler
*compiler
=
99 device
->instance
->physicalDevice
.compiler
;
100 const nir_shader_compiler_options
*nir_options
=
101 compiler
->glsl_compiler_options
[stage
].NirOptions
;
104 nir_function
*entry_point
;
106 /* Some things such as our meta clear/blit code will give us a NIR
107 * shader directly. In that case, we just ignore the SPIR-V entirely
108 * and just use the NIR shader */
110 nir
->options
= nir_options
;
111 nir_validate_shader(nir
);
113 assert(exec_list_length(&nir
->functions
) == 1);
114 struct exec_node
*node
= exec_list_get_head(&nir
->functions
);
115 entry_point
= exec_node_data(nir_function
, node
, node
);
117 uint32_t *spirv
= (uint32_t *) module
->data
;
118 assert(spirv
[0] == SPIR_V_MAGIC_NUMBER
);
119 assert(module
->size
% 4 == 0);
121 uint32_t num_spec_entries
= 0;
122 struct nir_spirv_specialization
*spec_entries
= NULL
;
123 if (spec_info
&& spec_info
->mapEntryCount
> 0) {
124 num_spec_entries
= spec_info
->mapEntryCount
;
125 spec_entries
= malloc(num_spec_entries
* sizeof(*spec_entries
));
126 for (uint32_t i
= 0; i
< num_spec_entries
; i
++) {
127 VkSpecializationMapEntry entry
= spec_info
->pMapEntries
[i
];
128 const void *data
= spec_info
->pData
+ entry
.offset
;
129 assert(data
+ entry
.size
<= spec_info
->pData
+ spec_info
->dataSize
);
131 spec_entries
[i
].id
= spec_info
->pMapEntries
[i
].constantID
;
132 spec_entries
[i
].data
= *(const uint32_t *)data
;
136 entry_point
= spirv_to_nir(spirv
, module
->size
/ 4,
137 spec_entries
, num_spec_entries
,
138 stage
, entrypoint_name
, nir_options
);
139 nir
= entry_point
->shader
;
140 assert(nir
->stage
== stage
);
141 nir_validate_shader(nir
);
145 if (stage
== MESA_SHADER_FRAGMENT
) {
146 nir_lower_wpos_center(nir
);
147 nir_validate_shader(nir
);
150 nir_lower_returns(nir
);
151 nir_validate_shader(nir
);
153 nir_inline_functions(nir
);
154 nir_validate_shader(nir
);
156 /* Pick off the single entrypoint that we want */
157 foreach_list_typed_safe(nir_function
, func
, node
, &nir
->functions
) {
158 if (func
!= entry_point
)
159 exec_node_remove(&func
->node
);
161 assert(exec_list_length(&nir
->functions
) == 1);
162 entry_point
->name
= ralloc_strdup(entry_point
, "main");
164 nir_remove_dead_variables(nir
, nir_var_shader_in
);
165 nir_remove_dead_variables(nir
, nir_var_shader_out
);
166 nir_remove_dead_variables(nir
, nir_var_system_value
);
167 nir_validate_shader(nir
);
169 nir_propagate_invariant(nir
);
170 nir_validate_shader(nir
);
172 nir_lower_io_to_temporaries(entry_point
->shader
, entry_point
->impl
,
175 nir_lower_system_values(nir
);
176 nir_validate_shader(nir
);
179 /* Vulkan uses the separate-shader linking model */
180 nir
->info
.separate_shader
= true;
182 nir
= brw_preprocess_nir(compiler
, nir
);
184 nir_shader_gather_info(nir
, entry_point
->impl
);
186 nir_variable_mode indirect_mask
= 0;
187 if (compiler
->glsl_compiler_options
[stage
].EmitNoIndirectInput
)
188 indirect_mask
|= nir_var_shader_in
;
189 if (compiler
->glsl_compiler_options
[stage
].EmitNoIndirectOutput
)
190 indirect_mask
|= nir_var_shader_out
;
191 if (compiler
->glsl_compiler_options
[stage
].EmitNoIndirectTemp
)
192 indirect_mask
|= nir_var_local
;
194 nir_lower_indirect_derefs(nir
, indirect_mask
);
199 void anv_DestroyPipeline(
201 VkPipeline _pipeline
,
202 const VkAllocationCallbacks
* pAllocator
)
204 ANV_FROM_HANDLE(anv_device
, device
, _device
);
205 ANV_FROM_HANDLE(anv_pipeline
, pipeline
, _pipeline
);
207 anv_reloc_list_finish(&pipeline
->batch_relocs
,
208 pAllocator
? pAllocator
: &device
->alloc
);
209 if (pipeline
->blend_state
.map
)
210 anv_state_pool_free(&device
->dynamic_state_pool
, pipeline
->blend_state
);
212 for (unsigned s
= 0; s
< MESA_SHADER_STAGES
; s
++) {
213 if (pipeline
->shaders
[s
])
214 anv_shader_bin_unref(device
, pipeline
->shaders
[s
]);
217 anv_free2(&device
->alloc
, pAllocator
, pipeline
);
220 static const uint32_t vk_to_gen_primitive_type
[] = {
221 [VK_PRIMITIVE_TOPOLOGY_POINT_LIST
] = _3DPRIM_POINTLIST
,
222 [VK_PRIMITIVE_TOPOLOGY_LINE_LIST
] = _3DPRIM_LINELIST
,
223 [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP
] = _3DPRIM_LINESTRIP
,
224 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
] = _3DPRIM_TRILIST
,
225 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
] = _3DPRIM_TRISTRIP
,
226 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN
] = _3DPRIM_TRIFAN
,
227 [VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY
] = _3DPRIM_LINELIST_ADJ
,
228 [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY
] = _3DPRIM_LINESTRIP_ADJ
,
229 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY
] = _3DPRIM_TRILIST_ADJ
,
230 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY
] = _3DPRIM_TRISTRIP_ADJ
,
231 /* [VK_PRIMITIVE_TOPOLOGY_PATCH_LIST] = _3DPRIM_PATCHLIST_1 */
235 populate_sampler_prog_key(const struct gen_device_info
*devinfo
,
236 struct brw_sampler_prog_key_data
*key
)
238 /* XXX: Handle texture swizzle on HSW- */
239 for (int i
= 0; i
< MAX_SAMPLERS
; i
++) {
240 /* Assume color sampler, no swizzling. (Works for BDW+) */
241 key
->swizzles
[i
] = SWIZZLE_XYZW
;
246 populate_vs_prog_key(const struct gen_device_info
*devinfo
,
247 struct brw_vs_prog_key
*key
)
249 memset(key
, 0, sizeof(*key
));
251 populate_sampler_prog_key(devinfo
, &key
->tex
);
253 /* XXX: Handle vertex input work-arounds */
255 /* XXX: Handle sampler_prog_key */
259 populate_gs_prog_key(const struct gen_device_info
*devinfo
,
260 struct brw_gs_prog_key
*key
)
262 memset(key
, 0, sizeof(*key
));
264 populate_sampler_prog_key(devinfo
, &key
->tex
);
268 populate_wm_prog_key(const struct gen_device_info
*devinfo
,
269 const VkGraphicsPipelineCreateInfo
*info
,
270 const struct anv_graphics_pipeline_create_info
*extra
,
271 struct brw_wm_prog_key
*key
)
273 ANV_FROM_HANDLE(anv_render_pass
, render_pass
, info
->renderPass
);
275 memset(key
, 0, sizeof(*key
));
277 populate_sampler_prog_key(devinfo
, &key
->tex
);
279 /* TODO: Fill out key->input_slots_valid */
281 /* Vulkan doesn't specify a default */
282 key
->high_quality_derivatives
= false;
284 /* XXX Vulkan doesn't appear to specify */
285 key
->clamp_fragment_color
= false;
287 if (extra
&& extra
->color_attachment_count
>= 0) {
288 key
->nr_color_regions
= extra
->color_attachment_count
;
290 key
->nr_color_regions
=
291 render_pass
->subpasses
[info
->subpass
].color_count
;
294 key
->replicate_alpha
= key
->nr_color_regions
> 1 &&
295 info
->pMultisampleState
&&
296 info
->pMultisampleState
->alphaToCoverageEnable
;
298 if (info
->pMultisampleState
&& info
->pMultisampleState
->rasterizationSamples
> 1) {
299 /* We should probably pull this out of the shader, but it's fairly
300 * harmless to compute it and then let dead-code take care of it.
302 key
->persample_interp
=
303 (info
->pMultisampleState
->minSampleShading
*
304 info
->pMultisampleState
->rasterizationSamples
) > 1;
305 key
->multisample_fbo
= true;
310 populate_cs_prog_key(const struct gen_device_info
*devinfo
,
311 struct brw_cs_prog_key
*key
)
313 memset(key
, 0, sizeof(*key
));
315 populate_sampler_prog_key(devinfo
, &key
->tex
);
319 anv_pipeline_compile(struct anv_pipeline
*pipeline
,
320 struct anv_shader_module
*module
,
321 const char *entrypoint
,
322 gl_shader_stage stage
,
323 const VkSpecializationInfo
*spec_info
,
324 struct brw_stage_prog_data
*prog_data
,
325 struct anv_pipeline_bind_map
*map
)
327 nir_shader
*nir
= anv_shader_compile_to_nir(pipeline
->device
,
328 module
, entrypoint
, stage
,
333 anv_nir_lower_push_constants(nir
);
335 /* Figure out the number of parameters */
336 prog_data
->nr_params
= 0;
338 if (nir
->num_uniforms
> 0) {
339 /* If the shader uses any push constants at all, we'll just give
340 * them the maximum possible number
342 assert(nir
->num_uniforms
<= MAX_PUSH_CONSTANTS_SIZE
);
343 prog_data
->nr_params
+= MAX_PUSH_CONSTANTS_SIZE
/ sizeof(float);
346 if (pipeline
->layout
&& pipeline
->layout
->stage
[stage
].has_dynamic_offsets
)
347 prog_data
->nr_params
+= MAX_DYNAMIC_BUFFERS
* 2;
349 if (nir
->info
.num_images
> 0) {
350 prog_data
->nr_params
+= nir
->info
.num_images
* BRW_IMAGE_PARAM_SIZE
;
351 pipeline
->needs_data_cache
= true;
354 if (stage
== MESA_SHADER_COMPUTE
)
355 ((struct brw_cs_prog_data
*)prog_data
)->thread_local_id_index
=
356 prog_data
->nr_params
++; /* The CS Thread ID uniform */
358 if (nir
->info
.num_ssbos
> 0)
359 pipeline
->needs_data_cache
= true;
361 if (prog_data
->nr_params
> 0) {
362 /* XXX: I think we're leaking this */
363 prog_data
->param
= (const union gl_constant_value
**)
364 malloc(prog_data
->nr_params
* sizeof(union gl_constant_value
*));
366 /* We now set the param values to be offsets into a
367 * anv_push_constant_data structure. Since the compiler doesn't
368 * actually dereference any of the gl_constant_value pointers in the
369 * params array, it doesn't really matter what we put here.
371 struct anv_push_constants
*null_data
= NULL
;
372 if (nir
->num_uniforms
> 0) {
373 /* Fill out the push constants section of the param array */
374 for (unsigned i
= 0; i
< MAX_PUSH_CONSTANTS_SIZE
/ sizeof(float); i
++)
375 prog_data
->param
[i
] = (const union gl_constant_value
*)
376 &null_data
->client_data
[i
* sizeof(float)];
380 /* Set up dynamic offsets */
381 anv_nir_apply_dynamic_offsets(pipeline
, nir
, prog_data
);
383 /* Apply the actual pipeline layout to UBOs, SSBOs, and textures */
384 if (pipeline
->layout
)
385 anv_nir_apply_pipeline_layout(pipeline
, nir
, prog_data
, map
);
387 /* nir_lower_io will only handle the push constants; we need to set this
388 * to the full number of possible uniforms.
390 nir
->num_uniforms
= prog_data
->nr_params
* 4;
396 anv_fill_binding_table(struct brw_stage_prog_data
*prog_data
, unsigned bias
)
398 prog_data
->binding_table
.size_bytes
= 0;
399 prog_data
->binding_table
.texture_start
= bias
;
400 prog_data
->binding_table
.gather_texture_start
= bias
;
401 prog_data
->binding_table
.ubo_start
= bias
;
402 prog_data
->binding_table
.ssbo_start
= bias
;
403 prog_data
->binding_table
.image_start
= bias
;
406 static struct anv_shader_bin
*
407 anv_pipeline_upload_kernel(struct anv_pipeline
*pipeline
,
408 struct anv_pipeline_cache
*cache
,
409 const void *key_data
, uint32_t key_size
,
410 const void *kernel_data
, uint32_t kernel_size
,
411 const void *prog_data
, uint32_t prog_data_size
,
412 const struct anv_pipeline_bind_map
*bind_map
)
415 return anv_pipeline_cache_upload_kernel(cache
, key_data
, key_size
,
416 kernel_data
, kernel_size
,
417 prog_data
, prog_data_size
,
420 return anv_shader_bin_create(pipeline
->device
, key_data
, key_size
,
421 kernel_data
, kernel_size
,
422 prog_data
, prog_data_size
, bind_map
);
428 anv_pipeline_add_compiled_stage(struct anv_pipeline
*pipeline
,
429 gl_shader_stage stage
,
430 struct anv_shader_bin
*shader
)
432 pipeline
->shaders
[stage
] = shader
;
433 pipeline
->active_stages
|= mesa_to_vk_shader_stage(stage
);
437 anv_pipeline_compile_vs(struct anv_pipeline
*pipeline
,
438 struct anv_pipeline_cache
*cache
,
439 const VkGraphicsPipelineCreateInfo
*info
,
440 struct anv_shader_module
*module
,
441 const char *entrypoint
,
442 const VkSpecializationInfo
*spec_info
)
444 const struct brw_compiler
*compiler
=
445 pipeline
->device
->instance
->physicalDevice
.compiler
;
446 struct anv_pipeline_bind_map map
;
447 struct brw_vs_prog_key key
;
448 struct anv_shader_bin
*bin
= NULL
;
449 unsigned char sha1
[20];
451 populate_vs_prog_key(&pipeline
->device
->info
, &key
);
454 anv_hash_shader(sha1
, &key
, sizeof(key
), module
, entrypoint
,
455 pipeline
->layout
, spec_info
);
456 bin
= anv_pipeline_cache_search(cache
, sha1
, 20);
460 struct brw_vs_prog_data prog_data
= { 0, };
461 struct anv_pipeline_binding surface_to_descriptor
[256];
462 struct anv_pipeline_binding sampler_to_descriptor
[256];
464 map
= (struct anv_pipeline_bind_map
) {
465 .surface_to_descriptor
= surface_to_descriptor
,
466 .sampler_to_descriptor
= sampler_to_descriptor
469 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
470 MESA_SHADER_VERTEX
, spec_info
,
471 &prog_data
.base
.base
, &map
);
473 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
475 anv_fill_binding_table(&prog_data
.base
.base
, 0);
477 void *mem_ctx
= ralloc_context(NULL
);
479 if (module
->nir
== NULL
)
480 ralloc_steal(mem_ctx
, nir
);
482 prog_data
.inputs_read
= nir
->info
.inputs_read
;
484 brw_compute_vue_map(&pipeline
->device
->info
,
485 &prog_data
.base
.vue_map
,
486 nir
->info
.outputs_written
,
487 nir
->info
.separate_shader
);
490 const unsigned *shader_code
=
491 brw_compile_vs(compiler
, NULL
, mem_ctx
, &key
, &prog_data
, nir
,
492 NULL
, false, -1, &code_size
, NULL
);
493 if (shader_code
== NULL
) {
494 ralloc_free(mem_ctx
);
495 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
498 bin
= anv_pipeline_upload_kernel(pipeline
, cache
, sha1
, 20,
499 shader_code
, code_size
,
500 &prog_data
, sizeof(prog_data
), &map
);
502 ralloc_free(mem_ctx
);
503 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
506 ralloc_free(mem_ctx
);
509 const struct brw_vs_prog_data
*vs_prog_data
=
510 (const struct brw_vs_prog_data
*)anv_shader_bin_get_prog_data(bin
);
512 if (vs_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
) {
513 pipeline
->vs_simd8
= bin
->kernel
.offset
;
514 pipeline
->vs_vec4
= NO_KERNEL
;
516 pipeline
->vs_simd8
= NO_KERNEL
;
517 pipeline
->vs_vec4
= bin
->kernel
.offset
;
520 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_VERTEX
, bin
);
526 anv_pipeline_compile_gs(struct anv_pipeline
*pipeline
,
527 struct anv_pipeline_cache
*cache
,
528 const VkGraphicsPipelineCreateInfo
*info
,
529 struct anv_shader_module
*module
,
530 const char *entrypoint
,
531 const VkSpecializationInfo
*spec_info
)
533 const struct brw_compiler
*compiler
=
534 pipeline
->device
->instance
->physicalDevice
.compiler
;
535 struct anv_pipeline_bind_map map
;
536 struct brw_gs_prog_key key
;
537 struct anv_shader_bin
*bin
= NULL
;
538 unsigned char sha1
[20];
540 populate_gs_prog_key(&pipeline
->device
->info
, &key
);
543 anv_hash_shader(sha1
, &key
, sizeof(key
), module
, entrypoint
,
544 pipeline
->layout
, spec_info
);
545 bin
= anv_pipeline_cache_search(cache
, sha1
, 20);
549 struct brw_gs_prog_data prog_data
= { 0, };
550 struct anv_pipeline_binding surface_to_descriptor
[256];
551 struct anv_pipeline_binding sampler_to_descriptor
[256];
553 map
= (struct anv_pipeline_bind_map
) {
554 .surface_to_descriptor
= surface_to_descriptor
,
555 .sampler_to_descriptor
= sampler_to_descriptor
558 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
559 MESA_SHADER_GEOMETRY
, spec_info
,
560 &prog_data
.base
.base
, &map
);
562 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
564 anv_fill_binding_table(&prog_data
.base
.base
, 0);
566 void *mem_ctx
= ralloc_context(NULL
);
568 if (module
->nir
== NULL
)
569 ralloc_steal(mem_ctx
, nir
);
571 brw_compute_vue_map(&pipeline
->device
->info
,
572 &prog_data
.base
.vue_map
,
573 nir
->info
.outputs_written
,
574 nir
->info
.separate_shader
);
577 const unsigned *shader_code
=
578 brw_compile_gs(compiler
, NULL
, mem_ctx
, &key
, &prog_data
, nir
,
579 NULL
, -1, &code_size
, NULL
);
580 if (shader_code
== NULL
) {
581 ralloc_free(mem_ctx
);
582 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
586 bin
= anv_pipeline_upload_kernel(pipeline
, cache
, sha1
, 20,
587 shader_code
, code_size
,
588 &prog_data
, sizeof(prog_data
), &map
);
590 ralloc_free(mem_ctx
);
591 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
594 ralloc_free(mem_ctx
);
597 pipeline
->gs_kernel
= bin
->kernel
.offset
;
599 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_GEOMETRY
, bin
);
605 anv_pipeline_compile_fs(struct anv_pipeline
*pipeline
,
606 struct anv_pipeline_cache
*cache
,
607 const VkGraphicsPipelineCreateInfo
*info
,
608 const struct anv_graphics_pipeline_create_info
*extra
,
609 struct anv_shader_module
*module
,
610 const char *entrypoint
,
611 const VkSpecializationInfo
*spec_info
)
613 const struct brw_compiler
*compiler
=
614 pipeline
->device
->instance
->physicalDevice
.compiler
;
615 struct anv_pipeline_bind_map map
;
616 struct brw_wm_prog_key key
;
617 struct anv_shader_bin
*bin
= NULL
;
618 unsigned char sha1
[20];
620 populate_wm_prog_key(&pipeline
->device
->info
, info
, extra
, &key
);
623 anv_hash_shader(sha1
, &key
, sizeof(key
), module
, entrypoint
,
624 pipeline
->layout
, spec_info
);
625 bin
= anv_pipeline_cache_search(cache
, sha1
, 20);
629 struct brw_wm_prog_data prog_data
= { 0, };
630 struct anv_pipeline_binding surface_to_descriptor
[256];
631 struct anv_pipeline_binding sampler_to_descriptor
[256];
633 map
= (struct anv_pipeline_bind_map
) {
634 .surface_to_descriptor
= surface_to_descriptor
+ 8,
635 .sampler_to_descriptor
= sampler_to_descriptor
638 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
639 MESA_SHADER_FRAGMENT
, spec_info
,
640 &prog_data
.base
, &map
);
642 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
644 unsigned num_rts
= 0;
645 struct anv_pipeline_binding rt_bindings
[8];
646 nir_function_impl
*impl
= nir_shader_get_entrypoint(nir
);
647 nir_foreach_variable_safe(var
, &nir
->outputs
) {
648 if (var
->data
.location
< FRAG_RESULT_DATA0
)
651 unsigned rt
= var
->data
.location
- FRAG_RESULT_DATA0
;
652 if (rt
>= key
.nr_color_regions
) {
653 /* Out-of-bounds, throw it away */
654 var
->data
.mode
= nir_var_local
;
655 exec_node_remove(&var
->node
);
656 exec_list_push_tail(&impl
->locals
, &var
->node
);
660 /* Give it a new, compacted, location */
661 var
->data
.location
= FRAG_RESULT_DATA0
+ num_rts
;
664 glsl_type_is_array(var
->type
) ? glsl_get_length(var
->type
) : 1;
665 assert(num_rts
+ array_len
<= 8);
667 for (unsigned i
= 0; i
< array_len
; i
++) {
668 rt_bindings
[num_rts
+ i
] = (struct anv_pipeline_binding
) {
669 .set
= ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS
,
675 num_rts
+= array_len
;
678 if (pipeline
->use_repclear
) {
679 assert(num_rts
== 1);
680 key
.nr_color_regions
= 1;
684 /* If we have no render targets, we need a null render target */
685 rt_bindings
[0] = (struct anv_pipeline_binding
) {
686 .set
= ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS
,
693 assert(num_rts
<= 8);
694 map
.surface_to_descriptor
-= num_rts
;
695 map
.surface_count
+= num_rts
;
696 assert(map
.surface_count
<= 256);
697 memcpy(map
.surface_to_descriptor
, rt_bindings
,
698 num_rts
* sizeof(*rt_bindings
));
700 anv_fill_binding_table(&prog_data
.base
, num_rts
);
702 void *mem_ctx
= ralloc_context(NULL
);
704 if (module
->nir
== NULL
)
705 ralloc_steal(mem_ctx
, nir
);
708 const unsigned *shader_code
=
709 brw_compile_fs(compiler
, NULL
, mem_ctx
, &key
, &prog_data
, nir
,
710 NULL
, -1, -1, true, pipeline
->use_repclear
,
712 if (shader_code
== NULL
) {
713 ralloc_free(mem_ctx
);
714 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
717 bin
= anv_pipeline_upload_kernel(pipeline
, cache
, sha1
, 20,
718 shader_code
, code_size
,
719 &prog_data
, sizeof(prog_data
), &map
);
721 ralloc_free(mem_ctx
);
722 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
725 ralloc_free(mem_ctx
);
728 pipeline
->ps_ksp0
= bin
->kernel
.offset
;
730 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_FRAGMENT
, bin
);
736 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
737 struct anv_pipeline_cache
*cache
,
738 const VkComputePipelineCreateInfo
*info
,
739 struct anv_shader_module
*module
,
740 const char *entrypoint
,
741 const VkSpecializationInfo
*spec_info
)
743 const struct brw_compiler
*compiler
=
744 pipeline
->device
->instance
->physicalDevice
.compiler
;
745 struct anv_pipeline_bind_map map
;
746 struct brw_cs_prog_key key
;
747 struct anv_shader_bin
*bin
= NULL
;
748 unsigned char sha1
[20];
750 populate_cs_prog_key(&pipeline
->device
->info
, &key
);
753 anv_hash_shader(sha1
, &key
, sizeof(key
), module
, entrypoint
,
754 pipeline
->layout
, spec_info
);
755 bin
= anv_pipeline_cache_search(cache
, sha1
, 20);
759 struct brw_cs_prog_data prog_data
= { 0, };
760 struct anv_pipeline_binding surface_to_descriptor
[256];
761 struct anv_pipeline_binding sampler_to_descriptor
[256];
763 map
= (struct anv_pipeline_bind_map
) {
764 .surface_to_descriptor
= surface_to_descriptor
,
765 .sampler_to_descriptor
= sampler_to_descriptor
768 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
769 MESA_SHADER_COMPUTE
, spec_info
,
770 &prog_data
.base
, &map
);
772 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
774 anv_fill_binding_table(&prog_data
.base
, 1);
776 void *mem_ctx
= ralloc_context(NULL
);
778 if (module
->nir
== NULL
)
779 ralloc_steal(mem_ctx
, nir
);
782 const unsigned *shader_code
=
783 brw_compile_cs(compiler
, NULL
, mem_ctx
, &key
, &prog_data
, nir
,
784 -1, &code_size
, NULL
);
785 if (shader_code
== NULL
) {
786 ralloc_free(mem_ctx
);
787 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
790 bin
= anv_pipeline_upload_kernel(pipeline
, cache
, sha1
, 20,
791 shader_code
, code_size
,
792 &prog_data
, sizeof(prog_data
), &map
);
794 ralloc_free(mem_ctx
);
795 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
798 ralloc_free(mem_ctx
);
801 pipeline
->cs_simd
= bin
->kernel
.offset
;
803 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_COMPUTE
, bin
);
809 * Copy pipeline state not marked as dynamic.
810 * Dynamic state is pipeline state which hasn't been provided at pipeline
811 * creation time, but is dynamically provided afterwards using various
812 * vkCmdSet* functions.
814 * The set of state considered "non_dynamic" is determined by the pieces of
815 * state that have their corresponding VkDynamicState enums omitted from
816 * VkPipelineDynamicStateCreateInfo::pDynamicStates.
818 * @param[out] pipeline Destination non_dynamic state.
819 * @param[in] pCreateInfo Source of non_dynamic state to be copied.
822 copy_non_dynamic_state(struct anv_pipeline
*pipeline
,
823 const VkGraphicsPipelineCreateInfo
*pCreateInfo
)
825 anv_cmd_dirty_mask_t states
= ANV_CMD_DIRTY_DYNAMIC_ALL
;
826 ANV_FROM_HANDLE(anv_render_pass
, pass
, pCreateInfo
->renderPass
);
827 struct anv_subpass
*subpass
= &pass
->subpasses
[pCreateInfo
->subpass
];
829 pipeline
->dynamic_state
= default_dynamic_state
;
831 if (pCreateInfo
->pDynamicState
) {
832 /* Remove all of the states that are marked as dynamic */
833 uint32_t count
= pCreateInfo
->pDynamicState
->dynamicStateCount
;
834 for (uint32_t s
= 0; s
< count
; s
++)
835 states
&= ~(1 << pCreateInfo
->pDynamicState
->pDynamicStates
[s
]);
838 struct anv_dynamic_state
*dynamic
= &pipeline
->dynamic_state
;
840 /* Section 9.2 of the Vulkan 1.0.15 spec says:
842 * pViewportState is [...] NULL if the pipeline
843 * has rasterization disabled.
845 if (!pCreateInfo
->pRasterizationState
->rasterizerDiscardEnable
) {
846 assert(pCreateInfo
->pViewportState
);
848 dynamic
->viewport
.count
= pCreateInfo
->pViewportState
->viewportCount
;
849 if (states
& (1 << VK_DYNAMIC_STATE_VIEWPORT
)) {
850 typed_memcpy(dynamic
->viewport
.viewports
,
851 pCreateInfo
->pViewportState
->pViewports
,
852 pCreateInfo
->pViewportState
->viewportCount
);
855 dynamic
->scissor
.count
= pCreateInfo
->pViewportState
->scissorCount
;
856 if (states
& (1 << VK_DYNAMIC_STATE_SCISSOR
)) {
857 typed_memcpy(dynamic
->scissor
.scissors
,
858 pCreateInfo
->pViewportState
->pScissors
,
859 pCreateInfo
->pViewportState
->scissorCount
);
863 if (states
& (1 << VK_DYNAMIC_STATE_LINE_WIDTH
)) {
864 assert(pCreateInfo
->pRasterizationState
);
865 dynamic
->line_width
= pCreateInfo
->pRasterizationState
->lineWidth
;
868 if (states
& (1 << VK_DYNAMIC_STATE_DEPTH_BIAS
)) {
869 assert(pCreateInfo
->pRasterizationState
);
870 dynamic
->depth_bias
.bias
=
871 pCreateInfo
->pRasterizationState
->depthBiasConstantFactor
;
872 dynamic
->depth_bias
.clamp
=
873 pCreateInfo
->pRasterizationState
->depthBiasClamp
;
874 dynamic
->depth_bias
.slope
=
875 pCreateInfo
->pRasterizationState
->depthBiasSlopeFactor
;
878 /* Section 9.2 of the Vulkan 1.0.15 spec says:
880 * pColorBlendState is [...] NULL if the pipeline has rasterization
881 * disabled or if the subpass of the render pass the pipeline is
882 * created against does not use any color attachments.
884 bool uses_color_att
= false;
885 for (unsigned i
= 0; i
< subpass
->color_count
; ++i
) {
886 if (subpass
->color_attachments
[i
] != VK_ATTACHMENT_UNUSED
) {
887 uses_color_att
= true;
892 if (uses_color_att
&&
893 !pCreateInfo
->pRasterizationState
->rasterizerDiscardEnable
) {
894 assert(pCreateInfo
->pColorBlendState
);
896 if (states
& (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS
))
897 typed_memcpy(dynamic
->blend_constants
,
898 pCreateInfo
->pColorBlendState
->blendConstants
, 4);
901 /* If there is no depthstencil attachment, then don't read
902 * pDepthStencilState. The Vulkan spec states that pDepthStencilState may
903 * be NULL in this case. Even if pDepthStencilState is non-NULL, there is
904 * no need to override the depthstencil defaults in
905 * anv_pipeline::dynamic_state when there is no depthstencil attachment.
907 * Section 9.2 of the Vulkan 1.0.15 spec says:
909 * pDepthStencilState is [...] NULL if the pipeline has rasterization
910 * disabled or if the subpass of the render pass the pipeline is created
911 * against does not use a depth/stencil attachment.
913 if (!pCreateInfo
->pRasterizationState
->rasterizerDiscardEnable
&&
914 subpass
->depth_stencil_attachment
!= VK_ATTACHMENT_UNUSED
) {
915 assert(pCreateInfo
->pDepthStencilState
);
917 if (states
& (1 << VK_DYNAMIC_STATE_DEPTH_BOUNDS
)) {
918 dynamic
->depth_bounds
.min
=
919 pCreateInfo
->pDepthStencilState
->minDepthBounds
;
920 dynamic
->depth_bounds
.max
=
921 pCreateInfo
->pDepthStencilState
->maxDepthBounds
;
924 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
)) {
925 dynamic
->stencil_compare_mask
.front
=
926 pCreateInfo
->pDepthStencilState
->front
.compareMask
;
927 dynamic
->stencil_compare_mask
.back
=
928 pCreateInfo
->pDepthStencilState
->back
.compareMask
;
931 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
)) {
932 dynamic
->stencil_write_mask
.front
=
933 pCreateInfo
->pDepthStencilState
->front
.writeMask
;
934 dynamic
->stencil_write_mask
.back
=
935 pCreateInfo
->pDepthStencilState
->back
.writeMask
;
938 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE
)) {
939 dynamic
->stencil_reference
.front
=
940 pCreateInfo
->pDepthStencilState
->front
.reference
;
941 dynamic
->stencil_reference
.back
=
942 pCreateInfo
->pDepthStencilState
->back
.reference
;
946 pipeline
->dynamic_state_mask
= states
;
950 anv_pipeline_validate_create_info(const VkGraphicsPipelineCreateInfo
*info
)
952 struct anv_render_pass
*renderpass
= NULL
;
953 struct anv_subpass
*subpass
= NULL
;
955 /* Assert that all required members of VkGraphicsPipelineCreateInfo are
956 * present. See the Vulkan 1.0.28 spec, Section 9.2 Graphics Pipelines.
958 assert(info
->sType
== VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
);
960 renderpass
= anv_render_pass_from_handle(info
->renderPass
);
963 if (renderpass
!= &anv_meta_dummy_renderpass
) {
964 assert(info
->subpass
< renderpass
->subpass_count
);
965 subpass
= &renderpass
->subpasses
[info
->subpass
];
968 assert(info
->stageCount
>= 1);
969 assert(info
->pVertexInputState
);
970 assert(info
->pInputAssemblyState
);
971 assert(info
->pRasterizationState
);
972 if (!info
->pRasterizationState
->rasterizerDiscardEnable
) {
973 assert(info
->pViewportState
);
974 assert(info
->pMultisampleState
);
976 if (subpass
&& subpass
->depth_stencil_attachment
!= VK_ATTACHMENT_UNUSED
)
977 assert(info
->pDepthStencilState
);
979 if (subpass
&& subpass
->color_count
> 0)
980 assert(info
->pColorBlendState
);
983 for (uint32_t i
= 0; i
< info
->stageCount
; ++i
) {
984 switch (info
->pStages
[i
].stage
) {
985 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT
:
986 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
:
987 assert(info
->pTessellationState
);
996 * Calculate the desired L3 partitioning based on the current state of the
997 * pipeline. For now this simply returns the conservative defaults calculated
998 * by get_default_l3_weights(), but we could probably do better by gathering
999 * more statistics from the pipeline state (e.g. guess of expected URB usage
1000 * and bound surfaces), or by using feed-back from performance counters.
1003 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
)
1005 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1007 const struct gen_l3_weights w
=
1008 gen_get_default_l3_weights(devinfo
, pipeline
->needs_data_cache
, needs_slm
);
1010 pipeline
->urb
.l3_config
= gen_get_l3_config(devinfo
, w
);
1011 pipeline
->urb
.total_size
=
1012 gen_get_l3_config_urb_size(devinfo
, pipeline
->urb
.l3_config
);
1016 anv_pipeline_init(struct anv_pipeline
*pipeline
,
1017 struct anv_device
*device
,
1018 struct anv_pipeline_cache
*cache
,
1019 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1020 const struct anv_graphics_pipeline_create_info
*extra
,
1021 const VkAllocationCallbacks
*alloc
)
1026 anv_pipeline_validate_create_info(pCreateInfo
);
1030 alloc
= &device
->alloc
;
1032 pipeline
->device
= device
;
1033 pipeline
->layout
= anv_pipeline_layout_from_handle(pCreateInfo
->layout
);
1035 result
= anv_reloc_list_init(&pipeline
->batch_relocs
, alloc
);
1036 if (result
!= VK_SUCCESS
)
1039 pipeline
->batch
.alloc
= alloc
;
1040 pipeline
->batch
.next
= pipeline
->batch
.start
= pipeline
->batch_data
;
1041 pipeline
->batch
.end
= pipeline
->batch
.start
+ sizeof(pipeline
->batch_data
);
1042 pipeline
->batch
.relocs
= &pipeline
->batch_relocs
;
1044 copy_non_dynamic_state(pipeline
, pCreateInfo
);
1045 pipeline
->depth_clamp_enable
= pCreateInfo
->pRasterizationState
&&
1046 pCreateInfo
->pRasterizationState
->depthClampEnable
;
1048 pipeline
->use_repclear
= extra
&& extra
->use_repclear
;
1050 pipeline
->needs_data_cache
= false;
1052 /* When we free the pipeline, we detect stages based on the NULL status
1053 * of various prog_data pointers. Make them NULL by default.
1055 memset(pipeline
->shaders
, 0, sizeof(pipeline
->shaders
));
1057 pipeline
->vs_simd8
= NO_KERNEL
;
1058 pipeline
->vs_vec4
= NO_KERNEL
;
1059 pipeline
->gs_kernel
= NO_KERNEL
;
1060 pipeline
->ps_ksp0
= NO_KERNEL
;
1062 pipeline
->active_stages
= 0;
1064 const VkPipelineShaderStageCreateInfo
*pStages
[MESA_SHADER_STAGES
] = { 0, };
1065 struct anv_shader_module
*modules
[MESA_SHADER_STAGES
] = { 0, };
1066 for (uint32_t i
= 0; i
< pCreateInfo
->stageCount
; i
++) {
1067 gl_shader_stage stage
= ffs(pCreateInfo
->pStages
[i
].stage
) - 1;
1068 pStages
[stage
] = &pCreateInfo
->pStages
[i
];
1069 modules
[stage
] = anv_shader_module_from_handle(pStages
[stage
]->module
);
1072 if (modules
[MESA_SHADER_VERTEX
]) {
1073 result
= anv_pipeline_compile_vs(pipeline
, cache
, pCreateInfo
,
1074 modules
[MESA_SHADER_VERTEX
],
1075 pStages
[MESA_SHADER_VERTEX
]->pName
,
1076 pStages
[MESA_SHADER_VERTEX
]->pSpecializationInfo
);
1077 if (result
!= VK_SUCCESS
)
1081 if (modules
[MESA_SHADER_TESS_CTRL
] || modules
[MESA_SHADER_TESS_EVAL
])
1082 anv_finishme("no tessellation support");
1084 if (modules
[MESA_SHADER_GEOMETRY
]) {
1085 result
= anv_pipeline_compile_gs(pipeline
, cache
, pCreateInfo
,
1086 modules
[MESA_SHADER_GEOMETRY
],
1087 pStages
[MESA_SHADER_GEOMETRY
]->pName
,
1088 pStages
[MESA_SHADER_GEOMETRY
]->pSpecializationInfo
);
1089 if (result
!= VK_SUCCESS
)
1093 if (modules
[MESA_SHADER_FRAGMENT
]) {
1094 result
= anv_pipeline_compile_fs(pipeline
, cache
, pCreateInfo
, extra
,
1095 modules
[MESA_SHADER_FRAGMENT
],
1096 pStages
[MESA_SHADER_FRAGMENT
]->pName
,
1097 pStages
[MESA_SHADER_FRAGMENT
]->pSpecializationInfo
);
1098 if (result
!= VK_SUCCESS
)
1102 if (!(pipeline
->active_stages
& VK_SHADER_STAGE_VERTEX_BIT
)) {
1103 /* Vertex is only optional if disable_vs is set */
1104 assert(extra
->disable_vs
);
1107 anv_pipeline_setup_l3_config(pipeline
, false);
1109 const VkPipelineVertexInputStateCreateInfo
*vi_info
=
1110 pCreateInfo
->pVertexInputState
;
1112 uint64_t inputs_read
;
1113 if (extra
&& extra
->disable_vs
) {
1114 /* If the VS is disabled, just assume the user knows what they're
1115 * doing and apply the layout blindly. This can only come from
1116 * meta, so this *should* be safe.
1118 inputs_read
= ~0ull;
1120 inputs_read
= get_vs_prog_data(pipeline
)->inputs_read
;
1123 pipeline
->vb_used
= 0;
1124 for (uint32_t i
= 0; i
< vi_info
->vertexAttributeDescriptionCount
; i
++) {
1125 const VkVertexInputAttributeDescription
*desc
=
1126 &vi_info
->pVertexAttributeDescriptions
[i
];
1128 if (inputs_read
& (1 << (VERT_ATTRIB_GENERIC0
+ desc
->location
)))
1129 pipeline
->vb_used
|= 1 << desc
->binding
;
1132 for (uint32_t i
= 0; i
< vi_info
->vertexBindingDescriptionCount
; i
++) {
1133 const VkVertexInputBindingDescription
*desc
=
1134 &vi_info
->pVertexBindingDescriptions
[i
];
1136 pipeline
->binding_stride
[desc
->binding
] = desc
->stride
;
1138 /* Step rate is programmed per vertex element (attribute), not
1139 * binding. Set up a map of which bindings step per instance, for
1140 * reference by vertex element setup. */
1141 switch (desc
->inputRate
) {
1143 case VK_VERTEX_INPUT_RATE_VERTEX
:
1144 pipeline
->instancing_enable
[desc
->binding
] = false;
1146 case VK_VERTEX_INPUT_RATE_INSTANCE
:
1147 pipeline
->instancing_enable
[desc
->binding
] = true;
1152 const VkPipelineInputAssemblyStateCreateInfo
*ia_info
=
1153 pCreateInfo
->pInputAssemblyState
;
1154 pipeline
->primitive_restart
= ia_info
->primitiveRestartEnable
;
1155 pipeline
->topology
= vk_to_gen_primitive_type
[ia_info
->topology
];
1157 if (extra
&& extra
->use_rectlist
)
1158 pipeline
->topology
= _3DPRIM_RECTLIST
;
1163 for (unsigned s
= 0; s
< MESA_SHADER_STAGES
; s
++) {
1164 if (pipeline
->shaders
[s
])
1165 anv_shader_bin_unref(device
, pipeline
->shaders
[s
]);
1168 anv_reloc_list_finish(&pipeline
->batch_relocs
, alloc
);
1174 anv_graphics_pipeline_create(
1176 VkPipelineCache _cache
,
1177 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1178 const struct anv_graphics_pipeline_create_info
*extra
,
1179 const VkAllocationCallbacks
*pAllocator
,
1180 VkPipeline
*pPipeline
)
1182 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1183 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
1185 switch (device
->info
.gen
) {
1187 if (device
->info
.is_haswell
)
1188 return gen75_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1190 return gen7_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1192 return gen8_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1194 return gen9_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1196 unreachable("unsupported gen\n");
1200 VkResult
anv_CreateGraphicsPipelines(
1202 VkPipelineCache pipelineCache
,
1204 const VkGraphicsPipelineCreateInfo
* pCreateInfos
,
1205 const VkAllocationCallbacks
* pAllocator
,
1206 VkPipeline
* pPipelines
)
1208 VkResult result
= VK_SUCCESS
;
1211 for (; i
< count
; i
++) {
1212 result
= anv_graphics_pipeline_create(_device
,
1215 NULL
, pAllocator
, &pPipelines
[i
]);
1216 if (result
!= VK_SUCCESS
) {
1217 for (unsigned j
= 0; j
< i
; j
++) {
1218 anv_DestroyPipeline(_device
, pPipelines
[j
], pAllocator
);
1228 static VkResult
anv_compute_pipeline_create(
1230 VkPipelineCache _cache
,
1231 const VkComputePipelineCreateInfo
* pCreateInfo
,
1232 const VkAllocationCallbacks
* pAllocator
,
1233 VkPipeline
* pPipeline
)
1235 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1236 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
1238 switch (device
->info
.gen
) {
1240 if (device
->info
.is_haswell
)
1241 return gen75_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1243 return gen7_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1245 return gen8_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1247 return gen9_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1249 unreachable("unsupported gen\n");
1253 VkResult
anv_CreateComputePipelines(
1255 VkPipelineCache pipelineCache
,
1257 const VkComputePipelineCreateInfo
* pCreateInfos
,
1258 const VkAllocationCallbacks
* pAllocator
,
1259 VkPipeline
* pPipelines
)
1261 VkResult result
= VK_SUCCESS
;
1264 for (; i
< count
; i
++) {
1265 result
= anv_compute_pipeline_create(_device
, pipelineCache
,
1267 pAllocator
, &pPipelines
[i
]);
1268 if (result
!= VK_SUCCESS
) {
1269 for (unsigned j
= 0; j
< i
; j
++) {
1270 anv_DestroyPipeline(_device
, pPipelines
[j
], pAllocator
);