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 "anv_private.h"
33 #include "glsl/nir/spirv/nir_spirv.h"
35 /* Needed for SWIZZLE macros */
36 #include "program/prog_instruction.h"
40 VkResult
anv_CreateShaderModule(
42 const VkShaderModuleCreateInfo
* pCreateInfo
,
43 const VkAllocationCallbacks
* pAllocator
,
44 VkShaderModule
* pShaderModule
)
46 ANV_FROM_HANDLE(anv_device
, device
, _device
);
47 struct anv_shader_module
*module
;
49 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO
);
50 assert(pCreateInfo
->flags
== 0);
52 module
= anv_alloc2(&device
->alloc
, pAllocator
,
53 sizeof(*module
) + pCreateInfo
->codeSize
, 8,
54 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
56 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
59 module
->size
= pCreateInfo
->codeSize
;
60 memcpy(module
->data
, pCreateInfo
->pCode
, module
->size
);
62 *pShaderModule
= anv_shader_module_to_handle(module
);
67 void anv_DestroyShaderModule(
69 VkShaderModule _module
,
70 const VkAllocationCallbacks
* pAllocator
)
72 ANV_FROM_HANDLE(anv_device
, device
, _device
);
73 ANV_FROM_HANDLE(anv_shader_module
, module
, _module
);
75 anv_free2(&device
->alloc
, pAllocator
, module
);
78 #define SPIR_V_MAGIC_NUMBER 0x07230203
80 /* Eventually, this will become part of anv_CreateShader. Unfortunately,
81 * we can't do that yet because we don't have the ability to copy nir.
84 anv_shader_compile_to_nir(struct anv_device
*device
,
85 struct anv_shader_module
*module
,
86 const char *entrypoint_name
,
87 gl_shader_stage stage
,
88 const VkSpecializationInfo
*spec_info
)
90 if (strcmp(entrypoint_name
, "main") != 0) {
91 anv_finishme("Multiple shaders per module not really supported");
94 const struct brw_compiler
*compiler
=
95 device
->instance
->physicalDevice
.compiler
;
96 const nir_shader_compiler_options
*nir_options
=
97 compiler
->glsl_compiler_options
[stage
].NirOptions
;
100 nir_function
*entry_point
;
102 /* Some things such as our meta clear/blit code will give us a NIR
103 * shader directly. In that case, we just ignore the SPIR-V entirely
104 * and just use the NIR shader */
106 nir
->options
= nir_options
;
107 nir_validate_shader(nir
);
109 assert(exec_list_length(&nir
->functions
) == 1);
110 struct exec_node
*node
= exec_list_get_head(&nir
->functions
);
111 entry_point
= exec_node_data(nir_function
, node
, node
);
113 uint32_t *spirv
= (uint32_t *) module
->data
;
114 assert(spirv
[0] == SPIR_V_MAGIC_NUMBER
);
115 assert(module
->size
% 4 == 0);
117 uint32_t num_spec_entries
= 0;
118 struct nir_spirv_specialization
*spec_entries
= NULL
;
119 if (spec_info
&& spec_info
->mapEntryCount
> 0) {
120 num_spec_entries
= spec_info
->mapEntryCount
;
121 spec_entries
= malloc(num_spec_entries
* sizeof(*spec_entries
));
122 for (uint32_t i
= 0; i
< num_spec_entries
; i
++) {
123 const uint32_t *data
=
124 spec_info
->pData
+ spec_info
->pMapEntries
[i
].offset
;
125 assert((const void *)(data
+ 1) <=
126 spec_info
->pData
+ spec_info
->dataSize
);
128 spec_entries
[i
].id
= spec_info
->pMapEntries
[i
].constantID
;
129 spec_entries
[i
].data
= *data
;
133 entry_point
= spirv_to_nir(spirv
, module
->size
/ 4,
134 spec_entries
, num_spec_entries
,
135 stage
, entrypoint_name
, nir_options
);
136 nir
= entry_point
->shader
;
137 assert(nir
->stage
== stage
);
138 nir_validate_shader(nir
);
142 nir_lower_returns(nir
);
143 nir_validate_shader(nir
);
145 nir_inline_functions(nir
);
146 nir_validate_shader(nir
);
148 /* Pick off the single entrypoint that we want */
149 foreach_list_typed_safe(nir_function
, func
, node
, &nir
->functions
) {
150 if (func
!= entry_point
)
151 exec_node_remove(&func
->node
);
153 assert(exec_list_length(&nir
->functions
) == 1);
154 entry_point
->name
= ralloc_strdup(entry_point
, "main");
156 nir_remove_dead_variables(nir
, nir_var_shader_in
);
157 nir_remove_dead_variables(nir
, nir_var_shader_out
);
158 nir_remove_dead_variables(nir
, nir_var_system_value
);
159 nir_validate_shader(nir
);
161 nir_lower_outputs_to_temporaries(entry_point
->shader
, entry_point
);
163 nir_lower_system_values(nir
);
164 nir_validate_shader(nir
);
167 /* Vulkan uses the separate-shader linking model */
168 nir
->info
.separate_shader
= true;
170 nir
= brw_preprocess_nir(nir
, compiler
->scalar_stage
[stage
]);
172 nir_shader_gather_info(nir
, entry_point
->impl
);
174 uint32_t indirect_mask
= (1 << nir_var_shader_in
);
175 if (compiler
->glsl_compiler_options
[stage
].EmitNoIndirectTemp
)
176 indirect_mask
|= 1 << nir_var_local
;
178 nir_lower_indirect_derefs(nir
, indirect_mask
);
184 anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
185 struct anv_device
*device
)
187 cache
->device
= device
;
188 anv_state_stream_init(&cache
->program_stream
,
189 &device
->instruction_block_pool
);
190 pthread_mutex_init(&cache
->mutex
, NULL
);
194 anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
)
196 anv_state_stream_finish(&cache
->program_stream
);
197 pthread_mutex_destroy(&cache
->mutex
);
201 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
202 const void *data
, size_t size
)
204 pthread_mutex_lock(&cache
->mutex
);
206 struct anv_state state
=
207 anv_state_stream_alloc(&cache
->program_stream
, size
, 64);
209 pthread_mutex_unlock(&cache
->mutex
);
211 assert(size
< cache
->program_stream
.block_pool
->block_size
);
213 memcpy(state
.map
, data
, size
);
215 if (!cache
->device
->info
.has_llc
)
216 anv_state_clflush(state
);
221 VkResult
anv_CreatePipelineCache(
223 const VkPipelineCacheCreateInfo
* pCreateInfo
,
224 const VkAllocationCallbacks
* pAllocator
,
225 VkPipelineCache
* pPipelineCache
)
227 ANV_FROM_HANDLE(anv_device
, device
, _device
);
228 struct anv_pipeline_cache
*cache
;
230 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
);
231 assert(pCreateInfo
->flags
== 0);
233 cache
= anv_alloc2(&device
->alloc
, pAllocator
,
235 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
237 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
239 anv_pipeline_cache_init(cache
, device
);
241 *pPipelineCache
= anv_pipeline_cache_to_handle(cache
);
246 void anv_DestroyPipelineCache(
248 VkPipelineCache _cache
,
249 const VkAllocationCallbacks
* pAllocator
)
251 ANV_FROM_HANDLE(anv_device
, device
, _device
);
252 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
254 anv_pipeline_cache_finish(cache
);
256 anv_free2(&device
->alloc
, pAllocator
, cache
);
259 VkResult
anv_GetPipelineCacheData(
261 VkPipelineCache pipelineCache
,
270 VkResult
anv_MergePipelineCaches(
272 VkPipelineCache destCache
,
273 uint32_t srcCacheCount
,
274 const VkPipelineCache
* pSrcCaches
)
276 stub_return(VK_SUCCESS
);
279 void anv_DestroyPipeline(
281 VkPipeline _pipeline
,
282 const VkAllocationCallbacks
* pAllocator
)
284 ANV_FROM_HANDLE(anv_device
, device
, _device
);
285 ANV_FROM_HANDLE(anv_pipeline
, pipeline
, _pipeline
);
287 anv_reloc_list_finish(&pipeline
->batch_relocs
,
288 pAllocator
? pAllocator
: &device
->alloc
);
289 if (pipeline
->blend_state
.map
)
290 anv_state_pool_free(&device
->dynamic_state_pool
, pipeline
->blend_state
);
291 anv_free2(&device
->alloc
, pAllocator
, pipeline
);
294 static const uint32_t vk_to_gen_primitive_type
[] = {
295 [VK_PRIMITIVE_TOPOLOGY_POINT_LIST
] = _3DPRIM_POINTLIST
,
296 [VK_PRIMITIVE_TOPOLOGY_LINE_LIST
] = _3DPRIM_LINELIST
,
297 [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP
] = _3DPRIM_LINESTRIP
,
298 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
] = _3DPRIM_TRILIST
,
299 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
] = _3DPRIM_TRISTRIP
,
300 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN
] = _3DPRIM_TRIFAN
,
301 [VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY
] = _3DPRIM_LINELIST_ADJ
,
302 [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY
] = _3DPRIM_LINESTRIP_ADJ
,
303 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY
] = _3DPRIM_TRILIST_ADJ
,
304 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY
] = _3DPRIM_TRISTRIP_ADJ
,
305 /* [VK_PRIMITIVE_TOPOLOGY_PATCH_LIST] = _3DPRIM_PATCHLIST_1 */
309 populate_sampler_prog_key(const struct brw_device_info
*devinfo
,
310 struct brw_sampler_prog_key_data
*key
)
312 /* XXX: Handle texture swizzle on HSW- */
313 for (int i
= 0; i
< MAX_SAMPLERS
; i
++) {
314 /* Assume color sampler, no swizzling. (Works for BDW+) */
315 key
->swizzles
[i
] = SWIZZLE_XYZW
;
320 populate_vs_prog_key(const struct brw_device_info
*devinfo
,
321 struct brw_vs_prog_key
*key
)
323 memset(key
, 0, sizeof(*key
));
325 populate_sampler_prog_key(devinfo
, &key
->tex
);
327 /* XXX: Handle vertex input work-arounds */
329 /* XXX: Handle sampler_prog_key */
333 populate_gs_prog_key(const struct brw_device_info
*devinfo
,
334 struct brw_gs_prog_key
*key
)
336 memset(key
, 0, sizeof(*key
));
338 populate_sampler_prog_key(devinfo
, &key
->tex
);
342 populate_wm_prog_key(const struct brw_device_info
*devinfo
,
343 const VkGraphicsPipelineCreateInfo
*info
,
344 struct brw_wm_prog_key
*key
)
346 ANV_FROM_HANDLE(anv_render_pass
, render_pass
, info
->renderPass
);
348 memset(key
, 0, sizeof(*key
));
350 populate_sampler_prog_key(devinfo
, &key
->tex
);
352 /* TODO: Fill out key->input_slots_valid */
354 /* Vulkan doesn't specify a default */
355 key
->high_quality_derivatives
= false;
357 /* XXX Vulkan doesn't appear to specify */
358 key
->clamp_fragment_color
= false;
360 /* Vulkan always specifies upper-left coordinates */
361 key
->drawable_height
= 0;
362 key
->render_to_fbo
= false;
364 key
->nr_color_regions
= render_pass
->subpasses
[info
->subpass
].color_count
;
366 key
->replicate_alpha
= key
->nr_color_regions
> 1 &&
367 info
->pMultisampleState
&&
368 info
->pMultisampleState
->alphaToCoverageEnable
;
370 if (info
->pMultisampleState
&& info
->pMultisampleState
->rasterizationSamples
> 1) {
371 /* We should probably pull this out of the shader, but it's fairly
372 * harmless to compute it and then let dead-code take care of it.
374 key
->persample_shading
= info
->pMultisampleState
->sampleShadingEnable
;
375 if (key
->persample_shading
)
376 key
->persample_2x
= info
->pMultisampleState
->rasterizationSamples
== 2;
378 key
->compute_pos_offset
= info
->pMultisampleState
->sampleShadingEnable
;
379 key
->compute_sample_id
= info
->pMultisampleState
->sampleShadingEnable
;
384 populate_cs_prog_key(const struct brw_device_info
*devinfo
,
385 struct brw_cs_prog_key
*key
)
387 memset(key
, 0, sizeof(*key
));
389 populate_sampler_prog_key(devinfo
, &key
->tex
);
393 anv_pipeline_compile(struct anv_pipeline
*pipeline
,
394 struct anv_shader_module
*module
,
395 const char *entrypoint
,
396 gl_shader_stage stage
,
397 const VkSpecializationInfo
*spec_info
,
398 struct brw_stage_prog_data
*prog_data
)
400 const struct brw_compiler
*compiler
=
401 pipeline
->device
->instance
->physicalDevice
.compiler
;
403 nir_shader
*nir
= anv_shader_compile_to_nir(pipeline
->device
,
404 module
, entrypoint
, stage
,
409 anv_nir_lower_push_constants(nir
, compiler
->scalar_stage
[stage
]);
411 /* Figure out the number of parameters */
412 prog_data
->nr_params
= 0;
414 if (nir
->num_uniforms
> 0) {
415 /* If the shader uses any push constants at all, we'll just give
416 * them the maximum possible number
418 prog_data
->nr_params
+= MAX_PUSH_CONSTANTS_SIZE
/ sizeof(float);
421 if (pipeline
->layout
&& pipeline
->layout
->stage
[stage
].has_dynamic_offsets
)
422 prog_data
->nr_params
+= MAX_DYNAMIC_BUFFERS
* 2;
424 if (pipeline
->layout
&& pipeline
->layout
->stage
[stage
].image_count
> 0)
425 prog_data
->nr_params
+= pipeline
->layout
->stage
[stage
].image_count
*
426 BRW_IMAGE_PARAM_SIZE
;
428 if (prog_data
->nr_params
> 0) {
429 /* XXX: I think we're leaking this */
430 prog_data
->param
= (const union gl_constant_value
**)
431 malloc(prog_data
->nr_params
* sizeof(union gl_constant_value
*));
433 /* We now set the param values to be offsets into a
434 * anv_push_constant_data structure. Since the compiler doesn't
435 * actually dereference any of the gl_constant_value pointers in the
436 * params array, it doesn't really matter what we put here.
438 struct anv_push_constants
*null_data
= NULL
;
439 if (nir
->num_uniforms
> 0) {
440 /* Fill out the push constants section of the param array */
441 for (unsigned i
= 0; i
< MAX_PUSH_CONSTANTS_SIZE
/ sizeof(float); i
++)
442 prog_data
->param
[i
] = (const union gl_constant_value
*)
443 &null_data
->client_data
[i
* sizeof(float)];
447 /* Set up dynamic offsets */
448 anv_nir_apply_dynamic_offsets(pipeline
, nir
, prog_data
);
450 /* Apply the actual pipeline layout to UBOs, SSBOs, and textures */
451 if (pipeline
->layout
)
452 anv_nir_apply_pipeline_layout(nir
, prog_data
, pipeline
->layout
);
454 /* All binding table offsets provided by apply_pipeline_layout() are
455 * relative to the start of the bindint table (plus MAX_RTS for VS).
459 case MESA_SHADER_FRAGMENT
:
462 case MESA_SHADER_COMPUTE
:
469 prog_data
->binding_table
.size_bytes
= 0;
470 prog_data
->binding_table
.texture_start
= bias
;
471 prog_data
->binding_table
.ubo_start
= bias
;
472 prog_data
->binding_table
.ssbo_start
= bias
;
473 prog_data
->binding_table
.image_start
= bias
;
475 /* Finish the optimization and compilation process */
476 nir
= brw_nir_lower_io(nir
, &pipeline
->device
->info
,
477 compiler
->scalar_stage
[stage
]);
479 /* nir_lower_io will only handle the push constants; we need to set this
480 * to the full number of possible uniforms.
482 nir
->num_uniforms
= prog_data
->nr_params
* 4;
488 anv_pipeline_add_compiled_stage(struct anv_pipeline
*pipeline
,
489 gl_shader_stage stage
,
490 struct brw_stage_prog_data
*prog_data
)
492 struct brw_device_info
*devinfo
= &pipeline
->device
->info
;
493 uint32_t max_threads
[] = {
494 [MESA_SHADER_VERTEX
] = devinfo
->max_vs_threads
,
495 [MESA_SHADER_TESS_CTRL
] = 0,
496 [MESA_SHADER_TESS_EVAL
] = 0,
497 [MESA_SHADER_GEOMETRY
] = devinfo
->max_gs_threads
,
498 [MESA_SHADER_FRAGMENT
] = devinfo
->max_wm_threads
,
499 [MESA_SHADER_COMPUTE
] = devinfo
->max_cs_threads
,
502 pipeline
->prog_data
[stage
] = prog_data
;
503 pipeline
->active_stages
|= mesa_to_vk_shader_stage(stage
);
504 pipeline
->scratch_start
[stage
] = pipeline
->total_scratch
;
505 pipeline
->total_scratch
=
506 align_u32(pipeline
->total_scratch
, 1024) +
507 prog_data
->total_scratch
* max_threads
[stage
];
511 anv_pipeline_compile_vs(struct anv_pipeline
*pipeline
,
512 struct anv_pipeline_cache
*cache
,
513 const VkGraphicsPipelineCreateInfo
*info
,
514 struct anv_shader_module
*module
,
515 const char *entrypoint
,
516 const VkSpecializationInfo
*spec_info
)
518 const struct brw_compiler
*compiler
=
519 pipeline
->device
->instance
->physicalDevice
.compiler
;
520 struct brw_vs_prog_data
*prog_data
= &pipeline
->vs_prog_data
;
521 struct brw_vs_prog_key key
;
523 populate_vs_prog_key(&pipeline
->device
->info
, &key
);
525 /* TODO: Look up shader in cache */
527 memset(prog_data
, 0, sizeof(*prog_data
));
529 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
530 MESA_SHADER_VERTEX
, spec_info
,
531 &prog_data
->base
.base
);
533 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
535 void *mem_ctx
= ralloc_context(NULL
);
537 if (module
->nir
== NULL
)
538 ralloc_steal(mem_ctx
, nir
);
540 prog_data
->inputs_read
= nir
->info
.inputs_read
;
541 pipeline
->writes_point_size
= nir
->info
.outputs_written
& VARYING_SLOT_PSIZ
;
543 brw_compute_vue_map(&pipeline
->device
->info
,
544 &prog_data
->base
.vue_map
,
545 nir
->info
.outputs_written
,
546 nir
->info
.separate_shader
);
549 const unsigned *shader_code
=
550 brw_compile_vs(compiler
, NULL
, mem_ctx
, &key
, prog_data
, nir
,
551 NULL
, false, -1, &code_size
, NULL
);
552 if (shader_code
== NULL
) {
553 ralloc_free(mem_ctx
);
554 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
557 const uint32_t offset
=
558 anv_pipeline_cache_upload_kernel(cache
, shader_code
, code_size
);
559 if (prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
) {
560 pipeline
->vs_simd8
= offset
;
561 pipeline
->vs_vec4
= NO_KERNEL
;
563 pipeline
->vs_simd8
= NO_KERNEL
;
564 pipeline
->vs_vec4
= offset
;
567 ralloc_free(mem_ctx
);
569 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_VERTEX
,
570 &prog_data
->base
.base
);
576 anv_pipeline_compile_gs(struct anv_pipeline
*pipeline
,
577 struct anv_pipeline_cache
*cache
,
578 const VkGraphicsPipelineCreateInfo
*info
,
579 struct anv_shader_module
*module
,
580 const char *entrypoint
,
581 const VkSpecializationInfo
*spec_info
)
583 const struct brw_compiler
*compiler
=
584 pipeline
->device
->instance
->physicalDevice
.compiler
;
585 struct brw_gs_prog_data
*prog_data
= &pipeline
->gs_prog_data
;
586 struct brw_gs_prog_key key
;
588 populate_gs_prog_key(&pipeline
->device
->info
, &key
);
590 /* TODO: Look up shader in cache */
592 memset(prog_data
, 0, sizeof(*prog_data
));
594 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
595 MESA_SHADER_GEOMETRY
, spec_info
,
596 &prog_data
->base
.base
);
598 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
600 void *mem_ctx
= ralloc_context(NULL
);
602 if (module
->nir
== NULL
)
603 ralloc_steal(mem_ctx
, nir
);
605 brw_compute_vue_map(&pipeline
->device
->info
,
606 &prog_data
->base
.vue_map
,
607 nir
->info
.outputs_written
,
608 nir
->info
.separate_shader
);
611 const unsigned *shader_code
=
612 brw_compile_gs(compiler
, NULL
, mem_ctx
, &key
, prog_data
, nir
,
613 NULL
, -1, &code_size
, NULL
);
614 if (shader_code
== NULL
) {
615 ralloc_free(mem_ctx
);
616 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
620 pipeline
->gs_kernel
=
621 anv_pipeline_cache_upload_kernel(cache
, shader_code
, code_size
);
622 pipeline
->gs_vertex_count
= nir
->info
.gs
.vertices_in
;
624 ralloc_free(mem_ctx
);
626 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_GEOMETRY
,
627 &prog_data
->base
.base
);
633 anv_pipeline_compile_fs(struct anv_pipeline
*pipeline
,
634 struct anv_pipeline_cache
*cache
,
635 const VkGraphicsPipelineCreateInfo
*info
,
636 struct anv_shader_module
*module
,
637 const char *entrypoint
,
638 const VkSpecializationInfo
*spec_info
)
640 const struct brw_compiler
*compiler
=
641 pipeline
->device
->instance
->physicalDevice
.compiler
;
642 struct brw_wm_prog_data
*prog_data
= &pipeline
->wm_prog_data
;
643 struct brw_wm_prog_key key
;
645 populate_wm_prog_key(&pipeline
->device
->info
, info
, &key
);
647 if (pipeline
->use_repclear
)
648 key
.nr_color_regions
= 1;
650 /* TODO: Look up shader in cache */
652 memset(prog_data
, 0, sizeof(*prog_data
));
654 prog_data
->binding_table
.render_target_start
= 0;
656 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
657 MESA_SHADER_FRAGMENT
, spec_info
,
660 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
662 void *mem_ctx
= ralloc_context(NULL
);
664 if (module
->nir
== NULL
)
665 ralloc_steal(mem_ctx
, nir
);
668 const unsigned *shader_code
=
669 brw_compile_fs(compiler
, NULL
, mem_ctx
, &key
, prog_data
, nir
,
670 NULL
, -1, -1, pipeline
->use_repclear
, &code_size
, NULL
);
671 if (shader_code
== NULL
) {
672 ralloc_free(mem_ctx
);
673 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
677 anv_pipeline_cache_upload_kernel(cache
, shader_code
, code_size
);
679 pipeline
->ps_simd8
= NO_KERNEL
;
681 pipeline
->ps_simd8
= offset
;
683 if (prog_data
->no_8
|| prog_data
->prog_offset_16
) {
684 pipeline
->ps_simd16
= offset
+ prog_data
->prog_offset_16
;
686 pipeline
->ps_simd16
= NO_KERNEL
;
689 pipeline
->ps_ksp2
= 0;
690 pipeline
->ps_grf_start2
= 0;
691 if (pipeline
->ps_simd8
!= NO_KERNEL
) {
692 pipeline
->ps_ksp0
= pipeline
->ps_simd8
;
693 pipeline
->ps_grf_start0
= prog_data
->base
.dispatch_grf_start_reg
;
694 if (pipeline
->ps_simd16
!= NO_KERNEL
) {
695 pipeline
->ps_ksp2
= pipeline
->ps_simd16
;
696 pipeline
->ps_grf_start2
= prog_data
->dispatch_grf_start_reg_16
;
698 } else if (pipeline
->ps_simd16
!= NO_KERNEL
) {
699 pipeline
->ps_ksp0
= pipeline
->ps_simd16
;
700 pipeline
->ps_grf_start0
= prog_data
->dispatch_grf_start_reg_16
;
703 ralloc_free(mem_ctx
);
705 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_FRAGMENT
,
712 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
713 struct anv_pipeline_cache
*cache
,
714 const VkComputePipelineCreateInfo
*info
,
715 struct anv_shader_module
*module
,
716 const char *entrypoint
,
717 const VkSpecializationInfo
*spec_info
)
719 const struct brw_compiler
*compiler
=
720 pipeline
->device
->instance
->physicalDevice
.compiler
;
721 struct brw_cs_prog_data
*prog_data
= &pipeline
->cs_prog_data
;
722 struct brw_cs_prog_key key
;
724 populate_cs_prog_key(&pipeline
->device
->info
, &key
);
726 /* TODO: Look up shader in cache */
728 memset(prog_data
, 0, sizeof(*prog_data
));
730 prog_data
->binding_table
.work_groups_start
= 0;
732 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
733 MESA_SHADER_COMPUTE
, spec_info
,
736 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
738 void *mem_ctx
= ralloc_context(NULL
);
740 if (module
->nir
== NULL
)
741 ralloc_steal(mem_ctx
, nir
);
744 const unsigned *shader_code
=
745 brw_compile_cs(compiler
, NULL
, mem_ctx
, &key
, prog_data
, nir
,
746 -1, &code_size
, NULL
);
747 if (shader_code
== NULL
) {
748 ralloc_free(mem_ctx
);
749 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
753 anv_pipeline_cache_upload_kernel(cache
, shader_code
, code_size
);
754 ralloc_free(mem_ctx
);
756 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_COMPUTE
,
762 static const int gen8_push_size
= 32 * 1024;
765 gen7_compute_urb_partition(struct anv_pipeline
*pipeline
)
767 const struct brw_device_info
*devinfo
= &pipeline
->device
->info
;
768 bool vs_present
= pipeline
->active_stages
& VK_SHADER_STAGE_VERTEX_BIT
;
769 unsigned vs_size
= vs_present
? pipeline
->vs_prog_data
.base
.urb_entry_size
: 1;
770 unsigned vs_entry_size_bytes
= vs_size
* 64;
771 bool gs_present
= pipeline
->active_stages
& VK_SHADER_STAGE_GEOMETRY_BIT
;
772 unsigned gs_size
= gs_present
? pipeline
->gs_prog_data
.base
.urb_entry_size
: 1;
773 unsigned gs_entry_size_bytes
= gs_size
* 64;
775 /* From p35 of the Ivy Bridge PRM (section 1.7.1: 3DSTATE_URB_GS):
777 * VS Number of URB Entries must be divisible by 8 if the VS URB Entry
778 * Allocation Size is less than 9 512-bit URB entries.
780 * Similar text exists for GS.
782 unsigned vs_granularity
= (vs_size
< 9) ? 8 : 1;
783 unsigned gs_granularity
= (gs_size
< 9) ? 8 : 1;
785 /* URB allocations must be done in 8k chunks. */
786 unsigned chunk_size_bytes
= 8192;
788 /* Determine the size of the URB in chunks. */
789 unsigned urb_chunks
= devinfo
->urb
.size
* 1024 / chunk_size_bytes
;
791 /* Reserve space for push constants */
792 unsigned push_constant_bytes
= gen8_push_size
;
793 unsigned push_constant_chunks
=
794 push_constant_bytes
/ chunk_size_bytes
;
796 /* Initially, assign each stage the minimum amount of URB space it needs,
797 * and make a note of how much additional space it "wants" (the amount of
798 * additional space it could actually make use of).
801 /* VS has a lower limit on the number of URB entries */
803 ALIGN(devinfo
->urb
.min_vs_entries
* vs_entry_size_bytes
,
804 chunk_size_bytes
) / chunk_size_bytes
;
806 ALIGN(devinfo
->urb
.max_vs_entries
* vs_entry_size_bytes
,
807 chunk_size_bytes
) / chunk_size_bytes
- vs_chunks
;
809 unsigned gs_chunks
= 0;
810 unsigned gs_wants
= 0;
812 /* There are two constraints on the minimum amount of URB space we can
815 * (1) We need room for at least 2 URB entries, since we always operate
816 * the GS in DUAL_OBJECT mode.
818 * (2) We can't allocate less than nr_gs_entries_granularity.
820 gs_chunks
= ALIGN(MAX2(gs_granularity
, 2) * gs_entry_size_bytes
,
821 chunk_size_bytes
) / chunk_size_bytes
;
823 ALIGN(devinfo
->urb
.max_gs_entries
* gs_entry_size_bytes
,
824 chunk_size_bytes
) / chunk_size_bytes
- gs_chunks
;
827 /* There should always be enough URB space to satisfy the minimum
828 * requirements of each stage.
830 unsigned total_needs
= push_constant_chunks
+ vs_chunks
+ gs_chunks
;
831 assert(total_needs
<= urb_chunks
);
833 /* Mete out remaining space (if any) in proportion to "wants". */
834 unsigned total_wants
= vs_wants
+ gs_wants
;
835 unsigned remaining_space
= urb_chunks
- total_needs
;
836 if (remaining_space
> total_wants
)
837 remaining_space
= total_wants
;
838 if (remaining_space
> 0) {
839 unsigned vs_additional
= (unsigned)
840 round(vs_wants
* (((double) remaining_space
) / total_wants
));
841 vs_chunks
+= vs_additional
;
842 remaining_space
-= vs_additional
;
843 gs_chunks
+= remaining_space
;
846 /* Sanity check that we haven't over-allocated. */
847 assert(push_constant_chunks
+ vs_chunks
+ gs_chunks
<= urb_chunks
);
849 /* Finally, compute the number of entries that can fit in the space
850 * allocated to each stage.
852 unsigned nr_vs_entries
= vs_chunks
* chunk_size_bytes
/ vs_entry_size_bytes
;
853 unsigned nr_gs_entries
= gs_chunks
* chunk_size_bytes
/ gs_entry_size_bytes
;
855 /* Since we rounded up when computing *_wants, this may be slightly more
856 * than the maximum allowed amount, so correct for that.
858 nr_vs_entries
= MIN2(nr_vs_entries
, devinfo
->urb
.max_vs_entries
);
859 nr_gs_entries
= MIN2(nr_gs_entries
, devinfo
->urb
.max_gs_entries
);
861 /* Ensure that we program a multiple of the granularity. */
862 nr_vs_entries
= ROUND_DOWN_TO(nr_vs_entries
, vs_granularity
);
863 nr_gs_entries
= ROUND_DOWN_TO(nr_gs_entries
, gs_granularity
);
865 /* Finally, sanity check to make sure we have at least the minimum number
866 * of entries needed for each stage.
868 assert(nr_vs_entries
>= devinfo
->urb
.min_vs_entries
);
870 assert(nr_gs_entries
>= 2);
872 /* Lay out the URB in the following order:
877 pipeline
->urb
.vs_start
= push_constant_chunks
;
878 pipeline
->urb
.vs_size
= vs_size
;
879 pipeline
->urb
.nr_vs_entries
= nr_vs_entries
;
881 pipeline
->urb
.gs_start
= push_constant_chunks
+ vs_chunks
;
882 pipeline
->urb
.gs_size
= gs_size
;
883 pipeline
->urb
.nr_gs_entries
= nr_gs_entries
;
887 anv_pipeline_init_dynamic_state(struct anv_pipeline
*pipeline
,
888 const VkGraphicsPipelineCreateInfo
*pCreateInfo
)
890 anv_cmd_dirty_mask_t states
= ANV_CMD_DIRTY_DYNAMIC_ALL
;
891 ANV_FROM_HANDLE(anv_render_pass
, pass
, pCreateInfo
->renderPass
);
892 struct anv_subpass
*subpass
= &pass
->subpasses
[pCreateInfo
->subpass
];
894 pipeline
->dynamic_state
= default_dynamic_state
;
896 if (pCreateInfo
->pDynamicState
) {
897 /* Remove all of the states that are marked as dynamic */
898 uint32_t count
= pCreateInfo
->pDynamicState
->dynamicStateCount
;
899 for (uint32_t s
= 0; s
< count
; s
++)
900 states
&= ~(1 << pCreateInfo
->pDynamicState
->pDynamicStates
[s
]);
903 struct anv_dynamic_state
*dynamic
= &pipeline
->dynamic_state
;
905 dynamic
->viewport
.count
= pCreateInfo
->pViewportState
->viewportCount
;
906 if (states
& (1 << VK_DYNAMIC_STATE_VIEWPORT
)) {
907 typed_memcpy(dynamic
->viewport
.viewports
,
908 pCreateInfo
->pViewportState
->pViewports
,
909 pCreateInfo
->pViewportState
->viewportCount
);
912 dynamic
->scissor
.count
= pCreateInfo
->pViewportState
->scissorCount
;
913 if (states
& (1 << VK_DYNAMIC_STATE_SCISSOR
)) {
914 typed_memcpy(dynamic
->scissor
.scissors
,
915 pCreateInfo
->pViewportState
->pScissors
,
916 pCreateInfo
->pViewportState
->scissorCount
);
919 if (states
& (1 << VK_DYNAMIC_STATE_LINE_WIDTH
)) {
920 assert(pCreateInfo
->pRasterizationState
);
921 dynamic
->line_width
= pCreateInfo
->pRasterizationState
->lineWidth
;
924 if (states
& (1 << VK_DYNAMIC_STATE_DEPTH_BIAS
)) {
925 assert(pCreateInfo
->pRasterizationState
);
926 dynamic
->depth_bias
.bias
=
927 pCreateInfo
->pRasterizationState
->depthBiasConstantFactor
;
928 dynamic
->depth_bias
.clamp
=
929 pCreateInfo
->pRasterizationState
->depthBiasClamp
;
930 dynamic
->depth_bias
.slope
=
931 pCreateInfo
->pRasterizationState
->depthBiasSlopeFactor
;
934 if (states
& (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS
)) {
935 assert(pCreateInfo
->pColorBlendState
);
936 typed_memcpy(dynamic
->blend_constants
,
937 pCreateInfo
->pColorBlendState
->blendConstants
, 4);
940 /* If there is no depthstencil attachment, then don't read
941 * pDepthStencilState. The Vulkan spec states that pDepthStencilState may
942 * be NULL in this case. Even if pDepthStencilState is non-NULL, there is
943 * no need to override the depthstencil defaults in
944 * anv_pipeline::dynamic_state when there is no depthstencil attachment.
946 * From the Vulkan spec (20 Oct 2015, git-aa308cb):
948 * pDepthStencilState [...] may only be NULL if renderPass and subpass
949 * specify a subpass that has no depth/stencil attachment.
951 if (subpass
->depth_stencil_attachment
!= VK_ATTACHMENT_UNUSED
) {
952 if (states
& (1 << VK_DYNAMIC_STATE_DEPTH_BOUNDS
)) {
953 assert(pCreateInfo
->pDepthStencilState
);
954 dynamic
->depth_bounds
.min
=
955 pCreateInfo
->pDepthStencilState
->minDepthBounds
;
956 dynamic
->depth_bounds
.max
=
957 pCreateInfo
->pDepthStencilState
->maxDepthBounds
;
960 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
)) {
961 assert(pCreateInfo
->pDepthStencilState
);
962 dynamic
->stencil_compare_mask
.front
=
963 pCreateInfo
->pDepthStencilState
->front
.compareMask
;
964 dynamic
->stencil_compare_mask
.back
=
965 pCreateInfo
->pDepthStencilState
->back
.compareMask
;
968 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
)) {
969 assert(pCreateInfo
->pDepthStencilState
);
970 dynamic
->stencil_write_mask
.front
=
971 pCreateInfo
->pDepthStencilState
->front
.writeMask
;
972 dynamic
->stencil_write_mask
.back
=
973 pCreateInfo
->pDepthStencilState
->back
.writeMask
;
976 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE
)) {
977 assert(pCreateInfo
->pDepthStencilState
);
978 dynamic
->stencil_reference
.front
=
979 pCreateInfo
->pDepthStencilState
->front
.reference
;
980 dynamic
->stencil_reference
.back
=
981 pCreateInfo
->pDepthStencilState
->back
.reference
;
985 pipeline
->dynamic_state_mask
= states
;
989 anv_pipeline_validate_create_info(const VkGraphicsPipelineCreateInfo
*info
)
991 struct anv_render_pass
*renderpass
= NULL
;
992 struct anv_subpass
*subpass
= NULL
;
994 /* Assert that all required members of VkGraphicsPipelineCreateInfo are
995 * present, as explained by the Vulkan (20 Oct 2015, git-aa308cb), Section
996 * 4.2 Graphics Pipeline.
998 assert(info
->sType
== VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
);
1000 renderpass
= anv_render_pass_from_handle(info
->renderPass
);
1003 if (renderpass
!= &anv_meta_dummy_renderpass
) {
1004 assert(info
->subpass
< renderpass
->subpass_count
);
1005 subpass
= &renderpass
->subpasses
[info
->subpass
];
1008 assert(info
->stageCount
>= 1);
1009 assert(info
->pVertexInputState
);
1010 assert(info
->pInputAssemblyState
);
1011 assert(info
->pViewportState
);
1012 assert(info
->pRasterizationState
);
1014 if (subpass
&& subpass
->depth_stencil_attachment
!= VK_ATTACHMENT_UNUSED
)
1015 assert(info
->pDepthStencilState
);
1017 if (subpass
&& subpass
->color_count
> 0)
1018 assert(info
->pColorBlendState
);
1020 for (uint32_t i
= 0; i
< info
->stageCount
; ++i
) {
1021 switch (info
->pStages
[i
].stage
) {
1022 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT
:
1023 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
:
1024 assert(info
->pTessellationState
);
1033 anv_pipeline_init(struct anv_pipeline
*pipeline
,
1034 struct anv_device
*device
,
1035 struct anv_pipeline_cache
*cache
,
1036 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1037 const struct anv_graphics_pipeline_create_info
*extra
,
1038 const VkAllocationCallbacks
*alloc
)
1043 anv_pipeline_validate_create_info(pCreateInfo
);
1047 alloc
= &device
->alloc
;
1049 pipeline
->device
= device
;
1050 pipeline
->layout
= anv_pipeline_layout_from_handle(pCreateInfo
->layout
);
1052 result
= anv_reloc_list_init(&pipeline
->batch_relocs
, alloc
);
1053 if (result
!= VK_SUCCESS
)
1056 pipeline
->batch
.alloc
= alloc
;
1057 pipeline
->batch
.next
= pipeline
->batch
.start
= pipeline
->batch_data
;
1058 pipeline
->batch
.end
= pipeline
->batch
.start
+ sizeof(pipeline
->batch_data
);
1059 pipeline
->batch
.relocs
= &pipeline
->batch_relocs
;
1061 anv_pipeline_init_dynamic_state(pipeline
, pCreateInfo
);
1063 if (pCreateInfo
->pTessellationState
)
1064 anv_finishme("VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO");
1065 if (pCreateInfo
->pMultisampleState
&&
1066 pCreateInfo
->pMultisampleState
->rasterizationSamples
> 1)
1067 anv_finishme("VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO");
1069 pipeline
->use_repclear
= extra
&& extra
->use_repclear
;
1070 pipeline
->writes_point_size
= false;
1072 /* When we free the pipeline, we detect stages based on the NULL status
1073 * of various prog_data pointers. Make them NULL by default.
1075 memset(pipeline
->prog_data
, 0, sizeof(pipeline
->prog_data
));
1076 memset(pipeline
->scratch_start
, 0, sizeof(pipeline
->scratch_start
));
1078 pipeline
->vs_simd8
= NO_KERNEL
;
1079 pipeline
->vs_vec4
= NO_KERNEL
;
1080 pipeline
->gs_kernel
= NO_KERNEL
;
1082 pipeline
->active_stages
= 0;
1083 pipeline
->total_scratch
= 0;
1085 for (uint32_t i
= 0; i
< pCreateInfo
->stageCount
; i
++) {
1086 ANV_FROM_HANDLE(anv_shader_module
, module
,
1087 pCreateInfo
->pStages
[i
].module
);
1089 switch (pCreateInfo
->pStages
[i
].stage
) {
1090 case VK_SHADER_STAGE_VERTEX_BIT
:
1091 anv_pipeline_compile_vs(pipeline
, cache
, pCreateInfo
, module
,
1092 pCreateInfo
->pStages
[i
].pName
,
1093 pCreateInfo
->pStages
[i
].pSpecializationInfo
);
1095 case VK_SHADER_STAGE_GEOMETRY_BIT
:
1096 anv_pipeline_compile_gs(pipeline
, cache
, pCreateInfo
, module
,
1097 pCreateInfo
->pStages
[i
].pName
,
1098 pCreateInfo
->pStages
[i
].pSpecializationInfo
);
1100 case VK_SHADER_STAGE_FRAGMENT_BIT
:
1101 anv_pipeline_compile_fs(pipeline
, cache
, pCreateInfo
, module
,
1102 pCreateInfo
->pStages
[i
].pName
,
1103 pCreateInfo
->pStages
[i
].pSpecializationInfo
);
1106 anv_finishme("Unsupported shader stage");
1110 if (!(pipeline
->active_stages
& VK_SHADER_STAGE_VERTEX_BIT
)) {
1111 /* Vertex is only optional if disable_vs is set */
1112 assert(extra
->disable_vs
);
1113 memset(&pipeline
->vs_prog_data
, 0, sizeof(pipeline
->vs_prog_data
));
1116 gen7_compute_urb_partition(pipeline
);
1118 const VkPipelineVertexInputStateCreateInfo
*vi_info
=
1119 pCreateInfo
->pVertexInputState
;
1121 uint64_t inputs_read
;
1122 if (extra
&& extra
->disable_vs
) {
1123 /* If the VS is disabled, just assume the user knows what they're
1124 * doing and apply the layout blindly. This can only come from
1125 * meta, so this *should* be safe.
1127 inputs_read
= ~0ull;
1129 inputs_read
= pipeline
->vs_prog_data
.inputs_read
;
1132 pipeline
->vb_used
= 0;
1133 for (uint32_t i
= 0; i
< vi_info
->vertexAttributeDescriptionCount
; i
++) {
1134 const VkVertexInputAttributeDescription
*desc
=
1135 &vi_info
->pVertexAttributeDescriptions
[i
];
1137 if (inputs_read
& (1 << (VERT_ATTRIB_GENERIC0
+ desc
->location
)))
1138 pipeline
->vb_used
|= 1 << desc
->binding
;
1141 for (uint32_t i
= 0; i
< vi_info
->vertexBindingDescriptionCount
; i
++) {
1142 const VkVertexInputBindingDescription
*desc
=
1143 &vi_info
->pVertexBindingDescriptions
[i
];
1145 pipeline
->binding_stride
[desc
->binding
] = desc
->stride
;
1147 /* Step rate is programmed per vertex element (attribute), not
1148 * binding. Set up a map of which bindings step per instance, for
1149 * reference by vertex element setup. */
1150 switch (desc
->inputRate
) {
1152 case VK_VERTEX_INPUT_RATE_VERTEX
:
1153 pipeline
->instancing_enable
[desc
->binding
] = false;
1155 case VK_VERTEX_INPUT_RATE_INSTANCE
:
1156 pipeline
->instancing_enable
[desc
->binding
] = true;
1161 const VkPipelineInputAssemblyStateCreateInfo
*ia_info
=
1162 pCreateInfo
->pInputAssemblyState
;
1163 pipeline
->primitive_restart
= ia_info
->primitiveRestartEnable
;
1164 pipeline
->topology
= vk_to_gen_primitive_type
[ia_info
->topology
];
1166 if (extra
&& extra
->use_rectlist
)
1167 pipeline
->topology
= _3DPRIM_RECTLIST
;
1173 anv_graphics_pipeline_create(
1175 VkPipelineCache _cache
,
1176 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1177 const struct anv_graphics_pipeline_create_info
*extra
,
1178 const VkAllocationCallbacks
*pAllocator
,
1179 VkPipeline
*pPipeline
)
1181 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1182 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
1185 cache
= &device
->default_pipeline_cache
;
1187 switch (device
->info
.gen
) {
1189 if (device
->info
.is_haswell
)
1190 return gen75_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1192 return gen7_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1194 return gen8_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1196 return gen9_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1198 unreachable("unsupported gen\n");
1202 VkResult
anv_CreateGraphicsPipelines(
1204 VkPipelineCache pipelineCache
,
1206 const VkGraphicsPipelineCreateInfo
* pCreateInfos
,
1207 const VkAllocationCallbacks
* pAllocator
,
1208 VkPipeline
* pPipelines
)
1210 VkResult result
= VK_SUCCESS
;
1213 for (; i
< count
; i
++) {
1214 result
= anv_graphics_pipeline_create(_device
,
1217 NULL
, pAllocator
, &pPipelines
[i
]);
1218 if (result
!= VK_SUCCESS
) {
1219 for (unsigned j
= 0; j
< i
; j
++) {
1220 anv_DestroyPipeline(_device
, pPipelines
[j
], pAllocator
);
1230 static VkResult
anv_compute_pipeline_create(
1232 VkPipelineCache _cache
,
1233 const VkComputePipelineCreateInfo
* pCreateInfo
,
1234 const VkAllocationCallbacks
* pAllocator
,
1235 VkPipeline
* pPipeline
)
1237 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1238 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
1241 cache
= &device
->default_pipeline_cache
;
1243 switch (device
->info
.gen
) {
1245 if (device
->info
.is_haswell
)
1246 return gen75_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1248 return gen7_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1250 return gen8_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1252 return gen9_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1254 unreachable("unsupported gen\n");
1258 VkResult
anv_CreateComputePipelines(
1260 VkPipelineCache pipelineCache
,
1262 const VkComputePipelineCreateInfo
* pCreateInfos
,
1263 const VkAllocationCallbacks
* pAllocator
,
1264 VkPipeline
* pPipelines
)
1266 VkResult result
= VK_SUCCESS
;
1269 for (; i
< count
; i
++) {
1270 result
= anv_compute_pipeline_create(_device
, pipelineCache
,
1272 pAllocator
, &pPipelines
[i
]);
1273 if (result
!= VK_SUCCESS
) {
1274 for (unsigned j
= 0; j
< i
; j
++) {
1275 anv_DestroyPipeline(_device
, pPipelines
[j
], pAllocator
);