#ifndef HELPER_HH_ #define HELPER_HH_ #include #include #include namespace low_latency { #define THROW_NOT_VKSUCCESS(x) \ if (const auto result = x; result != VK_SUCCESS) { \ throw result; \ } // Small templates which allow us to SFINAE find pNext structs. template static T* find_next(void* const head, const VkStructureType& stype) { for (auto i = reinterpret_cast(head)->pNext; i; i = i->pNext) { if (i->sType == stype) { return reinterpret_cast(i); } } return nullptr; } template static const T* find_next(const void* const head, const VkStructureType& stype) { for (auto i = reinterpret_cast(head)->pNext; i; i = i->pNext) { if (i->sType == stype) { return reinterpret_cast(i); } } return nullptr; } template static const T* find_link(const void* const head, const VkStructureType& stype) { for (auto info = find_next(head, stype); info; info = find_next(info, stype)) { if (info->function == VK_LAYER_LINK_INFO) { return reinterpret_cast(info); } } return nullptr; } template std::uint64_t extract_present_id(const T& submit) { const auto lspi = find_next( &submit, VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV); return lspi ? lspi->presentID : 0; } } // namespace low_latency #endif