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> |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame^] | 19 | * Author: Mark Lobodzinski <mark@lunarg.com> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Jamie Madill | df5d573 | 2016-04-04 11:54:43 -0400 | [diff] [blame] | 22 | #include "vulkan/vulkan.h" |
| 23 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 24 | #include "vk_layer_data.h" |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 25 | #include "vk_safe_struct.h" |
Jon Ashburn | dc9111c | 2016-03-22 12:57:13 -0600 | [diff] [blame] | 26 | #include "vk_layer_utils.h" |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame^] | 27 | #include "mutex" |
| 28 | |
| 29 | #pragma once |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 30 | |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 31 | namespace unique_objects { |
| 32 | |
Mark Lobodzinski | ce1d1f7 | 2016-08-26 08:48:02 -0600 | [diff] [blame] | 33 | // The display-server-specific WSI extensions are handled explicitly |
| 34 | static const char *kUniqueObjectsSupportedInstanceExtensions = |
| 35 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 36 | VK_KHR_XLIB_SURFACE_EXTENSION_NAME |
| 37 | #endif |
| 38 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 39 | VK_KHR_XCB_SURFACE_EXTENSION_NAME |
| 40 | #endif |
| 41 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 42 | VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME |
| 43 | #endif |
| 44 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 45 | VK_KHR_MIR_SURFACE_EXTENSION_NAME |
| 46 | #endif |
| 47 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 48 | VK_KHR_ANDROID_SURFACE_EXTENSION_NAME |
| 49 | #endif |
| 50 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 51 | VK_KHR_WIN32_SURFACE_EXTENSION_NAME |
| 52 | #endif |
| 53 | VK_EXT_DEBUG_MARKER_EXTENSION_NAME |
| 54 | VK_EXT_DEBUG_REPORT_EXTENSION_NAME |
| 55 | VK_KHR_DISPLAY_EXTENSION_NAME |
Mark Lobodzinski | 52c89ba | 2016-09-27 08:59:49 -0600 | [diff] [blame] | 56 | VK_KHR_SURFACE_EXTENSION_NAME |
| 57 | VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME |
| 58 | VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME; |
Mark Lobodzinski | ce1d1f7 | 2016-08-26 08:48:02 -0600 | [diff] [blame] | 59 | |
| 60 | static const char *kUniqueObjectsSupportedDeviceExtensions = |
| 61 | VK_AMD_RASTERIZATION_ORDER_EXTENSION_NAME |
| 62 | VK_AMD_SHADER_TRINARY_MINMAX_EXTENSION_NAME |
| 63 | VK_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER_EXTENSION_NAME |
| 64 | VK_AMD_GCN_SHADER_EXTENSION_NAME |
| 65 | VK_IMG_FILTER_CUBIC_EXTENSION_NAME |
| 66 | VK_IMG_FORMAT_PVRTC_EXTENSION_NAME |
| 67 | VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME |
| 68 | VK_KHR_SWAPCHAIN_EXTENSION_NAME |
| 69 | VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME |
| 70 | VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME |
Mark Lobodzinski | 52c89ba | 2016-09-27 08:59:49 -0600 | [diff] [blame] | 71 | VK_NV_GLSL_SHADER_EXTENSION_NAME |
| 72 | VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME |
Mark Lobodzinski | 3c0f751 | 2016-10-03 08:17:59 -0600 | [diff] [blame] | 73 | VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME |
Mark Lobodzinski | 52c89ba | 2016-09-27 08:59:49 -0600 | [diff] [blame] | 74 | VK_AMD_GPU_SHADER_HALF_FLOAT_EXTENSION_NAME |
Mark Lobodzinski | 3c0f751 | 2016-10-03 08:17:59 -0600 | [diff] [blame] | 75 | VK_AMD_SHADER_BALLOT_EXTENSION_NAME |
Mark Lobodzinski | 52c89ba | 2016-09-27 08:59:49 -0600 | [diff] [blame] | 76 | VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME |
| 77 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 78 | VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME |
| 79 | VK_NV_WIN32_KEYED_MUTEX_EXTENSION_NAME |
| 80 | #endif |
| 81 | VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME; |
Mark Lobodzinski | ce1d1f7 | 2016-08-26 08:48:02 -0600 | [diff] [blame] | 82 | |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 83 | // All increments must be guarded by global_lock |
| 84 | static uint64_t global_unique_id = 1; |
| 85 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 86 | struct layer_data { |
Chia-I Wu | 1657047 | 2016-05-17 07:57:15 +0800 | [diff] [blame] | 87 | VkInstance instance; |
| 88 | |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame] | 89 | debug_report_data *report_data; |
| 90 | std::vector<VkDebugReportCallbackEXT> logging_callback; |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame^] | 91 | VkLayerDispatchTable *device_dispatch_table; |
| 92 | VkLayerInstanceDispatchTable *instance_dispatch_table; |
Mark Lobodzinski | 8a2305d | 2016-08-25 14:49:38 -0600 | [diff] [blame] | 93 | |
| 94 | // The following are for keeping track of the temporary callbacks that can |
| 95 | // be used in vkCreateInstance and vkDestroyInstance: |
| 96 | uint32_t num_tmp_callbacks; |
| 97 | VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos; |
| 98 | VkDebugReportCallbackEXT *tmp_callbacks; |
| 99 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 100 | bool wsi_enabled; |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 101 | std::unordered_map<uint64_t, uint64_t> unique_id_mapping; // Map uniqueID to actual object handle |
| 102 | VkPhysicalDevice gpu; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 103 | |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 104 | layer_data() : wsi_enabled(false), gpu(VK_NULL_HANDLE){}; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 107 | struct instance_extension_enables { |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 108 | bool wsi_enabled; |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 109 | bool xlib_enabled; |
| 110 | bool xcb_enabled; |
| 111 | bool wayland_enabled; |
| 112 | bool mir_enabled; |
| 113 | bool android_enabled; |
| 114 | bool win32_enabled; |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 115 | bool display_enabled; |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame^] | 118 | static std::unordered_map<void *, struct instance_extension_enables> instance_ext_map; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 119 | static std::unordered_map<void *, layer_data *> layer_data_map; |
Mark Lobodzinski | dc3bd85 | 2016-09-06 16:12:23 -0600 | [diff] [blame^] | 120 | |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 121 | static std::mutex global_lock; // Protect map accesses and unique_id increments |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 122 | |
Dustin Graves | 176f9df | 2016-07-14 17:28:11 -0600 | [diff] [blame] | 123 | struct GenericHeader { |
| 124 | VkStructureType sType; |
| 125 | void *pNext; |
| 126 | }; |
| 127 | |
| 128 | template <typename T> bool ContainsExtStruct(const T *target, VkStructureType ext_type) { |
| 129 | assert(target != nullptr); |
| 130 | |
| 131 | const GenericHeader *ext_struct = reinterpret_cast<const GenericHeader *>(target->pNext); |
| 132 | |
| 133 | while (ext_struct != nullptr) { |
| 134 | if (ext_struct->sType == ext_type) { |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | ext_struct = reinterpret_cast<const GenericHeader *>(ext_struct->pNext); |
| 139 | } |
| 140 | |
| 141 | return false; |
| 142 | } |
| 143 | |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 144 | } // namespace unique_objects |