radv: Add support for variable descriptor set layouts.
[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 struct radv_descriptor_set **out_set)
396 {
397 struct radv_descriptor_set *set;
398 unsigned range_offset = sizeof(struct radv_descriptor_set);
399 unsigned mem_size = range_offset +
400 sizeof(struct radv_descriptor_range) * layout->dynamic_offset_count;
401
402 if (pool->host_memory_base) {
403 if (pool->host_memory_end - pool->host_memory_ptr < mem_size)
404 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
405
406 set = (struct radv_descriptor_set*)pool->host_memory_ptr;
407 pool->host_memory_ptr += mem_size;
408 } else {
409 set = vk_alloc2(&device->alloc, NULL, mem_size, 8,
410 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
411
412 if (!set)
413 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
414 }
415
416 memset(set, 0, mem_size);
417
418 if (layout->dynamic_offset_count) {
419 set->dynamic_descriptors = (struct radv_descriptor_range*)((uint8_t*)set + range_offset);
420 }
421
422 set->layout = layout;
423 if (layout->size) {
424 uint32_t layout_size = align_u32(layout->size, 32);
425 set->size = layout->size;
426
427 if (!pool->host_memory_base && pool->entry_count == pool->max_entry_count) {
428 vk_free2(&device->alloc, NULL, set);
429 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
430 }
431
432 /* try to allocate linearly first, so that we don't spend
433 * time looking for gaps if the app only allocates &
434 * resets via the pool. */
435 if (pool->current_offset + layout_size <= pool->size) {
436 set->bo = pool->bo;
437 set->mapped_ptr = (uint32_t*)(pool->mapped_ptr + pool->current_offset);
438 set->va = radv_buffer_get_va(set->bo) + pool->current_offset;
439 if (!pool->host_memory_base) {
440 pool->entries[pool->entry_count].offset = pool->current_offset;
441 pool->entries[pool->entry_count].size = layout_size;
442 pool->entries[pool->entry_count].set = set;
443 pool->entry_count++;
444 }
445 pool->current_offset += layout_size;
446 } else if (!pool->host_memory_base) {
447 uint64_t offset = 0;
448 int index;
449
450 for (index = 0; index < pool->entry_count; ++index) {
451 if (pool->entries[index].offset - offset >= layout_size)
452 break;
453 offset = pool->entries[index].offset + pool->entries[index].size;
454 }
455
456 if (pool->size - offset < layout_size) {
457 vk_free2(&device->alloc, NULL, set);
458 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
459 }
460 set->bo = pool->bo;
461 set->mapped_ptr = (uint32_t*)(pool->mapped_ptr + offset);
462 set->va = radv_buffer_get_va(set->bo) + offset;
463 memmove(&pool->entries[index + 1], &pool->entries[index],
464 sizeof(pool->entries[0]) * (pool->entry_count - index));
465 pool->entries[index].offset = offset;
466 pool->entries[index].size = layout_size;
467 pool->entries[index].set = set;
468 pool->entry_count++;
469 } else
470 return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
471 }
472
473 if (layout->has_immutable_samplers) {
474 for (unsigned i = 0; i < layout->binding_count; ++i) {
475 if (!layout->binding[i].immutable_samplers_offset ||
476 layout->binding[i].immutable_samplers_equal)
477 continue;
478
479 unsigned offset = layout->binding[i].offset / 4;
480 if (layout->binding[i].type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
481 offset += 16;
482
483 const uint32_t *samplers = (const uint32_t*)((const char*)layout + layout->binding[i].immutable_samplers_offset);
484 for (unsigned j = 0; j < layout->binding[i].array_size; ++j) {
485 memcpy(set->mapped_ptr + offset, samplers + 4 * j, 16);
486 offset += layout->binding[i].size / 4;
487 }
488
489 }
490 }
491 *out_set = set;
492 return VK_SUCCESS;
493 }
494
495 static void
496 radv_descriptor_set_destroy(struct radv_device *device,
497 struct radv_descriptor_pool *pool,
498 struct radv_descriptor_set *set,
499 bool free_bo)
500 {
501 assert(!pool->host_memory_base);
502
503 if (free_bo && set->size && !pool->host_memory_base) {
504 uint32_t offset = (uint8_t*)set->mapped_ptr - pool->mapped_ptr;
505 for (int i = 0; i < pool->entry_count; ++i) {
506 if (pool->entries[i].offset == offset) {
507 memmove(&pool->entries[i], &pool->entries[i+1],
508 sizeof(pool->entries[i]) * (pool->entry_count - i - 1));
509 --pool->entry_count;
510 break;
511 }
512 }
513 }
514 vk_free2(&device->alloc, NULL, set);
515 }
516
517 VkResult radv_CreateDescriptorPool(
518 VkDevice _device,
519 const VkDescriptorPoolCreateInfo* pCreateInfo,
520 const VkAllocationCallbacks* pAllocator,
521 VkDescriptorPool* pDescriptorPool)
522 {
523 RADV_FROM_HANDLE(radv_device, device, _device);
524 struct radv_descriptor_pool *pool;
525 int size = sizeof(struct radv_descriptor_pool);
526 uint64_t bo_size = 0, bo_count = 0, range_count = 0;
527
528
529 for (unsigned i = 0; i < pCreateInfo->poolSizeCount; ++i) {
530 if (pCreateInfo->pPoolSizes[i].type != VK_DESCRIPTOR_TYPE_SAMPLER)
531 bo_count += pCreateInfo->pPoolSizes[i].descriptorCount;
532
533 switch(pCreateInfo->pPoolSizes[i].type) {
534 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
535 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
536 range_count += pCreateInfo->pPoolSizes[i].descriptorCount;
537 break;
538 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
539 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
540 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
541 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
542 case VK_DESCRIPTOR_TYPE_SAMPLER:
543 /* 32 as we may need to align for images */
544 bo_size += 32 * pCreateInfo->pPoolSizes[i].descriptorCount;
545 break;
546 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
547 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
548 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
549 bo_size += 64 * pCreateInfo->pPoolSizes[i].descriptorCount;
550 break;
551 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
552 bo_size += 96 * pCreateInfo->pPoolSizes[i].descriptorCount;
553 break;
554 default:
555 unreachable("unknown descriptor type\n");
556 break;
557 }
558 }
559
560 if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) {
561 uint64_t host_size = pCreateInfo->maxSets * sizeof(struct radv_descriptor_set);
562 host_size += sizeof(struct radeon_winsys_bo*) * bo_count;
563 host_size += sizeof(struct radv_descriptor_range) * range_count;
564 size += host_size;
565 } else {
566 size += sizeof(struct radv_descriptor_pool_entry) * pCreateInfo->maxSets;
567 }
568
569 pool = vk_alloc2(&device->alloc, pAllocator, size, 8,
570 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
571 if (!pool)
572 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
573
574 memset(pool, 0, sizeof(*pool));
575
576 if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) {
577 pool->host_memory_base = (uint8_t*)pool + sizeof(struct radv_descriptor_pool);
578 pool->host_memory_ptr = pool->host_memory_base;
579 pool->host_memory_end = (uint8_t*)pool + size;
580 }
581
582 if (bo_size) {
583 pool->bo = device->ws->buffer_create(device->ws, bo_size, 32,
584 RADEON_DOMAIN_VRAM,
585 RADEON_FLAG_NO_INTERPROCESS_SHARING |
586 RADEON_FLAG_READ_ONLY);
587 pool->mapped_ptr = (uint8_t*)device->ws->buffer_map(pool->bo);
588 }
589 pool->size = bo_size;
590 pool->max_entry_count = pCreateInfo->maxSets;
591
592 *pDescriptorPool = radv_descriptor_pool_to_handle(pool);
593 return VK_SUCCESS;
594 }
595
596 void radv_DestroyDescriptorPool(
597 VkDevice _device,
598 VkDescriptorPool _pool,
599 const VkAllocationCallbacks* pAllocator)
600 {
601 RADV_FROM_HANDLE(radv_device, device, _device);
602 RADV_FROM_HANDLE(radv_descriptor_pool, pool, _pool);
603
604 if (!pool)
605 return;
606
607 if (!pool->host_memory_base) {
608 for(int i = 0; i < pool->entry_count; ++i) {
609 radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
610 }
611 }
612
613 if (pool->bo)
614 device->ws->buffer_destroy(pool->bo);
615 vk_free2(&device->alloc, pAllocator, pool);
616 }
617
618 VkResult radv_ResetDescriptorPool(
619 VkDevice _device,
620 VkDescriptorPool descriptorPool,
621 VkDescriptorPoolResetFlags flags)
622 {
623 RADV_FROM_HANDLE(radv_device, device, _device);
624 RADV_FROM_HANDLE(radv_descriptor_pool, pool, descriptorPool);
625
626 if (!pool->host_memory_base) {
627 for(int i = 0; i < pool->entry_count; ++i) {
628 radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
629 }
630 pool->entry_count = 0;
631 }
632
633 pool->current_offset = 0;
634 pool->host_memory_ptr = pool->host_memory_base;
635
636 return VK_SUCCESS;
637 }
638
639 VkResult radv_AllocateDescriptorSets(
640 VkDevice _device,
641 const VkDescriptorSetAllocateInfo* pAllocateInfo,
642 VkDescriptorSet* pDescriptorSets)
643 {
644 RADV_FROM_HANDLE(radv_device, device, _device);
645 RADV_FROM_HANDLE(radv_descriptor_pool, pool, pAllocateInfo->descriptorPool);
646
647 VkResult result = VK_SUCCESS;
648 uint32_t i;
649 struct radv_descriptor_set *set = NULL;
650
651 /* allocate a set of buffers for each shader to contain descriptors */
652 for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
653 RADV_FROM_HANDLE(radv_descriptor_set_layout, layout,
654 pAllocateInfo->pSetLayouts[i]);
655
656 assert(!(layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
657
658 result = radv_descriptor_set_create(device, pool, layout, &set);
659 if (result != VK_SUCCESS)
660 break;
661
662 pDescriptorSets[i] = radv_descriptor_set_to_handle(set);
663 }
664
665 if (result != VK_SUCCESS)
666 radv_FreeDescriptorSets(_device, pAllocateInfo->descriptorPool,
667 i, pDescriptorSets);
668 return result;
669 }
670
671 VkResult radv_FreeDescriptorSets(
672 VkDevice _device,
673 VkDescriptorPool descriptorPool,
674 uint32_t count,
675 const VkDescriptorSet* pDescriptorSets)
676 {
677 RADV_FROM_HANDLE(radv_device, device, _device);
678 RADV_FROM_HANDLE(radv_descriptor_pool, pool, descriptorPool);
679
680 for (uint32_t i = 0; i < count; i++) {
681 RADV_FROM_HANDLE(radv_descriptor_set, set, pDescriptorSets[i]);
682
683 if (set && !pool->host_memory_base)
684 radv_descriptor_set_destroy(device, pool, set, true);
685 }
686 return VK_SUCCESS;
687 }
688
689 static void write_texel_buffer_descriptor(struct radv_device *device,
690 unsigned *dst,
691 const VkBufferView _buffer_view)
692 {
693 RADV_FROM_HANDLE(radv_buffer_view, buffer_view, _buffer_view);
694
695 memcpy(dst, buffer_view->state, 4 * 4);
696 }
697
698 static void write_buffer_descriptor(struct radv_device *device,
699 unsigned *dst,
700 const VkDescriptorBufferInfo *buffer_info)
701 {
702 RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
703 uint64_t va = radv_buffer_get_va(buffer->bo);
704 uint32_t range = buffer_info->range;
705
706 if (buffer_info->range == VK_WHOLE_SIZE)
707 range = buffer->size - buffer_info->offset;
708
709 va += buffer_info->offset + buffer->offset;
710 dst[0] = va;
711 dst[1] = S_008F04_BASE_ADDRESS_HI(va >> 32);
712 dst[2] = range;
713 dst[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
714 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
715 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
716 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
717 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
718 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32);
719
720 }
721
722 static void write_dynamic_buffer_descriptor(struct radv_device *device,
723 struct radv_descriptor_range *range,
724 const VkDescriptorBufferInfo *buffer_info)
725 {
726 RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
727 uint64_t va = radv_buffer_get_va(buffer->bo);
728 unsigned size = buffer_info->range;
729
730 if (buffer_info->range == VK_WHOLE_SIZE)
731 size = buffer->size - buffer_info->offset;
732
733 va += buffer_info->offset + buffer->offset;
734 range->va = va;
735 range->size = size;
736 }
737
738 static void
739 write_image_descriptor(struct radv_device *device,
740 unsigned *dst,
741 VkDescriptorType descriptor_type,
742 const VkDescriptorImageInfo *image_info)
743 {
744 RADV_FROM_HANDLE(radv_image_view, iview, image_info->imageView);
745 uint32_t *descriptor;
746
747 if (descriptor_type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
748 descriptor = iview->storage_descriptor;
749 } else {
750 descriptor = iview->descriptor;
751 }
752
753 memcpy(dst, descriptor, 16 * 4);
754 }
755
756 static void
757 write_combined_image_sampler_descriptor(struct radv_device *device,
758 unsigned *dst,
759 VkDescriptorType descriptor_type,
760 const VkDescriptorImageInfo *image_info,
761 bool has_sampler)
762 {
763 RADV_FROM_HANDLE(radv_sampler, sampler, image_info->sampler);
764
765 write_image_descriptor(device, dst, descriptor_type, image_info);
766 /* copy over sampler state */
767 if (has_sampler)
768 memcpy(dst + 16, sampler->state, 16);
769 }
770
771 static void
772 write_sampler_descriptor(struct radv_device *device,
773 unsigned *dst,
774 const VkDescriptorImageInfo *image_info)
775 {
776 RADV_FROM_HANDLE(radv_sampler, sampler, image_info->sampler);
777
778 memcpy(dst, sampler->state, 16);
779 }
780
781 void radv_update_descriptor_sets(
782 struct radv_device* device,
783 struct radv_cmd_buffer* cmd_buffer,
784 VkDescriptorSet dstSetOverride,
785 uint32_t descriptorWriteCount,
786 const VkWriteDescriptorSet* pDescriptorWrites,
787 uint32_t descriptorCopyCount,
788 const VkCopyDescriptorSet* pDescriptorCopies)
789 {
790 uint32_t i, j;
791 for (i = 0; i < descriptorWriteCount; i++) {
792 const VkWriteDescriptorSet *writeset = &pDescriptorWrites[i];
793 RADV_FROM_HANDLE(radv_descriptor_set, set,
794 dstSetOverride ? dstSetOverride : writeset->dstSet);
795 const struct radv_descriptor_set_binding_layout *binding_layout =
796 set->layout->binding + writeset->dstBinding;
797 uint32_t *ptr = set->mapped_ptr;
798
799 /* Immutable samplers are not copied into push descriptors when they are
800 * allocated, so if we are writing push descriptors we have to copy the
801 * immutable samplers into them now.
802 */
803 const bool copy_immutable_samplers = cmd_buffer &&
804 binding_layout->immutable_samplers_offset && !binding_layout->immutable_samplers_equal;
805 const uint32_t *samplers = radv_immutable_samplers(set->layout, binding_layout);
806
807 ptr += binding_layout->offset / 4;
808 ptr += binding_layout->size * writeset->dstArrayElement / 4;
809 for (j = 0; j < writeset->descriptorCount; ++j) {
810 switch(writeset->descriptorType) {
811 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
812 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
813 unsigned idx = writeset->dstArrayElement + j;
814 idx += binding_layout->dynamic_offset_offset;
815 assert(!(set->layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
816 write_dynamic_buffer_descriptor(device, set->dynamic_descriptors + idx,
817 writeset->pBufferInfo + j);
818 break;
819 }
820 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
821 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
822 write_buffer_descriptor(device, ptr, writeset->pBufferInfo + j);
823 break;
824 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
825 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
826 write_texel_buffer_descriptor(device, ptr, writeset->pTexelBufferView[j]);
827 break;
828 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
829 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
830 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
831 write_image_descriptor(device, ptr, writeset->descriptorType,
832 writeset->pImageInfo + j);
833 break;
834 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
835 write_combined_image_sampler_descriptor(device, ptr,
836 writeset->descriptorType,
837 writeset->pImageInfo + j,
838 !binding_layout->immutable_samplers_offset);
839 if (copy_immutable_samplers) {
840 const unsigned idx = writeset->dstArrayElement + j;
841 memcpy(ptr + 16, samplers + 4 * idx, 16);
842 }
843 break;
844 case VK_DESCRIPTOR_TYPE_SAMPLER:
845 if (!binding_layout->immutable_samplers_offset) {
846 write_sampler_descriptor(device, ptr,
847 writeset->pImageInfo + j);
848 } else if (copy_immutable_samplers) {
849 unsigned idx = writeset->dstArrayElement + j;
850 memcpy(ptr, samplers + 4 * idx, 16);
851 }
852 break;
853 default:
854 unreachable("unimplemented descriptor type");
855 break;
856 }
857 ptr += binding_layout->size / 4;
858 }
859
860 }
861
862 for (i = 0; i < descriptorCopyCount; i++) {
863 const VkCopyDescriptorSet *copyset = &pDescriptorCopies[i];
864 RADV_FROM_HANDLE(radv_descriptor_set, src_set,
865 copyset->srcSet);
866 RADV_FROM_HANDLE(radv_descriptor_set, dst_set,
867 copyset->dstSet);
868 const struct radv_descriptor_set_binding_layout *src_binding_layout =
869 src_set->layout->binding + copyset->srcBinding;
870 const struct radv_descriptor_set_binding_layout *dst_binding_layout =
871 dst_set->layout->binding + copyset->dstBinding;
872 uint32_t *src_ptr = src_set->mapped_ptr;
873 uint32_t *dst_ptr = dst_set->mapped_ptr;
874
875 src_ptr += src_binding_layout->offset / 4;
876 dst_ptr += dst_binding_layout->offset / 4;
877
878 src_ptr += src_binding_layout->size * copyset->srcArrayElement / 4;
879 dst_ptr += dst_binding_layout->size * copyset->dstArrayElement / 4;
880
881 for (j = 0; j < copyset->descriptorCount; ++j) {
882 switch (src_binding_layout->type) {
883 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
884 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
885 unsigned src_idx = copyset->srcArrayElement + j;
886 unsigned dst_idx = copyset->dstArrayElement + j;
887 struct radv_descriptor_range *src_range, *dst_range;
888 src_idx += src_binding_layout->dynamic_offset_offset;
889 dst_idx += dst_binding_layout->dynamic_offset_offset;
890
891 src_range = src_set->dynamic_descriptors + src_idx;
892 dst_range = dst_set->dynamic_descriptors + dst_idx;
893 *dst_range = *src_range;
894 break;
895 }
896 default:
897 memcpy(dst_ptr, src_ptr, src_binding_layout->size);
898 }
899 src_ptr += src_binding_layout->size / 4;
900 dst_ptr += dst_binding_layout->size / 4;
901 }
902 }
903 }
904
905 void radv_UpdateDescriptorSets(
906 VkDevice _device,
907 uint32_t descriptorWriteCount,
908 const VkWriteDescriptorSet* pDescriptorWrites,
909 uint32_t descriptorCopyCount,
910 const VkCopyDescriptorSet* pDescriptorCopies)
911 {
912 RADV_FROM_HANDLE(radv_device, device, _device);
913
914 radv_update_descriptor_sets(device, NULL, VK_NULL_HANDLE, descriptorWriteCount, pDescriptorWrites,
915 descriptorCopyCount, pDescriptorCopies);
916 }
917
918 VkResult radv_CreateDescriptorUpdateTemplate(VkDevice _device,
919 const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo,
920 const VkAllocationCallbacks *pAllocator,
921 VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate)
922 {
923 RADV_FROM_HANDLE(radv_device, device, _device);
924 RADV_FROM_HANDLE(radv_descriptor_set_layout, set_layout, pCreateInfo->descriptorSetLayout);
925 const uint32_t entry_count = pCreateInfo->descriptorUpdateEntryCount;
926 const size_t size = sizeof(struct radv_descriptor_update_template) +
927 sizeof(struct radv_descriptor_update_template_entry) * entry_count;
928 struct radv_descriptor_update_template *templ;
929 uint32_t i;
930
931 templ = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
932 if (!templ)
933 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
934
935 templ->entry_count = entry_count;
936 templ->bind_point = pCreateInfo->pipelineBindPoint;
937
938 for (i = 0; i < entry_count; i++) {
939 const VkDescriptorUpdateTemplateEntryKHR *entry = &pCreateInfo->pDescriptorUpdateEntries[i];
940 const struct radv_descriptor_set_binding_layout *binding_layout =
941 set_layout->binding + entry->dstBinding;
942 const uint32_t *immutable_samplers = NULL;
943 uint32_t dst_offset;
944 uint32_t dst_stride;
945
946 /* dst_offset is an offset into dynamic_descriptors when the descriptor
947 is dynamic, and an offset into mapped_ptr otherwise */
948 switch (entry->descriptorType) {
949 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
950 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
951 assert(pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR);
952 dst_offset = binding_layout->dynamic_offset_offset + entry->dstArrayElement;
953 dst_stride = 0; /* Not used */
954 break;
955 default:
956 switch (entry->descriptorType) {
957 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
958 case VK_DESCRIPTOR_TYPE_SAMPLER:
959 /* Immutable samplers are copied into push descriptors when they are pushed */
960 if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR &&
961 binding_layout->immutable_samplers_offset && !binding_layout->immutable_samplers_equal) {
962 immutable_samplers = radv_immutable_samplers(set_layout, binding_layout) + entry->dstArrayElement * 4;
963 }
964 break;
965 default:
966 break;
967 }
968 dst_offset = binding_layout->offset / 4 + binding_layout->size * entry->dstArrayElement / 4;
969 dst_stride = binding_layout->size / 4;
970 break;
971 }
972
973 templ->entry[i] = (struct radv_descriptor_update_template_entry) {
974 .descriptor_type = entry->descriptorType,
975 .descriptor_count = entry->descriptorCount,
976 .src_offset = entry->offset,
977 .src_stride = entry->stride,
978 .dst_offset = dst_offset,
979 .dst_stride = dst_stride,
980 .has_sampler = !binding_layout->immutable_samplers_offset,
981 .immutable_samplers = immutable_samplers
982 };
983 }
984
985 *pDescriptorUpdateTemplate = radv_descriptor_update_template_to_handle(templ);
986 return VK_SUCCESS;
987 }
988
989 void radv_DestroyDescriptorUpdateTemplate(VkDevice _device,
990 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
991 const VkAllocationCallbacks *pAllocator)
992 {
993 RADV_FROM_HANDLE(radv_device, device, _device);
994 RADV_FROM_HANDLE(radv_descriptor_update_template, templ, descriptorUpdateTemplate);
995
996 if (!templ)
997 return;
998
999 vk_free2(&device->alloc, pAllocator, templ);
1000 }
1001
1002 void radv_update_descriptor_set_with_template(struct radv_device *device,
1003 struct radv_cmd_buffer *cmd_buffer,
1004 struct radv_descriptor_set *set,
1005 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
1006 const void *pData)
1007 {
1008 RADV_FROM_HANDLE(radv_descriptor_update_template, templ, descriptorUpdateTemplate);
1009 uint32_t i;
1010
1011 for (i = 0; i < templ->entry_count; ++i) {
1012 uint32_t *pDst = set->mapped_ptr + templ->entry[i].dst_offset;
1013 const uint8_t *pSrc = ((const uint8_t *) pData) + templ->entry[i].src_offset;
1014 uint32_t j;
1015
1016 for (j = 0; j < templ->entry[i].descriptor_count; ++j) {
1017 switch (templ->entry[i].descriptor_type) {
1018 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1019 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
1020 const unsigned idx = templ->entry[i].dst_offset + j;
1021 assert(!(set->layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
1022 write_dynamic_buffer_descriptor(device, set->dynamic_descriptors + idx,
1023 (struct VkDescriptorBufferInfo *) pSrc);
1024 break;
1025 }
1026 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1027 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1028 write_buffer_descriptor(device, pDst,
1029 (struct VkDescriptorBufferInfo *) pSrc);
1030 break;
1031 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1032 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1033 write_texel_buffer_descriptor(device, pDst,
1034 *(VkBufferView *) pSrc);
1035 break;
1036 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1037 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1038 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1039 write_image_descriptor(device, pDst,
1040 templ->entry[i].descriptor_type,
1041 (struct VkDescriptorImageInfo *) pSrc);
1042 break;
1043 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1044 write_combined_image_sampler_descriptor(device, pDst,
1045 templ->entry[i].descriptor_type,
1046 (struct VkDescriptorImageInfo *) pSrc,
1047 templ->entry[i].has_sampler);
1048 if (templ->entry[i].immutable_samplers)
1049 memcpy(pDst + 16, templ->entry[i].immutable_samplers + 4 * j, 16);
1050 break;
1051 case VK_DESCRIPTOR_TYPE_SAMPLER:
1052 if (templ->entry[i].has_sampler)
1053 write_sampler_descriptor(device, pDst,
1054 (struct VkDescriptorImageInfo *) pSrc);
1055 else if (templ->entry[i].immutable_samplers)
1056 memcpy(pDst, templ->entry[i].immutable_samplers + 4 * j, 16);
1057 break;
1058 default:
1059 unreachable("unimplemented descriptor type");
1060 break;
1061 }
1062 pSrc += templ->entry[i].src_stride;
1063 pDst += templ->entry[i].dst_stride;
1064 }
1065 }
1066 }
1067
1068 void radv_UpdateDescriptorSetWithTemplate(VkDevice _device,
1069 VkDescriptorSet descriptorSet,
1070 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
1071 const void *pData)
1072 {
1073 RADV_FROM_HANDLE(radv_device, device, _device);
1074 RADV_FROM_HANDLE(radv_descriptor_set, set, descriptorSet);
1075
1076 radv_update_descriptor_set_with_template(device, NULL, set, descriptorUpdateTemplate, pData);
1077 }
1078
1079
1080 VkResult radv_CreateSamplerYcbcrConversion(VkDevice device,
1081 const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
1082 const VkAllocationCallbacks* pAllocator,
1083 VkSamplerYcbcrConversion* pYcbcrConversion)
1084 {
1085 *pYcbcrConversion = VK_NULL_HANDLE;
1086 return VK_SUCCESS;
1087 }
1088
1089
1090 void radv_DestroySamplerYcbcrConversion(VkDevice device,
1091 VkSamplerYcbcrConversion ycbcrConversion,
1092 const VkAllocationCallbacks* pAllocator)
1093 {
1094 /* Do nothing. */
1095 }