File: test_interface.cpp

package info (click to toggle)
vulkan-utility-libraries 1.4.335.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,476 kB
  • sloc: cpp: 106,816; ansic: 16,788; python: 2,218; sh: 23; makefile: 6
file content (56 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download | duplicates (7)
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
// Copyright 2023 The Khronos Group Inc.
// Copyright 2023 Valve Corporation
// Copyright 2023 LunarG, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//

#include <gtest/gtest.h>

#include <vulkan/utility/vk_dispatch_table.h>

// Only exists so that local_vkGetDeviceProcAddr can return a 'real' function pointer
inline VKAPI_ATTR void empty_func() {}

inline VKAPI_ATTR PFN_vkVoidFunction local_vkGetInstanceProcAddr(VkInstance instance, const char *pName) {
    if (instance == VK_NULL_HANDLE) {
        return NULL;
    }

    if (strcmp(pName, "vkGetInstanceProcAddr")) {
        return reinterpret_cast<PFN_vkVoidFunction>(&local_vkGetInstanceProcAddr);
    }

    return reinterpret_cast<PFN_vkVoidFunction>(&empty_func);
}

inline VKAPI_ATTR PFN_vkVoidFunction local_vkGetDeviceProcAddr(VkDevice device, const char *pName) {
    if (device == VK_NULL_HANDLE) {
        return NULL;
    }

    if (strcmp(pName, "vkGetDeviceProcAddr")) {
        return reinterpret_cast<PFN_vkVoidFunction>(&local_vkGetDeviceProcAddr);
    }

    return reinterpret_cast<PFN_vkVoidFunction>(&empty_func);
}

TEST(test_vk_dispatch_table, cpp_interface) {
    VkuDeviceDispatchTable device_dispatch_table{};
    VkuInstanceDispatchTable instance_dispatch_table{};

    VkInstance instance{};

    vkuInitInstanceDispatchTable(instance, &instance_dispatch_table, local_vkGetInstanceProcAddr);

    ASSERT_EQ(reinterpret_cast<PFN_vkVoidFunction>(instance_dispatch_table.GetInstanceProcAddr),
              reinterpret_cast<PFN_vkVoidFunction>(local_vkGetInstanceProcAddr));

    VkDevice device{};

    vkuInitDeviceDispatchTable(device, &device_dispatch_table, local_vkGetDeviceProcAddr);

    ASSERT_EQ(reinterpret_cast<PFN_vkVoidFunction>(device_dispatch_table.GetDeviceProcAddr),
              reinterpret_cast<PFN_vkVoidFunction>(local_vkGetDeviceProcAddr));
}