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:
87 * Input attachment doesn't use descriptor sets at all
90 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
91 /* We make offsets and sizes all 16 dwords, to match how the hardware
92 * interprets indices passed to sample/load/store instructions in
93 * multiples of 16 dwords. This means that "normal" descriptors are all
94 * of size 16, with padding for smaller descriptors like uniform storage
95 * descriptors which are less than 16 dwords. However combined images
96 * and samplers are actually two descriptors, so they have size 2.
98 return A6XX_TEX_CONST_DWORDS
* 4 * 2;
100 return A6XX_TEX_CONST_DWORDS
* 4;
105 tu_CreateDescriptorSetLayout(
107 const VkDescriptorSetLayoutCreateInfo
*pCreateInfo
,
108 const VkAllocationCallbacks
*pAllocator
,
109 VkDescriptorSetLayout
*pSetLayout
)
111 TU_FROM_HANDLE(tu_device
, device
, _device
);
112 struct tu_descriptor_set_layout
*set_layout
;
114 assert(pCreateInfo
->sType
==
115 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
116 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
117 vk_find_struct_const(
119 DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
121 uint32_t max_binding
= 0;
122 uint32_t immutable_sampler_count
= 0;
123 uint32_t ycbcr_sampler_count
= 0;
124 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
125 max_binding
= MAX2(max_binding
, pCreateInfo
->pBindings
[j
].binding
);
126 if ((pCreateInfo
->pBindings
[j
].descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
||
127 pCreateInfo
->pBindings
[j
].descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
) &&
128 pCreateInfo
->pBindings
[j
].pImmutableSamplers
) {
129 immutable_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
131 bool has_ycbcr_sampler
= false;
132 for (unsigned i
= 0; i
< pCreateInfo
->pBindings
[j
].descriptorCount
; ++i
) {
133 if (tu_sampler_from_handle(pCreateInfo
->pBindings
[j
].pImmutableSamplers
[i
])->ycbcr_sampler
)
134 has_ycbcr_sampler
= true;
137 if (has_ycbcr_sampler
)
138 ycbcr_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
142 uint32_t samplers_offset
=
143 offsetof(struct tu_descriptor_set_layout
, binding
[max_binding
+ 1]);
145 /* note: only need to store TEX_SAMP_DWORDS for immutable samples,
146 * but using struct tu_sampler makes things simpler */
147 uint32_t size
= samplers_offset
+
148 immutable_sampler_count
* sizeof(struct tu_sampler
) +
149 ycbcr_sampler_count
* sizeof(struct tu_sampler_ycbcr_conversion
);
151 set_layout
= vk_zalloc2(&device
->alloc
, pAllocator
, size
, 8,
152 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
154 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
156 set_layout
->flags
= pCreateInfo
->flags
;
158 /* We just allocate all the immutable samplers at the end of the struct */
159 struct tu_sampler
*samplers
= (void*) &set_layout
->binding
[max_binding
+ 1];
160 struct tu_sampler_ycbcr_conversion
*ycbcr_samplers
=
161 (void*) &samplers
[immutable_sampler_count
];
163 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(
164 pCreateInfo
->pBindings
, pCreateInfo
->bindingCount
);
166 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
167 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
170 set_layout
->binding_count
= max_binding
+ 1;
171 set_layout
->shader_stages
= 0;
172 set_layout
->has_immutable_samplers
= false;
173 set_layout
->size
= 0;
174 set_layout
->dynamic_ubo
= 0;
176 uint32_t dynamic_offset_count
= 0;
177 uint32_t buffer_count
= 0;
179 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
180 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ j
;
181 uint32_t b
= binding
->binding
;
183 set_layout
->binding
[b
].type
= binding
->descriptorType
;
184 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
185 set_layout
->binding
[b
].offset
= set_layout
->size
;
186 set_layout
->binding
[b
].buffer_offset
= buffer_count
;
187 set_layout
->binding
[b
].dynamic_offset_offset
= dynamic_offset_count
;
188 set_layout
->binding
[b
].size
= descriptor_size(binding
->descriptorType
);
189 set_layout
->binding
[b
].shader_stages
= binding
->stageFlags
;
191 if (variable_flags
&& binding
->binding
< variable_flags
->bindingCount
&&
192 (variable_flags
->pBindingFlags
[binding
->binding
] &
193 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
194 assert(!binding
->pImmutableSamplers
); /* Terribly ill defined how
195 many samplers are valid */
196 assert(binding
->binding
== max_binding
);
198 set_layout
->has_variable_descriptors
= true;
201 if ((binding
->descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
||
202 binding
->descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
) &&
203 binding
->pImmutableSamplers
) {
204 set_layout
->binding
[b
].immutable_samplers_offset
= samplers_offset
;
205 set_layout
->has_immutable_samplers
= true;
207 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
208 samplers
[i
] = *tu_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
210 samplers
+= binding
->descriptorCount
;
211 samplers_offset
+= sizeof(struct tu_sampler
) * binding
->descriptorCount
;
213 bool has_ycbcr_sampler
= false;
214 for (unsigned i
= 0; i
< pCreateInfo
->pBindings
[j
].descriptorCount
; ++i
) {
215 if (tu_sampler_from_handle(binding
->pImmutableSamplers
[i
])->ycbcr_sampler
)
216 has_ycbcr_sampler
= true;
219 if (has_ycbcr_sampler
) {
220 set_layout
->binding
[b
].ycbcr_samplers_offset
=
221 (const char*)ycbcr_samplers
- (const char*)set_layout
;
222 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++) {
223 struct tu_sampler
*sampler
= tu_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
224 if (sampler
->ycbcr_sampler
)
225 ycbcr_samplers
[i
] = *sampler
->ycbcr_sampler
;
227 ycbcr_samplers
[i
].ycbcr_model
= VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY
;
229 ycbcr_samplers
+= binding
->descriptorCount
;
231 set_layout
->binding
[b
].ycbcr_samplers_offset
= 0;
236 binding
->descriptorCount
* set_layout
->binding
[b
].size
;
237 if (binding
->descriptorType
!= VK_DESCRIPTOR_TYPE_SAMPLER
&&
238 binding
->descriptorType
!= VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
)
239 buffer_count
+= binding
->descriptorCount
;
240 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
||
241 binding
->descriptorType
== VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
) {
242 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
) {
243 STATIC_ASSERT(MAX_DYNAMIC_BUFFERS
<= 8 * sizeof(set_layout
->dynamic_ubo
));
244 set_layout
->dynamic_ubo
|=
245 ((1u << binding
->descriptorCount
) - 1) << dynamic_offset_count
;
248 dynamic_offset_count
+= binding
->descriptorCount
;
251 set_layout
->shader_stages
|= binding
->stageFlags
;
256 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
257 set_layout
->buffer_count
= buffer_count
;
259 *pSetLayout
= tu_descriptor_set_layout_to_handle(set_layout
);
265 tu_DestroyDescriptorSetLayout(VkDevice _device
,
266 VkDescriptorSetLayout _set_layout
,
267 const VkAllocationCallbacks
*pAllocator
)
269 TU_FROM_HANDLE(tu_device
, device
, _device
);
270 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
, _set_layout
);
275 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
279 tu_GetDescriptorSetLayoutSupport(
281 const VkDescriptorSetLayoutCreateInfo
*pCreateInfo
,
282 VkDescriptorSetLayoutSupport
*pSupport
)
284 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(
285 pCreateInfo
->pBindings
, pCreateInfo
->bindingCount
);
287 pSupport
->supported
= false;
291 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
292 vk_find_struct_const(
294 DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
295 VkDescriptorSetVariableDescriptorCountLayoutSupportEXT
*variable_count
=
297 (void *) pCreateInfo
->pNext
,
298 DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT
);
299 if (variable_count
) {
300 variable_count
->maxVariableDescriptorCount
= 0;
303 bool supported
= true;
305 for (uint32_t i
= 0; i
< pCreateInfo
->bindingCount
; i
++) {
306 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ i
;
308 uint64_t descriptor_sz
= descriptor_size(binding
->descriptorType
);
309 uint64_t descriptor_alignment
= 8;
311 if (size
&& !ALIGN_POT(size
, descriptor_alignment
)) {
314 size
= ALIGN_POT(size
, descriptor_alignment
);
316 uint64_t max_count
= UINT64_MAX
;
318 max_count
= (UINT64_MAX
- size
) / descriptor_sz
;
320 if (max_count
< binding
->descriptorCount
) {
323 if (variable_flags
&& binding
->binding
< variable_flags
->bindingCount
&&
325 (variable_flags
->pBindingFlags
[binding
->binding
] &
326 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
327 variable_count
->maxVariableDescriptorCount
=
328 MIN2(UINT32_MAX
, max_count
);
330 size
+= binding
->descriptorCount
* descriptor_sz
;
335 pSupport
->supported
= supported
;
339 * Pipeline layouts. These have nothing to do with the pipeline. They are
340 * just multiple descriptor set layouts pasted together.
344 tu_CreatePipelineLayout(VkDevice _device
,
345 const VkPipelineLayoutCreateInfo
*pCreateInfo
,
346 const VkAllocationCallbacks
*pAllocator
,
347 VkPipelineLayout
*pPipelineLayout
)
349 TU_FROM_HANDLE(tu_device
, device
, _device
);
350 struct tu_pipeline_layout
*layout
;
351 struct mesa_sha1 ctx
;
353 assert(pCreateInfo
->sType
==
354 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
356 layout
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
357 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
359 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
361 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
362 layout
->dynamic_offset_count
= 0;
364 unsigned dynamic_offset_count
= 0;
366 _mesa_sha1_init(&ctx
);
367 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
368 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
,
369 pCreateInfo
->pSetLayouts
[set
]);
370 layout
->set
[set
].layout
= set_layout
;
371 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
372 dynamic_offset_count
+= set_layout
->dynamic_offset_count
;
374 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
375 if (set_layout
->binding
[b
].immutable_samplers_offset
)
378 tu_immutable_samplers(set_layout
, set_layout
->binding
+ b
),
379 set_layout
->binding
[b
].array_size
* 4 * sizeof(uint32_t));
382 &ctx
, set_layout
->binding
,
383 sizeof(set_layout
->binding
[0]) * set_layout
->binding_count
);
386 layout
->dynamic_offset_count
= dynamic_offset_count
;
387 layout
->push_constant_size
= 0;
389 for (unsigned i
= 0; i
< pCreateInfo
->pushConstantRangeCount
; ++i
) {
390 const VkPushConstantRange
*range
= pCreateInfo
->pPushConstantRanges
+ i
;
391 layout
->push_constant_size
=
392 MAX2(layout
->push_constant_size
, range
->offset
+ range
->size
);
395 layout
->push_constant_size
= align(layout
->push_constant_size
, 16);
396 _mesa_sha1_update(&ctx
, &layout
->push_constant_size
,
397 sizeof(layout
->push_constant_size
));
398 _mesa_sha1_final(&ctx
, layout
->sha1
);
399 *pPipelineLayout
= tu_pipeline_layout_to_handle(layout
);
405 tu_DestroyPipelineLayout(VkDevice _device
,
406 VkPipelineLayout _pipelineLayout
,
407 const VkAllocationCallbacks
*pAllocator
)
409 TU_FROM_HANDLE(tu_device
, device
, _device
);
410 TU_FROM_HANDLE(tu_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
412 if (!pipeline_layout
)
414 vk_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
420 tu_descriptor_set_create(struct tu_device
*device
,
421 struct tu_descriptor_pool
*pool
,
422 const struct tu_descriptor_set_layout
*layout
,
423 const uint32_t *variable_count
,
424 struct tu_descriptor_set
**out_set
)
426 struct tu_descriptor_set
*set
;
427 uint32_t buffer_count
= layout
->buffer_count
;
428 if (variable_count
) {
430 if (layout
->binding
[layout
->binding_count
- 1].type
== VK_DESCRIPTOR_TYPE_SAMPLER
||
431 layout
->binding
[layout
->binding_count
- 1].type
== VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
)
433 buffer_count
= layout
->binding
[layout
->binding_count
- 1].buffer_offset
+
434 *variable_count
* stride
;
436 unsigned dynamic_offset
= sizeof(struct tu_descriptor_set
) +
437 sizeof(struct tu_bo
*) * buffer_count
;
438 unsigned mem_size
= dynamic_offset
+
439 A6XX_TEX_CONST_DWORDS
* 4 * layout
->dynamic_offset_count
;
441 if (pool
->host_memory_base
) {
442 if (pool
->host_memory_end
- pool
->host_memory_ptr
< mem_size
)
443 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
445 set
= (struct tu_descriptor_set
*)pool
->host_memory_ptr
;
446 pool
->host_memory_ptr
+= mem_size
;
448 set
= vk_alloc2(&device
->alloc
, NULL
, mem_size
, 8,
449 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
452 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
455 memset(set
, 0, mem_size
);
457 if (layout
->dynamic_offset_count
) {
458 set
->dynamic_descriptors
= (uint32_t *)((uint8_t*)set
+ dynamic_offset
);
461 set
->layout
= layout
;
463 uint32_t layout_size
= layout
->size
;
464 if (variable_count
) {
465 assert(layout
->has_variable_descriptors
);
466 uint32_t stride
= layout
->binding
[layout
->binding_count
- 1].size
;
467 layout_size
= layout
->binding
[layout
->binding_count
- 1].offset
+
468 *variable_count
* stride
;
472 set
->size
= layout_size
;
474 if (!pool
->host_memory_base
&& pool
->entry_count
== pool
->max_entry_count
) {
475 vk_free2(&device
->alloc
, NULL
, set
);
476 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
479 /* try to allocate linearly first, so that we don't spend
480 * time looking for gaps if the app only allocates &
481 * resets via the pool. */
482 if (pool
->current_offset
+ layout_size
<= pool
->size
) {
483 set
->mapped_ptr
= (uint32_t*)(pool
->bo
.map
+ pool
->current_offset
);
484 set
->va
= pool
->bo
.iova
+ pool
->current_offset
;
485 if (!pool
->host_memory_base
) {
486 pool
->entries
[pool
->entry_count
].offset
= pool
->current_offset
;
487 pool
->entries
[pool
->entry_count
].size
= layout_size
;
488 pool
->entries
[pool
->entry_count
].set
= set
;
491 pool
->current_offset
+= layout_size
;
492 } else if (!pool
->host_memory_base
) {
496 for (index
= 0; index
< pool
->entry_count
; ++index
) {
497 if (pool
->entries
[index
].offset
- offset
>= layout_size
)
499 offset
= pool
->entries
[index
].offset
+ pool
->entries
[index
].size
;
502 if (pool
->size
- offset
< layout_size
) {
503 vk_free2(&device
->alloc
, NULL
, set
);
504 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
507 set
->mapped_ptr
= (uint32_t*)(pool
->bo
.map
+ offset
);
508 set
->va
= pool
->bo
.iova
+ offset
;
509 memmove(&pool
->entries
[index
+ 1], &pool
->entries
[index
],
510 sizeof(pool
->entries
[0]) * (pool
->entry_count
- index
));
511 pool
->entries
[index
].offset
= offset
;
512 pool
->entries
[index
].size
= layout_size
;
513 pool
->entries
[index
].set
= set
;
516 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
519 if (layout
->has_immutable_samplers
) {
520 for (unsigned i
= 0; i
< layout
->binding_count
; ++i
) {
521 if (!layout
->binding
[i
].immutable_samplers_offset
)
524 unsigned offset
= layout
->binding
[i
].offset
/ 4;
525 if (layout
->binding
[i
].type
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
526 offset
+= A6XX_TEX_CONST_DWORDS
;
528 const struct tu_sampler
*samplers
=
529 (const struct tu_sampler
*)((const char *)layout
+
530 layout
->binding
[i
].immutable_samplers_offset
);
531 for (unsigned j
= 0; j
< layout
->binding
[i
].array_size
; ++j
) {
532 memcpy(set
->mapped_ptr
+ offset
, samplers
[j
].descriptor
,
533 sizeof(samplers
[j
].descriptor
));
534 offset
+= layout
->binding
[i
].size
/ 4;
544 tu_descriptor_set_destroy(struct tu_device
*device
,
545 struct tu_descriptor_pool
*pool
,
546 struct tu_descriptor_set
*set
,
549 assert(!pool
->host_memory_base
);
551 if (free_bo
&& set
->size
&& !pool
->host_memory_base
) {
552 uint32_t offset
= (uint8_t*)set
->mapped_ptr
- (uint8_t*)pool
->bo
.map
;
553 for (int i
= 0; i
< pool
->entry_count
; ++i
) {
554 if (pool
->entries
[i
].offset
== offset
) {
555 memmove(&pool
->entries
[i
], &pool
->entries
[i
+1],
556 sizeof(pool
->entries
[i
]) * (pool
->entry_count
- i
- 1));
562 vk_free2(&device
->alloc
, NULL
, set
);
566 tu_CreateDescriptorPool(VkDevice _device
,
567 const VkDescriptorPoolCreateInfo
*pCreateInfo
,
568 const VkAllocationCallbacks
*pAllocator
,
569 VkDescriptorPool
*pDescriptorPool
)
571 TU_FROM_HANDLE(tu_device
, device
, _device
);
572 struct tu_descriptor_pool
*pool
;
573 uint64_t size
= sizeof(struct tu_descriptor_pool
);
574 uint64_t bo_size
= 0, bo_count
= 0, dynamic_count
= 0;
576 for (unsigned i
= 0; i
< pCreateInfo
->poolSizeCount
; ++i
) {
577 if (pCreateInfo
->pPoolSizes
[i
].type
!= VK_DESCRIPTOR_TYPE_SAMPLER
)
578 bo_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
580 switch(pCreateInfo
->pPoolSizes
[i
].type
) {
581 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
582 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
583 dynamic_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
588 bo_size
+= descriptor_size(pCreateInfo
->pPoolSizes
[i
].type
) *
589 pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
592 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
593 uint64_t host_size
= pCreateInfo
->maxSets
* sizeof(struct tu_descriptor_set
);
594 host_size
+= sizeof(struct tu_bo
*) * bo_count
;
595 host_size
+= A6XX_TEX_CONST_DWORDS
* 4 * dynamic_count
;
598 size
+= sizeof(struct tu_descriptor_pool_entry
) * pCreateInfo
->maxSets
;
601 pool
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
602 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
604 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
606 memset(pool
, 0, sizeof(*pool
));
608 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
609 pool
->host_memory_base
= (uint8_t*)pool
+ sizeof(struct tu_descriptor_pool
);
610 pool
->host_memory_ptr
= pool
->host_memory_base
;
611 pool
->host_memory_end
= (uint8_t*)pool
+ size
;
617 ret
= tu_bo_init_new(device
, &pool
->bo
, bo_size
);
618 assert(ret
== VK_SUCCESS
);
620 ret
= tu_bo_map(device
, &pool
->bo
);
621 assert(ret
== VK_SUCCESS
);
623 pool
->size
= bo_size
;
624 pool
->max_entry_count
= pCreateInfo
->maxSets
;
626 *pDescriptorPool
= tu_descriptor_pool_to_handle(pool
);
631 tu_DestroyDescriptorPool(VkDevice _device
,
632 VkDescriptorPool _pool
,
633 const VkAllocationCallbacks
*pAllocator
)
635 TU_FROM_HANDLE(tu_device
, device
, _device
);
636 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, _pool
);
641 if (!pool
->host_memory_base
) {
642 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
643 tu_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
648 tu_bo_finish(device
, &pool
->bo
);
649 vk_free2(&device
->alloc
, pAllocator
, pool
);
653 tu_ResetDescriptorPool(VkDevice _device
,
654 VkDescriptorPool descriptorPool
,
655 VkDescriptorPoolResetFlags flags
)
657 TU_FROM_HANDLE(tu_device
, device
, _device
);
658 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, descriptorPool
);
660 if (!pool
->host_memory_base
) {
661 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
662 tu_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
664 pool
->entry_count
= 0;
667 pool
->current_offset
= 0;
668 pool
->host_memory_ptr
= pool
->host_memory_base
;
674 tu_AllocateDescriptorSets(VkDevice _device
,
675 const VkDescriptorSetAllocateInfo
*pAllocateInfo
,
676 VkDescriptorSet
*pDescriptorSets
)
678 TU_FROM_HANDLE(tu_device
, device
, _device
);
679 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
681 VkResult result
= VK_SUCCESS
;
683 struct tu_descriptor_set
*set
= NULL
;
685 const VkDescriptorSetVariableDescriptorCountAllocateInfoEXT
*variable_counts
=
686 vk_find_struct_const(pAllocateInfo
->pNext
, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT
);
687 const uint32_t zero
= 0;
689 /* allocate a set of buffers for each shader to contain descriptors */
690 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
691 TU_FROM_HANDLE(tu_descriptor_set_layout
, layout
,
692 pAllocateInfo
->pSetLayouts
[i
]);
694 const uint32_t *variable_count
= NULL
;
695 if (variable_counts
) {
696 if (i
< variable_counts
->descriptorSetCount
)
697 variable_count
= variable_counts
->pDescriptorCounts
+ i
;
699 variable_count
= &zero
;
702 assert(!(layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
704 result
= tu_descriptor_set_create(device
, pool
, layout
, variable_count
, &set
);
705 if (result
!= VK_SUCCESS
)
708 pDescriptorSets
[i
] = tu_descriptor_set_to_handle(set
);
711 if (result
!= VK_SUCCESS
) {
712 tu_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
714 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
715 pDescriptorSets
[i
] = VK_NULL_HANDLE
;
722 tu_FreeDescriptorSets(VkDevice _device
,
723 VkDescriptorPool descriptorPool
,
725 const VkDescriptorSet
*pDescriptorSets
)
727 TU_FROM_HANDLE(tu_device
, device
, _device
);
728 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, descriptorPool
);
730 for (uint32_t i
= 0; i
< count
; i
++) {
731 TU_FROM_HANDLE(tu_descriptor_set
, set
, pDescriptorSets
[i
]);
733 if (set
&& !pool
->host_memory_base
)
734 tu_descriptor_set_destroy(device
, pool
, set
, true);
739 static void write_texel_buffer_descriptor(struct tu_device
*device
,
740 struct tu_cmd_buffer
*cmd_buffer
,
742 struct tu_bo
**buffer_list
,
743 const VkBufferView buffer_view
)
745 TU_FROM_HANDLE(tu_buffer_view
, view
, buffer_view
);
747 memcpy(dst
, view
->descriptor
, sizeof(view
->descriptor
));
750 tu_bo_list_add(&cmd_buffer
->bo_list
, view
->buffer
->bo
, MSM_SUBMIT_BO_READ
);
752 *buffer_list
= view
->buffer
->bo
;
755 static uint32_t get_range(struct tu_buffer
*buf
, VkDeviceSize offset
,
758 if (range
== VK_WHOLE_SIZE
) {
759 return buf
->size
- offset
;
765 static void write_buffer_descriptor(struct tu_device
*device
,
766 struct tu_cmd_buffer
*cmd_buffer
,
768 struct tu_bo
**buffer_list
,
769 const VkDescriptorBufferInfo
*buffer_info
)
771 TU_FROM_HANDLE(tu_buffer
, buffer
, buffer_info
->buffer
);
773 uint64_t va
= tu_buffer_iova(buffer
) + buffer_info
->offset
;
774 uint32_t range
= get_range(buffer
, buffer_info
->offset
, buffer_info
->range
);
775 range
= ALIGN_POT(range
, 4) / 4;
777 A6XX_IBO_0_TILE_MODE(TILE6_LINEAR
) | A6XX_IBO_0_FMT(FMT6_32_UINT
);
780 A6XX_IBO_2_UNK4
| A6XX_IBO_2_TYPE(A6XX_TEX_1D
) | A6XX_IBO_2_UNK31
;
782 dst
[4] = A6XX_IBO_4_BASE_LO(va
);
783 dst
[5] = A6XX_IBO_5_BASE_HI(va
>> 32);
784 for (int i
= 6; i
< A6XX_TEX_CONST_DWORDS
; i
++)
788 tu_bo_list_add(&cmd_buffer
->bo_list
, buffer
->bo
, MSM_SUBMIT_BO_READ
);
790 *buffer_list
= buffer
->bo
;
793 static void write_ubo_descriptor(struct tu_device
*device
,
794 struct tu_cmd_buffer
*cmd_buffer
,
796 struct tu_bo
**buffer_list
,
797 const VkDescriptorBufferInfo
*buffer_info
)
799 TU_FROM_HANDLE(tu_buffer
, buffer
, buffer_info
->buffer
);
801 uint32_t range
= get_range(buffer
, buffer_info
->offset
, buffer_info
->range
);
802 /* The HW range is in vec4 units */
803 range
= ALIGN_POT(range
, 16) / 16;
804 uint64_t va
= tu_buffer_iova(buffer
) + buffer_info
->offset
;
805 dst
[0] = A6XX_UBO_0_BASE_LO(va
);
806 dst
[1] = A6XX_UBO_1_BASE_HI(va
>> 32) | A6XX_UBO_1_SIZE(range
);
809 tu_bo_list_add(&cmd_buffer
->bo_list
, buffer
->bo
, MSM_SUBMIT_BO_READ
);
811 *buffer_list
= buffer
->bo
;
815 write_image_descriptor(struct tu_device
*device
,
816 struct tu_cmd_buffer
*cmd_buffer
,
818 struct tu_bo
**buffer_list
,
819 VkDescriptorType descriptor_type
,
820 const VkDescriptorImageInfo
*image_info
)
822 TU_FROM_HANDLE(tu_image_view
, iview
, image_info
->imageView
);
824 if (descriptor_type
== VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
) {
825 memcpy(dst
, iview
->storage_descriptor
, sizeof(iview
->storage_descriptor
));
827 memcpy(dst
, iview
->descriptor
, sizeof(iview
->descriptor
));
831 tu_bo_list_add(&cmd_buffer
->bo_list
, iview
->image
->bo
, MSM_SUBMIT_BO_READ
);
833 *buffer_list
= iview
->image
->bo
;
837 write_combined_image_sampler_descriptor(struct tu_device
*device
,
838 struct tu_cmd_buffer
*cmd_buffer
,
839 unsigned sampler_offset
,
841 struct tu_bo
**buffer_list
,
842 VkDescriptorType descriptor_type
,
843 const VkDescriptorImageInfo
*image_info
,
846 TU_FROM_HANDLE(tu_sampler
, sampler
, image_info
->sampler
);
848 write_image_descriptor(device
, cmd_buffer
, dst
, buffer_list
,
849 descriptor_type
, image_info
);
850 /* copy over sampler state */
852 memcpy(dst
+ A6XX_TEX_CONST_DWORDS
, sampler
, sizeof(*sampler
));
857 write_sampler_descriptor(struct tu_device
*device
,
859 const VkDescriptorImageInfo
*image_info
)
861 TU_FROM_HANDLE(tu_sampler
, sampler
, image_info
->sampler
);
863 memcpy(dst
, sampler
, sizeof(*sampler
));
867 tu_update_descriptor_sets(struct tu_device
*device
,
868 struct tu_cmd_buffer
*cmd_buffer
,
869 VkDescriptorSet dstSetOverride
,
870 uint32_t descriptorWriteCount
,
871 const VkWriteDescriptorSet
*pDescriptorWrites
,
872 uint32_t descriptorCopyCount
,
873 const VkCopyDescriptorSet
*pDescriptorCopies
)
876 for (i
= 0; i
< descriptorWriteCount
; i
++) {
877 const VkWriteDescriptorSet
*writeset
= &pDescriptorWrites
[i
];
878 TU_FROM_HANDLE(tu_descriptor_set
, set
,
879 dstSetOverride
? dstSetOverride
: writeset
->dstSet
);
880 const struct tu_descriptor_set_binding_layout
*binding_layout
=
881 set
->layout
->binding
+ writeset
->dstBinding
;
882 uint32_t *ptr
= set
->mapped_ptr
;
883 struct tu_bo
**buffer_list
= set
->buffers
;
885 ptr
+= binding_layout
->offset
/ 4;
887 ptr
+= (binding_layout
->size
/ 4) * writeset
->dstArrayElement
;
888 buffer_list
+= binding_layout
->buffer_offset
;
889 buffer_list
+= writeset
->dstArrayElement
;
890 for (j
= 0; j
< writeset
->descriptorCount
; ++j
) {
891 switch(writeset
->descriptorType
) {
892 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
: {
893 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
894 unsigned idx
= writeset
->dstArrayElement
+ j
;
895 idx
+= binding_layout
->dynamic_offset_offset
;
896 write_ubo_descriptor(device
, cmd_buffer
,
897 set
->dynamic_descriptors
+ A6XX_TEX_CONST_DWORDS
* idx
,
898 buffer_list
, writeset
->pBufferInfo
+ j
);
901 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
902 write_ubo_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
903 writeset
->pBufferInfo
+ j
);
905 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
906 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
907 unsigned idx
= writeset
->dstArrayElement
+ j
;
908 idx
+= binding_layout
->dynamic_offset_offset
;
909 write_buffer_descriptor(device
, cmd_buffer
,
910 set
->dynamic_descriptors
+ A6XX_TEX_CONST_DWORDS
* idx
,
911 buffer_list
, writeset
->pBufferInfo
+ j
);
914 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
915 write_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
916 writeset
->pBufferInfo
+ j
);
918 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
919 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
920 write_texel_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
921 writeset
->pTexelBufferView
[j
]);
923 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
924 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
925 write_image_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
926 writeset
->descriptorType
,
927 writeset
->pImageInfo
+ j
);
929 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
930 write_combined_image_sampler_descriptor(device
, cmd_buffer
,
931 A6XX_TEX_CONST_DWORDS
* 4,
933 writeset
->descriptorType
,
934 writeset
->pImageInfo
+ j
,
935 !binding_layout
->immutable_samplers_offset
);
937 case VK_DESCRIPTOR_TYPE_SAMPLER
:
938 write_sampler_descriptor(device
, ptr
, writeset
->pImageInfo
+ j
);
940 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
941 /* nothing in descriptor set - framebuffer state is used instead */
944 unreachable("unimplemented descriptor type");
947 ptr
+= binding_layout
->size
/ 4;
952 for (i
= 0; i
< descriptorCopyCount
; i
++) {
953 const VkCopyDescriptorSet
*copyset
= &pDescriptorCopies
[i
];
954 TU_FROM_HANDLE(tu_descriptor_set
, src_set
,
956 TU_FROM_HANDLE(tu_descriptor_set
, dst_set
,
958 const struct tu_descriptor_set_binding_layout
*src_binding_layout
=
959 src_set
->layout
->binding
+ copyset
->srcBinding
;
960 const struct tu_descriptor_set_binding_layout
*dst_binding_layout
=
961 dst_set
->layout
->binding
+ copyset
->dstBinding
;
962 uint32_t *src_ptr
= src_set
->mapped_ptr
;
963 uint32_t *dst_ptr
= dst_set
->mapped_ptr
;
964 struct tu_bo
**src_buffer_list
= src_set
->buffers
;
965 struct tu_bo
**dst_buffer_list
= dst_set
->buffers
;
967 src_ptr
+= src_binding_layout
->offset
/ 4;
968 dst_ptr
+= dst_binding_layout
->offset
/ 4;
970 src_ptr
+= src_binding_layout
->size
* copyset
->srcArrayElement
/ 4;
971 dst_ptr
+= dst_binding_layout
->size
* copyset
->dstArrayElement
/ 4;
973 src_buffer_list
+= src_binding_layout
->buffer_offset
;
974 src_buffer_list
+= copyset
->srcArrayElement
;
976 dst_buffer_list
+= dst_binding_layout
->buffer_offset
;
977 dst_buffer_list
+= copyset
->dstArrayElement
;
979 for (j
= 0; j
< copyset
->descriptorCount
; ++j
) {
980 switch (src_binding_layout
->type
) {
981 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
982 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
983 unsigned src_idx
= copyset
->srcArrayElement
+ j
;
984 unsigned dst_idx
= copyset
->dstArrayElement
+ j
;
985 src_idx
+= src_binding_layout
->dynamic_offset_offset
;
986 dst_idx
+= dst_binding_layout
->dynamic_offset_offset
;
988 uint32_t *src_dynamic
, *dst_dynamic
;
989 src_dynamic
= src_set
->dynamic_descriptors
+ src_idx
* A6XX_TEX_CONST_DWORDS
;
990 dst_dynamic
= dst_set
->dynamic_descriptors
+ dst_idx
* A6XX_TEX_CONST_DWORDS
;
991 memcpy(dst_dynamic
, src_dynamic
, A6XX_TEX_CONST_DWORDS
* 4);
995 memcpy(dst_ptr
, src_ptr
, src_binding_layout
->size
);
998 src_ptr
+= src_binding_layout
->size
/ 4;
999 dst_ptr
+= dst_binding_layout
->size
/ 4;
1001 if (src_binding_layout
->type
!= VK_DESCRIPTOR_TYPE_SAMPLER
) {
1002 /* Sampler descriptors don't have a buffer list. */
1003 dst_buffer_list
[j
] = src_buffer_list
[j
];
1010 tu_UpdateDescriptorSets(VkDevice _device
,
1011 uint32_t descriptorWriteCount
,
1012 const VkWriteDescriptorSet
*pDescriptorWrites
,
1013 uint32_t descriptorCopyCount
,
1014 const VkCopyDescriptorSet
*pDescriptorCopies
)
1016 TU_FROM_HANDLE(tu_device
, device
, _device
);
1018 tu_update_descriptor_sets(device
, NULL
, VK_NULL_HANDLE
,
1019 descriptorWriteCount
, pDescriptorWrites
,
1020 descriptorCopyCount
, pDescriptorCopies
);
1024 tu_CreateDescriptorUpdateTemplate(
1026 const VkDescriptorUpdateTemplateCreateInfo
*pCreateInfo
,
1027 const VkAllocationCallbacks
*pAllocator
,
1028 VkDescriptorUpdateTemplate
*pDescriptorUpdateTemplate
)
1030 TU_FROM_HANDLE(tu_device
, device
, _device
);
1031 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
,
1032 pCreateInfo
->descriptorSetLayout
);
1033 const uint32_t entry_count
= pCreateInfo
->descriptorUpdateEntryCount
;
1035 sizeof(struct tu_descriptor_update_template
) +
1036 sizeof(struct tu_descriptor_update_template_entry
) * entry_count
;
1037 struct tu_descriptor_update_template
*templ
;
1039 templ
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1040 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1042 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1044 templ
->entry_count
= entry_count
;
1046 if (pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR
) {
1047 TU_FROM_HANDLE(tu_pipeline_layout
, pipeline_layout
, pCreateInfo
->pipelineLayout
);
1049 /* descriptorSetLayout should be ignored for push descriptors
1050 * and instead it refers to pipelineLayout and set.
1052 assert(pCreateInfo
->set
< MAX_SETS
);
1053 set_layout
= pipeline_layout
->set
[pCreateInfo
->set
].layout
;
1056 for (uint32_t i
= 0; i
< entry_count
; i
++) {
1057 const VkDescriptorUpdateTemplateEntry
*entry
= &pCreateInfo
->pDescriptorUpdateEntries
[i
];
1059 const struct tu_descriptor_set_binding_layout
*binding_layout
=
1060 set_layout
->binding
+ entry
->dstBinding
;
1061 const uint32_t buffer_offset
= binding_layout
->buffer_offset
+
1062 entry
->dstArrayElement
;
1063 uint32_t dst_offset
, dst_stride
;
1065 /* dst_offset is an offset into dynamic_descriptors when the descriptor
1066 * is dynamic, and an offset into mapped_ptr otherwise.
1068 switch (entry
->descriptorType
) {
1069 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1070 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1071 dst_offset
= (binding_layout
->dynamic_offset_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 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
: {
1164 write_image_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
1165 templ
->entry
[i
].descriptor_type
,
1169 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1170 write_combined_image_sampler_descriptor(device
, cmd_buffer
,
1171 A6XX_TEX_CONST_DWORDS
* 4,
1173 templ
->entry
[i
].descriptor_type
,
1175 templ
->entry
[i
].has_sampler
);
1177 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1178 write_sampler_descriptor(device
, ptr
, src
);
1181 unreachable("unimplemented descriptor type");
1184 src
= (char *) src
+ templ
->entry
[i
].src_stride
;
1185 ptr
+= templ
->entry
[i
].dst_stride
;
1186 dst_offset
+= templ
->entry
[i
].dst_stride
;
1193 tu_UpdateDescriptorSetWithTemplate(
1195 VkDescriptorSet descriptorSet
,
1196 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1199 TU_FROM_HANDLE(tu_device
, device
, _device
);
1200 TU_FROM_HANDLE(tu_descriptor_set
, set
, descriptorSet
);
1202 tu_update_descriptor_set_with_template(device
, NULL
, set
,
1203 descriptorUpdateTemplate
, pData
);
1207 tu_CreateSamplerYcbcrConversion(
1209 const VkSamplerYcbcrConversionCreateInfo
*pCreateInfo
,
1210 const VkAllocationCallbacks
*pAllocator
,
1211 VkSamplerYcbcrConversion
*pYcbcrConversion
)
1213 TU_FROM_HANDLE(tu_device
, device
, _device
);
1214 struct tu_sampler_ycbcr_conversion
*conversion
;
1216 conversion
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*conversion
), 8,
1217 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1219 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1221 conversion
->format
= pCreateInfo
->format
;
1222 conversion
->ycbcr_model
= pCreateInfo
->ycbcrModel
;
1223 conversion
->ycbcr_range
= pCreateInfo
->ycbcrRange
;
1224 conversion
->components
= pCreateInfo
->components
;
1225 conversion
->chroma_offsets
[0] = pCreateInfo
->xChromaOffset
;
1226 conversion
->chroma_offsets
[1] = pCreateInfo
->yChromaOffset
;
1227 conversion
->chroma_filter
= pCreateInfo
->chromaFilter
;
1229 *pYcbcrConversion
= tu_sampler_ycbcr_conversion_to_handle(conversion
);
1234 tu_DestroySamplerYcbcrConversion(VkDevice _device
,
1235 VkSamplerYcbcrConversion ycbcrConversion
,
1236 const VkAllocationCallbacks
*pAllocator
)
1238 TU_FROM_HANDLE(tu_device
, device
, _device
);
1239 TU_FROM_HANDLE(tu_sampler_ycbcr_conversion
, ycbcr_conversion
, ycbcrConversion
);
1241 if (ycbcr_conversion
)
1242 vk_free2(&device
->alloc
, pAllocator
, ycbcr_conversion
);