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
= sizeof(struct tu_descriptor_set_layout
) +
143 (max_binding
+ 1) * sizeof(set_layout
->binding
[0]);
144 /* note: only need to store TEX_SAMP_DWORDS for immutable samples,
145 * but using struct tu_sampler makes things simpler */
146 uint32_t size
= samplers_offset
+
147 immutable_sampler_count
* sizeof(struct tu_sampler
) +
148 ycbcr_sampler_count
* sizeof(struct tu_sampler_ycbcr_conversion
);
150 set_layout
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
151 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
153 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
155 set_layout
->flags
= pCreateInfo
->flags
;
157 /* We just allocate all the immutable samplers at the end of the struct */
158 struct tu_sampler
*samplers
= (void*) &set_layout
->binding
[max_binding
+ 1];
159 struct tu_sampler_ycbcr_conversion
*ycbcr_samplers
=
160 (void*) &samplers
[immutable_sampler_count
];
162 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(
163 pCreateInfo
->pBindings
, pCreateInfo
->bindingCount
);
165 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
166 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
169 set_layout
->binding_count
= max_binding
+ 1;
170 set_layout
->shader_stages
= 0;
171 set_layout
->has_immutable_samplers
= false;
172 set_layout
->size
= 0;
173 set_layout
->dynamic_ubo
= 0;
175 memset(set_layout
->binding
, 0,
176 size
- sizeof(struct tu_descriptor_set_layout
));
178 uint32_t dynamic_offset_count
= 0;
179 uint32_t buffer_count
= 0;
181 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
182 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ j
;
183 uint32_t b
= binding
->binding
;
185 set_layout
->binding
[b
].type
= binding
->descriptorType
;
186 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
187 set_layout
->binding
[b
].offset
= set_layout
->size
;
188 set_layout
->binding
[b
].buffer_offset
= buffer_count
;
189 set_layout
->binding
[b
].dynamic_offset_offset
= dynamic_offset_count
;
190 set_layout
->binding
[b
].size
= descriptor_size(binding
->descriptorType
);
191 set_layout
->binding
[b
].shader_stages
= binding
->stageFlags
;
193 if (variable_flags
&& binding
->binding
< variable_flags
->bindingCount
&&
194 (variable_flags
->pBindingFlags
[binding
->binding
] &
195 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
196 assert(!binding
->pImmutableSamplers
); /* Terribly ill defined how
197 many samplers are valid */
198 assert(binding
->binding
== max_binding
);
200 set_layout
->has_variable_descriptors
= true;
203 if ((binding
->descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
||
204 binding
->descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
) &&
205 binding
->pImmutableSamplers
) {
206 set_layout
->binding
[b
].immutable_samplers_offset
= samplers_offset
;
207 set_layout
->has_immutable_samplers
= true;
209 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
210 samplers
[i
] = *tu_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
212 samplers
+= binding
->descriptorCount
;
213 samplers_offset
+= sizeof(struct tu_sampler
) * binding
->descriptorCount
;
215 bool has_ycbcr_sampler
= false;
216 for (unsigned i
= 0; i
< pCreateInfo
->pBindings
[j
].descriptorCount
; ++i
) {
217 if (tu_sampler_from_handle(binding
->pImmutableSamplers
[i
])->ycbcr_sampler
)
218 has_ycbcr_sampler
= true;
221 if (has_ycbcr_sampler
) {
222 set_layout
->binding
[b
].ycbcr_samplers_offset
=
223 (const char*)ycbcr_samplers
- (const char*)set_layout
;
224 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++) {
225 struct tu_sampler
*sampler
= tu_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
226 if (sampler
->ycbcr_sampler
)
227 ycbcr_samplers
[i
] = *sampler
->ycbcr_sampler
;
229 ycbcr_samplers
[i
].ycbcr_model
= VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY
;
231 ycbcr_samplers
+= binding
->descriptorCount
;
233 set_layout
->binding
[b
].ycbcr_samplers_offset
= 0;
238 binding
->descriptorCount
* set_layout
->binding
[b
].size
;
239 if (binding
->descriptorType
!= VK_DESCRIPTOR_TYPE_SAMPLER
&&
240 binding
->descriptorType
!= VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
)
241 buffer_count
+= binding
->descriptorCount
;
242 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
||
243 binding
->descriptorType
== VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
) {
244 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
) {
245 STATIC_ASSERT(MAX_DYNAMIC_BUFFERS
<= 8 * sizeof(set_layout
->dynamic_ubo
));
246 set_layout
->dynamic_ubo
|=
247 ((1u << binding
->descriptorCount
) - 1) << dynamic_offset_count
;
250 dynamic_offset_count
+= binding
->descriptorCount
;
253 set_layout
->shader_stages
|= binding
->stageFlags
;
258 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
259 set_layout
->buffer_count
= buffer_count
;
261 *pSetLayout
= tu_descriptor_set_layout_to_handle(set_layout
);
267 tu_DestroyDescriptorSetLayout(VkDevice _device
,
268 VkDescriptorSetLayout _set_layout
,
269 const VkAllocationCallbacks
*pAllocator
)
271 TU_FROM_HANDLE(tu_device
, device
, _device
);
272 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
, _set_layout
);
277 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
281 tu_GetDescriptorSetLayoutSupport(
283 const VkDescriptorSetLayoutCreateInfo
*pCreateInfo
,
284 VkDescriptorSetLayoutSupport
*pSupport
)
286 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(
287 pCreateInfo
->pBindings
, pCreateInfo
->bindingCount
);
289 pSupport
->supported
= false;
293 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
294 vk_find_struct_const(
296 DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
297 VkDescriptorSetVariableDescriptorCountLayoutSupportEXT
*variable_count
=
299 (void *) pCreateInfo
->pNext
,
300 DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT
);
301 if (variable_count
) {
302 variable_count
->maxVariableDescriptorCount
= 0;
305 bool supported
= true;
307 for (uint32_t i
= 0; i
< pCreateInfo
->bindingCount
; i
++) {
308 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ i
;
310 uint64_t descriptor_sz
= descriptor_size(binding
->descriptorType
);
311 uint64_t descriptor_alignment
= 8;
313 if (size
&& !ALIGN_POT(size
, descriptor_alignment
)) {
316 size
= ALIGN_POT(size
, descriptor_alignment
);
318 uint64_t max_count
= UINT64_MAX
;
320 max_count
= (UINT64_MAX
- size
) / descriptor_sz
;
322 if (max_count
< binding
->descriptorCount
) {
325 if (variable_flags
&& binding
->binding
< variable_flags
->bindingCount
&&
327 (variable_flags
->pBindingFlags
[binding
->binding
] &
328 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
329 variable_count
->maxVariableDescriptorCount
=
330 MIN2(UINT32_MAX
, max_count
);
332 size
+= binding
->descriptorCount
* descriptor_sz
;
337 pSupport
->supported
= supported
;
341 * Pipeline layouts. These have nothing to do with the pipeline. They are
342 * just multiple descriptor set layouts pasted together.
346 tu_CreatePipelineLayout(VkDevice _device
,
347 const VkPipelineLayoutCreateInfo
*pCreateInfo
,
348 const VkAllocationCallbacks
*pAllocator
,
349 VkPipelineLayout
*pPipelineLayout
)
351 TU_FROM_HANDLE(tu_device
, device
, _device
);
352 struct tu_pipeline_layout
*layout
;
353 struct mesa_sha1 ctx
;
355 assert(pCreateInfo
->sType
==
356 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
358 layout
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
359 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
361 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
363 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
364 layout
->dynamic_offset_count
= 0;
366 unsigned dynamic_offset_count
= 0;
368 _mesa_sha1_init(&ctx
);
369 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
370 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
,
371 pCreateInfo
->pSetLayouts
[set
]);
372 layout
->set
[set
].layout
= set_layout
;
373 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
374 dynamic_offset_count
+= set_layout
->dynamic_offset_count
;
376 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
377 if (set_layout
->binding
[b
].immutable_samplers_offset
)
380 tu_immutable_samplers(set_layout
, set_layout
->binding
+ b
),
381 set_layout
->binding
[b
].array_size
* 4 * sizeof(uint32_t));
384 &ctx
, set_layout
->binding
,
385 sizeof(set_layout
->binding
[0]) * set_layout
->binding_count
);
388 layout
->dynamic_offset_count
= dynamic_offset_count
;
389 layout
->push_constant_size
= 0;
391 for (unsigned i
= 0; i
< pCreateInfo
->pushConstantRangeCount
; ++i
) {
392 const VkPushConstantRange
*range
= pCreateInfo
->pPushConstantRanges
+ i
;
393 layout
->push_constant_size
=
394 MAX2(layout
->push_constant_size
, range
->offset
+ range
->size
);
397 layout
->push_constant_size
= align(layout
->push_constant_size
, 16);
398 _mesa_sha1_update(&ctx
, &layout
->push_constant_size
,
399 sizeof(layout
->push_constant_size
));
400 _mesa_sha1_final(&ctx
, layout
->sha1
);
401 *pPipelineLayout
= tu_pipeline_layout_to_handle(layout
);
407 tu_DestroyPipelineLayout(VkDevice _device
,
408 VkPipelineLayout _pipelineLayout
,
409 const VkAllocationCallbacks
*pAllocator
)
411 TU_FROM_HANDLE(tu_device
, device
, _device
);
412 TU_FROM_HANDLE(tu_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
414 if (!pipeline_layout
)
416 vk_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
422 tu_descriptor_set_create(struct tu_device
*device
,
423 struct tu_descriptor_pool
*pool
,
424 const struct tu_descriptor_set_layout
*layout
,
425 const uint32_t *variable_count
,
426 struct tu_descriptor_set
**out_set
)
428 struct tu_descriptor_set
*set
;
429 uint32_t buffer_count
= layout
->buffer_count
;
430 if (variable_count
) {
432 if (layout
->binding
[layout
->binding_count
- 1].type
== VK_DESCRIPTOR_TYPE_SAMPLER
||
433 layout
->binding
[layout
->binding_count
- 1].type
== VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
)
435 buffer_count
= layout
->binding
[layout
->binding_count
- 1].buffer_offset
+
436 *variable_count
* stride
;
438 unsigned dynamic_offset
= sizeof(struct tu_descriptor_set
) +
439 sizeof(struct tu_bo
*) * buffer_count
;
440 unsigned mem_size
= dynamic_offset
+
441 A6XX_TEX_CONST_DWORDS
* 4 * layout
->dynamic_offset_count
;
443 if (pool
->host_memory_base
) {
444 if (pool
->host_memory_end
- pool
->host_memory_ptr
< mem_size
)
445 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
447 set
= (struct tu_descriptor_set
*)pool
->host_memory_ptr
;
448 pool
->host_memory_ptr
+= mem_size
;
450 set
= vk_alloc2(&device
->alloc
, NULL
, mem_size
, 8,
451 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
454 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
457 memset(set
, 0, mem_size
);
459 if (layout
->dynamic_offset_count
) {
460 set
->dynamic_descriptors
= (uint32_t *)((uint8_t*)set
+ dynamic_offset
);
463 set
->layout
= layout
;
465 uint32_t layout_size
= layout
->size
;
466 if (variable_count
) {
467 assert(layout
->has_variable_descriptors
);
468 uint32_t stride
= layout
->binding
[layout
->binding_count
- 1].size
;
469 layout_size
= layout
->binding
[layout
->binding_count
- 1].offset
+
470 *variable_count
* stride
;
474 set
->size
= layout_size
;
476 if (!pool
->host_memory_base
&& pool
->entry_count
== pool
->max_entry_count
) {
477 vk_free2(&device
->alloc
, NULL
, set
);
478 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
481 /* try to allocate linearly first, so that we don't spend
482 * time looking for gaps if the app only allocates &
483 * resets via the pool. */
484 if (pool
->current_offset
+ layout_size
<= pool
->size
) {
485 set
->mapped_ptr
= (uint32_t*)(pool
->bo
.map
+ pool
->current_offset
);
486 set
->va
= pool
->bo
.iova
+ pool
->current_offset
;
487 if (!pool
->host_memory_base
) {
488 pool
->entries
[pool
->entry_count
].offset
= pool
->current_offset
;
489 pool
->entries
[pool
->entry_count
].size
= layout_size
;
490 pool
->entries
[pool
->entry_count
].set
= set
;
493 pool
->current_offset
+= layout_size
;
494 } else if (!pool
->host_memory_base
) {
498 for (index
= 0; index
< pool
->entry_count
; ++index
) {
499 if (pool
->entries
[index
].offset
- offset
>= layout_size
)
501 offset
= pool
->entries
[index
].offset
+ pool
->entries
[index
].size
;
504 if (pool
->size
- offset
< layout_size
) {
505 vk_free2(&device
->alloc
, NULL
, set
);
506 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
509 set
->mapped_ptr
= (uint32_t*)(pool
->bo
.map
+ offset
);
510 set
->va
= pool
->bo
.iova
+ offset
;
511 memmove(&pool
->entries
[index
+ 1], &pool
->entries
[index
],
512 sizeof(pool
->entries
[0]) * (pool
->entry_count
- index
));
513 pool
->entries
[index
].offset
= offset
;
514 pool
->entries
[index
].size
= layout_size
;
515 pool
->entries
[index
].set
= set
;
518 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
521 if (layout
->has_immutable_samplers
) {
522 for (unsigned i
= 0; i
< layout
->binding_count
; ++i
) {
523 if (!layout
->binding
[i
].immutable_samplers_offset
)
526 unsigned offset
= layout
->binding
[i
].offset
/ 4;
527 if (layout
->binding
[i
].type
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
528 offset
+= A6XX_TEX_CONST_DWORDS
;
530 const struct tu_sampler
*samplers
=
531 (const struct tu_sampler
*)((const char *)layout
+
532 layout
->binding
[i
].immutable_samplers_offset
);
533 for (unsigned j
= 0; j
< layout
->binding
[i
].array_size
; ++j
) {
534 memcpy(set
->mapped_ptr
+ offset
, samplers
[j
].descriptor
,
535 sizeof(samplers
[j
].descriptor
));
536 offset
+= layout
->binding
[i
].size
/ 4;
546 tu_descriptor_set_destroy(struct tu_device
*device
,
547 struct tu_descriptor_pool
*pool
,
548 struct tu_descriptor_set
*set
,
551 assert(!pool
->host_memory_base
);
553 if (free_bo
&& set
->size
&& !pool
->host_memory_base
) {
554 uint32_t offset
= (uint8_t*)set
->mapped_ptr
- (uint8_t*)pool
->bo
.map
;
555 for (int i
= 0; i
< pool
->entry_count
; ++i
) {
556 if (pool
->entries
[i
].offset
== offset
) {
557 memmove(&pool
->entries
[i
], &pool
->entries
[i
+1],
558 sizeof(pool
->entries
[i
]) * (pool
->entry_count
- i
- 1));
564 vk_free2(&device
->alloc
, NULL
, set
);
568 tu_CreateDescriptorPool(VkDevice _device
,
569 const VkDescriptorPoolCreateInfo
*pCreateInfo
,
570 const VkAllocationCallbacks
*pAllocator
,
571 VkDescriptorPool
*pDescriptorPool
)
573 TU_FROM_HANDLE(tu_device
, device
, _device
);
574 struct tu_descriptor_pool
*pool
;
575 uint64_t size
= sizeof(struct tu_descriptor_pool
);
576 uint64_t bo_size
= 0, bo_count
= 0, dynamic_count
= 0;
578 for (unsigned i
= 0; i
< pCreateInfo
->poolSizeCount
; ++i
) {
579 if (pCreateInfo
->pPoolSizes
[i
].type
!= VK_DESCRIPTOR_TYPE_SAMPLER
)
580 bo_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
582 switch(pCreateInfo
->pPoolSizes
[i
].type
) {
583 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
584 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
585 dynamic_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
590 bo_size
+= descriptor_size(pCreateInfo
->pPoolSizes
[i
].type
) *
591 pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
594 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
595 uint64_t host_size
= pCreateInfo
->maxSets
* sizeof(struct tu_descriptor_set
);
596 host_size
+= sizeof(struct tu_bo
*) * bo_count
;
597 host_size
+= A6XX_TEX_CONST_DWORDS
* 4 * dynamic_count
;
600 size
+= sizeof(struct tu_descriptor_pool_entry
) * pCreateInfo
->maxSets
;
603 pool
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
604 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
606 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
608 memset(pool
, 0, sizeof(*pool
));
610 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
611 pool
->host_memory_base
= (uint8_t*)pool
+ sizeof(struct tu_descriptor_pool
);
612 pool
->host_memory_ptr
= pool
->host_memory_base
;
613 pool
->host_memory_end
= (uint8_t*)pool
+ size
;
619 ret
= tu_bo_init_new(device
, &pool
->bo
, bo_size
);
620 assert(ret
== VK_SUCCESS
);
622 ret
= tu_bo_map(device
, &pool
->bo
);
623 assert(ret
== VK_SUCCESS
);
625 pool
->size
= bo_size
;
626 pool
->max_entry_count
= pCreateInfo
->maxSets
;
628 *pDescriptorPool
= tu_descriptor_pool_to_handle(pool
);
633 tu_DestroyDescriptorPool(VkDevice _device
,
634 VkDescriptorPool _pool
,
635 const VkAllocationCallbacks
*pAllocator
)
637 TU_FROM_HANDLE(tu_device
, device
, _device
);
638 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, _pool
);
643 if (!pool
->host_memory_base
) {
644 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
645 tu_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
650 tu_bo_finish(device
, &pool
->bo
);
651 vk_free2(&device
->alloc
, pAllocator
, pool
);
655 tu_ResetDescriptorPool(VkDevice _device
,
656 VkDescriptorPool descriptorPool
,
657 VkDescriptorPoolResetFlags flags
)
659 TU_FROM_HANDLE(tu_device
, device
, _device
);
660 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, descriptorPool
);
662 if (!pool
->host_memory_base
) {
663 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
664 tu_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
666 pool
->entry_count
= 0;
669 pool
->current_offset
= 0;
670 pool
->host_memory_ptr
= pool
->host_memory_base
;
676 tu_AllocateDescriptorSets(VkDevice _device
,
677 const VkDescriptorSetAllocateInfo
*pAllocateInfo
,
678 VkDescriptorSet
*pDescriptorSets
)
680 TU_FROM_HANDLE(tu_device
, device
, _device
);
681 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
683 VkResult result
= VK_SUCCESS
;
685 struct tu_descriptor_set
*set
= NULL
;
687 const VkDescriptorSetVariableDescriptorCountAllocateInfoEXT
*variable_counts
=
688 vk_find_struct_const(pAllocateInfo
->pNext
, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT
);
689 const uint32_t zero
= 0;
691 /* allocate a set of buffers for each shader to contain descriptors */
692 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
693 TU_FROM_HANDLE(tu_descriptor_set_layout
, layout
,
694 pAllocateInfo
->pSetLayouts
[i
]);
696 const uint32_t *variable_count
= NULL
;
697 if (variable_counts
) {
698 if (i
< variable_counts
->descriptorSetCount
)
699 variable_count
= variable_counts
->pDescriptorCounts
+ i
;
701 variable_count
= &zero
;
704 assert(!(layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
706 result
= tu_descriptor_set_create(device
, pool
, layout
, variable_count
, &set
);
707 if (result
!= VK_SUCCESS
)
710 pDescriptorSets
[i
] = tu_descriptor_set_to_handle(set
);
713 if (result
!= VK_SUCCESS
) {
714 tu_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
716 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
717 pDescriptorSets
[i
] = VK_NULL_HANDLE
;
724 tu_FreeDescriptorSets(VkDevice _device
,
725 VkDescriptorPool descriptorPool
,
727 const VkDescriptorSet
*pDescriptorSets
)
729 TU_FROM_HANDLE(tu_device
, device
, _device
);
730 TU_FROM_HANDLE(tu_descriptor_pool
, pool
, descriptorPool
);
732 for (uint32_t i
= 0; i
< count
; i
++) {
733 TU_FROM_HANDLE(tu_descriptor_set
, set
, pDescriptorSets
[i
]);
735 if (set
&& !pool
->host_memory_base
)
736 tu_descriptor_set_destroy(device
, pool
, set
, true);
741 static void write_texel_buffer_descriptor(struct tu_device
*device
,
742 struct tu_cmd_buffer
*cmd_buffer
,
744 struct tu_bo
**buffer_list
,
745 const VkBufferView buffer_view
)
747 TU_FROM_HANDLE(tu_buffer_view
, view
, buffer_view
);
749 memcpy(dst
, view
->descriptor
, sizeof(view
->descriptor
));
752 tu_bo_list_add(&cmd_buffer
->bo_list
, view
->buffer
->bo
, MSM_SUBMIT_BO_READ
);
754 *buffer_list
= view
->buffer
->bo
;
757 static uint32_t get_range(struct tu_buffer
*buf
, VkDeviceSize offset
,
760 if (range
== VK_WHOLE_SIZE
) {
761 return buf
->size
- offset
;
767 static void write_buffer_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 uint64_t va
= tu_buffer_iova(buffer
) + buffer_info
->offset
;
776 uint32_t range
= get_range(buffer
, buffer_info
->offset
, buffer_info
->range
);
777 range
= ALIGN_POT(range
, 4) / 4;
779 A6XX_IBO_0_TILE_MODE(TILE6_LINEAR
) | A6XX_IBO_0_FMT(FMT6_32_UINT
);
782 A6XX_IBO_2_UNK4
| A6XX_IBO_2_TYPE(A6XX_TEX_1D
) | A6XX_IBO_2_UNK31
;
784 dst
[4] = A6XX_IBO_4_BASE_LO(va
);
785 dst
[5] = A6XX_IBO_5_BASE_HI(va
>> 32);
786 for (int i
= 6; i
< A6XX_TEX_CONST_DWORDS
; i
++)
790 tu_bo_list_add(&cmd_buffer
->bo_list
, buffer
->bo
, MSM_SUBMIT_BO_READ
);
792 *buffer_list
= buffer
->bo
;
795 static void write_ubo_descriptor(struct tu_device
*device
,
796 struct tu_cmd_buffer
*cmd_buffer
,
798 struct tu_bo
**buffer_list
,
799 const VkDescriptorBufferInfo
*buffer_info
)
801 TU_FROM_HANDLE(tu_buffer
, buffer
, buffer_info
->buffer
);
803 uint32_t range
= get_range(buffer
, buffer_info
->offset
, buffer_info
->range
);
804 /* The HW range is in vec4 units */
805 range
= ALIGN_POT(range
, 16) / 16;
806 uint64_t va
= tu_buffer_iova(buffer
) + buffer_info
->offset
;
807 dst
[0] = A6XX_UBO_0_BASE_LO(va
);
808 dst
[1] = A6XX_UBO_1_BASE_HI(va
>> 32) | A6XX_UBO_1_SIZE(range
);
811 tu_bo_list_add(&cmd_buffer
->bo_list
, buffer
->bo
, MSM_SUBMIT_BO_READ
);
813 *buffer_list
= buffer
->bo
;
817 write_image_descriptor(struct tu_device
*device
,
818 struct tu_cmd_buffer
*cmd_buffer
,
820 struct tu_bo
**buffer_list
,
821 VkDescriptorType descriptor_type
,
822 const VkDescriptorImageInfo
*image_info
)
824 TU_FROM_HANDLE(tu_image_view
, iview
, image_info
->imageView
);
826 if (descriptor_type
== VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
) {
827 memcpy(dst
, iview
->storage_descriptor
, sizeof(iview
->storage_descriptor
));
829 memcpy(dst
, iview
->descriptor
, sizeof(iview
->descriptor
));
833 tu_bo_list_add(&cmd_buffer
->bo_list
, iview
->image
->bo
, MSM_SUBMIT_BO_READ
);
835 *buffer_list
= iview
->image
->bo
;
839 write_combined_image_sampler_descriptor(struct tu_device
*device
,
840 struct tu_cmd_buffer
*cmd_buffer
,
841 unsigned sampler_offset
,
843 struct tu_bo
**buffer_list
,
844 VkDescriptorType descriptor_type
,
845 const VkDescriptorImageInfo
*image_info
,
848 TU_FROM_HANDLE(tu_sampler
, sampler
, image_info
->sampler
);
850 write_image_descriptor(device
, cmd_buffer
, dst
, buffer_list
,
851 descriptor_type
, image_info
);
852 /* copy over sampler state */
854 memcpy(dst
+ A6XX_TEX_CONST_DWORDS
, sampler
, sizeof(*sampler
));
859 write_sampler_descriptor(struct tu_device
*device
,
861 const VkDescriptorImageInfo
*image_info
)
863 TU_FROM_HANDLE(tu_sampler
, sampler
, image_info
->sampler
);
865 memcpy(dst
, sampler
, sizeof(*sampler
));
869 tu_update_descriptor_sets(struct tu_device
*device
,
870 struct tu_cmd_buffer
*cmd_buffer
,
871 VkDescriptorSet dstSetOverride
,
872 uint32_t descriptorWriteCount
,
873 const VkWriteDescriptorSet
*pDescriptorWrites
,
874 uint32_t descriptorCopyCount
,
875 const VkCopyDescriptorSet
*pDescriptorCopies
)
878 for (i
= 0; i
< descriptorWriteCount
; i
++) {
879 const VkWriteDescriptorSet
*writeset
= &pDescriptorWrites
[i
];
880 TU_FROM_HANDLE(tu_descriptor_set
, set
,
881 dstSetOverride
? dstSetOverride
: writeset
->dstSet
);
882 const struct tu_descriptor_set_binding_layout
*binding_layout
=
883 set
->layout
->binding
+ writeset
->dstBinding
;
884 uint32_t *ptr
= set
->mapped_ptr
;
885 struct tu_bo
**buffer_list
= set
->buffers
;
887 ptr
+= binding_layout
->offset
/ 4;
889 ptr
+= (binding_layout
->size
/ 4) * writeset
->dstArrayElement
;
890 buffer_list
+= binding_layout
->buffer_offset
;
891 buffer_list
+= writeset
->dstArrayElement
;
892 for (j
= 0; j
< writeset
->descriptorCount
; ++j
) {
893 switch(writeset
->descriptorType
) {
894 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
: {
895 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
896 unsigned idx
= writeset
->dstArrayElement
+ j
;
897 idx
+= binding_layout
->dynamic_offset_offset
;
898 write_ubo_descriptor(device
, cmd_buffer
,
899 set
->dynamic_descriptors
+ A6XX_TEX_CONST_DWORDS
* idx
,
900 buffer_list
, writeset
->pBufferInfo
+ j
);
903 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
904 write_ubo_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
905 writeset
->pBufferInfo
+ j
);
907 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
908 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
909 unsigned idx
= writeset
->dstArrayElement
+ j
;
910 idx
+= binding_layout
->dynamic_offset_offset
;
911 write_buffer_descriptor(device
, cmd_buffer
,
912 set
->dynamic_descriptors
+ A6XX_TEX_CONST_DWORDS
* idx
,
913 buffer_list
, writeset
->pBufferInfo
+ j
);
916 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
917 write_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
918 writeset
->pBufferInfo
+ j
);
920 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
921 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
922 write_texel_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
923 writeset
->pTexelBufferView
[j
]);
925 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
926 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
927 write_image_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
928 writeset
->descriptorType
,
929 writeset
->pImageInfo
+ j
);
931 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
932 write_combined_image_sampler_descriptor(device
, cmd_buffer
,
933 A6XX_TEX_CONST_DWORDS
* 4,
935 writeset
->descriptorType
,
936 writeset
->pImageInfo
+ j
,
937 !binding_layout
->immutable_samplers_offset
);
939 case VK_DESCRIPTOR_TYPE_SAMPLER
:
940 write_sampler_descriptor(device
, ptr
, writeset
->pImageInfo
+ j
);
942 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
943 /* nothing in descriptor set - framebuffer state is used instead */
946 unreachable("unimplemented descriptor type");
949 ptr
+= binding_layout
->size
/ 4;
954 for (i
= 0; i
< descriptorCopyCount
; i
++) {
955 const VkCopyDescriptorSet
*copyset
= &pDescriptorCopies
[i
];
956 TU_FROM_HANDLE(tu_descriptor_set
, src_set
,
958 TU_FROM_HANDLE(tu_descriptor_set
, dst_set
,
960 const struct tu_descriptor_set_binding_layout
*src_binding_layout
=
961 src_set
->layout
->binding
+ copyset
->srcBinding
;
962 const struct tu_descriptor_set_binding_layout
*dst_binding_layout
=
963 dst_set
->layout
->binding
+ copyset
->dstBinding
;
964 uint32_t *src_ptr
= src_set
->mapped_ptr
;
965 uint32_t *dst_ptr
= dst_set
->mapped_ptr
;
966 struct tu_bo
**src_buffer_list
= src_set
->buffers
;
967 struct tu_bo
**dst_buffer_list
= dst_set
->buffers
;
969 src_ptr
+= src_binding_layout
->offset
/ 4;
970 dst_ptr
+= dst_binding_layout
->offset
/ 4;
972 src_ptr
+= src_binding_layout
->size
* copyset
->srcArrayElement
/ 4;
973 dst_ptr
+= dst_binding_layout
->size
* copyset
->dstArrayElement
/ 4;
975 src_buffer_list
+= src_binding_layout
->buffer_offset
;
976 src_buffer_list
+= copyset
->srcArrayElement
;
978 dst_buffer_list
+= dst_binding_layout
->buffer_offset
;
979 dst_buffer_list
+= copyset
->dstArrayElement
;
981 for (j
= 0; j
< copyset
->descriptorCount
; ++j
) {
982 switch (src_binding_layout
->type
) {
983 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
984 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
985 unsigned src_idx
= copyset
->srcArrayElement
+ j
;
986 unsigned dst_idx
= copyset
->dstArrayElement
+ j
;
987 src_idx
+= src_binding_layout
->dynamic_offset_offset
;
988 dst_idx
+= dst_binding_layout
->dynamic_offset_offset
;
990 uint32_t *src_dynamic
, *dst_dynamic
;
991 src_dynamic
= src_set
->dynamic_descriptors
+ src_idx
* A6XX_TEX_CONST_DWORDS
;
992 dst_dynamic
= dst_set
->dynamic_descriptors
+ dst_idx
* A6XX_TEX_CONST_DWORDS
;
993 memcpy(dst_dynamic
, src_dynamic
, A6XX_TEX_CONST_DWORDS
* 4);
997 memcpy(dst_ptr
, src_ptr
, src_binding_layout
->size
);
1000 src_ptr
+= src_binding_layout
->size
/ 4;
1001 dst_ptr
+= dst_binding_layout
->size
/ 4;
1003 if (src_binding_layout
->type
!= VK_DESCRIPTOR_TYPE_SAMPLER
) {
1004 /* Sampler descriptors don't have a buffer list. */
1005 dst_buffer_list
[j
] = src_buffer_list
[j
];
1012 tu_UpdateDescriptorSets(VkDevice _device
,
1013 uint32_t descriptorWriteCount
,
1014 const VkWriteDescriptorSet
*pDescriptorWrites
,
1015 uint32_t descriptorCopyCount
,
1016 const VkCopyDescriptorSet
*pDescriptorCopies
)
1018 TU_FROM_HANDLE(tu_device
, device
, _device
);
1020 tu_update_descriptor_sets(device
, NULL
, VK_NULL_HANDLE
,
1021 descriptorWriteCount
, pDescriptorWrites
,
1022 descriptorCopyCount
, pDescriptorCopies
);
1026 tu_CreateDescriptorUpdateTemplate(
1028 const VkDescriptorUpdateTemplateCreateInfo
*pCreateInfo
,
1029 const VkAllocationCallbacks
*pAllocator
,
1030 VkDescriptorUpdateTemplate
*pDescriptorUpdateTemplate
)
1032 TU_FROM_HANDLE(tu_device
, device
, _device
);
1033 TU_FROM_HANDLE(tu_descriptor_set_layout
, set_layout
,
1034 pCreateInfo
->descriptorSetLayout
);
1035 const uint32_t entry_count
= pCreateInfo
->descriptorUpdateEntryCount
;
1037 sizeof(struct tu_descriptor_update_template
) +
1038 sizeof(struct tu_descriptor_update_template_entry
) * entry_count
;
1039 struct tu_descriptor_update_template
*templ
;
1041 templ
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1042 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1044 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1046 templ
->entry_count
= entry_count
;
1048 if (pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR
) {
1049 TU_FROM_HANDLE(tu_pipeline_layout
, pipeline_layout
, pCreateInfo
->pipelineLayout
);
1051 /* descriptorSetLayout should be ignored for push descriptors
1052 * and instead it refers to pipelineLayout and set.
1054 assert(pCreateInfo
->set
< MAX_SETS
);
1055 set_layout
= pipeline_layout
->set
[pCreateInfo
->set
].layout
;
1058 for (uint32_t i
= 0; i
< entry_count
; i
++) {
1059 const VkDescriptorUpdateTemplateEntry
*entry
= &pCreateInfo
->pDescriptorUpdateEntries
[i
];
1061 const struct tu_descriptor_set_binding_layout
*binding_layout
=
1062 set_layout
->binding
+ entry
->dstBinding
;
1063 const uint32_t buffer_offset
= binding_layout
->buffer_offset
+
1064 entry
->dstArrayElement
;
1065 uint32_t dst_offset
, dst_stride
;
1067 /* dst_offset is an offset into dynamic_descriptors when the descriptor
1068 * is dynamic, and an offset into mapped_ptr otherwise.
1070 switch (entry
->descriptorType
) {
1071 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1072 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1073 dst_offset
= (binding_layout
->dynamic_offset_offset
+
1074 entry
->dstArrayElement
) * A6XX_TEX_CONST_DWORDS
;
1075 dst_stride
= A6XX_TEX_CONST_DWORDS
;
1078 dst_offset
= binding_layout
->offset
/ 4;
1079 dst_offset
+= (binding_layout
->size
* entry
->dstArrayElement
) / 4;
1080 dst_stride
= binding_layout
->size
/ 4;
1083 templ
->entry
[i
] = (struct tu_descriptor_update_template_entry
) {
1084 .descriptor_type
= entry
->descriptorType
,
1085 .descriptor_count
= entry
->descriptorCount
,
1086 .src_offset
= entry
->offset
,
1087 .src_stride
= entry
->stride
,
1088 .dst_offset
= dst_offset
,
1089 .dst_stride
= dst_stride
,
1090 .buffer_offset
= buffer_offset
,
1091 .has_sampler
= !binding_layout
->immutable_samplers_offset
,
1095 *pDescriptorUpdateTemplate
=
1096 tu_descriptor_update_template_to_handle(templ
);
1102 tu_DestroyDescriptorUpdateTemplate(
1104 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1105 const VkAllocationCallbacks
*pAllocator
)
1107 TU_FROM_HANDLE(tu_device
, device
, _device
);
1108 TU_FROM_HANDLE(tu_descriptor_update_template
, templ
,
1109 descriptorUpdateTemplate
);
1114 vk_free2(&device
->alloc
, pAllocator
, templ
);
1118 tu_update_descriptor_set_with_template(
1119 struct tu_device
*device
,
1120 struct tu_cmd_buffer
*cmd_buffer
,
1121 struct tu_descriptor_set
*set
,
1122 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1125 TU_FROM_HANDLE(tu_descriptor_update_template
, templ
,
1126 descriptorUpdateTemplate
);
1128 for (uint32_t i
= 0; i
< templ
->entry_count
; i
++) {
1129 uint32_t *ptr
= set
->mapped_ptr
;
1130 const void *src
= ((const char *) pData
) + templ
->entry
[i
].src_offset
;
1131 struct tu_bo
**buffer_list
= set
->buffers
;
1133 ptr
+= templ
->entry
[i
].dst_offset
;
1134 buffer_list
+= templ
->entry
[i
].buffer_offset
;
1135 unsigned dst_offset
= templ
->entry
[i
].dst_offset
;
1136 for (unsigned j
= 0; j
< templ
->entry
[i
].descriptor_count
; ++j
) {
1137 switch(templ
->entry
[i
].descriptor_type
) {
1138 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
: {
1139 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
1140 write_ubo_descriptor(device
, cmd_buffer
,
1141 set
->dynamic_descriptors
+ dst_offset
,
1145 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1146 write_ubo_descriptor(device
, cmd_buffer
, ptr
, buffer_list
, src
);
1148 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
1149 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
1150 write_buffer_descriptor(device
, cmd_buffer
,
1151 set
->dynamic_descriptors
+ dst_offset
,
1155 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1156 write_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
, src
);
1158 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1159 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1160 write_texel_buffer_descriptor(device
, cmd_buffer
, ptr
,
1161 buffer_list
, *(VkBufferView
*) src
);
1163 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1164 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1165 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
: {
1166 write_image_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
1167 templ
->entry
[i
].descriptor_type
,
1171 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1172 write_combined_image_sampler_descriptor(device
, cmd_buffer
,
1173 A6XX_TEX_CONST_DWORDS
* 4,
1175 templ
->entry
[i
].descriptor_type
,
1177 templ
->entry
[i
].has_sampler
);
1179 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1180 write_sampler_descriptor(device
, ptr
, src
);
1183 unreachable("unimplemented descriptor type");
1186 src
= (char *) src
+ templ
->entry
[i
].src_stride
;
1187 ptr
+= templ
->entry
[i
].dst_stride
;
1188 dst_offset
+= templ
->entry
[i
].dst_stride
;
1195 tu_UpdateDescriptorSetWithTemplate(
1197 VkDescriptorSet descriptorSet
,
1198 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1201 TU_FROM_HANDLE(tu_device
, device
, _device
);
1202 TU_FROM_HANDLE(tu_descriptor_set
, set
, descriptorSet
);
1204 tu_update_descriptor_set_with_template(device
, NULL
, set
,
1205 descriptorUpdateTemplate
, pData
);
1209 tu_CreateSamplerYcbcrConversion(
1211 const VkSamplerYcbcrConversionCreateInfo
*pCreateInfo
,
1212 const VkAllocationCallbacks
*pAllocator
,
1213 VkSamplerYcbcrConversion
*pYcbcrConversion
)
1215 TU_FROM_HANDLE(tu_device
, device
, _device
);
1216 struct tu_sampler_ycbcr_conversion
*conversion
;
1218 conversion
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*conversion
), 8,
1219 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1221 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1223 conversion
->format
= pCreateInfo
->format
;
1224 conversion
->ycbcr_model
= pCreateInfo
->ycbcrModel
;
1225 conversion
->ycbcr_range
= pCreateInfo
->ycbcrRange
;
1226 conversion
->components
= pCreateInfo
->components
;
1227 conversion
->chroma_offsets
[0] = pCreateInfo
->xChromaOffset
;
1228 conversion
->chroma_offsets
[1] = pCreateInfo
->yChromaOffset
;
1229 conversion
->chroma_filter
= pCreateInfo
->chromaFilter
;
1231 *pYcbcrConversion
= tu_sampler_ycbcr_conversion_to_handle(conversion
);
1236 tu_DestroySamplerYcbcrConversion(VkDevice _device
,
1237 VkSamplerYcbcrConversion ycbcrConversion
,
1238 const VkAllocationCallbacks
*pAllocator
)
1240 TU_FROM_HANDLE(tu_device
, device
, _device
);
1241 TU_FROM_HANDLE(tu_sampler_ycbcr_conversion
, ycbcr_conversion
, ycbcrConversion
);
1243 if (ycbcr_conversion
)
1244 vk_free2(&device
->alloc
, pAllocator
, ycbcr_conversion
);