• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // vulkan_icd.h : Helper for creating vulkan instances & selecting physical device.
7 
8 #ifndef COMMON_VULKAN_VULKAN_ICD_H_
9 #define COMMON_VULKAN_VULKAN_ICD_H_
10 
11 #include <string>
12 
13 #include "common/Optional.h"
14 #include "common/angleutils.h"
15 #include "common/vulkan/vk_headers.h"
16 
17 namespace angle
18 {
19 
20 namespace vk
21 {
22 
23 // The minimum version of Vulkan that ANGLE requires.  If an instance or device below this version
24 // is encountered, initialization will skip the device if possible, or if no other suitable device
25 // is available then initialization will fail.
26 constexpr uint32_t kMinimumVulkanAPIVersion = VK_API_VERSION_1_1;
27 
28 enum class ICD
29 {
30     Default,
31     Mock,
32     SwiftShader,
33 };
34 
35 struct SimpleDisplayWindow
36 {
37     uint16_t width;
38     uint16_t height;
39 };
40 
41 class [[nodiscard]] ScopedVkLoaderEnvironment : angle::NonCopyable
42 {
43   public:
44     ScopedVkLoaderEnvironment(bool enableDebugLayers, vk::ICD icd);
45     ~ScopedVkLoaderEnvironment();
46 
canEnableDebugLayers()47     bool canEnableDebugLayers() const { return mEnableDebugLayers; }
getEnabledICD()48     vk::ICD getEnabledICD() const { return mICD; }
49 
50   private:
51     bool setICDEnvironment(const char *icd);
52 
53     bool mEnableDebugLayers;
54     vk::ICD mICD;
55     bool mChangedCWD;
56     Optional<std::string> mPreviousCWD;
57     bool mChangedICDEnv;
58     Optional<std::string> mPreviousICDEnv;
59     Optional<std::string> mPreviousCustomExtensionsEnv;
60     bool mChangedNoDeviceSelect;
61     Optional<std::string> mPreviousNoDeviceSelectEnv;
62 };
63 
64 void ChoosePhysicalDevice(PFN_vkGetPhysicalDeviceProperties2 pGetPhysicalDeviceProperties2,
65                           const std::vector<VkPhysicalDevice> &physicalDevices,
66                           vk::ICD preferredICD,
67                           uint32_t preferredVendorID,
68                           uint32_t preferredDeviceID,
69                           const uint8_t *preferredDeviceUUID,
70                           const uint8_t *preferredDriverUUID,
71                           VkDriverId preferredDriverID,
72                           VkPhysicalDevice *physicalDeviceOut,
73                           VkPhysicalDeviceProperties2 *physicalDeviceProperties2Out,
74                           VkPhysicalDeviceIDProperties *physicalDeviceIDPropertiesOut,
75                           VkPhysicalDeviceDriverProperties *physicalDeviceDriverPropertiesOut);
76 
77 }  // namespace vk
78 
79 }  // namespace angle
80 
81 #endif  // COMMON_VULKAN_VULKAN_ICD_H_
82