2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include "util/mesa-sha1.h"
33 #include "anv_private.h"
36 * Descriptor set layouts.
39 static enum anv_descriptor_data
40 anv_descriptor_data_for_type(const struct anv_physical_device
*device
,
41 VkDescriptorType type
)
43 enum anv_descriptor_data data
= 0;
46 case VK_DESCRIPTOR_TYPE_SAMPLER
:
47 data
= ANV_DESCRIPTOR_SAMPLER_STATE
;
50 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
51 data
= ANV_DESCRIPTOR_SURFACE_STATE
|
52 ANV_DESCRIPTOR_SAMPLER_STATE
;
55 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
56 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
57 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
58 data
= ANV_DESCRIPTOR_SURFACE_STATE
;
61 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
62 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
63 data
= ANV_DESCRIPTOR_SURFACE_STATE
;
64 if (device
->info
.gen
< 9)
65 data
|= ANV_DESCRIPTOR_IMAGE_PARAM
;
68 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
69 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
70 data
= ANV_DESCRIPTOR_SURFACE_STATE
|
71 ANV_DESCRIPTOR_BUFFER_VIEW
;
74 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
75 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
76 data
= ANV_DESCRIPTOR_SURFACE_STATE
;
79 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
:
80 data
= ANV_DESCRIPTOR_INLINE_UNIFORM
;
84 unreachable("Unsupported descriptor type");
91 anv_descriptor_data_size(enum anv_descriptor_data data
)
96 /** Returns the size in bytes of each descriptor with the given layout */
98 anv_descriptor_size(const struct anv_descriptor_set_binding_layout
*layout
)
100 if (layout
->data
& ANV_DESCRIPTOR_INLINE_UNIFORM
) {
101 assert(layout
->data
== ANV_DESCRIPTOR_INLINE_UNIFORM
);
102 return layout
->array_size
;
105 return anv_descriptor_data_size(layout
->data
);
108 /** Returns the size in bytes of each descriptor of the given type
110 * This version of the function does not have access to the entire layout so
111 * it may only work on certain descriptor types where the descriptor size is
112 * entirely determined by the descriptor type. Whenever possible, code should
113 * use anv_descriptor_size() instead.
116 anv_descriptor_type_size(const struct anv_physical_device
*pdevice
,
117 VkDescriptorType type
)
119 assert(type
!= VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
);
120 return anv_descriptor_data_size(anv_descriptor_data_for_type(pdevice
, type
));
123 void anv_GetDescriptorSetLayoutSupport(
125 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
126 VkDescriptorSetLayoutSupport
* pSupport
)
128 uint32_t surface_count
[MESA_SHADER_STAGES
] = { 0, };
130 for (uint32_t b
= 0; b
< pCreateInfo
->bindingCount
; b
++) {
131 const VkDescriptorSetLayoutBinding
*binding
= &pCreateInfo
->pBindings
[b
];
133 switch (binding
->descriptorType
) {
134 case VK_DESCRIPTOR_TYPE_SAMPLER
:
135 /* There is no real limit on samplers */
138 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
139 if (binding
->pImmutableSamplers
) {
140 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++) {
141 ANV_FROM_HANDLE(anv_sampler
, sampler
,
142 binding
->pImmutableSamplers
[i
]);
143 anv_foreach_stage(s
, binding
->stageFlags
)
144 surface_count
[s
] += sampler
->n_planes
;
147 anv_foreach_stage(s
, binding
->stageFlags
)
148 surface_count
[s
] += binding
->descriptorCount
;
153 anv_foreach_stage(s
, binding
->stageFlags
)
154 surface_count
[s
] += binding
->descriptorCount
;
159 bool supported
= true;
160 for (unsigned s
= 0; s
< MESA_SHADER_STAGES
; s
++) {
161 /* Our maximum binding table size is 250 and we need to reserve 8 for
162 * render targets. 240 is a nice round number.
164 if (surface_count
[s
] >= 240)
168 pSupport
->supported
= supported
;
171 VkResult
anv_CreateDescriptorSetLayout(
173 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
174 const VkAllocationCallbacks
* pAllocator
,
175 VkDescriptorSetLayout
* pSetLayout
)
177 ANV_FROM_HANDLE(anv_device
, device
, _device
);
179 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
181 uint32_t max_binding
= 0;
182 uint32_t immutable_sampler_count
= 0;
183 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
184 max_binding
= MAX2(max_binding
, pCreateInfo
->pBindings
[j
].binding
);
186 /* From the Vulkan 1.1.97 spec for VkDescriptorSetLayoutBinding:
188 * "If descriptorType specifies a VK_DESCRIPTOR_TYPE_SAMPLER or
189 * VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER type descriptor, then
190 * pImmutableSamplers can be used to initialize a set of immutable
191 * samplers. [...] If descriptorType is not one of these descriptor
192 * types, then pImmutableSamplers is ignored.
194 * We need to be careful here and only parse pImmutableSamplers if we
195 * have one of the right descriptor types.
197 VkDescriptorType desc_type
= pCreateInfo
->pBindings
[j
].descriptorType
;
198 if ((desc_type
== VK_DESCRIPTOR_TYPE_SAMPLER
||
199 desc_type
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
) &&
200 pCreateInfo
->pBindings
[j
].pImmutableSamplers
)
201 immutable_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
204 struct anv_descriptor_set_layout
*set_layout
;
205 struct anv_descriptor_set_binding_layout
*bindings
;
206 struct anv_sampler
**samplers
;
208 /* We need to allocate decriptor set layouts off the device allocator
209 * with DEVICE scope because they are reference counted and may not be
210 * destroyed when vkDestroyDescriptorSetLayout is called.
213 anv_multialloc_add(&ma
, &set_layout
, 1);
214 anv_multialloc_add(&ma
, &bindings
, max_binding
+ 1);
215 anv_multialloc_add(&ma
, &samplers
, immutable_sampler_count
);
217 if (!anv_multialloc_alloc(&ma
, &device
->alloc
,
218 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
))
219 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
221 memset(set_layout
, 0, sizeof(*set_layout
));
222 set_layout
->ref_cnt
= 1;
223 set_layout
->binding_count
= max_binding
+ 1;
225 for (uint32_t b
= 0; b
<= max_binding
; b
++) {
226 /* Initialize all binding_layout entries to -1 */
227 memset(&set_layout
->binding
[b
], -1, sizeof(set_layout
->binding
[b
]));
229 set_layout
->binding
[b
].data
= 0;
230 set_layout
->binding
[b
].array_size
= 0;
231 set_layout
->binding
[b
].immutable_samplers
= NULL
;
234 /* Initialize all samplers to 0 */
235 memset(samplers
, 0, immutable_sampler_count
* sizeof(*samplers
));
237 uint32_t buffer_view_count
= 0;
238 uint32_t dynamic_offset_count
= 0;
239 uint32_t descriptor_buffer_size
= 0;
241 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
242 const VkDescriptorSetLayoutBinding
*binding
= &pCreateInfo
->pBindings
[j
];
243 uint32_t b
= binding
->binding
;
244 /* We temporarily store the pointer to the binding in the
245 * immutable_samplers pointer. This provides us with a quick-and-dirty
246 * way to sort the bindings by binding number.
248 set_layout
->binding
[b
].immutable_samplers
= (void *)binding
;
251 for (uint32_t b
= 0; b
<= max_binding
; b
++) {
252 const VkDescriptorSetLayoutBinding
*binding
=
253 (void *)set_layout
->binding
[b
].immutable_samplers
;
258 /* We temporarily stashed the pointer to the binding in the
259 * immutable_samplers pointer. Now that we've pulled it back out
260 * again, we reset immutable_samplers to NULL.
262 set_layout
->binding
[b
].immutable_samplers
= NULL
;
264 if (binding
->descriptorCount
== 0)
268 set_layout
->binding
[b
].type
= binding
->descriptorType
;
270 set_layout
->binding
[b
].data
=
271 anv_descriptor_data_for_type(&device
->instance
->physicalDevice
,
272 binding
->descriptorType
);
273 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
274 set_layout
->binding
[b
].descriptor_index
= set_layout
->size
;
275 set_layout
->size
+= binding
->descriptorCount
;
277 if (set_layout
->binding
[b
].data
& ANV_DESCRIPTOR_BUFFER_VIEW
) {
278 set_layout
->binding
[b
].buffer_view_index
= buffer_view_count
;
279 buffer_view_count
+= binding
->descriptorCount
;
282 switch (binding
->descriptorType
) {
283 case VK_DESCRIPTOR_TYPE_SAMPLER
:
284 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
285 if (binding
->pImmutableSamplers
) {
286 set_layout
->binding
[b
].immutable_samplers
= samplers
;
287 samplers
+= binding
->descriptorCount
;
289 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
290 set_layout
->binding
[b
].immutable_samplers
[i
] =
291 anv_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
298 switch (binding
->descriptorType
) {
299 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
300 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
301 set_layout
->binding
[b
].dynamic_offset_index
= dynamic_offset_count
;
302 dynamic_offset_count
+= binding
->descriptorCount
;
309 if (binding
->descriptorType
==
310 VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
) {
311 /* Inline uniform blocks are specified to use the descriptor array
312 * size as the size in bytes of the block.
314 descriptor_buffer_size
= align_u32(descriptor_buffer_size
, 32);
315 set_layout
->binding
[b
].descriptor_offset
= descriptor_buffer_size
;
316 descriptor_buffer_size
+= binding
->descriptorCount
;
318 set_layout
->binding
[b
].descriptor_offset
= descriptor_buffer_size
;
319 descriptor_buffer_size
+= anv_descriptor_size(&set_layout
->binding
[b
]) *
320 binding
->descriptorCount
;
323 set_layout
->shader_stages
|= binding
->stageFlags
;
326 set_layout
->buffer_view_count
= buffer_view_count
;
327 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
328 set_layout
->descriptor_buffer_size
= descriptor_buffer_size
;
330 *pSetLayout
= anv_descriptor_set_layout_to_handle(set_layout
);
335 void anv_DestroyDescriptorSetLayout(
337 VkDescriptorSetLayout _set_layout
,
338 const VkAllocationCallbacks
* pAllocator
)
340 ANV_FROM_HANDLE(anv_device
, device
, _device
);
341 ANV_FROM_HANDLE(anv_descriptor_set_layout
, set_layout
, _set_layout
);
346 anv_descriptor_set_layout_unref(device
, set_layout
);
349 #define SHA1_UPDATE_VALUE(ctx, x) _mesa_sha1_update(ctx, &(x), sizeof(x));
352 sha1_update_immutable_sampler(struct mesa_sha1
*ctx
,
353 const struct anv_sampler
*sampler
)
355 if (!sampler
->conversion
)
358 /* The only thing that affects the shader is ycbcr conversion */
359 _mesa_sha1_update(ctx
, sampler
->conversion
,
360 sizeof(*sampler
->conversion
));
364 sha1_update_descriptor_set_binding_layout(struct mesa_sha1
*ctx
,
365 const struct anv_descriptor_set_binding_layout
*layout
)
367 SHA1_UPDATE_VALUE(ctx
, layout
->data
);
368 SHA1_UPDATE_VALUE(ctx
, layout
->array_size
);
369 SHA1_UPDATE_VALUE(ctx
, layout
->descriptor_index
);
370 SHA1_UPDATE_VALUE(ctx
, layout
->dynamic_offset_index
);
371 SHA1_UPDATE_VALUE(ctx
, layout
->buffer_view_index
);
372 SHA1_UPDATE_VALUE(ctx
, layout
->descriptor_offset
);
374 if (layout
->immutable_samplers
) {
375 for (uint16_t i
= 0; i
< layout
->array_size
; i
++)
376 sha1_update_immutable_sampler(ctx
, layout
->immutable_samplers
[i
]);
381 sha1_update_descriptor_set_layout(struct mesa_sha1
*ctx
,
382 const struct anv_descriptor_set_layout
*layout
)
384 SHA1_UPDATE_VALUE(ctx
, layout
->binding_count
);
385 SHA1_UPDATE_VALUE(ctx
, layout
->size
);
386 SHA1_UPDATE_VALUE(ctx
, layout
->shader_stages
);
387 SHA1_UPDATE_VALUE(ctx
, layout
->buffer_view_count
);
388 SHA1_UPDATE_VALUE(ctx
, layout
->dynamic_offset_count
);
389 SHA1_UPDATE_VALUE(ctx
, layout
->descriptor_buffer_size
);
391 for (uint16_t i
= 0; i
< layout
->binding_count
; i
++)
392 sha1_update_descriptor_set_binding_layout(ctx
, &layout
->binding
[i
]);
396 * Pipeline layouts. These have nothing to do with the pipeline. They are
397 * just multiple descriptor set layouts pasted together
400 VkResult
anv_CreatePipelineLayout(
402 const VkPipelineLayoutCreateInfo
* pCreateInfo
,
403 const VkAllocationCallbacks
* pAllocator
,
404 VkPipelineLayout
* pPipelineLayout
)
406 ANV_FROM_HANDLE(anv_device
, device
, _device
);
407 struct anv_pipeline_layout
*layout
;
409 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
411 layout
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
412 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
414 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
416 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
418 unsigned dynamic_offset_count
= 0;
420 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
421 ANV_FROM_HANDLE(anv_descriptor_set_layout
, set_layout
,
422 pCreateInfo
->pSetLayouts
[set
]);
423 layout
->set
[set
].layout
= set_layout
;
424 anv_descriptor_set_layout_ref(set_layout
);
426 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
427 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
428 if (set_layout
->binding
[b
].dynamic_offset_index
< 0)
431 dynamic_offset_count
+= set_layout
->binding
[b
].array_size
;
435 struct mesa_sha1 ctx
;
436 _mesa_sha1_init(&ctx
);
437 for (unsigned s
= 0; s
< layout
->num_sets
; s
++) {
438 sha1_update_descriptor_set_layout(&ctx
, layout
->set
[s
].layout
);
439 _mesa_sha1_update(&ctx
, &layout
->set
[s
].dynamic_offset_start
,
440 sizeof(layout
->set
[s
].dynamic_offset_start
));
442 _mesa_sha1_update(&ctx
, &layout
->num_sets
, sizeof(layout
->num_sets
));
443 _mesa_sha1_final(&ctx
, layout
->sha1
);
445 *pPipelineLayout
= anv_pipeline_layout_to_handle(layout
);
450 void anv_DestroyPipelineLayout(
452 VkPipelineLayout _pipelineLayout
,
453 const VkAllocationCallbacks
* pAllocator
)
455 ANV_FROM_HANDLE(anv_device
, device
, _device
);
456 ANV_FROM_HANDLE(anv_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
458 if (!pipeline_layout
)
461 for (uint32_t i
= 0; i
< pipeline_layout
->num_sets
; i
++)
462 anv_descriptor_set_layout_unref(device
, pipeline_layout
->set
[i
].layout
);
464 vk_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
470 * These are implemented using a big pool of memory and a free-list for the
471 * host memory allocations and a state_stream and a free list for the buffer
472 * view surface state. The spec allows us to fail to allocate due to
473 * fragmentation in all cases but two: 1) after pool reset, allocating up
474 * until the pool size with no freeing must succeed and 2) allocating and
475 * freeing only descriptor sets with the same layout. Case 1) is easy enogh,
476 * and the free lists lets us recycle blocks for case 2).
479 /* The vma heap reserves 0 to mean NULL; we have to offset by some ammount to
480 * ensure we can allocate the entire BO without hitting zero. The actual
481 * amount doesn't matter.
483 #define POOL_HEAP_OFFSET 64
487 VkResult
anv_CreateDescriptorPool(
489 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
490 const VkAllocationCallbacks
* pAllocator
,
491 VkDescriptorPool
* pDescriptorPool
)
493 ANV_FROM_HANDLE(anv_device
, device
, _device
);
494 struct anv_descriptor_pool
*pool
;
496 const VkDescriptorPoolInlineUniformBlockCreateInfoEXT
*inline_info
=
497 vk_find_struct_const(pCreateInfo
->pNext
,
498 DESCRIPTOR_POOL_INLINE_UNIFORM_BLOCK_CREATE_INFO_EXT
);
500 uint32_t descriptor_count
= 0;
501 uint32_t buffer_view_count
= 0;
502 uint32_t descriptor_bo_size
= 0;
503 for (uint32_t i
= 0; i
< pCreateInfo
->poolSizeCount
; i
++) {
504 enum anv_descriptor_data desc_data
=
505 anv_descriptor_data_for_type(&device
->instance
->physicalDevice
,
506 pCreateInfo
->pPoolSizes
[i
].type
);
508 if (desc_data
& ANV_DESCRIPTOR_BUFFER_VIEW
)
509 buffer_view_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
511 unsigned desc_data_size
= anv_descriptor_data_size(desc_data
) *
512 pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
514 if (pCreateInfo
->pPoolSizes
[i
].type
==
515 VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
) {
516 /* Inline uniform blocks are specified to use the descriptor array
517 * size as the size in bytes of the block.
520 desc_data_size
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
523 descriptor_bo_size
+= desc_data_size
;
525 descriptor_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
527 /* We have to align descriptor buffer allocations to 32B so that we can
528 * push descriptor buffers. This means that each descriptor buffer
529 * allocated may burn up to 32B of extra space to get the right alignment.
530 * (Technically, it's at most 28B because we're always going to start at
531 * least 4B aligned but we're being conservative here.) Allocate enough
532 * extra space that we can chop it into maxSets pieces and align each one
535 descriptor_bo_size
+= 32 * pCreateInfo
->maxSets
;
536 descriptor_bo_size
= ALIGN(descriptor_bo_size
, 4096);
537 /* We align inline uniform blocks to 32B */
539 descriptor_bo_size
+= 32 * inline_info
->maxInlineUniformBlockBindings
;
541 const size_t pool_size
=
542 pCreateInfo
->maxSets
* sizeof(struct anv_descriptor_set
) +
543 descriptor_count
* sizeof(struct anv_descriptor
) +
544 buffer_view_count
* sizeof(struct anv_buffer_view
);
545 const size_t total_size
= sizeof(*pool
) + pool_size
;
547 pool
= vk_alloc2(&device
->alloc
, pAllocator
, total_size
, 8,
548 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
550 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
552 pool
->size
= pool_size
;
554 pool
->free_list
= EMPTY
;
556 if (descriptor_bo_size
> 0) {
557 VkResult result
= anv_bo_init_new(&pool
->bo
, device
, descriptor_bo_size
);
558 if (result
!= VK_SUCCESS
) {
559 vk_free2(&device
->alloc
, pAllocator
, pool
);
563 anv_gem_set_caching(device
, pool
->bo
.gem_handle
, I915_CACHING_CACHED
);
565 pool
->bo
.map
= anv_gem_mmap(device
, pool
->bo
.gem_handle
, 0,
566 descriptor_bo_size
, 0);
567 if (pool
->bo
.map
== NULL
) {
568 anv_gem_close(device
, pool
->bo
.gem_handle
);
569 vk_free2(&device
->alloc
, pAllocator
, pool
);
570 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
573 if (device
->instance
->physicalDevice
.use_softpin
) {
574 pool
->bo
.flags
|= EXEC_OBJECT_PINNED
;
575 anv_vma_alloc(device
, &pool
->bo
);
578 util_vma_heap_init(&pool
->bo_heap
, POOL_HEAP_OFFSET
, descriptor_bo_size
);
583 anv_state_stream_init(&pool
->surface_state_stream
,
584 &device
->surface_state_pool
, 4096);
585 pool
->surface_state_free_list
= NULL
;
587 list_inithead(&pool
->desc_sets
);
589 *pDescriptorPool
= anv_descriptor_pool_to_handle(pool
);
594 void anv_DestroyDescriptorPool(
596 VkDescriptorPool _pool
,
597 const VkAllocationCallbacks
* pAllocator
)
599 ANV_FROM_HANDLE(anv_device
, device
, _device
);
600 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, _pool
);
606 anv_gem_munmap(pool
->bo
.map
, pool
->bo
.size
);
607 anv_vma_free(device
, &pool
->bo
);
608 anv_gem_close(device
, pool
->bo
.gem_handle
);
610 anv_state_stream_finish(&pool
->surface_state_stream
);
612 list_for_each_entry_safe(struct anv_descriptor_set
, set
,
613 &pool
->desc_sets
, pool_link
) {
614 anv_descriptor_set_destroy(device
, pool
, set
);
617 vk_free2(&device
->alloc
, pAllocator
, pool
);
620 VkResult
anv_ResetDescriptorPool(
622 VkDescriptorPool descriptorPool
,
623 VkDescriptorPoolResetFlags flags
)
625 ANV_FROM_HANDLE(anv_device
, device
, _device
);
626 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, descriptorPool
);
629 pool
->free_list
= EMPTY
;
632 util_vma_heap_finish(&pool
->bo_heap
);
633 util_vma_heap_init(&pool
->bo_heap
, POOL_HEAP_OFFSET
, pool
->bo
.size
);
636 anv_state_stream_finish(&pool
->surface_state_stream
);
637 anv_state_stream_init(&pool
->surface_state_stream
,
638 &device
->surface_state_pool
, 4096);
639 pool
->surface_state_free_list
= NULL
;
644 struct pool_free_list_entry
{
650 anv_descriptor_pool_alloc_set(struct anv_descriptor_pool
*pool
,
652 struct anv_descriptor_set
**set
)
654 if (size
<= pool
->size
- pool
->next
) {
655 *set
= (struct anv_descriptor_set
*) (pool
->data
+ pool
->next
);
659 struct pool_free_list_entry
*entry
;
660 uint32_t *link
= &pool
->free_list
;
661 for (uint32_t f
= pool
->free_list
; f
!= EMPTY
; f
= entry
->next
) {
662 entry
= (struct pool_free_list_entry
*) (pool
->data
+ f
);
663 if (size
<= entry
->size
) {
665 *set
= (struct anv_descriptor_set
*) entry
;
671 if (pool
->free_list
!= EMPTY
) {
672 return vk_error(VK_ERROR_FRAGMENTED_POOL
);
674 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY
);
680 anv_descriptor_pool_free_set(struct anv_descriptor_pool
*pool
,
681 struct anv_descriptor_set
*set
)
683 /* Put the descriptor set allocation back on the free list. */
684 const uint32_t index
= (char *) set
- pool
->data
;
685 if (index
+ set
->size
== pool
->next
) {
688 struct pool_free_list_entry
*entry
= (struct pool_free_list_entry
*) set
;
689 entry
->next
= pool
->free_list
;
690 entry
->size
= set
->size
;
691 pool
->free_list
= (char *) entry
- pool
->data
;
694 list_del(&set
->pool_link
);
697 struct surface_state_free_list_entry
{
699 struct anv_state state
;
702 static struct anv_state
703 anv_descriptor_pool_alloc_state(struct anv_descriptor_pool
*pool
)
705 struct surface_state_free_list_entry
*entry
=
706 pool
->surface_state_free_list
;
709 struct anv_state state
= entry
->state
;
710 pool
->surface_state_free_list
= entry
->next
;
711 assert(state
.alloc_size
== 64);
714 return anv_state_stream_alloc(&pool
->surface_state_stream
, 64, 64);
719 anv_descriptor_pool_free_state(struct anv_descriptor_pool
*pool
,
720 struct anv_state state
)
722 /* Put the buffer view surface state back on the free list. */
723 struct surface_state_free_list_entry
*entry
= state
.map
;
724 entry
->next
= pool
->surface_state_free_list
;
725 entry
->state
= state
;
726 pool
->surface_state_free_list
= entry
;
730 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout
*layout
)
733 sizeof(struct anv_descriptor_set
) +
734 layout
->size
* sizeof(struct anv_descriptor
) +
735 layout
->buffer_view_count
* sizeof(struct anv_buffer_view
);
739 anv_descriptor_set_create(struct anv_device
*device
,
740 struct anv_descriptor_pool
*pool
,
741 struct anv_descriptor_set_layout
*layout
,
742 struct anv_descriptor_set
**out_set
)
744 struct anv_descriptor_set
*set
;
745 const size_t size
= anv_descriptor_set_layout_size(layout
);
747 VkResult result
= anv_descriptor_pool_alloc_set(pool
, size
, &set
);
748 if (result
!= VK_SUCCESS
)
751 if (layout
->descriptor_buffer_size
) {
752 /* Align the size to 32 so that alignment gaps don't cause extra holes
753 * in the heap which can lead to bad performance.
755 uint64_t pool_vma_offset
=
756 util_vma_heap_alloc(&pool
->bo_heap
,
757 ALIGN(layout
->descriptor_buffer_size
, 32), 32);
758 if (pool_vma_offset
== 0) {
759 anv_descriptor_pool_free_set(pool
, set
);
760 return vk_error(VK_ERROR_FRAGMENTED_POOL
);
762 assert(pool_vma_offset
>= POOL_HEAP_OFFSET
&&
763 pool_vma_offset
- POOL_HEAP_OFFSET
<= INT32_MAX
);
764 set
->desc_mem
.offset
= pool_vma_offset
- POOL_HEAP_OFFSET
;
765 set
->desc_mem
.alloc_size
= layout
->descriptor_buffer_size
;
766 set
->desc_mem
.map
= pool
->bo
.map
+ set
->desc_mem
.offset
;
768 set
->desc_surface_state
= anv_descriptor_pool_alloc_state(pool
);
769 anv_fill_buffer_surface_state(device
, set
->desc_surface_state
,
770 ISL_FORMAT_R32G32B32A32_FLOAT
,
771 (struct anv_address
) {
773 .offset
= set
->desc_mem
.offset
,
775 layout
->descriptor_buffer_size
, 1);
777 set
->desc_mem
= ANV_STATE_NULL
;
778 set
->desc_surface_state
= ANV_STATE_NULL
;
782 set
->layout
= layout
;
783 anv_descriptor_set_layout_ref(layout
);
787 (struct anv_buffer_view
*) &set
->descriptors
[layout
->size
];
788 set
->buffer_view_count
= layout
->buffer_view_count
;
790 /* By defining the descriptors to be zero now, we can later verify that
791 * a descriptor has not been populated with user data.
793 memset(set
->descriptors
, 0, sizeof(struct anv_descriptor
) * layout
->size
);
795 /* Go through and fill out immutable samplers if we have any */
796 struct anv_descriptor
*desc
= set
->descriptors
;
797 for (uint32_t b
= 0; b
< layout
->binding_count
; b
++) {
798 if (layout
->binding
[b
].immutable_samplers
) {
799 for (uint32_t i
= 0; i
< layout
->binding
[b
].array_size
; i
++) {
800 /* The type will get changed to COMBINED_IMAGE_SAMPLER in
801 * UpdateDescriptorSets if needed. However, if the descriptor
802 * set has an immutable sampler, UpdateDescriptorSets may never
803 * touch it, so we need to make sure it's 100% valid now.
805 desc
[i
] = (struct anv_descriptor
) {
806 .type
= VK_DESCRIPTOR_TYPE_SAMPLER
,
807 .sampler
= layout
->binding
[b
].immutable_samplers
[i
],
811 desc
+= layout
->binding
[b
].array_size
;
814 /* Allocate surface state for the buffer views. */
815 for (uint32_t b
= 0; b
< layout
->buffer_view_count
; b
++) {
816 set
->buffer_views
[b
].surface_state
=
817 anv_descriptor_pool_alloc_state(pool
);
826 anv_descriptor_set_destroy(struct anv_device
*device
,
827 struct anv_descriptor_pool
*pool
,
828 struct anv_descriptor_set
*set
)
830 anv_descriptor_set_layout_unref(device
, set
->layout
);
832 if (set
->desc_mem
.alloc_size
) {
833 util_vma_heap_free(&pool
->bo_heap
,
834 (uint64_t)set
->desc_mem
.offset
+ POOL_HEAP_OFFSET
,
835 set
->desc_mem
.alloc_size
);
836 anv_descriptor_pool_free_state(pool
, set
->desc_surface_state
);
839 for (uint32_t b
= 0; b
< set
->buffer_view_count
; b
++)
840 anv_descriptor_pool_free_state(pool
, set
->buffer_views
[b
].surface_state
);
842 anv_descriptor_pool_free_set(pool
, set
);
845 VkResult
anv_AllocateDescriptorSets(
847 const VkDescriptorSetAllocateInfo
* pAllocateInfo
,
848 VkDescriptorSet
* pDescriptorSets
)
850 ANV_FROM_HANDLE(anv_device
, device
, _device
);
851 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
853 VkResult result
= VK_SUCCESS
;
854 struct anv_descriptor_set
*set
;
857 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
858 ANV_FROM_HANDLE(anv_descriptor_set_layout
, layout
,
859 pAllocateInfo
->pSetLayouts
[i
]);
861 result
= anv_descriptor_set_create(device
, pool
, layout
, &set
);
862 if (result
!= VK_SUCCESS
)
865 list_addtail(&set
->pool_link
, &pool
->desc_sets
);
867 pDescriptorSets
[i
] = anv_descriptor_set_to_handle(set
);
870 if (result
!= VK_SUCCESS
)
871 anv_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
877 VkResult
anv_FreeDescriptorSets(
879 VkDescriptorPool descriptorPool
,
881 const VkDescriptorSet
* pDescriptorSets
)
883 ANV_FROM_HANDLE(anv_device
, device
, _device
);
884 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, descriptorPool
);
886 for (uint32_t i
= 0; i
< count
; i
++) {
887 ANV_FROM_HANDLE(anv_descriptor_set
, set
, pDescriptorSets
[i
]);
892 anv_descriptor_set_destroy(device
, pool
, set
);
899 anv_descriptor_set_write_image_view(struct anv_device
*device
,
900 struct anv_descriptor_set
*set
,
901 const VkDescriptorImageInfo
* const info
,
902 VkDescriptorType type
,
906 const struct anv_descriptor_set_binding_layout
*bind_layout
=
907 &set
->layout
->binding
[binding
];
908 struct anv_descriptor
*desc
=
909 &set
->descriptors
[bind_layout
->descriptor_index
+ element
];
910 struct anv_image_view
*image_view
= NULL
;
911 struct anv_sampler
*sampler
= NULL
;
913 assert(type
== bind_layout
->type
);
916 case VK_DESCRIPTOR_TYPE_SAMPLER
:
917 sampler
= anv_sampler_from_handle(info
->sampler
);
920 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
921 image_view
= anv_image_view_from_handle(info
->imageView
);
922 sampler
= anv_sampler_from_handle(info
->sampler
);
925 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
926 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
927 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
928 image_view
= anv_image_view_from_handle(info
->imageView
);
932 unreachable("invalid descriptor type");
935 /* If this descriptor has an immutable sampler, we don't want to stomp on
938 sampler
= bind_layout
->immutable_samplers
?
939 bind_layout
->immutable_samplers
[element
] :
942 *desc
= (struct anv_descriptor
) {
944 .layout
= info
->imageLayout
,
945 .image_view
= image_view
,
951 anv_descriptor_set_write_buffer_view(struct anv_device
*device
,
952 struct anv_descriptor_set
*set
,
953 VkDescriptorType type
,
954 struct anv_buffer_view
*buffer_view
,
958 const struct anv_descriptor_set_binding_layout
*bind_layout
=
959 &set
->layout
->binding
[binding
];
960 struct anv_descriptor
*desc
=
961 &set
->descriptors
[bind_layout
->descriptor_index
+ element
];
963 assert(type
== bind_layout
->type
);
965 *desc
= (struct anv_descriptor
) {
967 .buffer_view
= buffer_view
,
972 anv_descriptor_set_write_buffer(struct anv_device
*device
,
973 struct anv_descriptor_set
*set
,
974 struct anv_state_stream
*alloc_stream
,
975 VkDescriptorType type
,
976 struct anv_buffer
*buffer
,
982 const struct anv_descriptor_set_binding_layout
*bind_layout
=
983 &set
->layout
->binding
[binding
];
984 struct anv_descriptor
*desc
=
985 &set
->descriptors
[bind_layout
->descriptor_index
+ element
];
987 assert(type
== bind_layout
->type
);
989 if (type
== VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
||
990 type
== VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
) {
991 *desc
= (struct anv_descriptor
) {
998 assert(bind_layout
->data
& ANV_DESCRIPTOR_BUFFER_VIEW
);
999 struct anv_buffer_view
*bview
=
1000 &set
->buffer_views
[bind_layout
->buffer_view_index
+ element
];
1002 bview
->format
= anv_isl_format_for_descriptor_type(type
);
1003 bview
->range
= anv_buffer_get_range(buffer
, offset
, range
);
1004 bview
->address
= anv_address_add(buffer
->address
, offset
);
1006 /* If we're writing descriptors through a push command, we need to
1007 * allocate the surface state from the command buffer. Otherwise it will
1008 * be allocated by the descriptor pool when calling
1009 * vkAllocateDescriptorSets. */
1011 bview
->surface_state
= anv_state_stream_alloc(alloc_stream
, 64, 64);
1013 anv_fill_buffer_surface_state(device
, bview
->surface_state
,
1015 bview
->address
, bview
->range
, 1);
1017 *desc
= (struct anv_descriptor
) {
1019 .buffer_view
= bview
,
1025 anv_descriptor_set_write_inline_uniform_data(struct anv_device
*device
,
1026 struct anv_descriptor_set
*set
,
1032 const struct anv_descriptor_set_binding_layout
*bind_layout
=
1033 &set
->layout
->binding
[binding
];
1035 assert(bind_layout
->data
& ANV_DESCRIPTOR_INLINE_UNIFORM
);
1037 void *desc_map
= set
->desc_mem
.map
+ bind_layout
->descriptor_offset
;
1039 memcpy(desc_map
+ offset
, data
, size
);
1042 void anv_UpdateDescriptorSets(
1044 uint32_t descriptorWriteCount
,
1045 const VkWriteDescriptorSet
* pDescriptorWrites
,
1046 uint32_t descriptorCopyCount
,
1047 const VkCopyDescriptorSet
* pDescriptorCopies
)
1049 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1051 for (uint32_t i
= 0; i
< descriptorWriteCount
; i
++) {
1052 const VkWriteDescriptorSet
*write
= &pDescriptorWrites
[i
];
1053 ANV_FROM_HANDLE(anv_descriptor_set
, set
, write
->dstSet
);
1055 switch (write
->descriptorType
) {
1056 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1057 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1058 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1059 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1060 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1061 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1062 anv_descriptor_set_write_image_view(device
, set
,
1063 write
->pImageInfo
+ j
,
1064 write
->descriptorType
,
1066 write
->dstArrayElement
+ j
);
1070 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1071 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1072 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1073 ANV_FROM_HANDLE(anv_buffer_view
, bview
,
1074 write
->pTexelBufferView
[j
]);
1076 anv_descriptor_set_write_buffer_view(device
, set
,
1077 write
->descriptorType
,
1080 write
->dstArrayElement
+ j
);
1084 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1085 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1086 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1087 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1088 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1089 assert(write
->pBufferInfo
[j
].buffer
);
1090 ANV_FROM_HANDLE(anv_buffer
, buffer
, write
->pBufferInfo
[j
].buffer
);
1093 anv_descriptor_set_write_buffer(device
, set
,
1095 write
->descriptorType
,
1098 write
->dstArrayElement
+ j
,
1099 write
->pBufferInfo
[j
].offset
,
1100 write
->pBufferInfo
[j
].range
);
1104 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
: {
1105 const VkWriteDescriptorSetInlineUniformBlockEXT
*inline_write
=
1106 vk_find_struct_const(write
->pNext
,
1107 WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT
);
1108 assert(inline_write
->dataSize
== write
->descriptorCount
);
1109 anv_descriptor_set_write_inline_uniform_data(device
, set
,
1111 inline_write
->pData
,
1112 write
->dstArrayElement
,
1113 inline_write
->dataSize
);
1122 for (uint32_t i
= 0; i
< descriptorCopyCount
; i
++) {
1123 const VkCopyDescriptorSet
*copy
= &pDescriptorCopies
[i
];
1124 ANV_FROM_HANDLE(anv_descriptor_set
, src
, copy
->srcSet
);
1125 ANV_FROM_HANDLE(anv_descriptor_set
, dst
, copy
->dstSet
);
1127 const struct anv_descriptor_set_binding_layout
*src_layout
=
1128 &src
->layout
->binding
[copy
->srcBinding
];
1129 struct anv_descriptor
*src_desc
=
1130 &src
->descriptors
[src_layout
->descriptor_index
];
1131 src_desc
+= copy
->srcArrayElement
;
1133 const struct anv_descriptor_set_binding_layout
*dst_layout
=
1134 &dst
->layout
->binding
[copy
->dstBinding
];
1135 struct anv_descriptor
*dst_desc
=
1136 &dst
->descriptors
[dst_layout
->descriptor_index
];
1137 dst_desc
+= copy
->dstArrayElement
;
1139 for (uint32_t j
= 0; j
< copy
->descriptorCount
; j
++)
1140 dst_desc
[j
] = src_desc
[j
];
1142 if (src_layout
->data
& ANV_DESCRIPTOR_INLINE_UNIFORM
) {
1143 assert(src_layout
->data
== ANV_DESCRIPTOR_INLINE_UNIFORM
);
1144 memcpy(dst
->desc_mem
.map
+ dst_layout
->descriptor_offset
+
1145 copy
->dstArrayElement
,
1146 src
->desc_mem
.map
+ src_layout
->descriptor_offset
+
1147 copy
->srcArrayElement
,
1148 copy
->descriptorCount
);
1150 unsigned desc_size
= anv_descriptor_size(src_layout
);
1151 if (desc_size
> 0) {
1152 assert(desc_size
== anv_descriptor_size(dst_layout
));
1153 memcpy(dst
->desc_mem
.map
+ dst_layout
->descriptor_offset
+
1154 copy
->dstArrayElement
* desc_size
,
1155 src
->desc_mem
.map
+ src_layout
->descriptor_offset
+
1156 copy
->srcArrayElement
* desc_size
,
1157 copy
->descriptorCount
* desc_size
);
1164 * Descriptor update templates.
1168 anv_descriptor_set_write_template(struct anv_device
*device
,
1169 struct anv_descriptor_set
*set
,
1170 struct anv_state_stream
*alloc_stream
,
1171 const struct anv_descriptor_update_template
*template,
1174 for (uint32_t i
= 0; i
< template->entry_count
; i
++) {
1175 const struct anv_descriptor_template_entry
*entry
=
1176 &template->entries
[i
];
1178 switch (entry
->type
) {
1179 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1180 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1181 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1182 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1183 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1184 for (uint32_t j
= 0; j
< entry
->array_count
; j
++) {
1185 const VkDescriptorImageInfo
*info
=
1186 data
+ entry
->offset
+ j
* entry
->stride
;
1187 anv_descriptor_set_write_image_view(device
, set
,
1190 entry
->array_element
+ j
);
1194 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1195 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1196 for (uint32_t j
= 0; j
< entry
->array_count
; j
++) {
1197 const VkBufferView
*_bview
=
1198 data
+ entry
->offset
+ j
* entry
->stride
;
1199 ANV_FROM_HANDLE(anv_buffer_view
, bview
, *_bview
);
1201 anv_descriptor_set_write_buffer_view(device
, set
,
1205 entry
->array_element
+ j
);
1209 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1210 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1211 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1212 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1213 for (uint32_t j
= 0; j
< entry
->array_count
; j
++) {
1214 const VkDescriptorBufferInfo
*info
=
1215 data
+ entry
->offset
+ j
* entry
->stride
;
1216 ANV_FROM_HANDLE(anv_buffer
, buffer
, info
->buffer
);
1218 anv_descriptor_set_write_buffer(device
, set
,
1223 entry
->array_element
+ j
,
1224 info
->offset
, info
->range
);
1228 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
:
1229 anv_descriptor_set_write_inline_uniform_data(device
, set
,
1231 data
+ entry
->offset
,
1232 entry
->array_element
,
1233 entry
->array_count
);
1242 VkResult
anv_CreateDescriptorUpdateTemplate(
1244 const VkDescriptorUpdateTemplateCreateInfo
* pCreateInfo
,
1245 const VkAllocationCallbacks
* pAllocator
,
1246 VkDescriptorUpdateTemplate
* pDescriptorUpdateTemplate
)
1248 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1249 struct anv_descriptor_update_template
*template;
1251 size_t size
= sizeof(*template) +
1252 pCreateInfo
->descriptorUpdateEntryCount
* sizeof(template->entries
[0]);
1253 template = vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1254 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1255 if (template == NULL
)
1256 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1258 template->bind_point
= pCreateInfo
->pipelineBindPoint
;
1260 if (pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET
)
1261 template->set
= pCreateInfo
->set
;
1263 template->entry_count
= pCreateInfo
->descriptorUpdateEntryCount
;
1264 for (uint32_t i
= 0; i
< template->entry_count
; i
++) {
1265 const VkDescriptorUpdateTemplateEntry
*pEntry
=
1266 &pCreateInfo
->pDescriptorUpdateEntries
[i
];
1268 template->entries
[i
] = (struct anv_descriptor_template_entry
) {
1269 .type
= pEntry
->descriptorType
,
1270 .binding
= pEntry
->dstBinding
,
1271 .array_element
= pEntry
->dstArrayElement
,
1272 .array_count
= pEntry
->descriptorCount
,
1273 .offset
= pEntry
->offset
,
1274 .stride
= pEntry
->stride
,
1278 *pDescriptorUpdateTemplate
=
1279 anv_descriptor_update_template_to_handle(template);
1284 void anv_DestroyDescriptorUpdateTemplate(
1286 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1287 const VkAllocationCallbacks
* pAllocator
)
1289 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1290 ANV_FROM_HANDLE(anv_descriptor_update_template
, template,
1291 descriptorUpdateTemplate
);
1293 vk_free2(&device
->alloc
, pAllocator
, template);
1296 void anv_UpdateDescriptorSetWithTemplate(
1298 VkDescriptorSet descriptorSet
,
1299 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1302 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1303 ANV_FROM_HANDLE(anv_descriptor_set
, set
, descriptorSet
);
1304 ANV_FROM_HANDLE(anv_descriptor_update_template
, template,
1305 descriptorUpdateTemplate
);
1307 anv_descriptor_set_write_template(device
, set
, NULL
, template, pData
);