1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2021 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "vk_physical_device.h" 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "vk_common_entrypoints.h" 27bf215546Sopenharmony_ci#include "vk_util.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ciVkResult 30bf215546Sopenharmony_civk_physical_device_init(struct vk_physical_device *pdevice, 31bf215546Sopenharmony_ci struct vk_instance *instance, 32bf215546Sopenharmony_ci const struct vk_device_extension_table *supported_extensions, 33bf215546Sopenharmony_ci const struct vk_physical_device_dispatch_table *dispatch_table) 34bf215546Sopenharmony_ci{ 35bf215546Sopenharmony_ci memset(pdevice, 0, sizeof(*pdevice)); 36bf215546Sopenharmony_ci vk_object_base_init(NULL, &pdevice->base, VK_OBJECT_TYPE_PHYSICAL_DEVICE); 37bf215546Sopenharmony_ci pdevice->instance = instance; 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci if (supported_extensions != NULL) 40bf215546Sopenharmony_ci pdevice->supported_extensions = *supported_extensions; 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci pdevice->dispatch_table = *dispatch_table; 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci /* Add common entrypoints without overwriting driver-provided ones. */ 45bf215546Sopenharmony_ci vk_physical_device_dispatch_table_from_entrypoints( 46bf215546Sopenharmony_ci &pdevice->dispatch_table, &vk_common_physical_device_entrypoints, false); 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci /* TODO */ 49bf215546Sopenharmony_ci pdevice->disk_cache = NULL; 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci return VK_SUCCESS; 52bf215546Sopenharmony_ci} 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_civoid 55bf215546Sopenharmony_civk_physical_device_finish(struct vk_physical_device *physical_device) 56bf215546Sopenharmony_ci{ 57bf215546Sopenharmony_ci vk_object_base_finish(&physical_device->base); 58bf215546Sopenharmony_ci} 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL 61bf215546Sopenharmony_civk_common_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, 62bf215546Sopenharmony_ci uint32_t *pPropertyCount, 63bf215546Sopenharmony_ci VkLayerProperties *pProperties) 64bf215546Sopenharmony_ci{ 65bf215546Sopenharmony_ci if (pProperties == NULL) { 66bf215546Sopenharmony_ci *pPropertyCount = 0; 67bf215546Sopenharmony_ci return VK_SUCCESS; 68bf215546Sopenharmony_ci } 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci /* None supported at this time */ 71bf215546Sopenharmony_ci return VK_ERROR_LAYER_NOT_PRESENT; 72bf215546Sopenharmony_ci} 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL 75bf215546Sopenharmony_civk_common_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, 76bf215546Sopenharmony_ci const char *pLayerName, 77bf215546Sopenharmony_ci uint32_t *pPropertyCount, 78bf215546Sopenharmony_ci VkExtensionProperties *pProperties) 79bf215546Sopenharmony_ci{ 80bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); 81bf215546Sopenharmony_ci VK_OUTARRAY_MAKE_TYPED(VkExtensionProperties, out, pProperties, pPropertyCount); 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci for (int i = 0; i < VK_DEVICE_EXTENSION_COUNT; i++) { 84bf215546Sopenharmony_ci if (!pdevice->supported_extensions.extensions[i]) 85bf215546Sopenharmony_ci continue; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci#ifdef ANDROID 88bf215546Sopenharmony_ci if (!vk_android_allowed_device_extensions.extensions[i]) 89bf215546Sopenharmony_ci continue; 90bf215546Sopenharmony_ci#endif 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci vk_outarray_append_typed(VkExtensionProperties, &out, prop) { 93bf215546Sopenharmony_ci *prop = vk_device_extensions[i]; 94bf215546Sopenharmony_ci } 95bf215546Sopenharmony_ci } 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci return vk_outarray_status(&out); 98bf215546Sopenharmony_ci} 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL 101bf215546Sopenharmony_civk_common_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, 102bf215546Sopenharmony_ci VkPhysicalDeviceFeatures *pFeatures) 103bf215546Sopenharmony_ci{ 104bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci /* Don't zero-init this struct since the driver fills it out entirely */ 107bf215546Sopenharmony_ci VkPhysicalDeviceFeatures2 features2; 108bf215546Sopenharmony_ci features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; 109bf215546Sopenharmony_ci features2.pNext = NULL; 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceFeatures2(physicalDevice, 112bf215546Sopenharmony_ci &features2); 113bf215546Sopenharmony_ci *pFeatures = features2.features; 114bf215546Sopenharmony_ci} 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL 117bf215546Sopenharmony_civk_common_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, 118bf215546Sopenharmony_ci VkPhysicalDeviceProperties *pProperties) 119bf215546Sopenharmony_ci{ 120bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci /* Don't zero-init this struct since the driver fills it out entirely */ 123bf215546Sopenharmony_ci VkPhysicalDeviceProperties2 props2; 124bf215546Sopenharmony_ci props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; 125bf215546Sopenharmony_ci props2.pNext = NULL; 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceProperties2(physicalDevice, 128bf215546Sopenharmony_ci &props2); 129bf215546Sopenharmony_ci *pProperties = props2.properties; 130bf215546Sopenharmony_ci} 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL 133bf215546Sopenharmony_civk_common_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, 134bf215546Sopenharmony_ci uint32_t *pQueueFamilyPropertyCount, 135bf215546Sopenharmony_ci VkQueueFamilyProperties *pQueueFamilyProperties) 136bf215546Sopenharmony_ci{ 137bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci if (!pQueueFamilyProperties) { 140bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceQueueFamilyProperties2(physicalDevice, 141bf215546Sopenharmony_ci pQueueFamilyPropertyCount, 142bf215546Sopenharmony_ci NULL); 143bf215546Sopenharmony_ci return; 144bf215546Sopenharmony_ci } 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci STACK_ARRAY(VkQueueFamilyProperties2, props2, *pQueueFamilyPropertyCount); 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci for (unsigned i = 0; i < *pQueueFamilyPropertyCount; ++i) { 149bf215546Sopenharmony_ci props2[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2; 150bf215546Sopenharmony_ci props2[i].pNext = NULL; 151bf215546Sopenharmony_ci } 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceQueueFamilyProperties2(physicalDevice, 154bf215546Sopenharmony_ci pQueueFamilyPropertyCount, 155bf215546Sopenharmony_ci props2); 156bf215546Sopenharmony_ci 157bf215546Sopenharmony_ci for (unsigned i = 0; i < *pQueueFamilyPropertyCount; ++i) 158bf215546Sopenharmony_ci pQueueFamilyProperties[i] = props2[i].queueFamilyProperties; 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci STACK_ARRAY_FINISH(props2); 161bf215546Sopenharmony_ci} 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL 164bf215546Sopenharmony_civk_common_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, 165bf215546Sopenharmony_ci VkPhysicalDeviceMemoryProperties *pMemoryProperties) 166bf215546Sopenharmony_ci{ 167bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci /* Don't zero-init this struct since the driver fills it out entirely */ 170bf215546Sopenharmony_ci VkPhysicalDeviceMemoryProperties2 props2; 171bf215546Sopenharmony_ci props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2; 172bf215546Sopenharmony_ci props2.pNext = NULL; 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceMemoryProperties2(physicalDevice, 175bf215546Sopenharmony_ci &props2); 176bf215546Sopenharmony_ci *pMemoryProperties = props2.memoryProperties; 177bf215546Sopenharmony_ci} 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL 180bf215546Sopenharmony_civk_common_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, 181bf215546Sopenharmony_ci VkFormat format, 182bf215546Sopenharmony_ci VkFormatProperties *pFormatProperties) 183bf215546Sopenharmony_ci{ 184bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci /* Don't zero-init this struct since the driver fills it out entirely */ 187bf215546Sopenharmony_ci VkFormatProperties2 props2; 188bf215546Sopenharmony_ci props2.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2; 189bf215546Sopenharmony_ci props2.pNext = NULL; 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceFormatProperties2(physicalDevice, 192bf215546Sopenharmony_ci format, &props2); 193bf215546Sopenharmony_ci *pFormatProperties = props2.formatProperties; 194bf215546Sopenharmony_ci} 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL 197bf215546Sopenharmony_civk_common_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, 198bf215546Sopenharmony_ci VkFormat format, 199bf215546Sopenharmony_ci VkImageType type, 200bf215546Sopenharmony_ci VkImageTiling tiling, 201bf215546Sopenharmony_ci VkImageUsageFlags usage, 202bf215546Sopenharmony_ci VkImageCreateFlags flags, 203bf215546Sopenharmony_ci VkImageFormatProperties *pImageFormatProperties) 204bf215546Sopenharmony_ci{ 205bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci VkPhysicalDeviceImageFormatInfo2 info = { 208bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, 209bf215546Sopenharmony_ci .format = format, 210bf215546Sopenharmony_ci .type = type, 211bf215546Sopenharmony_ci .tiling = tiling, 212bf215546Sopenharmony_ci .usage = usage, 213bf215546Sopenharmony_ci .flags = flags 214bf215546Sopenharmony_ci }; 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci /* Don't zero-init this struct since the driver fills it out entirely */ 217bf215546Sopenharmony_ci VkImageFormatProperties2 props2; 218bf215546Sopenharmony_ci props2.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2; 219bf215546Sopenharmony_ci props2.pNext = NULL; 220bf215546Sopenharmony_ci 221bf215546Sopenharmony_ci VkResult result = 222bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceImageFormatProperties2(physicalDevice, 223bf215546Sopenharmony_ci &info, &props2); 224bf215546Sopenharmony_ci *pImageFormatProperties = props2.imageFormatProperties; 225bf215546Sopenharmony_ci 226bf215546Sopenharmony_ci return result; 227bf215546Sopenharmony_ci} 228bf215546Sopenharmony_ci 229bf215546Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL 230bf215546Sopenharmony_civk_common_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, 231bf215546Sopenharmony_ci VkFormat format, 232bf215546Sopenharmony_ci VkImageType type, 233bf215546Sopenharmony_ci uint32_t samples, 234bf215546Sopenharmony_ci VkImageUsageFlags usage, 235bf215546Sopenharmony_ci VkImageTiling tiling, 236bf215546Sopenharmony_ci uint32_t *pNumProperties, 237bf215546Sopenharmony_ci VkSparseImageFormatProperties *pProperties) 238bf215546Sopenharmony_ci{ 239bf215546Sopenharmony_ci VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice); 240bf215546Sopenharmony_ci 241bf215546Sopenharmony_ci VkPhysicalDeviceSparseImageFormatInfo2 info = { 242bf215546Sopenharmony_ci .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, 243bf215546Sopenharmony_ci .format = format, 244bf215546Sopenharmony_ci .type = type, 245bf215546Sopenharmony_ci .samples = samples, 246bf215546Sopenharmony_ci .usage = usage, 247bf215546Sopenharmony_ci .tiling = tiling 248bf215546Sopenharmony_ci }; 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci if (!pProperties) { 251bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceSparseImageFormatProperties2(physicalDevice, 252bf215546Sopenharmony_ci &info, 253bf215546Sopenharmony_ci pNumProperties, 254bf215546Sopenharmony_ci NULL); 255bf215546Sopenharmony_ci return; 256bf215546Sopenharmony_ci } 257bf215546Sopenharmony_ci 258bf215546Sopenharmony_ci STACK_ARRAY(VkSparseImageFormatProperties2, props2, *pNumProperties); 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_ci for (unsigned i = 0; i < *pNumProperties; ++i) { 261bf215546Sopenharmony_ci props2[i].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2; 262bf215546Sopenharmony_ci props2[i].pNext = NULL; 263bf215546Sopenharmony_ci } 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ci pdevice->dispatch_table.GetPhysicalDeviceSparseImageFormatProperties2(physicalDevice, 266bf215546Sopenharmony_ci &info, 267bf215546Sopenharmony_ci pNumProperties, 268bf215546Sopenharmony_ci props2); 269bf215546Sopenharmony_ci 270bf215546Sopenharmony_ci for (unsigned i = 0; i < *pNumProperties; ++i) 271bf215546Sopenharmony_ci pProperties[i] = props2[i].properties; 272bf215546Sopenharmony_ci 273bf215546Sopenharmony_ci STACK_ARRAY_FINISH(props2); 274bf215546Sopenharmony_ci} 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_ci/* VK_EXT_tooling_info */ 277bf215546Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL 278bf215546Sopenharmony_civk_common_GetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, 279bf215546Sopenharmony_ci uint32_t *pToolCount, 280bf215546Sopenharmony_ci VkPhysicalDeviceToolProperties *pToolProperties) 281bf215546Sopenharmony_ci{ 282bf215546Sopenharmony_ci VK_OUTARRAY_MAKE_TYPED(VkPhysicalDeviceToolProperties, out, pToolProperties, pToolCount); 283bf215546Sopenharmony_ci 284bf215546Sopenharmony_ci return vk_outarray_status(&out); 285bf215546Sopenharmony_ci} 286