blob: 85d35fe02815f8cedaf59e1886191f25139fe5b2 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* 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 Ehlisd34a4c52015-12-08 10:50:10 -07005 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06006 * 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 Ehlisd34a4c52015-12-08 10:50:10 -07009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * 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 Ehlisd34a4c52015-12-08 10:50:10 -070017 *
18 * Author: Tobin Ehlis <tobine@google.com>
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -060019 * Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070020 */
21
Jamie Madilldf5d5732016-04-04 11:54:43 -040022#include "vulkan/vulkan.h"
23
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070024#include "vk_layer_data.h"
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -070025#include "vk_safe_struct.h"
Jon Ashburndc9111c2016-03-22 12:57:13 -060026#include "vk_layer_utils.h"
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -060027#include "mutex"
28
29#pragma once
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070030
Chia-I Wucdb70962016-05-13 14:07:36 +080031namespace unique_objects {
32
Mark Lobodzinskid4bf1672017-01-25 09:56:02 -070033// The clang-format utility does not handle non-delimited strings well at all
34// clang-format off
35
Mark Lobodzinskice1d1f72016-08-26 08:48:02 -060036// The display-server-specific WSI extensions are handled explicitly
37static 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 Lobodzinski52c89ba2016-09-27 08:59:49 -060059 VK_KHR_SURFACE_EXTENSION_NAME
60 VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
Lenny Komow2a193cc2017-01-25 13:35:01 -070061 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 Lobodzinskice1d1f72016-08-26 08:48:02 -060065
66static 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 Lobodzinski52c89ba2016-09-27 08:59:49 -060077 VK_NV_GLSL_SHADER_EXTENSION_NAME
78 VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME
Mark Lobodzinski3c0f7512016-10-03 08:17:59 -060079 VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME
Mark Lobodzinski52c89ba2016-09-27 08:59:49 -060080 VK_AMD_GPU_SHADER_HALF_FLOAT_EXTENSION_NAME
Mark Lobodzinski3c0f7512016-10-03 08:17:59 -060081 VK_AMD_SHADER_BALLOT_EXTENSION_NAME
Mark Lobodzinski52c89ba2016-09-27 08:59:49 -060082 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 Komow2a193cc2017-01-25 13:35:01 -070087 VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME
88 VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
89 VK_EXT_DISPLAY_CONTROL_EXTENSION_NAME;
Mark Lobodzinskice1d1f72016-08-26 08:48:02 -060090
Mark Lobodzinskid4bf1672017-01-25 09:56:02 -070091// clang-format on
92
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -060093// All increments must be guarded by global_lock
94static uint64_t global_unique_id = 1;
95
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070096struct layer_data {
Chia-I Wu16570472016-05-17 07:57:15 +080097 VkInstance instance;
98
Mark Lobodzinski8a2305d2016-08-25 14:49:38 -060099 debug_report_data *report_data;
100 std::vector<VkDebugReportCallbackEXT> logging_callback;
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -0600101 VkLayerDispatchTable *device_dispatch_table;
102 VkLayerInstanceDispatchTable *instance_dispatch_table;
Mark Lobodzinski8a2305d2016-08-25 14:49:38 -0600103
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 Ehlisd34a4c52015-12-08 10:50:10 -0700110 bool wsi_enabled;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700111 std::unordered_map<uint64_t, uint64_t> unique_id_mapping; // Map uniqueID to actual object handle
Tobin Ehlis10ba1de2016-04-13 12:59:43 -0600112 VkPhysicalDevice gpu;
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700113
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -0600114 layer_data() : wsi_enabled(false), gpu(VK_NULL_HANDLE){};
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700115};
116
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600117struct instance_extension_enables {
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700118 bool wsi_enabled;
Tobin Ehlisa39c26a2016-01-05 16:34:59 -0700119 bool xlib_enabled;
120 bool xcb_enabled;
121 bool wayland_enabled;
122 bool mir_enabled;
123 bool android_enabled;
124 bool win32_enabled;
Jon Ashburn5e026df2016-06-15 08:19:07 -0600125 bool display_enabled;
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700126};
127
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -0600128static std::unordered_map<void *, struct instance_extension_enables> instance_ext_map;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700129static std::unordered_map<void *, layer_data *> layer_data_map;
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -0600130
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700131static std::mutex global_lock; // Protect map accesses and unique_id increments
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700132
Dustin Graves176f9df2016-07-14 17:28:11 -0600133struct GenericHeader {
134 VkStructureType sType;
135 void *pNext;
136};
137
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700138template <typename T>
139bool ContainsExtStruct(const T *target, VkStructureType ext_type) {
Dustin Graves176f9df2016-07-14 17:28:11 -0600140 assert(target != nullptr);
141
142 const GenericHeader *ext_struct = reinterpret_cast<const GenericHeader *>(target->pNext);
143
144 while (ext_struct != nullptr) {
145 if (ext_struct->sType == ext_type) {
146 return true;
147 }
148
149 ext_struct = reinterpret_cast<const GenericHeader *>(ext_struct->pNext);
150 }
151
152 return false;
153}
154
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700155} // namespace unique_objects