Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
| 19 | */ |
| 20 | |
Jamie Madill | df5d573 | 2016-04-04 11:54:43 -0400 | [diff] [blame] | 21 | #include "vk_loader_platform.h" |
| 22 | #include "vulkan/vulkan.h" |
| 23 | |
Dustin Graves | 176f9df | 2016-07-14 17:28:11 -0600 | [diff] [blame] | 24 | #include <cinttypes> |
| 25 | #include <memory> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 29 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 30 | #include <unordered_map> |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 31 | #include <vector> |
| 32 | #include <mutex> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 33 | |
| 34 | #include "vulkan/vk_layer.h" |
| 35 | #include "vk_layer_config.h" |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 36 | #include "vk_layer_table.h" |
| 37 | #include "vk_layer_data.h" |
| 38 | #include "vk_layer_logging.h" |
| 39 | #include "vk_layer_extension_utils.h" |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 40 | #include "vk_safe_struct.h" |
Jon Ashburn | dc9111c | 2016-03-22 12:57:13 -0600 | [diff] [blame] | 41 | #include "vk_layer_utils.h" |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 42 | |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 43 | namespace unique_objects { |
| 44 | |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 45 | // All increments must be guarded by global_lock |
| 46 | static uint64_t global_unique_id = 1; |
| 47 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 48 | struct layer_data { |
Chia-I Wu | 1657047 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 49 | VkInstance instance; |
| 50 | |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 51 | debug_report_data *report_data; |
| 52 | std::vector<VkDebugReportCallbackEXT> logging_callback; |
| 53 | |
| 54 | // The following are for keeping track of the temporary callbacks that can |
| 55 | // be used in vkCreateInstance and vkDestroyInstance: |
| 56 | uint32_t num_tmp_callbacks; |
| 57 | VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos; |
| 58 | VkDebugReportCallbackEXT *tmp_callbacks; |
| 59 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 60 | bool wsi_enabled; |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 61 | std::unordered_map<uint64_t, uint64_t> unique_id_mapping; // Map uniqueID to actual object handle |
| 62 | VkPhysicalDevice gpu; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 63 | |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 64 | layer_data() : wsi_enabled(false), gpu(VK_NULL_HANDLE){}; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 67 | struct instance_extension_enables { |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 68 | bool wsi_enabled; |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 69 | bool xlib_enabled; |
| 70 | bool xcb_enabled; |
| 71 | bool wayland_enabled; |
| 72 | bool mir_enabled; |
| 73 | bool android_enabled; |
| 74 | bool win32_enabled; |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 75 | bool display_enabled; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 78 | static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 79 | static std::unordered_map<void *, layer_data *> layer_data_map; |
| 80 | static device_table_map unique_objects_device_table_map; |
| 81 | static instance_table_map unique_objects_instance_table_map; |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 82 | static std::mutex global_lock; // Protect map accesses and unique_id increments |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 83 | |
Dustin Graves | 176f9df | 2016-07-14 17:28:11 -0600 | [diff] [blame] | 84 | struct GenericHeader { |
| 85 | VkStructureType sType; |
| 86 | void *pNext; |
| 87 | }; |
| 88 | |
| 89 | template <typename T> bool ContainsExtStruct(const T *target, VkStructureType ext_type) { |
| 90 | assert(target != nullptr); |
| 91 | |
| 92 | const GenericHeader *ext_struct = reinterpret_cast<const GenericHeader *>(target->pNext); |
| 93 | |
| 94 | while (ext_struct != nullptr) { |
| 95 | if (ext_struct->sType == ext_type) { |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | ext_struct = reinterpret_cast<const GenericHeader *>(ext_struct->pNext); |
| 100 | } |
| 101 | |
| 102 | return false; |
| 103 | } |
| 104 | |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 105 | static void init_unique_objects(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { |
| 106 | layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "google_unique_objects"); |
| 107 | } |
| 108 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 109 | // Handle CreateInstance |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 110 | static void checkInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 111 | uint32_t i; |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 112 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(unique_objects_instance_table_map, instance); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 113 | |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 114 | instanceExtMap[pDisp] = {}; |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 115 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 116 | for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 117 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 118 | instanceExtMap[pDisp].wsi_enabled = true; |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 119 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) |
| 120 | instanceExtMap[pDisp].display_enabled = true; |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 121 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 122 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 123 | instanceExtMap[pDisp].xlib_enabled = true; |
| 124 | #endif |
| 125 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 126 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 127 | instanceExtMap[pDisp].xcb_enabled = true; |
| 128 | #endif |
| 129 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 130 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 131 | instanceExtMap[pDisp].wayland_enabled = true; |
| 132 | #endif |
| 133 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 134 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 135 | instanceExtMap[pDisp].mir_enabled = true; |
| 136 | #endif |
| 137 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 138 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 139 | instanceExtMap[pDisp].android_enabled = true; |
| 140 | #endif |
| 141 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 142 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 143 | instanceExtMap[pDisp].win32_enabled = true; |
| 144 | #endif |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 148 | VkResult explicit_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 149 | VkInstance *pInstance) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 150 | VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 151 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 152 | assert(chain_info->u.pLayerInfo); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 153 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 154 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 155 | if (fpCreateInstance == NULL) { |
| 156 | return VK_ERROR_INITIALIZATION_FAILED; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 157 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 158 | |
| 159 | // Advance the link info for the next element on the chain |
| 160 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 161 | |
| 162 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 163 | if (result != VK_SUCCESS) { |
| 164 | return result; |
| 165 | } |
| 166 | |
Chia-I Wu | 1657047 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 167 | layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); |
| 168 | my_data->instance = *pInstance; |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 169 | VkLayerInstanceDispatchTable *pTable = initInstanceTable(*pInstance, fpGetInstanceProcAddr, unique_objects_instance_table_map); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 170 | |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 171 | my_data->instance = *pInstance; |
| 172 | my_data->report_data = debug_report_create_instance(pTable, *pInstance, pCreateInfo->enabledExtensionCount, |
| 173 | pCreateInfo->ppEnabledExtensionNames); |
| 174 | |
| 175 | // Set up temporary debug callbacks to output messages at CreateInstance-time |
| 176 | if (!layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos, |
| 177 | &my_data->tmp_callbacks)) { |
| 178 | if (my_data->num_tmp_callbacks > 0) { |
| 179 | if (layer_enable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_dbg_create_infos, |
| 180 | my_data->tmp_callbacks)) { |
| 181 | layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos, my_data->tmp_callbacks); |
| 182 | my_data->num_tmp_callbacks = 0; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | init_unique_objects(my_data, pAllocator); |
Mark Young | aa1aa3a | 2016-07-05 16:41:50 -0600 | [diff] [blame] | 188 | checkInstanceRegisterExtensions(pCreateInfo, *pInstance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 189 | |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 190 | // Disable and free tmp callbacks, no longer necessary |
| 191 | if (my_data->num_tmp_callbacks > 0) { |
| 192 | layer_disable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_callbacks); |
| 193 | layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos, my_data->tmp_callbacks); |
| 194 | my_data->num_tmp_callbacks = 0; |
| 195 | } |
| 196 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 197 | return result; |
| 198 | } |
| 199 | |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 200 | void explicit_DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Dustin Graves | 7b098da | 2016-04-29 11:55:43 -0600 | [diff] [blame] | 201 | dispatch_key key = get_dispatch_key(instance); |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 202 | layer_data *my_data = get_my_data_ptr(key, layer_data_map); |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 203 | VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(unique_objects_instance_table_map, instance); |
| 204 | instanceExtMap.erase(pDisp); |
Cody Northrop | 48968b4 | 2016-07-12 11:43:32 -0600 | [diff] [blame] | 205 | pDisp->DestroyInstance(instance, pAllocator); |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 206 | |
| 207 | // Clean up logging callback, if any |
| 208 | while (my_data->logging_callback.size() > 0) { |
| 209 | VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); |
| 210 | layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); |
| 211 | my_data->logging_callback.pop_back(); |
| 212 | } |
| 213 | |
| 214 | layer_debug_report_destroy_instance(my_data->report_data); |
Cody Northrop | 48968b4 | 2016-07-12 11:43:32 -0600 | [diff] [blame] | 215 | layer_data_map.erase(key); |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 216 | } |
| 217 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 218 | // Handle CreateDevice |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 219 | static void createDeviceRegisterExtensions(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 220 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 221 | VkLayerDispatchTable *pDisp = get_dispatch_table(unique_objects_device_table_map, device); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 222 | PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 223 | pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR)gpa(device, "vkCreateSwapchainKHR"); |
| 224 | pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR)gpa(device, "vkDestroySwapchainKHR"); |
| 225 | pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR)gpa(device, "vkGetSwapchainImagesKHR"); |
| 226 | pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR)gpa(device, "vkAcquireNextImageKHR"); |
| 227 | pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR)gpa(device, "vkQueuePresentKHR"); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 228 | my_device_data->wsi_enabled = false; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 229 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 230 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 231 | my_device_data->wsi_enabled = true; |
| 232 | } |
| 233 | } |
| 234 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 235 | VkResult explicit_CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 236 | VkDevice *pDevice) { |
Chia-I Wu | 1657047 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 237 | layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 238 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 239 | |
| 240 | assert(chain_info->u.pLayerInfo); |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 241 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 242 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
Chia-I Wu | 1657047 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 243 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 244 | if (fpCreateDevice == NULL) { |
| 245 | return VK_ERROR_INITIALIZATION_FAILED; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 246 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 247 | |
| 248 | // Advance the link info for the next element on the chain |
| 249 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 250 | |
| 251 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| 252 | if (result != VK_SUCCESS) { |
| 253 | return result; |
| 254 | } |
| 255 | |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 256 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); |
| 257 | my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); |
| 258 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 259 | // Setup layer's device dispatch table |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 260 | initDeviceTable(*pDevice, fpGetDeviceProcAddr, unique_objects_device_table_map); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 261 | |
| 262 | createDeviceRegisterExtensions(pCreateInfo, *pDevice); |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 263 | // Set gpu for this device in order to get at any objects mapped at instance level |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 264 | |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 265 | my_device_data->gpu = gpu; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 266 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 267 | return result; |
| 268 | } |
| 269 | |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 270 | void explicit_DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
Dustin Graves | 7b098da | 2016-04-29 11:55:43 -0600 | [diff] [blame] | 271 | dispatch_key key = get_dispatch_key(device); |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame^] | 272 | layer_debug_report_destroy_device(device); |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 273 | get_dispatch_table(unique_objects_device_table_map, device)->DestroyDevice(device, pAllocator); |
Dustin Graves | 7b098da | 2016-04-29 11:55:43 -0600 | [diff] [blame] | 274 | layer_data_map.erase(key); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Dustin Graves | 176f9df | 2016-07-14 17:28:11 -0600 | [diff] [blame] | 277 | VkResult explicit_AllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, |
| 278 | const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory) { |
| 279 | const VkMemoryAllocateInfo *input_allocate_info = pAllocateInfo; |
| 280 | std::unique_ptr<safe_VkMemoryAllocateInfo> safe_allocate_info; |
| 281 | std::unique_ptr<safe_VkDedicatedAllocationMemoryAllocateInfoNV> safe_dedicated_allocate_info; |
| 282 | layer_data *my_map_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 283 | |
| 284 | if ((pAllocateInfo != nullptr) && |
| 285 | ContainsExtStruct(pAllocateInfo, VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV)) { |
| 286 | // Assuming there is only one extension struct of this type in the list for now |
| 287 | safe_dedicated_allocate_info = |
| 288 | std::unique_ptr<safe_VkDedicatedAllocationMemoryAllocateInfoNV>(new safe_VkDedicatedAllocationMemoryAllocateInfoNV); |
| 289 | safe_allocate_info = std::unique_ptr<safe_VkMemoryAllocateInfo>(new safe_VkMemoryAllocateInfo); |
| 290 | |
| 291 | safe_allocate_info->initialize(pAllocateInfo); |
| 292 | input_allocate_info = reinterpret_cast<const VkMemoryAllocateInfo *>(safe_allocate_info.get()); |
| 293 | |
| 294 | const GenericHeader *orig_pnext = reinterpret_cast<const GenericHeader *>(pAllocateInfo->pNext); |
| 295 | GenericHeader *input_pnext = reinterpret_cast<GenericHeader *>(safe_allocate_info.get()); |
| 296 | while (orig_pnext != nullptr) { |
| 297 | if (orig_pnext->sType == VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV) { |
| 298 | safe_dedicated_allocate_info->initialize( |
| 299 | reinterpret_cast<const VkDedicatedAllocationMemoryAllocateInfoNV *>(orig_pnext)); |
| 300 | |
| 301 | std::unique_lock<std::mutex> lock(global_lock); |
| 302 | |
| 303 | if (safe_dedicated_allocate_info->buffer != VK_NULL_HANDLE) { |
| 304 | uint64_t local_buffer = reinterpret_cast<uint64_t &>(safe_dedicated_allocate_info->buffer); |
| 305 | safe_dedicated_allocate_info->buffer = |
| 306 | reinterpret_cast<VkBuffer &>(my_map_data->unique_id_mapping[local_buffer]); |
| 307 | } |
| 308 | |
| 309 | if (safe_dedicated_allocate_info->image != VK_NULL_HANDLE) { |
| 310 | uint64_t local_image = reinterpret_cast<uint64_t &>(safe_dedicated_allocate_info->image); |
| 311 | safe_dedicated_allocate_info->image = reinterpret_cast<VkImage &>(my_map_data->unique_id_mapping[local_image]); |
| 312 | } |
| 313 | |
| 314 | lock.unlock(); |
| 315 | |
| 316 | input_pnext->pNext = reinterpret_cast<GenericHeader *>(safe_dedicated_allocate_info.get()); |
| 317 | input_pnext = reinterpret_cast<GenericHeader *>(input_pnext->pNext); |
| 318 | } else { |
| 319 | // TODO: generic handling of pNext copies |
| 320 | } |
| 321 | |
| 322 | orig_pnext = reinterpret_cast<const GenericHeader *>(orig_pnext->pNext); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | VkResult result = get_dispatch_table(unique_objects_device_table_map, device) |
| 327 | ->AllocateMemory(device, input_allocate_info, pAllocator, pMemory); |
| 328 | |
| 329 | if (VK_SUCCESS == result) { |
| 330 | std::lock_guard<std::mutex> lock(global_lock); |
| 331 | uint64_t unique_id = global_unique_id++; |
| 332 | my_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*pMemory); |
| 333 | *pMemory = reinterpret_cast<VkDeviceMemory &>(unique_id); |
| 334 | } |
| 335 | |
| 336 | return result; |
| 337 | } |
| 338 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 339 | VkResult explicit_CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 340 | const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator, |
| 341 | VkPipeline *pPipelines) { |
| 342 | // STRUCT USES:{'pipelineCache': 'VkPipelineCache', 'pCreateInfos[createInfoCount]': {'stage': {'module': 'VkShaderModule'}, |
| 343 | // 'layout': 'VkPipelineLayout', 'basePipelineHandle': 'VkPipeline'}} |
| 344 | // LOCAL DECLS:{'pCreateInfos': 'VkComputePipelineCreateInfo*'} |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 345 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 346 | safe_VkComputePipelineCreateInfo *local_pCreateInfos = NULL; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 347 | if (pCreateInfos) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 348 | std::lock_guard<std::mutex> lock(global_lock); |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 349 | local_pCreateInfos = new safe_VkComputePipelineCreateInfo[createInfoCount]; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 350 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 351 | local_pCreateInfos[idx0].initialize(&pCreateInfos[idx0]); |
| 352 | if (pCreateInfos[idx0].basePipelineHandle) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 353 | local_pCreateInfos[idx0].basePipelineHandle = |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 354 | (VkPipeline)my_device_data |
| 355 | ->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].basePipelineHandle)]; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 356 | } |
| 357 | if (pCreateInfos[idx0].layout) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 358 | local_pCreateInfos[idx0].layout = |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 359 | (VkPipelineLayout) |
| 360 | my_device_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].layout)]; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 361 | } |
| 362 | if (pCreateInfos[idx0].stage.module) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 363 | local_pCreateInfos[idx0].stage.module = |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 364 | (VkShaderModule) |
| 365 | my_device_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].stage.module)]; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | } |
| 369 | if (pipelineCache) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 370 | std::lock_guard<std::mutex> lock(global_lock); |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 371 | pipelineCache = (VkPipelineCache)my_device_data->unique_id_mapping[reinterpret_cast<uint64_t &>(pipelineCache)]; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 372 | } |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 373 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 374 | VkResult result = get_dispatch_table(unique_objects_device_table_map, device) |
| 375 | ->CreateComputePipelines(device, pipelineCache, createInfoCount, |
| 376 | (const VkComputePipelineCreateInfo *)local_pCreateInfos, pAllocator, pPipelines); |
Eric Engestrom | 53b513f | 2016-02-21 19:58:09 +0000 | [diff] [blame] | 377 | delete[] local_pCreateInfos; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 378 | if (VK_SUCCESS == result) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 379 | uint64_t unique_id = 0; |
| 380 | std::lock_guard<std::mutex> lock(global_lock); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 381 | for (uint32_t i = 0; i < createInfoCount; ++i) { |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 382 | unique_id = global_unique_id++; |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 383 | my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pPipelines[i]); |
| 384 | pPipelines[i] = reinterpret_cast<VkPipeline &>(unique_id); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | return result; |
| 388 | } |
| 389 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 390 | VkResult explicit_CreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 391 | const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator, |
| 392 | VkPipeline *pPipelines) { |
| 393 | // STRUCT USES:{'pipelineCache': 'VkPipelineCache', 'pCreateInfos[createInfoCount]': {'layout': 'VkPipelineLayout', |
| 394 | // 'pStages[stageCount]': {'module': 'VkShaderModule'}, 'renderPass': 'VkRenderPass', 'basePipelineHandle': 'VkPipeline'}} |
| 395 | // LOCAL DECLS:{'pCreateInfos': 'VkGraphicsPipelineCreateInfo*'} |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 396 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 397 | safe_VkGraphicsPipelineCreateInfo *local_pCreateInfos = NULL; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 398 | if (pCreateInfos) { |
| 399 | local_pCreateInfos = new safe_VkGraphicsPipelineCreateInfo[createInfoCount]; |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 400 | std::lock_guard<std::mutex> lock(global_lock); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 401 | for (uint32_t idx0 = 0; idx0 < createInfoCount; ++idx0) { |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 402 | local_pCreateInfos[idx0].initialize(&pCreateInfos[idx0]); |
| 403 | if (pCreateInfos[idx0].basePipelineHandle) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 404 | local_pCreateInfos[idx0].basePipelineHandle = |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 405 | (VkPipeline)my_device_data |
| 406 | ->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].basePipelineHandle)]; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 407 | } |
| 408 | if (pCreateInfos[idx0].layout) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 409 | local_pCreateInfos[idx0].layout = |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 410 | (VkPipelineLayout) |
| 411 | my_device_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].layout)]; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 412 | } |
| 413 | if (pCreateInfos[idx0].pStages) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 414 | for (uint32_t idx1 = 0; idx1 < pCreateInfos[idx0].stageCount; ++idx1) { |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 415 | if (pCreateInfos[idx0].pStages[idx1].module) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 416 | local_pCreateInfos[idx0].pStages[idx1].module = |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 417 | (VkShaderModule)my_device_data |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 418 | ->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].pStages[idx1].module)]; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
| 422 | if (pCreateInfos[idx0].renderPass) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 423 | local_pCreateInfos[idx0].renderPass = |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 424 | (VkRenderPass) |
| 425 | my_device_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfos[idx0].renderPass)]; |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | } |
| 429 | if (pipelineCache) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 430 | std::lock_guard<std::mutex> lock(global_lock); |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 431 | pipelineCache = (VkPipelineCache)my_device_data->unique_id_mapping[reinterpret_cast<uint64_t &>(pipelineCache)]; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 432 | } |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 433 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 434 | VkResult result = |
| 435 | get_dispatch_table(unique_objects_device_table_map, device) |
| 436 | ->CreateGraphicsPipelines(device, pipelineCache, createInfoCount, |
| 437 | (const VkGraphicsPipelineCreateInfo *)local_pCreateInfos, pAllocator, pPipelines); |
Eric Engestrom | 53b513f | 2016-02-21 19:58:09 +0000 | [diff] [blame] | 438 | delete[] local_pCreateInfos; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 439 | if (VK_SUCCESS == result) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 440 | uint64_t unique_id = 0; |
| 441 | std::lock_guard<std::mutex> lock(global_lock); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 442 | for (uint32_t i = 0; i < createInfoCount; ++i) { |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 443 | unique_id = global_unique_id++; |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 444 | my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pPipelines[i]); |
| 445 | pPipelines[i] = reinterpret_cast<VkPipeline &>(unique_id); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | return result; |
| 449 | } |
| 450 | |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 451 | VkResult explicit_CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, |
| 452 | const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) { |
| 453 | layer_data *my_map_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
| 454 | |
| 455 | safe_VkSwapchainCreateInfoKHR *local_pCreateInfo = NULL; |
| 456 | if (pCreateInfo) { |
| 457 | std::lock_guard<std::mutex> lock(global_lock); |
| 458 | local_pCreateInfo = new safe_VkSwapchainCreateInfoKHR(pCreateInfo); |
| 459 | local_pCreateInfo->oldSwapchain = |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 460 | (VkSwapchainKHR)my_map_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfo->oldSwapchain)]; |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 461 | // Need to pull surface mapping from the instance-level map |
| 462 | layer_data *instance_data = get_my_data_ptr(get_dispatch_key(my_map_data->gpu), layer_data_map); |
| 463 | local_pCreateInfo->surface = |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 464 | (VkSurfaceKHR)instance_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pCreateInfo->surface)]; |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | VkResult result = get_dispatch_table(unique_objects_device_table_map, device) |
| 468 | ->CreateSwapchainKHR(device, (const VkSwapchainCreateInfoKHR *)local_pCreateInfo, pAllocator, pSwapchain); |
| 469 | if (local_pCreateInfo) |
| 470 | delete local_pCreateInfo; |
| 471 | if (VK_SUCCESS == result) { |
| 472 | std::lock_guard<std::mutex> lock(global_lock); |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 473 | uint64_t unique_id =global_unique_id++; |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 474 | my_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*pSwapchain); |
| 475 | *pSwapchain = reinterpret_cast<VkSwapchainKHR &>(unique_id); |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 476 | } |
| 477 | return result; |
| 478 | } |
| 479 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 480 | VkResult explicit_GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, |
| 481 | VkImage *pSwapchainImages) { |
| 482 | // UNWRAP USES: |
| 483 | // 0 : swapchain,VkSwapchainKHR, pSwapchainImages,VkImage |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 484 | layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 485 | if (VK_NULL_HANDLE != swapchain) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 486 | std::lock_guard<std::mutex> lock(global_lock); |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 487 | swapchain = (VkSwapchainKHR)my_device_data->unique_id_mapping[reinterpret_cast<uint64_t &>(swapchain)]; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 488 | } |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 489 | VkResult result = get_dispatch_table(unique_objects_device_table_map, device) |
| 490 | ->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 491 | // TODO : Need to add corresponding code to delete these images |
| 492 | if (VK_SUCCESS == result) { |
| 493 | if ((*pSwapchainImageCount > 0) && pSwapchainImages) { |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 494 | uint64_t unique_id = 0; |
| 495 | std::lock_guard<std::mutex> lock(global_lock); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 496 | for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) { |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 497 | unique_id = global_unique_id++; |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 498 | my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pSwapchainImages[i]); |
| 499 | pSwapchainImages[i] = reinterpret_cast<VkImage &>(unique_id); |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | } |
| 503 | return result; |
| 504 | } |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 505 | |
Jon Ashburn | bd84645 | 2016-06-30 10:21:55 -0600 | [diff] [blame] | 506 | #ifndef __ANDROID__ |
Jon Ashburn | 73a3435 | 2016-06-29 16:12:51 -0600 | [diff] [blame] | 507 | VkResult explicit_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPropertiesKHR* pProperties) |
| 508 | { |
| 509 | layer_data *my_map_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 510 | safe_VkDisplayPropertiesKHR* local_pProperties = NULL; |
| 511 | { |
| 512 | std::lock_guard<std::mutex> lock(global_lock); |
| 513 | if (pProperties) { |
| 514 | local_pProperties = new safe_VkDisplayPropertiesKHR[*pPropertyCount]; |
| 515 | for (uint32_t idx0=0; idx0<*pPropertyCount; ++idx0) { |
| 516 | local_pProperties[idx0].initialize(&pProperties[idx0]); |
| 517 | if (pProperties[idx0].display) { |
| 518 | local_pProperties[idx0].display = (VkDisplayKHR)my_map_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(pProperties[idx0].display)]; |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | VkResult result = get_dispatch_table(unique_objects_instance_table_map, physicalDevice)->GetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, pPropertyCount, ( VkDisplayPropertiesKHR*)local_pProperties); |
| 525 | if (result == VK_SUCCESS && pProperties) |
| 526 | { |
| 527 | for (uint32_t idx0=0; idx0<*pPropertyCount; ++idx0) { |
| 528 | std::lock_guard<std::mutex> lock(global_lock); |
| 529 | |
| 530 | uint64_t unique_id = global_unique_id++; |
| 531 | my_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(local_pProperties[idx0].display); |
| 532 | pProperties[idx0].display = reinterpret_cast<VkDisplayKHR&>(unique_id); |
| 533 | pProperties[idx0].displayName = local_pProperties[idx0].displayName; |
| 534 | pProperties[idx0].physicalDimensions = local_pProperties[idx0].physicalDimensions; |
| 535 | pProperties[idx0].physicalResolution = local_pProperties[idx0].physicalResolution; |
| 536 | pProperties[idx0].supportedTransforms = local_pProperties[idx0].supportedTransforms; |
| 537 | pProperties[idx0].planeReorderPossible = local_pProperties[idx0].planeReorderPossible; |
| 538 | pProperties[idx0].persistentContent = local_pProperties[idx0].persistentContent; |
| 539 | } |
| 540 | } |
| 541 | if (local_pProperties) |
| 542 | delete[] local_pProperties; |
| 543 | return result; |
| 544 | } |
| 545 | |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 546 | VkResult explicit_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) |
| 547 | { |
| 548 | layer_data *my_map_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 549 | VkResult result = get_dispatch_table(unique_objects_instance_table_map, physicalDevice)->GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, pDisplays); |
| 550 | if (VK_SUCCESS == result) { |
| 551 | if ((*pDisplayCount > 0) && pDisplays) { |
| 552 | std::lock_guard<std::mutex> lock(global_lock); |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 553 | for (uint32_t i = 0; i < *pDisplayCount; i++) { |
Jon Ashburn | bd84645 | 2016-06-30 10:21:55 -0600 | [diff] [blame] | 554 | auto it = my_map_data->unique_id_mapping.find(reinterpret_cast<const uint64_t &> (pDisplays[i])); |
Jon Ashburn | 73a3435 | 2016-06-29 16:12:51 -0600 | [diff] [blame] | 555 | assert (it != my_map_data->unique_id_mapping.end()); |
Jon Ashburn | bd84645 | 2016-06-30 10:21:55 -0600 | [diff] [blame] | 556 | pDisplays[i] = reinterpret_cast<VkDisplayKHR&> (it->second); |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | } |
| 560 | return result; |
| 561 | } |
Jon Ashburn | 32e042d | 2016-06-28 14:46:12 -0600 | [diff] [blame] | 562 | |
| 563 | |
| 564 | VkResult explicit_GetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModePropertiesKHR* pProperties) |
| 565 | { |
| 566 | layer_data *my_map_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map); |
| 567 | safe_VkDisplayModePropertiesKHR* local_pProperties = NULL; |
| 568 | { |
| 569 | std::lock_guard<std::mutex> lock(global_lock); |
| 570 | display = (VkDisplayKHR)my_map_data->unique_id_mapping[reinterpret_cast<uint64_t &>(display)]; |
| 571 | if (pProperties) { |
| 572 | local_pProperties = new safe_VkDisplayModePropertiesKHR[*pPropertyCount]; |
| 573 | for (uint32_t idx0=0; idx0<*pPropertyCount; ++idx0) { |
| 574 | local_pProperties[idx0].initialize(&pProperties[idx0]); |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | VkResult result = get_dispatch_table(unique_objects_instance_table_map, physicalDevice)->GetDisplayModePropertiesKHR(physicalDevice, display, pPropertyCount, ( VkDisplayModePropertiesKHR*)local_pProperties); |
| 580 | if (result == VK_SUCCESS && pProperties) |
| 581 | { |
| 582 | for (uint32_t idx0=0; idx0<*pPropertyCount; ++idx0) { |
| 583 | std::lock_guard<std::mutex> lock(global_lock); |
| 584 | |
| 585 | uint64_t unique_id = global_unique_id++; |
| 586 | my_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(local_pProperties[idx0].displayMode); |
| 587 | pProperties[idx0].displayMode = reinterpret_cast<VkDisplayModeKHR&>(unique_id); |
| 588 | pProperties[idx0].parameters.visibleRegion.width = local_pProperties[idx0].parameters.visibleRegion.width; |
| 589 | pProperties[idx0].parameters.visibleRegion.height = local_pProperties[idx0].parameters.visibleRegion.height; |
| 590 | pProperties[idx0].parameters.refreshRate = local_pProperties[idx0].parameters.refreshRate; |
| 591 | } |
| 592 | } |
| 593 | if (local_pProperties) |
| 594 | delete[] local_pProperties; |
| 595 | return result; |
| 596 | } |
Jon Ashburn | bd84645 | 2016-06-30 10:21:55 -0600 | [diff] [blame] | 597 | #endif |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 598 | } // namespace unique_objects |