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
)
95 if (data
& ANV_DESCRIPTOR_IMAGE_PARAM
)
96 size
+= BRW_IMAGE_PARAM_SIZE
* 4;
101 /** Returns the size in bytes of each descriptor with the given layout */
103 anv_descriptor_size(const struct anv_descriptor_set_binding_layout
*layout
)
105 if (layout
->data
& ANV_DESCRIPTOR_INLINE_UNIFORM
) {
106 assert(layout
->data
== ANV_DESCRIPTOR_INLINE_UNIFORM
);
107 return layout
->array_size
;
110 return anv_descriptor_data_size(layout
->data
);
113 /** Returns the size in bytes of each descriptor of the given type
115 * This version of the function does not have access to the entire layout so
116 * it may only work on certain descriptor types where the descriptor size is
117 * entirely determined by the descriptor type. Whenever possible, code should
118 * use anv_descriptor_size() instead.
121 anv_descriptor_type_size(const struct anv_physical_device
*pdevice
,
122 VkDescriptorType type
)
124 assert(type
!= VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
);
125 return anv_descriptor_data_size(anv_descriptor_data_for_type(pdevice
, type
));
128 void anv_GetDescriptorSetLayoutSupport(
130 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
131 VkDescriptorSetLayoutSupport
* pSupport
)
133 uint32_t surface_count
[MESA_SHADER_STAGES
] = { 0, };
135 for (uint32_t b
= 0; b
< pCreateInfo
->bindingCount
; b
++) {
136 const VkDescriptorSetLayoutBinding
*binding
= &pCreateInfo
->pBindings
[b
];
138 switch (binding
->descriptorType
) {
139 case VK_DESCRIPTOR_TYPE_SAMPLER
:
140 /* There is no real limit on samplers */
143 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
144 if (binding
->pImmutableSamplers
) {
145 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++) {
146 ANV_FROM_HANDLE(anv_sampler
, sampler
,
147 binding
->pImmutableSamplers
[i
]);
148 anv_foreach_stage(s
, binding
->stageFlags
)
149 surface_count
[s
] += sampler
->n_planes
;
152 anv_foreach_stage(s
, binding
->stageFlags
)
153 surface_count
[s
] += binding
->descriptorCount
;
158 anv_foreach_stage(s
, binding
->stageFlags
)
159 surface_count
[s
] += binding
->descriptorCount
;
164 bool supported
= true;
165 for (unsigned s
= 0; s
< MESA_SHADER_STAGES
; s
++) {
166 /* Our maximum binding table size is 250 and we need to reserve 8 for
167 * render targets. 240 is a nice round number.
169 if (surface_count
[s
] >= 240)
173 pSupport
->supported
= supported
;
176 VkResult
anv_CreateDescriptorSetLayout(
178 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
179 const VkAllocationCallbacks
* pAllocator
,
180 VkDescriptorSetLayout
* pSetLayout
)
182 ANV_FROM_HANDLE(anv_device
, device
, _device
);
184 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
186 uint32_t max_binding
= 0;
187 uint32_t immutable_sampler_count
= 0;
188 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
189 max_binding
= MAX2(max_binding
, pCreateInfo
->pBindings
[j
].binding
);
191 /* From the Vulkan 1.1.97 spec for VkDescriptorSetLayoutBinding:
193 * "If descriptorType specifies a VK_DESCRIPTOR_TYPE_SAMPLER or
194 * VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER type descriptor, then
195 * pImmutableSamplers can be used to initialize a set of immutable
196 * samplers. [...] If descriptorType is not one of these descriptor
197 * types, then pImmutableSamplers is ignored.
199 * We need to be careful here and only parse pImmutableSamplers if we
200 * have one of the right descriptor types.
202 VkDescriptorType desc_type
= pCreateInfo
->pBindings
[j
].descriptorType
;
203 if ((desc_type
== VK_DESCRIPTOR_TYPE_SAMPLER
||
204 desc_type
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
) &&
205 pCreateInfo
->pBindings
[j
].pImmutableSamplers
)
206 immutable_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
209 struct anv_descriptor_set_layout
*set_layout
;
210 struct anv_descriptor_set_binding_layout
*bindings
;
211 struct anv_sampler
**samplers
;
213 /* We need to allocate decriptor set layouts off the device allocator
214 * with DEVICE scope because they are reference counted and may not be
215 * destroyed when vkDestroyDescriptorSetLayout is called.
218 anv_multialloc_add(&ma
, &set_layout
, 1);
219 anv_multialloc_add(&ma
, &bindings
, max_binding
+ 1);
220 anv_multialloc_add(&ma
, &samplers
, immutable_sampler_count
);
222 if (!anv_multialloc_alloc(&ma
, &device
->alloc
,
223 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
))
224 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
226 memset(set_layout
, 0, sizeof(*set_layout
));
227 set_layout
->ref_cnt
= 1;
228 set_layout
->binding_count
= max_binding
+ 1;
230 for (uint32_t b
= 0; b
<= max_binding
; b
++) {
231 /* Initialize all binding_layout entries to -1 */
232 memset(&set_layout
->binding
[b
], -1, sizeof(set_layout
->binding
[b
]));
234 set_layout
->binding
[b
].data
= 0;
235 set_layout
->binding
[b
].array_size
= 0;
236 set_layout
->binding
[b
].immutable_samplers
= NULL
;
239 /* Initialize all samplers to 0 */
240 memset(samplers
, 0, immutable_sampler_count
* sizeof(*samplers
));
242 uint32_t buffer_view_count
= 0;
243 uint32_t dynamic_offset_count
= 0;
244 uint32_t descriptor_buffer_size
= 0;
246 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
247 const VkDescriptorSetLayoutBinding
*binding
= &pCreateInfo
->pBindings
[j
];
248 uint32_t b
= binding
->binding
;
249 /* We temporarily store the pointer to the binding in the
250 * immutable_samplers pointer. This provides us with a quick-and-dirty
251 * way to sort the bindings by binding number.
253 set_layout
->binding
[b
].immutable_samplers
= (void *)binding
;
256 for (uint32_t b
= 0; b
<= max_binding
; b
++) {
257 const VkDescriptorSetLayoutBinding
*binding
=
258 (void *)set_layout
->binding
[b
].immutable_samplers
;
263 /* We temporarily stashed the pointer to the binding in the
264 * immutable_samplers pointer. Now that we've pulled it back out
265 * again, we reset immutable_samplers to NULL.
267 set_layout
->binding
[b
].immutable_samplers
= NULL
;
269 if (binding
->descriptorCount
== 0)
273 set_layout
->binding
[b
].type
= binding
->descriptorType
;
275 set_layout
->binding
[b
].data
=
276 anv_descriptor_data_for_type(&device
->instance
->physicalDevice
,
277 binding
->descriptorType
);
278 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
279 set_layout
->binding
[b
].descriptor_index
= set_layout
->size
;
280 set_layout
->size
+= binding
->descriptorCount
;
282 if (set_layout
->binding
[b
].data
& ANV_DESCRIPTOR_BUFFER_VIEW
) {
283 set_layout
->binding
[b
].buffer_view_index
= buffer_view_count
;
284 buffer_view_count
+= binding
->descriptorCount
;
287 switch (binding
->descriptorType
) {
288 case VK_DESCRIPTOR_TYPE_SAMPLER
:
289 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
290 if (binding
->pImmutableSamplers
) {
291 set_layout
->binding
[b
].immutable_samplers
= samplers
;
292 samplers
+= binding
->descriptorCount
;
294 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
295 set_layout
->binding
[b
].immutable_samplers
[i
] =
296 anv_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
303 switch (binding
->descriptorType
) {
304 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
305 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
306 set_layout
->binding
[b
].dynamic_offset_index
= dynamic_offset_count
;
307 dynamic_offset_count
+= binding
->descriptorCount
;
314 if (binding
->descriptorType
==
315 VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
) {
316 /* Inline uniform blocks are specified to use the descriptor array
317 * size as the size in bytes of the block.
319 descriptor_buffer_size
= align_u32(descriptor_buffer_size
, 32);
320 set_layout
->binding
[b
].descriptor_offset
= descriptor_buffer_size
;
321 descriptor_buffer_size
+= binding
->descriptorCount
;
323 set_layout
->binding
[b
].descriptor_offset
= descriptor_buffer_size
;
324 descriptor_buffer_size
+= anv_descriptor_size(&set_layout
->binding
[b
]) *
325 binding
->descriptorCount
;
328 set_layout
->shader_stages
|= binding
->stageFlags
;
331 set_layout
->buffer_view_count
= buffer_view_count
;
332 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
333 set_layout
->descriptor_buffer_size
= descriptor_buffer_size
;
335 *pSetLayout
= anv_descriptor_set_layout_to_handle(set_layout
);
340 void anv_DestroyDescriptorSetLayout(
342 VkDescriptorSetLayout _set_layout
,
343 const VkAllocationCallbacks
* pAllocator
)
345 ANV_FROM_HANDLE(anv_device
, device
, _device
);
346 ANV_FROM_HANDLE(anv_descriptor_set_layout
, set_layout
, _set_layout
);
351 anv_descriptor_set_layout_unref(device
, set_layout
);
354 #define SHA1_UPDATE_VALUE(ctx, x) _mesa_sha1_update(ctx, &(x), sizeof(x));
357 sha1_update_immutable_sampler(struct mesa_sha1
*ctx
,
358 const struct anv_sampler
*sampler
)
360 if (!sampler
->conversion
)
363 /* The only thing that affects the shader is ycbcr conversion */
364 _mesa_sha1_update(ctx
, sampler
->conversion
,
365 sizeof(*sampler
->conversion
));
369 sha1_update_descriptor_set_binding_layout(struct mesa_sha1
*ctx
,
370 const struct anv_descriptor_set_binding_layout
*layout
)
372 SHA1_UPDATE_VALUE(ctx
, layout
->data
);
373 SHA1_UPDATE_VALUE(ctx
, layout
->array_size
);
374 SHA1_UPDATE_VALUE(ctx
, layout
->descriptor_index
);
375 SHA1_UPDATE_VALUE(ctx
, layout
->dynamic_offset_index
);
376 SHA1_UPDATE_VALUE(ctx
, layout
->buffer_view_index
);
377 SHA1_UPDATE_VALUE(ctx
, layout
->descriptor_offset
);
379 if (layout
->immutable_samplers
) {
380 for (uint16_t i
= 0; i
< layout
->array_size
; i
++)
381 sha1_update_immutable_sampler(ctx
, layout
->immutable_samplers
[i
]);
386 sha1_update_descriptor_set_layout(struct mesa_sha1
*ctx
,
387 const struct anv_descriptor_set_layout
*layout
)
389 SHA1_UPDATE_VALUE(ctx
, layout
->binding_count
);
390 SHA1_UPDATE_VALUE(ctx
, layout
->size
);
391 SHA1_UPDATE_VALUE(ctx
, layout
->shader_stages
);
392 SHA1_UPDATE_VALUE(ctx
, layout
->buffer_view_count
);
393 SHA1_UPDATE_VALUE(ctx
, layout
->dynamic_offset_count
);
394 SHA1_UPDATE_VALUE(ctx
, layout
->descriptor_buffer_size
);
396 for (uint16_t i
= 0; i
< layout
->binding_count
; i
++)
397 sha1_update_descriptor_set_binding_layout(ctx
, &layout
->binding
[i
]);
401 * Pipeline layouts. These have nothing to do with the pipeline. They are
402 * just multiple descriptor set layouts pasted together
405 VkResult
anv_CreatePipelineLayout(
407 const VkPipelineLayoutCreateInfo
* pCreateInfo
,
408 const VkAllocationCallbacks
* pAllocator
,
409 VkPipelineLayout
* pPipelineLayout
)
411 ANV_FROM_HANDLE(anv_device
, device
, _device
);
412 struct anv_pipeline_layout
*layout
;
414 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
416 layout
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
417 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
419 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
421 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
423 unsigned dynamic_offset_count
= 0;
425 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
426 ANV_FROM_HANDLE(anv_descriptor_set_layout
, set_layout
,
427 pCreateInfo
->pSetLayouts
[set
]);
428 layout
->set
[set
].layout
= set_layout
;
429 anv_descriptor_set_layout_ref(set_layout
);
431 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
432 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
433 if (set_layout
->binding
[b
].dynamic_offset_index
< 0)
436 dynamic_offset_count
+= set_layout
->binding
[b
].array_size
;
440 struct mesa_sha1 ctx
;
441 _mesa_sha1_init(&ctx
);
442 for (unsigned s
= 0; s
< layout
->num_sets
; s
++) {
443 sha1_update_descriptor_set_layout(&ctx
, layout
->set
[s
].layout
);
444 _mesa_sha1_update(&ctx
, &layout
->set
[s
].dynamic_offset_start
,
445 sizeof(layout
->set
[s
].dynamic_offset_start
));
447 _mesa_sha1_update(&ctx
, &layout
->num_sets
, sizeof(layout
->num_sets
));
448 _mesa_sha1_final(&ctx
, layout
->sha1
);
450 *pPipelineLayout
= anv_pipeline_layout_to_handle(layout
);
455 void anv_DestroyPipelineLayout(
457 VkPipelineLayout _pipelineLayout
,
458 const VkAllocationCallbacks
* pAllocator
)
460 ANV_FROM_HANDLE(anv_device
, device
, _device
);
461 ANV_FROM_HANDLE(anv_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
463 if (!pipeline_layout
)
466 for (uint32_t i
= 0; i
< pipeline_layout
->num_sets
; i
++)
467 anv_descriptor_set_layout_unref(device
, pipeline_layout
->set
[i
].layout
);
469 vk_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
475 * These are implemented using a big pool of memory and a free-list for the
476 * host memory allocations and a state_stream and a free list for the buffer
477 * view surface state. The spec allows us to fail to allocate due to
478 * fragmentation in all cases but two: 1) after pool reset, allocating up
479 * until the pool size with no freeing must succeed and 2) allocating and
480 * freeing only descriptor sets with the same layout. Case 1) is easy enogh,
481 * and the free lists lets us recycle blocks for case 2).
484 /* The vma heap reserves 0 to mean NULL; we have to offset by some ammount to
485 * ensure we can allocate the entire BO without hitting zero. The actual
486 * amount doesn't matter.
488 #define POOL_HEAP_OFFSET 64
492 VkResult
anv_CreateDescriptorPool(
494 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
495 const VkAllocationCallbacks
* pAllocator
,
496 VkDescriptorPool
* pDescriptorPool
)
498 ANV_FROM_HANDLE(anv_device
, device
, _device
);
499 struct anv_descriptor_pool
*pool
;
501 const VkDescriptorPoolInlineUniformBlockCreateInfoEXT
*inline_info
=
502 vk_find_struct_const(pCreateInfo
->pNext
,
503 DESCRIPTOR_POOL_INLINE_UNIFORM_BLOCK_CREATE_INFO_EXT
);
505 uint32_t descriptor_count
= 0;
506 uint32_t buffer_view_count
= 0;
507 uint32_t descriptor_bo_size
= 0;
508 for (uint32_t i
= 0; i
< pCreateInfo
->poolSizeCount
; i
++) {
509 enum anv_descriptor_data desc_data
=
510 anv_descriptor_data_for_type(&device
->instance
->physicalDevice
,
511 pCreateInfo
->pPoolSizes
[i
].type
);
513 if (desc_data
& ANV_DESCRIPTOR_BUFFER_VIEW
)
514 buffer_view_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
516 unsigned desc_data_size
= anv_descriptor_data_size(desc_data
) *
517 pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
519 if (pCreateInfo
->pPoolSizes
[i
].type
==
520 VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
) {
521 /* Inline uniform blocks are specified to use the descriptor array
522 * size as the size in bytes of the block.
525 desc_data_size
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
528 descriptor_bo_size
+= desc_data_size
;
530 descriptor_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
532 /* We have to align descriptor buffer allocations to 32B so that we can
533 * push descriptor buffers. This means that each descriptor buffer
534 * allocated may burn up to 32B of extra space to get the right alignment.
535 * (Technically, it's at most 28B because we're always going to start at
536 * least 4B aligned but we're being conservative here.) Allocate enough
537 * extra space that we can chop it into maxSets pieces and align each one
540 descriptor_bo_size
+= 32 * pCreateInfo
->maxSets
;
541 descriptor_bo_size
= ALIGN(descriptor_bo_size
, 4096);
542 /* We align inline uniform blocks to 32B */
544 descriptor_bo_size
+= 32 * inline_info
->maxInlineUniformBlockBindings
;
546 const size_t pool_size
=
547 pCreateInfo
->maxSets
* sizeof(struct anv_descriptor_set
) +
548 descriptor_count
* sizeof(struct anv_descriptor
) +
549 buffer_view_count
* sizeof(struct anv_buffer_view
);
550 const size_t total_size
= sizeof(*pool
) + pool_size
;
552 pool
= vk_alloc2(&device
->alloc
, pAllocator
, total_size
, 8,
553 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
555 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
557 pool
->size
= pool_size
;
559 pool
->free_list
= EMPTY
;
561 if (descriptor_bo_size
> 0) {
562 VkResult result
= anv_bo_init_new(&pool
->bo
, device
, descriptor_bo_size
);
563 if (result
!= VK_SUCCESS
) {
564 vk_free2(&device
->alloc
, pAllocator
, pool
);
568 anv_gem_set_caching(device
, pool
->bo
.gem_handle
, I915_CACHING_CACHED
);
570 pool
->bo
.map
= anv_gem_mmap(device
, pool
->bo
.gem_handle
, 0,
571 descriptor_bo_size
, 0);
572 if (pool
->bo
.map
== NULL
) {
573 anv_gem_close(device
, pool
->bo
.gem_handle
);
574 vk_free2(&device
->alloc
, pAllocator
, pool
);
575 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
578 if (device
->instance
->physicalDevice
.use_softpin
) {
579 pool
->bo
.flags
|= EXEC_OBJECT_PINNED
;
580 anv_vma_alloc(device
, &pool
->bo
);
583 util_vma_heap_init(&pool
->bo_heap
, POOL_HEAP_OFFSET
, descriptor_bo_size
);
588 anv_state_stream_init(&pool
->surface_state_stream
,
589 &device
->surface_state_pool
, 4096);
590 pool
->surface_state_free_list
= NULL
;
592 list_inithead(&pool
->desc_sets
);
594 *pDescriptorPool
= anv_descriptor_pool_to_handle(pool
);
599 void anv_DestroyDescriptorPool(
601 VkDescriptorPool _pool
,
602 const VkAllocationCallbacks
* pAllocator
)
604 ANV_FROM_HANDLE(anv_device
, device
, _device
);
605 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, _pool
);
611 anv_gem_munmap(pool
->bo
.map
, pool
->bo
.size
);
612 anv_vma_free(device
, &pool
->bo
);
613 anv_gem_close(device
, pool
->bo
.gem_handle
);
615 anv_state_stream_finish(&pool
->surface_state_stream
);
617 list_for_each_entry_safe(struct anv_descriptor_set
, set
,
618 &pool
->desc_sets
, pool_link
) {
619 anv_descriptor_set_destroy(device
, pool
, set
);
622 util_vma_heap_finish(&pool
->bo_heap
);
624 vk_free2(&device
->alloc
, pAllocator
, pool
);
627 VkResult
anv_ResetDescriptorPool(
629 VkDescriptorPool descriptorPool
,
630 VkDescriptorPoolResetFlags flags
)
632 ANV_FROM_HANDLE(anv_device
, device
, _device
);
633 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, descriptorPool
);
635 list_for_each_entry_safe(struct anv_descriptor_set
, set
,
636 &pool
->desc_sets
, pool_link
) {
637 anv_descriptor_set_destroy(device
, pool
, set
);
641 pool
->free_list
= EMPTY
;
644 util_vma_heap_finish(&pool
->bo_heap
);
645 util_vma_heap_init(&pool
->bo_heap
, POOL_HEAP_OFFSET
, pool
->bo
.size
);
648 anv_state_stream_finish(&pool
->surface_state_stream
);
649 anv_state_stream_init(&pool
->surface_state_stream
,
650 &device
->surface_state_pool
, 4096);
651 pool
->surface_state_free_list
= NULL
;
656 struct pool_free_list_entry
{
662 anv_descriptor_pool_alloc_set(struct anv_descriptor_pool
*pool
,
664 struct anv_descriptor_set
**set
)
666 if (size
<= pool
->size
- pool
->next
) {
667 *set
= (struct anv_descriptor_set
*) (pool
->data
+ pool
->next
);
671 struct pool_free_list_entry
*entry
;
672 uint32_t *link
= &pool
->free_list
;
673 for (uint32_t f
= pool
->free_list
; f
!= EMPTY
; f
= entry
->next
) {
674 entry
= (struct pool_free_list_entry
*) (pool
->data
+ f
);
675 if (size
<= entry
->size
) {
677 *set
= (struct anv_descriptor_set
*) entry
;
683 if (pool
->free_list
!= EMPTY
) {
684 return vk_error(VK_ERROR_FRAGMENTED_POOL
);
686 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY
);
692 anv_descriptor_pool_free_set(struct anv_descriptor_pool
*pool
,
693 struct anv_descriptor_set
*set
)
695 /* Put the descriptor set allocation back on the free list. */
696 const uint32_t index
= (char *) set
- pool
->data
;
697 if (index
+ set
->size
== pool
->next
) {
700 struct pool_free_list_entry
*entry
= (struct pool_free_list_entry
*) set
;
701 entry
->next
= pool
->free_list
;
702 entry
->size
= set
->size
;
703 pool
->free_list
= (char *) entry
- pool
->data
;
706 list_del(&set
->pool_link
);
709 struct surface_state_free_list_entry
{
711 struct anv_state state
;
714 static struct anv_state
715 anv_descriptor_pool_alloc_state(struct anv_descriptor_pool
*pool
)
717 struct surface_state_free_list_entry
*entry
=
718 pool
->surface_state_free_list
;
721 struct anv_state state
= entry
->state
;
722 pool
->surface_state_free_list
= entry
->next
;
723 assert(state
.alloc_size
== 64);
726 return anv_state_stream_alloc(&pool
->surface_state_stream
, 64, 64);
731 anv_descriptor_pool_free_state(struct anv_descriptor_pool
*pool
,
732 struct anv_state state
)
734 /* Put the buffer view surface state back on the free list. */
735 struct surface_state_free_list_entry
*entry
= state
.map
;
736 entry
->next
= pool
->surface_state_free_list
;
737 entry
->state
= state
;
738 pool
->surface_state_free_list
= entry
;
742 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout
*layout
)
745 sizeof(struct anv_descriptor_set
) +
746 layout
->size
* sizeof(struct anv_descriptor
) +
747 layout
->buffer_view_count
* sizeof(struct anv_buffer_view
);
751 anv_descriptor_set_create(struct anv_device
*device
,
752 struct anv_descriptor_pool
*pool
,
753 struct anv_descriptor_set_layout
*layout
,
754 struct anv_descriptor_set
**out_set
)
756 struct anv_descriptor_set
*set
;
757 const size_t size
= anv_descriptor_set_layout_size(layout
);
759 VkResult result
= anv_descriptor_pool_alloc_set(pool
, size
, &set
);
760 if (result
!= VK_SUCCESS
)
763 if (layout
->descriptor_buffer_size
) {
764 /* Align the size to 32 so that alignment gaps don't cause extra holes
765 * in the heap which can lead to bad performance.
767 uint64_t pool_vma_offset
=
768 util_vma_heap_alloc(&pool
->bo_heap
,
769 ALIGN(layout
->descriptor_buffer_size
, 32), 32);
770 if (pool_vma_offset
== 0) {
771 anv_descriptor_pool_free_set(pool
, set
);
772 return vk_error(VK_ERROR_FRAGMENTED_POOL
);
774 assert(pool_vma_offset
>= POOL_HEAP_OFFSET
&&
775 pool_vma_offset
- POOL_HEAP_OFFSET
<= INT32_MAX
);
776 set
->desc_mem
.offset
= pool_vma_offset
- POOL_HEAP_OFFSET
;
777 set
->desc_mem
.alloc_size
= layout
->descriptor_buffer_size
;
778 set
->desc_mem
.map
= pool
->bo
.map
+ set
->desc_mem
.offset
;
780 set
->desc_surface_state
= anv_descriptor_pool_alloc_state(pool
);
781 anv_fill_buffer_surface_state(device
, set
->desc_surface_state
,
782 ISL_FORMAT_R32G32B32A32_FLOAT
,
783 (struct anv_address
) {
785 .offset
= set
->desc_mem
.offset
,
787 layout
->descriptor_buffer_size
, 1);
789 set
->desc_mem
= ANV_STATE_NULL
;
790 set
->desc_surface_state
= ANV_STATE_NULL
;
794 set
->layout
= layout
;
795 anv_descriptor_set_layout_ref(layout
);
799 (struct anv_buffer_view
*) &set
->descriptors
[layout
->size
];
800 set
->buffer_view_count
= layout
->buffer_view_count
;
802 /* By defining the descriptors to be zero now, we can later verify that
803 * a descriptor has not been populated with user data.
805 memset(set
->descriptors
, 0, sizeof(struct anv_descriptor
) * layout
->size
);
807 /* Go through and fill out immutable samplers if we have any */
808 struct anv_descriptor
*desc
= set
->descriptors
;
809 for (uint32_t b
= 0; b
< layout
->binding_count
; b
++) {
810 if (layout
->binding
[b
].immutable_samplers
) {
811 for (uint32_t i
= 0; i
< layout
->binding
[b
].array_size
; i
++) {
812 /* The type will get changed to COMBINED_IMAGE_SAMPLER in
813 * UpdateDescriptorSets if needed. However, if the descriptor
814 * set has an immutable sampler, UpdateDescriptorSets may never
815 * touch it, so we need to make sure it's 100% valid now.
817 desc
[i
] = (struct anv_descriptor
) {
818 .type
= VK_DESCRIPTOR_TYPE_SAMPLER
,
819 .sampler
= layout
->binding
[b
].immutable_samplers
[i
],
823 desc
+= layout
->binding
[b
].array_size
;
826 /* Allocate surface state for the buffer views. */
827 for (uint32_t b
= 0; b
< layout
->buffer_view_count
; b
++) {
828 set
->buffer_views
[b
].surface_state
=
829 anv_descriptor_pool_alloc_state(pool
);
838 anv_descriptor_set_destroy(struct anv_device
*device
,
839 struct anv_descriptor_pool
*pool
,
840 struct anv_descriptor_set
*set
)
842 anv_descriptor_set_layout_unref(device
, set
->layout
);
844 if (set
->desc_mem
.alloc_size
) {
845 util_vma_heap_free(&pool
->bo_heap
,
846 (uint64_t)set
->desc_mem
.offset
+ POOL_HEAP_OFFSET
,
847 set
->desc_mem
.alloc_size
);
848 anv_descriptor_pool_free_state(pool
, set
->desc_surface_state
);
851 for (uint32_t b
= 0; b
< set
->buffer_view_count
; b
++)
852 anv_descriptor_pool_free_state(pool
, set
->buffer_views
[b
].surface_state
);
854 anv_descriptor_pool_free_set(pool
, set
);
857 VkResult
anv_AllocateDescriptorSets(
859 const VkDescriptorSetAllocateInfo
* pAllocateInfo
,
860 VkDescriptorSet
* pDescriptorSets
)
862 ANV_FROM_HANDLE(anv_device
, device
, _device
);
863 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
865 VkResult result
= VK_SUCCESS
;
866 struct anv_descriptor_set
*set
;
869 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
870 ANV_FROM_HANDLE(anv_descriptor_set_layout
, layout
,
871 pAllocateInfo
->pSetLayouts
[i
]);
873 result
= anv_descriptor_set_create(device
, pool
, layout
, &set
);
874 if (result
!= VK_SUCCESS
)
877 list_addtail(&set
->pool_link
, &pool
->desc_sets
);
879 pDescriptorSets
[i
] = anv_descriptor_set_to_handle(set
);
882 if (result
!= VK_SUCCESS
)
883 anv_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
889 VkResult
anv_FreeDescriptorSets(
891 VkDescriptorPool descriptorPool
,
893 const VkDescriptorSet
* pDescriptorSets
)
895 ANV_FROM_HANDLE(anv_device
, device
, _device
);
896 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, descriptorPool
);
898 for (uint32_t i
= 0; i
< count
; i
++) {
899 ANV_FROM_HANDLE(anv_descriptor_set
, set
, pDescriptorSets
[i
]);
904 anv_descriptor_set_destroy(device
, pool
, set
);
911 anv_descriptor_set_write_image_param(uint32_t *param_desc_map
,
912 const struct brw_image_param
*param
)
914 #define WRITE_PARAM_FIELD(field, FIELD) \
915 for (unsigned i = 0; i < ARRAY_SIZE(param->field); i++) \
916 param_desc_map[BRW_IMAGE_PARAM_##FIELD##_OFFSET + i] = param->field[i]
918 WRITE_PARAM_FIELD(offset
, OFFSET
);
919 WRITE_PARAM_FIELD(size
, SIZE
);
920 WRITE_PARAM_FIELD(stride
, STRIDE
);
921 WRITE_PARAM_FIELD(tiling
, TILING
);
922 WRITE_PARAM_FIELD(swizzling
, SWIZZLING
);
923 WRITE_PARAM_FIELD(size
, SIZE
);
925 #undef WRITE_PARAM_FIELD
929 anv_descriptor_set_write_image_view(struct anv_device
*device
,
930 struct anv_descriptor_set
*set
,
931 const VkDescriptorImageInfo
* const info
,
932 VkDescriptorType type
,
936 const struct anv_descriptor_set_binding_layout
*bind_layout
=
937 &set
->layout
->binding
[binding
];
938 struct anv_descriptor
*desc
=
939 &set
->descriptors
[bind_layout
->descriptor_index
+ element
];
940 struct anv_image_view
*image_view
= NULL
;
941 struct anv_sampler
*sampler
= NULL
;
943 assert(type
== bind_layout
->type
);
946 case VK_DESCRIPTOR_TYPE_SAMPLER
:
947 sampler
= anv_sampler_from_handle(info
->sampler
);
950 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
951 image_view
= anv_image_view_from_handle(info
->imageView
);
952 sampler
= anv_sampler_from_handle(info
->sampler
);
955 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
956 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
957 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
958 image_view
= anv_image_view_from_handle(info
->imageView
);
962 unreachable("invalid descriptor type");
965 /* If this descriptor has an immutable sampler, we don't want to stomp on
968 sampler
= bind_layout
->immutable_samplers
?
969 bind_layout
->immutable_samplers
[element
] :
972 *desc
= (struct anv_descriptor
) {
974 .layout
= info
->imageLayout
,
975 .image_view
= image_view
,
979 void *desc_map
= set
->desc_mem
.map
+ bind_layout
->descriptor_offset
+
980 element
* anv_descriptor_size(bind_layout
);
982 if (bind_layout
->data
& ANV_DESCRIPTOR_IMAGE_PARAM
) {
983 /* Storage images can only ever have one plane */
984 assert(image_view
->n_planes
== 1);
985 const struct brw_image_param
*image_param
=
986 &image_view
->planes
[0].storage_image_param
;
988 anv_descriptor_set_write_image_param(desc_map
, image_param
);
993 anv_descriptor_set_write_buffer_view(struct anv_device
*device
,
994 struct anv_descriptor_set
*set
,
995 VkDescriptorType type
,
996 struct anv_buffer_view
*buffer_view
,
1000 const struct anv_descriptor_set_binding_layout
*bind_layout
=
1001 &set
->layout
->binding
[binding
];
1002 struct anv_descriptor
*desc
=
1003 &set
->descriptors
[bind_layout
->descriptor_index
+ element
];
1005 assert(type
== bind_layout
->type
);
1007 *desc
= (struct anv_descriptor
) {
1009 .buffer_view
= buffer_view
,
1012 void *desc_map
= set
->desc_mem
.map
+ bind_layout
->descriptor_offset
+
1013 element
* anv_descriptor_size(bind_layout
);
1015 if (bind_layout
->data
& ANV_DESCRIPTOR_IMAGE_PARAM
) {
1016 anv_descriptor_set_write_image_param(desc_map
,
1017 &buffer_view
->storage_image_param
);
1022 anv_descriptor_set_write_buffer(struct anv_device
*device
,
1023 struct anv_descriptor_set
*set
,
1024 struct anv_state_stream
*alloc_stream
,
1025 VkDescriptorType type
,
1026 struct anv_buffer
*buffer
,
1029 VkDeviceSize offset
,
1032 const struct anv_descriptor_set_binding_layout
*bind_layout
=
1033 &set
->layout
->binding
[binding
];
1034 struct anv_descriptor
*desc
=
1035 &set
->descriptors
[bind_layout
->descriptor_index
+ element
];
1037 assert(type
== bind_layout
->type
);
1039 if (type
== VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
||
1040 type
== VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
) {
1041 *desc
= (struct anv_descriptor
) {
1048 assert(bind_layout
->data
& ANV_DESCRIPTOR_BUFFER_VIEW
);
1049 struct anv_buffer_view
*bview
=
1050 &set
->buffer_views
[bind_layout
->buffer_view_index
+ element
];
1052 bview
->format
= anv_isl_format_for_descriptor_type(type
);
1053 bview
->range
= anv_buffer_get_range(buffer
, offset
, range
);
1054 bview
->address
= anv_address_add(buffer
->address
, offset
);
1056 /* If we're writing descriptors through a push command, we need to
1057 * allocate the surface state from the command buffer. Otherwise it will
1058 * be allocated by the descriptor pool when calling
1059 * vkAllocateDescriptorSets. */
1061 bview
->surface_state
= anv_state_stream_alloc(alloc_stream
, 64, 64);
1063 anv_fill_buffer_surface_state(device
, bview
->surface_state
,
1065 bview
->address
, bview
->range
, 1);
1067 *desc
= (struct anv_descriptor
) {
1069 .buffer_view
= bview
,
1075 anv_descriptor_set_write_inline_uniform_data(struct anv_device
*device
,
1076 struct anv_descriptor_set
*set
,
1082 const struct anv_descriptor_set_binding_layout
*bind_layout
=
1083 &set
->layout
->binding
[binding
];
1085 assert(bind_layout
->data
& ANV_DESCRIPTOR_INLINE_UNIFORM
);
1087 void *desc_map
= set
->desc_mem
.map
+ bind_layout
->descriptor_offset
;
1089 memcpy(desc_map
+ offset
, data
, size
);
1092 void anv_UpdateDescriptorSets(
1094 uint32_t descriptorWriteCount
,
1095 const VkWriteDescriptorSet
* pDescriptorWrites
,
1096 uint32_t descriptorCopyCount
,
1097 const VkCopyDescriptorSet
* pDescriptorCopies
)
1099 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1101 for (uint32_t i
= 0; i
< descriptorWriteCount
; i
++) {
1102 const VkWriteDescriptorSet
*write
= &pDescriptorWrites
[i
];
1103 ANV_FROM_HANDLE(anv_descriptor_set
, set
, write
->dstSet
);
1105 switch (write
->descriptorType
) {
1106 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1107 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1108 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1109 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1110 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1111 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1112 anv_descriptor_set_write_image_view(device
, set
,
1113 write
->pImageInfo
+ j
,
1114 write
->descriptorType
,
1116 write
->dstArrayElement
+ j
);
1120 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1121 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1122 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1123 ANV_FROM_HANDLE(anv_buffer_view
, bview
,
1124 write
->pTexelBufferView
[j
]);
1126 anv_descriptor_set_write_buffer_view(device
, set
,
1127 write
->descriptorType
,
1130 write
->dstArrayElement
+ j
);
1134 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1135 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1136 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1137 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1138 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
1139 assert(write
->pBufferInfo
[j
].buffer
);
1140 ANV_FROM_HANDLE(anv_buffer
, buffer
, write
->pBufferInfo
[j
].buffer
);
1143 anv_descriptor_set_write_buffer(device
, set
,
1145 write
->descriptorType
,
1148 write
->dstArrayElement
+ j
,
1149 write
->pBufferInfo
[j
].offset
,
1150 write
->pBufferInfo
[j
].range
);
1154 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
: {
1155 const VkWriteDescriptorSetInlineUniformBlockEXT
*inline_write
=
1156 vk_find_struct_const(write
->pNext
,
1157 WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT
);
1158 assert(inline_write
->dataSize
== write
->descriptorCount
);
1159 anv_descriptor_set_write_inline_uniform_data(device
, set
,
1161 inline_write
->pData
,
1162 write
->dstArrayElement
,
1163 inline_write
->dataSize
);
1172 for (uint32_t i
= 0; i
< descriptorCopyCount
; i
++) {
1173 const VkCopyDescriptorSet
*copy
= &pDescriptorCopies
[i
];
1174 ANV_FROM_HANDLE(anv_descriptor_set
, src
, copy
->srcSet
);
1175 ANV_FROM_HANDLE(anv_descriptor_set
, dst
, copy
->dstSet
);
1177 const struct anv_descriptor_set_binding_layout
*src_layout
=
1178 &src
->layout
->binding
[copy
->srcBinding
];
1179 struct anv_descriptor
*src_desc
=
1180 &src
->descriptors
[src_layout
->descriptor_index
];
1181 src_desc
+= copy
->srcArrayElement
;
1183 const struct anv_descriptor_set_binding_layout
*dst_layout
=
1184 &dst
->layout
->binding
[copy
->dstBinding
];
1185 struct anv_descriptor
*dst_desc
=
1186 &dst
->descriptors
[dst_layout
->descriptor_index
];
1187 dst_desc
+= copy
->dstArrayElement
;
1189 for (uint32_t j
= 0; j
< copy
->descriptorCount
; j
++)
1190 dst_desc
[j
] = src_desc
[j
];
1192 if (src_layout
->data
& ANV_DESCRIPTOR_INLINE_UNIFORM
) {
1193 assert(src_layout
->data
== ANV_DESCRIPTOR_INLINE_UNIFORM
);
1194 memcpy(dst
->desc_mem
.map
+ dst_layout
->descriptor_offset
+
1195 copy
->dstArrayElement
,
1196 src
->desc_mem
.map
+ src_layout
->descriptor_offset
+
1197 copy
->srcArrayElement
,
1198 copy
->descriptorCount
);
1200 unsigned desc_size
= anv_descriptor_size(src_layout
);
1201 if (desc_size
> 0) {
1202 assert(desc_size
== anv_descriptor_size(dst_layout
));
1203 memcpy(dst
->desc_mem
.map
+ dst_layout
->descriptor_offset
+
1204 copy
->dstArrayElement
* desc_size
,
1205 src
->desc_mem
.map
+ src_layout
->descriptor_offset
+
1206 copy
->srcArrayElement
* desc_size
,
1207 copy
->descriptorCount
* desc_size
);
1214 * Descriptor update templates.
1218 anv_descriptor_set_write_template(struct anv_device
*device
,
1219 struct anv_descriptor_set
*set
,
1220 struct anv_state_stream
*alloc_stream
,
1221 const struct anv_descriptor_update_template
*template,
1224 for (uint32_t i
= 0; i
< template->entry_count
; i
++) {
1225 const struct anv_descriptor_template_entry
*entry
=
1226 &template->entries
[i
];
1228 switch (entry
->type
) {
1229 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1230 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1231 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1232 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1233 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1234 for (uint32_t j
= 0; j
< entry
->array_count
; j
++) {
1235 const VkDescriptorImageInfo
*info
=
1236 data
+ entry
->offset
+ j
* entry
->stride
;
1237 anv_descriptor_set_write_image_view(device
, set
,
1240 entry
->array_element
+ j
);
1244 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1245 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1246 for (uint32_t j
= 0; j
< entry
->array_count
; j
++) {
1247 const VkBufferView
*_bview
=
1248 data
+ entry
->offset
+ j
* entry
->stride
;
1249 ANV_FROM_HANDLE(anv_buffer_view
, bview
, *_bview
);
1251 anv_descriptor_set_write_buffer_view(device
, set
,
1255 entry
->array_element
+ j
);
1259 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1260 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1261 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1262 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1263 for (uint32_t j
= 0; j
< entry
->array_count
; j
++) {
1264 const VkDescriptorBufferInfo
*info
=
1265 data
+ entry
->offset
+ j
* entry
->stride
;
1266 ANV_FROM_HANDLE(anv_buffer
, buffer
, info
->buffer
);
1268 anv_descriptor_set_write_buffer(device
, set
,
1273 entry
->array_element
+ j
,
1274 info
->offset
, info
->range
);
1278 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
:
1279 anv_descriptor_set_write_inline_uniform_data(device
, set
,
1281 data
+ entry
->offset
,
1282 entry
->array_element
,
1283 entry
->array_count
);
1292 VkResult
anv_CreateDescriptorUpdateTemplate(
1294 const VkDescriptorUpdateTemplateCreateInfo
* pCreateInfo
,
1295 const VkAllocationCallbacks
* pAllocator
,
1296 VkDescriptorUpdateTemplate
* pDescriptorUpdateTemplate
)
1298 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1299 struct anv_descriptor_update_template
*template;
1301 size_t size
= sizeof(*template) +
1302 pCreateInfo
->descriptorUpdateEntryCount
* sizeof(template->entries
[0]);
1303 template = vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1304 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1305 if (template == NULL
)
1306 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1308 template->bind_point
= pCreateInfo
->pipelineBindPoint
;
1310 if (pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET
)
1311 template->set
= pCreateInfo
->set
;
1313 template->entry_count
= pCreateInfo
->descriptorUpdateEntryCount
;
1314 for (uint32_t i
= 0; i
< template->entry_count
; i
++) {
1315 const VkDescriptorUpdateTemplateEntry
*pEntry
=
1316 &pCreateInfo
->pDescriptorUpdateEntries
[i
];
1318 template->entries
[i
] = (struct anv_descriptor_template_entry
) {
1319 .type
= pEntry
->descriptorType
,
1320 .binding
= pEntry
->dstBinding
,
1321 .array_element
= pEntry
->dstArrayElement
,
1322 .array_count
= pEntry
->descriptorCount
,
1323 .offset
= pEntry
->offset
,
1324 .stride
= pEntry
->stride
,
1328 *pDescriptorUpdateTemplate
=
1329 anv_descriptor_update_template_to_handle(template);
1334 void anv_DestroyDescriptorUpdateTemplate(
1336 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1337 const VkAllocationCallbacks
* pAllocator
)
1339 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1340 ANV_FROM_HANDLE(anv_descriptor_update_template
, template,
1341 descriptorUpdateTemplate
);
1343 vk_free2(&device
->alloc
, pAllocator
, template);
1346 void anv_UpdateDescriptorSetWithTemplate(
1348 VkDescriptorSet descriptorSet
,
1349 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1352 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1353 ANV_FROM_HANDLE(anv_descriptor_set
, set
, descriptorSet
);
1354 ANV_FROM_HANDLE(anv_descriptor_update_template
, template,
1355 descriptorUpdateTemplate
);
1357 anv_descriptor_set_write_template(device
, set
, NULL
, template, pData
);