| 990 | } |
| 991 | |
| 992 | GPUDevice* GPUDeviceVulkan::Create() |
| 993 | { |
| 994 | #if !USE_EDITOR && (PLATFORM_WINDOWS || PLATFORM_LINUX) |
| 995 | auto settings = PlatformSettings::Get(); |
| 996 | if (!settings->SupportVulkan) |
| 997 | { |
| 998 | // Skip if there is no support |
| 999 | LOG(Warning, "Cannot use Vulkan (support disabled)."); |
| 1000 | return nullptr; |
| 1001 | } |
| 1002 | #endif |
| 1003 | |
| 1004 | VkResult result; |
| 1005 | |
| 1006 | #if !PLATFORM_SWITCH |
| 1007 | // Initialize bindings |
| 1008 | result = volkInitialize(); |
| 1009 | if (result != VK_SUCCESS) |
| 1010 | { |
| 1011 | LOG(Warning, "Graphics Device init failed with error {0}", RenderToolsVulkan::GetVkErrorString(result)); |
| 1012 | return nullptr; |
| 1013 | } |
| 1014 | #endif |
| 1015 | |
| 1016 | // Engine registration |
| 1017 | const StringAsANSI<> appName(*Globals::ProductName); |
| 1018 | VkApplicationInfo appInfo; |
| 1019 | RenderToolsVulkan::ZeroStruct(appInfo, VK_STRUCTURE_TYPE_APPLICATION_INFO); |
| 1020 | appInfo.pApplicationName = appName.Get(); |
| 1021 | appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); |
| 1022 | appInfo.pEngineName = "Flax"; |
| 1023 | appInfo.engineVersion = VK_MAKE_VERSION(FLAXENGINE_VERSION_MAJOR, FLAXENGINE_VERSION_MINOR, FLAXENGINE_VERSION_BUILD); |
| 1024 | appInfo.apiVersion = VULKAN_API_VERSION; |
| 1025 | |
| 1026 | VkInstanceCreateInfo instInfo; |
| 1027 | RenderToolsVulkan::ZeroStruct(instInfo, VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO); |
| 1028 | #if PLATFORM_APPLE_FAMILY |
| 1029 | instInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; |
| 1030 | #endif |
| 1031 | instInfo.pApplicationInfo = &appInfo; |
| 1032 | GetInstanceLayersAndExtensions(InstanceExtensions, InstanceLayers, SupportsDebugUtilsExt); |
| 1033 | instInfo.enabledExtensionCount = InstanceExtensions.Count(); |
| 1034 | instInfo.ppEnabledExtensionNames = instInfo.enabledExtensionCount > 0 ? static_cast<const char* const*>(InstanceExtensions.Get()) : nullptr; |
| 1035 | instInfo.enabledLayerCount = InstanceLayers.Count(); |
| 1036 | instInfo.ppEnabledLayerNames = instInfo.enabledLayerCount > 0 ? InstanceLayers.Get() : nullptr; |
| 1037 | #if VULKAN_USE_DEBUG_LAYER |
| 1038 | SupportsDebugCallbackExt = !SupportsDebugUtilsExt && RenderToolsVulkan::HasExtension(InstanceExtensions, VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
| 1039 | #endif |
| 1040 | |
| 1041 | // Create Vulkan instance |
| 1042 | result = vkCreateInstance(&instInfo, nullptr, &Instance); |
| 1043 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) |
| 1044 | { |
| 1045 | // Missing driver |
| 1046 | #if PLATFORM_APPLE_FAMILY |
| 1047 | Platform::Fatal(TEXT("Cannot find a compatible Metal driver.")); |
| 1048 | #else |
| 1049 | Platform::Fatal(TEXT("Cannot find a compatible Vulkan driver.")); |
nothing calls this directly
no test coverage detected