1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "host/libs/graphics_detector/graphics_detector_vk.h" 18 19 #include <android-base/logging.h> 20 #include <android-base/strings.h> 21 22 #include "host/libs/graphics_detector/subprocess.h" 23 #include "host/libs/graphics_detector/vk.h" 24 25 namespace cuttlefish { 26 namespace { 27 PopulateVulkanAvailabilityImpl(GraphicsAvailability * availability)28vk::Result PopulateVulkanAvailabilityImpl(GraphicsAvailability* availability) { 29 auto vk = Vk::Load(); 30 if (!vk) { 31 LOG(ERROR) << "Failed to Vulkan library."; 32 return vk::Result::eErrorInitializationFailed; 33 } 34 LOG(VERBOSE) << "Loaded Vulkan library."; 35 availability->has_vulkan = true; 36 37 const auto physical_devices = 38 VK_EXPECT_RESULT(vk::raii::PhysicalDevices::create(vk->vk_instance)); 39 for (const auto& physical_device : physical_devices) { 40 const auto props = physical_device.getProperties(); 41 if (props.deviceType != vk::PhysicalDeviceType::eDiscreteGpu) { 42 continue; 43 } 44 45 const auto exts = physical_device.enumerateDeviceExtensionProperties(); 46 47 std::vector<std::string> exts_strs; 48 exts_strs.reserve(exts.size()); 49 for (const auto& ext : exts) { 50 exts_strs.push_back(std::string(ext.extensionName)); 51 } 52 53 availability->has_discrete_gpu = true; 54 availability->discrete_gpu_device_name = std::string(props.deviceName); 55 availability->discrete_gpu_device_extensions = 56 android::base::Join(exts_strs, ' '); 57 break; 58 } 59 60 return vk::Result::eSuccess; 61 } 62 63 } // namespace 64 PopulateVulkanAvailability(GraphicsAvailability * availability)65void PopulateVulkanAvailability(GraphicsAvailability* availability) { 66 DoWithSubprocessCheck("PopulateVulkanAvailability", [&]() { 67 PopulateVulkanAvailabilityImpl(availability); 68 }); 69 } 70 71 } // namespace cuttlefish 72