Vulkan-Utility-Libraries/tests/vul_dispatch_table/test_interface.cpp
Charles Giessen 2bd0e0d438 util: Fixup and add Dispatch Table header
Fixes the vk_layer_dispatch_table.h header file so that they can be used
in other projects. The contents of this header and
 vk_dispatch_table_helper.h have been moved into a new header
 vul_dispatch_table.h.

The structs VulDeviceDispatchTable and VulInstanceDispatchTable
struct contain function pointers for the device and instance, respectively.

The functions vul_init_device_dispatch_table and
vul_init_instance_dispatch_table fill out the aforementioned structs,
making the task of setting up the disptach table in a layer much simpler.
2023-08-23 15:07:01 -06:00

45 lines
1.5 KiB
C++

// 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/vul_dispatch_table.h>
// Only exists so that local_vkGetDeviceProcAddr can return a 'real' function pointer
inline void empty_func() {}
inline 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 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_vul_dispatch_table, cpp_interface) {
VulDeviceDispatchTable device_dispatch_table{};
VulInstanceDispatchTable instance_dispatch_table{};
VkInstance instance{};
vulInitInstanceDispatchTable(instance, &instance_dispatch_table, local_vkGetInstanceProcAddr);
ASSERT_EQ(instance_dispatch_table.GetInstanceProcAddr, local_vkGetInstanceProcAddr);
VkDevice device{};
vulInitDeviceDispatchTable(device, &device_dispatch_table, local_vkGetDeviceProcAddr);
ASSERT_EQ(device_dispatch_table.GetDeviceProcAddr, local_vkGetDeviceProcAddr);
}