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 <bitset>
19 #include <unordered_map>
20 
21 namespace dawn_native { namespace vulkan {
22 
23     // The list of known instance extensions. They must be in dependency order (this is checked
24     // inside EnsureDependencies)
25     enum class InstanceExt {
26         // Promoted to 1.1
27         GetPhysicalDeviceProperties2,
28         ExternalMemoryCapabilities,
29         ExternalSemaphoreCapabilities,
30 
31         // Surface extensions
32         Surface,
33         FuchsiaImagePipeSurface,
34         MetalSurface,
35         WaylandSurface,
36         Win32Surface,
37         XcbSurface,
38         XlibSurface,
39 
40         // Others
41         DebugReport,
42 
43         EnumCount,
44     };
45 
46     // A bitset wrapper that is indexed with InstanceExt.
47     struct InstanceExtSet {
48         std::bitset<static_cast<size_t>(InstanceExt::EnumCount)> extensionBitSet;
49         void Set(InstanceExt extension, bool enabled);
50         bool Has(InstanceExt extension) const;
51     };
52 
53     // Information about a known instance extension.
54     struct InstanceExtInfo {
55         InstanceExt index;
56         const char* name;
57         // The version in which this extension was promoted as built with VK_MAKE_VERSION,
58         // or NeverPromoted if it was never promoted.
59         uint32_t versionPromoted;
60     };
61 
62     // Returns the information about a known InstanceExt
63     const InstanceExtInfo& GetInstanceExtInfo(InstanceExt ext);
64     // Returns a map that maps a Vulkan extension name to its InstanceExt.
65     std::unordered_map<std::string, InstanceExt> CreateInstanceExtNameMap();
66 
67     // Sets entries in `extensions` to true if that entry was promoted in Vulkan version `version`
68     void MarkPromotedExtensions(InstanceExtSet* extensions, uint32_t version);
69     // From a set of extensions advertised as supported by the instance (or promoted), remove all
70     // extensions that don't have all their transitive dependencies in advertisedExts.
71     InstanceExtSet EnsureDependencies(const InstanceExtSet& advertisedExts);
72 
73     // The list of known device extensions. They must be in dependency order (this is checked
74     // inside EnsureDependencies)
75     enum class DeviceExt {
76         // Promoted to 1.1
77         BindMemory2,
78         Maintenance1,
79         StorageBufferStorageClass,
80         GetPhysicalDeviceProperties2,
81         GetMemoryRequirements2,
82         ExternalMemoryCapabilities,
83         ExternalSemaphoreCapabilities,
84         ExternalMemory,
85         ExternalSemaphore,
86         _16BitStorage,
87         SamplerYCbCrConversion,
88 
89         // Promoted to 1.2
90         DriverProperties,
91         ImageFormatList,
92         ShaderFloat16Int8,
93 
94         // External* extensions
95         ExternalMemoryFD,
96         ExternalMemoryDmaBuf,
97         ExternalMemoryZirconHandle,
98         ExternalSemaphoreFD,
99         ExternalSemaphoreZirconHandle,
100 
101         // Others
102         DebugMarker,
103         ImageDrmFormatModifier,
104         Swapchain,
105         SubgroupSizeControl,
106 
107         EnumCount,
108     };
109 
110     // A bitset wrapper that is indexed with DeviceExt.
111     struct DeviceExtSet {
112         std::bitset<static_cast<size_t>(DeviceExt::EnumCount)> extensionBitSet;
113         void Set(DeviceExt extension, bool enabled);
114         bool Has(DeviceExt extension) const;
115     };
116 
117     // A bitset wrapper that is indexed with DeviceExt.
118     struct DeviceExtInfo {
119         DeviceExt index;
120         const char* name;
121         // The version in which this extension was promoted as built with VK_MAKE_VERSION,
122         // or NeverPromoted if it was never promoted.
123         uint32_t versionPromoted;
124     };
125 
126     // Returns the information about a known DeviceExt
127     const DeviceExtInfo& GetDeviceExtInfo(DeviceExt ext);
128     // Returns a map that maps a Vulkan extension name to its DeviceExt.
129     std::unordered_map<std::string, DeviceExt> CreateDeviceExtNameMap();
130 
131     // Sets entries in `extensions` to true if that entry was promoted in Vulkan version `version`
132     void MarkPromotedExtensions(DeviceExtSet* extensions, uint32_t version);
133     // From a set of extensions advertised as supported by the device (or promoted), remove all
134     // extensions that don't have all their transitive dependencies in advertisedExts or in
135     // instanceExts.
136     DeviceExtSet EnsureDependencies(const DeviceExtSet& advertisedExts,
137                                     const InstanceExtSet& instanceExts,
138                                     uint32_t icdVersion);
139 
140 }}  // namespace dawn_native::vulkan
141 
142 #endif  // DAWNNATIVE_VULKAN_VULKANEXTENSIONS_H_
143