~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/virtio/vulkan/vn_device.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:
11
11
#include "vn_device.h"
12
12
 
13
13
#include "util/disk_cache.h"
 
14
#include "util/hex.h"
14
15
#include "venus-protocol/vn_protocol_driver_device.h"
15
16
 
16
17
#include "vn_android.h"
31
32
   if (queue->sync_fence != VK_NULL_HANDLE) {
32
33
      vn_DestroyFence(dev_handle, queue->sync_fence, NULL);
33
34
   }
 
35
   if (queue->sparse_semaphore != VK_NULL_HANDLE) {
 
36
      vn_DestroySemaphore(dev_handle, queue->sparse_semaphore, NULL);
 
37
   }
34
38
   vn_object_base_fini(&queue->base);
35
39
}
36
40
 
163
167
   vk_free(&dev->base.base.alloc, dev->queue_families);
164
168
}
165
169
 
 
170
static VkResult
 
171
vn_device_memory_report_init(struct vn_device *dev,
 
172
                             const VkDeviceCreateInfo *create_info)
 
173
{
 
174
   const struct vk_features *app_feats = &dev->base.base.enabled_features;
 
175
   if (!app_feats->deviceMemoryReport)
 
176
      return VK_SUCCESS;
 
177
 
 
178
   uint32_t count = 0;
 
179
   vk_foreach_struct_const(pnext, create_info->pNext) {
 
180
      if (pnext->sType ==
 
181
          VK_STRUCTURE_TYPE_DEVICE_DEVICE_MEMORY_REPORT_CREATE_INFO_EXT)
 
182
         count++;
 
183
   }
 
184
 
 
185
   struct vn_device_memory_report *mem_reports = NULL;
 
186
   if (count) {
 
187
      mem_reports =
 
188
         vk_alloc(&dev->base.base.alloc, sizeof(*mem_reports) * count,
 
189
                  VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
 
190
      if (!mem_reports)
 
191
         return VK_ERROR_OUT_OF_HOST_MEMORY;
 
192
   }
 
193
 
 
194
   count = 0;
 
195
   vk_foreach_struct_const(pnext, create_info->pNext) {
 
196
      if (pnext->sType ==
 
197
          VK_STRUCTURE_TYPE_DEVICE_DEVICE_MEMORY_REPORT_CREATE_INFO_EXT) {
 
198
         const struct VkDeviceDeviceMemoryReportCreateInfoEXT *report =
 
199
            (void *)pnext;
 
200
         mem_reports[count].callback = report->pfnUserCallback;
 
201
         mem_reports[count].data = report->pUserData;
 
202
         count++;
 
203
      }
 
204
   }
 
205
 
 
206
   dev->memory_report_count = count;
 
207
   dev->memory_reports = mem_reports;
 
208
 
 
209
   return VK_SUCCESS;
 
210
}
 
211
 
 
212
static inline void
 
213
vn_device_memory_report_fini(struct vn_device *dev)
 
214
{
 
215
   vk_free(&dev->base.base.alloc, dev->memory_reports);
 
216
}
 
217
 
166
218
static bool
167
219
find_extension_names(const char *const *exts,
168
220
                     uint32_t ext_count,
290
342
      extra_exts[extra_count++] = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME;
291
343
   }
292
344
 
 
345
   if (app_exts->EXT_device_memory_report) {
 
346
      /* see vn_physical_device_get_native_extensions */
 
347
      block_exts[block_count++] = VK_EXT_DEVICE_MEMORY_REPORT_EXTENSION_NAME;
 
348
   }
 
349
 
293
350
   if (app_exts->EXT_physical_device_drm) {
294
351
      /* see vn_physical_device_get_native_extensions */
295
352
      block_exts[block_count++] = VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME;
363
420
#if !defined(ANDROID) && defined(ENABLE_SHADER_CACHE)
364
421
   const VkPhysicalDeviceProperties *vulkan_1_0_props =
365
422
      &dev->physical_device->properties.vulkan_1_0;
366
 
   struct mesa_sha1 sha1_ctx;
367
 
   uint8_t sha1[SHA1_DIGEST_LENGTH];
368
 
 
369
 
   _mesa_sha1_init(&sha1_ctx);
370
 
   _mesa_sha1_update(&sha1_ctx, vulkan_1_0_props->pipelineCacheUUID,
371
 
                     sizeof(vulkan_1_0_props->pipelineCacheUUID));
372
 
   _mesa_sha1_update(&sha1_ctx, &vulkan_1_0_props->vendorID,
373
 
                     sizeof(vulkan_1_0_props->vendorID));
374
 
   _mesa_sha1_update(&sha1_ctx, &vulkan_1_0_props->deviceID,
375
 
                     sizeof(vulkan_1_0_props->deviceID));
376
 
   _mesa_sha1_final(&sha1_ctx, sha1);
377
 
 
378
 
   char uuid[VK_UUID_SIZE];
379
 
   _mesa_sha1_format(uuid, sha1);
 
423
 
 
424
   char uuid[VK_UUID_SIZE * 2 + 1];
 
425
   mesa_bytes_to_hex(uuid, vulkan_1_0_props->pipelineCacheUUID, VK_UUID_SIZE);
380
426
 
381
427
   struct disk_cache *cache = disk_cache_create("venus", uuid, 0);
382
428
   if (!cache)
427
473
   if (result != VK_SUCCESS)
428
474
      return result;
429
475
 
 
476
   result = vn_device_memory_report_init(dev, create_info);
 
477
   if (result != VK_SUCCESS)
 
478
      goto out_destroy_device;
 
479
 
430
480
   if (!vn_device_queue_family_init(dev, create_info)) {
431
481
      result = VK_ERROR_OUT_OF_HOST_MEMORY;
432
 
      goto out_destroy_device;
 
482
      goto out_memory_report_fini;
433
483
   }
434
484
 
435
485
   for (uint32_t i = 0; i < ARRAY_SIZE(dev->memory_pools); i++) {
437
487
      mtx_init(&pool->mutex, mtx_plain);
438
488
   }
439
489
 
440
 
   result = vn_buffer_cache_init(dev);
 
490
   result = vn_device_feedback_pool_init(dev);
441
491
   if (result != VK_SUCCESS)
442
492
      goto out_memory_pool_fini;
443
493
 
444
 
   result = vn_device_feedback_pool_init(dev);
445
 
   if (result != VK_SUCCESS)
446
 
      goto out_buffer_cache_fini;
447
 
 
448
494
   result = vn_feedback_cmd_pools_init(dev);
449
495
   if (result != VK_SUCCESS)
450
496
      goto out_feedback_pool_fini;
453
499
   if (result != VK_SUCCESS)
454
500
      goto out_cmd_pools_fini;
455
501
 
 
502
   vn_buffer_cache_init(dev);
 
503
 
456
504
   /* This is a WA to allow fossilize replay to detect if the host side shader
457
505
    * cache is no longer up to date.
458
506
    */
466
514
out_feedback_pool_fini:
467
515
   vn_device_feedback_pool_fini(dev);
468
516
 
469
 
out_buffer_cache_fini:
470
 
   vn_buffer_cache_fini(dev);
471
 
 
472
517
out_memory_pool_fini:
473
518
   for (uint32_t i = 0; i < ARRAY_SIZE(dev->memory_pools); i++)
474
519
      vn_device_memory_pool_fini(dev, i);
475
520
 
476
521
   vn_device_queue_family_fini(dev);
477
522
 
 
523
out_memory_report_fini:
 
524
   vn_device_memory_report_fini(dev);
 
525
 
478
526
out_destroy_device:
479
527
   vn_call_vkDestroyDevice(instance, dev_handle, NULL);
480
528
 
541
589
   if (!dev)
542
590
      return;
543
591
 
 
592
   vn_buffer_cache_fini(dev);
 
593
 
544
594
   for (uint32_t i = 0; i < dev->queue_count; i++)
545
595
      vn_queue_fini(&dev->queues[i]);
546
596
 
548
598
 
549
599
   vn_device_feedback_pool_fini(dev);
550
600
 
551
 
   vn_buffer_cache_fini(dev);
552
 
 
553
601
   for (uint32_t i = 0; i < ARRAY_SIZE(dev->memory_pools); i++)
554
602
      vn_device_memory_pool_fini(dev, i);
555
603
 
556
604
   vn_device_queue_family_fini(dev);
557
605
 
 
606
   vn_device_memory_report_fini(dev);
 
607
 
558
608
   /* We must emit vkDestroyDevice before freeing dev->queues.  Otherwise,
559
609
    * another thread might reuse their object ids while they still refer to
560
610
    * the queues in the renderer.