~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/amd/vulkan/radv_descriptor_set.c

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
radv_descriptor_type_buffer_count(VkDescriptorType type)
39
39
{
40
40
   switch (type) {
41
 
      case VK_DESCRIPTOR_TYPE_SAMPLER:
42
 
      case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
43
 
      case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
44
 
         return 0;
45
 
      case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
46
 
      case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
47
 
      case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
48
 
      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
49
 
      case VK_DESCRIPTOR_TYPE_MUTABLE_EXT:
50
 
         return 3;
51
 
      default:
52
 
         return 1;
 
41
   case VK_DESCRIPTOR_TYPE_SAMPLER:
 
42
   case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
 
43
   case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
 
44
      return 0;
 
45
   case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
 
46
   case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
 
47
   case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
 
48
   case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
 
49
   case VK_DESCRIPTOR_TYPE_MUTABLE_EXT:
 
50
      return 3;
 
51
   default:
 
52
      return 1;
53
53
   }
54
54
}
55
55
 
59
59
   if (!samplers)
60
60
      return false;
61
61
   for (uint32_t i = 1; i < count; ++i) {
62
 
      if (memcmp(radv_sampler_from_handle(samplers[0])->state,
63
 
                 radv_sampler_from_handle(samplers[i])->state, 16)) {
 
62
      if (memcmp(radv_sampler_from_handle(samplers[0])->state, radv_sampler_from_handle(samplers[i])->state, 16)) {
64
63
         return false;
65
64
      }
66
65
   }
91
90
}
92
91
 
93
92
static bool
94
 
radv_mutable_descriptor_type_size_alignment(const VkMutableDescriptorTypeListVALVE *list,
95
 
                                            uint64_t *out_size, uint64_t *out_align)
 
93
radv_mutable_descriptor_type_size_alignment(const VkMutableDescriptorTypeListVALVE *list, uint64_t *out_size,
 
94
                                            uint64_t *out_align)
96
95
{
97
96
   uint32_t max_size = 0;
98
97
   uint32_t max_align = 0;
130
129
 
131
130
VKAPI_ATTR VkResult VKAPI_CALL
132
131
radv_CreateDescriptorSetLayout(VkDevice _device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
133
 
                               const VkAllocationCallbacks *pAllocator,
134
 
                               VkDescriptorSetLayout *pSetLayout)
 
132
                               const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout)
135
133
{
136
134
   RADV_FROM_HANDLE(radv_device, device, _device);
137
135
   struct radv_descriptor_set_layout *set_layout;
154
152
 
155
153
         bool has_ycbcr_sampler = false;
156
154
         for (unsigned i = 0; i < pCreateInfo->pBindings[j].descriptorCount; ++i) {
157
 
            if (radv_sampler_from_handle(pCreateInfo->pBindings[j].pImmutableSamplers[i])
158
 
                   ->ycbcr_sampler)
 
155
            if (radv_sampler_from_handle(pCreateInfo->pBindings[j].pImmutableSamplers[i])->ycbcr_sampler)
159
156
               has_ycbcr_sampler = true;
160
157
         }
161
158
 
174
171
      size += ycbcr_sampler_count * sizeof(struct vk_ycbcr_conversion_state);
175
172
   }
176
173
 
177
 
   /* We need to allocate decriptor set layouts off the device allocator with DEVICE scope because
 
174
   /* We need to allocate descriptor set layouts off the device allocator with DEVICE scope because
178
175
    * they are reference counted and may not be destroyed when vkDestroyDescriptorSetLayout is
179
176
    * called.
180
177
    */
193
190
      ycbcr_sampler_offsets = samplers + 4 * immutable_sampler_count;
194
191
      set_layout->ycbcr_sampler_offsets_offset = (char *)ycbcr_sampler_offsets - (char *)set_layout;
195
192
 
196
 
      uintptr_t first_ycbcr_sampler_offset =
197
 
         (uintptr_t)ycbcr_sampler_offsets + sizeof(uint32_t) * num_bindings;
198
 
      first_ycbcr_sampler_offset =
199
 
         ALIGN(first_ycbcr_sampler_offset, alignof(struct vk_ycbcr_conversion_state));
 
193
      uintptr_t first_ycbcr_sampler_offset = (uintptr_t)ycbcr_sampler_offsets + sizeof(uint32_t) * num_bindings;
 
194
      first_ycbcr_sampler_offset = ALIGN(first_ycbcr_sampler_offset, alignof(struct vk_ycbcr_conversion_state));
200
195
      ycbcr_samplers = (struct vk_ycbcr_conversion_state *)first_ycbcr_sampler_offset;
201
196
   } else
202
197
      set_layout->ycbcr_sampler_offsets_offset = 0;
203
198
 
204
199
   VkDescriptorSetLayoutBinding *bindings = NULL;
205
 
   VkResult result =
206
 
      vk_create_sorted_bindings(pCreateInfo->pBindings, pCreateInfo->bindingCount, &bindings);
 
200
   VkResult result = vk_create_sorted_bindings(pCreateInfo->pBindings, pCreateInfo->bindingCount, &bindings);
207
201
   if (result != VK_SUCCESS) {
208
202
      vk_descriptor_set_layout_unref(&device->vk, &set_layout->vk);
209
203
      return vk_error(device, result);
220
214
 
221
215
   uint32_t first_alignment = 32;
222
216
   if (pCreateInfo->bindingCount > 0) {
223
 
      uint32_t last_alignment =
224
 
         radv_descriptor_alignment(bindings[pCreateInfo->bindingCount - 1].descriptorType);
225
 
      if (bindings[pCreateInfo->bindingCount - 1].descriptorType ==
226
 
          VK_DESCRIPTOR_TYPE_MUTABLE_EXT) {
 
217
      uint32_t last_alignment = radv_descriptor_alignment(bindings[pCreateInfo->bindingCount - 1].descriptorType);
 
218
      if (bindings[pCreateInfo->bindingCount - 1].descriptorType == VK_DESCRIPTOR_TYPE_MUTABLE_EXT) {
227
219
         uint64_t mutable_size = 0, mutable_align = 0;
228
220
         radv_mutable_descriptor_type_size_alignment(
229
 
            &mutable_info->pMutableDescriptorTypeLists[pCreateInfo->bindingCount - 1],
230
 
            &mutable_size, &mutable_align);
 
221
            &mutable_info->pMutableDescriptorTypeLists[pCreateInfo->bindingCount - 1], &mutable_size, &mutable_align);
231
222
         last_alignment = mutable_align;
232
223
      }
233
224
 
246
237
         /* main image + fmask */
247
238
         uint32_t max_sampled_image_descriptors = 2;
248
239
 
249
 
         if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
250
 
             binding->pImmutableSamplers) {
 
240
         if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER && binding->pImmutableSamplers) {
251
241
            for (unsigned i = 0; i < binding->descriptorCount; ++i) {
252
242
               struct vk_ycbcr_conversion *conversion =
253
243
                  radv_sampler_from_handle(binding->pImmutableSamplers[i])->ycbcr_sampler;
255
245
               if (conversion) {
256
246
                  has_ycbcr_sampler = true;
257
247
                  max_sampled_image_descriptors =
258
 
                     MAX2(max_sampled_image_descriptors,
259
 
                          vk_format_get_plane_count(conversion->state.format));
 
248
                     MAX2(max_sampled_image_descriptors, vk_format_get_plane_count(conversion->state.format));
260
249
               }
261
250
            }
262
251
         }
294
283
            break;
295
284
         case VK_DESCRIPTOR_TYPE_MUTABLE_EXT: {
296
285
            uint64_t mutable_size = 0, mutable_align = 0;
297
 
            radv_mutable_descriptor_type_size_alignment(
298
 
               &mutable_info->pMutableDescriptorTypeLists[j], &mutable_size, &mutable_align);
 
286
            radv_mutable_descriptor_type_size_alignment(&mutable_info->pMutableDescriptorTypeLists[j], &mutable_size,
 
287
                                                        &mutable_align);
299
288
            assert(mutable_size && mutable_align);
300
289
            set_layout->binding[b].size = mutable_size;
301
290
            alignment = mutable_align;
312
301
            break;
313
302
         }
314
303
 
315
 
         if ((pass == 0 && alignment != first_alignment) ||
316
 
             (pass == 1 && alignment == first_alignment))
 
304
         if ((pass == 0 && alignment != first_alignment) || (pass == 1 && alignment == first_alignment))
317
305
            continue;
318
306
 
319
307
         set_layout->size = align(set_layout->size, alignment);
324
312
         set_layout->binding[b].dynamic_offset_offset = dynamic_offset_count;
325
313
 
326
314
         if (variable_flags && binding->binding < variable_flags->bindingCount &&
327
 
             (variable_flags->pBindingFlags[binding->binding] &
328
 
              VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT)) {
329
 
            assert(
330
 
               !binding->pImmutableSamplers); /* Terribly ill defined  how many samplers are valid */
 
315
             (variable_flags->pBindingFlags[binding->binding] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT)) {
 
316
            assert(!binding->pImmutableSamplers); /* Terribly ill defined  how many samplers are valid */
331
317
            assert(binding->binding == num_bindings - 1);
332
318
 
333
319
            set_layout->has_variable_descriptors = true;
342
328
            /* Do not optimize space for descriptor buffers and embedded samplers, otherwise the set
343
329
             * layout size/offset are incorrect.
344
330
             */
345
 
            if (!(pCreateInfo->flags &
346
 
                  (VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT |
347
 
                   VK_DESCRIPTOR_SET_LAYOUT_CREATE_EMBEDDED_IMMUTABLE_SAMPLERS_BIT_EXT))) {
348
 
               set_layout->binding[b].immutable_samplers_equal = has_equal_immutable_samplers(
349
 
                  binding->pImmutableSamplers, binding->descriptorCount);
 
331
            if (!(pCreateInfo->flags & (VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT |
 
332
                                        VK_DESCRIPTOR_SET_LAYOUT_CREATE_EMBEDDED_IMMUTABLE_SAMPLERS_BIT_EXT))) {
 
333
               set_layout->binding[b].immutable_samplers_equal =
 
334
                  has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount);
350
335
            }
351
336
 
352
337
            for (uint32_t i = 0; i < binding->descriptorCount; i++)
353
 
               memcpy(samplers + 4 * i,
354
 
                      &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
 
338
               memcpy(samplers + 4 * i, &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
355
339
 
356
340
            /* Don't reserve space for the samplers if they're not accessed. */
357
341
            if (set_layout->binding[b].immutable_samplers_equal) {
368
352
               ycbcr_sampler_offsets[b] = (const char *)ycbcr_samplers - (const char *)set_layout;
369
353
               for (uint32_t i = 0; i < binding->descriptorCount; i++) {
370
354
                  if (radv_sampler_from_handle(binding->pImmutableSamplers[i])->ycbcr_sampler)
371
 
                     ycbcr_samplers[i] = radv_sampler_from_handle(binding->pImmutableSamplers[i])
372
 
                                            ->ycbcr_sampler->state;
 
355
                     ycbcr_samplers[i] = radv_sampler_from_handle(binding->pImmutableSamplers[i])->ycbcr_sampler->state;
373
356
                  else
374
357
                     ycbcr_samplers[i].format = VK_FORMAT_UNDEFINED;
375
358
               }
393
376
    * carefully constructed to not have pointers so a full hash instead of a per-field hash
394
377
    * should be ok.
395
378
    */
396
 
   uint32_t hash_offset =
397
 
      offsetof(struct radv_descriptor_set_layout, hash) + sizeof(set_layout->hash);
 
379
   uint32_t hash_offset = offsetof(struct radv_descriptor_set_layout, hash) + sizeof(set_layout->hash);
398
380
   _mesa_sha1_compute((const char *)set_layout + hash_offset, size - hash_offset, set_layout->hash);
399
381
 
400
382
   *pSetLayout = radv_descriptor_set_layout_to_handle(set_layout);
403
385
}
404
386
 
405
387
VKAPI_ATTR void VKAPI_CALL
406
 
radv_GetDescriptorSetLayoutSupport(VkDevice device,
407
 
                                   const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
 
388
radv_GetDescriptorSetLayoutSupport(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
408
389
                                   VkDescriptorSetLayoutSupport *pSupport)
409
390
{
410
391
   VkDescriptorSetLayoutBinding *bindings = NULL;
411
 
   VkResult result =
412
 
      vk_create_sorted_bindings(pCreateInfo->pBindings, pCreateInfo->bindingCount, &bindings);
 
392
   VkResult result = vk_create_sorted_bindings(pCreateInfo->pBindings, pCreateInfo->bindingCount, &bindings);
413
393
   if (result != VK_SUCCESS) {
414
394
      pSupport->supported = false;
415
395
      return;
417
397
 
418
398
   const VkDescriptorSetLayoutBindingFlagsCreateInfo *variable_flags =
419
399
      vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO);
420
 
   VkDescriptorSetVariableDescriptorCountLayoutSupport *variable_count = vk_find_struct(
421
 
      (void *)pCreateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT);
 
400
   VkDescriptorSetVariableDescriptorCountLayoutSupport *variable_count =
 
401
      vk_find_struct(pSupport->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT);
422
402
   const VkMutableDescriptorTypeCreateInfoEXT *mutable_info =
423
403
      vk_find_struct_const(pCreateInfo->pNext, MUTABLE_DESCRIPTOR_TYPE_CREATE_INFO_EXT);
424
404
   if (variable_count) {
427
407
 
428
408
   uint32_t first_alignment = 32;
429
409
   if (pCreateInfo->bindingCount > 0) {
430
 
      uint32_t last_alignment =
431
 
         radv_descriptor_alignment(bindings[pCreateInfo->bindingCount - 1].descriptorType);
432
 
      if (bindings[pCreateInfo->bindingCount - 1].descriptorType ==
433
 
          VK_DESCRIPTOR_TYPE_MUTABLE_EXT) {
 
410
      uint32_t last_alignment = radv_descriptor_alignment(bindings[pCreateInfo->bindingCount - 1].descriptorType);
 
411
      if (bindings[pCreateInfo->bindingCount - 1].descriptorType == VK_DESCRIPTOR_TYPE_MUTABLE_EXT) {
434
412
         uint64_t mutable_size = 0, mutable_align = 0;
435
413
         radv_mutable_descriptor_type_size_alignment(
436
 
            &mutable_info->pMutableDescriptorTypeLists[pCreateInfo->bindingCount - 1],
437
 
            &mutable_size, &mutable_align);
 
414
            &mutable_info->pMutableDescriptorTypeLists[pCreateInfo->bindingCount - 1], &mutable_size, &mutable_align);
438
415
         last_alignment = mutable_align;
439
416
      }
440
417
 
484
461
            descriptor_count = 1;
485
462
            break;
486
463
         case VK_DESCRIPTOR_TYPE_MUTABLE_EXT:
487
 
            if (!radv_mutable_descriptor_type_size_alignment(
488
 
                   &mutable_info->pMutableDescriptorTypeLists[i], &descriptor_size,
489
 
                   &descriptor_alignment)) {
 
464
            if (!radv_mutable_descriptor_type_size_alignment(&mutable_info->pMutableDescriptorTypeLists[i],
 
465
                                                             &descriptor_size, &descriptor_alignment)) {
490
466
               supported = false;
491
467
            }
492
468
            break;
516
492
            supported = false;
517
493
         }
518
494
         if (variable_flags && binding->binding < variable_flags->bindingCount && variable_count &&
519
 
             (variable_flags->pBindingFlags[binding->binding] &
520
 
              VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT)) {
 
495
             (variable_flags->pBindingFlags[binding->binding] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT)) {
521
496
            variable_count->maxVariableDescriptorCount = MIN2(UINT32_MAX, max_count);
522
497
         }
523
498
         size += descriptor_count * descriptor_size;
534
509
 * just multiple descriptor set layouts pasted together.
535
510
 */
536
511
void
537
 
radv_pipeline_layout_init(struct radv_device *device, struct radv_pipeline_layout *layout,
538
 
                          bool independent_sets)
 
512
radv_pipeline_layout_init(struct radv_device *device, struct radv_pipeline_layout *layout, bool independent_sets)
539
513
{
540
514
   memset(layout, 0, sizeof(*layout));
541
515
 
595
569
 
596
570
VKAPI_ATTR VkResult VKAPI_CALL
597
571
radv_CreatePipelineLayout(VkDevice _device, const VkPipelineLayoutCreateInfo *pCreateInfo,
598
 
                          const VkAllocationCallbacks *pAllocator,
599
 
                          VkPipelineLayout *pPipelineLayout)
 
572
                          const VkAllocationCallbacks *pAllocator, VkPipelineLayout *pPipelineLayout)
600
573
{
601
574
   RADV_FROM_HANDLE(radv_device, device, _device);
602
575
   struct radv_pipeline_layout *layout;
603
576
 
604
577
   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO);
605
578
 
606
 
   layout = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*layout), 8,
607
 
                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 
579
   layout = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*layout), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
608
580
   if (layout == NULL)
609
581
      return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
610
582
 
611
 
   radv_pipeline_layout_init(device, layout,
612
 
                             pCreateInfo->flags & VK_PIPELINE_LAYOUT_CREATE_INDEPENDENT_SETS_BIT_EXT);
 
583
   radv_pipeline_layout_init(device, layout, pCreateInfo->flags & VK_PIPELINE_LAYOUT_CREATE_INDEPENDENT_SETS_BIT_EXT);
613
584
 
614
585
   layout->num_sets = pCreateInfo->setLayoutCount;
615
586
 
641
612
}
642
613
 
643
614
VKAPI_ATTR void VKAPI_CALL
644
 
radv_DestroyPipelineLayout(VkDevice _device, VkPipelineLayout _pipelineLayout,
645
 
                           const VkAllocationCallbacks *pAllocator)
 
615
radv_DestroyPipelineLayout(VkDevice _device, VkPipelineLayout _pipelineLayout, const VkAllocationCallbacks *pAllocator)
646
616
{
647
617
   RADV_FROM_HANDLE(radv_device, device, _device);
648
618
   RADV_FROM_HANDLE(radv_pipeline_layout, pipeline_layout, _pipelineLayout);
666
636
   struct radv_descriptor_set *set;
667
637
   uint32_t buffer_count = layout->buffer_count;
668
638
   if (variable_count) {
669
 
      unsigned stride =
670
 
         radv_descriptor_type_buffer_count(layout->binding[layout->binding_count - 1].type);
671
 
      buffer_count =
672
 
         layout->binding[layout->binding_count - 1].buffer_offset + *variable_count * stride;
 
639
      unsigned stride = radv_descriptor_type_buffer_count(layout->binding[layout->binding_count - 1].type);
 
640
      buffer_count = layout->binding[layout->binding_count - 1].buffer_offset + *variable_count * stride;
673
641
   }
674
 
   unsigned range_offset =
675
 
      sizeof(struct radv_descriptor_set_header) + sizeof(struct radeon_winsys_bo *) * buffer_count;
 
642
   unsigned range_offset = sizeof(struct radv_descriptor_set_header) + sizeof(struct radeon_winsys_bo *) * buffer_count;
676
643
   const unsigned dynamic_offset_count = layout->dynamic_offset_count;
677
 
   unsigned mem_size =
678
 
      range_offset + sizeof(struct radv_descriptor_range) * dynamic_offset_count;
 
644
   unsigned mem_size = range_offset + sizeof(struct radv_descriptor_range) * dynamic_offset_count;
679
645
 
680
646
   if (pool->host_memory_base) {
681
647
      if (pool->host_memory_end - pool->host_memory_ptr < mem_size)
695
661
   vk_object_base_init(&device->vk, &set->header.base, VK_OBJECT_TYPE_DESCRIPTOR_SET);
696
662
 
697
663
   if (dynamic_offset_count) {
698
 
      set->header.dynamic_descriptors =
699
 
         (struct radv_descriptor_range *)((uint8_t *)set + range_offset);
 
664
      set->header.dynamic_descriptors = (struct radv_descriptor_range *)((uint8_t *)set + range_offset);
700
665
   }
701
666
 
702
667
   set->header.layout = layout;
704
669
   uint32_t layout_size = layout->size;
705
670
   if (variable_count) {
706
671
      uint32_t stride = layout->binding[layout->binding_count - 1].size;
707
 
      if (layout->binding[layout->binding_count - 1].type ==
708
 
          VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK)
 
672
      if (layout->binding[layout->binding_count - 1].type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK)
709
673
         stride = 1;
710
674
 
711
675
      layout_size = layout->binding[layout->binding_count - 1].offset + *variable_count * stride;
747
711
      set->header.bo = pool->bo;
748
712
      set->header.mapped_ptr = (uint32_t *)(pool->mapped_ptr + offset);
749
713
      set->header.va = pool->bo ? (radv_buffer_get_va(set->header.bo) + offset) : 0;
750
 
      memmove(&pool->entries[index + 1], &pool->entries[index],
751
 
              sizeof(pool->entries[0]) * (pool->entry_count - index));
 
714
      memmove(&pool->entries[index + 1], &pool->entries[index], sizeof(pool->entries[0]) * (pool->entry_count - index));
752
715
      pool->entries[index].offset = offset;
753
716
      pool->entries[index].size = layout_size;
754
717
      pool->entries[index].set = set;
757
720
 
758
721
   if (layout->has_immutable_samplers) {
759
722
      for (unsigned i = 0; i < layout->binding_count; ++i) {
760
 
         if (!layout->binding[i].immutable_samplers_offset ||
761
 
             layout->binding[i].immutable_samplers_equal)
 
723
         if (!layout->binding[i].immutable_samplers_offset || layout->binding[i].immutable_samplers_equal)
762
724
            continue;
763
725
 
764
726
         unsigned offset = layout->binding[i].offset / 4;
791
753
   if (free_bo && !pool->host_memory_base) {
792
754
      for (int i = 0; i < pool->entry_count; ++i) {
793
755
         if (pool->entries[i].set == set) {
794
 
            memmove(&pool->entries[i], &pool->entries[i + 1],
795
 
                    sizeof(pool->entries[i]) * (pool->entry_count - i - 1));
 
756
            memmove(&pool->entries[i], &pool->entries[i + 1], sizeof(pool->entries[i]) * (pool->entry_count - i - 1));
796
757
            --pool->entry_count;
797
758
            break;
798
759
         }
830
791
}
831
792
 
832
793
VkResult
833
 
radv_create_descriptor_pool(struct radv_device *device,
834
 
                            const VkDescriptorPoolCreateInfo *pCreateInfo,
835
 
                            const VkAllocationCallbacks *pAllocator,
836
 
                            VkDescriptorPool *pDescriptorPool, bool is_internal)
 
794
radv_create_descriptor_pool(struct radv_device *device, const VkDescriptorPoolCreateInfo *pCreateInfo,
 
795
                            const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool,
 
796
                            bool is_internal)
837
797
{
838
798
   struct radv_descriptor_pool *pool;
839
799
   uint64_t size = sizeof(struct radv_descriptor_pool);
842
802
   const VkMutableDescriptorTypeCreateInfoEXT *mutable_info =
843
803
      vk_find_struct_const(pCreateInfo->pNext, MUTABLE_DESCRIPTOR_TYPE_CREATE_INFO_EXT);
844
804
 
845
 
   vk_foreach_struct_const(ext, pCreateInfo->pNext)
846
 
   {
 
805
   vk_foreach_struct_const (ext, pCreateInfo->pNext) {
847
806
      switch (ext->sType) {
848
807
      case VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_INLINE_UNIFORM_BLOCK_CREATE_INFO: {
849
808
         const VkDescriptorPoolInlineUniformBlockCreateInfo *info =
862
821
   uint64_t num_16byte_descriptors = 0;
863
822
   for (unsigned i = 0; i < pCreateInfo->poolSizeCount; ++i) {
864
823
      bo_count += radv_descriptor_type_buffer_count(pCreateInfo->pPoolSizes[i].type) *
865
 
         pCreateInfo->pPoolSizes[i].descriptorCount;
 
824
                  pCreateInfo->pPoolSizes[i].descriptorCount;
866
825
 
867
826
      switch (pCreateInfo->pPoolSizes[i].type) {
868
827
      case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
892
851
          * we must allocate enough for any supported mutable descriptor type, i.e. 64 bytes. */
893
852
         if (mutable_info && i < mutable_info->mutableDescriptorTypeListCount) {
894
853
            uint64_t mutable_size, mutable_alignment;
895
 
            if (radv_mutable_descriptor_type_size_alignment(
896
 
                   &mutable_info->pMutableDescriptorTypeLists[i], &mutable_size,
897
 
                   &mutable_alignment)) {
 
854
            if (radv_mutable_descriptor_type_size_alignment(&mutable_info->pMutableDescriptorTypeLists[i],
 
855
                                                            &mutable_size, &mutable_alignment)) {
898
856
               /* 32 as we may need to align for images */
899
857
               mutable_size = align(mutable_size, 32);
900
858
               bo_size += mutable_size * pCreateInfo->pPoolSizes[i].descriptorCount;
951
909
 
952
910
   if (bo_size) {
953
911
      if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_VALVE)) {
954
 
         enum radeon_bo_flag flags = RADEON_FLAG_NO_INTERPROCESS_SHARING | RADEON_FLAG_READ_ONLY |
955
 
                                     RADEON_FLAG_32BIT;
 
912
         enum radeon_bo_flag flags = RADEON_FLAG_NO_INTERPROCESS_SHARING | RADEON_FLAG_READ_ONLY | RADEON_FLAG_32BIT;
956
913
 
957
914
         if (device->instance->zero_vram)
958
915
            flags |= RADEON_FLAG_ZERO_VRAM;
959
916
 
960
 
         VkResult result = device->ws->buffer_create(
961
 
            device->ws, bo_size, 32, RADEON_DOMAIN_VRAM, flags, RADV_BO_PRIORITY_DESCRIPTOR, 0,
962
 
            &pool->bo);
 
917
         VkResult result = device->ws->buffer_create(device->ws, bo_size, 32, RADEON_DOMAIN_VRAM, flags,
 
918
                                                     RADV_BO_PRIORITY_DESCRIPTOR, 0, &pool->bo);
963
919
         if (result != VK_SUCCESS) {
964
920
            radv_destroy_descriptor_pool(device, pAllocator, pool);
965
921
            return vk_error(device, result);
970
926
            return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY);
971
927
         }
972
928
      } else {
973
 
         pool->host_bo =
974
 
            vk_alloc2(&device->vk.alloc, pAllocator, bo_size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 
929
         pool->host_bo = vk_alloc2(&device->vk.alloc, pAllocator, bo_size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
975
930
         if (!pool->host_bo) {
976
931
            radv_destroy_descriptor_pool(device, pAllocator, pool);
977
932
            return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
989
944
 
990
945
VKAPI_ATTR VkResult VKAPI_CALL
991
946
radv_CreateDescriptorPool(VkDevice _device, const VkDescriptorPoolCreateInfo *pCreateInfo,
992
 
                          const VkAllocationCallbacks *pAllocator,
993
 
                          VkDescriptorPool *pDescriptorPool)
 
947
                          const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool)
994
948
{
995
949
   RADV_FROM_HANDLE(radv_device, device, _device);
996
950
   return radv_create_descriptor_pool(device, pCreateInfo, pAllocator, pDescriptorPool, false);
997
951
}
998
952
 
999
953
VKAPI_ATTR void VKAPI_CALL
1000
 
radv_DestroyDescriptorPool(VkDevice _device, VkDescriptorPool _pool,
1001
 
                           const VkAllocationCallbacks *pAllocator)
 
954
radv_DestroyDescriptorPool(VkDevice _device, VkDescriptorPool _pool, const VkAllocationCallbacks *pAllocator)
1002
955
{
1003
956
   RADV_FROM_HANDLE(radv_device, device, _device);
1004
957
   RADV_FROM_HANDLE(radv_descriptor_pool, pool, _pool);
1010
963
}
1011
964
 
1012
965
VKAPI_ATTR VkResult VKAPI_CALL
1013
 
radv_ResetDescriptorPool(VkDevice _device, VkDescriptorPool descriptorPool,
1014
 
                         VkDescriptorPoolResetFlags flags)
 
966
radv_ResetDescriptorPool(VkDevice _device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
1015
967
{
1016
968
   RADV_FROM_HANDLE(radv_device, device, _device);
1017
969
   RADV_FROM_HANDLE(radv_descriptor_pool, pool, descriptorPool);
1045
997
   uint32_t i;
1046
998
   struct radv_descriptor_set *set = NULL;
1047
999
 
1048
 
   const VkDescriptorSetVariableDescriptorCountAllocateInfo *variable_counts = vk_find_struct_const(
1049
 
      pAllocateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO);
 
1000
   const VkDescriptorSetVariableDescriptorCountAllocateInfo *variable_counts =
 
1001
      vk_find_struct_const(pAllocateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO);
1050
1002
   const uint32_t zero = 0;
1051
1003
 
1052
1004
   /* allocate a set of buffers for each shader to contain descriptors */
1096
1048
}
1097
1049
 
1098
1050
static ALWAYS_INLINE void
1099
 
write_texel_buffer_descriptor(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
1100
 
                              unsigned *dst, struct radeon_winsys_bo **buffer_list,
1101
 
                              const VkBufferView _buffer_view)
 
1051
write_texel_buffer_descriptor(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer, unsigned *dst,
 
1052
                              struct radeon_winsys_bo **buffer_list, const VkBufferView _buffer_view)
1102
1053
{
1103
1054
   RADV_FROM_HANDLE(radv_buffer_view, buffer_view, _buffer_view);
1104
1055
 
1128
1079
      return;
1129
1080
   }
1130
1081
 
1131
 
   uint32_t rsrc_word3 =
1132
 
      S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) | S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
1133
 
      S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) | S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W);
 
1082
   uint32_t rsrc_word3 = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) | S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
 
1083
                         S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) | S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W);
1134
1084
 
1135
1085
   if (device->physical_device->rad_info.gfx_level >= GFX11) {
1136
 
      rsrc_word3 |= S_008F0C_FORMAT(V_008F0C_GFX11_FORMAT_32_FLOAT) |
1137
 
                    S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW);
 
1086
      rsrc_word3 |= S_008F0C_FORMAT(V_008F0C_GFX11_FORMAT_32_FLOAT) | S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW);
1138
1087
   } else if (device->physical_device->rad_info.gfx_level >= GFX10) {
1139
 
      rsrc_word3 |= S_008F0C_FORMAT(V_008F0C_GFX10_FORMAT_32_FLOAT) |
1140
 
                    S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW) | S_008F0C_RESOURCE_LEVEL(1);
 
1088
      rsrc_word3 |= S_008F0C_FORMAT(V_008F0C_GFX10_FORMAT_32_FLOAT) | S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW) |
 
1089
                    S_008F0C_RESOURCE_LEVEL(1);
1141
1090
   } else {
1142
 
      rsrc_word3 |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
1143
 
                    S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32);
 
1091
      rsrc_word3 |=
 
1092
         S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) | S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32);
1144
1093
   }
1145
1094
 
1146
1095
   dst[0] = va;
1150
1099
}
1151
1100
 
1152
1101
static ALWAYS_INLINE void
1153
 
write_buffer_descriptor_impl(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
1154
 
                             unsigned *dst, struct radeon_winsys_bo **buffer_list,
1155
 
                             const VkDescriptorBufferInfo *buffer_info)
 
1102
write_buffer_descriptor_impl(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer, unsigned *dst,
 
1103
                             struct radeon_winsys_bo **buffer_list, const VkDescriptorBufferInfo *buffer_info)
1156
1104
{
1157
1105
   RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
1158
1106
   uint64_t va = 0, range = 0;
1199
1147
 
1200
1148
static ALWAYS_INLINE void
1201
1149
write_dynamic_buffer_descriptor(struct radv_device *device, struct radv_descriptor_range *range,
1202
 
                                struct radeon_winsys_bo **buffer_list,
1203
 
                                const VkDescriptorBufferInfo *buffer_info)
 
1150
                                struct radeon_winsys_bo **buffer_list, const VkDescriptorBufferInfo *buffer_info)
1204
1151
{
1205
1152
   RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
1206
1153
   uint64_t va;
1256
1203
}
1257
1204
 
1258
1205
static ALWAYS_INLINE void
1259
 
write_image_descriptor_impl(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
1260
 
                            unsigned size, unsigned *dst, struct radeon_winsys_bo **buffer_list,
1261
 
                            VkDescriptorType descriptor_type, const VkDescriptorImageInfo *image_info)
 
1206
write_image_descriptor_impl(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer, unsigned size,
 
1207
                            unsigned *dst, struct radeon_winsys_bo **buffer_list, VkDescriptorType descriptor_type,
 
1208
                            const VkDescriptorImageInfo *image_info)
1262
1209
{
1263
1210
   RADV_FROM_HANDLE(radv_image_view, iview, image_info->imageView);
1264
1211
 
1273
1220
      return;
1274
1221
   }
1275
1222
 
1276
 
   const uint32_t max_bindings = sizeof(iview->image->bindings) /
1277
 
                                 sizeof(iview->image->bindings[0]);
 
1223
   const uint32_t max_bindings = sizeof(iview->image->bindings) / sizeof(iview->image->bindings[0]);
1278
1224
   for (uint32_t b = 0; b < max_bindings; b++) {
1279
1225
      if (cmd_buffer) {
1280
1226
         if (iview->image->bindings[b].bo)
1287
1233
}
1288
1234
 
1289
1235
static ALWAYS_INLINE void
1290
 
write_combined_image_sampler_descriptor(struct radv_device *device,
1291
 
                                        struct radv_cmd_buffer *cmd_buffer, unsigned sampler_offset,
1292
 
                                        unsigned *dst, struct radeon_winsys_bo **buffer_list,
1293
 
                                        VkDescriptorType descriptor_type,
1294
 
                                        const VkDescriptorImageInfo *image_info, bool has_sampler)
 
1236
write_combined_image_sampler_descriptor(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
 
1237
                                        unsigned sampler_offset, unsigned *dst, struct radeon_winsys_bo **buffer_list,
 
1238
                                        VkDescriptorType descriptor_type, const VkDescriptorImageInfo *image_info,
 
1239
                                        bool has_sampler)
1295
1240
{
1296
 
   write_image_descriptor_impl(device, cmd_buffer, sampler_offset, dst, buffer_list, descriptor_type,
1297
 
                               image_info);
 
1241
   write_image_descriptor_impl(device, cmd_buffer, sampler_offset, dst, buffer_list, descriptor_type, image_info);
1298
1242
   /* copy over sampler state */
1299
1243
   if (has_sampler) {
1300
1244
      RADV_FROM_HANDLE(radv_sampler, sampler, image_info->sampler);
1324
1268
static ALWAYS_INLINE void
1325
1269
radv_update_descriptor_sets_impl(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
1326
1270
                                 VkDescriptorSet dstSetOverride, uint32_t descriptorWriteCount,
1327
 
                                 const VkWriteDescriptorSet *pDescriptorWrites,
1328
 
                                 uint32_t descriptorCopyCount,
 
1271
                                 const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
1329
1272
                                 const VkCopyDescriptorSet *pDescriptorCopies)
1330
1273
{
1331
1274
   uint32_t i, j;
1332
1275
   for (i = 0; i < descriptorWriteCount; i++) {
1333
1276
      const VkWriteDescriptorSet *writeset = &pDescriptorWrites[i];
1334
 
      RADV_FROM_HANDLE(radv_descriptor_set, set,
1335
 
                       dstSetOverride ? dstSetOverride : writeset->dstSet);
 
1277
      RADV_FROM_HANDLE(radv_descriptor_set, set, dstSetOverride ? dstSetOverride : writeset->dstSet);
1336
1278
      const struct radv_descriptor_set_binding_layout *binding_layout =
1337
1279
         set->header.layout->binding + writeset->dstBinding;
1338
1280
      uint32_t *ptr = set->header.mapped_ptr;
1341
1283
       * allocated, so if we are writing push descriptors we have to copy the
1342
1284
       * immutable samplers into them now.
1343
1285
       */
1344
 
      const bool copy_immutable_samplers = cmd_buffer &&
1345
 
                                           binding_layout->immutable_samplers_offset &&
1346
 
                                           !binding_layout->immutable_samplers_equal;
 
1286
      const bool copy_immutable_samplers =
 
1287
         cmd_buffer && binding_layout->immutable_samplers_offset && !binding_layout->immutable_samplers_equal;
1347
1288
      const uint32_t *samplers = radv_immutable_samplers(set->header.layout, binding_layout);
1348
1289
      const VkWriteDescriptorSetAccelerationStructureKHR *accel_structs = NULL;
1349
1290
 
1350
1291
      ptr += binding_layout->offset / 4;
1351
1292
 
1352
1293
      if (writeset->descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK) {
1353
 
         write_block_descriptor(device, cmd_buffer, (uint8_t *)ptr + writeset->dstArrayElement,
1354
 
                                writeset);
 
1294
         write_block_descriptor(device, cmd_buffer, (uint8_t *)ptr + writeset->dstArrayElement, writeset);
1355
1295
         continue;
1356
1296
      } else if (writeset->descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR) {
1357
 
         accel_structs =
1358
 
            vk_find_struct_const(writeset->pNext, WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR);
 
1297
         accel_structs = vk_find_struct_const(writeset->pNext, WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR);
1359
1298
      }
1360
1299
 
1361
1300
      ptr += binding_layout->size * writeset->dstArrayElement / 4;
1367
1306
         case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
1368
1307
            unsigned idx = writeset->dstArrayElement + j;
1369
1308
            idx += binding_layout->dynamic_offset_offset;
1370
 
            assert(!(set->header.layout->flags &
1371
 
                     VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
1372
 
            write_dynamic_buffer_descriptor(device, set->header.dynamic_descriptors + idx,
1373
 
                                            buffer_list, writeset->pBufferInfo + j);
 
1309
            assert(!(set->header.layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
 
1310
            write_dynamic_buffer_descriptor(device, set->header.dynamic_descriptors + idx, buffer_list,
 
1311
                                            writeset->pBufferInfo + j);
1374
1312
            break;
1375
1313
         }
1376
1314
         case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1377
1315
         case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1378
 
            write_buffer_descriptor_impl(device, cmd_buffer, ptr, buffer_list,
1379
 
                                         writeset->pBufferInfo + j);
 
1316
            write_buffer_descriptor_impl(device, cmd_buffer, ptr, buffer_list, writeset->pBufferInfo + j);
1380
1317
            break;
1381
1318
         case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1382
1319
         case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1383
 
            write_texel_buffer_descriptor(device, cmd_buffer, ptr, buffer_list,
1384
 
                                          writeset->pTexelBufferView[j]);
 
1320
            write_texel_buffer_descriptor(device, cmd_buffer, ptr, buffer_list, writeset->pTexelBufferView[j]);
1385
1321
            break;
1386
1322
         case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1387
 
            write_image_descriptor_impl(device, cmd_buffer, 32, ptr, buffer_list,
1388
 
                                        writeset->descriptorType, writeset->pImageInfo + j);
 
1323
            write_image_descriptor_impl(device, cmd_buffer, 32, ptr, buffer_list, writeset->descriptorType,
 
1324
                                        writeset->pImageInfo + j);
1389
1325
            break;
1390
1326
         case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1391
1327
         case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1392
 
            write_image_descriptor_impl(device, cmd_buffer, 64, ptr, buffer_list,
1393
 
                                        writeset->descriptorType, writeset->pImageInfo + j);
 
1328
            write_image_descriptor_impl(device, cmd_buffer, 64, ptr, buffer_list, writeset->descriptorType,
 
1329
                                        writeset->pImageInfo + j);
1394
1330
            break;
1395
1331
         case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
1396
1332
            unsigned sampler_offset = radv_combined_image_descriptor_sampler_offset(binding_layout);
1397
 
            write_combined_image_sampler_descriptor(
1398
 
               device, cmd_buffer, sampler_offset, ptr, buffer_list, writeset->descriptorType,
1399
 
               writeset->pImageInfo + j, !binding_layout->immutable_samplers_offset);
 
1333
            write_combined_image_sampler_descriptor(device, cmd_buffer, sampler_offset, ptr, buffer_list,
 
1334
                                                    writeset->descriptorType, writeset->pImageInfo + j,
 
1335
                                                    !binding_layout->immutable_samplers_offset);
1400
1336
            if (copy_immutable_samplers) {
1401
1337
               const unsigned idx = writeset->dstArrayElement + j;
1402
1338
               memcpy((char *)ptr + sampler_offset, samplers + 4 * idx, 16);
1413
1349
            }
1414
1350
            break;
1415
1351
         case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: {
1416
 
            RADV_FROM_HANDLE(vk_acceleration_structure, accel_struct,
1417
 
                             accel_structs->pAccelerationStructures[j]);
 
1352
            RADV_FROM_HANDLE(vk_acceleration_structure, accel_struct, accel_structs->pAccelerationStructures[j]);
1418
1353
 
1419
 
            write_accel_struct(device, ptr,
1420
 
                               accel_struct ? vk_acceleration_structure_get_va(accel_struct) : 0);
 
1354
            write_accel_struct(device, ptr, accel_struct ? vk_acceleration_structure_get_va(accel_struct) : 0);
1421
1355
            break;
1422
1356
         }
1423
1357
         default:
1503
1437
 
1504
1438
VKAPI_ATTR void VKAPI_CALL
1505
1439
radv_UpdateDescriptorSets(VkDevice _device, uint32_t descriptorWriteCount,
1506
 
                          const VkWriteDescriptorSet *pDescriptorWrites,
1507
 
                          uint32_t descriptorCopyCount,
 
1440
                          const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
1508
1441
                          const VkCopyDescriptorSet *pDescriptorCopies)
1509
1442
{
1510
1443
   RADV_FROM_HANDLE(radv_device, device, _device);
1511
1444
 
1512
 
   radv_update_descriptor_sets_impl(device, NULL, VK_NULL_HANDLE, descriptorWriteCount,
1513
 
                                    pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
 
1445
   radv_update_descriptor_sets_impl(device, NULL, VK_NULL_HANDLE, descriptorWriteCount, pDescriptorWrites,
 
1446
                                    descriptorCopyCount, pDescriptorCopies);
1514
1447
}
1515
1448
 
1516
1449
void
1517
1450
radv_cmd_update_descriptor_sets(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
1518
1451
                                VkDescriptorSet dstSetOverride, uint32_t descriptorWriteCount,
1519
 
                                const VkWriteDescriptorSet *pDescriptorWrites,
1520
 
                                uint32_t descriptorCopyCount,
 
1452
                                const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount,
1521
1453
                                const VkCopyDescriptorSet *pDescriptorCopies)
1522
1454
{
1523
1455
   /* Assume cmd_buffer != NULL to optimize out cmd_buffer checks in generic code above. */
1524
1456
   assume(cmd_buffer != NULL);
1525
 
   radv_update_descriptor_sets_impl(device, cmd_buffer, dstSetOverride, descriptorWriteCount,
1526
 
                                    pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
 
1457
   radv_update_descriptor_sets_impl(device, cmd_buffer, dstSetOverride, descriptorWriteCount, pDescriptorWrites,
 
1458
                                    descriptorCopyCount, pDescriptorCopies);
1527
1459
}
1528
1460
 
1529
1461
VKAPI_ATTR VkResult VKAPI_CALL
1530
 
radv_CreateDescriptorUpdateTemplate(VkDevice _device,
1531
 
                                    const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
 
1462
radv_CreateDescriptorUpdateTemplate(VkDevice _device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
1532
1463
                                    const VkAllocationCallbacks *pAllocator,
1533
1464
                                    VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate)
1534
1465
{
1565
1496
 
1566
1497
   for (i = 0; i < entry_count; i++) {
1567
1498
      const VkDescriptorUpdateTemplateEntry *entry = &pCreateInfo->pDescriptorUpdateEntries[i];
1568
 
      const struct radv_descriptor_set_binding_layout *binding_layout =
1569
 
         set_layout->binding + entry->dstBinding;
 
1499
      const struct radv_descriptor_set_binding_layout *binding_layout = set_layout->binding + entry->dstBinding;
1570
1500
      const uint32_t buffer_offset = binding_layout->buffer_offset + entry->dstArrayElement;
1571
1501
      const uint32_t *immutable_samplers = NULL;
1572
1502
      uint32_t dst_offset;
1586
1516
         case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1587
1517
         case VK_DESCRIPTOR_TYPE_SAMPLER:
1588
1518
            /* Immutable samplers are copied into push descriptors when they are pushed */
1589
 
            if (pCreateInfo->templateType ==
1590
 
                   VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR &&
1591
 
                binding_layout->immutable_samplers_offset &&
1592
 
                !binding_layout->immutable_samplers_equal) {
1593
 
               immutable_samplers =
1594
 
                  radv_immutable_samplers(set_layout, binding_layout) + entry->dstArrayElement * 4;
 
1519
            if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR &&
 
1520
                binding_layout->immutable_samplers_offset && !binding_layout->immutable_samplers_equal) {
 
1521
               immutable_samplers = radv_immutable_samplers(set_layout, binding_layout) + entry->dstArrayElement * 4;
1595
1522
            }
1596
1523
            break;
1597
1524
         default:
1625
1552
}
1626
1553
 
1627
1554
VKAPI_ATTR void VKAPI_CALL
1628
 
radv_DestroyDescriptorUpdateTemplate(VkDevice _device,
1629
 
                                     VkDescriptorUpdateTemplate descriptorUpdateTemplate,
 
1555
radv_DestroyDescriptorUpdateTemplate(VkDevice _device, VkDescriptorUpdateTemplate descriptorUpdateTemplate,
1630
1556
                                     const VkAllocationCallbacks *pAllocator)
1631
1557
{
1632
1558
   RADV_FROM_HANDLE(radv_device, device, _device);
1640
1566
}
1641
1567
 
1642
1568
static ALWAYS_INLINE void
1643
 
radv_update_descriptor_set_with_template_impl(struct radv_device *device,
1644
 
                                              struct radv_cmd_buffer *cmd_buffer,
 
1569
radv_update_descriptor_set_with_template_impl(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
1645
1570
                                              struct radv_descriptor_set *set,
1646
 
                                              VkDescriptorUpdateTemplate descriptorUpdateTemplate,
1647
 
                                              const void *pData)
 
1571
                                              VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void *pData)
1648
1572
{
1649
1573
   RADV_FROM_HANDLE(radv_descriptor_update_template, templ, descriptorUpdateTemplate);
1650
1574
   uint32_t i;
1665
1589
         case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1666
1590
         case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
1667
1591
            const unsigned idx = templ->entry[i].dst_offset + j;
1668
 
            assert(!(set->header.layout->flags &
1669
 
                     VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
1670
 
            write_dynamic_buffer_descriptor(device, set->header.dynamic_descriptors + idx,
1671
 
                                            buffer_list, (struct VkDescriptorBufferInfo *)pSrc);
 
1592
            assert(!(set->header.layout->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR));
 
1593
            write_dynamic_buffer_descriptor(device, set->header.dynamic_descriptors + idx, buffer_list,
 
1594
                                            (struct VkDescriptorBufferInfo *)pSrc);
1672
1595
            break;
1673
1596
         }
1674
1597
         case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1675
1598
         case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1676
 
            write_buffer_descriptor_impl(device, cmd_buffer, pDst, buffer_list,
1677
 
                                         (struct VkDescriptorBufferInfo *)pSrc);
 
1599
            write_buffer_descriptor_impl(device, cmd_buffer, pDst, buffer_list, (struct VkDescriptorBufferInfo *)pSrc);
1678
1600
            break;
1679
1601
         case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1680
1602
         case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1681
 
            write_texel_buffer_descriptor(device, cmd_buffer, pDst, buffer_list,
1682
 
                                          *(VkBufferView *)pSrc);
 
1603
            write_texel_buffer_descriptor(device, cmd_buffer, pDst, buffer_list, *(VkBufferView *)pSrc);
1683
1604
            break;
1684
1605
         case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1685
 
            write_image_descriptor_impl(device, cmd_buffer, 32, pDst, buffer_list,
1686
 
                                        templ->entry[i].descriptor_type,
 
1606
            write_image_descriptor_impl(device, cmd_buffer, 32, pDst, buffer_list, templ->entry[i].descriptor_type,
1687
1607
                                        (struct VkDescriptorImageInfo *)pSrc);
1688
1608
            break;
1689
1609
         case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1690
1610
         case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1691
 
            write_image_descriptor_impl(device, cmd_buffer, 64, pDst, buffer_list,
1692
 
                                        templ->entry[i].descriptor_type,
 
1611
            write_image_descriptor_impl(device, cmd_buffer, 64, pDst, buffer_list, templ->entry[i].descriptor_type,
1693
1612
                                        (struct VkDescriptorImageInfo *)pSrc);
1694
1613
            break;
1695
1614
         case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1696
 
            write_combined_image_sampler_descriptor(
1697
 
               device, cmd_buffer, templ->entry[i].sampler_offset, pDst, buffer_list,
1698
 
               templ->entry[i].descriptor_type, (struct VkDescriptorImageInfo *)pSrc,
1699
 
               templ->entry[i].has_sampler);
 
1615
            write_combined_image_sampler_descriptor(device, cmd_buffer, templ->entry[i].sampler_offset, pDst,
 
1616
                                                    buffer_list, templ->entry[i].descriptor_type,
 
1617
                                                    (struct VkDescriptorImageInfo *)pSrc, templ->entry[i].has_sampler);
1700
1618
            if (cmd_buffer && templ->entry[i].immutable_samplers) {
1701
 
               memcpy((char *)pDst + templ->entry[i].sampler_offset,
1702
 
                      templ->entry[i].immutable_samplers + 4 * j, 16);
 
1619
               memcpy((char *)pDst + templ->entry[i].sampler_offset, templ->entry[i].immutable_samplers + 4 * j, 16);
1703
1620
            }
1704
1621
            break;
1705
1622
         case VK_DESCRIPTOR_TYPE_SAMPLER:
1706
1623
            if (templ->entry[i].has_sampler) {
1707
1624
               const VkDescriptorImageInfo *pImageInfo = (struct VkDescriptorImageInfo *)pSrc;
1708
1625
               write_sampler_descriptor(pDst, pImageInfo->sampler);
1709
 
            }
1710
 
            else if (cmd_buffer && templ->entry[i].immutable_samplers)
 
1626
            } else if (cmd_buffer && templ->entry[i].immutable_samplers)
1711
1627
               memcpy(pDst, templ->entry[i].immutable_samplers + 4 * j, 16);
1712
1628
            break;
1713
1629
         case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: {
1714
 
            RADV_FROM_HANDLE(vk_acceleration_structure, accel_struct,
1715
 
                             *(const VkAccelerationStructureKHR *)pSrc);
1716
 
            write_accel_struct(device, pDst,
1717
 
                               accel_struct ? vk_acceleration_structure_get_va(accel_struct) : 0);
 
1630
            RADV_FROM_HANDLE(vk_acceleration_structure, accel_struct, *(const VkAccelerationStructureKHR *)pSrc);
 
1631
            write_accel_struct(device, pDst, accel_struct ? vk_acceleration_structure_get_va(accel_struct) : 0);
1718
1632
            break;
1719
1633
         }
1720
1634
         default:
1728
1642
}
1729
1643
 
1730
1644
void
1731
 
radv_cmd_update_descriptor_set_with_template(struct radv_device *device,
1732
 
                                             struct radv_cmd_buffer *cmd_buffer,
 
1645
radv_cmd_update_descriptor_set_with_template(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
1733
1646
                                             struct radv_descriptor_set *set,
1734
 
                                             VkDescriptorUpdateTemplate descriptorUpdateTemplate,
1735
 
                                             const void *pData)
 
1647
                                             VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void *pData)
1736
1648
{
1737
1649
   /* Assume cmd_buffer != NULL to optimize out cmd_buffer checks in generic code above. */
1738
1650
   assume(cmd_buffer != NULL);
1741
1653
 
1742
1654
VKAPI_ATTR void VKAPI_CALL
1743
1655
radv_UpdateDescriptorSetWithTemplate(VkDevice _device, VkDescriptorSet descriptorSet,
1744
 
                                     VkDescriptorUpdateTemplate descriptorUpdateTemplate,
1745
 
                                     const void *pData)
 
1656
                                     VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void *pData)
1746
1657
{
1747
1658
   RADV_FROM_HANDLE(radv_device, device, _device);
1748
1659
   RADV_FROM_HANDLE(radv_descriptor_set, set, descriptorSet);
1751
1662
}
1752
1663
 
1753
1664
VKAPI_ATTR void VKAPI_CALL
1754
 
radv_GetDescriptorSetLayoutHostMappingInfoVALVE(
1755
 
   VkDevice _device, const VkDescriptorSetBindingReferenceVALVE *pBindingReference,
1756
 
   VkDescriptorSetLayoutHostMappingInfoVALVE *pHostMapping)
 
1665
radv_GetDescriptorSetLayoutHostMappingInfoVALVE(VkDevice _device,
 
1666
                                                const VkDescriptorSetBindingReferenceVALVE *pBindingReference,
 
1667
                                                VkDescriptorSetLayoutHostMappingInfoVALVE *pHostMapping)
1757
1668
{
1758
1669
   struct radv_descriptor_set_layout *set_layout =
1759
1670
      radv_descriptor_set_layout_from_handle(pBindingReference->descriptorSetLayout);
1760
1671
 
1761
 
   const struct radv_descriptor_set_binding_layout *binding_layout =
1762
 
      set_layout->binding + pBindingReference->binding;
 
1672
   const struct radv_descriptor_set_binding_layout *binding_layout = set_layout->binding + pBindingReference->binding;
1763
1673
 
1764
1674
   pHostMapping->descriptorOffset = binding_layout->offset;
1765
1675
   pHostMapping->descriptorSize = binding_layout->size;
1766
1676
}
1767
1677
 
1768
1678
VKAPI_ATTR void VKAPI_CALL
1769
 
radv_GetDescriptorSetHostMappingVALVE(VkDevice _device, VkDescriptorSet descriptorSet,
1770
 
                                      void **ppData)
 
1679
radv_GetDescriptorSetHostMappingVALVE(VkDevice _device, VkDescriptorSet descriptorSet, void **ppData)
1771
1680
{
1772
1681
   RADV_FROM_HANDLE(radv_descriptor_set, set, descriptorSet);
1773
1682
   *ppData = set->header.mapped_ptr;
1775
1684
 
1776
1685
/* VK_EXT_descriptor_buffer */
1777
1686
VKAPI_ATTR void VKAPI_CALL
1778
 
radv_GetDescriptorSetLayoutSizeEXT(VkDevice device, VkDescriptorSetLayout layout,
1779
 
                                   VkDeviceSize *pLayoutSizeInBytes)
 
1687
radv_GetDescriptorSetLayoutSizeEXT(VkDevice device, VkDescriptorSetLayout layout, VkDeviceSize *pLayoutSizeInBytes)
1780
1688
{
1781
1689
   RADV_FROM_HANDLE(radv_descriptor_set_layout, set_layout, layout);
1782
1690
   *pLayoutSizeInBytes = set_layout->size;
1783
1691
}
1784
1692
 
1785
1693
VKAPI_ATTR void VKAPI_CALL
1786
 
radv_GetDescriptorSetLayoutBindingOffsetEXT(VkDevice device, VkDescriptorSetLayout layout,
1787
 
                                            uint32_t binding, VkDeviceSize *pOffset)
 
1694
radv_GetDescriptorSetLayoutBindingOffsetEXT(VkDevice device, VkDescriptorSetLayout layout, uint32_t binding,
 
1695
                                            VkDeviceSize *pOffset)
1788
1696
{
1789
1697
   RADV_FROM_HANDLE(radv_descriptor_set_layout, set_layout, layout);
1790
1698
   *pOffset = set_layout->binding[binding].offset;
1791
1699
}
1792
1700
 
1793
1701
VKAPI_ATTR void VKAPI_CALL
1794
 
radv_GetDescriptorEXT(VkDevice _device, const VkDescriptorGetInfoEXT *pDescriptorInfo,
1795
 
                      size_t dataSize, void *pDescriptor)
 
1702
radv_GetDescriptorEXT(VkDevice _device, const VkDescriptorGetInfoEXT *pDescriptorInfo, size_t dataSize,
 
1703
                      void *pDescriptor)
1796
1704
{
1797
1705
   RADV_FROM_HANDLE(radv_device, device, _device);
1798
1706
 
1801
1709
      write_sampler_descriptor(pDescriptor, *pDescriptorInfo->data.pSampler);
1802
1710
      break;
1803
1711
   case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1804
 
      write_image_descriptor(pDescriptor, 64, pDescriptorInfo->type,
1805
 
                             pDescriptorInfo->data.pCombinedImageSampler);
 
1712
      write_image_descriptor(pDescriptor, 64, pDescriptorInfo->type, pDescriptorInfo->data.pCombinedImageSampler);
1806
1713
      if (pDescriptorInfo->data.pCombinedImageSampler) {
1807
 
         write_sampler_descriptor((uint32_t *)pDescriptor + 20,
1808
 
                                  pDescriptorInfo->data.pCombinedImageSampler->sampler);
 
1714
         write_sampler_descriptor((uint32_t *)pDescriptor + 20, pDescriptorInfo->data.pCombinedImageSampler->sampler);
1809
1715
      }
1810
1716
      break;
1811
1717
   case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1812
 
      write_image_descriptor(pDescriptor, 64, pDescriptorInfo->type,
1813
 
                             pDescriptorInfo->data.pInputAttachmentImage);
 
1718
      write_image_descriptor(pDescriptor, 64, pDescriptorInfo->type, pDescriptorInfo->data.pInputAttachmentImage);
1814
1719
      break;
1815
1720
   case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1816
 
      write_image_descriptor(pDescriptor, 64, pDescriptorInfo->type,
1817
 
                             pDescriptorInfo->data.pSampledImage);
 
1721
      write_image_descriptor(pDescriptor, 64, pDescriptorInfo->type, pDescriptorInfo->data.pSampledImage);
1818
1722
      break;
1819
1723
   case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1820
 
      write_image_descriptor(pDescriptor, 32, pDescriptorInfo->type,
1821
 
                             pDescriptorInfo->data.pStorageImage);
 
1724
      write_image_descriptor(pDescriptor, 32, pDescriptorInfo->type, pDescriptorInfo->data.pStorageImage);
1822
1725
      break;
1823
1726
   case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: {
1824
1727
      const VkDescriptorAddressInfoEXT *addr_info = pDescriptorInfo->data.pUniformBuffer;
1838
1741
      const VkDescriptorAddressInfoEXT *addr_info = pDescriptorInfo->data.pUniformTexelBuffer;
1839
1742
 
1840
1743
      if (addr_info && addr_info->address) {
1841
 
         radv_make_texel_buffer_descriptor(device, addr_info->address, addr_info->format, 0,
1842
 
                                           addr_info->range, pDescriptor);
 
1744
         radv_make_texel_buffer_descriptor(device, addr_info->address, addr_info->format, 0, addr_info->range,
 
1745
                                           pDescriptor);
1843
1746
      } else {
1844
1747
         memset(pDescriptor, 0, 4 * 4);
1845
1748
      }
1849
1752
      const VkDescriptorAddressInfoEXT *addr_info = pDescriptorInfo->data.pStorageTexelBuffer;
1850
1753
 
1851
1754
      if (addr_info && addr_info->address) {
1852
 
         radv_make_texel_buffer_descriptor(device, addr_info->address, addr_info->format, 0,
1853
 
                                           addr_info->range, pDescriptor);
 
1755
         radv_make_texel_buffer_descriptor(device, addr_info->address, addr_info->format, 0, addr_info->range,
 
1756
                                           pDescriptor);
1854
1757
      } else {
1855
1758
         memset(pDescriptor, 0, 4 * 4);
1856
1759
      }