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 const struct anv_graphics_pipeline_create_info
*extra
,
345 struct brw_wm_prog_key
*key
)
347 ANV_FROM_HANDLE(anv_render_pass
, render_pass
, info
->renderPass
);
349 memset(key
, 0, sizeof(*key
));
351 populate_sampler_prog_key(devinfo
, &key
->tex
);
353 /* TODO: Fill out key->input_slots_valid */
355 /* Vulkan doesn't specify a default */
356 key
->high_quality_derivatives
= false;
358 /* XXX Vulkan doesn't appear to specify */
359 key
->clamp_fragment_color
= false;
361 /* Vulkan always specifies upper-left coordinates */
362 key
->drawable_height
= 0;
363 key
->render_to_fbo
= false;
365 if (extra
&& extra
->color_attachment_count
>= 0) {
366 key
->nr_color_regions
= extra
->color_attachment_count
;
368 key
->nr_color_regions
=
369 render_pass
->subpasses
[info
->subpass
].color_count
;
372 key
->replicate_alpha
= key
->nr_color_regions
> 1 &&
373 info
->pMultisampleState
&&
374 info
->pMultisampleState
->alphaToCoverageEnable
;
376 if (info
->pMultisampleState
&& info
->pMultisampleState
->rasterizationSamples
> 1) {
377 /* We should probably pull this out of the shader, but it's fairly
378 * harmless to compute it and then let dead-code take care of it.
380 key
->persample_shading
= info
->pMultisampleState
->sampleShadingEnable
;
381 if (key
->persample_shading
)
382 key
->persample_2x
= info
->pMultisampleState
->rasterizationSamples
== 2;
384 key
->compute_pos_offset
= info
->pMultisampleState
->sampleShadingEnable
;
385 key
->compute_sample_id
= info
->pMultisampleState
->sampleShadingEnable
;
390 populate_cs_prog_key(const struct brw_device_info
*devinfo
,
391 struct brw_cs_prog_key
*key
)
393 memset(key
, 0, sizeof(*key
));
395 populate_sampler_prog_key(devinfo
, &key
->tex
);
399 anv_pipeline_compile(struct anv_pipeline
*pipeline
,
400 struct anv_shader_module
*module
,
401 const char *entrypoint
,
402 gl_shader_stage stage
,
403 const VkSpecializationInfo
*spec_info
,
404 struct brw_stage_prog_data
*prog_data
)
406 const struct brw_compiler
*compiler
=
407 pipeline
->device
->instance
->physicalDevice
.compiler
;
409 nir_shader
*nir
= anv_shader_compile_to_nir(pipeline
->device
,
410 module
, entrypoint
, stage
,
415 anv_nir_lower_push_constants(nir
, compiler
->scalar_stage
[stage
]);
417 /* Figure out the number of parameters */
418 prog_data
->nr_params
= 0;
420 if (nir
->num_uniforms
> 0) {
421 /* If the shader uses any push constants at all, we'll just give
422 * them the maximum possible number
424 prog_data
->nr_params
+= MAX_PUSH_CONSTANTS_SIZE
/ sizeof(float);
427 if (pipeline
->layout
&& pipeline
->layout
->stage
[stage
].has_dynamic_offsets
)
428 prog_data
->nr_params
+= MAX_DYNAMIC_BUFFERS
* 2;
430 if (pipeline
->layout
&& pipeline
->layout
->stage
[stage
].image_count
> 0)
431 prog_data
->nr_params
+= pipeline
->layout
->stage
[stage
].image_count
*
432 BRW_IMAGE_PARAM_SIZE
;
434 if (prog_data
->nr_params
> 0) {
435 /* XXX: I think we're leaking this */
436 prog_data
->param
= (const union gl_constant_value
**)
437 malloc(prog_data
->nr_params
* sizeof(union gl_constant_value
*));
439 /* We now set the param values to be offsets into a
440 * anv_push_constant_data structure. Since the compiler doesn't
441 * actually dereference any of the gl_constant_value pointers in the
442 * params array, it doesn't really matter what we put here.
444 struct anv_push_constants
*null_data
= NULL
;
445 if (nir
->num_uniforms
> 0) {
446 /* Fill out the push constants section of the param array */
447 for (unsigned i
= 0; i
< MAX_PUSH_CONSTANTS_SIZE
/ sizeof(float); i
++)
448 prog_data
->param
[i
] = (const union gl_constant_value
*)
449 &null_data
->client_data
[i
* sizeof(float)];
453 /* Set up dynamic offsets */
454 anv_nir_apply_dynamic_offsets(pipeline
, nir
, prog_data
);
456 /* Apply the actual pipeline layout to UBOs, SSBOs, and textures */
457 if (pipeline
->layout
)
458 anv_nir_apply_pipeline_layout(nir
, prog_data
, pipeline
->layout
);
460 /* All binding table offsets provided by apply_pipeline_layout() are
461 * relative to the start of the bindint table (plus MAX_RTS for VS).
465 case MESA_SHADER_FRAGMENT
:
468 case MESA_SHADER_COMPUTE
:
475 prog_data
->binding_table
.size_bytes
= 0;
476 prog_data
->binding_table
.texture_start
= bias
;
477 prog_data
->binding_table
.ubo_start
= bias
;
478 prog_data
->binding_table
.ssbo_start
= bias
;
479 prog_data
->binding_table
.image_start
= bias
;
481 /* Finish the optimization and compilation process */
482 nir
= brw_nir_lower_io(nir
, &pipeline
->device
->info
,
483 compiler
->scalar_stage
[stage
]);
485 /* nir_lower_io will only handle the push constants; we need to set this
486 * to the full number of possible uniforms.
488 nir
->num_uniforms
= prog_data
->nr_params
* 4;
494 anv_pipeline_add_compiled_stage(struct anv_pipeline
*pipeline
,
495 gl_shader_stage stage
,
496 struct brw_stage_prog_data
*prog_data
)
498 struct brw_device_info
*devinfo
= &pipeline
->device
->info
;
499 uint32_t max_threads
[] = {
500 [MESA_SHADER_VERTEX
] = devinfo
->max_vs_threads
,
501 [MESA_SHADER_TESS_CTRL
] = 0,
502 [MESA_SHADER_TESS_EVAL
] = 0,
503 [MESA_SHADER_GEOMETRY
] = devinfo
->max_gs_threads
,
504 [MESA_SHADER_FRAGMENT
] = devinfo
->max_wm_threads
,
505 [MESA_SHADER_COMPUTE
] = devinfo
->max_cs_threads
,
508 pipeline
->prog_data
[stage
] = prog_data
;
509 pipeline
->active_stages
|= mesa_to_vk_shader_stage(stage
);
510 pipeline
->scratch_start
[stage
] = pipeline
->total_scratch
;
511 pipeline
->total_scratch
=
512 align_u32(pipeline
->total_scratch
, 1024) +
513 prog_data
->total_scratch
* max_threads
[stage
];
517 anv_pipeline_compile_vs(struct anv_pipeline
*pipeline
,
518 struct anv_pipeline_cache
*cache
,
519 const VkGraphicsPipelineCreateInfo
*info
,
520 struct anv_shader_module
*module
,
521 const char *entrypoint
,
522 const VkSpecializationInfo
*spec_info
)
524 const struct brw_compiler
*compiler
=
525 pipeline
->device
->instance
->physicalDevice
.compiler
;
526 struct brw_vs_prog_data
*prog_data
= &pipeline
->vs_prog_data
;
527 struct brw_vs_prog_key key
;
529 populate_vs_prog_key(&pipeline
->device
->info
, &key
);
531 /* TODO: Look up shader in cache */
533 memset(prog_data
, 0, sizeof(*prog_data
));
535 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
536 MESA_SHADER_VERTEX
, spec_info
,
537 &prog_data
->base
.base
);
539 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
541 void *mem_ctx
= ralloc_context(NULL
);
543 if (module
->nir
== NULL
)
544 ralloc_steal(mem_ctx
, nir
);
546 prog_data
->inputs_read
= nir
->info
.inputs_read
;
547 if (nir
->info
.outputs_written
& (1ull << VARYING_SLOT_PSIZ
))
548 pipeline
->writes_point_size
= true;
550 brw_compute_vue_map(&pipeline
->device
->info
,
551 &prog_data
->base
.vue_map
,
552 nir
->info
.outputs_written
,
553 nir
->info
.separate_shader
);
556 const unsigned *shader_code
=
557 brw_compile_vs(compiler
, NULL
, mem_ctx
, &key
, prog_data
, nir
,
558 NULL
, false, -1, &code_size
, NULL
);
559 if (shader_code
== NULL
) {
560 ralloc_free(mem_ctx
);
561 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
564 const uint32_t offset
=
565 anv_pipeline_cache_upload_kernel(cache
, shader_code
, code_size
);
566 if (prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
) {
567 pipeline
->vs_simd8
= offset
;
568 pipeline
->vs_vec4
= NO_KERNEL
;
570 pipeline
->vs_simd8
= NO_KERNEL
;
571 pipeline
->vs_vec4
= offset
;
574 ralloc_free(mem_ctx
);
576 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_VERTEX
,
577 &prog_data
->base
.base
);
583 anv_pipeline_compile_gs(struct anv_pipeline
*pipeline
,
584 struct anv_pipeline_cache
*cache
,
585 const VkGraphicsPipelineCreateInfo
*info
,
586 struct anv_shader_module
*module
,
587 const char *entrypoint
,
588 const VkSpecializationInfo
*spec_info
)
590 const struct brw_compiler
*compiler
=
591 pipeline
->device
->instance
->physicalDevice
.compiler
;
592 struct brw_gs_prog_data
*prog_data
= &pipeline
->gs_prog_data
;
593 struct brw_gs_prog_key key
;
595 populate_gs_prog_key(&pipeline
->device
->info
, &key
);
597 /* TODO: Look up shader in cache */
599 memset(prog_data
, 0, sizeof(*prog_data
));
601 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
602 MESA_SHADER_GEOMETRY
, spec_info
,
603 &prog_data
->base
.base
);
605 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
607 void *mem_ctx
= ralloc_context(NULL
);
609 if (module
->nir
== NULL
)
610 ralloc_steal(mem_ctx
, nir
);
612 if (nir
->info
.outputs_written
& (1ull << VARYING_SLOT_PSIZ
))
613 pipeline
->writes_point_size
= true;
615 brw_compute_vue_map(&pipeline
->device
->info
,
616 &prog_data
->base
.vue_map
,
617 nir
->info
.outputs_written
,
618 nir
->info
.separate_shader
);
621 const unsigned *shader_code
=
622 brw_compile_gs(compiler
, NULL
, mem_ctx
, &key
, prog_data
, nir
,
623 NULL
, -1, &code_size
, NULL
);
624 if (shader_code
== NULL
) {
625 ralloc_free(mem_ctx
);
626 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
630 pipeline
->gs_kernel
=
631 anv_pipeline_cache_upload_kernel(cache
, shader_code
, code_size
);
632 pipeline
->gs_vertex_count
= nir
->info
.gs
.vertices_in
;
634 ralloc_free(mem_ctx
);
636 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_GEOMETRY
,
637 &prog_data
->base
.base
);
643 anv_pipeline_compile_fs(struct anv_pipeline
*pipeline
,
644 struct anv_pipeline_cache
*cache
,
645 const VkGraphicsPipelineCreateInfo
*info
,
646 const struct anv_graphics_pipeline_create_info
*extra
,
647 struct anv_shader_module
*module
,
648 const char *entrypoint
,
649 const VkSpecializationInfo
*spec_info
)
651 const struct brw_compiler
*compiler
=
652 pipeline
->device
->instance
->physicalDevice
.compiler
;
653 struct brw_wm_prog_data
*prog_data
= &pipeline
->wm_prog_data
;
654 struct brw_wm_prog_key key
;
656 populate_wm_prog_key(&pipeline
->device
->info
, info
, extra
, &key
);
658 if (pipeline
->use_repclear
)
659 key
.nr_color_regions
= 1;
661 /* TODO: Look up shader in cache */
663 memset(prog_data
, 0, sizeof(*prog_data
));
665 prog_data
->binding_table
.render_target_start
= 0;
667 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
668 MESA_SHADER_FRAGMENT
, spec_info
,
671 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
673 void *mem_ctx
= ralloc_context(NULL
);
675 if (module
->nir
== NULL
)
676 ralloc_steal(mem_ctx
, nir
);
679 const unsigned *shader_code
=
680 brw_compile_fs(compiler
, NULL
, mem_ctx
, &key
, prog_data
, nir
,
681 NULL
, -1, -1, pipeline
->use_repclear
, &code_size
, NULL
);
682 if (shader_code
== NULL
) {
683 ralloc_free(mem_ctx
);
684 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
688 anv_pipeline_cache_upload_kernel(cache
, shader_code
, code_size
);
690 pipeline
->ps_simd8
= NO_KERNEL
;
692 pipeline
->ps_simd8
= offset
;
694 if (prog_data
->no_8
|| prog_data
->prog_offset_16
) {
695 pipeline
->ps_simd16
= offset
+ prog_data
->prog_offset_16
;
697 pipeline
->ps_simd16
= NO_KERNEL
;
700 pipeline
->ps_ksp2
= 0;
701 pipeline
->ps_grf_start2
= 0;
702 if (pipeline
->ps_simd8
!= NO_KERNEL
) {
703 pipeline
->ps_ksp0
= pipeline
->ps_simd8
;
704 pipeline
->ps_grf_start0
= prog_data
->base
.dispatch_grf_start_reg
;
705 if (pipeline
->ps_simd16
!= NO_KERNEL
) {
706 pipeline
->ps_ksp2
= pipeline
->ps_simd16
;
707 pipeline
->ps_grf_start2
= prog_data
->dispatch_grf_start_reg_16
;
709 } else if (pipeline
->ps_simd16
!= NO_KERNEL
) {
710 pipeline
->ps_ksp0
= pipeline
->ps_simd16
;
711 pipeline
->ps_grf_start0
= prog_data
->dispatch_grf_start_reg_16
;
714 ralloc_free(mem_ctx
);
716 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_FRAGMENT
,
723 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
724 struct anv_pipeline_cache
*cache
,
725 const VkComputePipelineCreateInfo
*info
,
726 struct anv_shader_module
*module
,
727 const char *entrypoint
,
728 const VkSpecializationInfo
*spec_info
)
730 const struct brw_compiler
*compiler
=
731 pipeline
->device
->instance
->physicalDevice
.compiler
;
732 struct brw_cs_prog_data
*prog_data
= &pipeline
->cs_prog_data
;
733 struct brw_cs_prog_key key
;
735 populate_cs_prog_key(&pipeline
->device
->info
, &key
);
737 /* TODO: Look up shader in cache */
739 memset(prog_data
, 0, sizeof(*prog_data
));
741 prog_data
->binding_table
.work_groups_start
= 0;
743 nir_shader
*nir
= anv_pipeline_compile(pipeline
, module
, entrypoint
,
744 MESA_SHADER_COMPUTE
, spec_info
,
747 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
749 prog_data
->base
.total_shared
= nir
->num_shared
;
751 void *mem_ctx
= ralloc_context(NULL
);
753 if (module
->nir
== NULL
)
754 ralloc_steal(mem_ctx
, nir
);
757 const unsigned *shader_code
=
758 brw_compile_cs(compiler
, NULL
, mem_ctx
, &key
, prog_data
, nir
,
759 -1, &code_size
, NULL
);
760 if (shader_code
== NULL
) {
761 ralloc_free(mem_ctx
);
762 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
766 anv_pipeline_cache_upload_kernel(cache
, shader_code
, code_size
);
767 ralloc_free(mem_ctx
);
769 anv_pipeline_add_compiled_stage(pipeline
, MESA_SHADER_COMPUTE
,
775 static const int gen8_push_size
= 32 * 1024;
778 gen7_compute_urb_partition(struct anv_pipeline
*pipeline
)
780 const struct brw_device_info
*devinfo
= &pipeline
->device
->info
;
781 bool vs_present
= pipeline
->active_stages
& VK_SHADER_STAGE_VERTEX_BIT
;
782 unsigned vs_size
= vs_present
? pipeline
->vs_prog_data
.base
.urb_entry_size
: 1;
783 unsigned vs_entry_size_bytes
= vs_size
* 64;
784 bool gs_present
= pipeline
->active_stages
& VK_SHADER_STAGE_GEOMETRY_BIT
;
785 unsigned gs_size
= gs_present
? pipeline
->gs_prog_data
.base
.urb_entry_size
: 1;
786 unsigned gs_entry_size_bytes
= gs_size
* 64;
788 /* From p35 of the Ivy Bridge PRM (section 1.7.1: 3DSTATE_URB_GS):
790 * VS Number of URB Entries must be divisible by 8 if the VS URB Entry
791 * Allocation Size is less than 9 512-bit URB entries.
793 * Similar text exists for GS.
795 unsigned vs_granularity
= (vs_size
< 9) ? 8 : 1;
796 unsigned gs_granularity
= (gs_size
< 9) ? 8 : 1;
798 /* URB allocations must be done in 8k chunks. */
799 unsigned chunk_size_bytes
= 8192;
801 /* Determine the size of the URB in chunks. */
802 unsigned urb_chunks
= devinfo
->urb
.size
* 1024 / chunk_size_bytes
;
804 /* Reserve space for push constants */
805 unsigned push_constant_bytes
= gen8_push_size
;
806 unsigned push_constant_chunks
=
807 push_constant_bytes
/ chunk_size_bytes
;
809 /* Initially, assign each stage the minimum amount of URB space it needs,
810 * and make a note of how much additional space it "wants" (the amount of
811 * additional space it could actually make use of).
814 /* VS has a lower limit on the number of URB entries */
816 ALIGN(devinfo
->urb
.min_vs_entries
* vs_entry_size_bytes
,
817 chunk_size_bytes
) / chunk_size_bytes
;
819 ALIGN(devinfo
->urb
.max_vs_entries
* vs_entry_size_bytes
,
820 chunk_size_bytes
) / chunk_size_bytes
- vs_chunks
;
822 unsigned gs_chunks
= 0;
823 unsigned gs_wants
= 0;
825 /* There are two constraints on the minimum amount of URB space we can
828 * (1) We need room for at least 2 URB entries, since we always operate
829 * the GS in DUAL_OBJECT mode.
831 * (2) We can't allocate less than nr_gs_entries_granularity.
833 gs_chunks
= ALIGN(MAX2(gs_granularity
, 2) * gs_entry_size_bytes
,
834 chunk_size_bytes
) / chunk_size_bytes
;
836 ALIGN(devinfo
->urb
.max_gs_entries
* gs_entry_size_bytes
,
837 chunk_size_bytes
) / chunk_size_bytes
- gs_chunks
;
840 /* There should always be enough URB space to satisfy the minimum
841 * requirements of each stage.
843 unsigned total_needs
= push_constant_chunks
+ vs_chunks
+ gs_chunks
;
844 assert(total_needs
<= urb_chunks
);
846 /* Mete out remaining space (if any) in proportion to "wants". */
847 unsigned total_wants
= vs_wants
+ gs_wants
;
848 unsigned remaining_space
= urb_chunks
- total_needs
;
849 if (remaining_space
> total_wants
)
850 remaining_space
= total_wants
;
851 if (remaining_space
> 0) {
852 unsigned vs_additional
= (unsigned)
853 round(vs_wants
* (((double) remaining_space
) / total_wants
));
854 vs_chunks
+= vs_additional
;
855 remaining_space
-= vs_additional
;
856 gs_chunks
+= remaining_space
;
859 /* Sanity check that we haven't over-allocated. */
860 assert(push_constant_chunks
+ vs_chunks
+ gs_chunks
<= urb_chunks
);
862 /* Finally, compute the number of entries that can fit in the space
863 * allocated to each stage.
865 unsigned nr_vs_entries
= vs_chunks
* chunk_size_bytes
/ vs_entry_size_bytes
;
866 unsigned nr_gs_entries
= gs_chunks
* chunk_size_bytes
/ gs_entry_size_bytes
;
868 /* Since we rounded up when computing *_wants, this may be slightly more
869 * than the maximum allowed amount, so correct for that.
871 nr_vs_entries
= MIN2(nr_vs_entries
, devinfo
->urb
.max_vs_entries
);
872 nr_gs_entries
= MIN2(nr_gs_entries
, devinfo
->urb
.max_gs_entries
);
874 /* Ensure that we program a multiple of the granularity. */
875 nr_vs_entries
= ROUND_DOWN_TO(nr_vs_entries
, vs_granularity
);
876 nr_gs_entries
= ROUND_DOWN_TO(nr_gs_entries
, gs_granularity
);
878 /* Finally, sanity check to make sure we have at least the minimum number
879 * of entries needed for each stage.
881 assert(nr_vs_entries
>= devinfo
->urb
.min_vs_entries
);
883 assert(nr_gs_entries
>= 2);
885 /* Lay out the URB in the following order:
890 pipeline
->urb
.vs_start
= push_constant_chunks
;
891 pipeline
->urb
.vs_size
= vs_size
;
892 pipeline
->urb
.nr_vs_entries
= nr_vs_entries
;
894 pipeline
->urb
.gs_start
= push_constant_chunks
+ vs_chunks
;
895 pipeline
->urb
.gs_size
= gs_size
;
896 pipeline
->urb
.nr_gs_entries
= nr_gs_entries
;
900 anv_pipeline_init_dynamic_state(struct anv_pipeline
*pipeline
,
901 const VkGraphicsPipelineCreateInfo
*pCreateInfo
)
903 anv_cmd_dirty_mask_t states
= ANV_CMD_DIRTY_DYNAMIC_ALL
;
904 ANV_FROM_HANDLE(anv_render_pass
, pass
, pCreateInfo
->renderPass
);
905 struct anv_subpass
*subpass
= &pass
->subpasses
[pCreateInfo
->subpass
];
907 pipeline
->dynamic_state
= default_dynamic_state
;
909 if (pCreateInfo
->pDynamicState
) {
910 /* Remove all of the states that are marked as dynamic */
911 uint32_t count
= pCreateInfo
->pDynamicState
->dynamicStateCount
;
912 for (uint32_t s
= 0; s
< count
; s
++)
913 states
&= ~(1 << pCreateInfo
->pDynamicState
->pDynamicStates
[s
]);
916 struct anv_dynamic_state
*dynamic
= &pipeline
->dynamic_state
;
918 dynamic
->viewport
.count
= pCreateInfo
->pViewportState
->viewportCount
;
919 if (states
& (1 << VK_DYNAMIC_STATE_VIEWPORT
)) {
920 typed_memcpy(dynamic
->viewport
.viewports
,
921 pCreateInfo
->pViewportState
->pViewports
,
922 pCreateInfo
->pViewportState
->viewportCount
);
925 dynamic
->scissor
.count
= pCreateInfo
->pViewportState
->scissorCount
;
926 if (states
& (1 << VK_DYNAMIC_STATE_SCISSOR
)) {
927 typed_memcpy(dynamic
->scissor
.scissors
,
928 pCreateInfo
->pViewportState
->pScissors
,
929 pCreateInfo
->pViewportState
->scissorCount
);
932 if (states
& (1 << VK_DYNAMIC_STATE_LINE_WIDTH
)) {
933 assert(pCreateInfo
->pRasterizationState
);
934 dynamic
->line_width
= pCreateInfo
->pRasterizationState
->lineWidth
;
937 if (states
& (1 << VK_DYNAMIC_STATE_DEPTH_BIAS
)) {
938 assert(pCreateInfo
->pRasterizationState
);
939 dynamic
->depth_bias
.bias
=
940 pCreateInfo
->pRasterizationState
->depthBiasConstantFactor
;
941 dynamic
->depth_bias
.clamp
=
942 pCreateInfo
->pRasterizationState
->depthBiasClamp
;
943 dynamic
->depth_bias
.slope
=
944 pCreateInfo
->pRasterizationState
->depthBiasSlopeFactor
;
947 if (states
& (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS
)) {
948 assert(pCreateInfo
->pColorBlendState
);
949 typed_memcpy(dynamic
->blend_constants
,
950 pCreateInfo
->pColorBlendState
->blendConstants
, 4);
953 /* If there is no depthstencil attachment, then don't read
954 * pDepthStencilState. The Vulkan spec states that pDepthStencilState may
955 * be NULL in this case. Even if pDepthStencilState is non-NULL, there is
956 * no need to override the depthstencil defaults in
957 * anv_pipeline::dynamic_state when there is no depthstencil attachment.
959 * From the Vulkan spec (20 Oct 2015, git-aa308cb):
961 * pDepthStencilState [...] may only be NULL if renderPass and subpass
962 * specify a subpass that has no depth/stencil attachment.
964 if (subpass
->depth_stencil_attachment
!= VK_ATTACHMENT_UNUSED
) {
965 if (states
& (1 << VK_DYNAMIC_STATE_DEPTH_BOUNDS
)) {
966 assert(pCreateInfo
->pDepthStencilState
);
967 dynamic
->depth_bounds
.min
=
968 pCreateInfo
->pDepthStencilState
->minDepthBounds
;
969 dynamic
->depth_bounds
.max
=
970 pCreateInfo
->pDepthStencilState
->maxDepthBounds
;
973 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
)) {
974 assert(pCreateInfo
->pDepthStencilState
);
975 dynamic
->stencil_compare_mask
.front
=
976 pCreateInfo
->pDepthStencilState
->front
.compareMask
;
977 dynamic
->stencil_compare_mask
.back
=
978 pCreateInfo
->pDepthStencilState
->back
.compareMask
;
981 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
)) {
982 assert(pCreateInfo
->pDepthStencilState
);
983 dynamic
->stencil_write_mask
.front
=
984 pCreateInfo
->pDepthStencilState
->front
.writeMask
;
985 dynamic
->stencil_write_mask
.back
=
986 pCreateInfo
->pDepthStencilState
->back
.writeMask
;
989 if (states
& (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE
)) {
990 assert(pCreateInfo
->pDepthStencilState
);
991 dynamic
->stencil_reference
.front
=
992 pCreateInfo
->pDepthStencilState
->front
.reference
;
993 dynamic
->stencil_reference
.back
=
994 pCreateInfo
->pDepthStencilState
->back
.reference
;
998 pipeline
->dynamic_state_mask
= states
;
1002 anv_pipeline_validate_create_info(const VkGraphicsPipelineCreateInfo
*info
)
1004 struct anv_render_pass
*renderpass
= NULL
;
1005 struct anv_subpass
*subpass
= NULL
;
1007 /* Assert that all required members of VkGraphicsPipelineCreateInfo are
1008 * present, as explained by the Vulkan (20 Oct 2015, git-aa308cb), Section
1009 * 4.2 Graphics Pipeline.
1011 assert(info
->sType
== VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
);
1013 renderpass
= anv_render_pass_from_handle(info
->renderPass
);
1016 if (renderpass
!= &anv_meta_dummy_renderpass
) {
1017 assert(info
->subpass
< renderpass
->subpass_count
);
1018 subpass
= &renderpass
->subpasses
[info
->subpass
];
1021 assert(info
->stageCount
>= 1);
1022 assert(info
->pVertexInputState
);
1023 assert(info
->pInputAssemblyState
);
1024 assert(info
->pViewportState
);
1025 assert(info
->pRasterizationState
);
1027 if (subpass
&& subpass
->depth_stencil_attachment
!= VK_ATTACHMENT_UNUSED
)
1028 assert(info
->pDepthStencilState
);
1030 if (subpass
&& subpass
->color_count
> 0)
1031 assert(info
->pColorBlendState
);
1033 for (uint32_t i
= 0; i
< info
->stageCount
; ++i
) {
1034 switch (info
->pStages
[i
].stage
) {
1035 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT
:
1036 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
:
1037 assert(info
->pTessellationState
);
1046 anv_pipeline_init(struct anv_pipeline
*pipeline
,
1047 struct anv_device
*device
,
1048 struct anv_pipeline_cache
*cache
,
1049 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1050 const struct anv_graphics_pipeline_create_info
*extra
,
1051 const VkAllocationCallbacks
*alloc
)
1056 anv_pipeline_validate_create_info(pCreateInfo
);
1060 alloc
= &device
->alloc
;
1062 pipeline
->device
= device
;
1063 pipeline
->layout
= anv_pipeline_layout_from_handle(pCreateInfo
->layout
);
1065 result
= anv_reloc_list_init(&pipeline
->batch_relocs
, alloc
);
1066 if (result
!= VK_SUCCESS
)
1069 pipeline
->batch
.alloc
= alloc
;
1070 pipeline
->batch
.next
= pipeline
->batch
.start
= pipeline
->batch_data
;
1071 pipeline
->batch
.end
= pipeline
->batch
.start
+ sizeof(pipeline
->batch_data
);
1072 pipeline
->batch
.relocs
= &pipeline
->batch_relocs
;
1074 anv_pipeline_init_dynamic_state(pipeline
, pCreateInfo
);
1076 if (pCreateInfo
->pTessellationState
)
1077 anv_finishme("VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO");
1078 if (pCreateInfo
->pMultisampleState
&&
1079 pCreateInfo
->pMultisampleState
->rasterizationSamples
> 1)
1080 anv_finishme("VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO");
1082 pipeline
->use_repclear
= extra
&& extra
->use_repclear
;
1083 pipeline
->writes_point_size
= false;
1085 /* When we free the pipeline, we detect stages based on the NULL status
1086 * of various prog_data pointers. Make them NULL by default.
1088 memset(pipeline
->prog_data
, 0, sizeof(pipeline
->prog_data
));
1089 memset(pipeline
->scratch_start
, 0, sizeof(pipeline
->scratch_start
));
1091 pipeline
->vs_simd8
= NO_KERNEL
;
1092 pipeline
->vs_vec4
= NO_KERNEL
;
1093 pipeline
->gs_kernel
= NO_KERNEL
;
1095 pipeline
->active_stages
= 0;
1096 pipeline
->total_scratch
= 0;
1098 for (uint32_t i
= 0; i
< pCreateInfo
->stageCount
; i
++) {
1099 ANV_FROM_HANDLE(anv_shader_module
, module
,
1100 pCreateInfo
->pStages
[i
].module
);
1102 switch (pCreateInfo
->pStages
[i
].stage
) {
1103 case VK_SHADER_STAGE_VERTEX_BIT
:
1104 anv_pipeline_compile_vs(pipeline
, cache
, pCreateInfo
, module
,
1105 pCreateInfo
->pStages
[i
].pName
,
1106 pCreateInfo
->pStages
[i
].pSpecializationInfo
);
1108 case VK_SHADER_STAGE_GEOMETRY_BIT
:
1109 anv_pipeline_compile_gs(pipeline
, cache
, pCreateInfo
, module
,
1110 pCreateInfo
->pStages
[i
].pName
,
1111 pCreateInfo
->pStages
[i
].pSpecializationInfo
);
1113 case VK_SHADER_STAGE_FRAGMENT_BIT
:
1114 anv_pipeline_compile_fs(pipeline
, cache
, pCreateInfo
, extra
, module
,
1115 pCreateInfo
->pStages
[i
].pName
,
1116 pCreateInfo
->pStages
[i
].pSpecializationInfo
);
1119 anv_finishme("Unsupported shader stage");
1123 if (!(pipeline
->active_stages
& VK_SHADER_STAGE_VERTEX_BIT
)) {
1124 /* Vertex is only optional if disable_vs is set */
1125 assert(extra
->disable_vs
);
1126 memset(&pipeline
->vs_prog_data
, 0, sizeof(pipeline
->vs_prog_data
));
1129 gen7_compute_urb_partition(pipeline
);
1131 const VkPipelineVertexInputStateCreateInfo
*vi_info
=
1132 pCreateInfo
->pVertexInputState
;
1134 uint64_t inputs_read
;
1135 if (extra
&& extra
->disable_vs
) {
1136 /* If the VS is disabled, just assume the user knows what they're
1137 * doing and apply the layout blindly. This can only come from
1138 * meta, so this *should* be safe.
1140 inputs_read
= ~0ull;
1142 inputs_read
= pipeline
->vs_prog_data
.inputs_read
;
1145 pipeline
->vb_used
= 0;
1146 for (uint32_t i
= 0; i
< vi_info
->vertexAttributeDescriptionCount
; i
++) {
1147 const VkVertexInputAttributeDescription
*desc
=
1148 &vi_info
->pVertexAttributeDescriptions
[i
];
1150 if (inputs_read
& (1 << (VERT_ATTRIB_GENERIC0
+ desc
->location
)))
1151 pipeline
->vb_used
|= 1 << desc
->binding
;
1154 for (uint32_t i
= 0; i
< vi_info
->vertexBindingDescriptionCount
; i
++) {
1155 const VkVertexInputBindingDescription
*desc
=
1156 &vi_info
->pVertexBindingDescriptions
[i
];
1158 pipeline
->binding_stride
[desc
->binding
] = desc
->stride
;
1160 /* Step rate is programmed per vertex element (attribute), not
1161 * binding. Set up a map of which bindings step per instance, for
1162 * reference by vertex element setup. */
1163 switch (desc
->inputRate
) {
1165 case VK_VERTEX_INPUT_RATE_VERTEX
:
1166 pipeline
->instancing_enable
[desc
->binding
] = false;
1168 case VK_VERTEX_INPUT_RATE_INSTANCE
:
1169 pipeline
->instancing_enable
[desc
->binding
] = true;
1174 const VkPipelineInputAssemblyStateCreateInfo
*ia_info
=
1175 pCreateInfo
->pInputAssemblyState
;
1176 pipeline
->primitive_restart
= ia_info
->primitiveRestartEnable
;
1177 pipeline
->topology
= vk_to_gen_primitive_type
[ia_info
->topology
];
1179 if (extra
&& extra
->use_rectlist
)
1180 pipeline
->topology
= _3DPRIM_RECTLIST
;
1186 anv_graphics_pipeline_create(
1188 VkPipelineCache _cache
,
1189 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1190 const struct anv_graphics_pipeline_create_info
*extra
,
1191 const VkAllocationCallbacks
*pAllocator
,
1192 VkPipeline
*pPipeline
)
1194 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1195 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
1198 cache
= &device
->default_pipeline_cache
;
1200 switch (device
->info
.gen
) {
1202 if (device
->info
.is_haswell
)
1203 return gen75_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1205 return gen7_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1207 return gen8_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1209 return gen9_graphics_pipeline_create(_device
, cache
, pCreateInfo
, extra
, pAllocator
, pPipeline
);
1211 unreachable("unsupported gen\n");
1215 VkResult
anv_CreateGraphicsPipelines(
1217 VkPipelineCache pipelineCache
,
1219 const VkGraphicsPipelineCreateInfo
* pCreateInfos
,
1220 const VkAllocationCallbacks
* pAllocator
,
1221 VkPipeline
* pPipelines
)
1223 VkResult result
= VK_SUCCESS
;
1226 for (; i
< count
; i
++) {
1227 result
= anv_graphics_pipeline_create(_device
,
1230 NULL
, pAllocator
, &pPipelines
[i
]);
1231 if (result
!= VK_SUCCESS
) {
1232 for (unsigned j
= 0; j
< i
; j
++) {
1233 anv_DestroyPipeline(_device
, pPipelines
[j
], pAllocator
);
1243 static VkResult
anv_compute_pipeline_create(
1245 VkPipelineCache _cache
,
1246 const VkComputePipelineCreateInfo
* pCreateInfo
,
1247 const VkAllocationCallbacks
* pAllocator
,
1248 VkPipeline
* pPipeline
)
1250 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1251 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
1254 cache
= &device
->default_pipeline_cache
;
1256 switch (device
->info
.gen
) {
1258 if (device
->info
.is_haswell
)
1259 return gen75_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1261 return gen7_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1263 return gen8_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1265 return gen9_compute_pipeline_create(_device
, cache
, pCreateInfo
, pAllocator
, pPipeline
);
1267 unreachable("unsupported gen\n");
1271 VkResult
anv_CreateComputePipelines(
1273 VkPipelineCache pipelineCache
,
1275 const VkComputePipelineCreateInfo
* pCreateInfos
,
1276 const VkAllocationCallbacks
* pAllocator
,
1277 VkPipeline
* pPipelines
)
1279 VkResult result
= VK_SUCCESS
;
1282 for (; i
< count
; i
++) {
1283 result
= anv_compute_pipeline_create(_device
, pipelineCache
,
1285 pAllocator
, &pPipelines
[i
]);
1286 if (result
!= VK_SUCCESS
) {
1287 for (unsigned j
= 0; j
< i
; j
++) {
1288 anv_DestroyPipeline(_device
, pPipelines
[j
], pAllocator
);