blob: a0fe99e4cc116a848b010a05f36a5ec9c2cdc5ce [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 Lobodzinskice1d1f72016-08-26 08:48:02 -060033// The display-server-specific WSI extensions are handled explicitly
34static 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 Lobodzinski52c89ba2016-09-27 08:59:49 -060056 VK_KHR_SURFACE_EXTENSION_NAME
57 VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
58 VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME;
Mark Lobodzinskice1d1f72016-08-26 08:48:02 -060059
60static 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 Lobodzinski52c89ba2016-09-27 08:59:49 -060071 VK_NV_GLSL_SHADER_EXTENSION_NAME
72 VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME
Mark Lobodzinski3c0f7512016-10-03 08:17:59 -060073 VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME
Mark Lobodzinski52c89ba2016-09-27 08:59:49 -060074 VK_AMD_GPU_SHADER_HALF_FLOAT_EXTENSION_NAME
Mark Lobodzinski3c0f7512016-10-03 08:17:59 -060075 VK_AMD_SHADER_BALLOT_EXTENSION_NAME
Mark Lobodzinski52c89ba2016-09-27 08:59:49 -060076 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 Lobodzinskice1d1f72016-08-26 08:48:02 -060082
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -060083// All increments must be guarded by global_lock
84static uint64_t global_unique_id = 1;
85
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070086struct layer_data {
Chia-I Wu16570472016-05-17 07:57:15 +080087 VkInstance instance;
88
Mark Lobodzinski8a2305d2016-08-25 14:49:38 -060089 debug_report_data *report_data;
90 std::vector<VkDebugReportCallbackEXT> logging_callback;
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -060091 VkLayerDispatchTable *device_dispatch_table;
92 VkLayerInstanceDispatchTable *instance_dispatch_table;
Mark Lobodzinski8a2305d2016-08-25 14:49:38 -060093
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 Ehlisd34a4c52015-12-08 10:50:10 -0700100 bool wsi_enabled;
Tobin Ehlis10ba1de2016-04-13 12:59:43 -0600101 std::unordered_map<uint64_t, uint64_t> unique_id_mapping; // Map uniqueID to actual object handle
102 VkPhysicalDevice gpu;
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700103
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -0600104 layer_data() : wsi_enabled(false), gpu(VK_NULL_HANDLE){};
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700105};
106
Mark Lobodzinskife1f0662016-06-24 09:57:32 -0600107struct instance_extension_enables {
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700108 bool wsi_enabled;
Tobin Ehlisa39c26a2016-01-05 16:34:59 -0700109 bool xlib_enabled;
110 bool xcb_enabled;
111 bool wayland_enabled;
112 bool mir_enabled;
113 bool android_enabled;
114 bool win32_enabled;
Jon Ashburn5e026df2016-06-15 08:19:07 -0600115 bool display_enabled;
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700116};
117
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -0600118static std::unordered_map<void *, struct instance_extension_enables> instance_ext_map;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700119static std::unordered_map<void *, layer_data *> layer_data_map;
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -0600120
Tobin Ehlis10ba1de2016-04-13 12:59:43 -0600121static std::mutex global_lock; // Protect map accesses and unique_id increments
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700122
Dustin Graves176f9df2016-07-14 17:28:11 -0600123struct GenericHeader {
124 VkStructureType sType;
125 void *pNext;
126};
127
128template <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 Wucdb70962016-05-13 14:07:36 +0800144} // namespace unique_objects