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 DEALINGS
30 #include "util/mesa-sha1.h"
31 #include "radv_private.h"
36 static bool has_equal_immutable_samplers(const VkSampler
*samplers
, uint32_t count
)
40 for(uint32_t i
= 1; i
< count
; ++i
) {
41 if (memcmp(radv_sampler_from_handle(samplers
[0])->state
,
42 radv_sampler_from_handle(samplers
[i
])->state
, 16)) {
49 static int binding_compare(const void* av
, const void *bv
)
51 const VkDescriptorSetLayoutBinding
*a
= (const VkDescriptorSetLayoutBinding
*)av
;
52 const VkDescriptorSetLayoutBinding
*b
= (const VkDescriptorSetLayoutBinding
*)bv
;
54 return (a
->binding
< b
->binding
) ? -1 : (a
->binding
> b
->binding
) ? 1 : 0;
57 static VkDescriptorSetLayoutBinding
*
58 create_sorted_bindings(const VkDescriptorSetLayoutBinding
*bindings
, unsigned count
) {
59 VkDescriptorSetLayoutBinding
*sorted_bindings
= malloc(count
* sizeof(VkDescriptorSetLayoutBinding
));
63 memcpy(sorted_bindings
, bindings
, count
* sizeof(VkDescriptorSetLayoutBinding
));
65 qsort(sorted_bindings
, count
, sizeof(VkDescriptorSetLayoutBinding
), binding_compare
);
67 return sorted_bindings
;
70 VkResult
radv_CreateDescriptorSetLayout(
72 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
73 const VkAllocationCallbacks
* pAllocator
,
74 VkDescriptorSetLayout
* pSetLayout
)
76 RADV_FROM_HANDLE(radv_device
, device
, _device
);
77 struct radv_descriptor_set_layout
*set_layout
;
79 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
80 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
81 vk_find_struct_const(pCreateInfo
->pNext
, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
83 uint32_t max_binding
= 0;
84 uint32_t immutable_sampler_count
= 0;
85 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
86 max_binding
= MAX2(max_binding
, pCreateInfo
->pBindings
[j
].binding
);
87 if ((pCreateInfo
->pBindings
[j
].descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
||
88 pCreateInfo
->pBindings
[j
].descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
) &&
89 pCreateInfo
->pBindings
[j
].pImmutableSamplers
)
90 immutable_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
93 uint32_t samplers_offset
= sizeof(struct radv_descriptor_set_layout
) +
94 (max_binding
+ 1) * sizeof(set_layout
->binding
[0]);
95 size_t size
= samplers_offset
+ immutable_sampler_count
* 4 * sizeof(uint32_t);
97 set_layout
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
98 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
100 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
102 set_layout
->flags
= pCreateInfo
->flags
;
104 /* We just allocate all the samplers at the end of the struct */
105 uint32_t *samplers
= (uint32_t*)&set_layout
->binding
[max_binding
+ 1];
107 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(pCreateInfo
->pBindings
,
108 pCreateInfo
->bindingCount
);
110 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
111 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
114 set_layout
->binding_count
= max_binding
+ 1;
115 set_layout
->shader_stages
= 0;
116 set_layout
->dynamic_shader_stages
= 0;
117 set_layout
->has_immutable_samplers
= false;
118 set_layout
->size
= 0;
120 memset(set_layout
->binding
, 0, size
- sizeof(struct radv_descriptor_set_layout
));
122 uint32_t buffer_count
= 0;
123 uint32_t dynamic_offset_count
= 0;
125 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
126 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ j
;
127 uint32_t b
= binding
->binding
;
129 unsigned binding_buffer_count
= 0;
131 switch (binding
->descriptorType
) {
132 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
133 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
134 assert(!(pCreateInfo
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
135 set_layout
->binding
[b
].dynamic_offset_count
= 1;
136 set_layout
->dynamic_shader_stages
|= binding
->stageFlags
;
137 set_layout
->binding
[b
].size
= 0;
138 binding_buffer_count
= 1;
141 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
142 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
143 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
144 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
145 set_layout
->binding
[b
].size
= 16;
146 binding_buffer_count
= 1;
149 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
150 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
151 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
152 /* main descriptor + fmask descriptor */
153 set_layout
->binding
[b
].size
= 64;
154 binding_buffer_count
= 1;
157 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
158 /* main descriptor + fmask descriptor + sampler */
159 set_layout
->binding
[b
].size
= 96;
160 binding_buffer_count
= 1;
163 case VK_DESCRIPTOR_TYPE_SAMPLER
:
164 set_layout
->binding
[b
].size
= 16;
168 unreachable("unknown descriptor type\n");
172 set_layout
->size
= align(set_layout
->size
, alignment
);
173 set_layout
->binding
[b
].type
= binding
->descriptorType
;
174 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
175 set_layout
->binding
[b
].offset
= set_layout
->size
;
176 set_layout
->binding
[b
].buffer_offset
= buffer_count
;
177 set_layout
->binding
[b
].dynamic_offset_offset
= dynamic_offset_count
;
179 if (variable_flags
&& binding
->binding
< variable_flags
->bindingCount
&&
180 (variable_flags
->pBindingFlags
[binding
->binding
] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
181 assert(!binding
->pImmutableSamplers
); /* Terribly ill defined how many samplers are valid */
182 assert(binding
->binding
== max_binding
);
184 set_layout
->has_variable_descriptors
= true;
187 if ((binding
->descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
||
188 binding
->descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
) &&
189 binding
->pImmutableSamplers
) {
190 set_layout
->binding
[b
].immutable_samplers_offset
= samplers_offset
;
191 set_layout
->binding
[b
].immutable_samplers_equal
=
192 has_equal_immutable_samplers(binding
->pImmutableSamplers
, binding
->descriptorCount
);
193 set_layout
->has_immutable_samplers
= true;
196 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
197 memcpy(samplers
+ 4 * i
, &radv_sampler_from_handle(binding
->pImmutableSamplers
[i
])->state
, 16);
199 /* Don't reserve space for the samplers if they're not accessed. */
200 if (set_layout
->binding
[b
].immutable_samplers_equal
) {
201 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
202 set_layout
->binding
[b
].size
-= 32;
203 else if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
)
204 set_layout
->binding
[b
].size
-= 16;
206 samplers
+= 4 * binding
->descriptorCount
;
207 samplers_offset
+= 4 * sizeof(uint32_t) * binding
->descriptorCount
;
210 set_layout
->size
+= binding
->descriptorCount
* set_layout
->binding
[b
].size
;
211 buffer_count
+= binding
->descriptorCount
* binding_buffer_count
;
212 dynamic_offset_count
+= binding
->descriptorCount
*
213 set_layout
->binding
[b
].dynamic_offset_count
;
214 set_layout
->shader_stages
|= binding
->stageFlags
;
219 set_layout
->buffer_count
= buffer_count
;
220 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
222 *pSetLayout
= radv_descriptor_set_layout_to_handle(set_layout
);
227 void radv_DestroyDescriptorSetLayout(
229 VkDescriptorSetLayout _set_layout
,
230 const VkAllocationCallbacks
* pAllocator
)
232 RADV_FROM_HANDLE(radv_device
, device
, _device
);
233 RADV_FROM_HANDLE(radv_descriptor_set_layout
, set_layout
, _set_layout
);
238 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
241 void radv_GetDescriptorSetLayoutSupport(VkDevice device
,
242 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
243 VkDescriptorSetLayoutSupport
* pSupport
)
245 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(pCreateInfo
->pBindings
,
246 pCreateInfo
->bindingCount
);
248 pSupport
->supported
= false;
252 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
253 vk_find_struct_const(pCreateInfo
->pNext
, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
254 VkDescriptorSetVariableDescriptorCountLayoutSupportEXT
*variable_count
=
255 vk_find_struct((void*)pCreateInfo
->pNext
, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT
);
256 if (variable_count
) {
257 variable_count
->maxVariableDescriptorCount
= 0;
260 bool supported
= true;
262 for (uint32_t i
= 0; i
< pCreateInfo
->bindingCount
; i
++) {
263 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ i
;
265 uint64_t descriptor_size
= 0;
266 uint64_t descriptor_alignment
= 1;
267 switch (binding
->descriptorType
) {
268 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
269 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
271 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
272 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
273 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
274 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
275 descriptor_size
= 16;
276 descriptor_alignment
= 16;
278 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
279 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
280 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
281 descriptor_size
= 64;
282 descriptor_alignment
= 32;
284 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
285 if (!has_equal_immutable_samplers(binding
->pImmutableSamplers
, binding
->descriptorCount
)) {
286 descriptor_size
= 64;
288 descriptor_size
= 96;
290 descriptor_alignment
= 32;
292 case VK_DESCRIPTOR_TYPE_SAMPLER
:
293 if (!has_equal_immutable_samplers(binding
->pImmutableSamplers
, binding
->descriptorCount
)) {
294 descriptor_size
= 16;
295 descriptor_alignment
= 16;
299 unreachable("unknown descriptor type\n");
303 if (size
&& !align_u64(size
, descriptor_alignment
)) {
306 size
= align_u64(size
, descriptor_alignment
);
308 uint64_t max_count
= UINT64_MAX
;
310 max_count
= (UINT64_MAX
- size
) / descriptor_size
;
312 if (max_count
< binding
->descriptorCount
) {
315 if (variable_flags
&& binding
->binding
<variable_flags
->bindingCount
&& variable_count
&&
316 (variable_flags
->pBindingFlags
[binding
->binding
] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
317 variable_count
->maxVariableDescriptorCount
= MIN2(UINT32_MAX
, max_count
);
319 size
+= binding
->descriptorCount
* descriptor_size
;
324 pSupport
->supported
= supported
;
328 * Pipeline layouts. These have nothing to do with the pipeline. They are
329 * just multiple descriptor set layouts pasted together.
332 VkResult
radv_CreatePipelineLayout(
334 const VkPipelineLayoutCreateInfo
* pCreateInfo
,
335 const VkAllocationCallbacks
* pAllocator
,
336 VkPipelineLayout
* pPipelineLayout
)
338 RADV_FROM_HANDLE(radv_device
, device
, _device
);
339 struct radv_pipeline_layout
*layout
;
340 struct mesa_sha1 ctx
;
342 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
344 layout
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
345 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
347 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
349 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
351 unsigned dynamic_offset_count
= 0;
352 uint16_t dynamic_shader_stages
= 0;
355 _mesa_sha1_init(&ctx
);
356 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
357 RADV_FROM_HANDLE(radv_descriptor_set_layout
, set_layout
,
358 pCreateInfo
->pSetLayouts
[set
]);
359 layout
->set
[set
].layout
= set_layout
;
361 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
362 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
363 dynamic_offset_count
+= set_layout
->binding
[b
].array_size
* set_layout
->binding
[b
].dynamic_offset_count
;
364 dynamic_shader_stages
|= set_layout
->dynamic_shader_stages
;
365 if (set_layout
->binding
[b
].immutable_samplers_offset
)
366 _mesa_sha1_update(&ctx
, radv_immutable_samplers(set_layout
, set_layout
->binding
+ b
),
367 set_layout
->binding
[b
].array_size
* 4 * sizeof(uint32_t));
369 _mesa_sha1_update(&ctx
, set_layout
->binding
,
370 sizeof(set_layout
->binding
[0]) * set_layout
->binding_count
);
373 layout
->dynamic_offset_count
= dynamic_offset_count
;
374 layout
->dynamic_shader_stages
= dynamic_shader_stages
;
375 layout
->push_constant_size
= 0;
377 for (unsigned i
= 0; i
< pCreateInfo
->pushConstantRangeCount
; ++i
) {
378 const VkPushConstantRange
*range
= pCreateInfo
->pPushConstantRanges
+ i
;
379 layout
->push_constant_size
= MAX2(layout
->push_constant_size
,
380 range
->offset
+ range
->size
);
383 layout
->push_constant_size
= align(layout
->push_constant_size
, 16);
384 _mesa_sha1_update(&ctx
, &layout
->push_constant_size
,
385 sizeof(layout
->push_constant_size
));
386 _mesa_sha1_final(&ctx
, layout
->sha1
);
387 *pPipelineLayout
= radv_pipeline_layout_to_handle(layout
);
392 void radv_DestroyPipelineLayout(
394 VkPipelineLayout _pipelineLayout
,
395 const VkAllocationCallbacks
* pAllocator
)
397 RADV_FROM_HANDLE(radv_device
, device
, _device
);
398 RADV_FROM_HANDLE(radv_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
400 if (!pipeline_layout
)
402 vk_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
408 radv_descriptor_set_create(struct radv_device
*device
,
409 struct radv_descriptor_pool
*pool
,
410 const struct radv_descriptor_set_layout
*layout
,
411 const uint32_t *variable_count
,
412 struct radv_descriptor_set
**out_set
)
414 struct radv_descriptor_set
*set
;
415 unsigned range_offset
= sizeof(struct radv_descriptor_set
) +
416 sizeof(struct radeon_winsys_bo
*) * layout
->buffer_count
;
417 unsigned mem_size
= range_offset
+
418 sizeof(struct radv_descriptor_range
) * layout
->dynamic_offset_count
;
420 if (pool
->host_memory_base
) {
421 if (pool
->host_memory_end
- pool
->host_memory_ptr
< mem_size
)
422 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
424 set
= (struct radv_descriptor_set
*)pool
->host_memory_ptr
;
425 pool
->host_memory_ptr
+= mem_size
;
427 set
= vk_alloc2(&device
->alloc
, NULL
, mem_size
, 8,
428 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
431 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
434 memset(set
, 0, mem_size
);
436 if (layout
->dynamic_offset_count
) {
437 set
->dynamic_descriptors
= (struct radv_descriptor_range
*)((uint8_t*)set
+ range_offset
);
440 set
->layout
= layout
;
441 uint32_t layout_size
= align_u32(layout
->size
, 32);
443 set
->size
= layout_size
;
445 if (!pool
->host_memory_base
&& pool
->entry_count
== pool
->max_entry_count
) {
446 vk_free2(&device
->alloc
, NULL
, set
);
447 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
450 /* try to allocate linearly first, so that we don't spend
451 * time looking for gaps if the app only allocates &
452 * resets via the pool. */
453 if (pool
->current_offset
+ layout_size
<= pool
->size
) {
455 set
->mapped_ptr
= (uint32_t*)(pool
->mapped_ptr
+ pool
->current_offset
);
456 set
->va
= radv_buffer_get_va(set
->bo
) + pool
->current_offset
;
457 if (!pool
->host_memory_base
) {
458 pool
->entries
[pool
->entry_count
].offset
= pool
->current_offset
;
459 pool
->entries
[pool
->entry_count
].size
= layout_size
;
460 pool
->entries
[pool
->entry_count
].set
= set
;
463 pool
->current_offset
+= layout_size
;
464 } else if (!pool
->host_memory_base
) {
468 for (index
= 0; index
< pool
->entry_count
; ++index
) {
469 if (pool
->entries
[index
].offset
- offset
>= layout_size
)
471 offset
= pool
->entries
[index
].offset
+ pool
->entries
[index
].size
;
474 if (pool
->size
- offset
< layout_size
) {
475 vk_free2(&device
->alloc
, NULL
, set
);
476 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
479 set
->mapped_ptr
= (uint32_t*)(pool
->mapped_ptr
+ offset
);
480 set
->va
= radv_buffer_get_va(set
->bo
) + offset
;
481 memmove(&pool
->entries
[index
+ 1], &pool
->entries
[index
],
482 sizeof(pool
->entries
[0]) * (pool
->entry_count
- index
));
483 pool
->entries
[index
].offset
= offset
;
484 pool
->entries
[index
].size
= layout_size
;
485 pool
->entries
[index
].set
= set
;
488 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
491 if (layout
->has_immutable_samplers
) {
492 for (unsigned i
= 0; i
< layout
->binding_count
; ++i
) {
493 if (!layout
->binding
[i
].immutable_samplers_offset
||
494 layout
->binding
[i
].immutable_samplers_equal
)
497 unsigned offset
= layout
->binding
[i
].offset
/ 4;
498 if (layout
->binding
[i
].type
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
501 const uint32_t *samplers
= (const uint32_t*)((const char*)layout
+ layout
->binding
[i
].immutable_samplers_offset
);
502 for (unsigned j
= 0; j
< layout
->binding
[i
].array_size
; ++j
) {
503 memcpy(set
->mapped_ptr
+ offset
, samplers
+ 4 * j
, 16);
504 offset
+= layout
->binding
[i
].size
/ 4;
514 radv_descriptor_set_destroy(struct radv_device
*device
,
515 struct radv_descriptor_pool
*pool
,
516 struct radv_descriptor_set
*set
,
519 assert(!pool
->host_memory_base
);
521 if (free_bo
&& set
->size
&& !pool
->host_memory_base
) {
522 uint32_t offset
= (uint8_t*)set
->mapped_ptr
- pool
->mapped_ptr
;
523 for (int i
= 0; i
< pool
->entry_count
; ++i
) {
524 if (pool
->entries
[i
].offset
== offset
) {
525 memmove(&pool
->entries
[i
], &pool
->entries
[i
+1],
526 sizeof(pool
->entries
[i
]) * (pool
->entry_count
- i
- 1));
532 vk_free2(&device
->alloc
, NULL
, set
);
535 VkResult
radv_CreateDescriptorPool(
537 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
538 const VkAllocationCallbacks
* pAllocator
,
539 VkDescriptorPool
* pDescriptorPool
)
541 RADV_FROM_HANDLE(radv_device
, device
, _device
);
542 struct radv_descriptor_pool
*pool
;
543 uint64_t size
= sizeof(struct radv_descriptor_pool
);
544 uint64_t bo_size
= 0, bo_count
= 0, range_count
= 0;
547 for (unsigned i
= 0; i
< pCreateInfo
->poolSizeCount
; ++i
) {
548 if (pCreateInfo
->pPoolSizes
[i
].type
!= VK_DESCRIPTOR_TYPE_SAMPLER
)
549 bo_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
551 switch(pCreateInfo
->pPoolSizes
[i
].type
) {
552 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
553 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
554 range_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
556 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
557 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
558 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
559 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
560 case VK_DESCRIPTOR_TYPE_SAMPLER
:
561 /* 32 as we may need to align for images */
562 bo_size
+= 32 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
564 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
565 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
566 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
567 bo_size
+= 64 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
569 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
570 bo_size
+= 96 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
573 unreachable("unknown descriptor type\n");
578 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
579 uint64_t host_size
= pCreateInfo
->maxSets
* sizeof(struct radv_descriptor_set
);
580 host_size
+= sizeof(struct radeon_winsys_bo
*) * bo_count
;
581 host_size
+= sizeof(struct radv_descriptor_range
) * range_count
;
584 size
+= sizeof(struct radv_descriptor_pool_entry
) * pCreateInfo
->maxSets
;
587 pool
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
588 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
590 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
592 memset(pool
, 0, sizeof(*pool
));
594 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
595 pool
->host_memory_base
= (uint8_t*)pool
+ sizeof(struct radv_descriptor_pool
);
596 pool
->host_memory_ptr
= pool
->host_memory_base
;
597 pool
->host_memory_end
= (uint8_t*)pool
+ size
;
601 pool
->bo
= device
->ws
->buffer_create(device
->ws
, bo_size
, 32,
603 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
604 RADEON_FLAG_READ_ONLY
|
606 RADV_BO_PRIORITY_DESCRIPTOR
);
607 pool
->mapped_ptr
= (uint8_t*)device
->ws
->buffer_map(pool
->bo
);
609 pool
->size
= bo_size
;
610 pool
->max_entry_count
= pCreateInfo
->maxSets
;
612 *pDescriptorPool
= radv_descriptor_pool_to_handle(pool
);
616 void radv_DestroyDescriptorPool(
618 VkDescriptorPool _pool
,
619 const VkAllocationCallbacks
* pAllocator
)
621 RADV_FROM_HANDLE(radv_device
, device
, _device
);
622 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, _pool
);
627 if (!pool
->host_memory_base
) {
628 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
629 radv_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
634 device
->ws
->buffer_destroy(pool
->bo
);
635 vk_free2(&device
->alloc
, pAllocator
, pool
);
638 VkResult
radv_ResetDescriptorPool(
640 VkDescriptorPool descriptorPool
,
641 VkDescriptorPoolResetFlags flags
)
643 RADV_FROM_HANDLE(radv_device
, device
, _device
);
644 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, descriptorPool
);
646 if (!pool
->host_memory_base
) {
647 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
648 radv_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
650 pool
->entry_count
= 0;
653 pool
->current_offset
= 0;
654 pool
->host_memory_ptr
= pool
->host_memory_base
;
659 VkResult
radv_AllocateDescriptorSets(
661 const VkDescriptorSetAllocateInfo
* pAllocateInfo
,
662 VkDescriptorSet
* pDescriptorSets
)
664 RADV_FROM_HANDLE(radv_device
, device
, _device
);
665 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
667 VkResult result
= VK_SUCCESS
;
669 struct radv_descriptor_set
*set
= NULL
;
671 const VkDescriptorSetVariableDescriptorCountAllocateInfoEXT
*variable_counts
=
672 vk_find_struct_const(pAllocateInfo
->pNext
, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT
);
673 const uint32_t zero
= 0;
675 /* allocate a set of buffers for each shader to contain descriptors */
676 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
677 RADV_FROM_HANDLE(radv_descriptor_set_layout
, layout
,
678 pAllocateInfo
->pSetLayouts
[i
]);
680 const uint32_t *variable_count
= NULL
;
681 if (variable_counts
) {
682 if (i
< variable_counts
->descriptorSetCount
)
683 variable_count
= variable_counts
->pDescriptorCounts
+ i
;
685 variable_count
= &zero
;
688 assert(!(layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
690 result
= radv_descriptor_set_create(device
, pool
, layout
, variable_count
, &set
);
691 if (result
!= VK_SUCCESS
)
694 pDescriptorSets
[i
] = radv_descriptor_set_to_handle(set
);
697 if (result
!= VK_SUCCESS
)
698 radv_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
703 VkResult
radv_FreeDescriptorSets(
705 VkDescriptorPool descriptorPool
,
707 const VkDescriptorSet
* pDescriptorSets
)
709 RADV_FROM_HANDLE(radv_device
, device
, _device
);
710 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, descriptorPool
);
712 for (uint32_t i
= 0; i
< count
; i
++) {
713 RADV_FROM_HANDLE(radv_descriptor_set
, set
, pDescriptorSets
[i
]);
715 if (set
&& !pool
->host_memory_base
)
716 radv_descriptor_set_destroy(device
, pool
, set
, true);
721 static void write_texel_buffer_descriptor(struct radv_device
*device
,
722 struct radv_cmd_buffer
*cmd_buffer
,
724 struct radeon_winsys_bo
**buffer_list
,
725 const VkBufferView _buffer_view
)
727 RADV_FROM_HANDLE(radv_buffer_view
, buffer_view
, _buffer_view
);
729 memcpy(dst
, buffer_view
->state
, 4 * 4);
732 radv_cs_add_buffer(device
->ws
, cmd_buffer
->cs
, buffer_view
->bo
);
734 *buffer_list
= buffer_view
->bo
;
737 static void write_buffer_descriptor(struct radv_device
*device
,
738 struct radv_cmd_buffer
*cmd_buffer
,
740 struct radeon_winsys_bo
**buffer_list
,
741 const VkDescriptorBufferInfo
*buffer_info
)
743 RADV_FROM_HANDLE(radv_buffer
, buffer
, buffer_info
->buffer
);
744 uint64_t va
= radv_buffer_get_va(buffer
->bo
);
745 uint32_t range
= buffer_info
->range
;
747 if (buffer_info
->range
== VK_WHOLE_SIZE
)
748 range
= buffer
->size
- buffer_info
->offset
;
750 va
+= buffer_info
->offset
+ buffer
->offset
;
752 dst
[1] = S_008F04_BASE_ADDRESS_HI(va
>> 32);
754 dst
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
755 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
756 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
757 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
758 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
759 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
762 radv_cs_add_buffer(device
->ws
, cmd_buffer
->cs
, buffer
->bo
);
764 *buffer_list
= buffer
->bo
;
767 static void write_dynamic_buffer_descriptor(struct radv_device
*device
,
768 struct radv_descriptor_range
*range
,
769 struct radeon_winsys_bo
**buffer_list
,
770 const VkDescriptorBufferInfo
*buffer_info
)
772 RADV_FROM_HANDLE(radv_buffer
, buffer
, buffer_info
->buffer
);
773 uint64_t va
= radv_buffer_get_va(buffer
->bo
);
774 unsigned size
= buffer_info
->range
;
776 if (buffer_info
->range
== VK_WHOLE_SIZE
)
777 size
= buffer
->size
- buffer_info
->offset
;
779 va
+= buffer_info
->offset
+ buffer
->offset
;
783 *buffer_list
= buffer
->bo
;
787 write_image_descriptor(struct radv_device
*device
,
788 struct radv_cmd_buffer
*cmd_buffer
,
790 struct radeon_winsys_bo
**buffer_list
,
791 VkDescriptorType descriptor_type
,
792 const VkDescriptorImageInfo
*image_info
)
794 RADV_FROM_HANDLE(radv_image_view
, iview
, image_info
->imageView
);
795 uint32_t *descriptor
;
797 if (descriptor_type
== VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
) {
798 descriptor
= iview
->storage_descriptor
;
800 descriptor
= iview
->descriptor
;
803 memcpy(dst
, descriptor
, 16 * 4);
806 radv_cs_add_buffer(device
->ws
, cmd_buffer
->cs
, iview
->bo
);
808 *buffer_list
= iview
->bo
;
812 write_combined_image_sampler_descriptor(struct radv_device
*device
,
813 struct radv_cmd_buffer
*cmd_buffer
,
815 struct radeon_winsys_bo
**buffer_list
,
816 VkDescriptorType descriptor_type
,
817 const VkDescriptorImageInfo
*image_info
,
820 RADV_FROM_HANDLE(radv_sampler
, sampler
, image_info
->sampler
);
822 write_image_descriptor(device
, cmd_buffer
, dst
, buffer_list
, descriptor_type
, image_info
);
823 /* copy over sampler state */
825 memcpy(dst
+ 16, sampler
->state
, 16);
829 write_sampler_descriptor(struct radv_device
*device
,
831 const VkDescriptorImageInfo
*image_info
)
833 RADV_FROM_HANDLE(radv_sampler
, sampler
, image_info
->sampler
);
835 memcpy(dst
, sampler
->state
, 16);
838 void radv_update_descriptor_sets(
839 struct radv_device
* device
,
840 struct radv_cmd_buffer
* cmd_buffer
,
841 VkDescriptorSet dstSetOverride
,
842 uint32_t descriptorWriteCount
,
843 const VkWriteDescriptorSet
* pDescriptorWrites
,
844 uint32_t descriptorCopyCount
,
845 const VkCopyDescriptorSet
* pDescriptorCopies
)
848 for (i
= 0; i
< descriptorWriteCount
; i
++) {
849 const VkWriteDescriptorSet
*writeset
= &pDescriptorWrites
[i
];
850 RADV_FROM_HANDLE(radv_descriptor_set
, set
,
851 dstSetOverride
? dstSetOverride
: writeset
->dstSet
);
852 const struct radv_descriptor_set_binding_layout
*binding_layout
=
853 set
->layout
->binding
+ writeset
->dstBinding
;
854 uint32_t *ptr
= set
->mapped_ptr
;
855 struct radeon_winsys_bo
**buffer_list
= set
->descriptors
;
856 /* Immutable samplers are not copied into push descriptors when they are
857 * allocated, so if we are writing push descriptors we have to copy the
858 * immutable samplers into them now.
860 const bool copy_immutable_samplers
= cmd_buffer
&&
861 binding_layout
->immutable_samplers_offset
&& !binding_layout
->immutable_samplers_equal
;
862 const uint32_t *samplers
= radv_immutable_samplers(set
->layout
, binding_layout
);
864 ptr
+= binding_layout
->offset
/ 4;
865 ptr
+= binding_layout
->size
* writeset
->dstArrayElement
/ 4;
866 buffer_list
+= binding_layout
->buffer_offset
;
867 buffer_list
+= writeset
->dstArrayElement
;
868 for (j
= 0; j
< writeset
->descriptorCount
; ++j
) {
869 switch(writeset
->descriptorType
) {
870 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
871 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
872 unsigned idx
= writeset
->dstArrayElement
+ j
;
873 idx
+= binding_layout
->dynamic_offset_offset
;
874 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
875 write_dynamic_buffer_descriptor(device
, set
->dynamic_descriptors
+ idx
,
876 buffer_list
, writeset
->pBufferInfo
+ j
);
879 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
880 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
881 write_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
882 writeset
->pBufferInfo
+ j
);
884 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
885 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
886 write_texel_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
887 writeset
->pTexelBufferView
[j
]);
889 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
890 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
891 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
892 write_image_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
893 writeset
->descriptorType
,
894 writeset
->pImageInfo
+ j
);
896 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
897 write_combined_image_sampler_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
898 writeset
->descriptorType
,
899 writeset
->pImageInfo
+ j
,
900 !binding_layout
->immutable_samplers_offset
);
901 if (copy_immutable_samplers
) {
902 const unsigned idx
= writeset
->dstArrayElement
+ j
;
903 memcpy(ptr
+ 16, samplers
+ 4 * idx
, 16);
906 case VK_DESCRIPTOR_TYPE_SAMPLER
:
907 if (!binding_layout
->immutable_samplers_offset
) {
908 write_sampler_descriptor(device
, ptr
,
909 writeset
->pImageInfo
+ j
);
910 } else if (copy_immutable_samplers
) {
911 unsigned idx
= writeset
->dstArrayElement
+ j
;
912 memcpy(ptr
, samplers
+ 4 * idx
, 16);
916 unreachable("unimplemented descriptor type");
919 ptr
+= binding_layout
->size
/ 4;
925 for (i
= 0; i
< descriptorCopyCount
; i
++) {
926 const VkCopyDescriptorSet
*copyset
= &pDescriptorCopies
[i
];
927 RADV_FROM_HANDLE(radv_descriptor_set
, src_set
,
929 RADV_FROM_HANDLE(radv_descriptor_set
, dst_set
,
931 const struct radv_descriptor_set_binding_layout
*src_binding_layout
=
932 src_set
->layout
->binding
+ copyset
->srcBinding
;
933 const struct radv_descriptor_set_binding_layout
*dst_binding_layout
=
934 dst_set
->layout
->binding
+ copyset
->dstBinding
;
935 uint32_t *src_ptr
= src_set
->mapped_ptr
;
936 uint32_t *dst_ptr
= dst_set
->mapped_ptr
;
937 struct radeon_winsys_bo
**src_buffer_list
= src_set
->descriptors
;
938 struct radeon_winsys_bo
**dst_buffer_list
= dst_set
->descriptors
;
940 src_ptr
+= src_binding_layout
->offset
/ 4;
941 dst_ptr
+= dst_binding_layout
->offset
/ 4;
943 src_ptr
+= src_binding_layout
->size
* copyset
->srcArrayElement
/ 4;
944 dst_ptr
+= dst_binding_layout
->size
* copyset
->dstArrayElement
/ 4;
946 src_buffer_list
+= src_binding_layout
->buffer_offset
;
947 src_buffer_list
+= copyset
->srcArrayElement
;
949 dst_buffer_list
+= dst_binding_layout
->buffer_offset
;
950 dst_buffer_list
+= copyset
->dstArrayElement
;
952 for (j
= 0; j
< copyset
->descriptorCount
; ++j
) {
953 switch (src_binding_layout
->type
) {
954 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
955 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
956 unsigned src_idx
= copyset
->srcArrayElement
+ j
;
957 unsigned dst_idx
= copyset
->dstArrayElement
+ j
;
958 struct radv_descriptor_range
*src_range
, *dst_range
;
959 src_idx
+= src_binding_layout
->dynamic_offset_offset
;
960 dst_idx
+= dst_binding_layout
->dynamic_offset_offset
;
962 src_range
= src_set
->dynamic_descriptors
+ src_idx
;
963 dst_range
= dst_set
->dynamic_descriptors
+ dst_idx
;
964 *dst_range
= *src_range
;
968 memcpy(dst_ptr
, src_ptr
, src_binding_layout
->size
);
970 src_ptr
+= src_binding_layout
->size
/ 4;
971 dst_ptr
+= dst_binding_layout
->size
/ 4;
973 if (src_binding_layout
->type
!= VK_DESCRIPTOR_TYPE_SAMPLER
) {
974 /* Sampler descriptors don't have a buffer list. */
975 dst_buffer_list
[j
] = src_buffer_list
[j
];
981 void radv_UpdateDescriptorSets(
983 uint32_t descriptorWriteCount
,
984 const VkWriteDescriptorSet
* pDescriptorWrites
,
985 uint32_t descriptorCopyCount
,
986 const VkCopyDescriptorSet
* pDescriptorCopies
)
988 RADV_FROM_HANDLE(radv_device
, device
, _device
);
990 radv_update_descriptor_sets(device
, NULL
, VK_NULL_HANDLE
, descriptorWriteCount
, pDescriptorWrites
,
991 descriptorCopyCount
, pDescriptorCopies
);
994 VkResult
radv_CreateDescriptorUpdateTemplate(VkDevice _device
,
995 const VkDescriptorUpdateTemplateCreateInfo
*pCreateInfo
,
996 const VkAllocationCallbacks
*pAllocator
,
997 VkDescriptorUpdateTemplate
*pDescriptorUpdateTemplate
)
999 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1000 RADV_FROM_HANDLE(radv_descriptor_set_layout
, set_layout
, pCreateInfo
->descriptorSetLayout
);
1001 const uint32_t entry_count
= pCreateInfo
->descriptorUpdateEntryCount
;
1002 const size_t size
= sizeof(struct radv_descriptor_update_template
) +
1003 sizeof(struct radv_descriptor_update_template_entry
) * entry_count
;
1004 struct radv_descriptor_update_template
*templ
;
1007 templ
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1009 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1011 templ
->entry_count
= entry_count
;
1012 templ
->bind_point
= pCreateInfo
->pipelineBindPoint
;
1014 for (i
= 0; i
< entry_count
; i
++) {
1015 const VkDescriptorUpdateTemplateEntry
*entry
= &pCreateInfo
->pDescriptorUpdateEntries
[i
];
1016 const struct radv_descriptor_set_binding_layout
*binding_layout
=
1017 set_layout
->binding
+ entry
->dstBinding
;
1018 const uint32_t buffer_offset
= binding_layout
->buffer_offset
+ entry
->dstArrayElement
;
1019 const uint32_t *immutable_samplers
= NULL
;
1020 uint32_t dst_offset
;
1021 uint32_t dst_stride
;
1023 /* dst_offset is an offset into dynamic_descriptors when the descriptor
1024 is dynamic, and an offset into mapped_ptr otherwise */
1025 switch (entry
->descriptorType
) {
1026 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1027 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1028 assert(pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET
);
1029 dst_offset
= binding_layout
->dynamic_offset_offset
+ entry
->dstArrayElement
;
1030 dst_stride
= 0; /* Not used */
1033 switch (entry
->descriptorType
) {
1034 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1035 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1036 /* Immutable samplers are copied into push descriptors when they are pushed */
1037 if (pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR
&&
1038 binding_layout
->immutable_samplers_offset
&& !binding_layout
->immutable_samplers_equal
) {
1039 immutable_samplers
= radv_immutable_samplers(set_layout
, binding_layout
) + entry
->dstArrayElement
* 4;
1045 dst_offset
= binding_layout
->offset
/ 4 + binding_layout
->size
* entry
->dstArrayElement
/ 4;
1046 dst_stride
= binding_layout
->size
/ 4;
1050 templ
->entry
[i
] = (struct radv_descriptor_update_template_entry
) {
1051 .descriptor_type
= entry
->descriptorType
,
1052 .descriptor_count
= entry
->descriptorCount
,
1053 .src_offset
= entry
->offset
,
1054 .src_stride
= entry
->stride
,
1055 .dst_offset
= dst_offset
,
1056 .dst_stride
= dst_stride
,
1057 .buffer_offset
= buffer_offset
,
1058 .has_sampler
= !binding_layout
->immutable_samplers_offset
,
1059 .immutable_samplers
= immutable_samplers
1063 *pDescriptorUpdateTemplate
= radv_descriptor_update_template_to_handle(templ
);
1067 void radv_DestroyDescriptorUpdateTemplate(VkDevice _device
,
1068 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1069 const VkAllocationCallbacks
*pAllocator
)
1071 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1072 RADV_FROM_HANDLE(radv_descriptor_update_template
, templ
, descriptorUpdateTemplate
);
1077 vk_free2(&device
->alloc
, pAllocator
, templ
);
1080 void radv_update_descriptor_set_with_template(struct radv_device
*device
,
1081 struct radv_cmd_buffer
*cmd_buffer
,
1082 struct radv_descriptor_set
*set
,
1083 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1086 RADV_FROM_HANDLE(radv_descriptor_update_template
, templ
, descriptorUpdateTemplate
);
1089 for (i
= 0; i
< templ
->entry_count
; ++i
) {
1090 struct radeon_winsys_bo
**buffer_list
= set
->descriptors
+ templ
->entry
[i
].buffer_offset
;
1091 uint32_t *pDst
= set
->mapped_ptr
+ templ
->entry
[i
].dst_offset
;
1092 const uint8_t *pSrc
= ((const uint8_t *) pData
) + templ
->entry
[i
].src_offset
;
1095 for (j
= 0; j
< templ
->entry
[i
].descriptor_count
; ++j
) {
1096 switch (templ
->entry
[i
].descriptor_type
) {
1097 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1098 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
1099 const unsigned idx
= templ
->entry
[i
].dst_offset
+ j
;
1100 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
1101 write_dynamic_buffer_descriptor(device
, set
->dynamic_descriptors
+ idx
,
1102 buffer_list
, (struct VkDescriptorBufferInfo
*) pSrc
);
1105 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1106 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1107 write_buffer_descriptor(device
, cmd_buffer
, pDst
, buffer_list
,
1108 (struct VkDescriptorBufferInfo
*) pSrc
);
1110 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1111 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1112 write_texel_buffer_descriptor(device
, cmd_buffer
, pDst
, buffer_list
,
1113 *(VkBufferView
*) pSrc
);
1115 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1116 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1117 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1118 write_image_descriptor(device
, cmd_buffer
, pDst
, buffer_list
,
1119 templ
->entry
[i
].descriptor_type
,
1120 (struct VkDescriptorImageInfo
*) pSrc
);
1122 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1123 write_combined_image_sampler_descriptor(device
, cmd_buffer
, pDst
, buffer_list
,
1124 templ
->entry
[i
].descriptor_type
,
1125 (struct VkDescriptorImageInfo
*) pSrc
,
1126 templ
->entry
[i
].has_sampler
);
1127 if (templ
->entry
[i
].immutable_samplers
)
1128 memcpy(pDst
+ 16, templ
->entry
[i
].immutable_samplers
+ 4 * j
, 16);
1130 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1131 if (templ
->entry
[i
].has_sampler
)
1132 write_sampler_descriptor(device
, pDst
,
1133 (struct VkDescriptorImageInfo
*) pSrc
);
1134 else if (templ
->entry
[i
].immutable_samplers
)
1135 memcpy(pDst
, templ
->entry
[i
].immutable_samplers
+ 4 * j
, 16);
1138 unreachable("unimplemented descriptor type");
1141 pSrc
+= templ
->entry
[i
].src_stride
;
1142 pDst
+= templ
->entry
[i
].dst_stride
;
1148 void radv_UpdateDescriptorSetWithTemplate(VkDevice _device
,
1149 VkDescriptorSet descriptorSet
,
1150 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1153 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1154 RADV_FROM_HANDLE(radv_descriptor_set
, set
, descriptorSet
);
1156 radv_update_descriptor_set_with_template(device
, NULL
, set
, descriptorUpdateTemplate
, pData
);
1160 VkResult
radv_CreateSamplerYcbcrConversion(VkDevice device
,
1161 const VkSamplerYcbcrConversionCreateInfo
* pCreateInfo
,
1162 const VkAllocationCallbacks
* pAllocator
,
1163 VkSamplerYcbcrConversion
* pYcbcrConversion
)
1165 *pYcbcrConversion
= VK_NULL_HANDLE
;
1170 void radv_DestroySamplerYcbcrConversion(VkDevice device
,
1171 VkSamplerYcbcrConversion ycbcrConversion
,
1172 const VkAllocationCallbacks
* pAllocator
)