mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 07:24:34 +00:00
Support tests on windows with clang & clang-cl
Required adding a .def file to properly export the required symbols and disabling pointer cast warnings that are coming from Catch2.
This commit is contained in:
parent
767bd1baf2
commit
348e8bf796
@ -12,7 +12,14 @@ target_link_libraries(VulkanMock
|
|||||||
vk-bootstrap-compiler-warnings
|
vk-bootstrap-compiler-warnings
|
||||||
)
|
)
|
||||||
target_compile_features(VulkanMock PUBLIC cxx_std_17)
|
target_compile_features(VulkanMock PUBLIC cxx_std_17)
|
||||||
target_compile_definitions(VulkanMock PUBLIC VK_NO_PROTOTYPES)
|
target_compile_definitions(VulkanMock PUBLIC VK_NO_PROTOTYPES COMPILING_DLL)
|
||||||
|
if(WIN32)
|
||||||
|
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
|
||||||
|
target_link_options(VulkanMock PRIVATE /DEF:${CMAKE_CURRENT_SOURCE_DIR}/vulkan_mock.def)
|
||||||
|
elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "GNU")
|
||||||
|
target_link_options(VulkanMock PRIVATE -Wl,/DEF:${CMAKE_CURRENT_SOURCE_DIR}/vulkan_mock.def)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(vk-bootstrap-test
|
add_executable(vk-bootstrap-test
|
||||||
vulkan_library_loader.hpp
|
vulkan_library_loader.hpp
|
||||||
@ -37,6 +44,10 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|||||||
target_compile_options(vk-bootstrap-test PRIVATE /wd4996)
|
target_compile_options(vk-bootstrap-test PRIVATE /wd4996)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
target_compile_options(vk-bootstrap-compiler-warnings INTERFACE -Wno-microsoft-cast)
|
||||||
|
endif()
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
|
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
|
||||||
include(Catch)
|
include(Catch)
|
||||||
catch_discover_tests(vk-bootstrap-test)
|
catch_discover_tests(vk-bootstrap-test)
|
||||||
|
@ -25,7 +25,7 @@ VkExtensionProperties get_extension_properties(const char* extName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VulkanMock& get_and_setup_default() {
|
VulkanMock& get_and_setup_default() {
|
||||||
VulkanMock& mock = get_vulkan_mock();
|
VulkanMock& mock = *get_vulkan_mock();
|
||||||
mock.instance_extensions.push_back(get_extension_properties(VK_KHR_SURFACE_EXTENSION_NAME));
|
mock.instance_extensions.push_back(get_extension_properties(VK_KHR_SURFACE_EXTENSION_NAME));
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
mock.instance_extensions.push_back(get_extension_properties("VK_KHR_win32_surface"));
|
mock.instance_extensions.push_back(get_extension_properties("VK_KHR_win32_surface"));
|
||||||
@ -512,7 +512,7 @@ TEST_CASE("SystemInfo Loading Vulkan Automatically", "[VkBootstrap.loading]") {
|
|||||||
TEST_CASE("SystemInfo Loading Vulkan Manually", "[VkBootstrap.loading]") {
|
TEST_CASE("SystemInfo Loading Vulkan Manually", "[VkBootstrap.loading]") {
|
||||||
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
|
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
|
||||||
VulkanLibrary vk_lib;
|
VulkanLibrary vk_lib;
|
||||||
REQUIRE(vk_lib.vkGetInstanceProcAddr != NULL);
|
REQUIRE(vk_lib.vkGetInstanceProcAddr);
|
||||||
auto info_ret = vkb::SystemInfo::get_system_info(vk_lib.vkGetInstanceProcAddr);
|
auto info_ret = vkb::SystemInfo::get_system_info(vk_lib.vkGetInstanceProcAddr);
|
||||||
REQUIRE(info_ret);
|
REQUIRE(info_ret);
|
||||||
vkb::InstanceBuilder builder;
|
vkb::InstanceBuilder builder;
|
||||||
@ -531,7 +531,7 @@ TEST_CASE("InstanceBuilder Loading Vulkan Automatically", "[VkBootstrap.loading]
|
|||||||
TEST_CASE("InstanceBuilder Loading Vulkan Manually", "[VkBootstrap.loading]") {
|
TEST_CASE("InstanceBuilder Loading Vulkan Manually", "[VkBootstrap.loading]") {
|
||||||
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
|
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
|
||||||
VulkanLibrary vk_lib;
|
VulkanLibrary vk_lib;
|
||||||
REQUIRE(vk_lib.vkGetInstanceProcAddr != NULL);
|
REQUIRE(vk_lib.vkGetInstanceProcAddr);
|
||||||
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
|
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
|
||||||
auto ret = builder.build();
|
auto ret = builder.build();
|
||||||
vk_lib.close();
|
vk_lib.close();
|
||||||
@ -554,7 +554,7 @@ TEST_CASE("ReLoading Vulkan Manually", "[VkBootstrap.loading]") {
|
|||||||
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
|
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
|
||||||
{
|
{
|
||||||
VulkanLibrary vk_lib;
|
VulkanLibrary vk_lib;
|
||||||
REQUIRE(vk_lib.vkGetInstanceProcAddr != NULL);
|
REQUIRE(vk_lib.vkGetInstanceProcAddr);
|
||||||
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
|
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
|
||||||
auto ret = builder.build();
|
auto ret = builder.build();
|
||||||
REQUIRE(ret);
|
REQUIRE(ret);
|
||||||
@ -562,7 +562,7 @@ TEST_CASE("ReLoading Vulkan Manually", "[VkBootstrap.loading]") {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
VulkanLibrary vk_lib;
|
VulkanLibrary vk_lib;
|
||||||
REQUIRE(vk_lib.vkGetInstanceProcAddr != NULL);
|
REQUIRE(vk_lib.vkGetInstanceProcAddr);
|
||||||
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
|
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
|
||||||
auto ret = builder.build();
|
auto ret = builder.build();
|
||||||
REQUIRE(ret);
|
REQUIRE(ret);
|
||||||
@ -643,7 +643,7 @@ TEST_CASE("Passing vkb classes to Vulkan handles", "[VkBootstrap.pass_class_to_h
|
|||||||
|
|
||||||
// Check if we can get instance functions.
|
// Check if we can get instance functions.
|
||||||
PFN_vkVoidFunction instanceFunction = instance.fp_vkGetInstanceProcAddr(instance, "vkEnumeratePhysicalDevices"); // validation layers should be provided.
|
PFN_vkVoidFunction instanceFunction = instance.fp_vkGetInstanceProcAddr(instance, "vkEnumeratePhysicalDevices"); // validation layers should be provided.
|
||||||
REQUIRE(instanceFunction != NULL);
|
REQUIRE(instanceFunction);
|
||||||
|
|
||||||
vkb::PhysicalDeviceSelector physicalDeviceSelector(instance);
|
vkb::PhysicalDeviceSelector physicalDeviceSelector(instance);
|
||||||
auto physicalDevice =
|
auto physicalDevice =
|
||||||
@ -655,7 +655,7 @@ TEST_CASE("Passing vkb classes to Vulkan handles", "[VkBootstrap.pass_class_to_h
|
|||||||
|
|
||||||
// Check if we can get a device function address, passing vkb::Device to the function.
|
// Check if we can get a device function address, passing vkb::Device to the function.
|
||||||
PFN_vkVoidFunction deviceFunction = instance.fp_vkGetDeviceProcAddr(device.value(), "vkAcquireNextImageKHR");
|
PFN_vkVoidFunction deviceFunction = instance.fp_vkGetDeviceProcAddr(device.value(), "vkAcquireNextImageKHR");
|
||||||
REQUIRE(deviceFunction != NULL);
|
REQUIRE(deviceFunction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,11 @@
|
|||||||
|
|
||||||
VulkanMock mock;
|
VulkanMock mock;
|
||||||
|
|
||||||
EXPORT_MACRO VulkanMock& get_vulkan_mock() {
|
extern "C" {
|
||||||
|
VulkanMock* get_vulkan_mock() {
|
||||||
mock = VulkanMock{};
|
mock = VulkanMock{};
|
||||||
return mock;
|
return &mock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> VkResult fill_out_count_pointer_pair(std::vector<T> const& data_vec, uint32_t* pCount, T* pData) {
|
template <typename T> VkResult fill_out_count_pointer_pair(std::vector<T> const& data_vec, uint32_t* pCount, T* pData) {
|
||||||
@ -368,13 +370,9 @@ PFN_vkVoidFunction shim_vkGetInstanceProcAddr([[maybe_unused]] VkInstance instan
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#if defined(WIN32)
|
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
|
||||||
|
|
||||||
EXPORT_MACRO VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
|
|
||||||
#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
|
|
||||||
return shim_vkGetInstanceProcAddr(instance, pName);
|
return shim_vkGetInstanceProcAddr(instance, pName);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
|
||||||
#define DLSYM_FUNC_NAME dlsym
|
#define DLSYM_FUNC_NAME dlsym
|
||||||
|
4
tests/vulkan_mock.def
Normal file
4
tests/vulkan_mock.def
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
LIBRARY vulkan-1
|
||||||
|
EXPORTS
|
||||||
|
get_vulkan_mock
|
||||||
|
vkGetInstanceProcAddr
|
@ -91,12 +91,6 @@ struct VulkanMock {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined(EXPORT_MACRO)
|
extern "C" {
|
||||||
#if defined(WIN32)
|
VulkanMock* get_vulkan_mock();
|
||||||
#define EXPORT_MACRO __declspec(dllexport)
|
}
|
||||||
#else
|
|
||||||
#define EXPORT_MACRO
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
EXPORT_MACRO VulkanMock& get_vulkan_mock();
|
|
||||||
|
Loading…
Reference in New Issue
Block a user