/* * WiVRn VR streaming * Copyright (C) 2022 Guillaume Meunier * Copyright (C) 2022 Patrick Nicolas * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include "utils/typename.h" #include "vk/vk.h" #include #include #include namespace vk::details { template struct structure_traits_base { static constexpr inline VkStructureType type = VK_STRUCTURE_TYPE_MAX_ENUM; using base = T; }; template struct structure_traits : structure_traits_base {}; template constexpr inline VkStructureType structure_type = structure_traits::type; template auto enumerate(F f, Args &&... args) -> auto { std::vector array; uint32_t count; VkResult result; result = f(std::forward(args)..., &count, nullptr); if (result >= 0) { if constexpr (structure_type == VK_STRUCTURE_TYPE_MAX_ENUM) { array.resize(count); } else { T default_value{}; default_value.type = structure_type; array.resize(count, default_value); } result = f(std::forward(args)..., &count, reinterpret_cast::base *>(array.data())); } if (result < 0) { throw std::system_error(result, vk::error_category(), "enumerating " + type_name()); } return array; } } // namespace vk::details