/* * WiVRn VR streaming * Copyright (C) 2025 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 #include #include #include template class specialization_constants { std::tuple values; std::array entries; vk::SpecializationInfo info_; specialization_constants(specialization_constants &&) = delete; specialization_constants(const specialization_constants &) = delete; specialization_constants & operator=(const specialization_constants &) = delete; specialization_constants & operator=(specialization_constants &&) = delete; template void fill_entries() { entries[i] = vk::SpecializationMapEntry{ .constantID = i, .offset = uint32_t(uintptr_t(std::addressof(std::get(values))) - uintptr_t(std::addressof(values))), .size = sizeof(std::get(values)), }; if constexpr (i > 0) fill_entries(); } public: specialization_constants(Args &&... args) : values(std::forward(args)...), info_{ .mapEntryCount = uint32_t(entries.size()), .pMapEntries = entries.data(), .dataSize = sizeof(values), .pData = &values, } { fill_entries(); } operator vk::SpecializationInfo *() { return &info_; } vk::SpecializationInfo * info() { return &info_; } template auto & data() { return std::get(values); } }; template specialization_constants make_specialization_constants(Args &&... args) { return specialization_constants(std::forward(args)...); }