2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
28 * We use the bindless descriptor model, which maps fairly closely to how
29 * Vulkan descriptor sets work. The two exceptions are input attachments and
30 * dynamic descriptors, which have to be patched when recording command
31 * buffers. We reserve an extra descriptor set for these. This descriptor set
32 * contains all the input attachments in the pipeline, in order, and then all
33 * the dynamic descriptors. The dynamic descriptors are stored in the CPU-side
34 * datastructure for each tu_descriptor_set, and then combined into one big
35 * descriptor set at CmdBindDescriptors time/draw time.
38 #include "tu_private.h"
46 #include "util/mesa-sha1.h"
50 binding_compare(const void *av
, const void *bv
)
52 const VkDescriptorSetLayoutBinding
*a
=
53 (const VkDescriptorSetLayoutBinding
*) av
;
54 const VkDescriptorSetLayoutBinding
*b
=
55 (const VkDescriptorSetLayoutBinding
*) bv
;
57 return (a
->binding
< b
->binding
) ? -1 : (a
->binding
> b
->binding
) ? 1 : 0;
60 static VkDescriptorSetLayoutBinding
*
61 create_sorted_bindings(const VkDescriptorSetLayoutBinding
*bindings
,
64 VkDescriptorSetLayoutBinding
*sorted_bindings
=
65 malloc(count
* sizeof(VkDescriptorSetLayoutBinding
));
69 memcpy(sorted_bindings
, bindings
,
70 count
* sizeof(VkDescriptorSetLayoutBinding
));
72 qsort(sorted_bindings
, count
, sizeof(VkDescriptorSetLayoutBinding
),
75 return sorted_bindings
;
79 descriptor_size(VkDescriptorType type
)
82 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
83 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
84 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
85 /* These are remapped to the special driver-managed descriptor set,
86 * hence they don't take up any space in the original descriptor set:
89 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
90 /* We make offsets and sizes all 16 dwords, to match how the hardware
91 * interprets indices passed to sample/load/store instructions in
92 * multiples of 16 dwords. This means that "normal" descriptors are all
93 * of size 16, with padding for smaller descriptors like uniform storage
94 * descriptors which are less than 16 dwords. However combined images
95 * and samplers are actually two descriptors, so they have size 2.
97 return A6XX_TEX_CONST_DWORDS
* 4 * 2;
99 return A6XX_TEX_CONST_DWORDS
* 4;
104 tu_CreateDescriptorSetLayout(
106 const VkDescriptorSetLayoutCreateInfo
*pCreateInfo
,
107 const VkAllocationCallbacks
*pAllocator
,
108 VkDescriptorSetLayout
*pSetLayout
)
110 TU_FROM_HANDLE(tu_device
, device
, _device
);
111 struct tu_descriptor_set_layout
*set_layout
;
113 assert(pCreateInfo
->sType
==
114 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
115 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
116 vk_find_struct_const(
118 DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
120 uint32_t max_binding
= 0;
121 uint32_t immutable_sampler_count
= 0;
122 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
123 max_binding
= MAX2(max_binding
, pCreateInfo
->pBindings
[j
].binding
);
124 if ((pCreateInfo
->pBindings
[j
].descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
||
125 pCreateInfo
->pBindings
[j
].descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
) &&
126 pCreateInfo
->pBindings
[j
].pImmutableSamplers
) {
127 immutable_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
131 uint32_t samplers_offset
= sizeof(struct tu_descriptor_set_layout
) +
132 (max_binding
+ 1) * sizeof(set_layout
->binding
[0]);
133 uint32_t size
= samplers_offset
+ immutable_sampler_count
* A6XX_TEX_SAMP_DWORDS
* 4;
135 set_layout
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
136 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
138 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
140 set_layout
->flags
= pCreateInfo
->flags
;
142 /* We just allocate all the immutable samplers at the end of the struct */
143 struct tu_sampler
*samplers
= (void*) &set_layout
->binding
[max_binding
+ 1];
145 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(
146 pCreateInfo
->pBindings
, pCreateInfo
->bindingCount
);
148 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
149 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
152 set_layout
->binding_count
= max_binding
+ 1;
153 set_layout
->shader_stages
= 0;
154 set_layout
->has_immutable_samplers
= false;
155 set_layout
->size
= 0;
156 set_layout
->dynamic_ubo
= 0;
158 memset(set_layout
->binding
, 0,
159 size
- sizeof(struct tu_descriptor_set_layout
));
161 uint32_t dynamic_offset_count
= 0;
162 uint32_t input_attachment_count
= 0;
163 uint32_t buffer_count
= 0;
165 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
166 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ j
;
167 uint32_t b
= binding
->binding
;
169 set_layout
->binding
[b
].type
= binding
->descriptorType
;
170 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
171 set_layout
->binding
[b
].offset
= set_layout
->size
;
172 set_layout
->binding
[b
].buffer_offset
= buffer_count
;
173 set_layout
->binding
[b
].dynamic_offset_offset
= dynamic_offset_count
;
174 set_layout
->binding
[b
].input_attachment_offset
= input_attachment_count
;
175 set_layout
->binding
[b
].size
= descriptor_size(binding
->descriptorType
);
176 set_layout
->binding
[b
].shader_stages
= binding
->stageFlags
;
178 if (variable_flags
&& binding
->binding
< variable_flags
->bindingCount
&&
179 (variable_flags
->pBindingFlags
[binding
->binding
] &
180 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
181 assert(!binding
->pImmutableSamplers
); /* Terribly ill defined how
182 many samplers are valid */
183 assert(binding
->binding
== max_binding
);
185 set_layout
->has_variable_descriptors
= true;
188 if ((binding
->descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
||
189 binding
->descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
) &&
190 binding
->pImmutableSamplers
) {
191 set_layout
->binding
[b
].immutable_samplers_offset
= samplers_offset
;
192 set_layout
->has_immutable_samplers
= true;
194 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
195 samplers
[i
] = *tu_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
197 samplers
+= binding
->descriptorCount
;
198 samplers_offset
+= sizeof(struct tu_sampler
) * binding
->descriptorCount
;
202 binding
->descriptorCount
* set_layout
->binding
[b
].size
;
203 if (binding
->descriptorType
!= VK_DESCRIPTOR_TYPE_SAMPLER
&&
204 binding
->descriptorType
!= VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
)
205 buffer_count
+= binding
->descriptorCount
;
206 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
||
207 binding
->descriptorType
== VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
) {
208 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
) {
209 STATIC_ASSERT(MAX_DYNAMIC_BUFFERS
<= 8 * sizeof(set_layout
->dynamic_ubo
));
210 set_layout
->dynamic_ubo
|=
211 ((1u << binding
->descriptorCount
) - 1) << dynamic_offset_count
;
214 dynamic_offset_count
+= binding
->descriptorCount
;
216 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
)
217 input_attachment_count
+= binding
->descriptorCount
;
218 set_layout
->shader_stages
|= binding
->stageFlags
;
223 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
224 set_layout
->input_attachment_count
= input_attachment_count
;
225 set_layout
->buffer_count
= buffer_count
;
227 *pSetLayout
= tu_descriptor_set_layout_to_handle(set_layout
);
233 tu_DestroyDescriptorSetLayout(VkDevice _device
,
234 VkDescriptorSetLayout _set_layout
,
235 const VkAllocationCallbacks
*pAllocator
)
237 TU_FROM_HANDLE(tu_device
, device
, _device
);
238 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
, _set_layout
);
243 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
247 tu_GetDescriptorSetLayoutSupport(
249 const VkDescriptorSetLayoutCreateInfo
*pCreateInfo
,
250 VkDescriptorSetLayoutSupport
*pSupport
)
252 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(
253 pCreateInfo
->pBindings
, pCreateInfo
->bindingCount
);
255 pSupport
->supported
= false;
259 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
260 vk_find_struct_const(
262 DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
263 VkDescriptorSetVariableDescriptorCountLayoutSupportEXT
*variable_count
=
265 (void *) pCreateInfo
->pNext
,
266 DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT
);
267 if (variable_count
) {
268 variable_count
->maxVariableDescriptorCount
= 0;
271 bool supported
= true;
273 for (uint32_t i
= 0; i
< pCreateInfo
->bindingCount
; i
++) {
274 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ i
;
276 uint64_t descriptor_sz
= descriptor_size(binding
->descriptorType
);
277 uint64_t descriptor_alignment
= 8;
279 if (size
&& !align_u64(size
, descriptor_alignment
)) {
282 size
= align_u64(size
, descriptor_alignment
);
284 uint64_t max_count
= UINT64_MAX
;
286 max_count
= (UINT64_MAX
- size
) / descriptor_sz
;
288 if (max_count
< binding
->descriptorCount
) {
291 if (variable_flags
&& binding
->binding
< variable_flags
->bindingCount
&&
293 (variable_flags
->pBindingFlags
[binding
->binding
] &
294 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
295 variable_count
->maxVariableDescriptorCount
=
296 MIN2(UINT32_MAX
, max_count
);
298 size
+= binding
->descriptorCount
* descriptor_sz
;
303 pSupport
->supported
= supported
;
307 * Pipeline layouts. These have nothing to do with the pipeline. They are
308 * just multiple descriptor set layouts pasted together.
312 tu_CreatePipelineLayout(VkDevice _device
,
313 const VkPipelineLayoutCreateInfo
*pCreateInfo
,
314 const VkAllocationCallbacks
*pAllocator
,
315 VkPipelineLayout
*pPipelineLayout
)
317 TU_FROM_HANDLE(tu_device
, device
, _device
);
318 struct tu_pipeline_layout
*layout
;
319 struct mesa_sha1 ctx
;
321 assert(pCreateInfo
->sType
==
322 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
324 layout
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
325 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
327 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
329 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
330 layout
->input_attachment_count
= 0;
331 layout
->dynamic_offset_count
= 0;
333 unsigned dynamic_offset_count
= 0, input_attachment_count
= 0;
335 _mesa_sha1_init(&ctx
);
336 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
337 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
,
338 pCreateInfo
->pSetLayouts
[set
]);
339 layout
->set
[set
].layout
= set_layout
;
340 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
341 layout
->set
[set
].input_attachment_start
= input_attachment_count
;
342 dynamic_offset_count
+= set_layout
->dynamic_offset_count
;
343 input_attachment_count
+= set_layout
->input_attachment_count
;
345 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
346 if (set_layout
->binding
[b
].immutable_samplers_offset
)
349 tu_immutable_samplers(set_layout
, set_layout
->binding
+ b
),
350 set_layout
->binding
[b
].array_size
* 4 * sizeof(uint32_t));
353 &ctx
, set_layout
->binding
,
354 sizeof(set_layout
->binding
[0]) * set_layout
->binding_count
);
357 layout
->dynamic_offset_count
= dynamic_offset_count
;
358 layout
->input_attachment_count
= input_attachment_count
;
359 layout
->push_constant_size
= 0;
361 for (unsigned i
= 0; i
< pCreateInfo
->pushConstantRangeCount
; ++i
) {
362 const VkPushConstantRange
*range
= pCreateInfo
->pPushConstantRanges
+ i
;
363 layout
->push_constant_size
=
364 MAX2(layout
->push_constant_size
, range
->offset
+ range
->size
);
367 layout
->push_constant_size
= align(layout
->push_constant_size
, 16);
368 _mesa_sha1_update(&ctx
, &layout
->push_constant_size
,
369 sizeof(layout
->push_constant_size
));
370 _mesa_sha1_final(&ctx
, layout
->sha1
);
371 *pPipelineLayout
= tu_pipeline_layout_to_handle(layout
);
377 tu_DestroyPipelineLayout(VkDevice _device
,
378 VkPipelineLayout _pipelineLayout
,
379 const VkAllocationCallbacks
*pAllocator
)
381 TU_FROM_HANDLE(tu_device
, device
, _device
);
382 TU_FROM_HANDLE(tu_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
384 if (!pipeline_layout
)
386 vk_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
392 tu_descriptor_set_create(struct tu_device
*device
,
393 struct tu_descriptor_pool
*pool
,
394 const struct tu_descriptor_set_layout
*layout
,
395 const uint32_t *variable_count
,
396 struct tu_descriptor_set
**out_set
)
398 struct tu_descriptor_set
*set
;
399 uint32_t buffer_count
= layout
->buffer_count
;
400 if (variable_count
) {
402 if (layout
->binding
[layout
->binding_count
- 1].type
== VK_DESCRIPTOR_TYPE_SAMPLER
||
403 layout
->binding
[layout
->binding_count
- 1].type
== VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
)
405 buffer_count
= layout
->binding
[layout
->binding_count
- 1].buffer_offset
+
406 *variable_count
* stride
;
408 unsigned dynamic_offset
= sizeof(struct tu_descriptor_set
) +
409 sizeof(struct tu_bo
*) * buffer_count
;
410 unsigned mem_size
= dynamic_offset
+
411 A6XX_TEX_CONST_DWORDS
* 4 * (layout
->dynamic_offset_count
+
412 layout
->input_attachment_count
);;
414 if (pool
->host_memory_base
) {
415 if (pool
->host_memory_end
- pool
->host_memory_ptr
< mem_size
)
416 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
418 set
= (struct tu_descriptor_set
*)pool
->host_memory_ptr
;
419 pool
->host_memory_ptr
+= mem_size
;
421 set
= vk_alloc2(&device
->alloc
, NULL
, mem_size
, 8,
422 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
425 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
428 memset(set
, 0, mem_size
);
430 if (layout
->dynamic_offset_count
+ layout
->input_attachment_count
> 0) {
431 set
->dynamic_descriptors
= (uint32_t *)((uint8_t*)set
+ dynamic_offset
);
434 set
->layout
= layout
;
436 uint32_t layout_size
= layout
->size
;
437 if (variable_count
) {
438 assert(layout
->has_variable_descriptors
);
439 uint32_t stride
= layout
->binding
[layout
->binding_count
- 1].size
;
440 layout_size
= layout
->binding
[layout
->binding_count
- 1].offset
+
441 *variable_count
* stride
;
445 set
->size
= layout_size
;
447 if (!pool
->host_memory_base
&& pool
->entry_count
== pool
->max_entry_count
) {
448 vk_free2(&device
->alloc
, NULL
, set
);
449 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
452 /* try to allocate linearly first, so that we don't spend
453 * time looking for gaps if the app only allocates &
454 * resets via the pool. */
455 if (pool
->current_offset
+ layout_size
<= pool
->size
) {
456 set
->mapped_ptr
= (uint32_t*)(pool
->bo
.map
+ pool
->current_offset
);
457 set
->va
= pool
->bo
.iova
+ pool
->current_offset
;
458 if (!pool
->host_memory_base
) {
459 pool
->entries
[pool
->entry_count
].offset
= pool
->current_offset
;
460 pool
->entries
[pool
->entry_count
].size
= layout_size
;
461 pool
->entries
[pool
->entry_count
].set
= set
;
464 pool
->current_offset
+= layout_size
;
465 } else if (!pool
->host_memory_base
) {
469 for (index
= 0; index
< pool
->entry_count
; ++index
) {
470 if (pool
->entries
[index
].offset
- offset
>= layout_size
)
472 offset
= pool
->entries
[index
].offset
+ pool
->entries
[index
].size
;
475 if (pool
->size
- offset
< layout_size
) {
476 vk_free2(&device
->alloc
, NULL
, set
);
477 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
480 set
->mapped_ptr
= (uint32_t*)(pool
->bo
.map
+ offset
);
481 set
->va
= pool
->bo
.iova
+ offset
;
482 memmove(&pool
->entries
[index
+ 1], &pool
->entries
[index
],
483 sizeof(pool
->entries
[0]) * (pool
->entry_count
- index
));
484 pool
->entries
[index
].offset
= offset
;
485 pool
->entries
[index
].size
= layout_size
;
486 pool
->entries
[index
].set
= set
;
489 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
492 if (layout
->has_immutable_samplers
) {
493 for (unsigned i
= 0; i
< layout
->binding_count
; ++i
) {
494 if (!layout
->binding
[i
].immutable_samplers_offset
)
497 unsigned offset
= layout
->binding
[i
].offset
/ 4;
498 if (layout
->binding
[i
].type
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
499 offset
+= A6XX_TEX_CONST_DWORDS
;
501 const struct tu_sampler
*samplers
=
502 (const struct tu_sampler
*)((const char *)layout
+
503 layout
->binding
[i
].immutable_samplers_offset
);
504 for (unsigned j
= 0; j
< layout
->binding
[i
].array_size
; ++j
) {
505 memcpy(set
->mapped_ptr
+ offset
, samplers
+ j
,
506 sizeof(struct tu_sampler
));
507 offset
+= layout
->binding
[i
].size
/ 4;
517 tu_descriptor_set_destroy(struct tu_device
*device
,
518 struct tu_descriptor_pool
*pool
,
519 struct tu_descriptor_set
*set
,
522 assert(!pool
->host_memory_base
);
524 if (free_bo
&& set
->size
&& !pool
->host_memory_base
) {
525 uint32_t offset
= (uint8_t*)set
->mapped_ptr
- (uint8_t*)pool
->bo
.map
;
526 for (int i
= 0; i
< pool
->entry_count
; ++i
) {
527 if (pool
->entries
[i
].offset
== offset
) {
528 memmove(&pool
->entries
[i
], &pool
->entries
[i
+1],
529 sizeof(pool
->entries
[i
]) * (pool
->entry_count
- i
- 1));
535 vk_free2(&device
->alloc
, NULL
, set
);
539 tu_CreateDescriptorPool(VkDevice _device
,
540 const VkDescriptorPoolCreateInfo
*pCreateInfo
,
541 const VkAllocationCallbacks
*pAllocator
,
542 VkDescriptorPool
*pDescriptorPool
)
544 TU_FROM_HANDLE(tu_device
, device
, _device
);
545 struct tu_descriptor_pool
*pool
;
546 uint64_t size
= sizeof(struct tu_descriptor_pool
);
547 uint64_t bo_size
= 0, bo_count
= 0, dynamic_count
= 0;
549 for (unsigned i
= 0; i
< pCreateInfo
->poolSizeCount
; ++i
) {
550 if (pCreateInfo
->pPoolSizes
[i
].type
!= VK_DESCRIPTOR_TYPE_SAMPLER
)
551 bo_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
553 switch(pCreateInfo
->pPoolSizes
[i
].type
) {
554 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
555 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
556 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
557 dynamic_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
562 bo_size
+= descriptor_size(pCreateInfo
->pPoolSizes
[i
].type
) *
563 pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
566 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
567 uint64_t host_size
= pCreateInfo
->maxSets
* sizeof(struct tu_descriptor_set
);
568 host_size
+= sizeof(struct tu_bo
*) * bo_count
;
569 host_size
+= A6XX_TEX_CONST_DWORDS
* 4 * dynamic_count
;
572 size
+= sizeof(struct tu_descriptor_pool_entry
) * pCreateInfo
->maxSets
;
575 pool
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
576 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
578 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
580 memset(pool
, 0, sizeof(*pool
));
582 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
583 pool
->host_memory_base
= (uint8_t*)pool
+ sizeof(struct tu_descriptor_pool
);
584 pool
->host_memory_ptr
= pool
->host_memory_base
;
585 pool
->host_memory_end
= (uint8_t*)pool
+ size
;
591 ret
= tu_bo_init_new(device
, &pool
->bo
, bo_size
);
592 assert(ret
== VK_SUCCESS
);
594 ret
= tu_bo_map(device
, &pool
->bo
);
595 assert(ret
== VK_SUCCESS
);
597 pool
->size
= bo_size
;
598 pool
->max_entry_count
= pCreateInfo
->maxSets
;
600 *pDescriptorPool
= tu_descriptor_pool_to_handle(pool
);
605 tu_DestroyDescriptorPool(VkDevice _device
,
606 VkDescriptorPool _pool
,
607 const VkAllocationCallbacks
*pAllocator
)
609 TU_FROM_HANDLE(tu_device
, device
, _device
);
610 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, _pool
);
615 if (!pool
->host_memory_base
) {
616 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
617 tu_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
622 tu_bo_finish(device
, &pool
->bo
);
623 vk_free2(&device
->alloc
, pAllocator
, pool
);
627 tu_ResetDescriptorPool(VkDevice _device
,
628 VkDescriptorPool descriptorPool
,
629 VkDescriptorPoolResetFlags flags
)
631 TU_FROM_HANDLE(tu_device
, device
, _device
);
632 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, descriptorPool
);
634 if (!pool
->host_memory_base
) {
635 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
636 tu_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
638 pool
->entry_count
= 0;
641 pool
->current_offset
= 0;
642 pool
->host_memory_ptr
= pool
->host_memory_base
;
648 tu_AllocateDescriptorSets(VkDevice _device
,
649 const VkDescriptorSetAllocateInfo
*pAllocateInfo
,
650 VkDescriptorSet
*pDescriptorSets
)
652 TU_FROM_HANDLE(tu_device
, device
, _device
);
653 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
655 VkResult result
= VK_SUCCESS
;
657 struct tu_descriptor_set
*set
= NULL
;
659 const VkDescriptorSetVariableDescriptorCountAllocateInfoEXT
*variable_counts
=
660 vk_find_struct_const(pAllocateInfo
->pNext
, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT
);
661 const uint32_t zero
= 0;
663 /* allocate a set of buffers for each shader to contain descriptors */
664 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
665 TU_FROM_HANDLE(tu_descriptor_set_layout
, layout
,
666 pAllocateInfo
->pSetLayouts
[i
]);
668 const uint32_t *variable_count
= NULL
;
669 if (variable_counts
) {
670 if (i
< variable_counts
->descriptorSetCount
)
671 variable_count
= variable_counts
->pDescriptorCounts
+ i
;
673 variable_count
= &zero
;
676 assert(!(layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
678 result
= tu_descriptor_set_create(device
, pool
, layout
, variable_count
, &set
);
679 if (result
!= VK_SUCCESS
)
682 pDescriptorSets
[i
] = tu_descriptor_set_to_handle(set
);
685 if (result
!= VK_SUCCESS
) {
686 tu_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
688 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
689 pDescriptorSets
[i
] = VK_NULL_HANDLE
;
696 tu_FreeDescriptorSets(VkDevice _device
,
697 VkDescriptorPool descriptorPool
,
699 const VkDescriptorSet
*pDescriptorSets
)
701 TU_FROM_HANDLE(tu_device
, device
, _device
);
702 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, descriptorPool
);
704 for (uint32_t i
= 0; i
< count
; i
++) {
705 TU_FROM_HANDLE(tu_descriptor_set
, set
, pDescriptorSets
[i
]);
707 if (set
&& !pool
->host_memory_base
)
708 tu_descriptor_set_destroy(device
, pool
, set
, true);
713 static void write_texel_buffer_descriptor(struct tu_device
*device
,
714 struct tu_cmd_buffer
*cmd_buffer
,
716 struct tu_bo
**buffer_list
,
717 const VkBufferView buffer_view
)
719 TU_FROM_HANDLE(tu_buffer_view
, view
, buffer_view
);
721 memcpy(dst
, view
->descriptor
, sizeof(view
->descriptor
));
724 tu_bo_list_add(&cmd_buffer
->bo_list
, view
->buffer
->bo
, MSM_SUBMIT_BO_READ
);
726 *buffer_list
= view
->buffer
->bo
;
729 static uint32_t get_range(struct tu_buffer
*buf
, VkDeviceSize offset
,
732 if (range
== VK_WHOLE_SIZE
) {
733 return buf
->size
- offset
;
739 static void write_buffer_descriptor(struct tu_device
*device
,
740 struct tu_cmd_buffer
*cmd_buffer
,
742 struct tu_bo
**buffer_list
,
743 const VkDescriptorBufferInfo
*buffer_info
)
745 TU_FROM_HANDLE(tu_buffer
, buffer
, buffer_info
->buffer
);
747 uint64_t va
= tu_buffer_iova(buffer
) + buffer_info
->offset
;
748 uint32_t range
= get_range(buffer
, buffer_info
->offset
, buffer_info
->range
);
749 range
= ALIGN_POT(range
, 4) / 4;
751 A6XX_IBO_0_TILE_MODE(TILE6_LINEAR
) | A6XX_IBO_0_FMT(FMT6_32_UINT
);
754 A6XX_IBO_2_UNK4
| A6XX_IBO_2_TYPE(A6XX_TEX_1D
) | A6XX_IBO_2_UNK31
;
756 dst
[4] = A6XX_IBO_4_BASE_LO(va
);
757 dst
[5] = A6XX_IBO_5_BASE_HI(va
>> 32);
758 for (int i
= 6; i
< A6XX_TEX_CONST_DWORDS
; i
++)
762 tu_bo_list_add(&cmd_buffer
->bo_list
, buffer
->bo
, MSM_SUBMIT_BO_READ
);
764 *buffer_list
= buffer
->bo
;
767 static void write_ubo_descriptor(struct tu_device
*device
,
768 struct tu_cmd_buffer
*cmd_buffer
,
770 struct tu_bo
**buffer_list
,
771 const VkDescriptorBufferInfo
*buffer_info
)
773 TU_FROM_HANDLE(tu_buffer
, buffer
, buffer_info
->buffer
);
775 uint32_t range
= get_range(buffer
, buffer_info
->offset
, buffer_info
->range
);
776 /* The HW range is in vec4 units */
777 range
= ALIGN_POT(range
, 16) / 16;
778 uint64_t va
= tu_buffer_iova(buffer
) + buffer_info
->offset
;
779 dst
[0] = A6XX_UBO_0_BASE_LO(va
);
780 dst
[1] = A6XX_UBO_1_BASE_HI(va
>> 32) | A6XX_UBO_1_SIZE(range
);
783 tu_bo_list_add(&cmd_buffer
->bo_list
, buffer
->bo
, MSM_SUBMIT_BO_READ
);
785 *buffer_list
= buffer
->bo
;
789 write_image_descriptor(struct tu_device
*device
,
790 struct tu_cmd_buffer
*cmd_buffer
,
792 struct tu_bo
**buffer_list
,
793 VkDescriptorType descriptor_type
,
794 const VkDescriptorImageInfo
*image_info
)
796 TU_FROM_HANDLE(tu_image_view
, iview
, image_info
->imageView
);
798 if (descriptor_type
== VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
) {
799 memcpy(dst
, iview
->storage_descriptor
, sizeof(iview
->storage_descriptor
));
801 memcpy(dst
, iview
->descriptor
, sizeof(iview
->descriptor
));
805 tu_bo_list_add(&cmd_buffer
->bo_list
, iview
->image
->bo
, MSM_SUBMIT_BO_READ
);
807 *buffer_list
= iview
->image
->bo
;
811 write_combined_image_sampler_descriptor(struct tu_device
*device
,
812 struct tu_cmd_buffer
*cmd_buffer
,
813 unsigned sampler_offset
,
815 struct tu_bo
**buffer_list
,
816 VkDescriptorType descriptor_type
,
817 const VkDescriptorImageInfo
*image_info
,
820 TU_FROM_HANDLE(tu_sampler
, sampler
, image_info
->sampler
);
822 write_image_descriptor(device
, cmd_buffer
, dst
, buffer_list
,
823 descriptor_type
, image_info
);
824 /* copy over sampler state */
826 memcpy(dst
+ A6XX_TEX_CONST_DWORDS
, sampler
, sizeof(*sampler
));
831 write_sampler_descriptor(struct tu_device
*device
,
833 const VkDescriptorImageInfo
*image_info
)
835 TU_FROM_HANDLE(tu_sampler
, sampler
, image_info
->sampler
);
837 memcpy(dst
, sampler
, sizeof(*sampler
));
841 tu_update_descriptor_sets(struct tu_device
*device
,
842 struct tu_cmd_buffer
*cmd_buffer
,
843 VkDescriptorSet dstSetOverride
,
844 uint32_t descriptorWriteCount
,
845 const VkWriteDescriptorSet
*pDescriptorWrites
,
846 uint32_t descriptorCopyCount
,
847 const VkCopyDescriptorSet
*pDescriptorCopies
)
850 for (i
= 0; i
< descriptorWriteCount
; i
++) {
851 const VkWriteDescriptorSet
*writeset
= &pDescriptorWrites
[i
];
852 TU_FROM_HANDLE(tu_descriptor_set
, set
,
853 dstSetOverride
? dstSetOverride
: writeset
->dstSet
);
854 const struct tu_descriptor_set_binding_layout
*binding_layout
=
855 set
->layout
->binding
+ writeset
->dstBinding
;
856 uint32_t *ptr
= set
->mapped_ptr
;
857 struct tu_bo
**buffer_list
= set
->buffers
;
859 ptr
+= binding_layout
->offset
/ 4;
861 ptr
+= (binding_layout
->size
/ 4) * writeset
->dstArrayElement
;
862 buffer_list
+= binding_layout
->buffer_offset
;
863 buffer_list
+= writeset
->dstArrayElement
;
864 for (j
= 0; j
< writeset
->descriptorCount
; ++j
) {
865 switch(writeset
->descriptorType
) {
866 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
: {
867 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
868 unsigned idx
= writeset
->dstArrayElement
+ j
;
869 idx
+= set
->layout
->input_attachment_count
+ binding_layout
->dynamic_offset_offset
;
870 write_ubo_descriptor(device
, cmd_buffer
,
871 set
->dynamic_descriptors
+ A6XX_TEX_CONST_DWORDS
* idx
,
872 buffer_list
, writeset
->pBufferInfo
+ j
);
875 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
876 write_ubo_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
877 writeset
->pBufferInfo
+ j
);
879 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
880 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
881 unsigned idx
= writeset
->dstArrayElement
+ j
;
882 idx
+= set
->layout
->input_attachment_count
+ binding_layout
->dynamic_offset_offset
;
883 write_buffer_descriptor(device
, cmd_buffer
,
884 set
->dynamic_descriptors
+ A6XX_TEX_CONST_DWORDS
* idx
,
885 buffer_list
, writeset
->pBufferInfo
+ j
);
888 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
889 write_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
890 writeset
->pBufferInfo
+ j
);
892 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
893 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
894 write_texel_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
895 writeset
->pTexelBufferView
[j
]);
897 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
898 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
899 write_image_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
900 writeset
->descriptorType
,
901 writeset
->pImageInfo
+ j
);
903 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
: {
904 unsigned idx
= writeset
->dstArrayElement
+ j
;
905 idx
+= binding_layout
->input_attachment_offset
;
906 write_image_descriptor(device
, cmd_buffer
,
907 set
->dynamic_descriptors
+ A6XX_TEX_CONST_DWORDS
* idx
,
908 buffer_list
, writeset
->descriptorType
,
909 writeset
->pImageInfo
+ j
);
912 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
913 write_combined_image_sampler_descriptor(device
, cmd_buffer
,
914 A6XX_TEX_CONST_DWORDS
* 4,
916 writeset
->descriptorType
,
917 writeset
->pImageInfo
+ j
,
918 !binding_layout
->immutable_samplers_offset
);
920 case VK_DESCRIPTOR_TYPE_SAMPLER
:
921 write_sampler_descriptor(device
, ptr
, writeset
->pImageInfo
+ j
);
924 unreachable("unimplemented descriptor type");
927 ptr
+= binding_layout
->size
/ 4;
932 for (i
= 0; i
< descriptorCopyCount
; i
++) {
933 const VkCopyDescriptorSet
*copyset
= &pDescriptorCopies
[i
];
934 TU_FROM_HANDLE(tu_descriptor_set
, src_set
,
936 TU_FROM_HANDLE(tu_descriptor_set
, dst_set
,
938 const struct tu_descriptor_set_binding_layout
*src_binding_layout
=
939 src_set
->layout
->binding
+ copyset
->srcBinding
;
940 const struct tu_descriptor_set_binding_layout
*dst_binding_layout
=
941 dst_set
->layout
->binding
+ copyset
->dstBinding
;
942 uint32_t *src_ptr
= src_set
->mapped_ptr
;
943 uint32_t *dst_ptr
= dst_set
->mapped_ptr
;
944 struct tu_bo
**src_buffer_list
= src_set
->buffers
;
945 struct tu_bo
**dst_buffer_list
= dst_set
->buffers
;
947 src_ptr
+= src_binding_layout
->offset
/ 4;
948 dst_ptr
+= dst_binding_layout
->offset
/ 4;
950 src_ptr
+= src_binding_layout
->size
* copyset
->srcArrayElement
/ 4;
951 dst_ptr
+= dst_binding_layout
->size
* copyset
->dstArrayElement
/ 4;
953 src_buffer_list
+= src_binding_layout
->buffer_offset
;
954 src_buffer_list
+= copyset
->srcArrayElement
;
956 dst_buffer_list
+= dst_binding_layout
->buffer_offset
;
957 dst_buffer_list
+= copyset
->dstArrayElement
;
959 for (j
= 0; j
< copyset
->descriptorCount
; ++j
) {
960 switch (src_binding_layout
->type
) {
961 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
962 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
963 unsigned src_idx
= copyset
->srcArrayElement
+ j
;
964 unsigned dst_idx
= copyset
->dstArrayElement
+ j
;
965 src_idx
+= src_set
->layout
->input_attachment_count
;
966 dst_idx
+= dst_set
->layout
->input_attachment_count
;
967 src_idx
+= src_binding_layout
->dynamic_offset_offset
;
968 dst_idx
+= dst_binding_layout
->dynamic_offset_offset
;
970 uint32_t *src_dynamic
, *dst_dynamic
;
971 src_dynamic
= src_set
->dynamic_descriptors
+ src_idx
* A6XX_TEX_CONST_DWORDS
;
972 dst_dynamic
= dst_set
->dynamic_descriptors
+ dst_idx
* A6XX_TEX_CONST_DWORDS
;
973 memcpy(dst_dynamic
, src_dynamic
, A6XX_TEX_CONST_DWORDS
* 4);
976 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
: {
977 unsigned src_idx
= copyset
->srcArrayElement
+ j
;
978 unsigned dst_idx
= copyset
->dstArrayElement
+ j
;
979 src_idx
+= src_binding_layout
->input_attachment_offset
;
980 dst_idx
+= dst_binding_layout
->input_attachment_offset
;
982 uint32_t *src_dynamic
, *dst_dynamic
;
983 src_dynamic
= src_set
->dynamic_descriptors
+ src_idx
* A6XX_TEX_CONST_DWORDS
;
984 dst_dynamic
= dst_set
->dynamic_descriptors
+ dst_idx
* A6XX_TEX_CONST_DWORDS
;
985 memcpy(dst_dynamic
, src_dynamic
, A6XX_TEX_CONST_DWORDS
* 4);
989 memcpy(dst_ptr
, src_ptr
, src_binding_layout
->size
);
992 src_ptr
+= src_binding_layout
->size
/ 4;
993 dst_ptr
+= dst_binding_layout
->size
/ 4;
995 if (src_binding_layout
->type
!= VK_DESCRIPTOR_TYPE_SAMPLER
) {
996 /* Sampler descriptors don't have a buffer list. */
997 dst_buffer_list
[j
] = src_buffer_list
[j
];
1004 tu_UpdateDescriptorSets(VkDevice _device
,
1005 uint32_t descriptorWriteCount
,
1006 const VkWriteDescriptorSet
*pDescriptorWrites
,
1007 uint32_t descriptorCopyCount
,
1008 const VkCopyDescriptorSet
*pDescriptorCopies
)
1010 TU_FROM_HANDLE(tu_device
, device
, _device
);
1012 tu_update_descriptor_sets(device
, NULL
, VK_NULL_HANDLE
,
1013 descriptorWriteCount
, pDescriptorWrites
,
1014 descriptorCopyCount
, pDescriptorCopies
);
1018 tu_CreateDescriptorUpdateTemplate(
1020 const VkDescriptorUpdateTemplateCreateInfo
*pCreateInfo
,
1021 const VkAllocationCallbacks
*pAllocator
,
1022 VkDescriptorUpdateTemplate
*pDescriptorUpdateTemplate
)
1024 TU_FROM_HANDLE(tu_device
, device
, _device
);
1025 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
,
1026 pCreateInfo
->descriptorSetLayout
);
1027 const uint32_t entry_count
= pCreateInfo
->descriptorUpdateEntryCount
;
1029 sizeof(struct tu_descriptor_update_template
) +
1030 sizeof(struct tu_descriptor_update_template_entry
) * entry_count
;
1031 struct tu_descriptor_update_template
*templ
;
1033 templ
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1034 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1036 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1038 templ
->entry_count
= entry_count
;
1040 if (pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR
) {
1041 TU_FROM_HANDLE(tu_pipeline_layout
, pipeline_layout
, pCreateInfo
->pipelineLayout
);
1043 /* descriptorSetLayout should be ignored for push descriptors
1044 * and instead it refers to pipelineLayout and set.
1046 assert(pCreateInfo
->set
< MAX_SETS
);
1047 set_layout
= pipeline_layout
->set
[pCreateInfo
->set
].layout
;
1050 for (uint32_t i
= 0; i
< entry_count
; i
++) {
1051 const VkDescriptorUpdateTemplateEntry
*entry
= &pCreateInfo
->pDescriptorUpdateEntries
[i
];
1053 const struct tu_descriptor_set_binding_layout
*binding_layout
=
1054 set_layout
->binding
+ entry
->dstBinding
;
1055 const uint32_t buffer_offset
= binding_layout
->buffer_offset
+
1056 entry
->dstArrayElement
;
1057 uint32_t dst_offset
, dst_stride
;
1059 /* dst_offset is an offset into dynamic_descriptors when the descriptor
1060 * is dynamic, and an offset into mapped_ptr otherwise.
1062 switch (entry
->descriptorType
) {
1063 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1064 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1065 dst_offset
= (set_layout
->input_attachment_count
+
1066 binding_layout
->dynamic_offset_offset
+
1067 entry
->dstArrayElement
) * A6XX_TEX_CONST_DWORDS
;
1068 dst_stride
= A6XX_TEX_CONST_DWORDS
;
1070 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1071 dst_offset
= (binding_layout
->input_attachment_offset
+
1072 entry
->dstArrayElement
) * A6XX_TEX_CONST_DWORDS
;
1073 dst_stride
= A6XX_TEX_CONST_DWORDS
;
1076 dst_offset
= binding_layout
->offset
/ 4;
1077 dst_offset
+= (binding_layout
->size
* entry
->dstArrayElement
) / 4;
1078 dst_stride
= binding_layout
->size
/ 4;
1081 templ
->entry
[i
] = (struct tu_descriptor_update_template_entry
) {
1082 .descriptor_type
= entry
->descriptorType
,
1083 .descriptor_count
= entry
->descriptorCount
,
1084 .src_offset
= entry
->offset
,
1085 .src_stride
= entry
->stride
,
1086 .dst_offset
= dst_offset
,
1087 .dst_stride
= dst_stride
,
1088 .buffer_offset
= buffer_offset
,
1089 .has_sampler
= !binding_layout
->immutable_samplers_offset
,
1093 *pDescriptorUpdateTemplate
=
1094 tu_descriptor_update_template_to_handle(templ
);
1100 tu_DestroyDescriptorUpdateTemplate(
1102 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1103 const VkAllocationCallbacks
*pAllocator
)
1105 TU_FROM_HANDLE(tu_device
, device
, _device
);
1106 TU_FROM_HANDLE(tu_descriptor_update_template
, templ
,
1107 descriptorUpdateTemplate
);
1112 vk_free2(&device
->alloc
, pAllocator
, templ
);
1116 tu_update_descriptor_set_with_template(
1117 struct tu_device
*device
,
1118 struct tu_cmd_buffer
*cmd_buffer
,
1119 struct tu_descriptor_set
*set
,
1120 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1123 TU_FROM_HANDLE(tu_descriptor_update_template
, templ
,
1124 descriptorUpdateTemplate
);
1126 for (uint32_t i
= 0; i
< templ
->entry_count
; i
++) {
1127 uint32_t *ptr
= set
->mapped_ptr
;
1128 const void *src
= ((const char *) pData
) + templ
->entry
[i
].src_offset
;
1129 struct tu_bo
**buffer_list
= set
->buffers
;
1131 ptr
+= templ
->entry
[i
].dst_offset
;
1132 buffer_list
+= templ
->entry
[i
].buffer_offset
;
1133 unsigned dst_offset
= templ
->entry
[i
].dst_offset
;
1134 for (unsigned j
= 0; j
< templ
->entry
[i
].descriptor_count
; ++j
) {
1135 switch(templ
->entry
[i
].descriptor_type
) {
1136 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
: {
1137 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
1138 write_ubo_descriptor(device
, cmd_buffer
,
1139 set
->dynamic_descriptors
+ dst_offset
,
1143 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1144 write_ubo_descriptor(device
, cmd_buffer
, ptr
, buffer_list
, src
);
1146 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
1147 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
1148 write_buffer_descriptor(device
, cmd_buffer
,
1149 set
->dynamic_descriptors
+ dst_offset
,
1153 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1154 write_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
, src
);
1156 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1157 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1158 write_texel_buffer_descriptor(device
, cmd_buffer
, ptr
,
1159 buffer_list
, *(VkBufferView
*) src
);
1161 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1162 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1163 write_image_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
1164 templ
->entry
[i
].descriptor_type
,
1167 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
: {
1168 write_image_descriptor(device
, cmd_buffer
,
1169 set
->dynamic_descriptors
+ dst_offset
,
1170 buffer_list
, templ
->entry
[i
].descriptor_type
,
1174 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1175 write_combined_image_sampler_descriptor(device
, cmd_buffer
,
1176 A6XX_TEX_CONST_DWORDS
* 4,
1178 templ
->entry
[i
].descriptor_type
,
1180 templ
->entry
[i
].has_sampler
);
1182 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1183 write_sampler_descriptor(device
, ptr
, src
);
1186 unreachable("unimplemented descriptor type");
1189 src
= (char *) src
+ templ
->entry
[i
].src_stride
;
1190 ptr
+= templ
->entry
[i
].dst_stride
;
1191 dst_offset
+= templ
->entry
[i
].dst_stride
;
1198 tu_UpdateDescriptorSetWithTemplate(
1200 VkDescriptorSet descriptorSet
,
1201 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1204 TU_FROM_HANDLE(tu_device
, device
, _device
);
1205 TU_FROM_HANDLE(tu_descriptor_set
, set
, descriptorSet
);
1207 tu_update_descriptor_set_with_template(device
, NULL
, set
,
1208 descriptorUpdateTemplate
, pData
);
1212 tu_CreateSamplerYcbcrConversion(
1214 const VkSamplerYcbcrConversionCreateInfo
*pCreateInfo
,
1215 const VkAllocationCallbacks
*pAllocator
,
1216 VkSamplerYcbcrConversion
*pYcbcrConversion
)
1218 *pYcbcrConversion
= VK_NULL_HANDLE
;
1223 tu_DestroySamplerYcbcrConversion(VkDevice device
,
1224 VkSamplerYcbcrConversion ycbcrConversion
,
1225 const VkAllocationCallbacks
*pAllocator
)