PFN_vkSetInstanceLoaderData set_loader_data,
util::wsi_platform_set enabled_layer_platforms, const util::allocator &allocator)
{
- auto *instance_data =
- allocator.create<instance_private_data>(1, table, set_loader_data, enabled_layer_platforms, allocator);
+ auto instance_data =
+ allocator.make_unique<instance_private_data>(table, set_loader_data, enabled_layer_platforms, allocator);
if (instance_data == nullptr)
{
g_instance_data.erase(it);
}
- auto result = g_instance_data.try_insert(std::make_pair(key, instance_data));
+ auto result = g_instance_data.try_insert(std::make_pair(key, instance_data.get()));
if (result.has_value())
{
+ instance_data.release();
return VK_SUCCESS;
}
else
WSI_LOG_WARNING("Failed to insert instance_private_data for instance (%p) as host is out of memory",
reinterpret_cast<void *>(instance));
- destroy(instance_data);
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
}
const device_dispatch_table &table, PFN_vkSetDeviceLoaderData set_loader_data,
const util::allocator &allocator)
{
- auto *device_data =
- allocator.create<device_private_data>(1, inst_data, phys_dev, dev, table, set_loader_data, allocator);
+ auto device_data =
+ allocator.make_unique<device_private_data>(inst_data, phys_dev, dev, table, set_loader_data, allocator);
if (device_data == nullptr)
{
g_device_data.erase(it);
}
- auto result = g_device_data.try_insert(std::make_pair(key, device_data));
+ auto result = g_device_data.try_insert(std::make_pair(key, device_data.get()));
if (result.has_value())
{
+ device_data.release();
return VK_SUCCESS;
}
else
WSI_LOG_WARNING("Failed to insert device_private_data for device (%p) as host is out of memory",
reinterpret_cast<void *>(dev));
- destroy(device_data);
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
}
#include <vector>
#include <string>
#include <cassert>
+#include <memory>
#include <vulkan/vulkan.h>
namespace util
{
+template <typename T>
+class deleter;
+
+template <typename T>
+using unique_ptr = std::unique_ptr<T, deleter<T>>;
+
/**
* @brief Minimalistic wrapper of VkAllocationCallbacks.
*/
template <typename T>
void destroy(size_t num_objects, T *obj) const noexcept;
+ template <typename T, typename... Args>
+ util::unique_ptr<T> make_unique(Args &&...args) const noexcept;
+
VkAllocationCallbacks m_callbacks;
VkSystemAllocationScope m_scope;
};
}
template <typename T>
-void destroy_custom(T *obj)
+class deleter
+{
+public:
+ deleter(allocator allocator)
+ : m_allocator(std::move(allocator))
+ {}
+
+ void operator()(T *object)
+ {
+ m_allocator.destroy<T>(1, object);
+ }
+
+private:
+ allocator m_allocator;
+};
+
+template <typename T, typename... Args>
+util::unique_ptr<T> allocator::make_unique(Args &&...args) const noexcept
{
- T::destroy(obj);
+ T *object = create<T>(1, std::forward<Args>(args)...);
+ return util::unique_ptr<T>(object, *this);
}
/**
/**
* @brief Return the device extensions that this surface_properties implementation needs.
*/
- virtual const util::extension_list &get_required_device_extensions()
+ virtual VkResult get_required_device_extensions(util::extension_list &extension_list)
{
- static const util::extension_list empty{util::allocator::get_generic()};
- return empty;
+ /* Requires no additional extensions */
+ return VK_SUCCESS;
}
/**
VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME,
};
-static std::unique_ptr<util::extension_list> populate_device_extensions()
+VkResult surface_properties::get_required_device_extensions(util::extension_list &extension_list)
{
- std::unique_ptr<util::extension_list> ret(new util::extension_list(util::allocator::get_generic()));
- ret->add(required_device_extensions, NELEMS(required_device_extensions));
-
- return ret;
-}
-
-const util::extension_list &surface_properties::get_required_device_extensions()
-{
- static std::unique_ptr<util::extension_list> device_extensions = populate_device_extensions();
- return *device_extensions;
+ return extension_list.add(required_device_extensions, NELEMS(required_device_extensions));
}
/* TODO: Check for zwp_linux_dmabuf_v1 protocol in display */
VkResult get_surface_present_modes(VkPhysicalDevice physical_device, VkSurfaceKHR surface,
uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes) override;
- const util::extension_list &get_required_device_extensions() override;
+ VkResult get_required_device_extensions(util::extension_list &extension_list) override;
PFN_vkVoidFunction get_proc_addr(const char *name) override;
};
continue;
}
+ util::extension_list extensions_required_by_layer{allocator};
surface_properties *props = get_surface_properties(wsi_ext.platform);
- const auto &extensions_required_by_layer = props->get_required_device_extensions();
+ res = props->get_required_device_extensions(extensions_required_by_layer);
+ if (res != VK_SUCCESS)
+ {
+ return res;
+ }
+
bool supported = device_extensions.contains(extensions_required_by_layer);
if (!supported)
{