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