aboutsummaryrefslogtreecommitdiff
path: root/src/helper.hh
blob: 4567d4001515acf81b82da4f3012c23ab848407e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef HELPER_HH_
#define HELPER_HH_

#include <vulkan/vk_layer.h>
#include <vulkan/vulkan.h>

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 <typename T>
static T* find_next(void* const head, const VkStructureType& stype) {
    for (auto i = reinterpret_cast<VkBaseOutStructure*>(head)->pNext; i;
         i = i->pNext) {

        if (i->sType == stype) {
            return reinterpret_cast<T*>(i);
        }
    }
    return nullptr;
}

template <typename T>
static const T* find_next(const void* const head,
                          const VkStructureType& stype) {

    for (auto i = reinterpret_cast<const VkBaseInStructure*>(head)->pNext; i;
         i = i->pNext) {

        if (i->sType == stype) {
            return reinterpret_cast<const T*>(i);
        }
    }
    return nullptr;
}

template <typename T>
static const T* find_link(const void* const head,
                          const VkStructureType& stype) {
    for (auto info = find_next<T>(head, stype); info;
         info = find_next<T>(info, stype)) {

        if (info->function == VK_LAYER_LINK_INFO) {
            return reinterpret_cast<const T*>(info);
        }
    }
    return nullptr;
}

} // namespace low_latency

#endif