2 * Copyright (c) 2018-2019 Arm Limited.
4 * SPDX-License-Identifier: MIT
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include "private_data.hpp"
31 using scoped_mutex = std::lock_guard<std::mutex>;
36 static std::mutex g_data_lock;
37 static std::map<void *, instance_private_data *> g_instance_data;
38 static std::map<void *, device_private_data *> g_device_data;
40 instance_private_data::instance_private_data(VkInstance inst, PFN_vkGetInstanceProcAddr get_proc,
41 PFN_vkSetInstanceLoaderData set_loader_data)
42 : disp(inst, get_proc)
43 , SetInstanceLoaderData(set_loader_data)
47 instance_private_data &instance_private_data::create(VkInstance inst, PFN_vkGetInstanceProcAddr get_proc,
48 PFN_vkSetInstanceLoaderData set_loader_data)
50 instance_private_data *inst_data = new instance_private_data(inst, get_proc, set_loader_data);
51 scoped_mutex lock(g_data_lock);
52 g_instance_data[get_key(inst)] = inst_data;
56 instance_private_data &instance_private_data::get(void *key)
58 scoped_mutex lock(g_data_lock);
59 instance_private_data *data = g_instance_data[key];
64 void instance_private_data::destroy(VkInstance inst)
66 instance_private_data *data;
68 scoped_mutex lock(g_data_lock);
69 data = g_instance_data[get_key(inst)];
71 g_instance_data.erase(get_key(inst));
76 device_private_data::device_private_data(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
77 instance_private_data &inst_data, PFN_vkSetDeviceLoaderData set_loader_data)
79 , instance_data(inst_data)
80 , SetDeviceLoaderData(set_loader_data)
84 device_private_data &device_private_data::create(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
85 VkPhysicalDevice phys_dev, PFN_vkSetDeviceLoaderData set_loader_data)
87 device_private_data *dev_data =
88 new device_private_data(dev, get_proc, instance_private_data::get(get_key(phys_dev)), set_loader_data);
89 scoped_mutex lock(g_data_lock);
90 g_device_data[get_key(dev)] = dev_data;
93 device_private_data &device_private_data::get(void *key)
95 scoped_mutex lock(g_data_lock);
96 device_private_data *data = g_device_data[key];
101 void device_private_data::destroy(VkDevice dev)
103 device_private_data *data;
105 scoped_mutex lock(g_data_lock);
106 data = g_device_data[get_key(dev)];
107 g_device_data.erase(get_key(dev));
112 } /* namespace layer */