Chromium Code Reviews| 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 #include "vk/GrVkExtensions.h" | 8 #include "vk/GrVkExtensions.h" |
| 9 #include "vk/GrVkUtil.h" | 9 #include "vk/GrVkUtil.h" |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 *fDeviceExtensionStrings = *that.fDeviceExtensionStrings; | 43 *fDeviceExtensionStrings = *that.fDeviceExtensionStrings; |
| 44 *fInstanceLayerStrings = *that.fInstanceLayerStrings; | 44 *fInstanceLayerStrings = *that.fInstanceLayerStrings; |
| 45 *fDeviceLayerStrings = *that.fDeviceLayerStrings; | 45 *fDeviceLayerStrings = *that.fDeviceLayerStrings; |
| 46 | 46 |
| 47 fInitialized = that.fInitialized; | 47 fInitialized = that.fInitialized; |
| 48 return *this; | 48 return *this; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool GrVkExtensions::init( | 51 bool GrVkExtensions::init( |
| 52 uint32_t specVersion, | 52 uint32_t specVersion, |
| 53 VkPhysicalDevice physDev, | |
| 53 PFN_vkEnumerateInstanceExtensionProperties enumerateInstanceExtensionPropert ies, | 54 PFN_vkEnumerateInstanceExtensionProperties enumerateInstanceExtensionPropert ies, |
| 54 PFN_vkEnumerateDeviceExtensionProperties enumerateDeviceExtensionProperties, | 55 PFN_vkEnumerateDeviceExtensionProperties enumerateDeviceExtensionProperties, |
| 55 PFN_vkEnumerateInstanceLayerProperties enumerateInstanceLayerProperties, | 56 PFN_vkEnumerateInstanceLayerProperties enumerateInstanceLayerProperties, |
| 56 PFN_vkEnumerateDeviceLayerProperties enumerateDeviceLayerProperties) { | 57 PFN_vkEnumerateDeviceLayerProperties enumerateDeviceLayerProperties) { |
| 57 fInitialized = false; | 58 fInitialized = false; |
| 58 this->reset(); | 59 this->reset(); |
| 60 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; | |
| 59 | 61 |
| 60 if (!enumerateInstanceExtensionProperties || | 62 if (!enumerateInstanceExtensionProperties || |
| 61 !enumerateDeviceExtensionProperties || | 63 !enumerateDeviceExtensionProperties || |
| 62 !enumerateInstanceLayerProperties || | 64 !enumerateInstanceLayerProperties || |
| 63 !enumerateDeviceLayerProperties) { | 65 !enumerateDeviceLayerProperties) { |
| 64 return false; | 66 return false; |
| 65 } | 67 } |
| 66 | 68 |
| 69 // instance layers | |
|
egdaniel
2016/03/23 14:51:57
So most of all this work here will actually be del
jvanverth1
2016/03/23 15:44:13
Yes, and I'll be using a version of it in the defa
| |
| 70 uint32_t layerCount = 0; | |
| 71 VkResult res = enumerateInstanceLayerProperties(&layerCount, nullptr); | |
| 72 if (VK_SUCCESS != res) { | |
| 73 return false; | |
| 74 } | |
| 75 VkLayerProperties* layers = new VkLayerProperties[layerCount]; | |
| 76 res = enumerateInstanceLayerProperties(&layerCount, layers); | |
| 77 if (VK_SUCCESS != res) { | |
| 78 return false; | |
| 79 } | |
| 80 for (uint32_t i = 0; i < layerCount; ++i) { | |
| 81 if (specVersion >= layers[i].specVersion) { | |
| 82 fInstanceLayerStrings->push_back() = layers[i].layerName; | |
| 83 } | |
| 84 } | |
| 85 delete[] layers; | |
| 86 if (!fInstanceLayerStrings->empty()) { | |
| 87 SkTQSort(&fInstanceLayerStrings->front(), &fInstanceLayerStrings->back() , cmp); | |
| 88 } | |
| 89 | |
| 67 // instance extensions | 90 // instance extensions |
| 91 // via Vulkan implementation and implicitly enabled layers | |
| 68 uint32_t extensionCount = 0; | 92 uint32_t extensionCount = 0; |
| 69 VkResult res = enumerateInstanceExtensionProperties(nullptr, &extensionCount , nullptr); | 93 res = enumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr ); |
| 70 | 94 if (VK_SUCCESS != res) { |
| 95 return false; | |
| 96 } | |
| 71 VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount ]; | 97 VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount ]; |
| 72 res = enumerateInstanceExtensionProperties(nullptr, &extensionCount, extensi ons); | 98 res = enumerateInstanceExtensionProperties(nullptr, &extensionCount, extensi ons); |
| 73 | 99 if (VK_SUCCESS != res) { |
| 74 fInstanceExtensionStrings->push_back_n(extensionCount); | 100 return false; |
| 101 } | |
| 75 for (uint32_t i = 0; i < extensionCount; ++i) { | 102 for (uint32_t i = 0; i < extensionCount; ++i) { |
| 76 if (specVersion >= extensions[i].specVersion) { | 103 if (specVersion >= extensions[i].specVersion) { |
| 77 (*fInstanceExtensionStrings)[i] = extensions[i].extensionName; | 104 fInstanceExtensionStrings->push_back() = extensions[i].extensionName ; |
| 78 } | 105 } |
| 79 } | 106 } |
| 80 delete [] extensions; | 107 delete [] extensions; |
| 108 // sort so we can search | |
| 109 if (!fInstanceExtensionStrings->empty()) { | |
| 110 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensionStrings ->back(), cmp); | |
| 111 } | |
| 112 // via explicitly enabled layers | |
| 113 layerCount = fInstanceLayerStrings->count(); | |
| 114 for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) { | |
| 115 uint32_t extensionCount = 0; | |
| 116 res = enumerateInstanceExtensionProperties((*fInstanceLayerStrings)[laye rIndex].c_str(), | |
| 117 &extensionCount, nullptr); | |
| 118 if (VK_SUCCESS != res) { | |
| 119 return false; | |
| 120 } | |
| 121 VkExtensionProperties* extensions = new VkExtensionProperties[extensionC ount]; | |
| 122 res = enumerateInstanceExtensionProperties((*fInstanceLayerStrings)[laye rIndex].c_str(), | |
| 123 &extensionCount, extensions); | |
| 124 if (VK_SUCCESS != res) { | |
| 125 return false; | |
| 126 } | |
| 127 for (uint32_t i = 0; i < extensionCount; ++i) { | |
| 128 // if not already in the list, add it | |
| 129 if (specVersion >= extensions[i].specVersion && | |
| 130 find_string(*fInstanceExtensionStrings, extensions[i].extensionN ame) < 0) { | |
| 131 fInstanceExtensionStrings->push_back() = extensions[i].extension Name; | |
| 132 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensio nStrings->back(), | |
| 133 cmp); | |
| 134 } | |
| 135 } | |
| 136 delete[] extensions; | |
| 137 } | |
| 81 | 138 |
| 82 if (!fInstanceExtensionStrings->empty()) { | 139 // device layers |
| 140 layerCount = 0; | |
| 141 res = enumerateDeviceLayerProperties(physDev, &layerCount, nullptr); | |
| 142 if (VK_SUCCESS != res) { | |
| 143 return false; | |
| 144 } | |
| 145 layers = new VkLayerProperties[layerCount]; | |
| 146 res = enumerateDeviceLayerProperties(physDev, &layerCount, layers); | |
| 147 if (VK_SUCCESS != res) { | |
| 148 return false; | |
| 149 } | |
| 150 for (uint32_t i = 0; i < layerCount; ++i) { | |
| 151 if (specVersion >= layers[i].specVersion) { | |
| 152 fDeviceLayerStrings->push_back() = layers[i].layerName; | |
| 153 } | |
| 154 } | |
| 155 delete[] layers; | |
| 156 if (!fDeviceLayerStrings->empty()) { | |
| 83 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; | 157 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
| 84 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensionStrings ->back(), cmp); | 158 SkTQSort(&fDeviceLayerStrings->front(), &fDeviceLayerStrings->back(), cm p); |
| 159 } | |
| 160 | |
| 161 // device extensions | |
| 162 // via Vulkan implementation and implicitly enabled layers | |
| 163 extensionCount = 0; | |
| 164 res = enumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, nullptr); | |
| 165 if (VK_SUCCESS != res) { | |
| 166 return false; | |
| 167 } | |
| 168 extensions = new VkExtensionProperties[extensionCount]; | |
| 169 res = enumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, extensions); | |
| 170 if (VK_SUCCESS != res) { | |
| 171 return false; | |
| 172 } | |
| 173 for (uint32_t i = 0; i < extensionCount; ++i) { | |
| 174 if (specVersion >= extensions[i].specVersion) { | |
| 175 fDeviceExtensionStrings->push_back() = extensions[i].extensionName; | |
| 176 } | |
| 177 } | |
| 178 delete[] extensions; | |
| 179 if (!fDeviceExtensionStrings->empty()) { | |
| 180 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; | |
| 181 SkTQSort(&fDeviceExtensionStrings->front(), &fDeviceExtensionStrings->ba ck(), cmp); | |
| 182 } | |
| 183 // via explicitly enabled layers | |
| 184 layerCount = fDeviceLayerStrings->count(); | |
| 185 for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) { | |
| 186 uint32_t extensionCount = 0; | |
| 187 res = enumerateDeviceExtensionProperties(physDev, | |
| 188 (*fDeviceLayerStrings)[layerInd ex].c_str(), | |
| 189 &extensionCount, nullptr); | |
| 190 if (VK_SUCCESS != res) { | |
| 191 return false; | |
| 192 } | |
| 193 VkExtensionProperties* extensions = new VkExtensionProperties[extensionC ount]; | |
| 194 res = enumerateDeviceExtensionProperties(physDev, | |
| 195 (*fDeviceLayerStrings)[layerInd ex].c_str(), | |
| 196 &extensionCount, extensions); | |
| 197 if (VK_SUCCESS != res) { | |
| 198 return false; | |
| 199 } | |
| 200 for (uint32_t i = 0; i < extensionCount; ++i) { | |
| 201 // if not already in the list, add it | |
| 202 if (specVersion >= extensions[i].specVersion && | |
| 203 find_string(*fDeviceExtensionStrings, extensions[i].extensionNam e) < 0) { | |
| 204 fDeviceExtensionStrings->push_back() = extensions[i].extensionNa me; | |
| 205 SkTQSort(&fDeviceExtensionStrings->front(), &fDeviceExtensionStr ings->back(), cmp); | |
| 206 } | |
| 207 } | |
| 208 delete[] extensions; | |
| 85 } | 209 } |
| 86 | 210 |
| 87 fInitialized = true; | 211 fInitialized = true; |
| 88 return true; | 212 return true; |
| 89 } | 213 } |
| 90 | 214 |
| 91 | 215 |
| 92 bool GrVkExtensions::hasInstanceExtension(const char ext[]) const { | 216 bool GrVkExtensions::hasInstanceExtension(const char ext[]) const { |
| 93 SkASSERT(fInitialized); | 217 SkASSERT(fInitialized); |
| 94 | 218 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 SkDebugf("\nInstance Layers: "); | 367 SkDebugf("\nInstance Layers: "); |
| 244 for (int i = 0; i < cnt; ++i) { | 368 for (int i = 0; i < cnt; ++i) { |
| 245 SkDebugf("%s%s", (*fInstanceLayerStrings)[i].c_str(), (i < cnt - 1) ? se p : ""); | 369 SkDebugf("%s%s", (*fInstanceLayerStrings)[i].c_str(), (i < cnt - 1) ? se p : ""); |
| 246 } | 370 } |
| 247 cnt = fDeviceLayerStrings->count(); | 371 cnt = fDeviceLayerStrings->count(); |
| 248 SkDebugf("\nDevice Layers: "); | 372 SkDebugf("\nDevice Layers: "); |
| 249 for (int i = 0; i < cnt; ++i) { | 373 for (int i = 0; i < cnt; ++i) { |
| 250 SkDebugf("%s%s", (*fDeviceLayerStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); | 374 SkDebugf("%s%s", (*fDeviceLayerStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); |
| 251 } | 375 } |
| 252 } | 376 } |
| OLD | NEW |