mirror of
https://gitlab.freedesktop.org/mesa/vulkan-wsi-layer.git
synced 2025-12-20 04:30:11 +01:00
Refactoring of extension_list
Unused methods removed. Specialised methods moved out of the extension_list utility and closer to the point of usage. Signed-off-by: Fufu Fang <fufu.fang@arm.com> Change-Id: I8e6d2786881b5306de21797cfdda46d0e678da8d
This commit is contained in:
parent
af2af23333
commit
b64498c021
6 changed files with 72 additions and 125 deletions
|
|
@ -267,9 +267,10 @@ VKAPI_ATTR VkResult create_device(VkPhysicalDevice physicalDevice, const VkDevic
|
|||
}
|
||||
|
||||
util::vector<const char *> modified_enabled_extensions{allocator};
|
||||
if (!enabled_extensions.get_extension_strings(modified_enabled_extensions))
|
||||
result = enabled_extensions.get_extension_strings(modified_enabled_extensions);
|
||||
if (result != VK_SUCCESS)
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Now call create device on the chain further down the list. */
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
#include "extension_list.hpp"
|
||||
#include "util/custom_allocator.hpp"
|
||||
#include <layer/private_data.hpp>
|
||||
#include <string.h>
|
||||
#include <cassert>
|
||||
|
|
@ -36,87 +37,17 @@ extension_list::extension_list(const util::allocator& allocator)
|
|||
{
|
||||
}
|
||||
|
||||
VkResult extension_list::add(const struct VkEnumerateInstanceExtensionPropertiesChain *chain)
|
||||
{
|
||||
uint32_t count;
|
||||
VkResult m_error = chain->CallDown(nullptr, &count, nullptr);
|
||||
if (m_error == VK_SUCCESS)
|
||||
{
|
||||
if (!m_ext_props.try_resize(count))
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
m_error = chain->CallDown(nullptr, &count, m_ext_props.data());
|
||||
}
|
||||
return m_error;
|
||||
}
|
||||
|
||||
VkResult extension_list::add(VkPhysicalDevice dev)
|
||||
{
|
||||
layer::instance_private_data &inst_data = layer::instance_private_data::get(dev);
|
||||
uint32_t count;
|
||||
VkResult m_error = inst_data.disp.EnumerateDeviceExtensionProperties(dev, nullptr, &count, nullptr);
|
||||
|
||||
if (m_error == VK_SUCCESS)
|
||||
{
|
||||
if (!m_ext_props.try_resize(count))
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
m_error = inst_data.disp.EnumerateDeviceExtensionProperties(dev, nullptr, &count, m_ext_props.data());
|
||||
}
|
||||
return m_error;
|
||||
}
|
||||
|
||||
VkResult extension_list::add(PFN_vkEnumerateInstanceExtensionProperties fpEnumerateInstanceExtensionProperties)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
VkResult m_error = fpEnumerateInstanceExtensionProperties(nullptr, &count, nullptr);
|
||||
|
||||
if (m_error == VK_SUCCESS)
|
||||
{
|
||||
if (!m_ext_props.try_resize(count))
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
m_error = fpEnumerateInstanceExtensionProperties(nullptr, &count, m_ext_props.data());
|
||||
}
|
||||
return m_error;
|
||||
}
|
||||
|
||||
VkResult extension_list::add(const char *const *extensions, uint32_t count)
|
||||
{
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
{
|
||||
VkExtensionProperties props = {};
|
||||
strncpy(props.extensionName, extensions[i], sizeof(props.extensionName));
|
||||
if (!m_ext_props.try_push_back(props))
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult extension_list::add(const VkExtensionProperties *props, uint32_t count)
|
||||
{
|
||||
if (!m_ext_props.try_push_back_many(props, props + count))
|
||||
auto initial_size = m_ext_props.size();
|
||||
if (!m_ext_props.try_resize(initial_size + count))
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult extension_list::add(const char *ext)
|
||||
{
|
||||
if (!contains(ext))
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
{
|
||||
VkExtensionProperties props = {};
|
||||
strncpy(props.extensionName, ext, sizeof(props.extensionName));
|
||||
if (!m_ext_props.try_push_back(props))
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
auto &dst = m_ext_props[initial_size + i];
|
||||
strncpy(dst.extensionName, extensions[i], sizeof(dst.extensionName));
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
|
@ -133,45 +64,45 @@ VkResult extension_list::add(VkExtensionProperties ext_prop)
|
|||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult extension_list::add(const char **ext_list, uint32_t count)
|
||||
VkResult extension_list::add(const VkExtensionProperties *props, uint32_t count)
|
||||
{
|
||||
auto initial_size = m_ext_props.size();
|
||||
if (!m_ext_props.try_resize(initial_size + count))
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
{
|
||||
if (add(ext_list[i]) != VK_SUCCESS)
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
m_ext_props[initial_size + i] = props[i];
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult extension_list::add(const extension_list &ext_list)
|
||||
{
|
||||
util::vector<VkExtensionProperties> ext_vect = ext_list.get_extension_props();
|
||||
for (auto &ext : ext_vect)
|
||||
util::vector<const char *> ext_vect{m_alloc};
|
||||
VkResult result = ext_list.get_extension_strings(ext_vect);
|
||||
if (result != VK_SUCCESS)
|
||||
{
|
||||
if (add(ext) != VK_SUCCESS)
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
return add(ext_vect.data(), ext_vect.size());
|
||||
}
|
||||
|
||||
bool extension_list::get_extension_strings(util::vector<const char*> &out) const
|
||||
VkResult extension_list::get_extension_strings(util::vector<const char*> &out) const
|
||||
{
|
||||
size_t old_size = out.size();
|
||||
size_t new_size = old_size + m_ext_props.size();
|
||||
if (!out.try_resize(new_size))
|
||||
{
|
||||
return false;
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
for (size_t i = old_size; i < new_size; i++)
|
||||
{
|
||||
out[i] = m_ext_props[i - old_size].extensionName;
|
||||
}
|
||||
return true;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
bool extension_list::contains(const extension_list &req) const
|
||||
|
|
|
|||
|
|
@ -29,11 +29,15 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vk_layer.h>
|
||||
|
||||
namespace util
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A helper class for storing a vector of extension names
|
||||
*
|
||||
* @note This class does not store the extension versions.
|
||||
*/
|
||||
class extension_list
|
||||
{
|
||||
public:
|
||||
|
|
@ -42,14 +46,6 @@ public:
|
|||
extension_list(const extension_list &rhs) = delete;
|
||||
const extension_list &operator=(const extension_list &rhs) = delete;
|
||||
|
||||
/**
|
||||
* @brief Obtain a vector of #VkExtensionProperties equivalent to this extension_list object.
|
||||
*/
|
||||
const util::vector<VkExtensionProperties> &get_extension_props() const
|
||||
{
|
||||
return m_ext_props;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the allocator used to manage the memory of this object.
|
||||
*/
|
||||
|
|
@ -66,26 +62,37 @@ public:
|
|||
*
|
||||
* @param[out] out A vector of C strings to which all extension are appended.
|
||||
*
|
||||
* @return A boolean indicating whether the operation was successful. If this is @c false, then @p out is
|
||||
* unmodified.
|
||||
* @return Indicates whether the operation was successful. If this is @c VK_ERROR_OUT_OF_HOST_MEMORY,
|
||||
* then @p out is unmodified.
|
||||
*/
|
||||
bool get_extension_strings(util::vector<const char*> &out) const;
|
||||
VkResult get_extension_strings(util::vector<const char*> &out) const;
|
||||
|
||||
/**
|
||||
* @brief Check if this extension list contains all the extensions listed in req.
|
||||
*/
|
||||
bool contains(const extension_list &req) const;
|
||||
|
||||
/**
|
||||
* @brief Check if this extension list contains the extension specified by ext.
|
||||
*/
|
||||
bool contains(const char *ext) const;
|
||||
|
||||
/**
|
||||
* @brief Remove an extension from a extension list
|
||||
*/
|
||||
void remove(const char *ext);
|
||||
VkResult add(const char *ext);
|
||||
|
||||
VkResult add(VkExtensionProperties ext_prop);
|
||||
VkResult add(const char **ext_list, uint32_t count);
|
||||
VkResult add(const extension_list &ext_list);
|
||||
VkResult add(const struct VkEnumerateInstanceExtensionPropertiesChain *chain);
|
||||
VkResult add(PFN_vkEnumerateInstanceExtensionProperties fpEnumerateInstanceExtensionProperties);
|
||||
VkResult add(VkPhysicalDevice dev);
|
||||
VkResult add(const char *const *extensions, uint32_t count);
|
||||
VkResult add(const VkExtensionProperties *props, uint32_t count);
|
||||
VkResult add(const extension_list &ext_list);
|
||||
VkResult add(const char *const *extensions, uint32_t count);
|
||||
|
||||
private:
|
||||
util::allocator m_alloc;
|
||||
|
||||
/**
|
||||
* @note We are using VkExtensionProperties to store the extension name only
|
||||
*/
|
||||
util::vector<VkExtensionProperties> m_ext_props;
|
||||
};
|
||||
} // namespace util
|
||||
|
|
|
|||
|
|
@ -283,17 +283,6 @@ const util::extension_list &surface_properties::get_required_device_extensions()
|
|||
return *device_extensions;
|
||||
}
|
||||
|
||||
bool surface_properties::physical_device_supported(VkPhysicalDevice dev)
|
||||
{
|
||||
static util::extension_list device_extensions{util::allocator::get_generic()};
|
||||
device_extensions.add(dev);
|
||||
|
||||
static util::extension_list required_extensions{util::allocator::get_generic()};
|
||||
required_extensions.add(required_device_extensions, NELEMS(required_device_extensions));
|
||||
|
||||
return device_extensions.contains(required_extensions);
|
||||
}
|
||||
|
||||
/* TODO: Check for zwp_linux_dmabuf_v1 protocol in display */
|
||||
VkBool32 GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physical_device, uint32_t queue_index,
|
||||
struct wl_display *display)
|
||||
|
|
|
|||
|
|
@ -45,8 +45,6 @@ public:
|
|||
|
||||
const util::extension_list &get_required_device_extensions() override;
|
||||
|
||||
bool physical_device_supported(VkPhysicalDevice dev);
|
||||
|
||||
PFN_vkVoidFunction get_proc_addr(const char *name) override;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,28 @@ VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util:
|
|||
{
|
||||
util::allocator allocator{extensions_to_enable.get_allocator(), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND};
|
||||
util::extension_list device_extensions{allocator};
|
||||
VkResult res = device_extensions.add(phys_dev);
|
||||
|
||||
util::vector<VkExtensionProperties> ext_props{allocator};
|
||||
layer::instance_private_data &inst_data = layer::instance_private_data::get(phys_dev);
|
||||
uint32_t count;
|
||||
VkResult res = inst_data.disp.EnumerateDeviceExtensionProperties(phys_dev, nullptr, &count, nullptr);
|
||||
|
||||
if (res == VK_SUCCESS)
|
||||
{
|
||||
if (!ext_props.try_resize(count))
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
res = inst_data.disp.EnumerateDeviceExtensionProperties(phys_dev, nullptr, &count, ext_props.data());
|
||||
}
|
||||
|
||||
if (res != VK_SUCCESS)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
res = device_extensions.add(ext_props.data(), count);
|
||||
|
||||
if (res != VK_SUCCESS)
|
||||
{
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue