diff options
author | Ben Davis <ben.davis@arm.com> | 2021-10-07 14:48:44 +0100 |
---|---|---|
committer | Matteo Franchin <matteo.franchin@arm.com> | 2021-11-11 10:15:22 +0000 |
commit | 6ef056b5171ea87bae62d2d5ec9c12e72a399645 (patch) | |
tree | a604a1873574e7d5af34d38cd05efd73e3e8eecf | |
parent | 5bf469a278eef55eeef68ef2c88597194f06d87e (diff) | |
download | vulkan-wsi-layer-6ef056b5171ea87bae62d2d5ec9c12e72a399645.tar.gz vulkan-wsi-layer-6ef056b5171ea87bae62d2d5ec9c12e72a399645.tar.bz2 vulkan-wsi-layer-6ef056b5171ea87bae62d2d5ec9c12e72a399645.zip |
Update code to use modern c++ style
Fix warnings given by clang-tidy 8 with checks 'bugprone-*,modernize-*'
Change-Id: I2e5660c5872728f957869c66b1143cfcc76bc20e
Signed-off-by: Ben Davis <ben.davis@arm.com>
-rw-r--r-- | layer/layer.cpp | 12 | ||||
-rw-r--r-- | layer/private_data.cpp | 4 | ||||
-rw-r--r-- | layer/swapchain_api.cpp | 17 | ||||
-rw-r--r-- | util/custom_allocator.hpp | 2 | ||||
-rw-r--r-- | util/extension_list.cpp | 2 | ||||
-rw-r--r-- | util/timed_semaphore.cpp | 6 | ||||
-rw-r--r-- | wsi/headless/surface_properties.cpp | 2 | ||||
-rw-r--r-- | wsi/headless/swapchain.cpp | 2 | ||||
-rw-r--r-- | wsi/swapchain_base.cpp | 8 | ||||
-rw-r--r-- | wsi/synchronization.cpp | 2 |
10 files changed, 29 insertions, 28 deletions
diff --git a/layer/layer.cpp b/layer/layer.cpp index a90a336..9282662 100644 --- a/layer/layer.cpp +++ b/layer/layer.cpp @@ -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> diff --git a/layer/private_data.cpp b/layer/private_data.cpp index b47e7a7..6fa3d38 100644 --- a/layer/private_data.cpp +++ b/layer/private_data.cpp @@ -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 diff --git a/layer/swapchain_api.cpp b/layer/swapchain_api.cpp index 3ccbb73..e46ca87 100644 --- a/layer/swapchain_api.cpp +++ b/layer/swapchain_api.cpp @@ -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); } @@ -146,7 +146,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); VkResult res = sc->queue_present(queue, pPresentInfo, pPresentInfo->pImageIndices[i]); @@ -263,7 +263,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); } @@ -274,9 +274,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)) { @@ -295,7 +294,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 || diff --git a/util/custom_allocator.hpp b/util/custom_allocator.hpp index 486fd18..829c798 100644 --- a/util/custom_allocator.hpp +++ b/util/custom_allocator.hpp @@ -108,7 +108,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; }; diff --git a/util/extension_list.cpp b/util/extension_list.cpp index 4194404..47dfa06 100644 --- a/util/extension_list.cpp +++ b/util/extension_list.cpp @@ -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 diff --git a/util/timed_semaphore.cpp b/util/timed_semaphore.cpp index 138cc9c..9b2c117 100644 --- a/util/timed_semaphore.cpp +++ b/util/timed_semaphore.cpp @@ -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) */ diff --git a/wsi/headless/surface_properties.cpp b/wsi/headless/surface_properties.cpp index 326216b..9f944bf 100644 --- a/wsi/headless/surface_properties.cpp +++ b/wsi/headless/surface_properties.cpp @@ -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++) diff --git a/wsi/headless/swapchain.cpp b/wsi/headless/swapchain.cpp index 1005809..cb32e30 100644 --- a/wsi/headless/swapchain.cpp +++ b/wsi/headless/swapchain.cpp @@ -43,7 +43,7 @@ namespace headless struct image_data { /* Device memory backing the image. */ - VkDeviceMemory memory; + VkDeviceMemory memory{}; fence_sync present_fence; }; diff --git a/wsi/swapchain_base.cpp b/wsi/swapchain_base.cpp index fdc0c29..a082735 100644 --- a/wsi/swapchain_base.cpp +++ b/wsi/swapchain_base.cpp @@ -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) @@ -372,7 +374,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) @@ -529,7 +531,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) diff --git a/wsi/synchronization.cpp b/wsi/synchronization.cpp index 5e5a0d0..c2c7333 100644 --- a/wsi/synchronization.cpp +++ b/wsi/synchronization.cpp @@ -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); |