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 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 bool mChangedNoDeviceSelect; 57 Optional<std::string> mPreviousNoDeviceSelectEnv; 58 }; 59 60 void ChoosePhysicalDevice(PFN_vkGetPhysicalDeviceProperties pGetPhysicalDeviceProperties, 61 const std::vector<VkPhysicalDevice> &physicalDevices, 62 vk::ICD preferredICD, 63 uint32_t preferredVendorID, 64 uint32_t preferredDeviceID, 65 VkPhysicalDevice *physicalDeviceOut, 66 VkPhysicalDeviceProperties *physicalDevicePropertiesOut); 67 68 } // namespace vk 69 70 } // namespace angle 71 72 #endif // COMMON_VULKAN_VULKAN_ICD_H_ 73