mirror of
https://gitlab.freedesktop.org/mesa/vulkan-wsi-layer.git
synced 2026-05-04 22:18:00 +02:00
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>
This commit is contained in:
parent
5bf469a278
commit
6ef056b517
10 changed files with 29 additions and 28 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) */
|
||||
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace headless
|
|||
struct image_data
|
||||
{
|
||||
/* Device memory backing the image. */
|
||||
VkDeviceMemory memory;
|
||||
VkDeviceMemory memory{};
|
||||
fence_sync present_fence;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue