• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GraphicsDetectorVk.h"
18 
19 #include "Vulkan.h"
20 
21 namespace gfxstream {
22 namespace {
23 
PopulateVulkanAvailabilityImpl(::gfxstream::proto::GraphicsAvailability * availability)24 gfxstream::expected<Ok, vkhpp::Result> PopulateVulkanAvailabilityImpl(
25         ::gfxstream::proto::GraphicsAvailability* availability) {
26     auto vk = GFXSTREAM_EXPECT(Vk::Load());
27 
28     ::gfxstream::proto::VulkanAvailability* vulkanAvailability = availability->mutable_vulkan();
29 
30     const auto physicalDevices = VK_EXPECT_RV(vk.instance().enumeratePhysicalDevices());
31     for (const auto& physicalDevice : physicalDevices) {
32         auto* outPhysicalDevice = vulkanAvailability->add_physical_devices();
33 
34         const auto props = physicalDevice.getProperties();
35         outPhysicalDevice->set_name(std::string(props.deviceName));
36         outPhysicalDevice->set_type(
37             props.deviceType == vkhpp::PhysicalDeviceType::eDiscreteGpu ?
38                 ::gfxstream::proto::VulkanPhysicalDevice::TYPE_DISCRETE_GPU :
39                 ::gfxstream::proto::VulkanPhysicalDevice::TYPE_OTHER);
40 
41         const auto exts = VK_EXPECT_RV(physicalDevice.enumerateDeviceExtensionProperties());
42         for (const auto& ext : exts) {
43             outPhysicalDevice->add_extensions(std::string(ext.extensionName));
44         }
45     }
46 
47     return Ok{};
48 }
49 
50 }  // namespace
51 
PopulateVulkanAvailability(::gfxstream::proto::GraphicsAvailability * availability)52 gfxstream::expected<Ok, std::string> PopulateVulkanAvailability(
53         ::gfxstream::proto::GraphicsAvailability* availability) {
54     return PopulateVulkanAvailabilityImpl(availability)
55         .transform_error([](vkhpp::Result r) { return vkhpp::to_string(r); });
56 }
57 
58 }  // namespace gfxstream
59