Jesse Hall | d02edcb | 2015-09-08 07:44:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 17 | // module header |
| 18 | #include "loader.h" |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 19 | #include "driver.h" |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 20 | // standard C headers |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 21 | #include <dirent.h> |
| 22 | #include <dlfcn.h> |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 23 | #include <inttypes.h> |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 24 | #include <pthread.h> |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 25 | #include <stdlib.h> |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 26 | #include <string.h> |
Jesse Hall | 2159766 | 2015-12-18 13:48:24 -0800 | [diff] [blame] | 27 | #include <sys/prctl.h> |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 28 | // standard C++ headers |
| 29 | #include <algorithm> |
| 30 | #include <mutex> |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 31 | #include <sstream> |
| 32 | #include <string> |
| 33 | #include <unordered_map> |
| 34 | #include <vector> |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 35 | // platform/library headers |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 36 | #include <cutils/properties.h> |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 37 | #include <hardware/hwvulkan.h> |
| 38 | #include <log/log.h> |
Michael Lentine | 1c69b9e | 2015-09-14 13:26:59 -0500 | [diff] [blame] | 39 | #include <vulkan/vulkan_loader_data.h> |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 40 | #include <vulkan/vk_layer_interface.h> |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 41 | |
| 42 | using namespace vulkan; |
| 43 | |
| 44 | static const uint32_t kMaxPhysicalDevices = 4; |
| 45 | |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 46 | namespace { |
| 47 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 48 | // ---------------------------------------------------------------------------- |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 49 | |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 50 | // Standard-library allocator that delegates to VkAllocationCallbacks. |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 51 | // |
| 52 | // TODO(jessehall): This class currently always uses |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 53 | // VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE. The scope to use could be a template |
Jesse Hall | 03b6fe1 | 2015-11-24 12:44:21 -0800 | [diff] [blame] | 54 | // parameter or a constructor parameter. The former would help catch bugs |
| 55 | // where we use the wrong scope, e.g. adding a command-scope string to an |
| 56 | // instance-scope vector. But that might also be pretty annoying to deal with. |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 57 | template <class T> |
| 58 | class CallbackAllocator { |
| 59 | public: |
| 60 | typedef T value_type; |
| 61 | |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 62 | CallbackAllocator(const VkAllocationCallbacks* alloc_input) |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 63 | : alloc(alloc_input) {} |
| 64 | |
| 65 | template <class T2> |
| 66 | CallbackAllocator(const CallbackAllocator<T2>& other) |
| 67 | : alloc(other.alloc) {} |
| 68 | |
| 69 | T* allocate(std::size_t n) { |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 70 | void* mem = |
| 71 | alloc->pfnAllocation(alloc->pUserData, n * sizeof(T), alignof(T), |
| 72 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 73 | if (!mem) |
| 74 | throw std::bad_alloc(); |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 75 | return static_cast<T*>(mem); |
| 76 | } |
| 77 | |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 78 | void deallocate(T* array, std::size_t /*n*/) noexcept { |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 79 | alloc->pfnFree(alloc->pUserData, array); |
| 80 | } |
| 81 | |
Jesse Hall | 3fbc856 | 2015-11-29 22:10:52 -0800 | [diff] [blame] | 82 | const VkAllocationCallbacks* alloc; |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 83 | }; |
| 84 | // These are needed in order to move Strings |
| 85 | template <class T> |
| 86 | bool operator==(const CallbackAllocator<T>& alloc1, |
| 87 | const CallbackAllocator<T>& alloc2) { |
| 88 | return alloc1.alloc == alloc2.alloc; |
| 89 | } |
| 90 | template <class T> |
| 91 | bool operator!=(const CallbackAllocator<T>& alloc1, |
| 92 | const CallbackAllocator<T>& alloc2) { |
| 93 | return !(alloc1 == alloc2); |
| 94 | } |
| 95 | |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 96 | template <class T> |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 97 | using Vector = std::vector<T, CallbackAllocator<T>>; |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 98 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 99 | typedef std::basic_string<char, std::char_traits<char>, CallbackAllocator<char>> |
| 100 | String; |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 101 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 102 | // ---------------------------------------------------------------------------- |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 103 | // Global Data and Initialization |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 104 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 105 | hwvulkan_device_t* g_hwdevice = nullptr; |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 106 | InstanceExtensionSet g_driver_instance_extensions; |
| 107 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 108 | bool LoadVulkanHAL() { |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 109 | VkResult vkresult; |
| 110 | uint32_t count; |
| 111 | if ((vkresult = g_hwdevice->EnumerateInstanceExtensionProperties( |
| 112 | nullptr, &count, nullptr)) != VK_SUCCESS) { |
| 113 | ALOGE("driver EnumerateInstanceExtensionProperties failed: %d", |
| 114 | vkresult); |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 115 | return false; |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 116 | } |
| 117 | VkExtensionProperties* extensions = static_cast<VkExtensionProperties*>( |
| 118 | alloca(count * sizeof(VkExtensionProperties))); |
| 119 | if ((vkresult = g_hwdevice->EnumerateInstanceExtensionProperties( |
| 120 | nullptr, &count, extensions)) != VK_SUCCESS) { |
| 121 | ALOGE("driver EnumerateInstanceExtensionProperties failed: %d", |
| 122 | vkresult); |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 123 | return false; |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 124 | } |
| 125 | ALOGV_IF(count > 0, "Driver-supported instance extensions:"); |
| 126 | for (uint32_t i = 0; i < count; i++) { |
| 127 | ALOGV(" %s (v%u)", extensions[i].extensionName, |
| 128 | extensions[i].specVersion); |
| 129 | InstanceExtension id = |
| 130 | InstanceExtensionFromName(extensions[i].extensionName); |
| 131 | if (id != kInstanceExtensionCount) |
| 132 | g_driver_instance_extensions.set(id); |
| 133 | } |
| 134 | // Ignore driver attempts to support loader extensions |
| 135 | g_driver_instance_extensions.reset(kKHR_surface); |
| 136 | g_driver_instance_extensions.reset(kKHR_android_surface); |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 137 | |
| 138 | return true; |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 141 | // ----------------------------------------------------------------------------- |
| 142 | |
| 143 | struct Instance { |
| 144 | Instance(const VkAllocationCallbacks* alloc_callbacks) |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 145 | : base{{}, *alloc_callbacks}, |
| 146 | alloc(&base.allocator), |
| 147 | num_physical_devices(0) { |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 148 | memset(physical_devices, 0, sizeof(physical_devices)); |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 149 | enabled_extensions.reset(); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 150 | memset(&drv.dispatch, 0, sizeof(drv.dispatch)); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 153 | ~Instance() {} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 154 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 155 | driver::InstanceData base; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 156 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 157 | const VkAllocationCallbacks* alloc; |
| 158 | uint32_t num_physical_devices; |
Courtney Goeltzenleuchter | 84cd4c2 | 2016-03-16 12:20:13 -0600 | [diff] [blame] | 159 | VkPhysicalDevice physical_devices_top[kMaxPhysicalDevices]; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 160 | VkPhysicalDevice physical_devices[kMaxPhysicalDevices]; |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 161 | DeviceExtensionSet physical_device_driver_extensions[kMaxPhysicalDevices]; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 162 | |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 163 | DebugReportCallbackList debug_report_callbacks; |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 164 | InstanceExtensionSet enabled_extensions; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 165 | |
| 166 | struct { |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 167 | DriverDispatchTable dispatch; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 168 | } drv; // may eventually be an array |
| 169 | }; |
| 170 | |
| 171 | struct Device { |
| 172 | Device(Instance* instance_) |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 173 | : base{{}, *instance_->alloc}, instance(instance_) { |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 174 | enabled_extensions.reset(); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 175 | } |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 176 | |
| 177 | driver::DeviceData base; |
| 178 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 179 | Instance* instance; |
| 180 | PFN_vkGetDeviceProcAddr get_device_proc_addr; |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 181 | DeviceExtensionSet enabled_extensions; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | template <typename THandle> |
| 185 | struct HandleTraits {}; |
| 186 | template <> |
| 187 | struct HandleTraits<VkInstance> { |
| 188 | typedef Instance LoaderObjectType; |
| 189 | }; |
| 190 | template <> |
| 191 | struct HandleTraits<VkPhysicalDevice> { |
| 192 | typedef Instance LoaderObjectType; |
| 193 | }; |
| 194 | template <> |
| 195 | struct HandleTraits<VkDevice> { |
| 196 | typedef Device LoaderObjectType; |
| 197 | }; |
| 198 | template <> |
| 199 | struct HandleTraits<VkQueue> { |
| 200 | typedef Device LoaderObjectType; |
| 201 | }; |
| 202 | template <> |
| 203 | struct HandleTraits<VkCommandBuffer> { |
| 204 | typedef Device LoaderObjectType; |
| 205 | }; |
| 206 | |
| 207 | template <typename THandle> |
| 208 | typename HandleTraits<THandle>::LoaderObjectType& GetDispatchParent( |
| 209 | THandle handle) { |
| 210 | // TODO(jessehall): Make Instance and Device POD types (by removing the |
| 211 | // non-default constructors), so that offsetof is actually legal to use. |
| 212 | // The specific case we're using here is safe in gcc/clang (and probably |
| 213 | // most other C++ compilers), but isn't guaranteed by C++. |
| 214 | typedef typename HandleTraits<THandle>::LoaderObjectType ObjectType; |
| 215 | #pragma clang diagnostic push |
| 216 | #pragma clang diagnostic ignored "-Winvalid-offsetof" |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 217 | const size_t kBaseOffset = offsetof(ObjectType, base); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 218 | #pragma clang diagnostic pop |
| 219 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 220 | const auto& base = driver::GetData(handle); |
| 221 | uintptr_t base_addr = reinterpret_cast<uintptr_t>(&base); |
| 222 | uintptr_t object_addr = base_addr - kBaseOffset; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 223 | return *reinterpret_cast<ObjectType*>(object_addr); |
| 224 | } |
| 225 | |
| 226 | // ----------------------------------------------------------------------------- |
| 227 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 228 | void DestroyDevice(Device* device, VkDevice vkdevice) { |
| 229 | const auto& instance = *device->instance; |
| 230 | |
| 231 | if (vkdevice != VK_NULL_HANDLE) |
| 232 | instance.drv.dispatch.DestroyDevice(vkdevice, instance.alloc); |
| 233 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 234 | device->~Device(); |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 235 | instance.alloc->pfnFree(instance.alloc->pUserData, device); |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 236 | } |
| 237 | |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 238 | /* |
| 239 | * This function will return the pNext pointer of any |
| 240 | * CreateInfo extensions that are not loader extensions. |
| 241 | * This is used to skip past the loader extensions prepended |
| 242 | * to the list during CreateInstance and CreateDevice. |
| 243 | */ |
| 244 | void* StripCreateExtensions(const void* pNext) { |
| 245 | VkLayerInstanceCreateInfo* create_info = |
| 246 | const_cast<VkLayerInstanceCreateInfo*>( |
| 247 | static_cast<const VkLayerInstanceCreateInfo*>(pNext)); |
| 248 | |
| 249 | while ( |
| 250 | create_info && |
| 251 | (create_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO || |
| 252 | create_info->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO)) { |
| 253 | create_info = const_cast<VkLayerInstanceCreateInfo*>( |
| 254 | static_cast<const VkLayerInstanceCreateInfo*>(create_info->pNext)); |
| 255 | } |
| 256 | |
| 257 | return create_info; |
| 258 | } |
| 259 | |
Jesse Hall | fee7143 | 2016-03-05 22:27:02 -0800 | [diff] [blame] | 260 | // Clean up and deallocate an Instance; called from both the failure paths in |
| 261 | // CreateInstance_Top as well as from DestroyInstance_Top. This function does |
| 262 | // not call down the dispatch chain; that should be done before calling this |
| 263 | // function, iff the lower vkCreateInstance call has been made and returned |
| 264 | // successfully. |
| 265 | void DestroyInstance(Instance* instance, |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 266 | const VkAllocationCallbacks* allocator, |
| 267 | VkInstance vkinstance) { |
| 268 | if (vkinstance != VK_NULL_HANDLE && instance->drv.dispatch.DestroyInstance) |
| 269 | instance->drv.dispatch.DestroyInstance(vkinstance, allocator); |
| 270 | |
Jesse Hall | fee7143 | 2016-03-05 22:27:02 -0800 | [diff] [blame] | 271 | instance->~Instance(); |
| 272 | allocator->pfnFree(allocator->pUserData, instance); |
Courtney Goeltzenleuchter | e6e6968 | 2016-01-28 17:26:17 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 275 | } // anonymous namespace |
| 276 | |
| 277 | namespace vulkan { |
Michael Lentine | cd6cabf | 2015-09-14 17:32:59 -0500 | [diff] [blame] | 278 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 279 | // ----------------------------------------------------------------------------- |
| 280 | // "Bottom" functions. These are called at the end of the instance dispatch |
| 281 | // chain. |
| 282 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 283 | VkResult CreateInstance_Bottom(const VkInstanceCreateInfo* create_info, |
| 284 | const VkAllocationCallbacks* allocator, |
| 285 | VkInstance* vkinstance) { |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 286 | VkResult result; |
| 287 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 288 | if (!allocator) |
Chia-I Wu | dbb7e9c | 2016-03-24 15:09:38 +0800 | [diff] [blame] | 289 | allocator = &driver::GetDefaultAllocator(); |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 290 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 291 | void* instance_mem = allocator->pfnAllocation( |
| 292 | allocator->pUserData, sizeof(Instance), alignof(Instance), |
| 293 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 294 | if (!instance_mem) |
| 295 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 296 | Instance& instance = *new (instance_mem) Instance(allocator); |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 297 | |
Jesse Hall | 4b62e4f | 2016-01-21 09:49:49 -0800 | [diff] [blame] | 298 | // Check that all enabled extensions are supported |
Jesse Hall | 4b62e4f | 2016-01-21 09:49:49 -0800 | [diff] [blame] | 299 | uint32_t num_driver_extensions = 0; |
| 300 | for (uint32_t i = 0; i < create_info->enabledExtensionCount; i++) { |
| 301 | const char* name = create_info->ppEnabledExtensionNames[i]; |
| 302 | InstanceExtension id = InstanceExtensionFromName(name); |
| 303 | if (id != kInstanceExtensionCount) { |
| 304 | if (g_driver_instance_extensions[id]) { |
| 305 | num_driver_extensions++; |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 306 | instance.enabled_extensions.set(id); |
Jesse Hall | 4b62e4f | 2016-01-21 09:49:49 -0800 | [diff] [blame] | 307 | continue; |
| 308 | } |
Courtney Goeltzenleuchter | 6fecdd5 | 2016-02-03 15:14:46 -0700 | [diff] [blame] | 309 | if (id == kKHR_surface || id == kKHR_android_surface) { |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 310 | instance.enabled_extensions.set(id); |
Jesse Hall | 4b62e4f | 2016-01-21 09:49:49 -0800 | [diff] [blame] | 311 | continue; |
| 312 | } |
Courtney Goeltzenleuchter | 6fecdd5 | 2016-02-03 15:14:46 -0700 | [diff] [blame] | 313 | // The loader natively supports debug report. |
| 314 | if (id == kEXT_debug_report) { |
| 315 | continue; |
| 316 | } |
Jesse Hall | 4b62e4f | 2016-01-21 09:49:49 -0800 | [diff] [blame] | 317 | } |
Jesse Hall | 4b62e4f | 2016-01-21 09:49:49 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Jesse Hall | a7ac76d | 2016-01-08 22:29:42 -0800 | [diff] [blame] | 320 | VkInstanceCreateInfo driver_create_info = *create_info; |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 321 | driver_create_info.pNext = StripCreateExtensions(create_info->pNext); |
Jesse Hall | a7ac76d | 2016-01-08 22:29:42 -0800 | [diff] [blame] | 322 | driver_create_info.enabledLayerCount = 0; |
| 323 | driver_create_info.ppEnabledLayerNames = nullptr; |
Jesse Hall | a7ac76d | 2016-01-08 22:29:42 -0800 | [diff] [blame] | 324 | driver_create_info.enabledExtensionCount = 0; |
| 325 | driver_create_info.ppEnabledExtensionNames = nullptr; |
Jesse Hall | 4b62e4f | 2016-01-21 09:49:49 -0800 | [diff] [blame] | 326 | if (num_driver_extensions > 0) { |
| 327 | const char** names = static_cast<const char**>( |
| 328 | alloca(num_driver_extensions * sizeof(char*))); |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 329 | for (uint32_t i = 0; i < create_info->enabledExtensionCount; i++) { |
Jesse Hall | ae3b70d | 2016-01-17 22:05:29 -0800 | [diff] [blame] | 330 | const char* name = create_info->ppEnabledExtensionNames[i]; |
| 331 | InstanceExtension id = InstanceExtensionFromName(name); |
| 332 | if (id != kInstanceExtensionCount) { |
| 333 | if (g_driver_instance_extensions[id]) { |
| 334 | names[driver_create_info.enabledExtensionCount++] = name; |
Jesse Hall | ae3b70d | 2016-01-17 22:05:29 -0800 | [diff] [blame] | 335 | continue; |
| 336 | } |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | driver_create_info.ppEnabledExtensionNames = names; |
Jesse Hall | 4b62e4f | 2016-01-21 09:49:49 -0800 | [diff] [blame] | 340 | ALOG_ASSERT( |
| 341 | driver_create_info.enabledExtensionCount == num_driver_extensions, |
| 342 | "counted enabled driver instance extensions twice and got " |
| 343 | "different answers!"); |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 344 | } |
Jesse Hall | a7ac76d | 2016-01-08 22:29:42 -0800 | [diff] [blame] | 345 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 346 | VkInstance drv_instance; |
Jesse Hall | a7ac76d | 2016-01-08 22:29:42 -0800 | [diff] [blame] | 347 | result = g_hwdevice->CreateInstance(&driver_create_info, instance.alloc, |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 348 | &drv_instance); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 349 | if (result != VK_SUCCESS) { |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 350 | DestroyInstance(&instance, allocator, VK_NULL_HANDLE); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 351 | return result; |
| 352 | } |
| 353 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 354 | if (!driver::SetData(drv_instance, instance.base)) { |
| 355 | DestroyInstance(&instance, allocator, drv_instance); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 356 | return VK_ERROR_INITIALIZATION_FAILED; |
| 357 | } |
| 358 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 359 | if (!LoadDriverDispatchTable(drv_instance, g_hwdevice->GetInstanceProcAddr, |
| 360 | instance.enabled_extensions, |
| 361 | instance.drv.dispatch)) { |
| 362 | DestroyInstance(&instance, allocator, drv_instance); |
Courtney Goeltzenleuchter | aa6c872 | 2016-01-29 08:57:16 -0700 | [diff] [blame] | 363 | return VK_ERROR_INITIALIZATION_FAILED; |
| 364 | } |
| 365 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 366 | uint32_t num_physical_devices = 0; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 367 | result = instance.drv.dispatch.EnumeratePhysicalDevices( |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 368 | drv_instance, &num_physical_devices, nullptr); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 369 | if (result != VK_SUCCESS) { |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 370 | DestroyInstance(&instance, allocator, drv_instance); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 371 | return VK_ERROR_INITIALIZATION_FAILED; |
| 372 | } |
| 373 | num_physical_devices = std::min(num_physical_devices, kMaxPhysicalDevices); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 374 | result = instance.drv.dispatch.EnumeratePhysicalDevices( |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 375 | drv_instance, &num_physical_devices, instance.physical_devices); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 376 | if (result != VK_SUCCESS) { |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 377 | DestroyInstance(&instance, allocator, drv_instance); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 378 | return VK_ERROR_INITIALIZATION_FAILED; |
| 379 | } |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 380 | |
| 381 | Vector<VkExtensionProperties> extensions( |
| 382 | Vector<VkExtensionProperties>::allocator_type(instance.alloc)); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 383 | for (uint32_t i = 0; i < num_physical_devices; i++) { |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 384 | if (!driver::SetData(instance.physical_devices[i], instance.base)) { |
| 385 | DestroyInstance(&instance, allocator, drv_instance); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 386 | return VK_ERROR_INITIALIZATION_FAILED; |
| 387 | } |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 388 | |
| 389 | uint32_t count; |
| 390 | if ((result = instance.drv.dispatch.EnumerateDeviceExtensionProperties( |
| 391 | instance.physical_devices[i], nullptr, &count, nullptr)) != |
| 392 | VK_SUCCESS) { |
| 393 | ALOGW("driver EnumerateDeviceExtensionProperties(%u) failed: %d", i, |
| 394 | result); |
| 395 | continue; |
| 396 | } |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 397 | try { |
| 398 | extensions.resize(count); |
| 399 | } catch (std::bad_alloc&) { |
| 400 | ALOGE("instance creation failed: out of memory"); |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 401 | DestroyInstance(&instance, allocator, drv_instance); |
Jesse Hall | 26cecff | 2016-01-21 19:52:25 -0800 | [diff] [blame] | 402 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 403 | } |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 404 | if ((result = instance.drv.dispatch.EnumerateDeviceExtensionProperties( |
| 405 | instance.physical_devices[i], nullptr, &count, |
| 406 | extensions.data())) != VK_SUCCESS) { |
| 407 | ALOGW("driver EnumerateDeviceExtensionProperties(%u) failed: %d", i, |
| 408 | result); |
| 409 | continue; |
| 410 | } |
| 411 | ALOGV_IF(count > 0, "driver gpu[%u] supports extensions:", i); |
| 412 | for (const auto& extension : extensions) { |
| 413 | ALOGV(" %s (v%u)", extension.extensionName, extension.specVersion); |
| 414 | DeviceExtension id = |
| 415 | DeviceExtensionFromName(extension.extensionName); |
| 416 | if (id == kDeviceExtensionCount) { |
| 417 | ALOGW("driver gpu[%u] extension '%s' unknown to loader", i, |
| 418 | extension.extensionName); |
| 419 | } else { |
| 420 | instance.physical_device_driver_extensions[i].set(id); |
| 421 | } |
| 422 | } |
| 423 | // Ignore driver attempts to support loader extensions |
| 424 | instance.physical_device_driver_extensions[i].reset(kKHR_swapchain); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 425 | } |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 426 | instance.num_physical_devices = num_physical_devices; |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 427 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 428 | *vkinstance = drv_instance; |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 429 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 430 | return VK_SUCCESS; |
| 431 | } |
| 432 | |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 433 | VkResult CreateAndroidSurfaceKHR_Disabled(VkInstance, |
| 434 | const VkAndroidSurfaceCreateInfoKHR*, |
| 435 | const VkAllocationCallbacks*, |
| 436 | VkSurfaceKHR*) { |
| 437 | ALOGE( |
| 438 | "VK_KHR_android_surface not enabled. vkCreateAndroidSurfaceKHR not " |
| 439 | "executed."); |
| 440 | |
| 441 | return VK_SUCCESS; |
| 442 | } |
| 443 | |
| 444 | void DestroySurfaceKHR_Disabled(VkInstance, |
| 445 | VkSurfaceKHR, |
| 446 | const VkAllocationCallbacks*) { |
| 447 | ALOGE("VK_KHR_surface not enabled. vkDestroySurfaceKHR not executed."); |
| 448 | } |
| 449 | |
| 450 | VkResult GetPhysicalDeviceSurfaceSupportKHR_Disabled(VkPhysicalDevice, |
| 451 | uint32_t, |
| 452 | VkSurfaceKHR, |
| 453 | VkBool32*) { |
| 454 | ALOGE( |
| 455 | "VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceSupportKHR not " |
| 456 | "executed."); |
| 457 | |
| 458 | return VK_SUCCESS; |
| 459 | } |
| 460 | |
| 461 | VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR_Disabled( |
| 462 | VkPhysicalDevice, |
| 463 | VkSurfaceKHR, |
| 464 | VkSurfaceCapabilitiesKHR*) { |
| 465 | ALOGE( |
| 466 | "VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceapabilitiesKHR " |
| 467 | "not executed."); |
| 468 | |
| 469 | return VK_SUCCESS; |
| 470 | } |
| 471 | |
| 472 | VkResult GetPhysicalDeviceSurfaceFormatsKHR_Disabled(VkPhysicalDevice, |
| 473 | VkSurfaceKHR, |
| 474 | uint32_t*, |
| 475 | VkSurfaceFormatKHR*) { |
| 476 | ALOGE( |
| 477 | "VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceFormatsKHR not " |
| 478 | "executed."); |
| 479 | |
| 480 | return VK_SUCCESS; |
| 481 | } |
| 482 | |
| 483 | VkResult GetPhysicalDeviceSurfacePresentModesKHR_Disabled(VkPhysicalDevice, |
| 484 | VkSurfaceKHR, |
| 485 | uint32_t*, |
| 486 | VkPresentModeKHR*) { |
| 487 | ALOGE( |
| 488 | "VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfacePresentModesKHR " |
| 489 | "not executed."); |
| 490 | |
| 491 | return VK_SUCCESS; |
| 492 | } |
| 493 | |
| 494 | PFN_vkVoidFunction GetInstanceProcAddr_Bottom(VkInstance vkinstance, |
| 495 | const char* name) { |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 496 | PFN_vkVoidFunction pfn; |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 497 | |
| 498 | if (vkinstance) { |
| 499 | Instance& instance = GetDispatchParent(vkinstance); |
| 500 | if (!instance.enabled_extensions[kKHR_android_surface]) { |
| 501 | // KHR_android_surface is not enabled, use error stubs instead |
| 502 | if (strcmp(name, "vkCreateAndroidSurfaceKHR") == 0) { |
| 503 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 504 | CreateAndroidSurfaceKHR_Disabled); |
| 505 | } |
| 506 | } |
| 507 | if (!instance.enabled_extensions[kKHR_surface]) { |
| 508 | // KHR_surface is not enabled, use error stubs instead |
| 509 | if (strcmp(name, "vkDestroySurfaceKHR") == 0) { |
| 510 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 511 | DestroySurfaceKHR_Disabled); |
| 512 | } |
| 513 | if (strcmp(name, "vkGetPhysicalDeviceSurfaceSupportKHR") == 0) { |
| 514 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 515 | GetPhysicalDeviceSurfaceSupportKHR_Disabled); |
| 516 | } |
| 517 | if (strcmp(name, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR") == |
| 518 | 0) { |
| 519 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 520 | GetPhysicalDeviceSurfaceCapabilitiesKHR_Disabled); |
| 521 | } |
| 522 | if (strcmp(name, "vkGetPhysicalDeviceSurfaceFormatsKHR") == 0) { |
| 523 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 524 | GetPhysicalDeviceSurfaceFormatsKHR_Disabled); |
| 525 | } |
| 526 | if (strcmp(name, "vkGetPhysicalDeviceSurfacePresentModesKHR") == |
| 527 | 0) { |
| 528 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 529 | GetPhysicalDeviceSurfacePresentModesKHR_Disabled); |
| 530 | } |
| 531 | } |
| 532 | } |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 533 | if ((pfn = GetLoaderBottomProcAddr(name))) |
| 534 | return pfn; |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 535 | return g_hwdevice->GetInstanceProcAddr(vkinstance, name); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | VkResult EnumeratePhysicalDevices_Bottom(VkInstance vkinstance, |
| 539 | uint32_t* pdev_count, |
| 540 | VkPhysicalDevice* pdevs) { |
| 541 | Instance& instance = GetDispatchParent(vkinstance); |
| 542 | uint32_t count = instance.num_physical_devices; |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 543 | if (pdevs) { |
| 544 | count = std::min(count, *pdev_count); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 545 | std::copy(instance.physical_devices, instance.physical_devices + count, |
| 546 | pdevs); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 547 | } |
| 548 | *pdev_count = count; |
| 549 | return VK_SUCCESS; |
| 550 | } |
| 551 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 552 | void GetPhysicalDeviceProperties_Bottom( |
| 553 | VkPhysicalDevice pdev, |
| 554 | VkPhysicalDeviceProperties* properties) { |
| 555 | GetDispatchParent(pdev).drv.dispatch.GetPhysicalDeviceProperties( |
| 556 | pdev, properties); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 559 | void GetPhysicalDeviceFeatures_Bottom(VkPhysicalDevice pdev, |
| 560 | VkPhysicalDeviceFeatures* features) { |
| 561 | GetDispatchParent(pdev).drv.dispatch.GetPhysicalDeviceFeatures(pdev, |
| 562 | features); |
| 563 | } |
| 564 | |
| 565 | void GetPhysicalDeviceMemoryProperties_Bottom( |
| 566 | VkPhysicalDevice pdev, |
| 567 | VkPhysicalDeviceMemoryProperties* properties) { |
| 568 | GetDispatchParent(pdev).drv.dispatch.GetPhysicalDeviceMemoryProperties( |
| 569 | pdev, properties); |
| 570 | } |
| 571 | |
| 572 | void GetPhysicalDeviceQueueFamilyProperties_Bottom( |
| 573 | VkPhysicalDevice pdev, |
| 574 | uint32_t* pCount, |
| 575 | VkQueueFamilyProperties* properties) { |
| 576 | GetDispatchParent(pdev).drv.dispatch.GetPhysicalDeviceQueueFamilyProperties( |
| 577 | pdev, pCount, properties); |
| 578 | } |
| 579 | |
| 580 | void GetPhysicalDeviceFormatProperties_Bottom(VkPhysicalDevice pdev, |
| 581 | VkFormat format, |
| 582 | VkFormatProperties* properties) { |
| 583 | GetDispatchParent(pdev).drv.dispatch.GetPhysicalDeviceFormatProperties( |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 584 | pdev, format, properties); |
| 585 | } |
| 586 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 587 | VkResult GetPhysicalDeviceImageFormatProperties_Bottom( |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 588 | VkPhysicalDevice pdev, |
| 589 | VkFormat format, |
| 590 | VkImageType type, |
| 591 | VkImageTiling tiling, |
| 592 | VkImageUsageFlags usage, |
Jesse Hall | 5ae3abb | 2015-10-08 14:00:22 -0700 | [diff] [blame] | 593 | VkImageCreateFlags flags, |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 594 | VkImageFormatProperties* properties) { |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 595 | return GetDispatchParent(pdev) |
| 596 | .drv.dispatch.GetPhysicalDeviceImageFormatProperties( |
Jesse Hall | a9e5703 | 2015-11-30 01:03:10 -0800 | [diff] [blame] | 597 | pdev, format, type, tiling, usage, flags, properties); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 600 | void GetPhysicalDeviceSparseImageFormatProperties_Bottom( |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 601 | VkPhysicalDevice pdev, |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 602 | VkFormat format, |
| 603 | VkImageType type, |
| 604 | VkSampleCountFlagBits samples, |
| 605 | VkImageUsageFlags usage, |
| 606 | VkImageTiling tiling, |
| 607 | uint32_t* properties_count, |
| 608 | VkSparseImageFormatProperties* properties) { |
| 609 | GetDispatchParent(pdev) |
| 610 | .drv.dispatch.GetPhysicalDeviceSparseImageFormatProperties( |
| 611 | pdev, format, type, samples, usage, tiling, properties_count, |
| 612 | properties); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 615 | VKAPI_ATTR |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 616 | VkResult EnumerateDeviceExtensionProperties_Bottom( |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 617 | VkPhysicalDevice pdev, |
| 618 | const char* layer_name, |
| 619 | uint32_t* properties_count, |
| 620 | VkExtensionProperties* properties) { |
| 621 | (void)layer_name; |
| 622 | |
| 623 | Instance& instance = GetDispatchParent(pdev); |
| 624 | |
| 625 | size_t gpu_idx = 0; |
| 626 | while (instance.physical_devices[gpu_idx] != pdev) |
| 627 | gpu_idx++; |
| 628 | const DeviceExtensionSet driver_extensions = |
| 629 | instance.physical_device_driver_extensions[gpu_idx]; |
| 630 | |
| 631 | // We only support VK_KHR_swapchain if the GPU supports |
| 632 | // VK_ANDROID_native_buffer |
| 633 | VkExtensionProperties* available = static_cast<VkExtensionProperties*>( |
| 634 | alloca(kDeviceExtensionCount * sizeof(VkExtensionProperties))); |
| 635 | uint32_t num_extensions = 0; |
| 636 | if (driver_extensions[kANDROID_native_buffer]) { |
| 637 | available[num_extensions++] = VkExtensionProperties{ |
| 638 | VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_SPEC_VERSION}; |
| 639 | } |
| 640 | |
| 641 | if (!properties || *properties_count > num_extensions) |
| 642 | *properties_count = num_extensions; |
| 643 | if (properties) |
| 644 | std::copy(available, available + *properties_count, properties); |
| 645 | |
| 646 | return *properties_count < num_extensions ? VK_INCOMPLETE : VK_SUCCESS; |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Courtney Goeltzenleuchter | 1cc0d37 | 2016-02-05 17:10:59 -0700 | [diff] [blame] | 649 | // This is a no-op, the Top function returns the aggregate layer property |
| 650 | // data. This is to keep the dispatch generator happy. |
Jesse Hall | e1b1278 | 2015-11-30 11:27:32 -0800 | [diff] [blame] | 651 | VKAPI_ATTR |
Courtney Goeltzenleuchter | 1cc0d37 | 2016-02-05 17:10:59 -0700 | [diff] [blame] | 652 | VkResult EnumerateDeviceLayerProperties_Bottom( |
| 653 | VkPhysicalDevice /*pdev*/, |
| 654 | uint32_t* /*properties_count*/, |
| 655 | VkLayerProperties* /*properties*/) { |
| 656 | return VK_SUCCESS; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | VKAPI_ATTR |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 660 | VkResult CreateDevice_Bottom(VkPhysicalDevice gpu, |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 661 | const VkDeviceCreateInfo* create_info, |
| 662 | const VkAllocationCallbacks* allocator, |
| 663 | VkDevice* device_out) { |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 664 | Instance& instance = GetDispatchParent(gpu); |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 665 | |
| 666 | // FIXME(jessehall): We don't have good conventions or infrastructure yet to |
| 667 | // do better than just using the instance allocator and scope for |
| 668 | // everything. See b/26732122. |
| 669 | if (true /*!allocator*/) |
| 670 | allocator = instance.alloc; |
| 671 | |
| 672 | void* mem = allocator->pfnAllocation(allocator->pUserData, sizeof(Device), |
| 673 | alignof(Device), |
| 674 | VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 675 | if (!mem) |
| 676 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 677 | Device* device = new (mem) Device(&instance); |
| 678 | |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 679 | size_t gpu_idx = 0; |
| 680 | while (instance.physical_devices[gpu_idx] != gpu) |
| 681 | gpu_idx++; |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 682 | |
| 683 | VkDeviceCreateInfo driver_create_info = *create_info; |
| 684 | driver_create_info.pNext = StripCreateExtensions(create_info->pNext); |
| 685 | driver_create_info.enabledLayerCount = 0; |
| 686 | driver_create_info.ppEnabledLayerNames = nullptr; |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 687 | |
| 688 | uint32_t num_driver_extensions = 0; |
| 689 | const char** driver_extensions = static_cast<const char**>( |
| 690 | alloca(create_info->enabledExtensionCount * sizeof(const char*))); |
| 691 | for (uint32_t i = 0; i < create_info->enabledExtensionCount; i++) { |
| 692 | const char* name = create_info->ppEnabledExtensionNames[i]; |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 693 | DeviceExtension id = DeviceExtensionFromName(name); |
Jesse Hall | ae3b70d | 2016-01-17 22:05:29 -0800 | [diff] [blame] | 694 | if (id != kDeviceExtensionCount) { |
| 695 | if (instance.physical_device_driver_extensions[gpu_idx][id]) { |
| 696 | driver_extensions[num_driver_extensions++] = name; |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 697 | device->enabled_extensions.set(id); |
Jesse Hall | ae3b70d | 2016-01-17 22:05:29 -0800 | [diff] [blame] | 698 | continue; |
| 699 | } |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 700 | // Add the VK_ANDROID_native_buffer extension to the list iff |
| 701 | // the VK_KHR_swapchain extension was requested |
Jesse Hall | ae3b70d | 2016-01-17 22:05:29 -0800 | [diff] [blame] | 702 | if (id == kKHR_swapchain && |
| 703 | instance.physical_device_driver_extensions |
| 704 | [gpu_idx][kANDROID_native_buffer]) { |
| 705 | driver_extensions[num_driver_extensions++] = |
| 706 | VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME; |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 707 | device->enabled_extensions.set(id); |
Jesse Hall | ae3b70d | 2016-01-17 22:05:29 -0800 | [diff] [blame] | 708 | continue; |
| 709 | } |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 710 | } |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 711 | } |
| 712 | |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 713 | driver_create_info.enabledExtensionCount = num_driver_extensions; |
| 714 | driver_create_info.ppEnabledExtensionNames = driver_extensions; |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 715 | VkDevice drv_device; |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 716 | VkResult result = instance.drv.dispatch.CreateDevice( |
| 717 | gpu, &driver_create_info, allocator, &drv_device); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 718 | if (result != VK_SUCCESS) { |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 719 | DestroyDevice(device, VK_NULL_HANDLE); |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 720 | return VK_ERROR_INITIALIZATION_FAILED; |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 723 | if (!driver::SetData(drv_device, device->base)) { |
| 724 | DestroyDevice(device, drv_device); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 725 | return VK_ERROR_INITIALIZATION_FAILED; |
| 726 | } |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 727 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 728 | device->get_device_proc_addr = reinterpret_cast<PFN_vkGetDeviceProcAddr>( |
| 729 | instance.drv.dispatch.GetDeviceProcAddr(drv_device, |
| 730 | "vkGetDeviceProcAddr")); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 731 | *device_out = drv_device; |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 732 | return VK_SUCCESS; |
| 733 | } |
| 734 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 735 | void DestroyInstance_Bottom(VkInstance vkinstance, |
| 736 | const VkAllocationCallbacks* allocator) { |
| 737 | Instance& instance = GetDispatchParent(vkinstance); |
| 738 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 739 | VkAllocationCallbacks local_allocator; |
| 740 | if (!allocator) { |
| 741 | local_allocator = *instance.alloc; |
| 742 | allocator = &local_allocator; |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 743 | } |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 744 | |
| 745 | DestroyInstance(&instance, allocator, vkinstance); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 748 | VkResult CreateSwapchainKHR_Disabled(VkDevice, |
| 749 | const VkSwapchainCreateInfoKHR*, |
| 750 | const VkAllocationCallbacks*, |
| 751 | VkSwapchainKHR*) { |
| 752 | ALOGE("VK_KHR_swapchain not enabled. vkCreateSwapchainKHR not executed."); |
| 753 | |
| 754 | return VK_SUCCESS; |
| 755 | } |
| 756 | |
| 757 | void DestroySwapchainKHR_Disabled(VkDevice, |
| 758 | VkSwapchainKHR, |
| 759 | const VkAllocationCallbacks*) { |
| 760 | ALOGE("VK_KHR_swapchain not enabled. vkDestroySwapchainKHR not executed."); |
| 761 | } |
| 762 | |
| 763 | VkResult GetSwapchainImagesKHR_Disabled(VkDevice, |
| 764 | VkSwapchainKHR, |
| 765 | uint32_t*, |
| 766 | VkImage*) { |
| 767 | ALOGE( |
| 768 | "VK_KHR_swapchain not enabled. vkGetSwapchainImagesKHR not executed."); |
| 769 | |
| 770 | return VK_SUCCESS; |
| 771 | } |
| 772 | |
| 773 | VkResult AcquireNextImageKHR_Disabled(VkDevice, |
| 774 | VkSwapchainKHR, |
| 775 | uint64_t, |
| 776 | VkSemaphore, |
| 777 | VkFence, |
| 778 | uint32_t*) { |
| 779 | ALOGE("VK_KHR_swapchain not enabled. vkAcquireNextImageKHR not executed."); |
| 780 | |
| 781 | return VK_SUCCESS; |
| 782 | } |
| 783 | |
| 784 | VkResult QueuePresentKHR_Disabled(VkQueue, const VkPresentInfoKHR*) { |
| 785 | ALOGE("VK_KHR_swapchain not enabled. vkQueuePresentKHR not executed."); |
| 786 | |
| 787 | return VK_SUCCESS; |
| 788 | } |
| 789 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 790 | PFN_vkVoidFunction GetDeviceProcAddr_Bottom(VkDevice vkdevice, |
| 791 | const char* name) { |
| 792 | if (strcmp(name, "vkCreateDevice") == 0) { |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 793 | return reinterpret_cast<PFN_vkVoidFunction>(CreateDevice_Bottom); |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 794 | } |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 795 | |
Courtney Goeltzenleuchter | a76e8ff | 2016-03-22 08:09:58 -0600 | [diff] [blame] | 796 | Device& device = GetDispatchParent(vkdevice); |
| 797 | if (!device.enabled_extensions[kKHR_swapchain]) { |
| 798 | if (strcmp(name, "vkCreateSwapchainKHR") == 0) { |
| 799 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 800 | CreateSwapchainKHR_Disabled); |
| 801 | } |
| 802 | if (strcmp(name, "vkDestroySwapchainKHR") == 0) { |
| 803 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 804 | DestroySwapchainKHR_Disabled); |
| 805 | } |
| 806 | if (strcmp(name, "vkGetSwapchainImagesKHR") == 0) { |
| 807 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 808 | GetSwapchainImagesKHR_Disabled); |
| 809 | } |
| 810 | if (strcmp(name, "vkAcquireNextSwapchainImageKHR") == 0) { |
| 811 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 812 | AcquireNextImageKHR_Disabled); |
| 813 | } |
| 814 | if (strcmp(name, "vkQueuePresentKHR") == 0) { |
| 815 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 816 | QueuePresentKHR_Disabled); |
| 817 | } |
| 818 | } |
| 819 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 820 | // VK_ANDROID_native_buffer should be hidden from applications and layers. |
| 821 | // TODO(jessehall): Generate this as part of GetLoaderBottomProcAddr. |
| 822 | PFN_vkVoidFunction pfn; |
| 823 | if (strcmp(name, "vkGetSwapchainGrallocUsageANDROID") == 0 || |
| 824 | strcmp(name, "vkAcquireImageANDROID") == 0 || |
| 825 | strcmp(name, "vkQueueSignalReleaseImageANDROID") == 0) { |
| 826 | return nullptr; |
Michael Lentine | 03c64b0 | 2015-08-26 18:27:26 -0500 | [diff] [blame] | 827 | } |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 828 | if ((pfn = GetLoaderBottomProcAddr(name))) |
| 829 | return pfn; |
| 830 | return GetDispatchParent(vkdevice).get_device_proc_addr(vkdevice, name); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 833 | void DestroyDevice_Bottom(VkDevice vkdevice, const VkAllocationCallbacks*) { |
| 834 | DestroyDevice(&GetDispatchParent(vkdevice), vkdevice); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 837 | void GetDeviceQueue_Bottom(VkDevice vkdevice, |
| 838 | uint32_t family, |
| 839 | uint32_t index, |
| 840 | VkQueue* queue_out) { |
| 841 | const auto& device = GetDispatchParent(vkdevice); |
| 842 | const auto& instance = *device.instance; |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 843 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 844 | instance.drv.dispatch.GetDeviceQueue(vkdevice, family, index, queue_out); |
| 845 | driver::SetData(*queue_out, device.base); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 848 | VkResult AllocateCommandBuffers_Bottom( |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 849 | VkDevice vkdevice, |
| 850 | const VkCommandBufferAllocateInfo* alloc_info, |
| 851 | VkCommandBuffer* cmdbufs) { |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 852 | const auto& device = GetDispatchParent(vkdevice); |
| 853 | const auto& instance = *device.instance; |
Jesse Hall | c7a6eb5 | 2015-08-31 12:52:03 -0700 | [diff] [blame] | 854 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 855 | VkResult result = instance.drv.dispatch.AllocateCommandBuffers( |
| 856 | vkdevice, alloc_info, cmdbufs); |
| 857 | if (result == VK_SUCCESS) { |
| 858 | for (uint32_t i = 0; i < alloc_info->commandBufferCount; i++) |
| 859 | driver::SetData(cmdbufs[i], device.base); |
| 860 | } |
| 861 | |
| 862 | return result; |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 865 | // ----------------------------------------------------------------------------- |
| 866 | |
| 867 | const VkAllocationCallbacks* GetAllocator(VkInstance vkinstance) { |
| 868 | return GetDispatchParent(vkinstance).alloc; |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 871 | const VkAllocationCallbacks* GetAllocator(VkDevice vkdevice) { |
| 872 | return GetDispatchParent(vkdevice).instance->alloc; |
Jesse Hall | 1356b0d | 2015-11-23 17:24:58 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 875 | VkInstance GetDriverInstance(VkInstance instance) { |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 876 | return instance; |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | const DriverDispatchTable& GetDriverDispatch(VkInstance instance) { |
| 880 | return GetDispatchParent(instance).drv.dispatch; |
| 881 | } |
| 882 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 883 | const DriverDispatchTable& GetDriverDispatch(VkDevice device) { |
| 884 | return GetDispatchParent(device).instance->drv.dispatch; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 887 | const DriverDispatchTable& GetDriverDispatch(VkQueue queue) { |
| 888 | return GetDispatchParent(queue).instance->drv.dispatch; |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 891 | DebugReportCallbackList& GetDebugReportCallbacks(VkInstance instance) { |
| 892 | return GetDispatchParent(instance).debug_report_callbacks; |
| 893 | } |
| 894 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 895 | bool InitLoader(hwvulkan_device_t* dev) { |
| 896 | if (!g_hwdevice) { |
| 897 | g_hwdevice = dev; |
| 898 | if (!LoadVulkanHAL()) |
| 899 | g_hwdevice = nullptr; |
| 900 | } |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 901 | |
| 902 | return (g_hwdevice != nullptr); |
| 903 | } |
| 904 | |
Chia-I Wu | 136b8eb | 2016-03-24 15:01:52 +0800 | [diff] [blame] | 905 | namespace driver { |
| 906 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 907 | PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName) { |
| 908 | return GetInstanceProcAddr_Bottom(instance, pName); |
| 909 | } |
| 910 | |
| 911 | PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName) { |
| 912 | return GetDeviceProcAddr_Bottom(device, pName); |
| 913 | } |
| 914 | |
| 915 | VkResult EnumerateInstanceExtensionProperties( |
| 916 | const char* pLayerName, |
| 917 | uint32_t* pPropertyCount, |
| 918 | VkExtensionProperties* pProperties) { |
| 919 | (void)pLayerName; |
| 920 | |
| 921 | VkExtensionProperties* available = static_cast<VkExtensionProperties*>( |
| 922 | alloca(kInstanceExtensionCount * sizeof(VkExtensionProperties))); |
| 923 | uint32_t num_extensions = 0; |
| 924 | |
| 925 | available[num_extensions++] = VkExtensionProperties{ |
| 926 | VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_SPEC_VERSION}; |
| 927 | available[num_extensions++] = |
| 928 | VkExtensionProperties{VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, |
| 929 | VK_KHR_ANDROID_SURFACE_SPEC_VERSION}; |
| 930 | if (g_driver_instance_extensions[kEXT_debug_report]) { |
| 931 | available[num_extensions++] = |
| 932 | VkExtensionProperties{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, |
| 933 | VK_EXT_DEBUG_REPORT_SPEC_VERSION}; |
| 934 | } |
| 935 | |
| 936 | if (!pProperties || *pPropertyCount > num_extensions) |
| 937 | *pPropertyCount = num_extensions; |
| 938 | if (pProperties) |
| 939 | std::copy(available, available + *pPropertyCount, pProperties); |
| 940 | |
| 941 | return *pPropertyCount < num_extensions ? VK_INCOMPLETE : VK_SUCCESS; |
| 942 | } |
| 943 | |
| 944 | } // namespace driver |
| 945 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 946 | } // namespace vulkan |