blob: 8ea09805aed714842044476c7cdbdd6ccd849656 [file] [log] [blame]
Chia-I Wu9d518162016-03-24 14:55:27 +08001/*
2 * Copyright 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -080017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Mark Salyzyn7823e122016-09-29 08:08:05 -070019#include <malloc.h>
Chia-I Wudbb7e9c2016-03-24 15:09:38 +080020#include <stdlib.h>
21#include <string.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070022#include <sys/prctl.h>
23
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -080024#include <dlfcn.h>
Chia-I Wudbb7e9c2016-03-24 15:09:38 +080025#include <algorithm>
Chia-I Wuff4a6c72016-03-24 16:05:56 +080026#include <array>
Chia-I Wu4901db72016-03-24 16:38:58 +080027#include <new>
Mark Salyzyn7823e122016-09-29 08:08:05 -070028
29#include <log/log.h>
Chia-I Wu9d518162016-03-24 14:55:27 +080030
Jesse Hall53457db2016-12-14 16:54:06 -080031#include <android/dlext.h>
Courtney Goeltzenleuchter7671d462018-01-24 11:51:01 -080032#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
33#include <configstore/Utils.h>
Jesse Hall53457db2016-12-14 16:54:06 -080034#include <cutils/properties.h>
Jiyong Park27c39e12017-05-08 13:00:02 +090035#include <graphicsenv/GraphicsEnv.h>
Yiwei Zhangd9861812019-02-13 11:51:55 -080036#include <utils/Timers.h>
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -080037#include <utils/Trace.h>
Chris Forbesfa25e632017-02-22 12:36:02 +130038#include <utils/Vector.h>
Jesse Hall53457db2016-12-14 16:54:06 -080039
Wei Wangf9b05ee2017-07-19 20:59:39 -070040#include "android-base/properties.h"
41
Chia-I Wu9d518162016-03-24 14:55:27 +080042#include "driver.h"
Jesse Hallb7c4e3b2016-04-11 13:51:38 -070043#include "stubhal.h"
Chia-I Wu9d518162016-03-24 14:55:27 +080044
Courtney Goeltzenleuchter7671d462018-01-24 11:51:01 -080045using namespace android::hardware::configstore;
46using namespace android::hardware::configstore::V1_0;
47
Jesse Hall00e61ff2017-04-07 16:48:02 -070048// TODO(b/37049319) Get this from a header once one exists
49extern "C" {
50android_namespace_t* android_get_exported_namespace(const char*);
51}
52
Chia-I Wudbb7e9c2016-03-24 15:09:38 +080053// #define ENABLE_ALLOC_CALLSTACKS 1
54#if ENABLE_ALLOC_CALLSTACKS
55#include <utils/CallStack.h>
56#define ALOGD_CALLSTACK(...) \
57 do { \
58 ALOGD(__VA_ARGS__); \
59 android::CallStack callstack; \
60 callstack.update(); \
61 callstack.log(LOG_TAG, ANDROID_LOG_DEBUG, " "); \
62 } while (false)
63#else
64#define ALOGD_CALLSTACK(...) \
65 do { \
66 } while (false)
67#endif
68
Chia-I Wu9d518162016-03-24 14:55:27 +080069namespace vulkan {
70namespace driver {
71
Chia-I Wu136b8eb2016-03-24 15:01:52 +080072namespace {
73
Chia-I Wu31b2e4f2016-05-23 10:47:57 +080074class Hal {
75 public:
76 static bool Open();
77
78 static const Hal& Get() { return hal_; }
79 static const hwvulkan_device_t& Device() { return *Get().dev_; }
80
Chia-I Wu31938252016-05-23 15:31:02 +080081 int GetDebugReportIndex() const { return debug_report_index_; }
82
Chia-I Wu31b2e4f2016-05-23 10:47:57 +080083 private:
Chia-I Wu31938252016-05-23 15:31:02 +080084 Hal() : dev_(nullptr), debug_report_index_(-1) {}
Chia-I Wu31b2e4f2016-05-23 10:47:57 +080085 Hal(const Hal&) = delete;
86 Hal& operator=(const Hal&) = delete;
87
Chia-I Wu31938252016-05-23 15:31:02 +080088 bool InitDebugReportIndex();
89
Chia-I Wu31b2e4f2016-05-23 10:47:57 +080090 static Hal hal_;
91
92 const hwvulkan_device_t* dev_;
Chia-I Wu31938252016-05-23 15:31:02 +080093 int debug_report_index_;
Chia-I Wu31b2e4f2016-05-23 10:47:57 +080094};
95
Chia-I Wu4901db72016-03-24 16:38:58 +080096class CreateInfoWrapper {
97 public:
Chia-I Wu31b2e4f2016-05-23 10:47:57 +080098 CreateInfoWrapper(const VkInstanceCreateInfo& create_info,
Chia-I Wuff4a6c72016-03-24 16:05:56 +080099 const VkAllocationCallbacks& allocator);
Chia-I Wu4901db72016-03-24 16:38:58 +0800100 CreateInfoWrapper(VkPhysicalDevice physical_dev,
101 const VkDeviceCreateInfo& create_info,
102 const VkAllocationCallbacks& allocator);
103 ~CreateInfoWrapper();
104
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800105 VkResult Validate();
Ian Elliottf3e872d2017-11-02 10:15:13 -0600106 void DowngradeApiVersion();
Chia-I Wu4901db72016-03-24 16:38:58 +0800107
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800108 const std::bitset<ProcHook::EXTENSION_COUNT>& GetHookExtensions() const;
109 const std::bitset<ProcHook::EXTENSION_COUNT>& GetHalExtensions() const;
Chia-I Wu4901db72016-03-24 16:38:58 +0800110
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800111 explicit operator const VkInstanceCreateInfo*() const;
Chia-I Wu4901db72016-03-24 16:38:58 +0800112 explicit operator const VkDeviceCreateInfo*() const;
113
114 private:
115 struct ExtensionFilter {
116 VkExtensionProperties* exts;
117 uint32_t ext_count;
118
119 const char** names;
120 uint32_t name_count;
121 };
122
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800123 VkResult SanitizePNext();
Chia-I Wu4901db72016-03-24 16:38:58 +0800124
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800125 VkResult SanitizeLayers();
126 VkResult SanitizeExtensions();
Chia-I Wu4901db72016-03-24 16:38:58 +0800127
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800128 VkResult QueryExtensionCount(uint32_t& count) const;
129 VkResult EnumerateExtensions(uint32_t& count,
130 VkExtensionProperties* props) const;
131 VkResult InitExtensionFilter();
132 void FilterExtension(const char* name);
Chia-I Wu4901db72016-03-24 16:38:58 +0800133
134 const bool is_instance_;
135 const VkAllocationCallbacks& allocator_;
136
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800137 VkPhysicalDevice physical_dev_;
Chia-I Wu4901db72016-03-24 16:38:58 +0800138
139 union {
140 VkInstanceCreateInfo instance_info_;
141 VkDeviceCreateInfo dev_info_;
142 };
143
Ian Elliottf3e872d2017-11-02 10:15:13 -0600144 VkApplicationInfo application_info_;
145
Chia-I Wu4901db72016-03-24 16:38:58 +0800146 ExtensionFilter extension_filter_;
147
148 std::bitset<ProcHook::EXTENSION_COUNT> hook_extensions_;
149 std::bitset<ProcHook::EXTENSION_COUNT> hal_extensions_;
150};
151
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800152Hal Hal::hal_;
153
Jesse Hall53457db2016-12-14 16:54:06 -0800154void* LoadLibrary(const android_dlextinfo& dlextinfo,
155 const char* subname,
156 int subname_len) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800157 ATRACE_CALL();
158
Jesse Hall53457db2016-12-14 16:54:06 -0800159 const char kLibFormat[] = "vulkan.%*s.so";
160 char* name = static_cast<char*>(
161 alloca(sizeof(kLibFormat) + static_cast<size_t>(subname_len)));
162 sprintf(name, kLibFormat, subname_len, subname);
163 return android_dlopen_ext(name, RTLD_LOCAL | RTLD_NOW, &dlextinfo);
164}
165
166const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{
167 "ro.hardware." HWVULKAN_HARDWARE_MODULE_ID,
168 "ro.board.platform",
169}};
170
Jesse Hall00e61ff2017-04-07 16:48:02 -0700171int LoadDriver(android_namespace_t* library_namespace,
172 const hwvulkan_module_t** module) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800173 ATRACE_CALL();
174
Jesse Hall53457db2016-12-14 16:54:06 -0800175 const android_dlextinfo dlextinfo = {
176 .flags = ANDROID_DLEXT_USE_NAMESPACE,
Jesse Hall00e61ff2017-04-07 16:48:02 -0700177 .library_namespace = library_namespace,
Jesse Hall53457db2016-12-14 16:54:06 -0800178 };
Jesse Hall53457db2016-12-14 16:54:06 -0800179 void* so = nullptr;
180 char prop[PROPERTY_VALUE_MAX];
181 for (auto key : HAL_SUBNAME_KEY_PROPERTIES) {
182 int prop_len = property_get(key, prop, nullptr);
183 if (prop_len > 0) {
184 so = LoadLibrary(dlextinfo, prop, prop_len);
185 if (so)
186 break;
187 }
188 }
189 if (!so)
190 return -ENOENT;
191
Jesse Hall00e61ff2017-04-07 16:48:02 -0700192 auto hmi = static_cast<hw_module_t*>(dlsym(so, HAL_MODULE_INFO_SYM_AS_STR));
Jesse Hall53457db2016-12-14 16:54:06 -0800193 if (!hmi) {
194 ALOGE("couldn't find symbol '%s' in HAL library: %s", HAL_MODULE_INFO_SYM_AS_STR, dlerror());
195 dlclose(so);
196 return -EINVAL;
197 }
198 if (strcmp(hmi->id, HWVULKAN_HARDWARE_MODULE_ID) != 0) {
199 ALOGE("HAL id '%s' != '%s'", hmi->id, HWVULKAN_HARDWARE_MODULE_ID);
200 dlclose(so);
201 return -EINVAL;
202 }
203 hmi->dso = so;
Jesse Hall00e61ff2017-04-07 16:48:02 -0700204 *module = reinterpret_cast<const hwvulkan_module_t*>(hmi);
Jesse Hall53457db2016-12-14 16:54:06 -0800205 return 0;
206}
207
Jesse Hall00e61ff2017-04-07 16:48:02 -0700208int LoadBuiltinDriver(const hwvulkan_module_t** module) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800209 ATRACE_CALL();
210
Jesse Hall00e61ff2017-04-07 16:48:02 -0700211 auto ns = android_get_exported_namespace("sphal");
212 if (!ns)
213 return -ENOENT;
Yiwei Zhangd9861812019-02-13 11:51:55 -0800214 android::GraphicsEnv::getInstance().setDriverToLoad(
215 android::GraphicsEnv::Driver::VULKAN);
Jesse Hall00e61ff2017-04-07 16:48:02 -0700216 return LoadDriver(ns, module);
217}
218
219int LoadUpdatedDriver(const hwvulkan_module_t** module) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800220 ATRACE_CALL();
221
Jesse Hall00e61ff2017-04-07 16:48:02 -0700222 auto ns = android::GraphicsEnv::getInstance().getDriverNamespace();
223 if (!ns)
224 return -ENOENT;
Yiwei Zhangd9861812019-02-13 11:51:55 -0800225 android::GraphicsEnv::getInstance().setDriverToLoad(
226 android::GraphicsEnv::Driver::VULKAN_UPDATED);
Jesse Hall00e61ff2017-04-07 16:48:02 -0700227 return LoadDriver(ns, module);
228}
229
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800230bool Hal::Open() {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800231 ATRACE_CALL();
232
Yiwei Zhangd9861812019-02-13 11:51:55 -0800233 const nsecs_t openTime = systemTime();
234
Jesse Halldc225072016-05-30 22:40:14 -0700235 ALOG_ASSERT(!hal_.dev_, "OpenHAL called more than once");
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800236
237 // Use a stub device unless we successfully open a real HAL device.
238 hal_.dev_ = &stubhal::kDevice;
239
Jesse Hall53457db2016-12-14 16:54:06 -0800240 int result;
241 const hwvulkan_module_t* module = nullptr;
242
Jesse Hall00e61ff2017-04-07 16:48:02 -0700243 result = LoadUpdatedDriver(&module);
Jesse Hall53457db2016-12-14 16:54:06 -0800244 if (result == -ENOENT) {
Jesse Hall00e61ff2017-04-07 16:48:02 -0700245 result = LoadBuiltinDriver(&module);
246 if (result != 0) {
247 // -ENOENT means the sphal namespace doesn't exist, not that there
248 // is a problem with the driver.
249 ALOGW_IF(
250 result != -ENOENT,
251 "Failed to load Vulkan driver into sphal namespace. This "
252 "usually means the driver has forbidden library dependencies."
253 "Please fix, this will soon stop working.");
254 result =
255 hw_get_module(HWVULKAN_HARDWARE_MODULE_ID,
256 reinterpret_cast<const hw_module_t**>(&module));
257 }
Jesse Hall53457db2016-12-14 16:54:06 -0800258 }
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800259 if (result != 0) {
Yiwei Zhangd9861812019-02-13 11:51:55 -0800260 android::GraphicsEnv::getInstance().setDriverLoaded(
261 android::GraphicsEnv::Api::API_VK, false, systemTime() - openTime);
Jesse Hall53457db2016-12-14 16:54:06 -0800262 ALOGV("unable to load Vulkan HAL, using stub HAL (result=%d)", result);
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800263 return true;
264 }
265
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800266
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800267 hwvulkan_device_t* device;
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800268 ATRACE_BEGIN("hwvulkan module open");
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800269 result =
270 module->common.methods->open(&module->common, HWVULKAN_DEVICE_0,
271 reinterpret_cast<hw_device_t**>(&device));
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800272 ATRACE_END();
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800273 if (result != 0) {
Yiwei Zhangd9861812019-02-13 11:51:55 -0800274 android::GraphicsEnv::getInstance().setDriverLoaded(
275 android::GraphicsEnv::Api::API_VK, false, systemTime() - openTime);
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800276 // Any device with a Vulkan HAL should be able to open the device.
277 ALOGE("failed to open Vulkan HAL device: %s (%d)", strerror(-result),
278 result);
279 return false;
280 }
281
282 hal_.dev_ = device;
283
Chia-I Wu31938252016-05-23 15:31:02 +0800284 hal_.InitDebugReportIndex();
285
Yiwei Zhangd9861812019-02-13 11:51:55 -0800286 android::GraphicsEnv::getInstance().setDriverLoaded(
287 android::GraphicsEnv::Api::API_VK, true, systemTime() - openTime);
288
Chia-I Wu31938252016-05-23 15:31:02 +0800289 return true;
290}
291
292bool Hal::InitDebugReportIndex() {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800293 ATRACE_CALL();
294
Chia-I Wu31938252016-05-23 15:31:02 +0800295 uint32_t count;
296 if (dev_->EnumerateInstanceExtensionProperties(nullptr, &count, nullptr) !=
297 VK_SUCCESS) {
298 ALOGE("failed to get HAL instance extension count");
299 return false;
300 }
301
302 VkExtensionProperties* exts = reinterpret_cast<VkExtensionProperties*>(
303 malloc(sizeof(VkExtensionProperties) * count));
304 if (!exts) {
305 ALOGE("failed to allocate HAL instance extension array");
306 return false;
307 }
308
309 if (dev_->EnumerateInstanceExtensionProperties(nullptr, &count, exts) !=
310 VK_SUCCESS) {
311 ALOGE("failed to enumerate HAL instance extensions");
312 free(exts);
313 return false;
314 }
315
316 for (uint32_t i = 0; i < count; i++) {
317 if (strcmp(exts[i].extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME) ==
318 0) {
319 debug_report_index_ = static_cast<int>(i);
320 break;
321 }
322 }
323
324 free(exts);
325
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800326 return true;
327}
328
329CreateInfoWrapper::CreateInfoWrapper(const VkInstanceCreateInfo& create_info,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800330 const VkAllocationCallbacks& allocator)
331 : is_instance_(true),
332 allocator_(allocator),
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800333 physical_dev_(VK_NULL_HANDLE),
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800334 instance_info_(create_info),
335 extension_filter_() {
336 hook_extensions_.set(ProcHook::EXTENSION_CORE);
337 hal_extensions_.set(ProcHook::EXTENSION_CORE);
338}
339
Chia-I Wu4901db72016-03-24 16:38:58 +0800340CreateInfoWrapper::CreateInfoWrapper(VkPhysicalDevice physical_dev,
341 const VkDeviceCreateInfo& create_info,
342 const VkAllocationCallbacks& allocator)
343 : is_instance_(false),
344 allocator_(allocator),
345 physical_dev_(physical_dev),
346 dev_info_(create_info),
347 extension_filter_() {
348 hook_extensions_.set(ProcHook::EXTENSION_CORE);
349 hal_extensions_.set(ProcHook::EXTENSION_CORE);
350}
351
352CreateInfoWrapper::~CreateInfoWrapper() {
353 allocator_.pfnFree(allocator_.pUserData, extension_filter_.exts);
354 allocator_.pfnFree(allocator_.pUserData, extension_filter_.names);
355}
356
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800357VkResult CreateInfoWrapper::Validate() {
358 VkResult result = SanitizePNext();
Chia-I Wu4901db72016-03-24 16:38:58 +0800359 if (result == VK_SUCCESS)
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800360 result = SanitizeLayers();
Chia-I Wu4901db72016-03-24 16:38:58 +0800361 if (result == VK_SUCCESS)
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800362 result = SanitizeExtensions();
Chia-I Wu4901db72016-03-24 16:38:58 +0800363
364 return result;
365}
366
367const std::bitset<ProcHook::EXTENSION_COUNT>&
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800368CreateInfoWrapper::GetHookExtensions() const {
Chia-I Wu4901db72016-03-24 16:38:58 +0800369 return hook_extensions_;
370}
371
372const std::bitset<ProcHook::EXTENSION_COUNT>&
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800373CreateInfoWrapper::GetHalExtensions() const {
Chia-I Wu4901db72016-03-24 16:38:58 +0800374 return hal_extensions_;
375}
376
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800377CreateInfoWrapper::operator const VkInstanceCreateInfo*() const {
378 return &instance_info_;
379}
380
Chia-I Wu4901db72016-03-24 16:38:58 +0800381CreateInfoWrapper::operator const VkDeviceCreateInfo*() const {
382 return &dev_info_;
383}
384
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800385VkResult CreateInfoWrapper::SanitizePNext() {
Chia-I Wu4901db72016-03-24 16:38:58 +0800386 const struct StructHeader {
387 VkStructureType type;
388 const void* next;
389 } * header;
390
391 if (is_instance_) {
392 header = reinterpret_cast<const StructHeader*>(instance_info_.pNext);
393
394 // skip leading VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFOs
395 while (header &&
396 header->type == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO)
397 header = reinterpret_cast<const StructHeader*>(header->next);
398
399 instance_info_.pNext = header;
400 } else {
401 header = reinterpret_cast<const StructHeader*>(dev_info_.pNext);
402
403 // skip leading VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFOs
404 while (header &&
405 header->type == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO)
406 header = reinterpret_cast<const StructHeader*>(header->next);
407
408 dev_info_.pNext = header;
409 }
410
411 return VK_SUCCESS;
412}
413
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800414VkResult CreateInfoWrapper::SanitizeLayers() {
Chia-I Wu4901db72016-03-24 16:38:58 +0800415 auto& layer_names = (is_instance_) ? instance_info_.ppEnabledLayerNames
416 : dev_info_.ppEnabledLayerNames;
417 auto& layer_count = (is_instance_) ? instance_info_.enabledLayerCount
418 : dev_info_.enabledLayerCount;
419
420 // remove all layers
421 layer_names = nullptr;
422 layer_count = 0;
423
424 return VK_SUCCESS;
425}
426
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800427VkResult CreateInfoWrapper::SanitizeExtensions() {
Chia-I Wu4901db72016-03-24 16:38:58 +0800428 auto& ext_names = (is_instance_) ? instance_info_.ppEnabledExtensionNames
429 : dev_info_.ppEnabledExtensionNames;
430 auto& ext_count = (is_instance_) ? instance_info_.enabledExtensionCount
431 : dev_info_.enabledExtensionCount;
432 if (!ext_count)
433 return VK_SUCCESS;
434
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800435 VkResult result = InitExtensionFilter();
Chia-I Wu4901db72016-03-24 16:38:58 +0800436 if (result != VK_SUCCESS)
437 return result;
438
439 for (uint32_t i = 0; i < ext_count; i++)
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800440 FilterExtension(ext_names[i]);
Chia-I Wu4901db72016-03-24 16:38:58 +0800441
Jesse Halld3d887a2018-03-05 13:34:45 -0800442 // Enable device extensions that contain physical-device commands, so that
443 // vkGetInstanceProcAddr will return those physical-device commands.
444 if (is_instance_) {
445 hook_extensions_.set(ProcHook::KHR_swapchain);
446 }
447
Chia-I Wu4901db72016-03-24 16:38:58 +0800448 ext_names = extension_filter_.names;
449 ext_count = extension_filter_.name_count;
450
451 return VK_SUCCESS;
452}
453
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800454VkResult CreateInfoWrapper::QueryExtensionCount(uint32_t& count) const {
Chia-I Wu4901db72016-03-24 16:38:58 +0800455 if (is_instance_) {
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800456 return Hal::Device().EnumerateInstanceExtensionProperties(
457 nullptr, &count, nullptr);
Chia-I Wu4901db72016-03-24 16:38:58 +0800458 } else {
459 const auto& driver = GetData(physical_dev_).driver;
460 return driver.EnumerateDeviceExtensionProperties(physical_dev_, nullptr,
461 &count, nullptr);
462 }
463}
464
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800465VkResult CreateInfoWrapper::EnumerateExtensions(
Chia-I Wu4901db72016-03-24 16:38:58 +0800466 uint32_t& count,
467 VkExtensionProperties* props) const {
468 if (is_instance_) {
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800469 return Hal::Device().EnumerateInstanceExtensionProperties(
470 nullptr, &count, props);
Chia-I Wu4901db72016-03-24 16:38:58 +0800471 } else {
472 const auto& driver = GetData(physical_dev_).driver;
473 return driver.EnumerateDeviceExtensionProperties(physical_dev_, nullptr,
474 &count, props);
475 }
476}
477
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800478VkResult CreateInfoWrapper::InitExtensionFilter() {
Chia-I Wu4901db72016-03-24 16:38:58 +0800479 // query extension count
480 uint32_t count;
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800481 VkResult result = QueryExtensionCount(count);
Chia-I Wu4901db72016-03-24 16:38:58 +0800482 if (result != VK_SUCCESS || count == 0)
483 return result;
484
485 auto& filter = extension_filter_;
486 filter.exts =
487 reinterpret_cast<VkExtensionProperties*>(allocator_.pfnAllocation(
488 allocator_.pUserData, sizeof(VkExtensionProperties) * count,
489 alignof(VkExtensionProperties),
490 VK_SYSTEM_ALLOCATION_SCOPE_COMMAND));
491 if (!filter.exts)
492 return VK_ERROR_OUT_OF_HOST_MEMORY;
493
494 // enumerate extensions
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800495 result = EnumerateExtensions(count, filter.exts);
Chia-I Wu4901db72016-03-24 16:38:58 +0800496 if (result != VK_SUCCESS && result != VK_INCOMPLETE)
497 return result;
498
499 if (!count)
500 return VK_SUCCESS;
501
502 filter.ext_count = count;
503
504 // allocate name array
505 uint32_t enabled_ext_count = (is_instance_)
506 ? instance_info_.enabledExtensionCount
507 : dev_info_.enabledExtensionCount;
508 count = std::min(filter.ext_count, enabled_ext_count);
509 filter.names = reinterpret_cast<const char**>(allocator_.pfnAllocation(
510 allocator_.pUserData, sizeof(const char*) * count, alignof(const char*),
511 VK_SYSTEM_ALLOCATION_SCOPE_COMMAND));
512 if (!filter.names)
513 return VK_ERROR_OUT_OF_HOST_MEMORY;
514
515 return VK_SUCCESS;
516}
517
Chia-I Wu3e6c2d62016-04-11 13:55:56 +0800518void CreateInfoWrapper::FilterExtension(const char* name) {
Chia-I Wu4901db72016-03-24 16:38:58 +0800519 auto& filter = extension_filter_;
520
521 ProcHook::Extension ext_bit = GetProcHookExtension(name);
522 if (is_instance_) {
523 switch (ext_bit) {
524 case ProcHook::KHR_android_surface:
525 case ProcHook::KHR_surface:
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700526 case ProcHook::EXT_swapchain_colorspace:
Chris Forbes2452cf72017-03-16 16:30:17 +1300527 case ProcHook::KHR_get_surface_capabilities2:
Chia-I Wu4901db72016-03-24 16:38:58 +0800528 hook_extensions_.set(ext_bit);
529 // return now as these extensions do not require HAL support
530 return;
531 case ProcHook::EXT_debug_report:
532 // both we and HAL can take part in
533 hook_extensions_.set(ext_bit);
534 break;
Chris Forbes6aa30db2017-02-20 17:12:53 +1300535 case ProcHook::KHR_get_physical_device_properties2:
Jesse Hall7f983a82018-03-29 14:46:45 -0700536 case ProcHook::EXTENSION_UNKNOWN:
537 // Extensions we don't need to do anything about at this level
Chia-I Wu4901db72016-03-24 16:38:58 +0800538 break;
Jesse Hall7f983a82018-03-29 14:46:45 -0700539
Yiwei Zhang23143102019-04-10 18:24:05 -0700540 case ProcHook::KHR_bind_memory2:
Jesse Hall7f983a82018-03-29 14:46:45 -0700541 case ProcHook::KHR_incremental_present:
542 case ProcHook::KHR_shared_presentable_image:
543 case ProcHook::KHR_swapchain:
544 case ProcHook::EXT_hdr_metadata:
545 case ProcHook::ANDROID_external_memory_android_hardware_buffer:
546 case ProcHook::ANDROID_native_buffer:
547 case ProcHook::GOOGLE_display_timing:
548 case ProcHook::EXTENSION_CORE:
549 case ProcHook::EXTENSION_COUNT:
550 // Device and meta extensions. If we ever get here it's a bug in
551 // our code. But enumerating them lets us avoid having a default
552 // case, and default hides other bugs.
553 ALOGE(
554 "CreateInfoWrapper::FilterExtension: invalid instance "
555 "extension '%s'. FIX ME",
556 name);
Chia-I Wu4901db72016-03-24 16:38:58 +0800557 return;
Jesse Hall7f983a82018-03-29 14:46:45 -0700558
559 // Don't use a default case. Without it, -Wswitch will tell us
560 // at compile time if someone adds a new ProcHook extension but
561 // doesn't handle it above. That's a real bug that has
562 // not-immediately-obvious effects.
563 //
564 // default:
565 // break;
Chia-I Wu4901db72016-03-24 16:38:58 +0800566 }
567 } else {
568 switch (ext_bit) {
569 case ProcHook::KHR_swapchain:
570 // map VK_KHR_swapchain to VK_ANDROID_native_buffer
571 name = VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME;
572 ext_bit = ProcHook::ANDROID_native_buffer;
573 break;
Ian Elliott9e853732017-02-03 11:24:07 -0700574 case ProcHook::KHR_incremental_present:
Ian Elliott8a977262017-01-19 09:05:58 -0700575 case ProcHook::GOOGLE_display_timing:
Chris Forbesfa25e632017-02-22 12:36:02 +1300576 case ProcHook::KHR_shared_presentable_image:
Ian Elliott8a977262017-01-19 09:05:58 -0700577 hook_extensions_.set(ext_bit);
578 // return now as these extensions do not require HAL support
579 return;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700580 case ProcHook::EXT_hdr_metadata:
Yiwei Zhang23143102019-04-10 18:24:05 -0700581 case ProcHook::KHR_bind_memory2:
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700582 hook_extensions_.set(ext_bit);
583 break;
Jesse Hall7f983a82018-03-29 14:46:45 -0700584 case ProcHook::ANDROID_external_memory_android_hardware_buffer:
Chia-I Wu4901db72016-03-24 16:38:58 +0800585 case ProcHook::EXTENSION_UNKNOWN:
Jesse Hall7f983a82018-03-29 14:46:45 -0700586 // Extensions we don't need to do anything about at this level
Chia-I Wu4901db72016-03-24 16:38:58 +0800587 break;
Jesse Hall7f983a82018-03-29 14:46:45 -0700588
589 case ProcHook::KHR_android_surface:
590 case ProcHook::KHR_get_physical_device_properties2:
591 case ProcHook::KHR_get_surface_capabilities2:
592 case ProcHook::KHR_surface:
593 case ProcHook::EXT_debug_report:
594 case ProcHook::EXT_swapchain_colorspace:
595 case ProcHook::ANDROID_native_buffer:
596 case ProcHook::EXTENSION_CORE:
597 case ProcHook::EXTENSION_COUNT:
598 // Instance and meta extensions. If we ever get here it's a bug
599 // in our code. But enumerating them lets us avoid having a
600 // default case, and default hides other bugs.
601 ALOGE(
602 "CreateInfoWrapper::FilterExtension: invalid device "
603 "extension '%s'. FIX ME",
604 name);
Chia-I Wu4901db72016-03-24 16:38:58 +0800605 return;
Jesse Hall7f983a82018-03-29 14:46:45 -0700606
607 // Don't use a default case. Without it, -Wswitch will tell us
608 // at compile time if someone adds a new ProcHook extension but
609 // doesn't handle it above. That's a real bug that has
610 // not-immediately-obvious effects.
611 //
612 // default:
613 // break;
Chia-I Wu4901db72016-03-24 16:38:58 +0800614 }
615 }
616
617 for (uint32_t i = 0; i < filter.ext_count; i++) {
618 const VkExtensionProperties& props = filter.exts[i];
619 // ignore unknown extensions
620 if (strcmp(name, props.extensionName) != 0)
621 continue;
622
Chia-I Wu4901db72016-03-24 16:38:58 +0800623 filter.names[filter.name_count++] = name;
Chia-I Wu1600e262016-04-12 09:40:06 +0800624 if (ext_bit != ProcHook::EXTENSION_UNKNOWN) {
625 if (ext_bit == ProcHook::ANDROID_native_buffer)
626 hook_extensions_.set(ProcHook::KHR_swapchain);
627
628 hal_extensions_.set(ext_bit);
629 }
Chia-I Wu4901db72016-03-24 16:38:58 +0800630
631 break;
632 }
633}
634
Ian Elliottf3e872d2017-11-02 10:15:13 -0600635void CreateInfoWrapper::DowngradeApiVersion() {
636 // If pApplicationInfo is NULL, apiVersion is assumed to be 1.0:
637 if (instance_info_.pApplicationInfo) {
638 application_info_ = *instance_info_.pApplicationInfo;
639 instance_info_.pApplicationInfo = &application_info_;
640 application_info_.apiVersion = VK_API_VERSION_1_0;
641 }
642}
643
Chia-I Wudbb7e9c2016-03-24 15:09:38 +0800644VKAPI_ATTR void* DefaultAllocate(void*,
645 size_t size,
646 size_t alignment,
647 VkSystemAllocationScope) {
648 void* ptr = nullptr;
649 // Vulkan requires 'alignment' to be a power of two, but posix_memalign
650 // additionally requires that it be at least sizeof(void*).
651 int ret = posix_memalign(&ptr, std::max(alignment, sizeof(void*)), size);
652 ALOGD_CALLSTACK("Allocate: size=%zu align=%zu => (%d) %p", size, alignment,
653 ret, ptr);
654 return ret == 0 ? ptr : nullptr;
655}
656
657VKAPI_ATTR void* DefaultReallocate(void*,
658 void* ptr,
659 size_t size,
660 size_t alignment,
661 VkSystemAllocationScope) {
662 if (size == 0) {
663 free(ptr);
664 return nullptr;
665 }
666
667 // TODO(jessehall): Right now we never shrink allocations; if the new
668 // request is smaller than the existing chunk, we just continue using it.
669 // Right now the loader never reallocs, so this doesn't matter. If that
670 // changes, or if this code is copied into some other project, this should
671 // probably have a heuristic to allocate-copy-free when doing so will save
672 // "enough" space.
673 size_t old_size = ptr ? malloc_usable_size(ptr) : 0;
674 if (size <= old_size)
675 return ptr;
676
677 void* new_ptr = nullptr;
678 if (posix_memalign(&new_ptr, std::max(alignment, sizeof(void*)), size) != 0)
679 return nullptr;
680 if (ptr) {
681 memcpy(new_ptr, ptr, std::min(old_size, size));
682 free(ptr);
683 }
684 return new_ptr;
685}
686
687VKAPI_ATTR void DefaultFree(void*, void* ptr) {
688 ALOGD_CALLSTACK("Free: %p", ptr);
689 free(ptr);
690}
691
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800692InstanceData* AllocateInstanceData(const VkAllocationCallbacks& allocator) {
693 void* data_mem = allocator.pfnAllocation(
694 allocator.pUserData, sizeof(InstanceData), alignof(InstanceData),
695 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
696 if (!data_mem)
697 return nullptr;
698
699 return new (data_mem) InstanceData(allocator);
700}
701
702void FreeInstanceData(InstanceData* data,
703 const VkAllocationCallbacks& allocator) {
704 data->~InstanceData();
705 allocator.pfnFree(allocator.pUserData, data);
706}
707
Chia-I Wu950d6e12016-05-03 09:12:35 +0800708DeviceData* AllocateDeviceData(
709 const VkAllocationCallbacks& allocator,
710 const DebugReportCallbackList& debug_report_callbacks) {
Chia-I Wu4901db72016-03-24 16:38:58 +0800711 void* data_mem = allocator.pfnAllocation(
712 allocator.pUserData, sizeof(DeviceData), alignof(DeviceData),
713 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
714 if (!data_mem)
715 return nullptr;
716
Chia-I Wu950d6e12016-05-03 09:12:35 +0800717 return new (data_mem) DeviceData(allocator, debug_report_callbacks);
Chia-I Wu4901db72016-03-24 16:38:58 +0800718}
719
720void FreeDeviceData(DeviceData* data, const VkAllocationCallbacks& allocator) {
721 data->~DeviceData();
722 allocator.pfnFree(allocator.pUserData, data);
723}
724
Chia-I Wu136b8eb2016-03-24 15:01:52 +0800725} // anonymous namespace
726
Chia-I Wu136b8eb2016-03-24 15:01:52 +0800727bool OpenHAL() {
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800728 return Hal::Open();
Chia-I Wu136b8eb2016-03-24 15:01:52 +0800729}
730
Chia-I Wudbb7e9c2016-03-24 15:09:38 +0800731const VkAllocationCallbacks& GetDefaultAllocator() {
732 static const VkAllocationCallbacks kDefaultAllocCallbacks = {
733 .pUserData = nullptr,
734 .pfnAllocation = DefaultAllocate,
735 .pfnReallocation = DefaultReallocate,
736 .pfnFree = DefaultFree,
737 };
738
739 return kDefaultAllocCallbacks;
740}
741
Chia-I Wueb7db122016-03-24 09:11:06 +0800742PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName) {
743 const ProcHook* hook = GetProcHook(pName);
744 if (!hook)
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800745 return Hal::Device().GetInstanceProcAddr(instance, pName);
Chia-I Wueb7db122016-03-24 09:11:06 +0800746
747 if (!instance) {
748 if (hook->type == ProcHook::GLOBAL)
749 return hook->proc;
750
Chia-I Wu109f8982016-04-22 06:40:40 +0800751 // v0 layers expect
752 //
753 // vkGetInstanceProcAddr(VK_NULL_HANDLE, "vkCreateDevice");
754 //
755 // to work.
756 if (strcmp(pName, "vkCreateDevice") == 0)
757 return hook->proc;
758
Chia-I Wueb7db122016-03-24 09:11:06 +0800759 ALOGE(
Chia-I Wue201c3f2016-05-03 13:26:08 +0800760 "internal vkGetInstanceProcAddr called for %s without an instance",
Chia-I Wueb7db122016-03-24 09:11:06 +0800761 pName);
762
Chia-I Wu109f8982016-04-22 06:40:40 +0800763 return nullptr;
Chia-I Wueb7db122016-03-24 09:11:06 +0800764 }
765
766 PFN_vkVoidFunction proc;
767
768 switch (hook->type) {
769 case ProcHook::INSTANCE:
770 proc = (GetData(instance).hook_extensions[hook->extension])
771 ? hook->proc
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800772 : nullptr;
Chia-I Wueb7db122016-03-24 09:11:06 +0800773 break;
774 case ProcHook::DEVICE:
775 proc = (hook->extension == ProcHook::EXTENSION_CORE)
776 ? hook->proc
777 : hook->checked_proc;
778 break;
779 default:
780 ALOGE(
Chia-I Wue201c3f2016-05-03 13:26:08 +0800781 "internal vkGetInstanceProcAddr called for %s with an instance",
Chia-I Wueb7db122016-03-24 09:11:06 +0800782 pName);
783 proc = nullptr;
784 break;
785 }
786
787 return proc;
788}
789
790PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName) {
791 const ProcHook* hook = GetProcHook(pName);
792 if (!hook)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800793 return GetData(device).driver.GetDeviceProcAddr(device, pName);
Chia-I Wueb7db122016-03-24 09:11:06 +0800794
795 if (hook->type != ProcHook::DEVICE) {
Chia-I Wue201c3f2016-05-03 13:26:08 +0800796 ALOGE("internal vkGetDeviceProcAddr called for %s", pName);
Chia-I Wueb7db122016-03-24 09:11:06 +0800797 return nullptr;
798 }
799
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800800 return (GetData(device).hook_extensions[hook->extension]) ? hook->proc
801 : nullptr;
Chia-I Wueb7db122016-03-24 09:11:06 +0800802}
803
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800804VkResult EnumerateInstanceExtensionProperties(
805 const char* pLayerName,
806 uint32_t* pPropertyCount,
807 VkExtensionProperties* pProperties) {
Ian Elliott34a327b2017-03-28 13:20:35 -0600808
809 android::Vector<VkExtensionProperties> loader_extensions;
810 loader_extensions.push_back({
811 VK_KHR_SURFACE_EXTENSION_NAME,
812 VK_KHR_SURFACE_SPEC_VERSION});
813 loader_extensions.push_back({
814 VK_KHR_ANDROID_SURFACE_EXTENSION_NAME,
815 VK_KHR_ANDROID_SURFACE_SPEC_VERSION});
816 loader_extensions.push_back({
817 VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME,
818 VK_EXT_SWAPCHAIN_COLOR_SPACE_SPEC_VERSION});
Chris Forbes16095002017-05-05 15:33:29 -0700819 loader_extensions.push_back({
820 VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME,
821 VK_KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION});
Ian Elliott34a327b2017-03-28 13:20:35 -0600822
Chia-I Wu31938252016-05-23 15:31:02 +0800823 static const VkExtensionProperties loader_debug_report_extension = {
824 VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION,
825 };
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800826
827 // enumerate our extensions first
828 if (!pLayerName && pProperties) {
829 uint32_t count = std::min(
830 *pPropertyCount, static_cast<uint32_t>(loader_extensions.size()));
831
832 std::copy_n(loader_extensions.begin(), count, pProperties);
833
834 if (count < loader_extensions.size()) {
835 *pPropertyCount = count;
836 return VK_INCOMPLETE;
837 }
838
839 pProperties += count;
840 *pPropertyCount -= count;
Chia-I Wu31938252016-05-23 15:31:02 +0800841
842 if (Hal::Get().GetDebugReportIndex() < 0) {
843 if (!*pPropertyCount) {
844 *pPropertyCount = count;
845 return VK_INCOMPLETE;
846 }
847
848 pProperties[0] = loader_debug_report_extension;
849 pProperties += 1;
850 *pPropertyCount -= 1;
851 }
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800852 }
853
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800854 ATRACE_BEGIN("driver.EnumerateInstanceExtensionProperties");
Chia-I Wu31b2e4f2016-05-23 10:47:57 +0800855 VkResult result = Hal::Device().EnumerateInstanceExtensionProperties(
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800856 pLayerName, pPropertyCount, pProperties);
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800857 ATRACE_END();
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800858
Chia-I Wu31938252016-05-23 15:31:02 +0800859 if (!pLayerName && (result == VK_SUCCESS || result == VK_INCOMPLETE)) {
860 int idx = Hal::Get().GetDebugReportIndex();
861 if (idx < 0) {
862 *pPropertyCount += 1;
863 } else if (pProperties &&
864 static_cast<uint32_t>(idx) < *pPropertyCount) {
865 pProperties[idx].specVersion =
866 std::min(pProperties[idx].specVersion,
867 loader_debug_report_extension.specVersion);
868 }
869
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800870 *pPropertyCount += loader_extensions.size();
Chia-I Wu31938252016-05-23 15:31:02 +0800871 }
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800872
873 return result;
874}
875
Chris Forbesfa25e632017-02-22 12:36:02 +1300876bool QueryPresentationProperties(
877 VkPhysicalDevice physicalDevice,
878 VkPhysicalDevicePresentationPropertiesANDROID *presentation_properties)
879{
880 const InstanceData& data = GetData(physicalDevice);
881
882 // GPDP2 must be present and enabled on the instance.
Yiwei Zhang922b1e32018-03-13 17:12:11 -0700883 if (!data.driver.GetPhysicalDeviceProperties2KHR &&
884 !data.driver.GetPhysicalDeviceProperties2)
Chris Forbesfa25e632017-02-22 12:36:02 +1300885 return false;
886
887 // Request the android-specific presentation properties via GPDP2
888 VkPhysicalDeviceProperties2KHR properties = {
889 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR,
890 presentation_properties,
891 {}
892 };
893
894#pragma clang diagnostic push
895#pragma clang diagnostic ignored "-Wold-style-cast"
896 presentation_properties->sType =
897 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID;
898#pragma clang diagnostic pop
899 presentation_properties->pNext = nullptr;
900 presentation_properties->sharedImage = VK_FALSE;
901
Yiwei Zhang922b1e32018-03-13 17:12:11 -0700902 if (data.driver.GetPhysicalDeviceProperties2KHR) {
903 data.driver.GetPhysicalDeviceProperties2KHR(physicalDevice,
904 &properties);
905 } else {
906 data.driver.GetPhysicalDeviceProperties2(physicalDevice, &properties);
907 }
Chris Forbesfa25e632017-02-22 12:36:02 +1300908
909 return true;
910}
911
Chia-I Wu01cf3052016-03-24 16:16:21 +0800912VkResult EnumerateDeviceExtensionProperties(
913 VkPhysicalDevice physicalDevice,
914 const char* pLayerName,
915 uint32_t* pPropertyCount,
916 VkExtensionProperties* pProperties) {
917 const InstanceData& data = GetData(physicalDevice);
Chris Forbesfa25e632017-02-22 12:36:02 +1300918 // extensions that are unconditionally exposed by the loader
919 android::Vector<VkExtensionProperties> loader_extensions;
920 loader_extensions.push_back({
921 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME,
922 VK_KHR_INCREMENTAL_PRESENT_SPEC_VERSION});
Chris Forbesfa25e632017-02-22 12:36:02 +1300923
Courtney Goeltzenleuchter7671d462018-01-24 11:51:01 -0800924 bool hdrBoardConfig =
925 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(
926 false);
927 if (hdrBoardConfig) {
928 loader_extensions.push_back({VK_EXT_HDR_METADATA_EXTENSION_NAME,
929 VK_EXT_HDR_METADATA_SPEC_VERSION});
930 }
931
Chris Forbes16095002017-05-05 15:33:29 -0700932 VkPhysicalDevicePresentationPropertiesANDROID presentation_properties;
933 if (QueryPresentationProperties(physicalDevice, &presentation_properties) &&
934 presentation_properties.sharedImage) {
935 loader_extensions.push_back({
936 VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME,
937 VK_KHR_SHARED_PRESENTABLE_IMAGE_SPEC_VERSION});
Chris Forbesfa25e632017-02-22 12:36:02 +1300938 }
Ian Elliottd4b50aa2017-01-09 16:21:36 -0700939
Ian Elliott5c34de22017-04-10 14:42:30 -0600940 // conditionally add VK_GOOGLE_display_timing if present timestamps are
941 // supported by the driver:
Wei Wangf9b05ee2017-07-19 20:59:39 -0700942 const std::string timestamp_property("service.sf.present_timestamp");
943 android::base::WaitForPropertyCreation(timestamp_property);
944 if (android::base::GetBoolProperty(timestamp_property, true)) {
Ian Elliott5c34de22017-04-10 14:42:30 -0600945 loader_extensions.push_back({
946 VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME,
947 VK_GOOGLE_DISPLAY_TIMING_SPEC_VERSION});
948 }
949
Ian Elliottd4b50aa2017-01-09 16:21:36 -0700950 // enumerate our extensions first
951 if (!pLayerName && pProperties) {
952 uint32_t count = std::min(
953 *pPropertyCount, static_cast<uint32_t>(loader_extensions.size()));
954
955 std::copy_n(loader_extensions.begin(), count, pProperties);
956
957 if (count < loader_extensions.size()) {
958 *pPropertyCount = count;
959 return VK_INCOMPLETE;
960 }
961
962 pProperties += count;
963 *pPropertyCount -= count;
964 }
Chia-I Wu01cf3052016-03-24 16:16:21 +0800965
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800966 ATRACE_BEGIN("driver.EnumerateDeviceExtensionProperties");
Chia-I Wu01cf3052016-03-24 16:16:21 +0800967 VkResult result = data.driver.EnumerateDeviceExtensionProperties(
968 physicalDevice, pLayerName, pPropertyCount, pProperties);
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -0800969 ATRACE_END();
Chia-I Wu01cf3052016-03-24 16:16:21 +0800970
Ian Elliottd4b50aa2017-01-09 16:21:36 -0700971 if (pProperties) {
972 // map VK_ANDROID_native_buffer to VK_KHR_swapchain
973 for (uint32_t i = 0; i < *pPropertyCount; i++) {
974 auto& prop = pProperties[i];
Chia-I Wu01cf3052016-03-24 16:16:21 +0800975
Ian Elliottd4b50aa2017-01-09 16:21:36 -0700976 if (strcmp(prop.extensionName,
977 VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME) != 0)
978 continue;
Chia-I Wu01cf3052016-03-24 16:16:21 +0800979
Ian Elliottd4b50aa2017-01-09 16:21:36 -0700980 memcpy(prop.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME,
981 sizeof(VK_KHR_SWAPCHAIN_EXTENSION_NAME));
Yiwei Zhang14f4d422019-04-17 12:24:39 -0700982
983 if (prop.specVersion >= 8) {
984 prop.specVersion = VK_KHR_SWAPCHAIN_SPEC_VERSION;
985 } else {
986 prop.specVersion = 68;
987 }
Ian Elliottd4b50aa2017-01-09 16:21:36 -0700988 }
989 }
Chia-I Wu01cf3052016-03-24 16:16:21 +0800990
Ian Elliottd4b50aa2017-01-09 16:21:36 -0700991 // restore loader extension count
992 if (!pLayerName && (result == VK_SUCCESS || result == VK_INCOMPLETE)) {
993 *pPropertyCount += loader_extensions.size();
Chia-I Wu01cf3052016-03-24 16:16:21 +0800994 }
995
996 return result;
997}
998
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800999VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo,
1000 const VkAllocationCallbacks* pAllocator,
1001 VkInstance* pInstance) {
1002 const VkAllocationCallbacks& data_allocator =
1003 (pAllocator) ? *pAllocator : GetDefaultAllocator();
1004
Chia-I Wu31b2e4f2016-05-23 10:47:57 +08001005 CreateInfoWrapper wrapper(*pCreateInfo, data_allocator);
Chia-I Wu3e6c2d62016-04-11 13:55:56 +08001006 VkResult result = wrapper.Validate();
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001007 if (result != VK_SUCCESS)
1008 return result;
1009
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001010 ATRACE_BEGIN("AllocateInstanceData");
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001011 InstanceData* data = AllocateInstanceData(data_allocator);
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001012 ATRACE_END();
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001013 if (!data)
1014 return VK_ERROR_OUT_OF_HOST_MEMORY;
1015
Chia-I Wu3e6c2d62016-04-11 13:55:56 +08001016 data->hook_extensions |= wrapper.GetHookExtensions();
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001017
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001018 ATRACE_BEGIN("autoDowngradeApiVersion");
Ian Elliottf3e872d2017-11-02 10:15:13 -06001019#pragma clang diagnostic push
1020#pragma clang diagnostic ignored "-Wold-style-cast"
1021 uint32_t api_version = ((pCreateInfo->pApplicationInfo)
1022 ? pCreateInfo->pApplicationInfo->apiVersion
1023 : VK_API_VERSION_1_0);
1024 uint32_t api_major_version = VK_VERSION_MAJOR(api_version);
1025 uint32_t api_minor_version = VK_VERSION_MINOR(api_version);
1026 uint32_t icd_api_version;
1027 PFN_vkEnumerateInstanceVersion pfn_enumerate_instance_version =
1028 reinterpret_cast<PFN_vkEnumerateInstanceVersion>(
Yi Kongbcbc73a2018-07-18 10:13:04 -07001029 Hal::Device().GetInstanceProcAddr(nullptr,
Ian Elliottf3e872d2017-11-02 10:15:13 -06001030 "vkEnumerateInstanceVersion"));
1031 if (!pfn_enumerate_instance_version) {
1032 icd_api_version = VK_API_VERSION_1_0;
1033 } else {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001034 ATRACE_BEGIN("pfn_enumerate_instance_version");
Ian Elliottf3e872d2017-11-02 10:15:13 -06001035 result = (*pfn_enumerate_instance_version)(&icd_api_version);
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001036 ATRACE_END();
Ian Elliottf3e872d2017-11-02 10:15:13 -06001037 }
1038 uint32_t icd_api_major_version = VK_VERSION_MAJOR(icd_api_version);
1039 uint32_t icd_api_minor_version = VK_VERSION_MINOR(icd_api_version);
1040
1041 if ((icd_api_major_version == 1) && (icd_api_minor_version == 0) &&
1042 ((api_major_version > 1) || (api_minor_version > 0))) {
1043 api_version = VK_API_VERSION_1_0;
1044 wrapper.DowngradeApiVersion();
1045 }
1046#pragma clang diagnostic pop
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001047 ATRACE_END();
Ian Elliottf3e872d2017-11-02 10:15:13 -06001048
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001049 // call into the driver
1050 VkInstance instance;
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001051 ATRACE_BEGIN("driver.CreateInstance");
Chia-I Wu31b2e4f2016-05-23 10:47:57 +08001052 result = Hal::Device().CreateInstance(
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001053 static_cast<const VkInstanceCreateInfo*>(wrapper), pAllocator,
1054 &instance);
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001055 ATRACE_END();
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001056 if (result != VK_SUCCESS) {
1057 FreeInstanceData(data, data_allocator);
1058 return result;
1059 }
1060
1061 // initialize InstanceDriverTable
1062 if (!SetData(instance, *data) ||
Chia-I Wu31b2e4f2016-05-23 10:47:57 +08001063 !InitDriverTable(instance, Hal::Device().GetInstanceProcAddr,
Chia-I Wucbe07ef2016-04-13 15:01:00 +08001064 wrapper.GetHalExtensions())) {
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001065 data->driver.DestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>(
Chia-I Wu31b2e4f2016-05-23 10:47:57 +08001066 Hal::Device().GetInstanceProcAddr(instance, "vkDestroyInstance"));
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001067 if (data->driver.DestroyInstance)
1068 data->driver.DestroyInstance(instance, pAllocator);
1069
1070 FreeInstanceData(data, data_allocator);
1071
1072 return VK_ERROR_INCOMPATIBLE_DRIVER;
1073 }
1074
1075 data->get_device_proc_addr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(
Chia-I Wu31b2e4f2016-05-23 10:47:57 +08001076 Hal::Device().GetInstanceProcAddr(instance, "vkGetDeviceProcAddr"));
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001077 if (!data->get_device_proc_addr) {
1078 data->driver.DestroyInstance(instance, pAllocator);
1079 FreeInstanceData(data, data_allocator);
1080
1081 return VK_ERROR_INCOMPATIBLE_DRIVER;
1082 }
1083
1084 *pInstance = instance;
1085
1086 return VK_SUCCESS;
1087}
1088
1089void DestroyInstance(VkInstance instance,
1090 const VkAllocationCallbacks* pAllocator) {
1091 InstanceData& data = GetData(instance);
1092 data.driver.DestroyInstance(instance, pAllocator);
1093
1094 VkAllocationCallbacks local_allocator;
1095 if (!pAllocator) {
1096 local_allocator = data.allocator;
1097 pAllocator = &local_allocator;
1098 }
1099
1100 FreeInstanceData(&data, *pAllocator);
1101}
1102
Chia-I Wu4901db72016-03-24 16:38:58 +08001103VkResult CreateDevice(VkPhysicalDevice physicalDevice,
1104 const VkDeviceCreateInfo* pCreateInfo,
1105 const VkAllocationCallbacks* pAllocator,
1106 VkDevice* pDevice) {
1107 const InstanceData& instance_data = GetData(physicalDevice);
1108 const VkAllocationCallbacks& data_allocator =
1109 (pAllocator) ? *pAllocator : instance_data.allocator;
1110
1111 CreateInfoWrapper wrapper(physicalDevice, *pCreateInfo, data_allocator);
Chia-I Wu3e6c2d62016-04-11 13:55:56 +08001112 VkResult result = wrapper.Validate();
Chia-I Wu4901db72016-03-24 16:38:58 +08001113 if (result != VK_SUCCESS)
1114 return result;
1115
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001116 ATRACE_BEGIN("AllocateDeviceData");
Chia-I Wu950d6e12016-05-03 09:12:35 +08001117 DeviceData* data = AllocateDeviceData(data_allocator,
1118 instance_data.debug_report_callbacks);
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001119 ATRACE_END();
Chia-I Wu4901db72016-03-24 16:38:58 +08001120 if (!data)
1121 return VK_ERROR_OUT_OF_HOST_MEMORY;
1122
Chia-I Wu3e6c2d62016-04-11 13:55:56 +08001123 data->hook_extensions |= wrapper.GetHookExtensions();
Chia-I Wu4901db72016-03-24 16:38:58 +08001124
1125 // call into the driver
1126 VkDevice dev;
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001127 ATRACE_BEGIN("driver.CreateDevice");
Chia-I Wu4901db72016-03-24 16:38:58 +08001128 result = instance_data.driver.CreateDevice(
1129 physicalDevice, static_cast<const VkDeviceCreateInfo*>(wrapper),
1130 pAllocator, &dev);
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001131 ATRACE_END();
Chia-I Wu4901db72016-03-24 16:38:58 +08001132 if (result != VK_SUCCESS) {
1133 FreeDeviceData(data, data_allocator);
1134 return result;
1135 }
1136
1137 // initialize DeviceDriverTable
1138 if (!SetData(dev, *data) ||
Chia-I Wucbe07ef2016-04-13 15:01:00 +08001139 !InitDriverTable(dev, instance_data.get_device_proc_addr,
1140 wrapper.GetHalExtensions())) {
Chia-I Wu4901db72016-03-24 16:38:58 +08001141 data->driver.DestroyDevice = reinterpret_cast<PFN_vkDestroyDevice>(
1142 instance_data.get_device_proc_addr(dev, "vkDestroyDevice"));
1143 if (data->driver.DestroyDevice)
1144 data->driver.DestroyDevice(dev, pAllocator);
1145
1146 FreeDeviceData(data, data_allocator);
1147
1148 return VK_ERROR_INCOMPATIBLE_DRIVER;
1149 }
Chris Forbesd8277912017-02-10 14:59:59 +13001150
1151 // sanity check ANDROID_native_buffer implementation, whose set of
1152 // entrypoints varies according to the spec version.
1153 if ((wrapper.GetHalExtensions()[ProcHook::ANDROID_native_buffer]) &&
1154 !data->driver.GetSwapchainGrallocUsageANDROID &&
1155 !data->driver.GetSwapchainGrallocUsage2ANDROID) {
1156 ALOGE("Driver's implementation of ANDROID_native_buffer is broken;"
1157 " must expose at least one of "
1158 "vkGetSwapchainGrallocUsageANDROID or "
1159 "vkGetSwapchainGrallocUsage2ANDROID");
1160
1161 data->driver.DestroyDevice(dev, pAllocator);
1162 FreeDeviceData(data, data_allocator);
1163
1164 return VK_ERROR_INCOMPATIBLE_DRIVER;
1165 }
1166
Jesse Hall85bb0c52017-02-09 22:13:02 -08001167 VkPhysicalDeviceProperties properties;
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001168 ATRACE_BEGIN("driver.GetPhysicalDeviceProperties");
Jesse Hall85bb0c52017-02-09 22:13:02 -08001169 instance_data.driver.GetPhysicalDeviceProperties(physicalDevice,
1170 &properties);
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001171 ATRACE_END();
Jesse Hall85bb0c52017-02-09 22:13:02 -08001172
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -07001173 if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) {
1174 // Log that the app is hitting software Vulkan implementation
Yiwei Zhangb1c1a372019-07-03 13:39:32 -07001175 android::GraphicsEnv::getInstance().setTargetStats(
1176 android::GraphicsEnv::Stats::CPU_VULKAN_IN_USE);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -07001177 }
1178
Jesse Halldc225072016-05-30 22:40:14 -07001179 data->driver_device = dev;
Jesse Hall85bb0c52017-02-09 22:13:02 -08001180 data->driver_version = properties.driverVersion;
Chia-I Wu4901db72016-03-24 16:38:58 +08001181
1182 *pDevice = dev;
1183
1184 return VK_SUCCESS;
1185}
1186
1187void DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) {
1188 DeviceData& data = GetData(device);
1189 data.driver.DestroyDevice(device, pAllocator);
1190
1191 VkAllocationCallbacks local_allocator;
1192 if (!pAllocator) {
1193 local_allocator = data.allocator;
1194 pAllocator = &local_allocator;
1195 }
1196
1197 FreeDeviceData(&data, *pAllocator);
1198}
1199
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001200VkResult EnumeratePhysicalDevices(VkInstance instance,
1201 uint32_t* pPhysicalDeviceCount,
1202 VkPhysicalDevice* pPhysicalDevices) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001203 ATRACE_CALL();
1204
Chia-I Wuff4a6c72016-03-24 16:05:56 +08001205 const auto& data = GetData(instance);
1206
1207 VkResult result = data.driver.EnumeratePhysicalDevices(
1208 instance, pPhysicalDeviceCount, pPhysicalDevices);
1209 if ((result == VK_SUCCESS || result == VK_INCOMPLETE) && pPhysicalDevices) {
1210 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++)
1211 SetData(pPhysicalDevices[i], data);
1212 }
1213
1214 return result;
1215}
1216
Daniel Kochf25f5bb2017-10-05 00:26:58 -04001217VkResult EnumeratePhysicalDeviceGroups(
1218 VkInstance instance,
1219 uint32_t* pPhysicalDeviceGroupCount,
1220 VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001221 ATRACE_CALL();
1222
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -08001223 VkResult result = VK_SUCCESS;
Daniel Kochf25f5bb2017-10-05 00:26:58 -04001224 const auto& data = GetData(instance);
1225
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -08001226 if (!data.driver.EnumeratePhysicalDeviceGroups) {
1227 uint32_t device_count = 0;
1228 result = EnumeratePhysicalDevices(instance, &device_count, nullptr);
1229 if (result < 0)
1230 return result;
Chad Versace32c087f2018-09-09 07:28:05 -07001231
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -08001232 if (!pPhysicalDeviceGroupProperties) {
1233 *pPhysicalDeviceGroupCount = device_count;
1234 return result;
1235 }
1236
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -08001237 if (!device_count) {
1238 *pPhysicalDeviceGroupCount = 0;
1239 return result;
1240 }
Chad Versace32c087f2018-09-09 07:28:05 -07001241 device_count = std::min(device_count, *pPhysicalDeviceGroupCount);
1242 if (!device_count)
1243 return VK_INCOMPLETE;
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -08001244
1245 android::Vector<VkPhysicalDevice> devices;
1246 devices.resize(device_count);
Chad Versace32c087f2018-09-09 07:28:05 -07001247 *pPhysicalDeviceGroupCount = device_count;
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -08001248 result = EnumeratePhysicalDevices(instance, &device_count,
1249 devices.editArray());
1250 if (result < 0)
1251 return result;
1252
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -08001253 for (uint32_t i = 0; i < device_count; ++i) {
1254 pPhysicalDeviceGroupProperties[i].physicalDeviceCount = 1;
1255 pPhysicalDeviceGroupProperties[i].physicalDevices[0] = devices[i];
1256 pPhysicalDeviceGroupProperties[i].subsetAllocation = 0;
1257 }
1258 } else {
1259 result = data.driver.EnumeratePhysicalDeviceGroups(
1260 instance, pPhysicalDeviceGroupCount,
1261 pPhysicalDeviceGroupProperties);
1262 if ((result == VK_SUCCESS || result == VK_INCOMPLETE) &&
1263 *pPhysicalDeviceGroupCount && pPhysicalDeviceGroupProperties) {
1264 for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) {
1265 for (uint32_t j = 0;
1266 j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount;
1267 j++) {
1268 SetData(
1269 pPhysicalDeviceGroupProperties[i].physicalDevices[j],
Ian Elliottcd8ad332017-10-13 09:21:12 -06001270 data);
Yiwei Zhang4cd9cc92018-01-08 17:55:50 -08001271 }
Ian Elliottcd8ad332017-10-13 09:21:12 -06001272 }
1273 }
Daniel Kochf25f5bb2017-10-05 00:26:58 -04001274 }
1275
1276 return result;
1277}
1278
Chia-I Wuba0be412016-03-24 16:24:40 +08001279void GetDeviceQueue(VkDevice device,
1280 uint32_t queueFamilyIndex,
1281 uint32_t queueIndex,
1282 VkQueue* pQueue) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001283 ATRACE_CALL();
1284
Chia-I Wuba0be412016-03-24 16:24:40 +08001285 const auto& data = GetData(device);
1286
1287 data.driver.GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
1288 SetData(*pQueue, data);
1289}
1290
Daniel Kochf25f5bb2017-10-05 00:26:58 -04001291void GetDeviceQueue2(VkDevice device,
1292 const VkDeviceQueueInfo2* pQueueInfo,
1293 VkQueue* pQueue) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001294 ATRACE_CALL();
1295
Daniel Kochf25f5bb2017-10-05 00:26:58 -04001296 const auto& data = GetData(device);
1297
1298 data.driver.GetDeviceQueue2(device, pQueueInfo, pQueue);
Yiwei Zhangf5b9f732018-02-07 14:06:09 -08001299 if (*pQueue != VK_NULL_HANDLE) SetData(*pQueue, data);
Daniel Kochf25f5bb2017-10-05 00:26:58 -04001300}
1301
Chia-I Wu6a58a8a2016-03-24 16:29:51 +08001302VKAPI_ATTR VkResult
1303AllocateCommandBuffers(VkDevice device,
1304 const VkCommandBufferAllocateInfo* pAllocateInfo,
1305 VkCommandBuffer* pCommandBuffers) {
Yiwei Zhangfdd0c2a2019-01-30 20:16:37 -08001306 ATRACE_CALL();
1307
Chia-I Wu6a58a8a2016-03-24 16:29:51 +08001308 const auto& data = GetData(device);
1309
1310 VkResult result = data.driver.AllocateCommandBuffers(device, pAllocateInfo,
1311 pCommandBuffers);
1312 if (result == VK_SUCCESS) {
1313 for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++)
1314 SetData(pCommandBuffers[i], data);
1315 }
1316
1317 return result;
1318}
1319
Chia-I Wu9d518162016-03-24 14:55:27 +08001320} // namespace driver
1321} // namespace vulkan