xref: /aosp_15_r20/external/virglrenderer/src/venus/vkr_physical_device.c (revision bbecb9d118dfdb95f99bd754f8fa9be01f189df3)
1 /*
2  * Copyright 2020 Google LLC
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "vkr_physical_device.h"
7 
8 #include "venus-protocol/vn_protocol_renderer_device.h"
9 #include "vrend_winsys_gbm.h"
10 
11 #include "vkr_context.h"
12 #include "vkr_device.h"
13 #include "vkr_instance.h"
14 
15 /* TODO open render node and create gbm_device per vkr_physical_device */
16 static struct gbm_device *vkr_gbm_dev;
17 
18 static void
vkr_gbm_device_init_once(void)19 vkr_gbm_device_init_once(void)
20 {
21    struct virgl_gbm *vkr_gbm = virgl_gbm_init(-1);
22    if (!vkr_gbm) {
23       vkr_log("virgl_gbm_init failed");
24       exit(-1);
25    }
26 
27    vkr_gbm_dev = vkr_gbm->device;
28 }
29 
30 static struct gbm_device *
vkr_physical_device_get_gbm_device(UNUSED struct vkr_physical_device * physical_dev)31 vkr_physical_device_get_gbm_device(UNUSED struct vkr_physical_device *physical_dev)
32 {
33    static once_flag gbm_once_flag = ONCE_FLAG_INIT;
34    call_once(&gbm_once_flag, vkr_gbm_device_init_once);
35 
36    return vkr_gbm_dev;
37 }
38 
39 void
vkr_physical_device_destroy(struct vkr_context * ctx,struct vkr_physical_device * physical_dev)40 vkr_physical_device_destroy(struct vkr_context *ctx,
41                             struct vkr_physical_device *physical_dev)
42 {
43    struct vkr_device *dev, *tmp;
44    LIST_FOR_EACH_ENTRY_SAFE (dev, tmp, &physical_dev->devices, base.track_head)
45       vkr_device_destroy(ctx, dev);
46 
47    free(physical_dev->extensions);
48 
49    vkr_context_remove_object(ctx, &physical_dev->base);
50 }
51 
52 static VkResult
vkr_instance_enumerate_physical_devices(struct vkr_instance * instance)53 vkr_instance_enumerate_physical_devices(struct vkr_instance *instance)
54 {
55    if (instance->physical_device_count)
56       return VK_SUCCESS;
57 
58    uint32_t count;
59    VkResult result =
60       vkEnumeratePhysicalDevices(instance->base.handle.instance, &count, NULL);
61    if (result != VK_SUCCESS)
62       return result;
63 
64    VkPhysicalDevice *handles = calloc(count, sizeof(*handles));
65    struct vkr_physical_device **physical_devs = calloc(count, sizeof(*physical_devs));
66    if (!handles || !physical_devs) {
67       free(physical_devs);
68       free(handles);
69       return VK_ERROR_OUT_OF_HOST_MEMORY;
70    }
71 
72    result = vkEnumeratePhysicalDevices(instance->base.handle.instance, &count, handles);
73    if (result != VK_SUCCESS) {
74       free(physical_devs);
75       free(handles);
76       return result;
77    }
78 
79    instance->physical_device_count = count;
80    instance->physical_device_handles = handles;
81    instance->physical_devices = physical_devs;
82 
83    return VK_SUCCESS;
84 }
85 
86 static struct vkr_physical_device *
vkr_instance_lookup_physical_device(struct vkr_instance * instance,VkPhysicalDevice handle)87 vkr_instance_lookup_physical_device(struct vkr_instance *instance,
88                                     VkPhysicalDevice handle)
89 {
90    for (uint32_t i = 0; i < instance->physical_device_count; i++) {
91       /* XXX this assumes VkPhysicalDevice handles are unique */
92       if (instance->physical_device_handles[i] == handle)
93          return instance->physical_devices[i];
94    }
95    return NULL;
96 }
97 
98 static void
vkr_physical_device_init_id_properties(struct vkr_physical_device * physical_dev)99 vkr_physical_device_init_id_properties(struct vkr_physical_device *physical_dev)
100 {
101    VkPhysicalDevice handle = physical_dev->base.handle.physical_device;
102    physical_dev->id_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES;
103    VkPhysicalDeviceProperties2 props2 = {
104       .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
105       .pNext = &physical_dev->id_properties
106    };
107    vkGetPhysicalDeviceProperties2(handle, &props2);
108 }
109 
110 static void
vkr_physical_device_init_memory_properties(struct vkr_physical_device * physical_dev)111 vkr_physical_device_init_memory_properties(struct vkr_physical_device *physical_dev)
112 {
113    VkPhysicalDevice handle = physical_dev->base.handle.physical_device;
114    vkGetPhysicalDeviceMemoryProperties(handle, &physical_dev->memory_properties);
115 
116    /* XXX When a VkMemoryType has VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, we
117     * assume any VkDeviceMemory with the memory type can be made external and
118     * be exportable.  That is incorrect but is what we have to live with with
119     * the existing external memory extensions.
120     *
121     * The main reason is that the external memory extensions require us to use
122     * vkGetPhysicalDeviceExternalBufferProperties or
123     * vkGetPhysicalDeviceImageFormatProperties2 to determine if we can
124     * allocate an exportable external VkDeviceMemory.  But we normally do not
125     * have the info to make the queries during vkAllocateMemory.
126     *
127     * We only have VkMemoryAllocateInfo during vkAllocateMemory.  The only
128     * useful info in the struct is the memory type.  What we need is thus an
129     * extension that tells us that, given a memory type, if all VkDeviceMemory
130     * with the memory type is exportable.  If we had the extension, we could
131     * filter out VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT here if a memory type is
132     * not always exportable.
133     */
134 
135    /* XXX is_dma_buf_fd_export_supported and is_opaque_fd_export_supported
136     * needs to be filled with a new extension which supports query fd export
137     * against the raw memory types. Currently, we workaround by checking
138     * external buffer properties before force-enabling either dma_buf or opaque
139     * fd path of device memory allocation.
140     */
141    physical_dev->is_dma_buf_fd_export_supported = false;
142    physical_dev->is_opaque_fd_export_supported = false;
143 
144    VkPhysicalDeviceExternalBufferInfo info = {
145       .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO,
146       .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
147    };
148    VkExternalBufferProperties props = {
149       .sType = VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES,
150    };
151 
152    if (physical_dev->EXT_external_memory_dma_buf) {
153       info.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
154       vkGetPhysicalDeviceExternalBufferProperties(handle, &info, &props);
155       physical_dev->is_dma_buf_fd_export_supported =
156          (props.externalMemoryProperties.externalMemoryFeatures &
157           VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) &&
158          (props.externalMemoryProperties.exportFromImportedHandleTypes &
159           VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
160    }
161 
162    if (physical_dev->KHR_external_memory_fd) {
163       info.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
164       vkGetPhysicalDeviceExternalBufferProperties(handle, &info, &props);
165       physical_dev->is_opaque_fd_export_supported =
166          (props.externalMemoryProperties.externalMemoryFeatures &
167           VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) &&
168          (props.externalMemoryProperties.exportFromImportedHandleTypes &
169           VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT);
170    }
171 
172    if (!physical_dev->is_dma_buf_fd_export_supported &&
173        !physical_dev->is_opaque_fd_export_supported)
174       physical_dev->gbm_device = vkr_physical_device_get_gbm_device(physical_dev);
175 }
176 
177 static void
vkr_physical_device_init_extensions(struct vkr_physical_device * physical_dev,struct vkr_instance * instance)178 vkr_physical_device_init_extensions(struct vkr_physical_device *physical_dev,
179                                     struct vkr_instance *instance)
180 {
181    VkPhysicalDevice handle = physical_dev->base.handle.physical_device;
182 
183    VkExtensionProperties *exts;
184    uint32_t count;
185    VkResult result = vkEnumerateDeviceExtensionProperties(handle, NULL, &count, NULL);
186    if (result != VK_SUCCESS)
187       return;
188 
189    exts = malloc(sizeof(*exts) * count);
190    if (!exts)
191       return;
192 
193    result = vkEnumerateDeviceExtensionProperties(handle, NULL, &count, exts);
194    if (result != VK_SUCCESS) {
195       free(exts);
196       return;
197    }
198 
199    uint32_t advertised_count = 0;
200    for (uint32_t i = 0; i < count; i++) {
201       VkExtensionProperties *props = &exts[i];
202 
203       if (!strcmp(props->extensionName, "VK_KHR_external_memory_fd"))
204          physical_dev->KHR_external_memory_fd = true;
205       else if (!strcmp(props->extensionName, "VK_EXT_external_memory_dma_buf"))
206          physical_dev->EXT_external_memory_dma_buf = true;
207       else if (!strcmp(props->extensionName, "VK_KHR_external_fence_fd"))
208          physical_dev->KHR_external_fence_fd = true;
209 
210       const uint32_t spec_ver = vkr_extension_get_spec_version(props->extensionName);
211       if (spec_ver) {
212          if (props->specVersion > spec_ver)
213             props->specVersion = spec_ver;
214          exts[advertised_count++] = exts[i];
215       }
216    }
217 
218    if (physical_dev->KHR_external_fence_fd) {
219       const VkPhysicalDeviceExternalFenceInfo fence_info = {
220          .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO,
221          .handleType = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT,
222       };
223       VkExternalFenceProperties fence_props = {
224          .sType = VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES,
225       };
226       PFN_vkGetPhysicalDeviceExternalFenceProperties get_fence_props =
227          (PFN_vkGetPhysicalDeviceExternalFenceProperties)vkGetInstanceProcAddr(
228             instance->base.handle.instance, "vkGetPhysicalDeviceExternalFenceProperties");
229       get_fence_props(handle, &fence_info, &fence_props);
230 
231       if (!(fence_props.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT))
232          physical_dev->KHR_external_fence_fd = false;
233    }
234 
235    physical_dev->extensions = exts;
236    physical_dev->extension_count = advertised_count;
237 }
238 
239 static void
vkr_physical_device_init_properties(struct vkr_physical_device * physical_dev)240 vkr_physical_device_init_properties(struct vkr_physical_device *physical_dev)
241 {
242    VkPhysicalDevice handle = physical_dev->base.handle.physical_device;
243    vkGetPhysicalDeviceProperties(handle, &physical_dev->properties);
244 
245    VkPhysicalDeviceProperties *props = &physical_dev->properties;
246    props->apiVersion = vkr_api_version_cap_minor(props->apiVersion, VKR_MAX_API_VERSION);
247 }
248 
249 static void
vkr_physical_device_init_proc_table(struct vkr_physical_device * physical_dev,struct vkr_instance * instance)250 vkr_physical_device_init_proc_table(struct vkr_physical_device *physical_dev,
251                                     struct vkr_instance *instance)
252 {
253    vn_util_init_physical_device_proc_table(instance->base.handle.instance,
254                                            &physical_dev->proc_table);
255 }
256 
257 static void
vkr_dispatch_vkEnumeratePhysicalDevices(struct vn_dispatch_context * dispatch,struct vn_command_vkEnumeratePhysicalDevices * args)258 vkr_dispatch_vkEnumeratePhysicalDevices(struct vn_dispatch_context *dispatch,
259                                         struct vn_command_vkEnumeratePhysicalDevices *args)
260 {
261    struct vkr_context *ctx = dispatch->data;
262 
263    struct vkr_instance *instance = vkr_instance_from_handle(args->instance);
264    if (instance != ctx->instance) {
265       vkr_cs_decoder_set_fatal(&ctx->decoder);
266       return;
267    }
268 
269    args->ret = vkr_instance_enumerate_physical_devices(instance);
270    if (args->ret != VK_SUCCESS)
271       return;
272 
273    uint32_t count = instance->physical_device_count;
274    if (!args->pPhysicalDevices) {
275       *args->pPhysicalDeviceCount = count;
276       args->ret = VK_SUCCESS;
277       return;
278    }
279 
280    if (count > *args->pPhysicalDeviceCount) {
281       count = *args->pPhysicalDeviceCount;
282       args->ret = VK_INCOMPLETE;
283    } else {
284       *args->pPhysicalDeviceCount = count;
285       args->ret = VK_SUCCESS;
286    }
287 
288    uint32_t i;
289    for (i = 0; i < count; i++) {
290       struct vkr_physical_device *physical_dev = instance->physical_devices[i];
291       const vkr_object_id id = vkr_cs_handle_load_id(
292          (const void **)&args->pPhysicalDevices[i], VK_OBJECT_TYPE_PHYSICAL_DEVICE);
293 
294       if (physical_dev) {
295          if (physical_dev->base.id != id) {
296             vkr_cs_decoder_set_fatal(&ctx->decoder);
297             break;
298          }
299          continue;
300       }
301 
302       if (!vkr_context_validate_object_id(ctx, id))
303          break;
304 
305       physical_dev =
306          vkr_object_alloc(sizeof(*physical_dev), VK_OBJECT_TYPE_PHYSICAL_DEVICE, id);
307       if (!physical_dev) {
308          args->ret = VK_ERROR_OUT_OF_HOST_MEMORY;
309          break;
310       }
311 
312       physical_dev->base.handle.physical_device = instance->physical_device_handles[i];
313 
314       vkr_physical_device_init_proc_table(physical_dev, instance);
315       vkr_physical_device_init_properties(physical_dev);
316       physical_dev->api_version =
317          MIN2(physical_dev->properties.apiVersion, instance->api_version);
318       vkr_physical_device_init_extensions(physical_dev, instance);
319       vkr_physical_device_init_memory_properties(physical_dev);
320       vkr_physical_device_init_id_properties(physical_dev);
321 
322       list_inithead(&physical_dev->devices);
323 
324       instance->physical_devices[i] = physical_dev;
325 
326       vkr_context_add_object(ctx, &physical_dev->base);
327    }
328    /* remove all physical devices on errors */
329    if (i < count) {
330       for (i = 0; i < instance->physical_device_count; i++) {
331          struct vkr_physical_device *physical_dev = instance->physical_devices[i];
332          if (!physical_dev)
333             break;
334          free(physical_dev->extensions);
335          vkr_context_remove_object(ctx, &physical_dev->base);
336          instance->physical_devices[i] = NULL;
337       }
338    }
339 }
340 
341 static void
vkr_dispatch_vkEnumeratePhysicalDeviceGroups(struct vn_dispatch_context * dispatch,struct vn_command_vkEnumeratePhysicalDeviceGroups * args)342 vkr_dispatch_vkEnumeratePhysicalDeviceGroups(
343    struct vn_dispatch_context *dispatch,
344    struct vn_command_vkEnumeratePhysicalDeviceGroups *args)
345 {
346    struct vkr_context *ctx = dispatch->data;
347 
348    struct vkr_instance *instance = vkr_instance_from_handle(args->instance);
349    if (instance != ctx->instance) {
350       vkr_cs_decoder_set_fatal(&ctx->decoder);
351       return;
352    }
353 
354    args->ret = vkr_instance_enumerate_physical_devices(instance);
355    if (args->ret != VK_SUCCESS)
356       return;
357 
358    VkPhysicalDeviceGroupProperties *orig_props = args->pPhysicalDeviceGroupProperties;
359    if (orig_props) {
360       args->pPhysicalDeviceGroupProperties =
361          calloc(*args->pPhysicalDeviceGroupCount, sizeof(*orig_props));
362       if (!args->pPhysicalDeviceGroupProperties) {
363          args->ret = VK_ERROR_OUT_OF_HOST_MEMORY;
364          return;
365       }
366 
367       for (uint32_t i = 0; i < *args->pPhysicalDeviceGroupCount; i++) {
368          args->pPhysicalDeviceGroupProperties[i].sType =
369             VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
370       }
371    }
372 
373    vn_replace_vkEnumeratePhysicalDeviceGroups_args_handle(args);
374    args->ret =
375       vkEnumeratePhysicalDeviceGroups(args->instance, args->pPhysicalDeviceGroupCount,
376                                       args->pPhysicalDeviceGroupProperties);
377    if (args->ret != VK_SUCCESS)
378       return;
379 
380    if (!orig_props)
381       return;
382 
383    /* XXX this assumes vkEnumeratePhysicalDevices is called first */
384    /* replace VkPhysicalDevice handles by object ids */
385    for (uint32_t i = 0; i < *args->pPhysicalDeviceGroupCount; i++) {
386       const VkPhysicalDeviceGroupProperties *props =
387          &args->pPhysicalDeviceGroupProperties[i];
388       VkPhysicalDeviceGroupProperties *out = &orig_props[i];
389 
390       out->physicalDeviceCount = props->physicalDeviceCount;
391       out->subsetAllocation = props->subsetAllocation;
392       for (uint32_t j = 0; j < props->physicalDeviceCount; j++) {
393          const struct vkr_physical_device *physical_dev =
394             vkr_instance_lookup_physical_device(instance, props->physicalDevices[j]);
395          vkr_cs_handle_store_id((void **)&out->physicalDevices[j], physical_dev->base.id,
396                                 VK_OBJECT_TYPE_PHYSICAL_DEVICE);
397       }
398    }
399 
400    free(args->pPhysicalDeviceGroupProperties);
401    args->pPhysicalDeviceGroupProperties = orig_props;
402 }
403 
404 static void
vkr_dispatch_vkEnumerateDeviceExtensionProperties(struct vn_dispatch_context * dispatch,struct vn_command_vkEnumerateDeviceExtensionProperties * args)405 vkr_dispatch_vkEnumerateDeviceExtensionProperties(
406    struct vn_dispatch_context *dispatch,
407    struct vn_command_vkEnumerateDeviceExtensionProperties *args)
408 {
409    struct vkr_context *ctx = dispatch->data;
410 
411    struct vkr_physical_device *physical_dev =
412       vkr_physical_device_from_handle(args->physicalDevice);
413    if (args->pLayerName) {
414       vkr_cs_decoder_set_fatal(&ctx->decoder);
415       return;
416    }
417 
418    if (!args->pProperties) {
419       *args->pPropertyCount = physical_dev->extension_count;
420       args->ret = VK_SUCCESS;
421       return;
422    }
423 
424    uint32_t count = physical_dev->extension_count;
425    if (count > *args->pPropertyCount) {
426       count = *args->pPropertyCount;
427       args->ret = VK_INCOMPLETE;
428    } else {
429       *args->pPropertyCount = count;
430       args->ret = VK_SUCCESS;
431    }
432 
433    memcpy(args->pProperties, physical_dev->extensions,
434           sizeof(*args->pProperties) * count);
435 }
436 
437 static void
vkr_dispatch_vkGetPhysicalDeviceFeatures(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceFeatures * args)438 vkr_dispatch_vkGetPhysicalDeviceFeatures(
439    UNUSED struct vn_dispatch_context *dispatch,
440    struct vn_command_vkGetPhysicalDeviceFeatures *args)
441 {
442    vn_replace_vkGetPhysicalDeviceFeatures_args_handle(args);
443    vkGetPhysicalDeviceFeatures(args->physicalDevice, args->pFeatures);
444 }
445 
446 static void
vkr_dispatch_vkGetPhysicalDeviceProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceProperties * args)447 vkr_dispatch_vkGetPhysicalDeviceProperties(
448    UNUSED struct vn_dispatch_context *dispatch,
449    struct vn_command_vkGetPhysicalDeviceProperties *args)
450 {
451    struct vkr_physical_device *physical_dev =
452       vkr_physical_device_from_handle(args->physicalDevice);
453 
454    *args->pProperties = physical_dev->properties;
455 }
456 
457 static void
vkr_dispatch_vkGetPhysicalDeviceQueueFamilyProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceQueueFamilyProperties * args)458 vkr_dispatch_vkGetPhysicalDeviceQueueFamilyProperties(
459    UNUSED struct vn_dispatch_context *dispatch,
460    struct vn_command_vkGetPhysicalDeviceQueueFamilyProperties *args)
461 {
462    vn_replace_vkGetPhysicalDeviceQueueFamilyProperties_args_handle(args);
463    vkGetPhysicalDeviceQueueFamilyProperties(args->physicalDevice,
464                                             args->pQueueFamilyPropertyCount,
465                                             args->pQueueFamilyProperties);
466 }
467 
468 static void
vkr_dispatch_vkGetPhysicalDeviceMemoryProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceMemoryProperties * args)469 vkr_dispatch_vkGetPhysicalDeviceMemoryProperties(
470    UNUSED struct vn_dispatch_context *dispatch,
471    struct vn_command_vkGetPhysicalDeviceMemoryProperties *args)
472 {
473    struct vkr_physical_device *physical_dev =
474       vkr_physical_device_from_handle(args->physicalDevice);
475    *args->pMemoryProperties = physical_dev->memory_properties;
476 }
477 
478 static void
vkr_dispatch_vkGetPhysicalDeviceFormatProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceFormatProperties * args)479 vkr_dispatch_vkGetPhysicalDeviceFormatProperties(
480    UNUSED struct vn_dispatch_context *dispatch,
481    struct vn_command_vkGetPhysicalDeviceFormatProperties *args)
482 {
483    vn_replace_vkGetPhysicalDeviceFormatProperties_args_handle(args);
484    vkGetPhysicalDeviceFormatProperties(args->physicalDevice, args->format,
485                                        args->pFormatProperties);
486 }
487 
488 static void
vkr_dispatch_vkGetPhysicalDeviceImageFormatProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceImageFormatProperties * args)489 vkr_dispatch_vkGetPhysicalDeviceImageFormatProperties(
490    UNUSED struct vn_dispatch_context *dispatch,
491    struct vn_command_vkGetPhysicalDeviceImageFormatProperties *args)
492 {
493    vn_replace_vkGetPhysicalDeviceImageFormatProperties_args_handle(args);
494    args->ret = vkGetPhysicalDeviceImageFormatProperties(
495       args->physicalDevice, args->format, args->type, args->tiling, args->usage,
496       args->flags, args->pImageFormatProperties);
497 }
498 
499 static void
vkr_dispatch_vkGetPhysicalDeviceSparseImageFormatProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceSparseImageFormatProperties * args)500 vkr_dispatch_vkGetPhysicalDeviceSparseImageFormatProperties(
501    UNUSED struct vn_dispatch_context *dispatch,
502    struct vn_command_vkGetPhysicalDeviceSparseImageFormatProperties *args)
503 {
504    vn_replace_vkGetPhysicalDeviceSparseImageFormatProperties_args_handle(args);
505    vkGetPhysicalDeviceSparseImageFormatProperties(
506       args->physicalDevice, args->format, args->type, args->samples, args->usage,
507       args->tiling, args->pPropertyCount, args->pProperties);
508 }
509 
510 static void
vkr_dispatch_vkGetPhysicalDeviceFeatures2(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceFeatures2 * args)511 vkr_dispatch_vkGetPhysicalDeviceFeatures2(
512    UNUSED struct vn_dispatch_context *dispatch,
513    struct vn_command_vkGetPhysicalDeviceFeatures2 *args)
514 {
515    vn_replace_vkGetPhysicalDeviceFeatures2_args_handle(args);
516    vkGetPhysicalDeviceFeatures2(args->physicalDevice, args->pFeatures);
517 }
518 
519 static void
vkr_dispatch_vkGetPhysicalDeviceProperties2(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceProperties2 * args)520 vkr_dispatch_vkGetPhysicalDeviceProperties2(
521    UNUSED struct vn_dispatch_context *dispatch,
522    struct vn_command_vkGetPhysicalDeviceProperties2 *args)
523 {
524    vn_replace_vkGetPhysicalDeviceProperties2_args_handle(args);
525    vkGetPhysicalDeviceProperties2(args->physicalDevice, args->pProperties);
526 }
527 
528 static void
vkr_dispatch_vkGetPhysicalDeviceQueueFamilyProperties2(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceQueueFamilyProperties2 * args)529 vkr_dispatch_vkGetPhysicalDeviceQueueFamilyProperties2(
530    UNUSED struct vn_dispatch_context *dispatch,
531    struct vn_command_vkGetPhysicalDeviceQueueFamilyProperties2 *args)
532 {
533    vn_replace_vkGetPhysicalDeviceQueueFamilyProperties2_args_handle(args);
534    vkGetPhysicalDeviceQueueFamilyProperties2(args->physicalDevice,
535                                              args->pQueueFamilyPropertyCount,
536                                              args->pQueueFamilyProperties);
537 }
538 
539 static void
vkr_dispatch_vkGetPhysicalDeviceMemoryProperties2(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceMemoryProperties2 * args)540 vkr_dispatch_vkGetPhysicalDeviceMemoryProperties2(
541    UNUSED struct vn_dispatch_context *dispatch,
542    struct vn_command_vkGetPhysicalDeviceMemoryProperties2 *args)
543 {
544    struct vkr_physical_device *physical_dev =
545       vkr_physical_device_from_handle(args->physicalDevice);
546    args->pMemoryProperties->memoryProperties = physical_dev->memory_properties;
547 }
548 
549 static void
vkr_dispatch_vkGetPhysicalDeviceFormatProperties2(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceFormatProperties2 * args)550 vkr_dispatch_vkGetPhysicalDeviceFormatProperties2(
551    UNUSED struct vn_dispatch_context *dispatch,
552    struct vn_command_vkGetPhysicalDeviceFormatProperties2 *args)
553 {
554    vn_replace_vkGetPhysicalDeviceFormatProperties2_args_handle(args);
555    vkGetPhysicalDeviceFormatProperties2(args->physicalDevice, args->format,
556                                         args->pFormatProperties);
557 }
558 
559 static void
vkr_dispatch_vkGetPhysicalDeviceImageFormatProperties2(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceImageFormatProperties2 * args)560 vkr_dispatch_vkGetPhysicalDeviceImageFormatProperties2(
561    UNUSED struct vn_dispatch_context *dispatch,
562    struct vn_command_vkGetPhysicalDeviceImageFormatProperties2 *args)
563 {
564    vn_replace_vkGetPhysicalDeviceImageFormatProperties2_args_handle(args);
565    args->ret = vkGetPhysicalDeviceImageFormatProperties2(
566       args->physicalDevice, args->pImageFormatInfo, args->pImageFormatProperties);
567 }
568 
569 static void
vkr_dispatch_vkGetPhysicalDeviceSparseImageFormatProperties2(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceSparseImageFormatProperties2 * args)570 vkr_dispatch_vkGetPhysicalDeviceSparseImageFormatProperties2(
571    UNUSED struct vn_dispatch_context *dispatch,
572    struct vn_command_vkGetPhysicalDeviceSparseImageFormatProperties2 *args)
573 {
574    vn_replace_vkGetPhysicalDeviceSparseImageFormatProperties2_args_handle(args);
575    vkGetPhysicalDeviceSparseImageFormatProperties2(
576       args->physicalDevice, args->pFormatInfo, args->pPropertyCount, args->pProperties);
577 }
578 
579 static void
vkr_dispatch_vkGetPhysicalDeviceExternalBufferProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceExternalBufferProperties * args)580 vkr_dispatch_vkGetPhysicalDeviceExternalBufferProperties(
581    UNUSED struct vn_dispatch_context *dispatch,
582    struct vn_command_vkGetPhysicalDeviceExternalBufferProperties *args)
583 {
584    vn_replace_vkGetPhysicalDeviceExternalBufferProperties_args_handle(args);
585    vkGetPhysicalDeviceExternalBufferProperties(
586       args->physicalDevice, args->pExternalBufferInfo, args->pExternalBufferProperties);
587 }
588 
589 static void
vkr_dispatch_vkGetPhysicalDeviceExternalSemaphoreProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceExternalSemaphoreProperties * args)590 vkr_dispatch_vkGetPhysicalDeviceExternalSemaphoreProperties(
591    UNUSED struct vn_dispatch_context *dispatch,
592    struct vn_command_vkGetPhysicalDeviceExternalSemaphoreProperties *args)
593 {
594    vn_replace_vkGetPhysicalDeviceExternalSemaphoreProperties_args_handle(args);
595    vkGetPhysicalDeviceExternalSemaphoreProperties(args->physicalDevice,
596                                                   args->pExternalSemaphoreInfo,
597                                                   args->pExternalSemaphoreProperties);
598 }
599 
600 static void
vkr_dispatch_vkGetPhysicalDeviceExternalFenceProperties(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPhysicalDeviceExternalFenceProperties * args)601 vkr_dispatch_vkGetPhysicalDeviceExternalFenceProperties(
602    UNUSED struct vn_dispatch_context *dispatch,
603    struct vn_command_vkGetPhysicalDeviceExternalFenceProperties *args)
604 {
605    vn_replace_vkGetPhysicalDeviceExternalFenceProperties_args_handle(args);
606    vkGetPhysicalDeviceExternalFenceProperties(
607       args->physicalDevice, args->pExternalFenceInfo, args->pExternalFenceProperties);
608 }
609 
610 static void
vkr_dispatch_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(UNUSED struct vn_dispatch_context * ctx,struct vn_command_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT * args)611 vkr_dispatch_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(
612    UNUSED struct vn_dispatch_context *ctx,
613    struct vn_command_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT *args)
614 {
615    struct vkr_physical_device *physical_dev =
616       vkr_physical_device_from_handle(args->physicalDevice);
617    struct vn_physical_device_proc_table *vk = &physical_dev->proc_table;
618 
619    vn_replace_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT_args_handle(args);
620    args->ret = vk->GetPhysicalDeviceCalibrateableTimeDomainsEXT(
621       args->physicalDevice, args->pTimeDomainCount, args->pTimeDomains);
622 }
623 
624 void
vkr_context_init_physical_device_dispatch(struct vkr_context * ctx)625 vkr_context_init_physical_device_dispatch(struct vkr_context *ctx)
626 {
627    struct vn_dispatch_context *dispatch = &ctx->dispatch;
628 
629    dispatch->dispatch_vkEnumeratePhysicalDevices =
630       vkr_dispatch_vkEnumeratePhysicalDevices;
631    dispatch->dispatch_vkEnumeratePhysicalDeviceGroups =
632       vkr_dispatch_vkEnumeratePhysicalDeviceGroups;
633    dispatch->dispatch_vkEnumerateDeviceExtensionProperties =
634       vkr_dispatch_vkEnumerateDeviceExtensionProperties;
635    dispatch->dispatch_vkEnumerateDeviceLayerProperties = NULL;
636 
637    dispatch->dispatch_vkGetPhysicalDeviceFeatures =
638       vkr_dispatch_vkGetPhysicalDeviceFeatures;
639    dispatch->dispatch_vkGetPhysicalDeviceProperties =
640       vkr_dispatch_vkGetPhysicalDeviceProperties;
641    dispatch->dispatch_vkGetPhysicalDeviceQueueFamilyProperties =
642       vkr_dispatch_vkGetPhysicalDeviceQueueFamilyProperties;
643    dispatch->dispatch_vkGetPhysicalDeviceMemoryProperties =
644       vkr_dispatch_vkGetPhysicalDeviceMemoryProperties;
645    dispatch->dispatch_vkGetPhysicalDeviceFormatProperties =
646       vkr_dispatch_vkGetPhysicalDeviceFormatProperties;
647    dispatch->dispatch_vkGetPhysicalDeviceImageFormatProperties =
648       vkr_dispatch_vkGetPhysicalDeviceImageFormatProperties;
649    dispatch->dispatch_vkGetPhysicalDeviceSparseImageFormatProperties =
650       vkr_dispatch_vkGetPhysicalDeviceSparseImageFormatProperties;
651    dispatch->dispatch_vkGetPhysicalDeviceFeatures2 =
652       vkr_dispatch_vkGetPhysicalDeviceFeatures2;
653    dispatch->dispatch_vkGetPhysicalDeviceProperties2 =
654       vkr_dispatch_vkGetPhysicalDeviceProperties2;
655    dispatch->dispatch_vkGetPhysicalDeviceQueueFamilyProperties2 =
656       vkr_dispatch_vkGetPhysicalDeviceQueueFamilyProperties2;
657    dispatch->dispatch_vkGetPhysicalDeviceMemoryProperties2 =
658       vkr_dispatch_vkGetPhysicalDeviceMemoryProperties2;
659    dispatch->dispatch_vkGetPhysicalDeviceFormatProperties2 =
660       vkr_dispatch_vkGetPhysicalDeviceFormatProperties2;
661    dispatch->dispatch_vkGetPhysicalDeviceImageFormatProperties2 =
662       vkr_dispatch_vkGetPhysicalDeviceImageFormatProperties2;
663    dispatch->dispatch_vkGetPhysicalDeviceSparseImageFormatProperties2 =
664       vkr_dispatch_vkGetPhysicalDeviceSparseImageFormatProperties2;
665    dispatch->dispatch_vkGetPhysicalDeviceExternalBufferProperties =
666       vkr_dispatch_vkGetPhysicalDeviceExternalBufferProperties;
667    dispatch->dispatch_vkGetMemoryFdKHR = NULL;
668    dispatch->dispatch_vkGetMemoryFdPropertiesKHR = NULL;
669    dispatch->dispatch_vkGetPhysicalDeviceExternalSemaphoreProperties =
670       vkr_dispatch_vkGetPhysicalDeviceExternalSemaphoreProperties;
671    dispatch->dispatch_vkGetPhysicalDeviceExternalFenceProperties =
672       vkr_dispatch_vkGetPhysicalDeviceExternalFenceProperties;
673    dispatch->dispatch_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT =
674       vkr_dispatch_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT;
675 }
676