anv/pipeline: Validate VkGraphicsPipelineCreateInfo
[mesa.git] / src / vulkan / anv_pipeline.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29
30 #include "anv_private.h"
31
32 // Shader functions
33
34 VkResult anv_CreateShaderModule(
35 VkDevice _device,
36 const VkShaderModuleCreateInfo* pCreateInfo,
37 VkShaderModule* pShaderModule)
38 {
39 ANV_FROM_HANDLE(anv_device, device, _device);
40 struct anv_shader_module *module;
41
42 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
43 assert(pCreateInfo->flags == 0);
44
45 module = anv_device_alloc(device, sizeof(*module) + pCreateInfo->codeSize, 8,
46 VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
47 if (module == NULL)
48 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
49
50 module->nir = NULL;
51 module->size = pCreateInfo->codeSize;
52 memcpy(module->data, pCreateInfo->pCode, module->size);
53
54 *pShaderModule = anv_shader_module_to_handle(module);
55
56 return VK_SUCCESS;
57 }
58
59 void anv_DestroyShaderModule(
60 VkDevice _device,
61 VkShaderModule _module)
62 {
63 ANV_FROM_HANDLE(anv_device, device, _device);
64 ANV_FROM_HANDLE(anv_shader_module, module, _module);
65
66 anv_device_free(device, module);
67 }
68
69 VkResult anv_CreateShader(
70 VkDevice _device,
71 const VkShaderCreateInfo* pCreateInfo,
72 VkShader* pShader)
73 {
74 ANV_FROM_HANDLE(anv_device, device, _device);
75 ANV_FROM_HANDLE(anv_shader_module, module, pCreateInfo->module);
76 struct anv_shader *shader;
77
78 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_CREATE_INFO);
79 assert(pCreateInfo->flags == 0);
80
81 const char *name = pCreateInfo->pName ? pCreateInfo->pName : "main";
82 size_t name_len = strlen(name);
83
84 if (strcmp(name, "main") != 0) {
85 anv_finishme("Multiple shaders per module not really supported");
86 }
87
88 shader = anv_device_alloc(device, sizeof(*shader) + name_len + 1, 8,
89 VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
90 if (shader == NULL)
91 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
92
93 shader->module = module;
94 memcpy(shader->entrypoint, name, name_len + 1);
95
96 *pShader = anv_shader_to_handle(shader);
97
98 return VK_SUCCESS;
99 }
100
101 void anv_DestroyShader(
102 VkDevice _device,
103 VkShader _shader)
104 {
105 ANV_FROM_HANDLE(anv_device, device, _device);
106 ANV_FROM_HANDLE(anv_shader, shader, _shader);
107
108 anv_device_free(device, shader);
109 }
110
111
112 VkResult anv_CreatePipelineCache(
113 VkDevice device,
114 const VkPipelineCacheCreateInfo* pCreateInfo,
115 VkPipelineCache* pPipelineCache)
116 {
117 pPipelineCache->handle = 1;
118
119 stub_return(VK_SUCCESS);
120 }
121
122 void anv_DestroyPipelineCache(
123 VkDevice _device,
124 VkPipelineCache _cache)
125 {
126 }
127
128 size_t anv_GetPipelineCacheSize(
129 VkDevice device,
130 VkPipelineCache pipelineCache)
131 {
132 stub_return(0);
133 }
134
135 VkResult anv_GetPipelineCacheData(
136 VkDevice device,
137 VkPipelineCache pipelineCache,
138 void* pData)
139 {
140 stub_return(VK_UNSUPPORTED);
141 }
142
143 VkResult anv_MergePipelineCaches(
144 VkDevice device,
145 VkPipelineCache destCache,
146 uint32_t srcCacheCount,
147 const VkPipelineCache* pSrcCaches)
148 {
149 stub_return(VK_UNSUPPORTED);
150 }
151
152 void anv_DestroyPipeline(
153 VkDevice _device,
154 VkPipeline _pipeline)
155 {
156 ANV_FROM_HANDLE(anv_device, device, _device);
157 ANV_FROM_HANDLE(anv_pipeline, pipeline, _pipeline);
158
159 anv_compiler_free(pipeline);
160 anv_reloc_list_finish(&pipeline->batch_relocs, pipeline->device);
161 anv_state_stream_finish(&pipeline->program_stream);
162 anv_state_pool_free(&device->dynamic_state_pool, pipeline->blend_state);
163 anv_device_free(pipeline->device, pipeline);
164 }
165
166 static const uint32_t vk_to_gen_primitive_type[] = {
167 [VK_PRIMITIVE_TOPOLOGY_POINT_LIST] = _3DPRIM_POINTLIST,
168 [VK_PRIMITIVE_TOPOLOGY_LINE_LIST] = _3DPRIM_LINELIST,
169 [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP] = _3DPRIM_LINESTRIP,
170 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST] = _3DPRIM_TRILIST,
171 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP] = _3DPRIM_TRISTRIP,
172 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN] = _3DPRIM_TRIFAN,
173 [VK_PRIMITIVE_TOPOLOGY_LINE_LIST_ADJ] = _3DPRIM_LINELIST_ADJ,
174 [VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_ADJ] = _3DPRIM_LINESTRIP_ADJ,
175 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_ADJ] = _3DPRIM_TRILIST_ADJ,
176 [VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_ADJ] = _3DPRIM_TRISTRIP_ADJ,
177 [VK_PRIMITIVE_TOPOLOGY_PATCH] = _3DPRIM_PATCHLIST_1
178 };
179
180 static void
181 anv_pipeline_init_dynamic_state(struct anv_pipeline *pipeline,
182 const VkGraphicsPipelineCreateInfo *pCreateInfo)
183 {
184 uint32_t states = ANV_DYNAMIC_STATE_DIRTY_MASK;
185
186 if (pCreateInfo->pDynamicState) {
187 /* Remove all of the states that are marked as dynamic */
188 uint32_t count = pCreateInfo->pDynamicState->dynamicStateCount;
189 for (uint32_t s = 0; s < count; s++)
190 states &= ~(1 << pCreateInfo->pDynamicState->pDynamicStates[s]);
191 }
192
193 struct anv_dynamic_state *dynamic = &pipeline->dynamic_state;
194
195 dynamic->viewport.count = pCreateInfo->pViewportState->viewportCount;
196 if (states & (1 << VK_DYNAMIC_STATE_VIEWPORT)) {
197 typed_memcpy(dynamic->viewport.viewports,
198 pCreateInfo->pViewportState->pViewports,
199 pCreateInfo->pViewportState->viewportCount);
200 }
201
202 dynamic->scissor.count = pCreateInfo->pViewportState->scissorCount;
203 if (states & (1 << VK_DYNAMIC_STATE_SCISSOR)) {
204 typed_memcpy(dynamic->scissor.scissors,
205 pCreateInfo->pViewportState->pScissors,
206 pCreateInfo->pViewportState->scissorCount);
207 }
208
209 if (states & (1 << VK_DYNAMIC_STATE_LINE_WIDTH)) {
210 assert(pCreateInfo->pRasterState);
211 dynamic->line_width = pCreateInfo->pRasterState->lineWidth;
212 }
213
214 if (states & (1 << VK_DYNAMIC_STATE_DEPTH_BIAS)) {
215 assert(pCreateInfo->pRasterState);
216 dynamic->depth_bias.bias = pCreateInfo->pRasterState->depthBias;
217 dynamic->depth_bias.clamp = pCreateInfo->pRasterState->depthBiasClamp;
218 dynamic->depth_bias.slope_scaled =
219 pCreateInfo->pRasterState->slopeScaledDepthBias;
220 }
221
222 if (states & (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS)) {
223 assert(pCreateInfo->pColorBlendState);
224 typed_memcpy(dynamic->blend_constants,
225 pCreateInfo->pColorBlendState->blendConst, 4);
226 }
227
228 if (states & (1 << VK_DYNAMIC_STATE_DEPTH_BOUNDS)) {
229 assert(pCreateInfo->pDepthStencilState);
230 dynamic->depth_bounds.min =
231 pCreateInfo->pDepthStencilState->minDepthBounds;
232 dynamic->depth_bounds.max =
233 pCreateInfo->pDepthStencilState->maxDepthBounds;
234 }
235
236 if (states & (1 << VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK)) {
237 assert(pCreateInfo->pDepthStencilState);
238 dynamic->stencil_compare_mask.front =
239 pCreateInfo->pDepthStencilState->front.stencilCompareMask;
240 dynamic->stencil_compare_mask.back =
241 pCreateInfo->pDepthStencilState->back.stencilCompareMask;
242 }
243
244 if (states & (1 << VK_DYNAMIC_STATE_STENCIL_WRITE_MASK)) {
245 assert(pCreateInfo->pDepthStencilState);
246 dynamic->stencil_write_mask.front =
247 pCreateInfo->pDepthStencilState->front.stencilWriteMask;
248 dynamic->stencil_write_mask.back =
249 pCreateInfo->pDepthStencilState->back.stencilWriteMask;
250 }
251
252 if (states & (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE)) {
253 assert(pCreateInfo->pDepthStencilState);
254 dynamic->stencil_reference.front =
255 pCreateInfo->pDepthStencilState->front.stencilReference;
256 dynamic->stencil_reference.back =
257 pCreateInfo->pDepthStencilState->back.stencilReference;
258 }
259
260 pipeline->dynamic_state_mask = states;
261 }
262
263 static void
264 anv_pipeline_validate_create_info(const VkGraphicsPipelineCreateInfo *info)
265 {
266 struct anv_render_pass *renderpass = NULL;
267 struct anv_subpass *subpass = NULL;
268
269 /* Assert that all required members of VkGraphicsPipelineCreateInfo are
270 * present, as explained by the Vulkan (20 Oct 2015, git-aa308cb), Section
271 * 4.2 Graphics Pipeline.
272 */
273 assert(info->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
274
275 renderpass = anv_render_pass_from_handle(info->renderPass);
276 assert(renderpass);
277
278 if (renderpass != &anv_meta_dummy_renderpass) {
279 assert(info->subpass < renderpass->subpass_count);
280 subpass = &renderpass->subpasses[info->subpass];
281 }
282
283 assert(info->stageCount >= 1);
284 assert(info->pVertexInputState);
285 assert(info->pInputAssemblyState);
286 assert(info->pViewportState);
287 assert(info->pRasterState);
288 assert(info->pMultisampleState);
289
290 if (subpass && subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED)
291 assert(info->pDepthStencilState);
292
293 if (subpass && subpass->color_count > 0)
294 assert(info->pColorBlendState);
295
296 for (uint32_t i = 0; i < info->stageCount; ++i) {
297 switch (info->pStages[i].stage) {
298 case VK_SHADER_STAGE_TESS_CONTROL:
299 case VK_SHADER_STAGE_TESS_EVALUATION:
300 assert(info->pTessellationState);
301 break;
302 default:
303 break;
304 }
305 }
306 }
307
308 VkResult
309 anv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device,
310 const VkGraphicsPipelineCreateInfo *pCreateInfo,
311 const struct anv_graphics_pipeline_create_info *extra)
312 {
313 VkResult result;
314
315 anv_validate {
316 anv_pipeline_validate_create_info(pCreateInfo);
317 }
318
319 pipeline->device = device;
320 pipeline->layout = anv_pipeline_layout_from_handle(pCreateInfo->layout);
321 memset(pipeline->shaders, 0, sizeof(pipeline->shaders));
322
323 result = anv_reloc_list_init(&pipeline->batch_relocs, device);
324 if (result != VK_SUCCESS) {
325 anv_device_free(device, pipeline);
326 return result;
327 }
328 pipeline->batch.next = pipeline->batch.start = pipeline->batch_data;
329 pipeline->batch.end = pipeline->batch.start + sizeof(pipeline->batch_data);
330 pipeline->batch.relocs = &pipeline->batch_relocs;
331
332 anv_state_stream_init(&pipeline->program_stream,
333 &device->instruction_block_pool);
334
335 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
336 pipeline->shaders[pCreateInfo->pStages[i].stage] =
337 anv_shader_from_handle(pCreateInfo->pStages[i].shader);
338 }
339
340 anv_pipeline_init_dynamic_state(pipeline, pCreateInfo);
341
342 if (pCreateInfo->pTessellationState)
343 anv_finishme("VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO");
344 if (pCreateInfo->pMultisampleState &&
345 pCreateInfo->pMultisampleState->rasterSamples > 1)
346 anv_finishme("VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO");
347
348 pipeline->use_repclear = extra && extra->use_repclear;
349
350 anv_compiler_run(device->compiler, pipeline);
351
352 const struct brw_wm_prog_data *wm_prog_data = &pipeline->wm_prog_data;
353
354 pipeline->ps_ksp2 = 0;
355 pipeline->ps_grf_start2 = 0;
356 if (pipeline->ps_simd8 != NO_KERNEL) {
357 pipeline->ps_ksp0 = pipeline->ps_simd8;
358 pipeline->ps_grf_start0 = wm_prog_data->base.dispatch_grf_start_reg;
359 if (pipeline->ps_simd16 != NO_KERNEL) {
360 pipeline->ps_ksp2 = pipeline->ps_simd16;
361 pipeline->ps_grf_start2 = wm_prog_data->dispatch_grf_start_reg_16;
362 }
363 } else if (pipeline->ps_simd16 != NO_KERNEL) {
364 pipeline->ps_ksp0 = pipeline->ps_simd16;
365 pipeline->ps_grf_start0 = wm_prog_data->dispatch_grf_start_reg_16;
366 } else {
367 unreachable("no ps shader");
368 }
369
370 const VkPipelineVertexInputStateCreateInfo *vi_info =
371 pCreateInfo->pVertexInputState;
372 pipeline->vb_used = 0;
373 for (uint32_t i = 0; i < vi_info->bindingCount; i++) {
374 const VkVertexInputBindingDescription *desc =
375 &vi_info->pVertexBindingDescriptions[i];
376
377 pipeline->vb_used |= 1 << desc->binding;
378 pipeline->binding_stride[desc->binding] = desc->strideInBytes;
379
380 /* Step rate is programmed per vertex element (attribute), not
381 * binding. Set up a map of which bindings step per instance, for
382 * reference by vertex element setup. */
383 switch (desc->stepRate) {
384 default:
385 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
386 pipeline->instancing_enable[desc->binding] = false;
387 break;
388 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
389 pipeline->instancing_enable[desc->binding] = true;
390 break;
391 }
392 }
393
394 const VkPipelineInputAssemblyStateCreateInfo *ia_info =
395 pCreateInfo->pInputAssemblyState;
396 pipeline->primitive_restart = ia_info->primitiveRestartEnable;
397 pipeline->topology = vk_to_gen_primitive_type[ia_info->topology];
398
399 if (extra && extra->use_rectlist)
400 pipeline->topology = _3DPRIM_RECTLIST;
401
402 return VK_SUCCESS;
403 }
404
405 VkResult
406 anv_graphics_pipeline_create(
407 VkDevice _device,
408 const VkGraphicsPipelineCreateInfo *pCreateInfo,
409 const struct anv_graphics_pipeline_create_info *extra,
410 VkPipeline *pPipeline)
411 {
412 ANV_FROM_HANDLE(anv_device, device, _device);
413
414 switch (device->info.gen) {
415 case 7:
416 return gen7_graphics_pipeline_create(_device, pCreateInfo, extra, pPipeline);
417 case 8:
418 return gen8_graphics_pipeline_create(_device, pCreateInfo, extra, pPipeline);
419 default:
420 unreachable("unsupported gen\n");
421 }
422 }
423
424 VkResult anv_CreateGraphicsPipelines(
425 VkDevice _device,
426 VkPipelineCache pipelineCache,
427 uint32_t count,
428 const VkGraphicsPipelineCreateInfo* pCreateInfos,
429 VkPipeline* pPipelines)
430 {
431 VkResult result = VK_SUCCESS;
432
433 unsigned i = 0;
434 for (; i < count; i++) {
435 result = anv_graphics_pipeline_create(_device, &pCreateInfos[i],
436 NULL, &pPipelines[i]);
437 if (result != VK_SUCCESS) {
438 for (unsigned j = 0; j < i; j++) {
439 anv_DestroyPipeline(_device, pPipelines[j]);
440 }
441
442 return result;
443 }
444 }
445
446 return VK_SUCCESS;
447 }
448
449 static VkResult anv_compute_pipeline_create(
450 VkDevice _device,
451 const VkComputePipelineCreateInfo* pCreateInfo,
452 VkPipeline* pPipeline)
453 {
454 ANV_FROM_HANDLE(anv_device, device, _device);
455
456 switch (device->info.gen) {
457 case 7:
458 return gen7_compute_pipeline_create(_device, pCreateInfo, pPipeline);
459 case 8:
460 return gen8_compute_pipeline_create(_device, pCreateInfo, pPipeline);
461 default:
462 unreachable("unsupported gen\n");
463 }
464 }
465
466 VkResult anv_CreateComputePipelines(
467 VkDevice _device,
468 VkPipelineCache pipelineCache,
469 uint32_t count,
470 const VkComputePipelineCreateInfo* pCreateInfos,
471 VkPipeline* pPipelines)
472 {
473 VkResult result = VK_SUCCESS;
474
475 unsigned i = 0;
476 for (; i < count; i++) {
477 result = anv_compute_pipeline_create(_device, &pCreateInfos[i],
478 &pPipelines[i]);
479 if (result != VK_SUCCESS) {
480 for (unsigned j = 0; j < i; j++) {
481 anv_DestroyPipeline(_device, pPipelines[j]);
482 }
483
484 return result;
485 }
486 }
487
488 return VK_SUCCESS;
489 }
490
491 // Pipeline layout functions
492
493 VkResult anv_CreatePipelineLayout(
494 VkDevice _device,
495 const VkPipelineLayoutCreateInfo* pCreateInfo,
496 VkPipelineLayout* pPipelineLayout)
497 {
498 ANV_FROM_HANDLE(anv_device, device, _device);
499 struct anv_pipeline_layout l, *layout;
500
501 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO);
502
503 l.num_sets = pCreateInfo->descriptorSetCount;
504
505 unsigned dynamic_offset_count = 0;
506
507 memset(l.stage, 0, sizeof(l.stage));
508 for (uint32_t set = 0; set < pCreateInfo->descriptorSetCount; set++) {
509 ANV_FROM_HANDLE(anv_descriptor_set_layout, set_layout,
510 pCreateInfo->pSetLayouts[set]);
511 l.set[set].layout = set_layout;
512
513 l.set[set].dynamic_offset_start = dynamic_offset_count;
514 for (uint32_t b = 0; b < set_layout->binding_count; b++) {
515 if (set_layout->binding[b].dynamic_offset_index >= 0)
516 dynamic_offset_count += set_layout->binding[b].array_size;
517 }
518
519 for (VkShaderStage s = 0; s < VK_SHADER_STAGE_NUM; s++) {
520 l.set[set].stage[s].surface_start = l.stage[s].surface_count;
521 l.set[set].stage[s].sampler_start = l.stage[s].sampler_count;
522
523 for (uint32_t b = 0; b < set_layout->binding_count; b++) {
524 unsigned array_size = set_layout->binding[b].array_size;
525
526 if (set_layout->binding[b].stage[s].surface_index >= 0) {
527 l.stage[s].surface_count += array_size;
528
529 if (set_layout->binding[b].dynamic_offset_index >= 0)
530 l.stage[s].has_dynamic_offsets = true;
531 }
532
533 if (set_layout->binding[b].stage[s].sampler_index >= 0)
534 l.stage[s].sampler_count += array_size;
535 }
536 }
537 }
538
539 unsigned num_bindings = 0;
540 for (VkShaderStage s = 0; s < VK_SHADER_STAGE_NUM; s++)
541 num_bindings += l.stage[s].surface_count + l.stage[s].sampler_count;
542
543 size_t size = sizeof(*layout) + num_bindings * sizeof(layout->entries[0]);
544
545 layout = anv_device_alloc(device, size, 8, VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
546 if (layout == NULL)
547 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
548
549 /* Now we can actually build our surface and sampler maps */
550 struct anv_pipeline_binding *entry = layout->entries;
551 for (VkShaderStage s = 0; s < VK_SHADER_STAGE_NUM; s++) {
552 l.stage[s].surface_to_descriptor = entry;
553 entry += l.stage[s].surface_count;
554 l.stage[s].sampler_to_descriptor = entry;
555 entry += l.stage[s].sampler_count;
556
557 int surface = 0;
558 int sampler = 0;
559 for (uint32_t set = 0; set < pCreateInfo->descriptorSetCount; set++) {
560 struct anv_descriptor_set_layout *set_layout = l.set[set].layout;
561
562 unsigned set_offset = 0;
563 for (uint32_t b = 0; b < set_layout->binding_count; b++) {
564 unsigned array_size = set_layout->binding[b].array_size;
565
566 if (set_layout->binding[b].stage[s].surface_index >= 0) {
567 assert(surface == l.set[set].stage[s].surface_start +
568 set_layout->binding[b].stage[s].surface_index);
569 for (unsigned i = 0; i < array_size; i++) {
570 l.stage[s].surface_to_descriptor[surface + i].set = set;
571 l.stage[s].surface_to_descriptor[surface + i].offset = set_offset + i;
572 }
573 surface += array_size;
574 }
575
576 if (set_layout->binding[b].stage[s].sampler_index >= 0) {
577 assert(sampler == l.set[set].stage[s].sampler_start +
578 set_layout->binding[b].stage[s].sampler_index);
579 for (unsigned i = 0; i < array_size; i++) {
580 l.stage[s].sampler_to_descriptor[sampler + i].set = set;
581 l.stage[s].sampler_to_descriptor[sampler + i].offset = set_offset + i;
582 }
583 sampler += array_size;
584 }
585
586 set_offset += array_size;
587 }
588 }
589 }
590
591 /* Finally, we're done setting it up, copy into the allocated version */
592 *layout = l;
593
594 *pPipelineLayout = anv_pipeline_layout_to_handle(layout);
595
596 return VK_SUCCESS;
597 }
598
599 void anv_DestroyPipelineLayout(
600 VkDevice _device,
601 VkPipelineLayout _pipelineLayout)
602 {
603 ANV_FROM_HANDLE(anv_device, device, _device);
604 ANV_FROM_HANDLE(anv_pipeline_layout, pipeline_layout, _pipelineLayout);
605
606 anv_device_free(device, pipeline_layout);
607 }