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 [[nodiscard]] 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 48 bool mEnableValidationLayers; 49 vk::ICD mICD; 50 bool mChangedCWD; 51 Optional<std::string> mPreviousCWD; 52 bool mChangedICDEnv; 53 Optional<std::string> mPreviousICDEnv; 54 Optional<std::string> mPreviousCustomExtensionsEnv; 55 bool mChangedNoDeviceSelect; 56 Optional<std::string> mPreviousNoDeviceSelectEnv; 57 }; 58 59 void ChoosePhysicalDevice(PFN_vkGetPhysicalDeviceProperties pGetPhysicalDeviceProperties, 60 const std::vector<VkPhysicalDevice> &physicalDevices, 61 vk::ICD preferredICD, 62 uint32_t preferredVendorID, 63 uint32_t preferredDeviceID, 64 VkPhysicalDevice *physicalDeviceOut, 65 VkPhysicalDeviceProperties *physicalDevicePropertiesOut); 66 67 } // namespace vk 68 69 } // namespace angle 70 71 #endif // COMMON_VULKAN_VULKAN_ICD_H_ 72