From 96722abe4eb675ea310ec67c2152fa17f64bc7f3 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 1 Jun 2022 02:39:08 +0200 Subject: [PATCH] load vulkan using volk and create window instance surface --- .gitmodules | 3 + external/CMakeLists.txt | 8 ++- external/volk | 1 + framework/sdl_service/CMakeLists.txt | 3 + framework/sdl_service/test/CMakeLists.txt | 5 +- framework/sdl_service/test/volk_test1.cpp | 82 +++++++++++++++++++++++ 6 files changed, 100 insertions(+), 2 deletions(-) create mode 160000 external/volk create mode 100644 framework/sdl_service/test/volk_test1.cpp diff --git a/.gitmodules b/.gitmodules index f476259..9ad1af6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,3 +37,6 @@ path = external/physfs/physfs url = https://github.com/icculus/physfs.git branch = main +[submodule "external/volk"] + path = external/volk + url = https://github.com/zeux/volk.git diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index aa4c6e9..c481563 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -38,6 +38,13 @@ if(NOT MM_HEADLESS) add_subdirectory("glad-debug") endif() + # TODO: determain if we need this + #if (WIN32) + #set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR) + #elseif() + #endif() + add_subdirectory("volk") + # stb utilies add_subdirectory("stb") @@ -54,4 +61,3 @@ if(NOT MM_HEADLESS) add_subdirectory("soloud") endif() - diff --git a/external/volk b/external/volk new file mode 160000 index 0000000..2784718 --- /dev/null +++ b/external/volk @@ -0,0 +1 @@ +Subproject commit 2784718c913433d718561f9a9488996b4c05c2ff diff --git a/framework/sdl_service/CMakeLists.txt b/framework/sdl_service/CMakeLists.txt index 4ca7020..8efca9a 100644 --- a/framework/sdl_service/CMakeLists.txt +++ b/framework/sdl_service/CMakeLists.txt @@ -40,6 +40,9 @@ else() target_link_libraries(sdl_service glad) endif() +# TODO: conditionaly +target_link_libraries(sdl_service volk::volk) + if(VCPKG_TARGET_TRIPLET) target_link_libraries(sdl_service SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static) endif() diff --git a/framework/sdl_service/test/CMakeLists.txt b/framework/sdl_service/test/CMakeLists.txt index d3f6046..6063c04 100644 --- a/framework/sdl_service/test/CMakeLists.txt +++ b/framework/sdl_service/test/CMakeLists.txt @@ -1,4 +1,7 @@ -add_executable(sdl_service_test start_test.cpp) +add_executable(sdl_service_test + ./start_test.cpp + ./volk_test1.cpp +) target_include_directories(sdl_service_test PRIVATE ".") diff --git a/framework/sdl_service/test/volk_test1.cpp b/framework/sdl_service/test/volk_test1.cpp new file mode 100644 index 0000000..31d73b1 --- /dev/null +++ b/framework/sdl_service/test/volk_test1.cpp @@ -0,0 +1,82 @@ +#include + +#include +#include + +#include + +#include + +TEST(sdl_service, window_volk) { + MM::Engine engine; + + engine.addService(); + ASSERT_TRUE(engine.enableService()); + + auto* sdl_ss_ptr = engine.tryService(); + ASSERT_NE(sdl_ss_ptr, nullptr); + + // init volk + auto init_res = volkInitialize(); + ASSERT_EQ(init_res, VK_SUCCESS); + + + // create window + ASSERT_EQ(sdl_ss_ptr->win, nullptr); + ASSERT_TRUE(sdl_ss_ptr->createWindow("test vulkan window", 800, 600, SDL_WINDOW_VULKAN)); + ASSERT_NE(sdl_ss_ptr->win, nullptr); + + // create vulkan instance + + // Get the required extension count + unsigned int count; + ASSERT_TRUE( + SDL_Vulkan_GetInstanceExtensions( + sdl_ss_ptr->win, + &count, + nullptr + ) + ); + + std::vector extensions { + //VK_EXT_DEBUG_REPORT_EXTENSION_NAME // Sample additional extension + }; + size_t additional_extension_count = extensions.size(); + extensions.resize(additional_extension_count + count); + + ASSERT_TRUE( + SDL_Vulkan_GetInstanceExtensions( + sdl_ss_ptr->win, + &count, + extensions.data() + additional_extension_count + ) + ); + + // Now we can make the Vulkan instance + VkInstanceCreateInfo create_info {}; + //create_info.pApplicationInfo; + create_info.enabledExtensionCount = static_cast(extensions.size()); + create_info.ppEnabledExtensionNames = extensions.data(); + + VkInstance instance; + VkResult result = vkCreateInstance(&create_info, nullptr, &instance); + ASSERT_EQ(result, VK_SUCCESS); + + // finish setting up volk ? + volkLoadInstance(instance); + + // the surface for the window + VkSurfaceKHR surface; + ASSERT_TRUE( + SDL_Vulkan_CreateSurface( + sdl_ss_ptr->win, + instance, + &surface + ) + ); + + engine.disableService(); + + ASSERT_EQ(sdl_ss_ptr->win, nullptr); +} +