Merge master branch into multiple_swapchains_present_req

Change-Id: I153e7a78609651bbfdf4fc0b6675d0ea97763905
Signed-off-by: Iason Paraskevopoulos <iason.paraskevopoulos@arm.com>
This commit is contained in:
Iason Paraskevopoulos 2021-11-12 12:19:58 +00:00
commit 0c8259a994
20 changed files with 72 additions and 63 deletions

View file

@ -26,6 +26,13 @@ project(VkLayer_window_system_integration)
find_package(PkgConfig REQUIRED)
pkg_check_modules(VULKAN_PKG_CONFIG vulkan)
find_program(CLANG_TIDY clang-tidy-8)
if (NOT CLANG_TIDY STREQUAL "CLANG_TIDY-NOTFOUND")
message(STATUS "Using clang-tidy: ${CLANG_TIDY}")
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY} -checks=bugprone-*,modernize-*)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread -fPIC")
if (DEFINED DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")

View file

@ -44,26 +44,26 @@ namespace layer
VKAPI_ATTR VkLayerInstanceCreateInfo *get_chain_info(const VkInstanceCreateInfo *pCreateInfo, VkLayerFunction func)
{
VkLayerInstanceCreateInfo *chain_info = (VkLayerInstanceCreateInfo *)pCreateInfo->pNext;
auto *chain_info = reinterpret_cast<const VkLayerInstanceCreateInfo *>(pCreateInfo->pNext);
while (chain_info &&
!(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && chain_info->function == func))
{
chain_info = (VkLayerInstanceCreateInfo *)chain_info->pNext;
chain_info = reinterpret_cast<const VkLayerInstanceCreateInfo *>(chain_info->pNext);
}
return chain_info;
return const_cast<VkLayerInstanceCreateInfo *>(chain_info);
}
VKAPI_ATTR VkLayerDeviceCreateInfo *get_chain_info(const VkDeviceCreateInfo *pCreateInfo, VkLayerFunction func)
{
VkLayerDeviceCreateInfo *chain_info = (VkLayerDeviceCreateInfo *)pCreateInfo->pNext;
auto *chain_info = reinterpret_cast<const VkLayerDeviceCreateInfo *>(pCreateInfo->pNext);
while (chain_info &&
!(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && chain_info->function == func))
{
chain_info = (VkLayerDeviceCreateInfo *)chain_info->pNext;
chain_info = reinterpret_cast<const VkLayerDeviceCreateInfo *>(chain_info->pNext);
}
return chain_info;
return const_cast<VkLayerDeviceCreateInfo *>(chain_info);
}
template <typename T>

View file

@ -125,7 +125,7 @@ VkResult instance_private_data::associate(VkInstance instance, instance_dispatch
auto result = g_instance_data.try_insert(std::make_pair(key, instance_data.get()));
if (result.has_value())
{
instance_data.release();
instance_data.release(); // NOLINT(bugprone-unused-return-value)
return VK_SUCCESS;
}
else
@ -302,7 +302,7 @@ VkResult device_private_data::associate(VkDevice dev, instance_private_data &ins
auto result = g_device_data.try_insert(std::make_pair(key, device_data.get()));
if (result.has_value())
{
device_data.release();
device_data.release(); // NOLINT(bugprone-unused-return-value)
return VK_SUCCESS;
}
else

View file

@ -89,7 +89,7 @@ wsi_layer_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapc,
}
assert(swapc != VK_NULL_HANDLE);
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
wsi::destroy_surface_swapchain(sc, device_data, pAllocator);
}
@ -106,7 +106,7 @@ wsi_layer_vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapc, uint32_
assert(pSwapchainImageCount != nullptr);
assert(swapc != VK_NULL_HANDLE);
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
return sc->get_swapchain_images(pSwapchainImageCount, pSwapchainImages);
}
@ -124,7 +124,7 @@ wsi_layer_vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapc, uint64_t
assert(swapc != VK_NULL_HANDLE);
assert(semaphore != VK_NULL_HANDLE || fence != VK_NULL_HANDLE);
assert(pImageIndex != nullptr);
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
return sc->acquire_next_image(timeout, semaphore, fence, pImageIndex);
}
@ -209,7 +209,7 @@ wsi_layer_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo)
{
VkSwapchainKHR swapc = pPresentInfo->pSwapchains[i];
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
assert(sc != nullptr);
res = sc->queue_present(queue, present_info, pPresentInfo->pImageIndices[i]);
@ -326,7 +326,7 @@ wsi_layer_vkAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKH
return device_data.disp.AcquireNextImage2KHR(device, pAcquireInfo, pImageIndex);
}
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(pAcquireInfo->swapchain);
auto *sc = reinterpret_cast<wsi::swapchain_base *>(pAcquireInfo->swapchain);
return sc->acquire_next_image(pAcquireInfo->timeout, pAcquireInfo->semaphore, pAcquireInfo->fence, pImageIndex);
}
@ -337,9 +337,8 @@ wsi_layer_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, c
{
auto &device_data = layer::device_private_data::get(device);
const VkImageSwapchainCreateInfoKHR *image_sc_create_info =
util::find_extension<VkImageSwapchainCreateInfoKHR>(VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHR,
pCreateInfo->pNext);
const auto *image_sc_create_info = util::find_extension<VkImageSwapchainCreateInfoKHR>(
VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHR, pCreateInfo->pNext);
if (image_sc_create_info == nullptr || !device_data.layer_owns_swapchain(image_sc_create_info->swapchain))
{
@ -358,7 +357,7 @@ wsi_layer_vkBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
for (uint32_t i = 0; i < bindInfoCount; i++)
{
const VkBindImageMemorySwapchainInfoKHR *bind_sc_info = util::find_extension<VkBindImageMemorySwapchainInfoKHR>(
const auto *bind_sc_info = util::find_extension<VkBindImageMemorySwapchainInfoKHR>(
VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR, pBindInfos[i].pNext);
if (bind_sc_info == nullptr || bind_sc_info->swapchain == VK_NULL_HANDLE ||

View file

@ -30,6 +30,8 @@
#include <vulkan/vulkan.h>
#include "helpers.hpp"
#pragma once
namespace util
@ -108,7 +110,7 @@ public:
template <typename T, typename... Args>
util::unique_ptr<T> make_unique(Args &&...args) const noexcept;
VkAllocationCallbacks m_callbacks;
VkAllocationCallbacks m_callbacks{};
VkSystemAllocationScope m_scope;
};
@ -280,7 +282,7 @@ util::unique_ptr<T> allocator::make_unique(Args &&...args) const noexcept
* vector.
*/
template <typename T>
class vector : public std::vector<T, custom_allocator<T>>
class vector : public std::vector<T, custom_allocator<T>>, private noncopyable
{
public:
using base = std::vector<T, custom_allocator<T>>;

View file

@ -25,7 +25,7 @@
#include "extension_list.hpp"
#include "util/custom_allocator.hpp"
#include <layer/private_data.hpp>
#include <string.h>
#include <cstring>
#include <cassert>
namespace util

View file

@ -23,7 +23,8 @@
*/
#pragma once
#include "util/custom_allocator.hpp"
#include "custom_allocator.hpp"
#include "helpers.hpp"
#include <vector>
#include <algorithm>
@ -38,14 +39,11 @@ namespace util
*
* @note This class does not store the extension versions.
*/
class extension_list
class extension_list : private noncopyable
{
public:
extension_list(const util::allocator& allocator);
extension_list(const extension_list &rhs) = delete;
const extension_list &operator=(const extension_list &rhs) = delete;
/**
* @brief Get the allocator used to manage the memory of this object.
*/

View file

@ -33,13 +33,15 @@
#include <unistd.h>
#include <utility>
#include "helpers.hpp"
namespace util
{
/**
* Manages a POSIX file descriptor.
*/
class fd_owner
class fd_owner : private noncopyable
{
public:
@ -49,9 +51,6 @@ public:
{
}
fd_owner(const fd_owner &) = delete;
fd_owner &operator=(const fd_owner &) = delete;
fd_owner(fd_owner &&rhs)
{
*this = std::move(rhs);

View file

@ -44,4 +44,15 @@ const T *find_extension(VkStructureType sType, const void *pNext)
}
return reinterpret_cast<const T *>(entry);
}
class noncopyable
{
protected:
noncopyable() = default;
~noncopyable() = default;
private:
noncopyable(const noncopyable &) = delete;
noncopyable& operator=(const noncopyable &) = delete;
};
} // namespace util

View file

@ -24,18 +24,16 @@
#pragma once
#include <cassert>
#include "helpers.hpp"
namespace util
{
template <typename T>
class optional
class optional : private noncopyable
{
public:
using value_type = T;
optional(const optional &) = delete;
optional &operator=(const optional &) = delete;
/**
* @brief Construct an empty optional object.
*/

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019 Arm Limited.
* Copyright (c) 2017, 2019, 2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@ -62,7 +62,7 @@ VkResult timed_semaphore::init(unsigned count)
/* only programming error can cause _destroy to fail */
assert(res == 0);
res = pthread_mutex_init(&m_mutex, NULL);
res = pthread_mutex_init(&m_mutex, nullptr);
/* only programming errors can result in failure */
assert(res == 0);
@ -114,7 +114,7 @@ VkResult timed_semaphore::wait(uint64_t timeout)
static_cast<long>(timeout % (1000 * 1000 * 1000))
};
struct timespec now;
struct timespec now = {};
res = clock_gettime(CLOCK_MONOTONIC, &now);
assert(res == 0); /* only fails with programming error (EINVAL, EFAULT, EPERM) */

View file

@ -45,6 +45,7 @@ extern "C"
}
#include <vulkan/vulkan.h>
#include "helpers.hpp"
namespace util
{
@ -61,13 +62,9 @@ namespace util
*
* This code does not use the C++ standard library to avoid exceptions.
*/
class timed_semaphore
class timed_semaphore : private noncopyable
{
public:
/* copying not implemented */
timed_semaphore &operator=(const timed_semaphore &) = delete;
timed_semaphore(const timed_semaphore &) = delete;
~timed_semaphore();
timed_semaphore()
: initialized(false){};

View file

@ -26,6 +26,7 @@
#include <unordered_map>
#include "custom_allocator.hpp"
#include "optional.hpp"
#include "helpers.hpp"
namespace util
{
@ -39,7 +40,7 @@ template <typename Key, typename Value,
typename Hash = std::hash<Key>,
typename Comparator = std::equal_to<Key>,
typename Allocator = util::custom_allocator<std::pair<const Key, Value>>>
class unordered_map : public std::unordered_map<Key, Value, Hash, Comparator, Allocator>
class unordered_map : public std::unordered_map<Key, Value, Hash, Comparator, Allocator>, private noncopyable
{
using base = std::unordered_map<Key, Value, Hash, Comparator, Allocator>;
using size_type = typename base::size_type;
@ -52,9 +53,6 @@ public:
Value &operator[](const Key &key) = delete;
Value &operator[](Key &&key) = delete;
unordered_map(const unordered_map &) = delete;
unordered_map &operator=(const unordered_map &) = delete;
void insert() = delete;
void emplace() = delete;
void emplace_hint() = delete;

View file

@ -26,6 +26,7 @@
#include <unordered_set>
#include "custom_allocator.hpp"
#include "optional.hpp"
#include "helpers.hpp"
namespace util
{
@ -39,7 +40,7 @@ template <typename Key,
typename Hash = std::hash<Key>,
typename Comparator = std::equal_to<Key>,
typename Allocator = util::custom_allocator<Key>>
class unordered_set : public std::unordered_set<Key, Hash, Comparator, Allocator>
class unordered_set : public std::unordered_set<Key, Hash, Comparator, Allocator>, private noncopyable
{
using value_type = Key;
using base = std::unordered_set<Key, Hash, Comparator, Allocator>;
@ -50,9 +51,6 @@ public:
/**
* Delete all member functions that can cause allocation failure by throwing std::bad_alloc.
*/
unordered_set(const unordered_set &) = delete;
unordered_set &operator=(const unordered_set &) = delete;
void insert() = delete;
void emplace() = delete;
void emplace_hint() = delete;

View file

@ -96,7 +96,7 @@ VkResult surface_properties::get_surface_formats(VkPhysicalDevice physical_devic
VkResult res = VK_SUCCESS;
/* Construct a list of all formats supported by the driver - for color attachment */
constexpr int max_core_1_0_formats = VK_FORMAT_ASTC_12x12_SRGB_BLOCK + 1;
VkFormat formats[max_core_1_0_formats];
std::array<VkFormat, max_core_1_0_formats> formats{};
uint32_t format_count = 0;
for (int id = 0; id < max_core_1_0_formats; id++)

View file

@ -43,7 +43,7 @@ namespace headless
struct image_data
{
/* Device memory backing the image. */
VkDeviceMemory memory;
VkDeviceMemory memory{};
fence_sync present_fence;
};

View file

@ -171,9 +171,11 @@ void swapchain_base::unpresent_image(uint32_t presented_index)
swapchain_base::swapchain_base(layer::device_private_data &dev_data, const VkAllocationCallbacks *callbacks)
: m_device_data(dev_data)
, m_page_flip_thread_run(false)
, m_is_valid(false)
, m_start_present_semaphore()
, m_thread_sem_defined(false)
, m_first_present(true)
, m_pending_buffer_pool{}
, m_pending_buffer_pool()
, m_allocator(dev_data.get_allocator(), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT, callbacks)
, m_swapchain_images(m_allocator)
, m_surface(VK_NULL_HANDLE)
@ -385,7 +387,7 @@ VkResult swapchain_base::acquire_next_image(uint64_t timeout, VkSemaphore semaph
std::unique_lock<std::recursive_mutex> image_status_lock(m_image_status_mutex);
uint32_t i;
size_t i;
for (i = 0; i < m_swapchain_images.size(); ++i)
{
if (m_swapchain_images[i].status == swapchain_image::FREE)
@ -549,7 +551,7 @@ void swapchain_base::wait_for_pending_buffers()
/* Waiting for free images waits for both free and pending. One pending image may be presented and acquired by a
* compositor. The WSI backend may not necessarily know which pending image is presented to change its state. It may
* be impossible to wait for that one presented image. */
wait = m_swapchain_images.size() - acquired_images - 1;
wait = static_cast<int>(m_swapchain_images.size()) - acquired_images - 1;
image_status_lock.unlock();
while (wait > 0)

View file

@ -106,7 +106,7 @@ VkResult fence_sync::set_payload(VkQueue queue, const VkSemaphore *sem_payload,
VkPipelineStageFlags pipeline_stage_flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
VkSubmitInfo submit_info = {
VK_STRUCTURE_TYPE_SUBMIT_INFO, NULL, sem_count, sem_payload, &pipeline_stage_flags, 0, NULL, 0, NULL
VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, sem_count, sem_payload, &pipeline_stage_flags, 0, nullptr, 0, nullptr
};
result = dev->disp.QueueSubmit(queue, 1, &submit_info, fence);

View file

@ -398,8 +398,8 @@ VkResult swapchain::create_aliased_image_handle(const VkImageCreateInfo *image_c
get_allocation_callbacks(), image);
}
VkResult swapchain::allocate_wsialloc(VkImageCreateInfo &image_create_info, wayland_image_data *image_data,
util::vector<wsialloc_format> importable_formats,
VkResult swapchain::allocate_wsialloc(VkImageCreateInfo &image_create_info, wayland_image_data &image_data,
util::vector<wsialloc_format> &importable_formats,
wsialloc_format *allocated_format)
{
bool is_protected_memory = (image_create_info.flags & VK_IMAGE_CREATE_PROTECTED_BIT) != 0;
@ -407,8 +407,8 @@ VkResult swapchain::allocate_wsialloc(VkImageCreateInfo &image_create_info, wayl
wsialloc_allocate_info alloc_info = { importable_formats.data(), static_cast<unsigned>(importable_formats.size()),
image_create_info.extent.width, image_create_info.extent.height,
allocation_flags };
const auto res = wsialloc_alloc(m_wsi_allocator, &alloc_info, allocated_format, image_data->stride,
image_data->buffer_fd, image_data->offset);
const auto res = wsialloc_alloc(m_wsi_allocator, &alloc_info, allocated_format, image_data.stride,
image_data.buffer_fd, image_data.offset);
if (res != WSIALLOC_ERROR_NONE)
{
WSI_LOG_ERROR("Failed allocation of DMA Buffer. WSI error: %d", static_cast<int>(res));
@ -442,7 +442,7 @@ VkResult swapchain::allocate_image(VkImageCreateInfo &image_create_info, wayland
{
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
VkResult result = allocate_wsialloc(m_image_create_info, image_data, importable_formats, &m_allocated_format);
VkResult result = allocate_wsialloc(m_image_create_info, *image_data, importable_formats, &m_allocated_format);
if (result != VK_SUCCESS)
{
return result;
@ -473,7 +473,7 @@ VkResult swapchain::allocate_image(VkImageCreateInfo &image_create_info, wayland
}
wsialloc_format allocated_format = { 0 };
result = allocate_wsialloc(image_create_info, image_data, importable_formats, &allocated_format);
result = allocate_wsialloc(image_create_info, *image_data, importable_formats, &allocated_format);
if (result != VK_SUCCESS)
{
return result;

View file

@ -163,8 +163,8 @@ private:
struct wayland_image_data;
VkResult allocate_image(VkImageCreateInfo &image_create_info, wayland_image_data *image_data, VkImage *image);
VkResult allocate_wsialloc(VkImageCreateInfo &image_create_info, wayland_image_data *image_data,
util::vector<wsialloc_format> importable_formats, wsialloc_format *allocated_format);
VkResult allocate_wsialloc(VkImageCreateInfo &image_create_info, wayland_image_data &image_data,
util::vector<wsialloc_format> &importable_formats, wsialloc_format *allocated_format);
VkResult internal_bind_swapchain_image(VkDevice &device, wayland_image_data *swapchain_image,
const VkImage &image);