Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: src/gpu/vk/GrVkExtensions.cpp

Issue 1785813002: Enable extension support and debug layer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes for line endings and versioning Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkExtensions.h ('k') | src/gpu/vk/GrVkGpu.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
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 #include "vk/GrVkExtensions.h"
9 #include "vk/GrVkUtil.h"
10
11 #include "SkTSearch.h"
12 #include "SkTSort.h"
13
14 namespace { // This cannot be static because it is used as a template parameter.
15 inline bool extension_compare(const SkString& a, const SkString& b) {
16 return strcmp(a.c_str(), b.c_str()) < 0;
17 }
18 }
19
20 // finds the index of ext in strings or a negative result if ext is not found.
21 static int find_string(const SkTArray<SkString>& strings, const char ext[]) {
22 if (strings.empty()) {
23 return -1;
24 }
25 SkString extensionStr(ext);
26 int idx = SkTSearch<SkString, extension_compare>(&strings.front(),
27 strings.count(),
28 extensionStr,
29 sizeof(SkString));
30 return idx;
31 }
32
33 GrVkExtensions::GrVkExtensions(const GrVkExtensions& that)
34 : fInstanceExtensionStrings(new SkTArray<SkString>)
35 , fDeviceExtensionStrings(new SkTArray<SkString>)
36 , fInstanceLayerStrings(new SkTArray<SkString>)
37 , fDeviceLayerStrings(new SkTArray<SkString>) {
38 *this = that;
39 }
40
41 GrVkExtensions& GrVkExtensions::operator=(const GrVkExtensions& that) {
42 *fInstanceExtensionStrings = *that.fInstanceExtensionStrings;
43 *fDeviceExtensionStrings = *that.fDeviceExtensionStrings;
44 *fInstanceLayerStrings = *that.fInstanceLayerStrings;
45 *fDeviceLayerStrings = *that.fDeviceLayerStrings;
46
47 fInitialized = that.fInitialized;
48 return *this;
49 }
50
51 bool GrVkExtensions::init(
52 uint32_t specVersion,
53 PFN_vkEnumerateInstanceExtensionProperties enumerateInstanceExtensionPropert ies,
54 PFN_vkEnumerateDeviceExtensionProperties enumerateDeviceExtensionProperties,
55 PFN_vkEnumerateInstanceLayerProperties enumerateInstanceLayerProperties,
56 PFN_vkEnumerateDeviceLayerProperties enumerateDeviceLayerProperties) {
57 fInitialized = false;
58 this->reset();
59
60 if (!enumerateInstanceExtensionProperties ||
61 !enumerateDeviceExtensionProperties ||
62 !enumerateInstanceLayerProperties ||
63 !enumerateDeviceLayerProperties) {
64 return false;
65 }
66
67 // instance extensions
68 uint32_t extensionCount = 0;
69 VkResult res = enumerateInstanceExtensionProperties(nullptr, &extensionCount , nullptr);
70
71 VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount ];
72 res = enumerateInstanceExtensionProperties(nullptr, &extensionCount, extensi ons);
73
74 fInstanceExtensionStrings->push_back_n(extensionCount);
75 for (uint32_t i = 0; i < extensionCount; ++i) {
76 if (specVersion >= extensions[i].specVersion) {
77 (*fInstanceExtensionStrings)[i] = extensions[i].extensionName;
78 }
79 }
80 delete [] extensions;
81
82 if (!fInstanceExtensionStrings->empty()) {
83 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
84 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensionStrings ->back(), cmp);
85 }
86
87 fInitialized = true;
88 return true;
89 }
90
91
92 bool GrVkExtensions::hasInstanceExtension(const char ext[]) const {
93 SkASSERT(fInitialized);
94
95 return find_string(*fInstanceExtensionStrings, ext) >= 0;
96 }
97
98 bool GrVkExtensions::hasDeviceExtension(const char ext[]) const {
99 SkASSERT(fInitialized);
100
101 return find_string(*fDeviceExtensionStrings, ext) >= 0;
102 }
103
104 bool GrVkExtensions::hasInstanceLayer(const char ext[]) const {
105 SkASSERT(fInitialized);
106
107 return find_string(*fInstanceLayerStrings, ext) >= 0;
108 }
109
110 bool GrVkExtensions::hasDeviceLayer(const char ext[]) const {
111 SkASSERT(fInitialized);
112
113 return find_string(*fDeviceLayerStrings, ext) >= 0;
114 }
115
116
117 bool GrVkExtensions::removeInstanceExtension(const char ext[]) {
118 SkASSERT(fInitialized);
119 int idx = find_string(*fInstanceExtensionStrings, ext);
120 if (idx >= 0) {
121 // This is not terribly effecient but we really only expect this functio n to be called at
122 // most a handful of times when our test programs start.
123 SkAutoTDelete< SkTArray<SkString> > oldStrings(fInstanceExtensionStrings .release());
124 fInstanceExtensionStrings.reset(new SkTArray<SkString>(oldStrings->count () - 1));
125 fInstanceExtensionStrings->push_back_n(idx, &oldStrings->front());
126 fInstanceExtensionStrings->push_back_n(oldStrings->count() - idx-1, &(*o ldStrings)[idx]+1);
127 return true;
128 } else {
129 return false;
130 }
131 }
132
133 bool GrVkExtensions::removeDeviceExtension(const char ext[]) {
134 SkASSERT(fInitialized);
135 int idx = find_string(*fDeviceExtensionStrings, ext);
136 if (idx >= 0) {
137 // This is not terribly effecient but we really only expect this functio n to be called at
138 // most a handful of times when our test programs start.
139 SkAutoTDelete< SkTArray<SkString> > oldStrings(fDeviceExtensionStrings.r elease());
140 fDeviceExtensionStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1));
141 fDeviceExtensionStrings->push_back_n(idx, &oldStrings->front());
142 fDeviceExtensionStrings->push_back_n(oldStrings->count() - idx-1, &(*old Strings)[idx] + 1);
143 return true;
144 }
145 else {
146 return false;
147 }
148 }
149
150 bool GrVkExtensions::removeInstanceLayer(const char ext[]) {
151 SkASSERT(fInitialized);
152 int idx = find_string(*fInstanceLayerStrings, ext);
153 if (idx >= 0) {
154 // This is not terribly effecient but we really only expect this functio n to be called at
155 // most a handful of times when our test programs start.
156 SkAutoTDelete< SkTArray<SkString> > oldStrings(fInstanceLayerStrings.rel ease());
157 fInstanceLayerStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1));
158 fInstanceLayerStrings->push_back_n(idx, &oldStrings->front());
159 fInstanceLayerStrings->push_back_n(oldStrings->count() - idx - 1, &(*old Strings)[idx] + 1);
160 return true;
161 }
162 else {
163 return false;
164 }
165 }
166
167 bool GrVkExtensions::removeDeviceLayer(const char ext[]) {
168 SkASSERT(fInitialized);
169 int idx = find_string(*fDeviceLayerStrings, ext);
170 if (idx >= 0) {
171 // This is not terribly effecient but we really only expect this functio n to be called at
172 // most a handful of times when our test programs start.
173 SkAutoTDelete< SkTArray<SkString> > oldStrings(fDeviceLayerStrings.relea se());
174 fDeviceLayerStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1 ));
175 fDeviceLayerStrings->push_back_n(idx, &oldStrings->front());
176 fDeviceLayerStrings->push_back_n(oldStrings->count() - idx - 1, &(*oldSt rings)[idx] + 1);
177 return true;
178 }
179 else {
180 return false;
181 }
182 }
183
184 void GrVkExtensions::addInstanceExtension(const char ext[]) {
185 int idx = find_string(*fInstanceExtensionStrings, ext);
186 if (idx < 0) {
187 // This is not the most effecient approach since we end up doing a full sort of the
188 // extensions after the add
189 fInstanceExtensionStrings->push_back().set(ext);
190 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
191 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensionStrings ->back(), cmp);
192 }
193 }
194
195 void GrVkExtensions::addDeviceExtension(const char ext[]) {
196 int idx = find_string(*fDeviceExtensionStrings, ext);
197 if (idx < 0) {
198 // This is not the most effecient approach since we end up doing a full sort of the
199 // extensions after the add
200 fDeviceExtensionStrings->push_back().set(ext);
201 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
202 SkTQSort(&fDeviceExtensionStrings->front(), &fDeviceExtensionStrings->ba ck(), cmp);
203 }
204 }
205
206 void GrVkExtensions::addInstanceLayer(const char ext[]) {
207 int idx = find_string(*fInstanceLayerStrings, ext);
208 if (idx < 0) {
209 // This is not the most effecient approach since we end up doing a full sort of the
210 // extensions after the add
211 fInstanceLayerStrings->push_back().set(ext);
212 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
213 SkTQSort(&fInstanceLayerStrings->front(), &fInstanceLayerStrings->back() , cmp);
214 }
215 }
216
217 void GrVkExtensions::addDeviceLayer(const char ext[]) {
218 int idx = find_string(*fDeviceLayerStrings, ext);
219 if (idx < 0) {
220 // This is not the most effecient approach since we end up doing a full sort of the
221 // extensions after the add
222 fDeviceLayerStrings->push_back().set(ext);
223 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
224 SkTQSort(&fDeviceLayerStrings->front(), &fDeviceLayerStrings->back(), cm p);
225 }
226 }
227
228 void GrVkExtensions::print(const char* sep) const {
229 if (nullptr == sep) {
230 sep = " ";
231 }
232 int cnt = fInstanceExtensionStrings->count();
233 SkDebugf("Instance Extensions: ");
234 for (int i = 0; i < cnt; ++i) {
235 SkDebugf("%s%s", (*fInstanceExtensionStrings)[i].c_str(), (i < cnt - 1) ? sep : "");
236 }
237 cnt = fDeviceExtensionStrings->count();
238 SkDebugf("\nDevice Extensions: ");
239 for (int i = 0; i < cnt; ++i) {
240 SkDebugf("%s%s", (*fDeviceExtensionStrings)[i].c_str(), (i < cnt - 1) ? sep : "");
241 }
242 cnt = fInstanceLayerStrings->count();
243 SkDebugf("\nInstance Layers: ");
244 for (int i = 0; i < cnt; ++i) {
245 SkDebugf("%s%s", (*fInstanceLayerStrings)[i].c_str(), (i < cnt - 1) ? se p : "");
246 }
247 cnt = fDeviceLayerStrings->count();
248 SkDebugf("\nDevice Layers: ");
249 for (int i = 0; i < cnt; ++i) {
250 SkDebugf("%s%s", (*fDeviceLayerStrings)[i].c_str(), (i < cnt - 1) ? sep : "");
251 }
252 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkExtensions.h ('k') | src/gpu/vk/GrVkGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698