OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrVkExtensions_DEFINED | 8 #ifndef GrVkExtensions_DEFINED |
9 #define GrVkExtensions_DEFINED | 9 #define GrVkExtensions_DEFINED |
10 | 10 |
11 #include "../../private/SkTArray.h" | 11 #include "../../private/SkTArray.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "vulkan/vulkan.h" | 13 #include "vulkan/vulkan.h" |
14 | 14 |
15 /** | 15 /** |
16 * This helper queries the current Vulkan context for its extensions and layers,
remembers them, | 16 * This helper queries the Vulkan driver for available extensions and layers, re
members them, |
17 * and can be queried. It supports queries for both instance and device extensio
ns and layers. | 17 * and can be queried. It supports queries for both instance and device extensio
ns and layers. |
18 */ | 18 */ |
19 class SK_API GrVkExtensions { | 19 class SK_API GrVkExtensions { |
20 public: | 20 public: |
21 GrVkExtensions() : fInitialized(false) | 21 GrVkExtensions() : fInstanceExtensionStrings(new SkTArray<SkString>) |
22 , fInstanceExtensionStrings(new SkTArray<SkString>) | |
23 , fDeviceExtensionStrings(new SkTArray<SkString>) | 22 , fDeviceExtensionStrings(new SkTArray<SkString>) |
24 , fInstanceLayerStrings(new SkTArray<SkString>) | 23 , fInstanceLayerStrings(new SkTArray<SkString>) |
25 , fDeviceLayerStrings(new SkTArray<SkString>) {} | 24 , fDeviceLayerStrings(new SkTArray<SkString>) {} |
26 | 25 |
27 GrVkExtensions(const GrVkExtensions&); | 26 bool initInstance(uint32_t specVersion); |
28 | 27 bool initDevice(uint32_t specVersion, VkInstance, VkPhysicalDevice); |
29 GrVkExtensions& operator=(const GrVkExtensions&); | |
30 | |
31 void swap(GrVkExtensions* that) { | |
32 fInstanceExtensionStrings.swap(that->fInstanceExtensionStrings); | |
33 fDeviceExtensionStrings.swap(that->fDeviceExtensionStrings); | |
34 fInstanceLayerStrings.swap(that->fInstanceLayerStrings); | |
35 fDeviceLayerStrings.swap(that->fDeviceLayerStrings); | |
36 | |
37 SkTSwap(fInitialized, that->fInitialized); | |
38 } | |
39 | 28 |
40 /** | 29 /** |
41 * We sometimes need to use this class without having yet created a GrVkInte
rface. | 30 * Queries whether an extension or layer is present. Will fail if not initia
lized. |
42 */ | |
43 bool init(uint32_t specVersion, | |
44 VkPhysicalDevice physDev, | |
45 PFN_vkEnumerateInstanceExtensionProperties enumerateInstanceExtens
ionProperties, | |
46 PFN_vkEnumerateDeviceExtensionProperties enumerateDeviceExtensionP
roperties, | |
47 PFN_vkEnumerateInstanceLayerProperties enumerateInstanceLayerPrope
rties, | |
48 PFN_vkEnumerateDeviceLayerProperties enumerateDeviceLayerPropertie
s); | |
49 | |
50 bool isInitialized() const { return fInitialized; } | |
51 | |
52 /** | |
53 * Queries whether an extension or layer is present. Will fail if init() has
not been called. | |
54 */ | 31 */ |
55 bool hasInstanceExtension(const char[]) const; | 32 bool hasInstanceExtension(const char[]) const; |
56 bool hasDeviceExtension(const char[]) const; | 33 bool hasDeviceExtension(const char[]) const; |
57 bool hasInstanceLayer(const char[]) const; | 34 bool hasInstanceLayer(const char[]) const; |
58 bool hasDeviceLayer(const char[]) const; | 35 bool hasDeviceLayer(const char[]) const; |
59 | 36 |
60 /** | |
61 * Removes an extension or layer if present. Returns true if it was present
before the call. | |
62 */ | |
63 bool removeInstanceExtension(const char[]); | |
64 bool removeDeviceExtension(const char[]); | |
65 bool removeInstanceLayer(const char[]); | |
66 bool removeDeviceLayer(const char[]); | |
67 | |
68 /** | |
69 * Adds an extension or layer to list | |
70 */ | |
71 void addInstanceExtension(const char[]); | |
72 void addDeviceExtension(const char[]); | |
73 void addInstanceLayer(const char[]); | |
74 void addDeviceLayer(const char[]); | |
75 | |
76 void reset() { | |
77 fInstanceExtensionStrings->reset(); | |
78 fDeviceExtensionStrings->reset(); | |
79 fInstanceLayerStrings->reset(); | |
80 fDeviceLayerStrings->reset(); | |
81 } | |
82 | |
83 void print(const char* sep = "\n") const; | 37 void print(const char* sep = "\n") const; |
84 | 38 |
85 private: | 39 private: |
86 bool fInitialized; | |
87 SkAutoTDelete<SkTArray<SkString> > fInstanceExtensionStrings; | 40 SkAutoTDelete<SkTArray<SkString> > fInstanceExtensionStrings; |
88 SkAutoTDelete<SkTArray<SkString> > fDeviceExtensionStrings; | 41 SkAutoTDelete<SkTArray<SkString> > fDeviceExtensionStrings; |
89 SkAutoTDelete<SkTArray<SkString> > fInstanceLayerStrings; | 42 SkAutoTDelete<SkTArray<SkString> > fInstanceLayerStrings; |
90 SkAutoTDelete<SkTArray<SkString> > fDeviceLayerStrings; | 43 SkAutoTDelete<SkTArray<SkString> > fDeviceLayerStrings; |
91 }; | 44 }; |
92 | 45 |
93 #endif | 46 #endif |
OLD | NEW |