diff options
Diffstat (limited to 'lib/mesa/src/vulkan/util/vk_physical_device.c')
-rw-r--r-- | lib/mesa/src/vulkan/util/vk_physical_device.c | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/lib/mesa/src/vulkan/util/vk_physical_device.c b/lib/mesa/src/vulkan/util/vk_physical_device.c new file mode 100644 index 000000000..18cab2e87 --- /dev/null +++ b/lib/mesa/src/vulkan/util/vk_physical_device.c @@ -0,0 +1,193 @@ +/* + * Copyright © 2021 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "vk_physical_device.h" + +#include "vk_common_entrypoints.h" +#include "vk_util.h" + +VkResult +vk_physical_device_init(struct vk_physical_device *pdevice, + struct vk_instance *instance, + const struct vk_device_extension_table *supported_extensions, + const struct vk_physical_device_dispatch_table *dispatch_table) +{ + memset(pdevice, 0, sizeof(*pdevice)); + vk_object_base_init(NULL, &pdevice->base, VK_OBJECT_TYPE_PHYSICAL_DEVICE); + pdevice->instance = instance; + + if (supported_extensions != NULL) + pdevice->supported_extensions = *supported_extensions; + + pdevice->dispatch_table = *dispatch_table; + + /* Add common entrypoints without overwriting driver-provided ones. */ + vk_physical_device_dispatch_table_from_entrypoints( + &pdevice->dispatch_table, &vk_common_physical_device_entrypoints, false); + + return VK_SUCCESS; +} + +void +vk_physical_device_finish(struct vk_physical_device *physical_device) +{ + vk_object_base_finish(&physical_device->base); +} + +VKAPI_ATTR VkResult VKAPI_CALL +vk_common_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, + uint32_t *pPropertyCount, + VkLayerProperties *pProperties) +{ + if (pProperties == NULL) { + *pPropertyCount = 0; + return VK_SUCCESS; + } + + /* None supported at this time */ + return VK_ERROR_LAYER_NOT_PRESENT; +} + +VKAPI_ATTR VkResult VKAPI_CALL +vk_common_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, + const char *pLayerName, + uint32_t *pPropertyCount, + VkExtensionProperties *pProperties) +{ + VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); + VK_OUTARRAY_MAKE_TYPED(VkExtensionProperties, out, pProperties, pPropertyCount); + + for (int i = 0; i < VK_DEVICE_EXTENSION_COUNT; i++) { + if (!pdevice->supported_extensions.extensions[i]) + continue; + +#ifdef ANDROID + if (!vk_android_allowed_device_extensions.extensions[i]) + continue; +#endif + + vk_outarray_append_typed(VkExtensionProperties, &out, prop) { + *prop = vk_device_extensions[i]; + } + } + + return vk_outarray_status(&out); +} + +VKAPI_ATTR void VKAPI_CALL +vk_common_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, + VkPhysicalDeviceFeatures *pFeatures) +{ + VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); + + /* Don't zero-init this struct since the driver fills it out entirely */ + VkPhysicalDeviceFeatures2 features2; + features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + features2.pNext = NULL; + + pdevice->dispatch_table.GetPhysicalDeviceFeatures2(physicalDevice, + &features2); + *pFeatures = features2.features; +} + +VKAPI_ATTR void VKAPI_CALL +vk_common_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, + VkPhysicalDeviceProperties *pProperties) +{ + VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); + + /* Don't zero-init this struct since the driver fills it out entirely */ + VkPhysicalDeviceProperties2 props2; + props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; + props2.pNext = NULL; + + pdevice->dispatch_table.GetPhysicalDeviceProperties2(physicalDevice, + &props2); + *pProperties = props2.properties; +} + +VKAPI_ATTR void VKAPI_CALL +vk_common_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, + VkPhysicalDeviceMemoryProperties *pMemoryProperties) +{ + VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); + + /* Don't zero-init this struct since the driver fills it out entirely */ + VkPhysicalDeviceMemoryProperties2 props2; + props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2; + props2.pNext = NULL; + + pdevice->dispatch_table.GetPhysicalDeviceMemoryProperties2(physicalDevice, + &props2); + *pMemoryProperties = props2.memoryProperties; +} + +VKAPI_ATTR void VKAPI_CALL +vk_common_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, + VkFormat format, + VkFormatProperties *pFormatProperties) +{ + VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); + + /* Don't zero-init this struct since the driver fills it out entirely */ + VkFormatProperties2 props2; + props2.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2; + props2.pNext = NULL; + + pdevice->dispatch_table.GetPhysicalDeviceFormatProperties2(physicalDevice, + format, &props2); + *pFormatProperties = props2.formatProperties; +} + +VKAPI_ATTR VkResult VKAPI_CALL +vk_common_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags flags, + VkImageFormatProperties *pImageFormatProperties) +{ + VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); + + VkPhysicalDeviceImageFormatInfo2 info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, + .format = format, + .type = type, + .tiling = tiling, + .usage = usage, + .flags = flags + }; + + /* Don't zero-init this struct since the driver fills it out entirely */ + VkImageFormatProperties2 props2; + props2.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2; + props2.pNext = NULL; + + VkResult result = + pdevice->dispatch_table.GetPhysicalDeviceImageFormatProperties2(physicalDevice, + &info, &props2); + *pImageFormatProperties = props2.imageFormatProperties; + + return result; +} |