• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef skgpu_VulkanExtensions_DEFINED
9 #define skgpu_VulkanExtensions_DEFINED
10 
11 #include "include/core/SkString.h"
12 #include "include/gpu/vk/VulkanTypes.h"
13 #include "include/private/base/SkTArray.h"
14 
15 namespace skgpu {
16 
17 /**
18  * Helper class that eats in an array of extensions strings for instance and device and allows for
19  * quicker querying if an extension is present.
20  */
21 class SK_API VulkanExtensions {
22 public:
VulkanExtensions()23     VulkanExtensions() {}
24 
25     void init(VulkanGetProc, VkInstance, VkPhysicalDevice,
26               uint32_t instanceExtensionCount, const char* const* instanceExtensions,
27               uint32_t deviceExtensionCount, const char* const* deviceExtensions);
28 
29     bool hasExtension(const char[], uint32_t minVersion) const;
30 
31     struct Info {
InfoInfo32         Info() {}
InfoInfo33         Info(const char* name) : fName(name), fSpecVersion(0) {}
34 
35         SkString fName;
36         uint32_t fSpecVersion;
37 
38         struct Less {
operatorInfo::Less39             bool operator()(const Info& a, const SkString& b) const {
40                 return strcmp(a.fName.c_str(), b.c_str()) < 0;
41             }
operatorInfo::Less42             bool operator()(const SkString& a, const VulkanExtensions::Info& b) const {
43                 return strcmp(a.c_str(), b.fName.c_str()) < 0;
44             }
45         };
46     };
47 
48 #ifdef SK_DEBUG
dump()49     void dump() const {
50         SkDebugf("**Vulkan Extensions**\n");
51         for (int i = 0; i < fExtensions.size(); ++i) {
52             SkDebugf("%s. Version: %d\n",
53                      fExtensions[i].fName.c_str(), fExtensions[i].fSpecVersion);
54         }
55         SkDebugf("**End Vulkan Extensions**\n");
56     }
57 #endif
58 
59 private:
60     void getSpecVersions(VulkanGetProc getProc, VkInstance, VkPhysicalDevice);
61 
62     SkTArray<Info> fExtensions;
63 };
64 
65 } // namespace skgpu
66 
67 #endif // skgpu_VulkanExtensions_DEFINED
68