2 * Copyright (c) 2019, 2021 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
25 #include "extension_list.hpp"
26 #include <layer/private_data.hpp>
33 extension_list::extension_list(const util::allocator& allocator)
35 , m_ext_props(allocator)
39 VkResult extension_list::add(const struct VkEnumerateInstanceExtensionPropertiesChain *chain)
42 VkResult m_error = chain->CallDown(nullptr, &count, nullptr);
43 if (m_error == VK_SUCCESS)
45 if (!m_ext_props.try_resize(count))
47 return VK_ERROR_OUT_OF_HOST_MEMORY;
49 m_error = chain->CallDown(nullptr, &count, m_ext_props.data());
54 VkResult extension_list::add(VkPhysicalDevice dev)
56 layer::instance_private_data &inst_data = layer::instance_private_data::get(layer::get_key(dev));
58 VkResult m_error = inst_data.disp.EnumerateDeviceExtensionProperties(dev, nullptr, &count, nullptr);
60 if (m_error == VK_SUCCESS)
62 if (!m_ext_props.try_resize(count))
64 return VK_ERROR_OUT_OF_HOST_MEMORY;
66 m_error = inst_data.disp.EnumerateDeviceExtensionProperties(dev, nullptr, &count, m_ext_props.data());
71 VkResult extension_list::add(PFN_vkEnumerateInstanceExtensionProperties fpEnumerateInstanceExtensionProperties)
74 VkResult m_error = fpEnumerateInstanceExtensionProperties(nullptr, &count, nullptr);
76 if (m_error == VK_SUCCESS)
78 if (!m_ext_props.try_resize(count))
80 return VK_ERROR_OUT_OF_HOST_MEMORY;
82 m_error = fpEnumerateInstanceExtensionProperties(nullptr, &count, m_ext_props.data());
87 VkResult extension_list::add(const char *const *extensions, uint32_t count)
89 for (uint32_t i = 0; i < count; i++)
91 VkExtensionProperties props = {};
92 strncpy(props.extensionName, extensions[i], sizeof(props.extensionName));
93 if (!m_ext_props.try_push_back(props))
95 return VK_ERROR_OUT_OF_HOST_MEMORY;
101 VkResult extension_list::add(const VkExtensionProperties *props, uint32_t count)
103 if (!m_ext_props.try_push_back_many(props, props + count))
105 return VK_ERROR_OUT_OF_HOST_MEMORY;
110 VkResult extension_list::add(const char *ext)
114 VkExtensionProperties props = {};
115 strncpy(props.extensionName, ext, sizeof(props.extensionName));
116 if (!m_ext_props.try_push_back(props))
118 return VK_ERROR_OUT_OF_HOST_MEMORY;
124 VkResult extension_list::add(VkExtensionProperties ext_prop)
126 if (!contains(ext_prop.extensionName))
128 if (!m_ext_props.try_push_back(ext_prop))
130 return VK_ERROR_OUT_OF_HOST_MEMORY;
136 VkResult extension_list::add(const char **ext_list, uint32_t count)
138 for (uint32_t i = 0; i < count; i++)
140 if (add(ext_list[i]) != VK_SUCCESS)
142 return VK_ERROR_OUT_OF_HOST_MEMORY;
148 VkResult extension_list::add(const extension_list &ext_list)
150 util::vector<VkExtensionProperties> ext_vect = ext_list.get_extension_props();
151 for (auto &ext : ext_vect)
153 if (add(ext) != VK_SUCCESS)
155 return VK_ERROR_OUT_OF_HOST_MEMORY;
161 bool extension_list::get_extension_strings(util::vector<const char*> &out) const
163 size_t old_size = out.size();
164 size_t new_size = old_size + m_ext_props.size();
165 if (!out.try_resize(new_size))
170 for (size_t i = old_size; i < new_size; i++)
172 out[i] = m_ext_props[i - old_size].extensionName;
177 bool extension_list::contains(const extension_list &req) const
179 for (const auto &req_ext : req.m_ext_props)
181 if (!contains(req_ext.extensionName))
189 bool extension_list::contains(const char *extension_name) const
191 for (const auto &p : m_ext_props)
193 if (strcmp(p.extensionName, extension_name) == 0)
201 void extension_list::remove(const char *ext)
203 m_ext_props.erase(std::remove_if(m_ext_props.begin(), m_ext_props.end(), [&ext](VkExtensionProperties ext_prop) {
204 return (strcmp(ext_prop.extensionName, ext) == 0);