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

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

Issue 1867883002: Fix a bunch of memory issues in Vulkan (Closed) Base URL: https://skia.googlesource.com/skia.git@vkValgrind
Patch Set: Created 4 years, 8 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
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 // instance layers 47 // instance layers
48 uint32_t layerCount = 0; 48 uint32_t layerCount = 0;
49 VkResult res = EnumerateInstanceLayerProperties(&layerCount, nullptr); 49 VkResult res = EnumerateInstanceLayerProperties(&layerCount, nullptr);
50 if (VK_SUCCESS != res) { 50 if (VK_SUCCESS != res) {
51 return false; 51 return false;
52 } 52 }
53 VkLayerProperties* layers = new VkLayerProperties[layerCount]; 53 VkLayerProperties* layers = new VkLayerProperties[layerCount];
54 res = EnumerateInstanceLayerProperties(&layerCount, layers); 54 res = EnumerateInstanceLayerProperties(&layerCount, layers);
55 if (VK_SUCCESS != res) { 55 if (VK_SUCCESS != res) {
56 delete[] layers;
56 return false; 57 return false;
57 } 58 }
58 for (uint32_t i = 0; i < layerCount; ++i) { 59 for (uint32_t i = 0; i < layerCount; ++i) {
59 if (specVersion >= layers[i].specVersion) { 60 if (specVersion >= layers[i].specVersion) {
60 fInstanceLayerStrings->push_back() = layers[i].layerName; 61 fInstanceLayerStrings->push_back() = layers[i].layerName;
61 } 62 }
62 } 63 }
63 delete[] layers; 64 delete[] layers;
64 if (!fInstanceLayerStrings->empty()) { 65 if (!fInstanceLayerStrings->empty()) {
65 SkTQSort(&fInstanceLayerStrings->front(), &fInstanceLayerStrings->back() , cmp); 66 SkTQSort(&fInstanceLayerStrings->front(), &fInstanceLayerStrings->back() , cmp);
66 } 67 }
67 68
68 // instance extensions 69 // instance extensions
69 // via Vulkan implementation and implicitly enabled layers 70 // via Vulkan implementation and implicitly enabled layers
70 uint32_t extensionCount = 0; 71 uint32_t extensionCount = 0;
71 res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr ); 72 res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr );
72 if (VK_SUCCESS != res) { 73 if (VK_SUCCESS != res) {
73 return false; 74 return false;
74 } 75 }
75 VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount ]; 76 VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount ];
76 res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensi ons); 77 res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensi ons);
77 if (VK_SUCCESS != res) { 78 if (VK_SUCCESS != res) {
79 delete[] extensions;
78 return false; 80 return false;
79 } 81 }
80 for (uint32_t i = 0; i < extensionCount; ++i) { 82 for (uint32_t i = 0; i < extensionCount; ++i) {
81 if (specVersion >= extensions[i].specVersion) { 83 if (specVersion >= extensions[i].specVersion) {
82 fInstanceExtensionStrings->push_back() = extensions[i].extensionName ; 84 fInstanceExtensionStrings->push_back() = extensions[i].extensionName ;
83 } 85 }
84 } 86 }
85 delete [] extensions; 87 delete [] extensions;
86 // sort so we can search 88 // sort so we can search
87 if (!fInstanceExtensionStrings->empty()) { 89 if (!fInstanceExtensionStrings->empty()) {
88 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensionStrings ->back(), cmp); 90 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensionStrings ->back(), cmp);
89 } 91 }
90 // via explicitly enabled layers 92 // via explicitly enabled layers
91 layerCount = fInstanceLayerStrings->count(); 93 layerCount = fInstanceLayerStrings->count();
92 for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) { 94 for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) {
93 uint32_t extensionCount = 0; 95 uint32_t extensionCount = 0;
94 res = EnumerateInstanceExtensionProperties((*fInstanceLayerStrings)[laye rIndex].c_str(), 96 res = EnumerateInstanceExtensionProperties((*fInstanceLayerStrings)[laye rIndex].c_str(),
95 &extensionCount, nullptr); 97 &extensionCount, nullptr);
96 if (VK_SUCCESS != res) { 98 if (VK_SUCCESS != res) {
97 return false; 99 return false;
98 } 100 }
99 VkExtensionProperties* extensions = new VkExtensionProperties[extensionC ount]; 101 VkExtensionProperties* extensions = new VkExtensionProperties[extensionC ount];
100 res = EnumerateInstanceExtensionProperties((*fInstanceLayerStrings)[laye rIndex].c_str(), 102 res = EnumerateInstanceExtensionProperties((*fInstanceLayerStrings)[laye rIndex].c_str(),
101 &extensionCount, extensions); 103 &extensionCount, extensions);
102 if (VK_SUCCESS != res) { 104 if (VK_SUCCESS != res) {
105 delete[] extensions;
103 return false; 106 return false;
104 } 107 }
105 for (uint32_t i = 0; i < extensionCount; ++i) { 108 for (uint32_t i = 0; i < extensionCount; ++i) {
106 // if not already in the list, add it 109 // if not already in the list, add it
107 if (specVersion >= extensions[i].specVersion && 110 if (specVersion >= extensions[i].specVersion &&
108 find_string(*fInstanceExtensionStrings, extensions[i].extensionN ame) < 0) { 111 find_string(*fInstanceExtensionStrings, extensions[i].extensionN ame) < 0) {
109 fInstanceExtensionStrings->push_back() = extensions[i].extension Name; 112 fInstanceExtensionStrings->push_back() = extensions[i].extension Name;
110 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensio nStrings->back(), 113 SkTQSort(&fInstanceExtensionStrings->front(), &fInstanceExtensio nStrings->back(),
111 cmp); 114 cmp);
112 } 115 }
(...skipping 18 matching lines...) Expand all
131 134
132 // device layers 135 // device layers
133 uint32_t layerCount = 0; 136 uint32_t layerCount = 0;
134 VkResult res = EnumerateDeviceLayerProperties(physDev, &layerCount, nullptr) ; 137 VkResult res = EnumerateDeviceLayerProperties(physDev, &layerCount, nullptr) ;
135 if (VK_SUCCESS != res) { 138 if (VK_SUCCESS != res) {
136 return false; 139 return false;
137 } 140 }
138 VkLayerProperties* layers = new VkLayerProperties[layerCount]; 141 VkLayerProperties* layers = new VkLayerProperties[layerCount];
139 res = EnumerateDeviceLayerProperties(physDev, &layerCount, layers); 142 res = EnumerateDeviceLayerProperties(physDev, &layerCount, layers);
140 if (VK_SUCCESS != res) { 143 if (VK_SUCCESS != res) {
144 delete[] layers;
141 return false; 145 return false;
142 } 146 }
143 for (uint32_t i = 0; i < layerCount; ++i) { 147 for (uint32_t i = 0; i < layerCount; ++i) {
144 if (specVersion >= layers[i].specVersion) { 148 if (specVersion >= layers[i].specVersion) {
145 fDeviceLayerStrings->push_back() = layers[i].layerName; 149 fDeviceLayerStrings->push_back() = layers[i].layerName;
146 } 150 }
147 } 151 }
148 delete[] layers; 152 delete[] layers;
149 if (!fDeviceLayerStrings->empty()) { 153 if (!fDeviceLayerStrings->empty()) {
150 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; 154 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
151 SkTQSort(&fDeviceLayerStrings->front(), &fDeviceLayerStrings->back(), cm p); 155 SkTQSort(&fDeviceLayerStrings->front(), &fDeviceLayerStrings->back(), cm p);
152 } 156 }
153 157
154 // device extensions 158 // device extensions
155 // via Vulkan implementation and implicitly enabled layers 159 // via Vulkan implementation and implicitly enabled layers
156 uint32_t extensionCount = 0; 160 uint32_t extensionCount = 0;
157 res = EnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, nullptr); 161 res = EnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, nullptr);
158 if (VK_SUCCESS != res) { 162 if (VK_SUCCESS != res) {
159 return false; 163 return false;
160 } 164 }
161 VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount ]; 165 VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount ];
162 res = EnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, extensions); 166 res = EnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, extensions);
163 if (VK_SUCCESS != res) { 167 if (VK_SUCCESS != res) {
168 delete[] extensions;
164 return false; 169 return false;
165 } 170 }
166 for (uint32_t i = 0; i < extensionCount; ++i) { 171 for (uint32_t i = 0; i < extensionCount; ++i) {
167 if (specVersion >= extensions[i].specVersion) { 172 if (specVersion >= extensions[i].specVersion) {
168 fDeviceExtensionStrings->push_back() = extensions[i].extensionName; 173 fDeviceExtensionStrings->push_back() = extensions[i].extensionName;
169 } 174 }
170 } 175 }
171 delete[] extensions; 176 delete[] extensions;
172 if (!fDeviceExtensionStrings->empty()) { 177 if (!fDeviceExtensionStrings->empty()) {
173 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; 178 SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
174 SkTQSort(&fDeviceExtensionStrings->front(), &fDeviceExtensionStrings->ba ck(), cmp); 179 SkTQSort(&fDeviceExtensionStrings->front(), &fDeviceExtensionStrings->ba ck(), cmp);
175 } 180 }
176 // via explicitly enabled layers 181 // via explicitly enabled layers
177 layerCount = fDeviceLayerStrings->count(); 182 layerCount = fDeviceLayerStrings->count();
178 for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) { 183 for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) {
179 uint32_t extensionCount = 0; 184 uint32_t extensionCount = 0;
180 res = EnumerateDeviceExtensionProperties(physDev, 185 res = EnumerateDeviceExtensionProperties(physDev,
181 (*fDeviceLayerStrings)[layerIndex].c_str(), 186 (*fDeviceLayerStrings)[layerIndex].c_str(),
182 &extensionCount, nullptr); 187 &extensionCount, nullptr);
183 if (VK_SUCCESS != res) { 188 if (VK_SUCCESS != res) {
184 return false; 189 return false;
185 } 190 }
186 VkExtensionProperties* extensions = new VkExtensionProperties[extensionC ount]; 191 VkExtensionProperties* extensions = new VkExtensionProperties[extensionC ount];
187 res = EnumerateDeviceExtensionProperties(physDev, 192 res = EnumerateDeviceExtensionProperties(physDev,
188 (*fDeviceLayerStrings)[layerIndex].c_str(), 193 (*fDeviceLayerStrings)[layerIndex].c_str(),
189 &extensionCount, extensions); 194 &extensionCount, extensions);
190 if (VK_SUCCESS != res) { 195 if (VK_SUCCESS != res) {
196 delete[] extensions;
191 return false; 197 return false;
192 } 198 }
193 for (uint32_t i = 0; i < extensionCount; ++i) { 199 for (uint32_t i = 0; i < extensionCount; ++i) {
194 // if not already in the list, add it 200 // if not already in the list, add it
195 if (specVersion >= extensions[i].specVersion && 201 if (specVersion >= extensions[i].specVersion &&
196 find_string(*fDeviceExtensionStrings, extensions[i].extensionNam e) < 0) { 202 find_string(*fDeviceExtensionStrings, extensions[i].extensionNam e) < 0) {
197 fDeviceExtensionStrings->push_back() = extensions[i].extensionNa me; 203 fDeviceExtensionStrings->push_back() = extensions[i].extensionNa me;
198 SkTQSort(&fDeviceExtensionStrings->front(), &fDeviceExtensionStr ings->back(), cmp); 204 SkTQSort(&fDeviceExtensionStrings->front(), &fDeviceExtensionStr ings->back(), cmp);
199 } 205 }
200 } 206 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 SkDebugf("\nInstance Layers: "); 244 SkDebugf("\nInstance Layers: ");
239 for (int i = 0; i < cnt; ++i) { 245 for (int i = 0; i < cnt; ++i) {
240 SkDebugf("%s%s", (*fInstanceLayerStrings)[i].c_str(), (i < cnt - 1) ? se p : ""); 246 SkDebugf("%s%s", (*fInstanceLayerStrings)[i].c_str(), (i < cnt - 1) ? se p : "");
241 } 247 }
242 cnt = fDeviceLayerStrings->count(); 248 cnt = fDeviceLayerStrings->count();
243 SkDebugf("\nDevice Layers: "); 249 SkDebugf("\nDevice Layers: ");
244 for (int i = 0; i < cnt; ++i) { 250 for (int i = 0; i < cnt; ++i) {
245 SkDebugf("%s%s", (*fDeviceLayerStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); 251 SkDebugf("%s%s", (*fDeviceLayerStrings)[i].c_str(), (i < cnt - 1) ? sep : "");
246 } 252 }
247 } 253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698