• 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 enum class ICD
24 {
25     Default,
26     Mock,
27     SwiftShader,
28 };
29 
30 struct SimpleDisplayWindow
31 {
32     uint16_t width;
33     uint16_t height;
34 };
35 
36 class ScopedVkLoaderEnvironment : angle::NonCopyable
37 {
38   public:
39     ScopedVkLoaderEnvironment(bool enableValidationLayers, vk::ICD icd);
40     ~ScopedVkLoaderEnvironment();
41 
canEnableValidationLayers()42     bool canEnableValidationLayers() const { return mEnableValidationLayers; }
getEnabledICD()43     vk::ICD getEnabledICD() const { return mICD; }
44 
45   private:
46     bool setICDEnvironment(const char *icd);
47     bool setCustomExtensionsEnvironment();
48 
49     bool mEnableValidationLayers;
50     vk::ICD mICD;
51     bool mChangedCWD;
52     Optional<std::string> mPreviousCWD;
53     bool mChangedICDEnv;
54     Optional<std::string> mPreviousICDEnv;
55     Optional<std::string> mPreviousCustomExtensionsEnv;
56 };
57 
58 void ChoosePhysicalDevice(const std::vector<VkPhysicalDevice> &physicalDevices,
59                           vk::ICD preferredICD,
60                           VkPhysicalDevice *physicalDeviceOut,
61                           VkPhysicalDeviceProperties *physicalDevicePropertiesOut);
62 
63 }  // namespace vk
64 
65 }  // namespace angle
66 
67 #endif  // COMMON_VULKAN_VULKAN_ICD_H_
68