1 // Copyright 2020 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_VULKAN_VULKANEXTENSIONS_H_ 16 #define DAWNNATIVE_VULKAN_VULKANEXTENSIONS_H_ 17 18 #include "common/ityp_bitset.h" 19 20 #include <unordered_map> 21 22 namespace dawn_native { namespace vulkan { 23 24 // The list of known instance extensions. They must be in dependency order (this is checked 25 // inside EnsureDependencies) 26 enum class InstanceExt { 27 // Promoted to 1.1 28 GetPhysicalDeviceProperties2, 29 ExternalMemoryCapabilities, 30 ExternalSemaphoreCapabilities, 31 32 // Surface extensions 33 Surface, 34 FuchsiaImagePipeSurface, 35 MetalSurface, 36 WaylandSurface, 37 Win32Surface, 38 XcbSurface, 39 XlibSurface, 40 41 // Others 42 DebugUtils, 43 ValidationFeatures, 44 45 EnumCount, 46 }; 47 48 // A bitset that is indexed with InstanceExt. 49 using InstanceExtSet = ityp::bitset<InstanceExt, static_cast<uint32_t>(InstanceExt::EnumCount)>; 50 51 // Information about a known instance extension. 52 struct InstanceExtInfo { 53 InstanceExt index; 54 const char* name; 55 // The version in which this extension was promoted as built with VK_MAKE_VERSION, 56 // or NeverPromoted if it was never promoted. 57 uint32_t versionPromoted; 58 }; 59 60 // Returns the information about a known InstanceExt 61 const InstanceExtInfo& GetInstanceExtInfo(InstanceExt ext); 62 // Returns a map that maps a Vulkan extension name to its InstanceExt. 63 std::unordered_map<std::string, InstanceExt> CreateInstanceExtNameMap(); 64 65 // Sets entries in `extensions` to true if that entry was promoted in Vulkan version `version` 66 void MarkPromotedExtensions(InstanceExtSet* extensions, uint32_t version); 67 // From a set of extensions advertised as supported by the instance (or promoted), remove all 68 // extensions that don't have all their transitive dependencies in advertisedExts. 69 InstanceExtSet EnsureDependencies(const InstanceExtSet& advertisedExts); 70 71 // The list of known device extensions. They must be in dependency order (this is checked 72 // inside EnsureDependencies) 73 enum class DeviceExt { 74 // Promoted to 1.1 75 BindMemory2, 76 Maintenance1, 77 StorageBufferStorageClass, 78 GetPhysicalDeviceProperties2, 79 GetMemoryRequirements2, 80 ExternalMemoryCapabilities, 81 ExternalSemaphoreCapabilities, 82 ExternalMemory, 83 ExternalSemaphore, 84 _16BitStorage, 85 SamplerYCbCrConversion, 86 87 // Promoted to 1.2 88 DriverProperties, 89 ImageFormatList, 90 ShaderFloat16Int8, 91 92 // External* extensions 93 ExternalMemoryFD, 94 ExternalMemoryDmaBuf, 95 ExternalMemoryZirconHandle, 96 ExternalSemaphoreFD, 97 ExternalSemaphoreZirconHandle, 98 99 // Others 100 ImageDrmFormatModifier, 101 Swapchain, 102 SubgroupSizeControl, 103 104 EnumCount, 105 }; 106 107 // A bitset that is indexed with DeviceExt. 108 using DeviceExtSet = ityp::bitset<DeviceExt, static_cast<uint32_t>(DeviceExt::EnumCount)>; 109 110 // Information about a known device extension. 111 struct DeviceExtInfo { 112 DeviceExt index; 113 const char* name; 114 // The version in which this extension was promoted as built with VK_MAKE_VERSION, 115 // or NeverPromoted if it was never promoted. 116 uint32_t versionPromoted; 117 }; 118 119 // Returns the information about a known DeviceExt 120 const DeviceExtInfo& GetDeviceExtInfo(DeviceExt ext); 121 // Returns a map that maps a Vulkan extension name to its DeviceExt. 122 std::unordered_map<std::string, DeviceExt> CreateDeviceExtNameMap(); 123 124 // Sets entries in `extensions` to true if that entry was promoted in Vulkan version `version` 125 void MarkPromotedExtensions(DeviceExtSet* extensions, uint32_t version); 126 // From a set of extensions advertised as supported by the device (or promoted), remove all 127 // extensions that don't have all their transitive dependencies in advertisedExts or in 128 // instanceExts. 129 DeviceExtSet EnsureDependencies(const DeviceExtSet& advertisedExts, 130 const InstanceExtSet& instanceExts, 131 uint32_t icdVersion); 132 133 // The list of all known Vulkan layers. 134 enum class VulkanLayer { 135 Validation, 136 LunargVkTrace, 137 RenderDocCapture, 138 139 // Fuchsia implements the swapchain through a layer (VK_LAYER_FUCHSIA_image_pipe_swapchain), 140 // which adds an instance extensions (VK_FUCHSIA_image_surface) to all ICDs. 141 FuchsiaImagePipeSwapchain, 142 143 EnumCount, 144 }; 145 146 // A bitset that is indexed with VulkanLayer. 147 using VulkanLayerSet = ityp::bitset<VulkanLayer, static_cast<uint32_t>(VulkanLayer::EnumCount)>; 148 149 // Information about a known layer 150 struct VulkanLayerInfo { 151 VulkanLayer layer; 152 const char* name; 153 }; 154 155 // Returns the information about a known VulkanLayer 156 const VulkanLayerInfo& GetVulkanLayerInfo(VulkanLayer layer); 157 // Returns a map that maps a Vulkan layer name to its VulkanLayer. 158 std::unordered_map<std::string, VulkanLayer> CreateVulkanLayerNameMap(); 159 160 }} // namespace dawn_native::vulkan 161 162 #endif // DAWNNATIVE_VULKAN_VULKANEXTENSIONS_H_ 163