radv: Support allocating variable size descriptor sets.
[mesa.git] / src / amd / vulkan / radv_descriptor_set.c
1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
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:
11 *
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
14 * Software.
15 *
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
22 * IN THE SOFTWARE.
23 */
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29
30 #include "util/mesa-sha1.h"
31 #include "radv_private.h"
32 #include "sid.h"
33 #include "vk_util.h"
34
35
36 static bool has_equal_immutable_samplers(const VkSampler *samplers, uint32_t count)
37 {
38 if (!samplers)
39 return false;
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)) {
43 return false;
44 }
45 }
46 return true;
47 }
48
49 static int binding_compare(const void* av, const void *bv)
50 {
51 const VkDescriptorSetLayoutBinding *a = (const VkDescriptorSetLayoutBinding*)av;
52 const VkDescriptorSetLayoutBinding *b = (const VkDescriptorSetLayoutBinding*)bv;
53
54 return (a->binding < b->binding) ? -1 : (a->binding > b->binding) ? 1 : 0;
55 }
56
57 static VkDescriptorSetLayoutBinding *
58 create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count) {
59 VkDescriptorSetLayoutBinding *sorted_bindings = malloc(count * sizeof(VkDescriptorSetLayoutBinding));
60 if (!sorted_bindings)
61 return NULL;
62
63 memcpy(sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding));
64
65 qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare);
66
67 return sorted_bindings;
68 }
69
70 VkResult radv_CreateDescriptorSetLayout(
71 VkDevice _device,
72 const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
73 const VkAllocationCallbacks* pAllocator,
74 VkDescriptorSetLayout* pSetLayout)
75 {
76 RADV_FROM_HANDLE(radv_device, device, _device);
77 struct radv_descriptor_set_layout *set_layout;
78
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);
82
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].pImmutableSamplers)
88 immutable_sampler_count += pCreateInfo->pBindings[j].descriptorCount;
89 }
90
91 uint32_t samplers_offset = sizeof(struct radv_descriptor_set_layout) +
92 (max_binding + 1) * sizeof(set_layout->binding[0]);
93 size_t size = samplers_offset + immutable_sampler_count * 4 * sizeof(uint32_t);
94
95 set_layout = vk_alloc2(&device->alloc, pAllocator, size, 8,
96 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
97 if (!set_layout)
98 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
99
100 set_layout->flags = pCreateInfo->flags;
101
102 /* We just allocate all the samplers at the end of the struct */
103 uint32_t *samplers = (uint32_t*)&set_layout->binding[max_binding + 1];
104
105 VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(pCreateInfo->pBindings,
106 pCreateInfo->bindingCount);
107 if (!bindings) {
108 vk_free2(&device->alloc, pAllocator, set_layout);
109 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
110 }
111
112 set_layout->binding_count = max_binding + 1;
113 set_layout->shader_stages = 0;
114 set_layout->dynamic_shader_stages = 0;
115 set_layout->has_immutable_samplers = false;
116 set_layout->size = 0;
117
118 memset(set_layout->binding, 0, size - sizeof(struct radv_descriptor_set_layout));
119
120 uint32_t dynamic_offset_count = 0;
121
122 for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {
123 const VkDescriptorSetLayoutBinding *binding = bindings + j;
124 uint32_t b = binding->binding;
125 uint32_t alignment;
126
127 switch (binding->descriptorType) {
128 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
129 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
130 assert(!(pCreateInfo->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
131 set_layout->binding[b].dynamic_offset_count = 1;
132 set_layout->dynamic_shader_stages |= binding->stageFlags;
133 set_layout->binding[b].size = 0;
134 alignment = 1;
135 break;
136 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
137 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
138 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
139 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
140 set_layout->binding[b].size = 16;
141 alignment = 16;
142 break;
143 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
144 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
145 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
146 /* main descriptor + fmask descriptor */
147 set_layout->binding[b].size = 64;
148 alignment = 32;
149 break;
150 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
151 /* main descriptor + fmask descriptor + sampler */
152 set_layout->binding[b].size = 96;
153 alignment = 32;
154 break;
155 case VK_DESCRIPTOR_TYPE_SAMPLER:
156 set_layout->binding[b].size = 16;
157 alignment = 16;
158 break;
159 default:
160 unreachable("unknown descriptor type\n");
161 break;
162 }
163
164 set_layout->size = align(set_layout->size, alignment);
165 set_layout->binding[b].type = binding->descriptorType;
166 set_layout->binding[b].array_size = binding->descriptorCount;
167 set_layout->binding[b].offset = set_layout->size;
168 set_layout->binding[b].dynamic_offset_offset = dynamic_offset_count;
169
170 if (variable_flags && binding->binding < variable_flags->bindingCount &&
171 (variable_flags->pBindingFlags[binding->binding] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT)) {
172 assert(!binding->pImmutableSamplers); /* Terribly ill defined how many samplers are valid */
173 assert(binding->binding == max_binding);
174
175 set_layout->has_variable_descriptors = true;
176 }
177
178 if (binding->pImmutableSamplers) {
179 set_layout->binding[b].immutable_samplers_offset = samplers_offset;
180 set_layout->binding[b].immutable_samplers_equal =
181 has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount);
182 set_layout->has_immutable_samplers = true;
183
184
185 for (uint32_t i = 0; i < binding->descriptorCount; i++)
186 memcpy(samplers + 4 * i, &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
187
188 /* Don't reserve space for the samplers if they're not accessed. */
189 if (set_layout->binding[b].immutable_samplers_equal) {
190 if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
191 set_layout->binding[b].size -= 32;
192 else if (binding->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER)
193 set_layout->binding[b].size -= 16;
194 }
195 samplers += 4 * binding->descriptorCount;
196 samplers_offset += 4 * sizeof(uint32_t) * binding->descriptorCount;
197 }
198
199 set_layout->size += binding->descriptorCount * set_layout->binding[b].size;
200 dynamic_offset_count += binding->descriptorCount *
201 set_layout->binding[b].dynamic_offset_count;
202 set_layout->shader_stages |= binding->stageFlags;
203 }
204
205 free(bindings);
206
207 set_layout->dynamic_offset_count = dynamic_offset_count;
208
209 *pSetLayout = radv_descriptor_set_layout_to_handle(set_layout);
210
211 return VK_SUCCESS;
212 }
213
214 void radv_DestroyDescriptorSetLayout(
215 VkDevice _device,
216 VkDescriptorSetLayout _set_layout,
217 const VkAllocationCallbacks* pAllocator)
218 {
219 RADV_FROM_HANDLE(radv_device, device, _device);
220 RADV_FROM_HANDLE(radv_descriptor_set_layout, set_layout, _set_layout);
221
222 if (!set_layout)
223 return;
224
225 vk_free2(&device->alloc, pAllocator, set_layout);
226 }
227
228 void radv_GetDescriptorSetLayoutSupport(VkDevice device,
229 const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
230 VkDescriptorSetLayoutSupport* pSupport)
231 {
232 VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(pCreateInfo->pBindings,
233 pCreateInfo->bindingCount);
234 if (!bindings) {
235 pSupport->supported = false;
236 return;
237 }
238
239 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT *variable_flags =
240 vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT);
241 VkDescriptorSetVariableDescriptorCountLayoutSupportEXT *variable_count =
242 vk_find_struct((void*)pCreateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT);
243 if (variable_count) {
244 variable_count->maxVariableDescriptorCount = 0;
245 }
246
247 bool supported = true;
248 uint64_t size = 0;
249 for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
250 const VkDescriptorSetLayoutBinding *binding = bindings + i;
251
252 uint64_t descriptor_size = 0;
253 uint64_t descriptor_alignment = 1;
254 switch (binding->descriptorType) {
255 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
256 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
257 break;
258 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
259 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
260 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
261 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
262 descriptor_size = 16;
263 descriptor_alignment = 16;
264 break;
265 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
266 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
267 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
268 descriptor_size = 64;
269 descriptor_alignment = 32;
270 break;
271 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
272 if (!has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount)) {
273 descriptor_size = 64;
274 } else {
275 descriptor_size = 96;
276 }
277 descriptor_alignment = 32;
278 break;
279 case VK_DESCRIPTOR_TYPE_SAMPLER:
280 if (!has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount)) {
281 descriptor_size = 16;
282 descriptor_alignment = 16;
283 }
284 break;
285 default:
286 unreachable("unknown descriptor type\n");
287 break;
288 }
289
290 if (size && !align_u64(size, descriptor_alignment)) {
291 supported = false;
292 }
293 size = align_u64(size, descriptor_alignment);
294
295 uint64_t max_count = UINT64_MAX;
296 if (descriptor_size)
297 max_count = (UINT64_MAX - size) / descriptor_size;
298
299 if (max_count < binding->descriptorCount) {
300 supported = false;
301 }
302 if (variable_flags && binding->binding <variable_flags->bindingCount && variable_count &&
303 (variable_flags->pBindingFlags[binding->binding] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT)) {
304 variable_count->maxVariableDescriptorCount = MIN2(UINT32_MAX, max_count);
305 }
306 size += binding->descriptorCount * descriptor_size;
307 }
308
309 free(bindings);
310
311 pSupport->supported = supported;
312 }
313
314 /*
315 * Pipeline layouts. These have nothing to do with the pipeline. They are
316 * just muttiple descriptor set layouts pasted together
317 */
318
319 VkResult radv_CreatePipelineLayout(
320 VkDevice _device,
321 const VkPipelineLayoutCreateInfo* pCreateInfo,
322 const VkAllocationCallbacks* pAllocator,
323 VkPipelineLayout* pPipelineLayout)
324 {
325 RADV_FROM_HANDLE(radv_device, device, _device);
326 struct radv_pipeline_layout *layout;
327 struct mesa_sha1 ctx;
328
329 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO);
330
331 layout = vk_alloc2(&device->alloc, pAllocator, sizeof(*layout), 8,
332 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
333 if (layout == NULL)
334 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
335
336 layout->num_sets = pCreateInfo->setLayoutCount;
337
338 unsigned dynamic_offset_count = 0;
339
340
341 _mesa_sha1_init(&ctx);
342 for (uint32_t set = 0; set < pCreateInfo->setLayoutCount; set++) {
343 RADV_FROM_HANDLE(radv_descriptor_set_layout, set_layout,
344 pCreateInfo->pSetLayouts[set]);
345 layout->set[set].layout = set_layout;
346
347 layout->set[set].dynamic_offset_start = dynamic_offset_count;
348 for (uint32_t b = 0; b < set_layout->binding_count; b++) {
349 dynamic_offset_count += set_layout->binding[b].array_size * set_layout->binding[b].dynamic_offset_count;
350 if (set_layout->binding[b].immutable_samplers_offset)
351 _mesa_sha1_update(&ctx, radv_immutable_samplers(set_layout, set_layout->binding + b),
352 set_layout->binding[b].array_size * 4 * sizeof(uint32_t));
353 }
354 _mesa_sha1_update(&ctx, set_layout->binding,
355 sizeof(set_layout->binding[0]) * set_layout->binding_count);
356 }
357
358 layout->dynamic_offset_count = dynamic_offset_count;
359 layout->push_constant_size = 0;
360
361 for (unsigned i = 0; i < pCreateInfo->pushConstantRangeCount; ++i) {
362 const VkPushConstantRange *range = pCreateInfo->pPushConstantRanges + i;
363 layout->push_constant_size = MAX2(layout->push_constant_size,
364 range->offset + range->size);
365 }
366
367 layout->push_constant_size = align(layout->push_constant_size, 16);
368 _mesa_sha1_update(&ctx, &layout->push_constant_size,
369 sizeof(layout->push_constant_size));
370 _mesa_sha1_final(&ctx, layout->sha1);
371 *pPipelineLayout = radv_pipeline_layout_to_handle(layout);
372
373 return VK_SUCCESS;
374 }
375
376 void radv_DestroyPipelineLayout(
377 VkDevice _device,
378 VkPipelineLayout _pipelineLayout,
379 const VkAllocationCallbacks* pAllocator)
380 {
381 RADV_FROM_HANDLE(radv_device, device, _device);
382 RADV_FROM_HANDLE(radv_pipeline_layout, pipeline_layout, _pipelineLayout);
383
384 if (!pipeline_layout)
385 return;
386 vk_free2(&device->alloc, pAllocator, pipeline_layout);
387 }
388
389 #define EMPTY 1
390
391 static VkResult
392 radv_descriptor_set_create(struct radv_device *device,
393 struct radv_descriptor_pool *pool,
394 const struct radv_descriptor_set_layout *layout,
395 const uint32_t *variable_count,
396 struct radv_descriptor_set **out_set)
397 {
398 struct radv_descriptor_set *set;
399 unsigned range_offset = sizeof(struct radv_descriptor_set);
400 unsigned mem_size = range_offset +
401 sizeof(struct radv_descriptor_range) * layout->dynamic_offset_count;
402
403 if (pool->host_memory_base) {
404 if (pool->host_memory_end - pool->host_memory_ptr < mem_size)
405 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
406
407 set = (struct radv_descriptor_set*)pool->host_memory_ptr;
408 pool->host_memory_ptr += mem_size;
409 } else {
410 set = vk_alloc2(&device->alloc, NULL, mem_size, 8,
411 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
412
413 if (!set)
414 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
415 }
416
417 memset(set, 0, mem_size);
418
419 if (layout->dynamic_offset_count) {
420 set->dynamic_descriptors = (struct radv_descriptor_range*)((uint8_t*)set + range_offset);
421 }
422
423 set->layout = layout;
424 uint32_t layout_size = align_u32(layout->size, 32);
425 if (layout_size) {
426 set->size = layout_size;
427
428 if (!pool->host_memory_base && pool->entry_count == pool->max_entry_count) {
429 vk_free2(&device->alloc, NULL, set);
430 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
431 }
432
433 /* try to allocate linearly first, so that we don't spend
434 * time looking for gaps if the app only allocates &
435 * resets via the pool. */
436 if (pool->current_offset + layout_size <= pool->size) {
437 set->bo = pool->bo;
438 set->mapped_ptr = (uint32_t*)(pool->mapped_ptr + pool->current_offset);
439 set->va = radv_buffer_get_va(set->bo) + pool->current_offset;
440 if (!pool->host_memory_base) {
441 pool->entries[pool->entry_count].offset = pool->current_offset;
442 pool->entries[pool->entry_count].size = layout_size;
443 pool->entries[pool->entry_count].set = set;
444 pool->entry_count++;
445 }
446 pool->current_offset += layout_size;
447 } else if (!pool->host_memory_base) {
448 uint64_t offset = 0;
449 int index;
450
451 for (index = 0; index < pool->entry_count; ++index) {
452 if (pool->entries[index].offset - offset >= layout_size)
453 break;
454 offset = pool->entries[index].offset + pool->entries[index].size;
455 }
456
457 if (pool->size - offset < layout_size) {
458 vk_free2(&device->alloc, NULL, set);
459 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
460 }
461 set->bo = pool->bo;
462 set->mapped_ptr = (uint32_t*)(pool->mapped_ptr + offset);
463 set->va = radv_buffer_get_va(set->bo) + offset;
464 memmove(&pool->entries[index + 1], &pool->entries[index],
465 sizeof(pool->entries[0]) * (pool->entry_count - index));
466 pool->entries[index].offset = offset;
467 pool->entries[index].size = layout_size;
468 pool->entries[index].set = set;
469 pool->entry_count++;
470 } else
471 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
472 }
473
474 if (layout->has_immutable_samplers) {
475 for (unsigned i = 0; i < layout->binding_count; ++i) {
476 if (!layout->binding[i].immutable_samplers_offset ||
477 layout->binding[i].immutable_samplers_equal)
478 continue;
479
480 unsigned offset = layout->binding[i].offset / 4;
481 if (layout->binding[i].type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
482 offset += 16;
483
484 const uint32_t *samplers = (const uint32_t*)((const char*)layout + layout->binding[i].immutable_samplers_offset);
485 for (unsigned j = 0; j < layout->binding[i].array_size; ++j) {
486 memcpy(set->mapped_ptr + offset, samplers + 4 * j, 16);
487 offset += layout->binding[i].size / 4;
488 }
489
490 }
491 }
492 *out_set = set;
493 return VK_SUCCESS;
494 }
495
496 static void
497 radv_descriptor_set_destroy(struct radv_device *device,
498 struct radv_descriptor_pool *pool,
499 struct radv_descriptor_set *set,
500 bool free_bo)
501 {
502 assert(!pool->host_memory_base);
503
504 if (free_bo && set->size && !pool->host_memory_base) {
505 uint32_t offset = (uint8_t*)set->mapped_ptr - pool->mapped_ptr;
506 for (int i = 0; i < pool->entry_count; ++i) {
507 if (pool->entries[i].offset == offset) {
508 memmove(&pool->entries[i], &pool->entries[i+1],
509 sizeof(pool->entries[i]) * (pool->entry_count - i - 1));
510 --pool->entry_count;
511 break;
512 }
513 }
514 }
515 vk_free2(&device->alloc, NULL, set);
516 }
517
518 VkResult radv_CreateDescriptorPool(
519 VkDevice _device,
520 const VkDescriptorPoolCreateInfo* pCreateInfo,
521 const VkAllocationCallbacks* pAllocator,
522 VkDescriptorPool* pDescriptorPool)
523 {
524 RADV_FROM_HANDLE(radv_device, device, _device);
525 struct radv_descriptor_pool *pool;
526 int size = sizeof(struct radv_descriptor_pool);
527 uint64_t bo_size = 0, bo_count = 0, range_count = 0;
528
529
530 for (unsigned i = 0; i < pCreateInfo->poolSizeCount; ++i) {
531 if (pCreateInfo->pPoolSizes[i].type != VK_DESCRIPTOR_TYPE_SAMPLER)
532 bo_count += pCreateInfo->pPoolSizes[i].descriptorCount;
533
534 switch(pCreateInfo->pPoolSizes[i].type) {
535 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
536 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
537 range_count += pCreateInfo->pPoolSizes[i].descriptorCount;
538 break;
539 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
540 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
541 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
542 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
543 case VK_DESCRIPTOR_TYPE_SAMPLER:
544 /* 32 as we may need to align for images */
545 bo_size += 32 * pCreateInfo->pPoolSizes[i].descriptorCount;
546 break;
547 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
548 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
549 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
550 bo_size += 64 * pCreateInfo->pPoolSizes[i].descriptorCount;
551 break;
552 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
553 bo_size += 96 * pCreateInfo->pPoolSizes[i].descriptorCount;
554 break;
555 default:
556 unreachable("unknown descriptor type\n");
557 break;
558 }
559 }
560
561 if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) {
562 uint64_t host_size = pCreateInfo->maxSets * sizeof(struct radv_descriptor_set);
563 host_size += sizeof(struct radeon_winsys_bo*) * bo_count;
564 host_size += sizeof(struct radv_descriptor_range) * range_count;
565 size += host_size;
566 } else {
567 size += sizeof(struct radv_descriptor_pool_entry) * pCreateInfo->maxSets;
568 }
569
570 pool = vk_alloc2(&device->alloc, pAllocator, size, 8,
571 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
572 if (!pool)
573 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
574
575 memset(pool, 0, sizeof(*pool));
576
577 if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) {
578 pool->host_memory_base = (uint8_t*)pool + sizeof(struct radv_descriptor_pool);
579 pool->host_memory_ptr = pool->host_memory_base;
580 pool->host_memory_end = (uint8_t*)pool + size;
581 }
582
583 if (bo_size) {
584 pool->bo = device->ws->buffer_create(device->ws, bo_size, 32,
585 RADEON_DOMAIN_VRAM,
586 RADEON_FLAG_NO_INTERPROCESS_SHARING |
587 RADEON_FLAG_READ_ONLY);
588 pool->mapped_ptr = (uint8_t*)device->ws->buffer_map(pool->bo);
589 }
590 pool->size = bo_size;
591 pool->max_entry_count = pCreateInfo->maxSets;
592
593 *pDescriptorPool = radv_descriptor_pool_to_handle(pool);
594 return VK_SUCCESS;
595 }
596
597 void radv_DestroyDescriptorPool(
598 VkDevice _device,
599 VkDescriptorPool _pool,
600 const VkAllocationCallbacks* pAllocator)
601 {
602 RADV_FROM_HANDLE(radv_device, device, _device);
603 RADV_FROM_HANDLE(radv_descriptor_pool, pool, _pool);
604
605 if (!pool)
606 return;
607
608 if (!pool->host_memory_base) {
609 for(int i = 0; i < pool->entry_count; ++i) {
610 radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
611 }
612 }
613
614 if (pool->bo)
615 device->ws->buffer_destroy(pool->bo);
616 vk_free2(&device->alloc, pAllocator, pool);
617 }
618
619 VkResult radv_ResetDescriptorPool(
620 VkDevice _device,
621 VkDescriptorPool descriptorPool,
622 VkDescriptorPoolResetFlags flags)
623 {
624 RADV_FROM_HANDLE(radv_device, device, _device);
625 RADV_FROM_HANDLE(radv_descriptor_pool, pool, descriptorPool);
626
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);
630 }
631 pool->entry_count = 0;
632 }
633
634 pool->current_offset = 0;
635 pool->host_memory_ptr = pool->host_memory_base;
636
637 return VK_SUCCESS;
638 }
639
640 VkResult radv_AllocateDescriptorSets(
641 VkDevice _device,
642 const VkDescriptorSetAllocateInfo* pAllocateInfo,
643 VkDescriptorSet* pDescriptorSets)
644 {
645 RADV_FROM_HANDLE(radv_device, device, _device);
646 RADV_FROM_HANDLE(radv_descriptor_pool, pool, pAllocateInfo->descriptorPool);
647
648 VkResult result = VK_SUCCESS;
649 uint32_t i;
650 struct radv_descriptor_set *set = NULL;
651
652 const VkDescriptorSetVariableDescriptorCountAllocateInfoEXT *variable_counts =
653 vk_find_struct_const(pAllocateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT);
654 const uint32_t zero = 0;
655
656 /* allocate a set of buffers for each shader to contain descriptors */
657 for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
658 RADV_FROM_HANDLE(radv_descriptor_set_layout, layout,
659 pAllocateInfo->pSetLayouts[i]);
660
661 const uint32_t *variable_count = NULL;
662 if (variable_counts) {
663 if (i < variable_counts->descriptorSetCount)
664 variable_count = variable_counts->pDescriptorCounts + i;
665 else
666 variable_count = &zero;
667 }
668
669 assert(!(layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
670
671 result = radv_descriptor_set_create(device, pool, layout, variable_count, &set);
672 if (result != VK_SUCCESS)
673 break;
674
675 pDescriptorSets[i] = radv_descriptor_set_to_handle(set);
676 }
677
678 if (result != VK_SUCCESS)
679 radv_FreeDescriptorSets(_device, pAllocateInfo->descriptorPool,
680 i, pDescriptorSets);
681 return result;
682 }
683
684 VkResult radv_FreeDescriptorSets(
685 VkDevice _device,
686 VkDescriptorPool descriptorPool,
687 uint32_t count,
688 const VkDescriptorSet* pDescriptorSets)
689 {
690 RADV_FROM_HANDLE(radv_device, device, _device);
691 RADV_FROM_HANDLE(radv_descriptor_pool, pool, descriptorPool);
692
693 for (uint32_t i = 0; i < count; i++) {
694 RADV_FROM_HANDLE(radv_descriptor_set, set, pDescriptorSets[i]);
695
696 if (set && !pool->host_memory_base)
697 radv_descriptor_set_destroy(device, pool, set, true);
698 }
699 return VK_SUCCESS;
700 }
701
702 static void write_texel_buffer_descriptor(struct radv_device *device,
703 unsigned *dst,
704 const VkBufferView _buffer_view)
705 {
706 RADV_FROM_HANDLE(radv_buffer_view, buffer_view, _buffer_view);
707
708 memcpy(dst, buffer_view->state, 4 * 4);
709 }
710
711 static void write_buffer_descriptor(struct radv_device *device,
712 unsigned *dst,
713 const VkDescriptorBufferInfo *buffer_info)
714 {
715 RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
716 uint64_t va = radv_buffer_get_va(buffer->bo);
717 uint32_t range = buffer_info->range;
718
719 if (buffer_info->range == VK_WHOLE_SIZE)
720 range = buffer->size - buffer_info->offset;
721
722 va += buffer_info->offset + buffer->offset;
723 dst[0] = va;
724 dst[1] = S_008F04_BASE_ADDRESS_HI(va >> 32);
725 dst[2] = range;
726 dst[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
727 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
728 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
729 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
730 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
731 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32);
732
733 }
734
735 static void write_dynamic_buffer_descriptor(struct radv_device *device,
736 struct radv_descriptor_range *range,
737 const VkDescriptorBufferInfo *buffer_info)
738 {
739 RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
740 uint64_t va = radv_buffer_get_va(buffer->bo);
741 unsigned size = buffer_info->range;
742
743 if (buffer_info->range == VK_WHOLE_SIZE)
744 size = buffer->size - buffer_info->offset;
745
746 va += buffer_info->offset + buffer->offset;
747 range->va = va;
748 range->size = size;
749 }
750
751 static void
752 write_image_descriptor(struct radv_device *device,
753 unsigned *dst,
754 VkDescriptorType descriptor_type,
755 const VkDescriptorImageInfo *image_info)
756 {
757 RADV_FROM_HANDLE(radv_image_view, iview, image_info->imageView);
758 uint32_t *descriptor;
759
760 if (descriptor_type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
761 descriptor = iview->storage_descriptor;
762 } else {
763 descriptor = iview->descriptor;
764 }
765
766 memcpy(dst, descriptor, 16 * 4);
767 }
768
769 static void
770 write_combined_image_sampler_descriptor(struct radv_device *device,
771 unsigned *dst,
772 VkDescriptorType descriptor_type,
773 const VkDescriptorImageInfo *image_info,
774 bool has_sampler)
775 {
776 RADV_FROM_HANDLE(radv_sampler, sampler, image_info->sampler);
777
778 write_image_descriptor(device, dst, descriptor_type, image_info);
779 /* copy over sampler state */
780 if (has_sampler)
781 memcpy(dst + 16, sampler->state, 16);
782 }
783
784 static void
785 write_sampler_descriptor(struct radv_device *device,
786 unsigned *dst,
787 const VkDescriptorImageInfo *image_info)
788 {
789 RADV_FROM_HANDLE(radv_sampler, sampler, image_info->sampler);
790
791 memcpy(dst, sampler->state, 16);
792 }
793
794 void radv_update_descriptor_sets(
795 struct radv_device* device,
796 struct radv_cmd_buffer* cmd_buffer,
797 VkDescriptorSet dstSetOverride,
798 uint32_t descriptorWriteCount,
799 const VkWriteDescriptorSet* pDescriptorWrites,
800 uint32_t descriptorCopyCount,
801 const VkCopyDescriptorSet* pDescriptorCopies)
802 {
803 uint32_t i, j;
804 for (i = 0; i < descriptorWriteCount; i++) {
805 const VkWriteDescriptorSet *writeset = &pDescriptorWrites[i];
806 RADV_FROM_HANDLE(radv_descriptor_set, set,
807 dstSetOverride ? dstSetOverride : writeset->dstSet);
808 const struct radv_descriptor_set_binding_layout *binding_layout =
809 set->layout->binding + writeset->dstBinding;
810 uint32_t *ptr = set->mapped_ptr;
811
812 /* Immutable samplers are not copied into push descriptors when they are
813 * allocated, so if we are writing push descriptors we have to copy the
814 * immutable samplers into them now.
815 */
816 const bool copy_immutable_samplers = cmd_buffer &&
817 binding_layout->immutable_samplers_offset && !binding_layout->immutable_samplers_equal;
818 const uint32_t *samplers = radv_immutable_samplers(set->layout, binding_layout);
819
820 ptr += binding_layout->offset / 4;
821 ptr += binding_layout->size * writeset->dstArrayElement / 4;
822 for (j = 0; j < writeset->descriptorCount; ++j) {
823 switch(writeset->descriptorType) {
824 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
825 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
826 unsigned idx = writeset->dstArrayElement + j;
827 idx += binding_layout->dynamic_offset_offset;
828 assert(!(set->layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
829 write_dynamic_buffer_descriptor(device, set->dynamic_descriptors + idx,
830 writeset->pBufferInfo + j);
831 break;
832 }
833 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
834 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
835 write_buffer_descriptor(device, ptr, writeset->pBufferInfo + j);
836 break;
837 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
838 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
839 write_texel_buffer_descriptor(device, ptr, writeset->pTexelBufferView[j]);
840 break;
841 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
842 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
843 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
844 write_image_descriptor(device, ptr, writeset->descriptorType,
845 writeset->pImageInfo + j);
846 break;
847 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
848 write_combined_image_sampler_descriptor(device, ptr,
849 writeset->descriptorType,
850 writeset->pImageInfo + j,
851 !binding_layout->immutable_samplers_offset);
852 if (copy_immutable_samplers) {
853 const unsigned idx = writeset->dstArrayElement + j;
854 memcpy(ptr + 16, samplers + 4 * idx, 16);
855 }
856 break;
857 case VK_DESCRIPTOR_TYPE_SAMPLER:
858 if (!binding_layout->immutable_samplers_offset) {
859 write_sampler_descriptor(device, ptr,
860 writeset->pImageInfo + j);
861 } else if (copy_immutable_samplers) {
862 unsigned idx = writeset->dstArrayElement + j;
863 memcpy(ptr, samplers + 4 * idx, 16);
864 }
865 break;
866 default:
867 unreachable("unimplemented descriptor type");
868 break;
869 }
870 ptr += binding_layout->size / 4;
871 }
872
873 }
874
875 for (i = 0; i < descriptorCopyCount; i++) {
876 const VkCopyDescriptorSet *copyset = &pDescriptorCopies[i];
877 RADV_FROM_HANDLE(radv_descriptor_set, src_set,
878 copyset->srcSet);
879 RADV_FROM_HANDLE(radv_descriptor_set, dst_set,
880 copyset->dstSet);
881 const struct radv_descriptor_set_binding_layout *src_binding_layout =
882 src_set->layout->binding + copyset->srcBinding;
883 const struct radv_descriptor_set_binding_layout *dst_binding_layout =
884 dst_set->layout->binding + copyset->dstBinding;
885 uint32_t *src_ptr = src_set->mapped_ptr;
886 uint32_t *dst_ptr = dst_set->mapped_ptr;
887
888 src_ptr += src_binding_layout->offset / 4;
889 dst_ptr += dst_binding_layout->offset / 4;
890
891 src_ptr += src_binding_layout->size * copyset->srcArrayElement / 4;
892 dst_ptr += dst_binding_layout->size * copyset->dstArrayElement / 4;
893
894 for (j = 0; j < copyset->descriptorCount; ++j) {
895 switch (src_binding_layout->type) {
896 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
897 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
898 unsigned src_idx = copyset->srcArrayElement + j;
899 unsigned dst_idx = copyset->dstArrayElement + j;
900 struct radv_descriptor_range *src_range, *dst_range;
901 src_idx += src_binding_layout->dynamic_offset_offset;
902 dst_idx += dst_binding_layout->dynamic_offset_offset;
903
904 src_range = src_set->dynamic_descriptors + src_idx;
905 dst_range = dst_set->dynamic_descriptors + dst_idx;
906 *dst_range = *src_range;
907 break;
908 }
909 default:
910 memcpy(dst_ptr, src_ptr, src_binding_layout->size);
911 }
912 src_ptr += src_binding_layout->size / 4;
913 dst_ptr += dst_binding_layout->size / 4;
914 }
915 }
916 }
917
918 void radv_UpdateDescriptorSets(
919 VkDevice _device,
920 uint32_t descriptorWriteCount,
921 const VkWriteDescriptorSet* pDescriptorWrites,
922 uint32_t descriptorCopyCount,
923 const VkCopyDescriptorSet* pDescriptorCopies)
924 {
925 RADV_FROM_HANDLE(radv_device, device, _device);
926
927 radv_update_descriptor_sets(device, NULL, VK_NULL_HANDLE, descriptorWriteCount, pDescriptorWrites,
928 descriptorCopyCount, pDescriptorCopies);
929 }
930
931 VkResult radv_CreateDescriptorUpdateTemplate(VkDevice _device,
932 const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo,
933 const VkAllocationCallbacks *pAllocator,
934 VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate)
935 {
936 RADV_FROM_HANDLE(radv_device, device, _device);
937 RADV_FROM_HANDLE(radv_descriptor_set_layout, set_layout, pCreateInfo->descriptorSetLayout);
938 const uint32_t entry_count = pCreateInfo->descriptorUpdateEntryCount;
939 const size_t size = sizeof(struct radv_descriptor_update_template) +
940 sizeof(struct radv_descriptor_update_template_entry) * entry_count;
941 struct radv_descriptor_update_template *templ;
942 uint32_t i;
943
944 templ = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
945 if (!templ)
946 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
947
948 templ->entry_count = entry_count;
949 templ->bind_point = pCreateInfo->pipelineBindPoint;
950
951 for (i = 0; i < entry_count; i++) {
952 const VkDescriptorUpdateTemplateEntryKHR *entry = &pCreateInfo->pDescriptorUpdateEntries[i];
953 const struct radv_descriptor_set_binding_layout *binding_layout =
954 set_layout->binding + entry->dstBinding;
955 const uint32_t *immutable_samplers = NULL;
956 uint32_t dst_offset;
957 uint32_t dst_stride;
958
959 /* dst_offset is an offset into dynamic_descriptors when the descriptor
960 is dynamic, and an offset into mapped_ptr otherwise */
961 switch (entry->descriptorType) {
962 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
963 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
964 assert(pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR);
965 dst_offset = binding_layout->dynamic_offset_offset + entry->dstArrayElement;
966 dst_stride = 0; /* Not used */
967 break;
968 default:
969 switch (entry->descriptorType) {
970 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
971 case VK_DESCRIPTOR_TYPE_SAMPLER:
972 /* Immutable samplers are copied into push descriptors when they are pushed */
973 if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR &&
974 binding_layout->immutable_samplers_offset && !binding_layout->immutable_samplers_equal) {
975 immutable_samplers = radv_immutable_samplers(set_layout, binding_layout) + entry->dstArrayElement * 4;
976 }
977 break;
978 default:
979 break;
980 }
981 dst_offset = binding_layout->offset / 4 + binding_layout->size * entry->dstArrayElement / 4;
982 dst_stride = binding_layout->size / 4;
983 break;
984 }
985
986 templ->entry[i] = (struct radv_descriptor_update_template_entry) {
987 .descriptor_type = entry->descriptorType,
988 .descriptor_count = entry->descriptorCount,
989 .src_offset = entry->offset,
990 .src_stride = entry->stride,
991 .dst_offset = dst_offset,
992 .dst_stride = dst_stride,
993 .has_sampler = !binding_layout->immutable_samplers_offset,
994 .immutable_samplers = immutable_samplers
995 };
996 }
997
998 *pDescriptorUpdateTemplate = radv_descriptor_update_template_to_handle(templ);
999 return VK_SUCCESS;
1000 }
1001
1002 void radv_DestroyDescriptorUpdateTemplate(VkDevice _device,
1003 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
1004 const VkAllocationCallbacks *pAllocator)
1005 {
1006 RADV_FROM_HANDLE(radv_device, device, _device);
1007 RADV_FROM_HANDLE(radv_descriptor_update_template, templ, descriptorUpdateTemplate);
1008
1009 if (!templ)
1010 return;
1011
1012 vk_free2(&device->alloc, pAllocator, templ);
1013 }
1014
1015 void radv_update_descriptor_set_with_template(struct radv_device *device,
1016 struct radv_cmd_buffer *cmd_buffer,
1017 struct radv_descriptor_set *set,
1018 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
1019 const void *pData)
1020 {
1021 RADV_FROM_HANDLE(radv_descriptor_update_template, templ, descriptorUpdateTemplate);
1022 uint32_t i;
1023
1024 for (i = 0; i < templ->entry_count; ++i) {
1025 uint32_t *pDst = set->mapped_ptr + templ->entry[i].dst_offset;
1026 const uint8_t *pSrc = ((const uint8_t *) pData) + templ->entry[i].src_offset;
1027 uint32_t j;
1028
1029 for (j = 0; j < templ->entry[i].descriptor_count; ++j) {
1030 switch (templ->entry[i].descriptor_type) {
1031 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1032 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
1033 const unsigned idx = templ->entry[i].dst_offset + j;
1034 assert(!(set->layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
1035 write_dynamic_buffer_descriptor(device, set->dynamic_descriptors + idx,
1036 (struct VkDescriptorBufferInfo *) pSrc);
1037 break;
1038 }
1039 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1040 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1041 write_buffer_descriptor(device, pDst,
1042 (struct VkDescriptorBufferInfo *) pSrc);
1043 break;
1044 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1045 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1046 write_texel_buffer_descriptor(device, pDst,
1047 *(VkBufferView *) pSrc);
1048 break;
1049 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1050 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1051 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1052 write_image_descriptor(device, pDst,
1053 templ->entry[i].descriptor_type,
1054 (struct VkDescriptorImageInfo *) pSrc);
1055 break;
1056 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1057 write_combined_image_sampler_descriptor(device, pDst,
1058 templ->entry[i].descriptor_type,
1059 (struct VkDescriptorImageInfo *) pSrc,
1060 templ->entry[i].has_sampler);
1061 if (templ->entry[i].immutable_samplers)
1062 memcpy(pDst + 16, templ->entry[i].immutable_samplers + 4 * j, 16);
1063 break;
1064 case VK_DESCRIPTOR_TYPE_SAMPLER:
1065 if (templ->entry[i].has_sampler)
1066 write_sampler_descriptor(device, pDst,
1067 (struct VkDescriptorImageInfo *) pSrc);
1068 else if (templ->entry[i].immutable_samplers)
1069 memcpy(pDst, templ->entry[i].immutable_samplers + 4 * j, 16);
1070 break;
1071 default:
1072 unreachable("unimplemented descriptor type");
1073 break;
1074 }
1075 pSrc += templ->entry[i].src_stride;
1076 pDst += templ->entry[i].dst_stride;
1077 }
1078 }
1079 }
1080
1081 void radv_UpdateDescriptorSetWithTemplate(VkDevice _device,
1082 VkDescriptorSet descriptorSet,
1083 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
1084 const void *pData)
1085 {
1086 RADV_FROM_HANDLE(radv_device, device, _device);
1087 RADV_FROM_HANDLE(radv_descriptor_set, set, descriptorSet);
1088
1089 radv_update_descriptor_set_with_template(device, NULL, set, descriptorUpdateTemplate, pData);
1090 }
1091
1092
1093 VkResult radv_CreateSamplerYcbcrConversion(VkDevice device,
1094 const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
1095 const VkAllocationCallbacks* pAllocator,
1096 VkSamplerYcbcrConversion* pYcbcrConversion)
1097 {
1098 *pYcbcrConversion = VK_NULL_HANDLE;
1099 return VK_SUCCESS;
1100 }
1101
1102
1103 void radv_DestroySamplerYcbcrConversion(VkDevice device,
1104 VkSamplerYcbcrConversion ycbcrConversion,
1105 const VkAllocationCallbacks* pAllocator)
1106 {
1107 /* Do nothing. */
1108 }