mirror of
https://gitlab.freedesktop.org/mesa/vulkan-wsi-layer.git
synced 2025-12-20 06:50:08 +01:00
Update WSI layer to use C++17
This commit is contained in:
parent
128fafb083
commit
8444165b25
9 changed files with 38 additions and 233 deletions
|
|
@ -35,7 +35,8 @@ endif()
|
|||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread -fPIC")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ enabled via a build option [as explained below](#building-with-wayland-support).
|
|||
### Dependencies
|
||||
|
||||
* [CMake](https://cmake.org) version 3.4.3 or above.
|
||||
* C++11 compiler.
|
||||
* C++17 compiler.
|
||||
* Vulkan® loader and associated headers with support for the
|
||||
`VK_EXT_headless_surface` extension and for the Vulkan 1.1, or later API.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,195 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Arm Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cassert>
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace util
|
||||
{
|
||||
template <typename T>
|
||||
class optional : private noncopyable
|
||||
{
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
/**
|
||||
* @brief Construct an empty optional object.
|
||||
*/
|
||||
optional() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct an optional object with a value.
|
||||
*
|
||||
* @param val The value that will be placed in the optional.
|
||||
*/
|
||||
optional(value_type &&val) noexcept
|
||||
: m_has_value(true), m_value(std::move(val))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new optional object from another optional
|
||||
*
|
||||
* @param opt The optional object that will be moved
|
||||
*/
|
||||
optional(optional &&opt)
|
||||
: m_has_value(opt.m_has_value)
|
||||
{
|
||||
if (opt.m_has_value)
|
||||
{
|
||||
m_value = std::move(opt.m_value);
|
||||
opt.m_has_value = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_value = T{};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if optional has a value.
|
||||
*
|
||||
* @return true If the optional has a value.
|
||||
* @return false If the optional does not have a value.
|
||||
*/
|
||||
bool has_value() const noexcept
|
||||
{
|
||||
return m_has_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the value in the optional. It is only
|
||||
* valid to call this function if optional has a value.
|
||||
*
|
||||
* @return value_type& The value that is in the optional
|
||||
*/
|
||||
value_type &value() noexcept
|
||||
{
|
||||
assert(has_value());
|
||||
return m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears the value from the optional
|
||||
*
|
||||
*/
|
||||
void reset() noexcept
|
||||
{
|
||||
m_has_value = false;
|
||||
m_value = T{};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reassign/assign the value in the optional.
|
||||
*
|
||||
* @return optional& This optional object with the value.
|
||||
*/
|
||||
optional &set(T &&val) noexcept
|
||||
{
|
||||
m_value = std::move(val);
|
||||
m_has_value = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
optional &set(const T &val) noexcept
|
||||
{
|
||||
m_value = val;
|
||||
m_has_value = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the value in the optional, same as value()
|
||||
*
|
||||
* @return value_type& The value in the optional
|
||||
*/
|
||||
value_type &operator*() noexcept
|
||||
{
|
||||
assert(has_value());
|
||||
return m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the value in the optional as pointer.
|
||||
*
|
||||
* @return value_type* The value in the optional
|
||||
*/
|
||||
value_type *operator->() noexcept
|
||||
{
|
||||
assert(has_value());
|
||||
return &m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reassign/assign the value in the optional
|
||||
*
|
||||
* @param val The value to assign to this optional
|
||||
* @return optional& This optional object with the value
|
||||
*/
|
||||
optional &operator=(value_type &&val) noexcept
|
||||
{
|
||||
m_has_value = true;
|
||||
m_value = std::move(val);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new optional object from another optional
|
||||
*
|
||||
* @param opt The optional object that will be moved
|
||||
* @return optional& This optional object with the value
|
||||
*/
|
||||
optional &operator=(optional &&opt)
|
||||
{
|
||||
if (this != &opt)
|
||||
{
|
||||
if (opt.m_has_value)
|
||||
{
|
||||
m_has_value = true;
|
||||
m_value = std::move(opt.m_value);
|
||||
opt.m_has_value = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_value = T{};
|
||||
m_has_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_has_value{false};
|
||||
T m_value{};
|
||||
};
|
||||
|
||||
template <typename T, typename... Args>
|
||||
inline optional<T> make_optional(Args &&...args)
|
||||
{
|
||||
return optional<T>{T(std::forward<Args>(args)...)};
|
||||
}
|
||||
} /* namespace util */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Arm Limited.
|
||||
* Copyright (c) 2021-2022 Arm Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
|
@ -22,10 +22,9 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <array>
|
||||
|
||||
#include "optional.hpp"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace util
|
||||
{
|
||||
|
|
@ -62,7 +61,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
m_data[(m_begin + m_size) % N].set(std::forward<U>(item));
|
||||
m_data[(m_begin + m_size) % N].emplace(std::forward<U>(item));
|
||||
++m_size;
|
||||
|
||||
return true;
|
||||
|
|
@ -92,14 +91,14 @@ public:
|
|||
*
|
||||
* @return Item wrapped in an optional.
|
||||
*/
|
||||
util::optional<T> pop_front()
|
||||
std::optional<T> pop_front()
|
||||
{
|
||||
if (size() == 0)
|
||||
{
|
||||
return util::optional<T>{};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
util::optional<T> value = std::move(m_data[m_begin]);
|
||||
std::optional<T> value = std::move(m_data[m_begin]);
|
||||
|
||||
m_begin = (m_begin + 1) % N;
|
||||
--m_size;
|
||||
|
|
@ -120,7 +119,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
std::array<util::optional<T>, N> m_data{};
|
||||
std::array<std::optional<T>, N> m_data{};
|
||||
|
||||
// Marks the start index of the ring buffer.
|
||||
std::size_t m_begin{};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Arm Limited.
|
||||
* Copyright (c) 2021-2022 Arm Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
|
@ -23,9 +23,10 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "custom_allocator.hpp"
|
||||
#include "optional.hpp"
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace util
|
||||
|
|
@ -73,11 +74,11 @@ public:
|
|||
* @brief Like std::unordered_map.insert but doesn't throw on out of memory errors.
|
||||
*
|
||||
* @param value The value to insert in the map.
|
||||
* @return util::optional<std::pair<iterator,bool>> If successful, the optional will
|
||||
* @return std::optional<std::pair<iterator,bool>> If successful, the optional will
|
||||
* contain the same return value as from std::unordered_map.insert, otherwise
|
||||
* if out of memory, optional will be empty.
|
||||
* if out of memory, the function returns std::nullopt.
|
||||
*/
|
||||
util::optional<std::pair<iterator, bool>> try_insert(const std::pair<Key, Value> &value)
|
||||
std::optional<std::pair<iterator, bool>> try_insert(const std::pair<Key, Value> &value)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -85,7 +86,7 @@ public:
|
|||
}
|
||||
catch(std::bad_alloc& e)
|
||||
{
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Arm Limited.
|
||||
* Copyright (c) 2021-2022 Arm Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
|
@ -23,9 +23,10 @@
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "custom_allocator.hpp"
|
||||
#include "optional.hpp"
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace util
|
||||
|
|
@ -71,11 +72,11 @@ public:
|
|||
* @brief Like std::unordered_set.insert but doesn't throw on out of memory errors.
|
||||
*
|
||||
* @param value The value to insert in the map.
|
||||
* @return util::optional<std::pair<iterator,bool>> If successful, the optional will
|
||||
* @return std::optional<std::pair<iterator,bool>> If successful, the optional will
|
||||
* contain the same return value as from std::unordered_set.insert, otherwise
|
||||
* if out of memory, optional will be empty.
|
||||
* if out of memory, the function returns std::nullopt.
|
||||
*/
|
||||
util::optional<std::pair<iterator, bool>> try_insert(const value_type &value) noexcept
|
||||
std::optional<std::pair<iterator, bool>> try_insert(const value_type &value) noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -83,7 +84,7 @@ public:
|
|||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -230,7 +230,6 @@ implemented there:
|
|||
* `util::vector`
|
||||
* `util::allocator`
|
||||
* `util::allocator::make_unique`
|
||||
* `util::optional`
|
||||
* `util::fd_owner`
|
||||
* `util::ring_buffer`
|
||||
* `util::unordered_map`
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Arm Limited.
|
||||
* Copyright (c) 2021-2022 Arm Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
|
@ -41,7 +41,7 @@ fence_sync::fence_sync(layer::device_private_data &device, VkFence vk_fence)
|
|||
{
|
||||
}
|
||||
|
||||
util::optional<fence_sync> fence_sync::create(layer::device_private_data &device)
|
||||
std::optional<fence_sync> fence_sync::create(layer::device_private_data &device)
|
||||
{
|
||||
VkFence fence{ VK_NULL_HANDLE };
|
||||
VkFenceCreateInfo fence_info{ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
|
||||
|
|
@ -49,7 +49,7 @@ util::optional<fence_sync> fence_sync::create(layer::device_private_data &device
|
|||
device.disp.CreateFence(device.device, &fence_info, device.get_allocator().get_original_callbacks(), &fence);
|
||||
if (res != VK_SUCCESS)
|
||||
{
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
return fence_sync(device, fence);
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ bool sync_fd_fence_sync::is_supported(layer::instance_private_data &instance, Vk
|
|||
return fence_properties.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR;
|
||||
}
|
||||
|
||||
util::optional<sync_fd_fence_sync> sync_fd_fence_sync::create(layer::device_private_data &device)
|
||||
std::optional<sync_fd_fence_sync> sync_fd_fence_sync::create(layer::device_private_data &device)
|
||||
{
|
||||
VkExportFenceCreateInfo export_fence_create_info = {};
|
||||
export_fence_create_info.sType = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO;
|
||||
|
|
@ -153,12 +153,12 @@ util::optional<sync_fd_fence_sync> sync_fd_fence_sync::create(layer::device_priv
|
|||
device.disp.CreateFence(device.device, &fence_info, device.get_allocator().get_original_callbacks(), &fence);
|
||||
if (res != VK_SUCCESS)
|
||||
{
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
return sync_fd_fence_sync{ device, fence };
|
||||
}
|
||||
|
||||
util::optional<util::fd_owner> sync_fd_fence_sync::export_sync_fd()
|
||||
std::optional<util::fd_owner> sync_fd_fence_sync::export_sync_fd()
|
||||
{
|
||||
int exported_fd = -1;
|
||||
VkFenceGetFdInfoKHR fence_fd_info = {};
|
||||
|
|
@ -172,7 +172,7 @@ util::optional<util::fd_owner> sync_fd_fence_sync::export_sync_fd()
|
|||
swap_payload(false);
|
||||
return util::fd_owner(exported_fd);
|
||||
}
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} /* namespace wsi */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Arm Limited.
|
||||
* Copyright (c) 2021-2022 Arm Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
|
@ -30,8 +30,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "util/file_descriptor.hpp"
|
||||
#include "util/optional.hpp"
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
|
|
@ -57,9 +58,8 @@ public:
|
|||
*
|
||||
* @return Empty optional on failure or initialized fence.
|
||||
*/
|
||||
static util::optional<fence_sync> create(layer::device_private_data &device);
|
||||
static std::optional<fence_sync> create(layer::device_private_data &device);
|
||||
|
||||
/** Default constructor provided for use with @ref util::optional */
|
||||
fence_sync() = default;
|
||||
fence_sync(const fence_sync &) = delete;
|
||||
fence_sync &operator=(const fence_sync &) = delete;
|
||||
|
|
@ -135,7 +135,6 @@ private:
|
|||
class sync_fd_fence_sync : public fence_sync
|
||||
{
|
||||
public:
|
||||
/** Default constructor provided for use with @ref util::optional */
|
||||
sync_fd_fence_sync() = default;
|
||||
|
||||
/**
|
||||
|
|
@ -155,7 +154,7 @@ public:
|
|||
*
|
||||
* @return Empty optional on failure or initialized fence.
|
||||
*/
|
||||
static util::optional<sync_fd_fence_sync> create(layer::device_private_data &device);
|
||||
static std::optional<sync_fd_fence_sync> create(layer::device_private_data &device);
|
||||
|
||||
/**
|
||||
* Exports the fence to a native Sync FD.
|
||||
|
|
@ -164,7 +163,7 @@ public:
|
|||
*
|
||||
* @return The exported Sync FD on success or empty optional on failure.
|
||||
*/
|
||||
util::optional<util::fd_owner> export_sync_fd();
|
||||
std::optional<util::fd_owner> export_sync_fd();
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue