Path: blob/21.2-virgl/src/vulkan/util/vk_physical_device.c
7202 views
/*1* Copyright © 2021 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "vk_physical_device.h"2425#include "vk_common_entrypoints.h"26#include "vk_util.h"2728VkResult29vk_physical_device_init(struct vk_physical_device *pdevice,30struct vk_instance *instance,31const struct vk_device_extension_table *supported_extensions,32const struct vk_physical_device_dispatch_table *dispatch_table)33{34memset(pdevice, 0, sizeof(*pdevice));35vk_object_base_init(NULL, &pdevice->base, VK_OBJECT_TYPE_PHYSICAL_DEVICE);36pdevice->instance = instance;3738if (supported_extensions != NULL)39pdevice->supported_extensions = *supported_extensions;4041pdevice->dispatch_table = *dispatch_table;4243/* Add common entrypoints without overwriting driver-provided ones. */44vk_physical_device_dispatch_table_from_entrypoints(45&pdevice->dispatch_table, &vk_common_physical_device_entrypoints, false);4647return VK_SUCCESS;48}4950void51vk_physical_device_finish(struct vk_physical_device *physical_device)52{53vk_object_base_finish(&physical_device->base);54}5556VKAPI_ATTR VkResult VKAPI_CALL57vk_common_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,58uint32_t *pPropertyCount,59VkLayerProperties *pProperties)60{61if (pProperties == NULL) {62*pPropertyCount = 0;63return VK_SUCCESS;64}6566/* None supported at this time */67return VK_ERROR_LAYER_NOT_PRESENT;68}6970VKAPI_ATTR VkResult VKAPI_CALL71vk_common_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,72const char *pLayerName,73uint32_t *pPropertyCount,74VkExtensionProperties *pProperties)75{76VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);77VK_OUTARRAY_MAKE_TYPED(VkExtensionProperties, out, pProperties, pPropertyCount);7879for (int i = 0; i < VK_DEVICE_EXTENSION_COUNT; i++) {80if (!pdevice->supported_extensions.extensions[i])81continue;8283#ifdef ANDROID84if (!vk_android_allowed_device_extensions.extensions[i])85continue;86#endif8788vk_outarray_append_typed(VkExtensionProperties, &out, prop) {89*prop = vk_device_extensions[i];90}91}9293return vk_outarray_status(&out);94}9596VKAPI_ATTR void VKAPI_CALL97vk_common_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,98VkPhysicalDeviceFeatures *pFeatures)99{100VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);101102/* Don't zero-init this struct since the driver fills it out entirely */103VkPhysicalDeviceFeatures2 features2;104features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;105features2.pNext = NULL;106107pdevice->dispatch_table.GetPhysicalDeviceFeatures2(physicalDevice,108&features2);109*pFeatures = features2.features;110}111112VKAPI_ATTR void VKAPI_CALL113vk_common_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,114VkPhysicalDeviceProperties *pProperties)115{116VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);117118/* Don't zero-init this struct since the driver fills it out entirely */119VkPhysicalDeviceProperties2 props2;120props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;121props2.pNext = NULL;122123pdevice->dispatch_table.GetPhysicalDeviceProperties2(physicalDevice,124&props2);125*pProperties = props2.properties;126}127128VKAPI_ATTR void VKAPI_CALL129vk_common_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,130VkPhysicalDeviceMemoryProperties *pMemoryProperties)131{132VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);133134/* Don't zero-init this struct since the driver fills it out entirely */135VkPhysicalDeviceMemoryProperties2 props2;136props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;137props2.pNext = NULL;138139pdevice->dispatch_table.GetPhysicalDeviceMemoryProperties2(physicalDevice,140&props2);141/* dEQP-VK.api.info.get_physical_device_properties2.memory_properties memsets142* the struct to 0xcd and expects that the unused array elements are143* untouched.144*/145pMemoryProperties->memoryHeapCount = props2.memoryProperties.memoryHeapCount;146for (int i = 0; i < pMemoryProperties->memoryHeapCount; i++) {147pMemoryProperties->memoryHeaps[i].flags = props2.memoryProperties.memoryHeaps[i].flags;148pMemoryProperties->memoryHeaps[i].size = props2.memoryProperties.memoryHeaps[i].size;149}150151pMemoryProperties->memoryTypeCount = props2.memoryProperties.memoryTypeCount;152for (int i = 0; i < pMemoryProperties->memoryTypeCount; i++) {153pMemoryProperties->memoryTypes[i].heapIndex = props2.memoryProperties.memoryTypes[i].heapIndex;154pMemoryProperties->memoryTypes[i].propertyFlags = props2.memoryProperties.memoryTypes[i].propertyFlags;155}156}157158VKAPI_ATTR void VKAPI_CALL159vk_common_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,160VkFormat format,161VkFormatProperties *pFormatProperties)162{163VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);164165/* Don't zero-init this struct since the driver fills it out entirely */166VkFormatProperties2 props2;167props2.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2;168props2.pNext = NULL;169170pdevice->dispatch_table.GetPhysicalDeviceFormatProperties2(physicalDevice,171format, &props2);172*pFormatProperties = props2.formatProperties;173}174175VKAPI_ATTR VkResult VKAPI_CALL176vk_common_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice,177VkFormat format,178VkImageType type,179VkImageTiling tiling,180VkImageUsageFlags usage,181VkImageCreateFlags flags,182VkImageFormatProperties *pImageFormatProperties)183{184VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);185186VkPhysicalDeviceImageFormatInfo2 info = {187.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,188.format = format,189.type = type,190.tiling = tiling,191.usage = usage,192.flags = flags193};194195/* Don't zero-init this struct since the driver fills it out entirely */196VkImageFormatProperties2 props2;197props2.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2;198props2.pNext = NULL;199200VkResult result =201pdevice->dispatch_table.GetPhysicalDeviceImageFormatProperties2(physicalDevice,202&info, &props2);203*pImageFormatProperties = props2.imageFormatProperties;204205return result;206}207208209