blob: 76420a6cb5ef015173014eb78e9063f68db1bcd7 [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 Lobodzinskifdf8f472016-04-28 16:36:58 -060033// All increments must be guarded by global_lock
34static uint64_t global_unique_id = 1;
35
Mark Lobodzinski4f3ce672017-03-03 10:28:21 -070036struct TEMPLATE_STATE {
37 VkDescriptorUpdateTemplateKHR desc_update_template;
38 safe_VkDescriptorUpdateTemplateCreateInfoKHR create_info;
39
40 TEMPLATE_STATE(VkDescriptorUpdateTemplateKHR update_template, safe_VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo)
41 : desc_update_template(update_template), create_info(*pCreateInfo) {}
42};
43
Chris Forbes5279a8c2017-05-02 16:26:23 -070044struct instance_layer_data {
Chia-I Wu16570472016-05-17 07:57:15 +080045 VkInstance instance;
46
Mark Lobodzinski8a2305d2016-08-25 14:49:38 -060047 debug_report_data *report_data;
48 std::vector<VkDebugReportCallbackEXT> logging_callback;
Chris Forbes5279a8c2017-05-02 16:26:23 -070049 VkLayerInstanceDispatchTable *dispatch_table;
Mark Lobodzinski8a2305d2016-08-25 14:49:38 -060050
51 // The following are for keeping track of the temporary callbacks that can
52 // be used in vkCreateInstance and vkDestroyInstance:
53 uint32_t num_tmp_callbacks;
54 VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos;
55 VkDebugReportCallbackEXT *tmp_callbacks;
56
Chris Forbes5279a8c2017-05-02 16:26:23 -070057 bool wsi_enabled;
58 std::unordered_map<uint64_t, uint64_t> unique_id_mapping; // Map uniqueID to actual object handle
59 VkPhysicalDevice gpu;
60
61 instance_layer_data() : wsi_enabled(false), gpu(VK_NULL_HANDLE){};
62};
63
64struct layer_data {
65 VkInstance instance;
66
67 debug_report_data *report_data;
68 VkLayerDispatchTable *dispatch_table;
69
Mark Lobodzinski4f3ce672017-03-03 10:28:21 -070070 std::unordered_map<uint64_t, std::unique_ptr<TEMPLATE_STATE>> desc_template_map;
71
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070072 bool wsi_enabled;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070073 std::unordered_map<uint64_t, uint64_t> unique_id_mapping; // Map uniqueID to actual object handle
Tobin Ehlis10ba1de2016-04-13 12:59:43 -060074 VkPhysicalDevice gpu;
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070075
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -060076 layer_data() : wsi_enabled(false), gpu(VK_NULL_HANDLE){};
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070077};
78
Mark Lobodzinskife1f0662016-06-24 09:57:32 -060079struct instance_extension_enables {
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070080 bool wsi_enabled;
Tobin Ehlisa39c26a2016-01-05 16:34:59 -070081 bool xlib_enabled;
82 bool xcb_enabled;
83 bool wayland_enabled;
84 bool mir_enabled;
85 bool android_enabled;
86 bool win32_enabled;
Jon Ashburn5e026df2016-06-15 08:19:07 -060087 bool display_enabled;
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070088};
89
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -060090static std::unordered_map<void *, struct instance_extension_enables> instance_ext_map;
Chris Forbes5279a8c2017-05-02 16:26:23 -070091static std::unordered_map<void *, instance_layer_data *> instance_layer_data_map;
Jon Ashburn5484e0c2016-03-08 17:48:44 -070092static std::unordered_map<void *, layer_data *> layer_data_map;
Mark Lobodzinskidc3bd852016-09-06 16:12:23 -060093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static std::mutex global_lock; // Protect map accesses and unique_id increments
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070095
Dustin Graves176f9df2016-07-14 17:28:11 -060096struct GenericHeader {
97 VkStructureType sType;
98 void *pNext;
99};
100
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700101template <typename T>
102bool ContainsExtStruct(const T *target, VkStructureType ext_type) {
Dustin Graves176f9df2016-07-14 17:28:11 -0600103 assert(target != nullptr);
104
105 const GenericHeader *ext_struct = reinterpret_cast<const GenericHeader *>(target->pNext);
106
107 while (ext_struct != nullptr) {
108 if (ext_struct->sType == ext_type) {
109 return true;
110 }
111
112 ext_struct = reinterpret_cast<const GenericHeader *>(ext_struct->pNext);
113 }
114
115 return false;
116}
117
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118} // namespace unique_objects